[Lldb-commits] [lldb] r150443 - /lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Greg Clayton gclayton at apple.com
Mon Feb 13 16:14:24 PST 2012


Author: gclayton
Date: Mon Feb 13 18:14:24 2012
New Revision: 150443

URL: http://llvm.org/viewvc/llvm-project?rev=150443&view=rev
Log:
Made loading sections in the DynamicLoaderDarwinKernel more robust as it
seems that sections in the memory module might be quite different from the
sections in the file module. Now we find all segments in the on disk file and
find that segment by name in the memory module and it is ok if any sections
from the file are missing in the memory image.


Modified:
    lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Modified: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp?rev=150443&r1=150442&r2=150443&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp Mon Feb 13 18:14:24 2012
@@ -210,37 +210,34 @@
                     SectionList *memory_section_list = memory_object_file->GetSectionList ();
                     if (memory_section_list && ondisk_section_list)
                     {
-                        const uint32_t num_sections = ondisk_section_list->GetSize();
+                        const uint32_t num_ondisk_sections = ondisk_section_list->GetSize();
                         // There may be CTF sections in the memory image so we can't
                         // always just compare the number of sections (which are actually
                         // segments in mach-o parlance)
                         uint32_t sect_idx = 0;
-                        const Section *memory_section;
-                        const Section *ondisk_section;
-                        // Always use the number of sections from the on disk file
-                        // in case there are extra sections added to the memory image.
-                        for (sect_idx=0; sect_idx<num_sections; ++sect_idx)
+                        
+                        
+                        // We now iterate through all sections in the file module 
+                        // and look to see if the memory module has a load address
+                        // for that section.
+                        uint32_t num_sections_loaded = 0;
+                        for (sect_idx=0; sect_idx<num_ondisk_sections; ++sect_idx)
                         {
-                            memory_section = memory_section_list->GetSectionAtIndex(sect_idx).get();
-                            ondisk_section = ondisk_section_list->GetSectionAtIndex(sect_idx).get();
-                            if (memory_section->GetName() != ondisk_section->GetName())
+                            const Section *ondisk_section = ondisk_section_list->GetSectionAtIndex(sect_idx).get();
+                            if (ondisk_section)
                             {
-                                // Section count was the same, but the sections themselves do not match
-                                module_sp.reset();
-                                break;
+                                const Section *memory_section = memory_section_list->FindSectionByName(ondisk_section->GetName()).get();
+                                if (memory_section)
+                                {
+                                    target.GetSectionLoadList().SetSectionLoadAddress (ondisk_section, memory_section->GetFileAddress());
+                                    ++num_sections_loaded;
+                                }
                             }
                         }
-                        if (module_sp)
-                        {
-                            for (sect_idx=0; sect_idx<num_sections; ++sect_idx)
-                            {
-                                memory_section = memory_section_list->GetSectionAtIndex(sect_idx).get();
-                                ondisk_section = ondisk_section_list->GetSectionAtIndex(sect_idx).get();
-                                target.GetSectionLoadList().SetSectionLoadAddress (ondisk_section, memory_section->GetFileAddress());
-                            }
-                            if (num_sections > 0)
-                                load_process_stop_id = process->GetStopID();
-                        }
+                        if (num_sections_loaded > 0)
+                            load_process_stop_id = process->GetStopID();
+                        else
+                            module_sp.reset(); // No sections were loaded
                     }
                     else
                         module_sp.reset(); // One or both section lists
@@ -569,14 +566,14 @@
             {
                 image_infos[i].reference_list = 0;
             }
-            printf ("[%3u] %*.*s: address=0x%16.16llx, size=0x%16.16llx, version=0x%16.16llx, load_tag=0x%8.8x, flags=0x%8.8x\n", 
-                    i,
-                    KERNEL_MODULE_MAX_NAME, KERNEL_MODULE_MAX_NAME,  (char *)name_data, 
-                    image_infos[i].address, 
-                    image_infos[i].size,
-                    image_infos[i].version,
-                    image_infos[i].load_tag,
-                    image_infos[i].flags);
+//            printf ("[%3u] %*.*s: address=0x%16.16llx, size=0x%16.16llx, version=0x%16.16llx, load_tag=0x%8.8x, flags=0x%8.8x\n", 
+//                    i,
+//                    KERNEL_MODULE_MAX_NAME, KERNEL_MODULE_MAX_NAME,  (char *)name_data, 
+//                    image_infos[i].address, 
+//                    image_infos[i].size,
+//                    image_infos[i].version,
+//                    image_infos[i].load_tag,
+//                    image_infos[i].flags);
         }
         if (i < image_infos.size())
             image_infos.resize(i);





More information about the lldb-commits mailing list