[Lldb-commits] [lldb] r216258 - When adding a dSYM to an existing ObjectFile, we can have a situation

Jason Molenda jmolenda at apple.com
Thu Aug 21 19:46:46 PDT 2014


Author: jmolenda
Date: Thu Aug 21 21:46:46 2014
New Revision: 216258

URL: http://llvm.org/viewvc/llvm-project?rev=216258&view=rev
Log:
When adding a dSYM to an existing ObjectFile, we can have a situation
with binaries in the dyld shared cache (esp on iOS) where the file
address for the executable binary (maybe from memory, maybe from
an expanded copy of the dyld shared cache) is different from the
file address in the dSYM.  In that case, ObjectFileMachO replaces
the file addresses from the original binary with the dSYM file
addresses (usually 0-based) -- lldb doesn't have a notion of two
file addresses for a given module so they need to agree.

There was a cache of file addresses over in the Symtab so I added
a method to the Module and the objects within to clear any file address
caches if they exist, and added an implementation in the Symtab
module to do that.
<rdar://problem/16929569> 


Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/include/lldb/Symbol/ObjectFile.h
    lldb/trunk/include/lldb/Symbol/SymbolFile.h
    lldb/trunk/include/lldb/Symbol/SymbolVendor.h
    lldb/trunk/include/lldb/Symbol/Symtab.h
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    lldb/trunk/source/Symbol/SymbolVendor.cpp
    lldb/trunk/source/Symbol/Symtab.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Thu Aug 21 21:46:46 2014
@@ -704,6 +704,18 @@ public:
     virtual SectionList *
     GetSectionList ();
 
+    //------------------------------------------------------------------
+    /// Notify the module that the file addresses for the Sections have
+    /// been updated.
+    ///
+    /// If the Section file addresses for a module are updated, this
+    /// method should be called.  Any parts of the module, object file,
+    /// or symbol file that has cached those file addresses must invalidate
+    /// or update its cache.
+    //------------------------------------------------------------------
+    virtual void
+    SectionFileAddressesChanged ();
+
     uint32_t
     GetVersion (uint32_t *versions, uint32_t num_versions);
 

Modified: lldb/trunk/include/lldb/Symbol/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ObjectFile.h?rev=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ObjectFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/ObjectFile.h Thu Aug 21 21:46:46 2014
@@ -374,6 +374,16 @@ public:
     virtual void
     CreateSections (SectionList &unified_section_list) = 0;
 
+
+    //------------------------------------------------------------------
+    /// Notify the ObjectFile that the file addresses in the Sections
+    /// for this module have been changed.
+    //------------------------------------------------------------------
+    virtual void
+    SectionFileAddressesChanged ()
+    {
+    }
+
     //------------------------------------------------------------------
     /// Gets the symbol table for the currently selected architecture
     /// (and object for archives).

Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Thu Aug 21 21:46:46 2014
@@ -152,6 +152,16 @@ public:
 
     ObjectFile*             GetObjectFile() { return m_obj_file; }
     const ObjectFile*       GetObjectFile() const { return m_obj_file; }
+
+    //------------------------------------------------------------------
+    /// Notify the SymbolFile that the file addresses in the Sections
+    /// for this module have been changed.
+    //------------------------------------------------------------------
+    virtual void
+    SectionFileAddressesChanged () 
+    { 
+    }
+
     
 protected:
     ObjectFile*             m_obj_file; // The object file that symbols can be extracted from.

Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Thu Aug 21 21:46:46 2014
@@ -173,6 +173,13 @@ public:
     ClearSymtab ();
 
     //------------------------------------------------------------------
+    /// Notify the SymbolVendor that the file addresses in the Sections
+    /// for this module have been changed.
+    //------------------------------------------------------------------
+    virtual void
+    SectionFileAddressesChanged ();
+
+    //------------------------------------------------------------------
     // PluginInterface protocol
     //------------------------------------------------------------------
     virtual ConstString

