[Lldb-commits] [lldb] r181916 - <rdar://problem/13128331>

Greg Clayton gclayton at apple.com
Wed May 15 12:52:08 PDT 2013


Author: gclayton
Date: Wed May 15 14:52:08 2013
New Revision: 181916

URL: http://llvm.org/viewvc/llvm-project?rev=181916&view=rev
Log:
<rdar://problem/13128331>

Fixed "target symbols add" to correctly extract all module specifications from a dSYM file that is supplied and match the symbol file to a current target module using the UUID values if they are available.

This fixes the case where you add a dSYM file (like "foo.dSYM") which is for a renamed executable (like "bar"). In our case it was "mach_kernel.dSYM" which didn't match "mach_kernel.sys". 


Modified:
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=181916&r1=181915&r2=181916&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed May 15 14:52:08 2013
@@ -4272,7 +4272,53 @@ protected:
             // current target, so we need to find that module in the
             // target
             ModuleList matching_module_list;
-            size_t num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
+            
+            size_t num_matches = 0;
+            // First extract all module specs from the symbol file
+            lldb_private::ModuleSpecList symfile_module_specs;
+            if (ObjectFile::GetModuleSpecifications(module_spec.GetSymbolFileSpec(), 0, symfile_module_specs))
+            {
+                // Now extract the module spec that matches the target architecture
+                ModuleSpec target_arch_module_spec;
+                ModuleSpec symfile_module_spec;
+                target_arch_module_spec.GetArchitecture() = target->GetArchitecture();
+                if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec, symfile_module_spec))
+                {
+                    // See if it has a UUID?
+                    if (symfile_module_spec.GetUUID().IsValid())
+                    {
+                        // It has a UUID, look for this UUID in the target modules
+                        ModuleSpec symfile_uuid_module_spec;
+                        symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
+                        num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
+                    }
+                }
+                
+                if (num_matches == 0)
+                {
+                    // No matches yet, iterate through the module specs to find a UUID value that
+                    // we can match up to an image in our target
+                    const size_t num_symfile_module_specs = symfile_module_specs.GetSize();
+                    for (size_t i=0; i<num_symfile_module_specs && num_matches == 0; ++i)
+                    {
+                        if (symfile_module_specs.GetModuleSpecAtIndex(i, symfile_module_spec))
+                        {
+                            if (symfile_module_spec.GetUUID().IsValid())
+                            {
+                                // It has a UUID, look for this UUID in the target modules
+                                ModuleSpec symfile_uuid_module_spec;
+                                symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
+                                num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
+                            }                            
+                        }
+                    }
+                }
+            }
+
+            // Just try to match up the file by basename if we have no matches at this point
+            if (num_matches == 0)
+                num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
+    
             while (num_matches == 0)
             {
                 ConstString filename_no_extension(module_spec.GetFileSpec().GetFileNameStrippingExtension());
@@ -4288,6 +4334,7 @@ protected:
                 module_spec.GetFileSpec().GetFilename() = filename_no_extension;
                 
                 num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
+                
             }
 
             if (num_matches > 1)

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=181916&r1=181915&r2=181916&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Wed May 15 14:52:08 2013
@@ -397,6 +397,26 @@ protected:
     }
 };
 
+static uint32_t
+MachHeaderSizeFromMagic(uint32_t magic)
+{
+    switch (magic)
+    {
+        case HeaderMagic32:
+        case HeaderMagic32Swapped:
+            return sizeof(struct mach_header);
+            
+        case HeaderMagic64:
+        case HeaderMagic64Swapped:
+            return sizeof(struct mach_header_64);
+            break;
+            
+        default:
+            break;
+    }
+    return 0;
+}
+
 #define MACHO_NLIST_ARM_SYMBOL_IS_THUMB 0x0008
 
 void
@@ -493,7 +513,7 @@ ObjectFileMachO::GetModuleSpecifications
             if (header.sizeofcmds >= data_sp->GetByteSize())
             {
                 data_sp = file.ReadFileContents(file_offset, header.sizeofcmds);
-                data_offset = 0;
+                data_offset = MachHeaderSizeFromMagic(header.magic) + file_offset;
             }
             if (data_sp)
             {
@@ -550,29 +570,6 @@ ObjectFileMachO::GetSectionNameEHFrame()
     return g_section_name_eh_frame;
 }
 
-
-
-static uint32_t
-MachHeaderSizeFromMagic(uint32_t magic)
-{
-    switch (magic)
-    {
-    case HeaderMagic32:
-    case HeaderMagic32Swapped:
-        return sizeof(struct mach_header);
-
-    case HeaderMagic64:
-    case HeaderMagic64Swapped:
-        return sizeof(struct mach_header_64);
-        break;
-
-    default:
-        break;
-    }
-    return 0;
-}
-
-
 bool
 ObjectFileMachO::MagicBytesMatch (DataBufferSP& data_sp,
                                   lldb::addr_t data_offset,





More information about the lldb-commits mailing list