[Lldb-commits] [lldb] r160085 - in /lldb/trunk: include/lldb/Core/Address.h source/Core/Address.cpp source/Core/DataExtractor.cpp

Greg Clayton gclayton at apple.com
Wed Jul 11 15:18:24 PDT 2012


Author: gclayton
Date: Wed Jul 11 17:18:24 2012
New Revision: 160085

URL: http://llvm.org/viewvc/llvm-project?rev=160085&view=rev
Log:
Modifying the "address" format, which prints a pointer and a description of what it points to, to detect when the deref of that pointer points to something valid. So if you have:

    % cat sp.cpp 
    #include <tr1/memory>

    class A
    {
    public:
        A (): m_i (12) {}
        virtual ~A() {}
    private:
        int m_i;
    };

    int main (int argc, char const *argv[], char const *envp[])
    {
        A *a_pointers[2] = { NULL, NULL };
        A a1;
        A a2;
        a_pointers[0] = &a1;
        a_pointers[1] = &a2;
        return 0;
    }


And you stop at the "return 0", you can now read memory using the "address" format and see:

(lldb) memory read --format address `&a_pointers`
0x7fff5fbff870: 0x00007fff5fbff860 -> 0x00000001000010b0 vtable for A + 16
0x7fff5fbff878: 0x00007fff5fbff850 -> 0x00000001000010b0 vtable for A + 16
0x7fff5fbff880: 0x00007fff5fbff8d0
0x7fff5fbff888: 0x00007fff5fbff8c0
0x7fff5fbff890: 0x0000000000000001
0x7fff5fbff898: 0x36d54c275add2294
0x7fff5fbff8a0: 0x00007fff5fbff8b0
0x7fff5fbff8a8: 0x0000000100000bb4 a.out`start + 52

Note the extra dereference that was applied to 0x00007fff5fbff860 and 0x00007fff5fbff850 so we can see that these are "A" classes.


Modified:
    lldb/trunk/include/lldb/Core/Address.h
    lldb/trunk/source/Core/Address.cpp
    lldb/trunk/source/Core/DataExtractor.cpp

Modified: lldb/trunk/include/lldb/Core/Address.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Address.h?rev=160085&r1=160084&r2=160085&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Address.h (original)
+++ lldb/trunk/include/lldb/Core/Address.h Wed Jul 11 17:18:24 2012
@@ -86,8 +86,10 @@
                                         ///< and file and line), to information about what the pointer points to
                                         ///< if the address is in a section (section of pointers, c strings, etc).
         DumpStyleResolvedDescriptionNoModule,
-        DumpStyleDetailedSymbolContext  ///< Detailed symbol context information for an address for all symbol
+        DumpStyleDetailedSymbolContext, ///< Detailed symbol context information for an address for all symbol
                                         ///< context members.
+        DumpStyleResolvedPointerDescription ///< Dereference a pointer at the current address and then lookup the
+                                             ///< dereferenced address using DumpStyleResolvedDescription
     } DumpStyle;
 
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Core/Address.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=160085&r1=160084&r2=160085&view=diff
==============================================================================
--- lldb/trunk/source/Core/Address.cpp (original)
+++ lldb/trunk/source/Core/Address.cpp Wed Jul 11 17:18:24 2012
@@ -354,9 +354,10 @@
 bool
 Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style, uint32_t addr_size) const
 {
-    // If the section was NULL, only load address is going to work.
+    // If the section was NULL, only load address is going to work unless we are
+    // trying to deref a pointer
     SectionSP section_sp (GetSection());
-    if (!section_sp)
+    if (!section_sp && style != DumpStyleResolvedPointerDescription)
         style = DumpStyleLoadAddress;
 
     ExecutionContext exe_ctx (exe_scope);
@@ -728,6 +729,37 @@
             return false;
         }
         break;
+    case DumpStyleResolvedPointerDescription:
+        {
+            Process *process = exe_ctx.GetProcessPtr();
+            if (process)
+            {
+                addr_t load_addr = GetLoadAddress (target);
+                if (load_addr != LLDB_INVALID_ADDRESS)
+                {
+                    Error memory_error;
+                    addr_t dereferenced_load_addr = process->ReadPointerFromMemory(load_addr, memory_error);
+                    if (dereferenced_load_addr != LLDB_INVALID_ADDRESS)
+                    {
+                        Address dereferenced_addr;
+                        if (dereferenced_addr.SetLoadAddress(dereferenced_load_addr, target))
+                        {
+                            StreamString strm;
+                            if (dereferenced_addr.Dump (&strm, exe_scope, DumpStyleResolvedDescription, DumpStyleInvalid, addr_size))
+                            {
+                                s->Address (dereferenced_load_addr, addr_size, " -> ", " ");
+                                s->Write(strm.GetData(), strm.GetSize());
+                                return true;
+                            }
+                        }
+                    }
+                }
+            }
+            if (fallback_style != DumpStyleInvalid)
+                return Dump (s, exe_scope, fallback_style, DumpStyleInvalid, addr_size);
+            return false;
+        }
+        break;
     }
 
     return true;

Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=160085&r1=160084&r2=160085&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Wed Jul 11 17:18:24 2012
@@ -1737,14 +1737,21 @@
                 {
                     TargetSP target_sp (exe_scope->CalculateTarget());
                     lldb_private::Address so_addr;
-                    if (target_sp && target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr))
+                    if (target_sp)
                     {
-                        s->PutChar(' ');
-                        so_addr.Dump (s, 
-                                      exe_scope, 
-                                      Address::DumpStyleResolvedDescription, 
-                                      Address::DumpStyleModuleWithFileAddress);
-                        break;
+                        if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr))
+                        {
+                            s->PutChar(' ');
+                            so_addr.Dump (s,
+                                          exe_scope,
+                                          Address::DumpStyleResolvedDescription,
+                                          Address::DumpStyleModuleWithFileAddress);
+                        }
+                        else
+                        {
+                            so_addr.SetOffset(addr);
+                            so_addr.Dump (s, exe_scope, Address::DumpStyleResolvedPointerDescription);
+                        }
                     }
                 }
             }





More information about the lldb-commits mailing list