Modified: lldb/trunk/include/lldb/Symbol/Symtab.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symtab.h?rev=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Symtab.h (original)
+++ lldb/trunk/include/lldb/Symbol/Symtab.h Thu Aug 21 21:46:46 2014
@@ -46,6 +46,7 @@ public:
             Symbol *    Resize (size_t count);
             uint32_t    AddSymbol(const Symbol& symbol);
             size_t      GetNumSymbols() const;
+            void        SectionFileAddressesChanged ();
             void        Dump(Stream *s, Target *target, SortOrder sort_type);
             void        Dump(Stream *s, Target *target, std::vector<uint32_t>& indexes) const;
             uint32_t    GetIndexForSymbol (const Symbol *symbol) const;

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Thu Aug 21 21:46:46 2014
@@ -1327,6 +1327,17 @@ Module::GetSectionList()
     return m_sections_ap.get();
 }
 
+void
+Module::SectionFileAddressesChanged ()
+{
+    ObjectFile *obj_file = GetObjectFile ();
+    if (obj_file)
+        obj_file->SectionFileAddressesChanged ();
+    SymbolVendor* sym_vendor = GetSymbolVendor();
+    if (sym_vendor)
+        sym_vendor->SectionFileAddressesChanged ();
+}
+
 SectionList *
 Module::GetUnifiedSectionList()
 {

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=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Thu Aug 21 21:46:46 2014
@@ -1249,6 +1249,8 @@ ObjectFileMachO::CreateSections (Section
             offset = load_cmd_offset + encryption_cmd.cmdsize;
         }
 
+        bool section_file_addresses_changed = false;
+
         offset = MachHeaderSizeFromMagic(m_header.magic);
 
         struct segment_command_64 load_cmd;
@@ -1377,6 +1379,10 @@ ObjectFileMachO::CreateSections (Section
                                     // where this code path will be taken will not have eh_frame sections.
 
                                     unified_section_sp->SetFileAddress(load_cmd.vmaddr);
+
+                                    // Notify the module that the section addresses have been changed once
+                                    // we're done so any file-address caches can be updated.
+                                    section_file_addresses_changed = true;
                                 }
                             }
                             m_sections_ap->AddSection(unified_section_sp);
@@ -1669,6 +1675,12 @@ ObjectFileMachO::CreateSections (Section
 
             offset = load_cmd_offset + load_cmd.cmdsize;
         }
+
+
+        if (section_file_addresses_changed && module_sp.get())
+        {
+            module_sp->SectionFileAddressesChanged();
+        }
     }
 }
 

Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Thu Aug 21 21:46:46 2014
@@ -468,6 +468,27 @@ SymbolVendor::ClearSymtab()
     }
 }
 
+void
+SymbolVendor::SectionFileAddressesChanged ()
+{
+    ModuleSP module_sp(GetModule());
+    if (module_sp)
+    {
+        ObjectFile *module_objfile = module_sp->GetObjectFile ();
+        if (m_sym_file_ap.get())
+        {
+            ObjectFile *symfile_objfile = m_sym_file_ap->GetObjectFile ();
+            if (symfile_objfile != module_objfile)
+                symfile_objfile->SectionFileAddressesChanged ();
+        }
+        Symtab *symtab = GetSymtab ();
+        if (symtab)
+        {
+            symtab->SectionFileAddressesChanged ();
+        }
+    }
+}
+
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------

Modified: lldb/trunk/source/Symbol/Symtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=216258&r1=216257&r2=216258&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symtab.cpp (original)
+++ lldb/trunk/source/Symbol/Symtab.cpp Thu Aug 21 21:46:46 2014
@@ -78,6 +78,13 @@ Symtab::GetNumSymbols() const
 }
 
 void
+Symtab::SectionFileAddressesChanged ()
+{
+    m_name_to_index.Clear();
+    m_file_addr_to_index_computed = false;
+}
+
+void
 Symtab::Dump (Stream *s, Target *target, SortOrder sort_order)
 {
     Mutex::Locker locker (m_mutex);





More information about the lldb-commits mailing list