[Lldb-commits] [lldb] r131914 - in /lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD: DynamicLoaderMacOSXDYLD.cpp DynamicLoaderMacOSXDYLD.h

Greg Clayton gclayton at apple.com
Mon May 23 13:06:52 PDT 2011


Author: gclayton
Date: Mon May 23 15:06:52 2011
New Revision: 131914

URL: http://llvm.org/viewvc/llvm-project?rev=131914&view=rev
Log:
Calculate the dyld slide from all in memory info without having to use the
lldb module.


Modified:
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
    lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp?rev=131914&r1=131913&r2=131914&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Mon May 23 15:06:52 2011
@@ -360,40 +360,6 @@
             SectionList *section_list = image_object_file->GetSectionList ();
             if (section_list)
             {
-                // All sections listed in the dyld image info structure will all
-                // either be fixed up already, or they will all be off by a single
-                // slide amount that is determined by finding the first segment
-                // that is at file offset zero which also has bytes (a file size
-                // that is greater than zero) in the object file.
-
-                // Determine the slide amount (if any)
-                info.slide = 0;
-                const size_t num_sections = section_list->GetSize();
-                size_t sect_idx = 0;
-                for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
-                {
-                    // Iterate through the object file sections to find the
-                    // first section that starts of file offset zero and that
-                    // has bytes in the file...
-                    Section *section = section_list->GetSectionAtIndex (sect_idx).get();
-                    if (section)
-                    {
-                        // Find the first section that begins at file offset zero
-                        // a file size (skip page zero).
-                        if (section->GetFileOffset() == 0 && section->GetFileSize() > 0)
-                        {
-                            // We have now found the section, lets match it up
-                            // with the section in the dyld image info structure.
-                            const Segment *dyld_segment = info.FindSegment (section->GetName());
-                            if (dyld_segment)
-                                info.slide = info.address - dyld_segment->addr;
-                            // We have found the slide amount, so we can exit
-                            // this for loop.
-                            break;
-                        }
-                    }
-                }
-
                 // We now know the slide amount, so go through all sections
                 // and update the load addresses with the correct values.
                 uint32_t num_segments = info.segments.size();
@@ -401,7 +367,7 @@
                 {
                     SectionSP section_sp(section_list->FindSectionByName(info.segments[i].name));
                     assert (section_sp.get() != NULL);
-                    const addr_t new_section_load_addr = info.segments[i].addr + info.slide;
+                    const addr_t new_section_load_addr = info.segments[i].vmaddr + info.slide;
                     const addr_t old_section_load_addr = m_process->GetTarget().GetSectionLoadList().GetSectionLoadAddress (section_sp.get());
                     if (old_section_load_addr == LLDB_INVALID_ADDRESS ||
                         old_section_load_addr != new_section_load_addr)
@@ -437,7 +403,7 @@
                 {
                     SectionSP section_sp(section_list->FindSectionByName(info.segments[i].name));
                     assert (section_sp.get() != NULL);
-                    const addr_t old_section_load_addr = info.segments[i].addr + info.slide;
+                    const addr_t old_section_load_addr = info.segments[i].vmaddr + info.slide;
                     if (m_process->GetTarget().GetSectionLoadList().SetSectionUnloaded (section_sp.get(), old_section_load_addr))
                         changed = true;
                 }
@@ -912,8 +878,14 @@
             case llvm::MachO::LoadCommandSegment32:
                 {
                     segment.name.SetTrimmedCStringWithLength ((const char *)data.GetData(&offset, 16), 16);
-                    segment.addr = data.GetU32 (&offset);
-                    segment.size = data.GetU32 (&offset);
+                    // We are putting 4 uint32_t values 4 uint64_t values so
+                    // we have to use multiple 32 bit gets below.
+                    segment.vmaddr = data.GetU32 (&offset);
+                    segment.vmsize = data.GetU32 (&offset);
+                    segment.fileoff = data.GetU32 (&offset);
+                    segment.filesize = data.GetU32 (&offset);
+                    // Extract maxprot, initprot, nsects and flags all at once
+                    data.GetU32(&offset, &segment.maxprot, 4);
                     dylib_info.segments.push_back (segment);
                 }
                 break;
@@ -921,8 +893,10 @@
             case llvm::MachO::LoadCommandSegment64:
                 {
                     segment.name.SetTrimmedCStringWithLength ((const char *)data.GetData(&offset, 16), 16);
-                    segment.addr = data.GetU64 (&offset);
-                    segment.size = data.GetU64 (&offset);
+                    // Extract vmaddr, vmsize, fileoff, and filesize all at once
+                    data.GetU64(&offset, &segment.vmaddr, 4);
+                    // Extract maxprot, initprot, nsects and flags all at once
+                    data.GetU32(&offset, &segment.maxprot, 4);
                     dylib_info.segments.push_back (segment);
                 }
                 break;
@@ -947,6 +921,28 @@
             offset = load_cmd_offset + load_cmd.cmdsize;
         }
     }
