[Lldb-commits] [lldb] r157230 - in /lldb/trunk/source/Plugins/Process/gdb-remote: GDBRemoteRegisterContext.cpp GDBRemoteRegisterContext.h ProcessGDBRemote.cpp

Johnny Chen johnny.chen at apple.com
Mon May 21 17:57:06 PDT 2012


Author: johnny
Date: Mon May 21 19:57:05 2012
New Revision: 157230

URL: http://llvm.org/viewvc/llvm-project?rev=157230&view=rev
Log:
rdar://problem/11487457

Add convenience registers eax, ebx, ecx, edx, edi, esi, ebp, esp to the 'register read' command for x86_64.
Add a GDBRemoteRegisterContext::Addx86_64ConvenienceRegisters() method called from ProcessGDBRemote::BuildDynamicRegisterInfo().
Servicing of eax, for example, is accomplished by delegating to rax with an adjusted offset into the register context.

Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp?rev=157230&r1=157229&r2=157230&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp Mon May 21 19:57:05 2012
@@ -929,3 +929,76 @@
     }
 }
 
+void
+GDBRemoteDynamicRegisterInfo::Addx86_64ConvenienceRegisters()
+{
+    // For eax, ebx, ecx, edx, esi, edi, ebp, esp register mapping.
+    static const char* g_mapped_names[] = {
+        "rax",
+        "rbx",
+        "rcx",
+        "rdx",
+        "rdi",
+        "rsi",
+        "rbp",
+        "rsp"
+    };
+
+    // These value regs are to be populated with the corresponding primordial register index.
+    // For example,
+    static uint32_t g_eax_regs[] =  { 0, LLDB_INVALID_REGNUM }; // 0 is to be replaced with rax's index.
+    static uint32_t g_ebx_regs[] =  { 0, LLDB_INVALID_REGNUM };
+    static uint32_t g_ecx_regs[] =  { 0, LLDB_INVALID_REGNUM };
+    static uint32_t g_edx_regs[] =  { 0, LLDB_INVALID_REGNUM };
+    static uint32_t g_edi_regs[] =  { 0, LLDB_INVALID_REGNUM };
+    static uint32_t g_esi_regs[] =  { 0, LLDB_INVALID_REGNUM };
+    static uint32_t g_ebp_regs[] =  { 0, LLDB_INVALID_REGNUM };
+    static uint32_t g_esp_regs[] =  { 0, LLDB_INVALID_REGNUM };
+    
+    static RegisterInfo g_conv_register_infos[] = 
+    {
+//    NAME      ALT      SZ OFF ENCODING         FORMAT                COMPILER              DWARF                 GENERIC                      GDB                   LLDB NATIVE            VALUE REGS    INVALIDATE REGS
+//    ======    =======  == === =============    ============          ===================== ===================== ============================ ====================  ====================== ==========    ===============
+    { "eax",    NULL,    4,  0, eEncodingUint  , eFormatHex          , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM }, g_eax_regs,              NULL},
+    { "ebx"   , NULL,    4,  0, eEncodingUint  , eFormatHex          , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM }, g_ebx_regs,              NULL},
+    { "ecx"   , NULL,    4,  0, eEncodingUint  , eFormatHex          , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM }, g_ecx_regs,              NULL},
+    { "edx"   , NULL,    4,  0, eEncodingUint  , eFormatHex          , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM }, g_edx_regs,              NULL},
+    { "edi"   , NULL,    4,  0, eEncodingUint  , eFormatHex          , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM }, g_edi_regs,              NULL},
+    { "esi"   , NULL,    4,  0, eEncodingUint  , eFormatHex          , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM }, g_esi_regs,              NULL},
+    { "ebp"   , NULL,    4,  0, eEncodingUint  , eFormatHex          , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM }, g_ebp_regs,              NULL},
+    { "esp"   , NULL,    4,  0, eEncodingUint  , eFormatHex          , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM }, g_esp_regs,              NULL}
+    };
+
+    static const uint32_t num_conv_regs = llvm::array_lengthof(g_mapped_names);
+    static ConstString gpr_reg_set ("General Purpose Registers");
+    
+    // Add convenience registers to our primordial registers.
+    const uint32_t num_primordials = GetNumRegisters();
+    uint32_t reg_kind = num_primordials;
+    for (uint32_t i=0; i<num_conv_regs; ++i)
+    {
+        ConstString name;
+        ConstString alt_name;
+        const char *prim_reg_name = g_mapped_names[i];
+        if (prim_reg_name && prim_reg_name[0])
+        {
+            for (uint32_t j = 0; j < num_primordials; ++j)
+            {
+                const RegisterInfo *reg_info = GetRegisterInfoAtIndex(j);
+                // Find a matching primordial register info entry.
+                if (reg_info && reg_info->name && ::strcasecmp(reg_info->name, prim_reg_name) == 0)
+                {
+                    // The name matches the existing primordial entry.
+                    // Find and assign the offset, and then add this composite register entry.
+                    g_conv_register_infos[i].byte_offset = reg_info->byte_offset + 4;
+                    // Update the value_regs and the kinds fields in order to delegate to the primordial register.
+                    g_conv_register_infos[i].value_regs[0] = j;
+                    g_conv_register_infos[i].kinds[eRegisterKindLLDB] = ++reg_kind;
+                    name.SetCString(g_conv_register_infos[i].name);
+                    AddRegister(g_conv_register_infos[i], name, alt_name, gpr_reg_set);
+                }
+            }
+        }
+    }
+}
+

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h?rev=157230&r1=157229&r2=157230&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h Mon May 21 19:57:05 2012
@@ -156,6 +156,9 @@
     void
     HardcodeARMRegisters(bool from_scratch);
 
+    void
+    Addx86_64ConvenienceRegisters();
+
 protected:
     //------------------------------------------------------------------
     // Classes that inherit from GDBRemoteRegisterContext can see and modify these

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=157230&r1=157229&r2=157230&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Mon May 21 19:57:05 2012
@@ -400,6 +400,10 @@
         m_register_info.HardcodeARMRegisters(from_scratch);
     }
 
+    // Add some convenience registers (eax, ebx, ecx, edx, esi, edi, ebp, esp) to x86_64.
+    if (target_arch.IsValid() && target_arch.GetMachine() == llvm::Triple::x86_64)
+        m_register_info.Addx86_64ConvenienceRegisters();
+
     // At this point, we can finalize our register info.
     m_register_info.Finalize ();
 }





More information about the lldb-commits mailing list