[Lldb-commits] [PATCH] Use DataBufferHeap to genericise elf-core RegisterContext gpr storage

Ed Maste emaste at freebsd.org
Wed Feb 19 12:04:22 PST 2014


We have two elf-core RegisterContext classes right now, and each stores its gpr data differently.

x86_64 does this:

    size_t size, len;                                                           
                                                                                
    size = GetGPRSize();                                                        
    m_gpregset = new uint8_t[size];                                             
    len = gpregset.ExtractBytes (0, size, lldb::eByteOrderLittle, m_gpregset);  
    assert(len == size);                                                        

and then accesses a register like so:

    switch (reg_info->byte_size)                                                
    {                                                                           
        case 4:                                                                 
            value = *(uint32_t *)(m_gpregset + reg_info->byte_offset);          
            return true;                                                        
        case 8:                                                                 
            value = *(uint64_t *)(m_gpregset + reg_info->byte_offset);          
            return true;                                                        
    }                                                                           
    return false;                                                               

Which has two issues:
1. It only works if the host and target have the same endianness
2. It relies on the byte_offset value having appropriate alignment for the host (admittedly, this is probably always true in practice)

mips64 does this:

    size_t i;                                                                   
    lldb::offset_t offset = 0;                                                  
                                                                                
    for (i = 0; i < k_num_gpr_registers_mips64; i++)                            
    {                                                                           
        m_reg[i] = gpregset.GetU64(&offset);                                    
    }                                                                           

and then access a register like so:

    int reg_num = reg_info->byte_offset / 8;                                    
    assert(reg_num < k_num_gpr_registers_mips64);                               
    value = m_reg[reg_num];                                                     
    return true;                                                                

Which solves the endianness issue, but is not generic.

Instead, store the gpr data in a DataBufferHeap and use a DataExtractor to extract register values with appropriate endianness.

Assuming this looks good we can rename this to RegisterContextCorePOSIX and use for i386/x86_64/mips64.


http://llvm-reviews.chandlerc.com/D2833

Files:
  source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
  source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h

Index: source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
===================================================================
--- source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
+++ source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.cpp
@@ -21,13 +21,9 @@
                                                                  const DataExtractor &fpregset)
     : RegisterContextPOSIX_mips64(thread, 0, register_info)
 {
-    size_t i;
-    lldb::offset_t offset = 0;
-
-    for (i = 0; i < k_num_gpr_registers_mips64; i++)
-    {
-        m_reg[i] = gpregset.GetU64(&offset);
-    }
+    m_gpr_buffer.reset(new DataBufferHeap(gpregset.GetDataStart(), gpregset.GetByteSize()));
+    m_gpr.SetData(m_gpr_buffer);
+    m_gpr.SetByteOrder(gpregset.GetByteOrder());
 }
 
 RegisterContextCorePOSIX_mips64::~RegisterContextCorePOSIX_mips64()
@@ -63,10 +59,14 @@
 bool
 RegisterContextCorePOSIX_mips64::ReadRegister(const RegisterInfo *reg_info, RegisterValue &value)
 {
-    int reg_num = reg_info->byte_offset / 8;
-    assert(reg_num < k_num_gpr_registers_mips64);
-    value = m_reg[reg_num];
-    return true;
+    lldb::offset_t offset = reg_info->byte_offset;
+    uint64_t v = m_gpr.GetMaxU64(&offset, reg_info->byte_size);
+    if (offset == reg_info->byte_offset + reg_info->byte_size)
+    {
+        value = v;
+        return true;
+    }
+    return false;
 }
 
 bool
Index: source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
===================================================================
--- source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
+++ source/Plugins/Process/elf-core/RegisterContextPOSIXCore_mips64.h
@@ -10,6 +10,7 @@
 #ifndef liblldb_RegisterContextCorePOSIX_mips64_H_
 #define liblldb_RegisterContextCorePOSIX_mips64_H_
 
+#include "lldb/Core/DataBufferHeap.h"
 #include "Plugins/Process/POSIX/RegisterContextPOSIX_mips64.h"
 
 class RegisterContextCorePOSIX_mips64 :
@@ -52,7 +53,8 @@
     WriteFPR();
 
 private:
-    uint64_t m_reg[40];
+    lldb::DataBufferSP m_gpr_buffer;
+    lldb_private::DataExtractor m_gpr;
 };
 
 #endif // #ifndef liblldb_RegisterContextCorePOSIX_mips64_H_
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2833.1.patch
Type: text/x-patch
Size: 2190 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140219/3747ac03/attachment.bin>


More information about the lldb-commits mailing list