+    
+    // All sections listed in the dyld image info structure will all
+    // either be fixed up already, or they will all be off by a single
+    // slide amount that is determined by finding the first segment
+    // that is at file offset zero which also has bytes (a file size
+    // that is greater than zero) in the object file.
+    
+    // Determine the slide amount (if any)
+    const size_t num_sections = dylib_info.segments.size();
+    for (size_t i = 0; i < num_sections; ++i)
+    {
+        // Iterate through the object file sections to find the
+        // first section that starts of file offset zero and that
+        // has bytes in the file...
+        if (dylib_info.segments[i].fileoff == 0 && dylib_info.segments[i].filesize > 0)
+        {
+            dylib_info.slide = dylib_info.address - dylib_info.segments[i].vmaddr;
+            // We have found the slide amount, so we can exit
+            // this for loop.
+            break;
+        }
+    }
     return cmd_idx;
 }
 
@@ -1011,7 +1007,19 @@
 DynamicLoaderMacOSXDYLD::Segment::PutToLog (Log *log, lldb::addr_t slide) const
 {
     if (log)
-        log->Printf("\t\t%16s [0x%16.16llx - 0x%16.16llx)", name.AsCString(""), addr + slide, addr + slide + size);
+    {
+        if (slide == 0)
+            log->Printf ("\t\t%16s [0x%16.16llx - 0x%16.16llx)", 
+                         name.AsCString(""), 
+                         vmaddr + slide, 
+                         vmaddr + slide + vmsize);
+        else
+            log->Printf ("\t\t%16s [0x%16.16llx - 0x%16.16llx) slide = 0x%llx", 
+                         name.AsCString(""), 
+                         vmaddr + slide, 
+                         vmaddr + slide + vmsize, 
+                         slide);
+    }
 }
 
 const DynamicLoaderMacOSXDYLD::Segment *

Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h?rev=131914&r1=131913&r2=131914&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h Mon May 23 15:06:52 2011
@@ -168,19 +168,31 @@
 
         Segment() :
             name(),
-            addr(LLDB_INVALID_ADDRESS),
-            size(0)
+            vmaddr(LLDB_INVALID_ADDRESS),
+            vmsize(0),
+            fileoff(0),
+            filesize(0),
+            maxprot(0),
+            initprot(0),
+            nsects(0),
+            flags(0)
         {
         }
 
         lldb_private::ConstString name;
-        lldb::addr_t addr;
-        lldb::addr_t size;
+        lldb::addr_t vmaddr;
+        lldb::addr_t vmsize;
+        lldb::addr_t fileoff;
+        lldb::addr_t filesize;
+        uint32_t maxprot;
+        uint32_t initprot;
+        uint32_t nsects;
+        uint32_t flags;
 
         bool
         operator==(const Segment& rhs) const
         {
-            return name == rhs.name && addr == rhs.addr && size == rhs.size;
+            return name == rhs.name && vmaddr == rhs.vmaddr && vmsize == rhs.vmsize;
         }
 
         void





More information about the lldb-commits mailing list