[Lldb-commits] [lldb] r153537 - in /lldb/trunk: include/lldb/Core/Section.h include/lldb/Target/Target.h source/API/SBTarget.cpp source/Commands/CommandObjectTarget.cpp source/Core/Module.cpp source/Core/Section.cpp source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp source/Target/Target.cpp

Greg Clayton gclayton at apple.com
Tue Mar 27 14:10:07 PDT 2012


Author: gclayton
Date: Tue Mar 27 16:10:07 2012
New Revision: 153537

URL: http://llvm.org/viewvc/llvm-project?rev=153537&view=rev
Log:
lldb_private::Section objects have a boolean flag that can be set that 
indicates that the section is thread specific. Any functions the load a module
given a slide, will currently ignore any sections that are thread specific.

lldb_private::Section now has:

bool
Section::IsThreadSpecific () const
{
    return m_thread_specific;
}

void
Section::SetIsThreadSpecific (bool b)
{
    m_thread_specific = b;
}

The ELF plug-in has been modified to set this for the ".tdata" and the ".tbss"
sections.

Eventually we need to have each lldb_private::Thread subclass be able to 
resolve a thread specific section, but for now they will just not resolve. The
code for that should be trivual to add, but the address resolving functions
will need to be changed to take a "ExecutionContext" object instead of just
a target so that thread specific sections can be resolved.


Modified:
    lldb/trunk/include/lldb/Core/Section.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Core/Section.cpp
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Core/Section.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Section.h?rev=153537&r1=153536&r2=153537&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Section.h (original)
+++ lldb/trunk/include/lldb/Core/Section.h Tue Mar 27 16:10:07 2012
@@ -261,6 +261,18 @@
     {
         return m_parent_wp.lock();
     }
+    
+    bool
+    IsThreadSpecific () const
+    {
+        return m_thread_specific;
+    }
+
+    void
+    SetIsThreadSpecific (bool b)
+    {
+        m_thread_specific = b;
+    }
 
 protected:
 
@@ -277,7 +289,8 @@
                                         // children contains an address. This allows for gaps between the children
                                         // that are contained in the address range for this section, but do not produce
                                         // hits unless the children contain the address.
-                    m_encrypted:1;      // Set to true if the contents are encrypted
+                    m_encrypted:1,      // Set to true if the contents are encrypted
+                    m_thread_specific:1;// This section is thread specific
     lldb::SectionWP m_linked_section_wp;
     uint64_t        m_linked_offset;
 private:

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=153537&r1=153536&r2=153537&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Tue Mar 27 16:10:07 2012
@@ -844,33 +844,6 @@
         return m_section_load_list;
     }
 
-
-    //------------------------------------------------------------------
-    /// Load a module in this target by at the section file addresses
-    /// with an optional constant slide applied to each section.
-    ///
-    /// This function will load all top level sections at their file
-    /// addresses and apply an optional constant slide amount to each 
-    /// section. This can be used to easily load a module at the same 
-    /// addresses that are contained in the object file (trust that
-    /// the addresses in an object file are the correct load addresses).
-    ///
-    /// @param[in] module
-    ///     The module to load.
-    ///
-    /// @param[in] slide
-    ///     A constant slide to add to each file address as each section
-    ///     is being loaded.
-    ///
-    /// @return
-    ///     \b true if loading the module at the specified address 
-    ///     causes a section to be loaded when it previously wasn't, or
-    ///     if a section changes load address. Returns \b false if
-    ///     the sections were all already loaded at these addresses.
-    //------------------------------------------------------------------
-    bool
-    LoadModuleWithSlide (Module *module, lldb::addr_t slide);
-
     static Target *
     GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, 
                            const SymbolContext *sc_ptr);

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=153537&r1=153536&r2=153537&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Mar 27 16:10:07 2012
@@ -2086,12 +2086,23 @@
         }
         else
         {
-            target_sp->GetSectionLoadList().SetSectionLoadAddress (section.GetSP().get(), section_base_addr);
+            SectionSP section_sp (section.GetSP());
+            if (section_sp)
+            {
+                if (section_sp->IsThreadSpecific())
+                {
+                    sb_error.SetErrorString ("thread specific sections are not yet supported");
+                }
+                else
+                {
+                    target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_base_addr);
+                }
+            }
         }
     }
     else
     {
-        sb_error.SetErrorStringWithFormat ("invalid target");
+        sb_error.SetErrorString ("invalid target");
     }
     return sb_error;
 }
@@ -2132,31 +2143,18 @@
         ModuleSP module_sp (module.GetSP());
         if (module_sp)
         {
-            ObjectFile *objfile = module_sp->GetObjectFile();
-            if (objfile)
+            bool changed = false;
+            if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed))
             {
-                SectionList *section_list = objfile->GetSectionList();
-                if (section_list)
-                {
-                    const size_t num_sections = section_list->GetSize();
-                    for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
-                    {
-                        SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
-                        if (section_sp)
-                            target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide_offset);
-                    }
-                }
-                else
+                // The load was successful, make sure that at least some sections
+                // changed before we notify that our module was loaded.
+                if (changed)
                 {
-                    module_sp->GetFileSpec().GetPath (path, sizeof(path));
-                    sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path);
+                    ModuleList module_list;
+                    module_list.Append(module_sp);
+                    target_sp->ModulesDidLoad (module_list);
                 }
             }
-            else
-            {
-                module_sp->GetFileSpec().GetPath (path, sizeof(path));
-                sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path);
-            }
         }
         else
         {

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=153537&r1=153536&r2=153537&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Tue Mar 27 16:10:07 2012
@@ -2517,30 +2517,13 @@
                             SectionList *section_list = objfile->GetSectionList();
                             if (section_list)
                             {
+                                bool changed = false;
                                 if (argc == 0)
                                 {
                                     if (m_slide_option.GetOptionValue().OptionWasSet())
                                     {
-                                        Module *module = matching_modules.GetModulePointerAtIndex(0);
-                                        if (module)
-                                        {
-                                            ObjectFile *objfile = module->GetObjectFile();
-                                            if (objfile)
-                                            {
-                                                SectionList *section_list = objfile->GetSectionList();
-                                                if (section_list)
-                                                {
-                                                    const size_t num_sections = section_list->GetSize();
-                                                    const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
-                                                    for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
-                                                    {
-                                                        SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
-                                                        if (section_sp)
-                                                            target->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), section_sp->GetFileAddress() + slide);
-                                                    }
-                                                }
-                                            }
-                                        }
+                                        const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
+                                        module->SetLoadAddress (*target, slide, changed);
                                     }
                                     else
                                     {
@@ -2572,8 +2555,18 @@
                                                 SectionSP section_sp (section_list->FindSectionByName(const_sect_name));
                                                 if (section_sp)
                                                 {
-                                                    target->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), load_addr);
-                                                    result.AppendMessageWithFormat("section '%s' loaded at 0x%llx\n", sect_name, load_addr);
+                                                    if (section_sp->IsThreadSpecific())
+                                                    {
+                                                        result.AppendErrorWithFormat ("thread specific sections are not yet supported (section '%s')\n", sect_name);
+                                                        result.SetStatus (eReturnStatusFailed);
+                                                        break;
+                                                    }
+                                                    else
+                                                    {
+                                                        if (target->GetSectionLoadList().SetSectionLoadAddress (section_sp.get(), load_addr))
+                                                            changed = true;
+                                                        result.AppendMessageWithFormat("section '%s' loaded at 0x%llx\n", sect_name, load_addr);
+                                                    }
                                                 }
                                                 else
                                                 {
@@ -2600,6 +2593,9 @@
                                         }
                                     }
                                 }
+                                
+                                if (changed)
+                                    target->ModulesDidLoad (matching_modules);
                             }
                             else
                             {

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=153537&r1=153536&r2=153537&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Tue Mar 27 16:10:07 2012
@@ -1104,11 +1104,11 @@
 bool 
 Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed)
 {
-    changed = false;
-    ObjectFile *image_object_file = GetObjectFile();
-    if (image_object_file)
+    size_t num_loaded_sections = 0;
+    ObjectFile *objfile = GetObjectFile();
+    if (objfile)
     {
-        SectionList *section_list = image_object_file->GetSectionList ();
+        SectionList *section_list = objfile->GetSectionList ();
         if (section_list)
         {
             const size_t num_sections = section_list->GetSize();
@@ -1119,16 +1119,17 @@
                 // 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)
+                // Only load non-thread specific sections when given a slide
+                if (section && !section->IsThreadSpecific())
                 {
                     if (target.GetSectionLoadList().SetSectionLoadAddress (section, section->GetFileAddress() + offset))
-                        changed = true;
+                        ++num_loaded_sections;
                 }
             }
-            return sect_idx > 0;
         }
     }
-    return false;
+    changed = num_loaded_sections > 0;
+    return num_loaded_sections > 0;
 }
 
 

Modified: lldb/trunk/source/Core/Section.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Section.cpp?rev=153537&r1=153536&r2=153537&view=diff
==============================================================================
--- lldb/trunk/source/Core/Section.cpp (original)
+++ lldb/trunk/source/Core/Section.cpp Tue Mar 27 16:10:07 2012
@@ -36,6 +36,8 @@
     m_file_size     (file_size),
     m_children      (),
     m_fake          (false),
+    m_encrypted     (false),
+    m_thread_specific (false),
     m_linked_section_wp(),
     m_linked_offset (0)
 {
@@ -65,6 +67,8 @@
     m_file_size     (file_size),
     m_children      (),
     m_fake          (false),
+    m_encrypted     (false),
+    m_thread_specific (false),
     m_linked_section_wp(),
     m_linked_offset (0)
 {

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=153537&r1=153536&r2=153537&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Tue Mar 27 16:10:07 2012
@@ -621,6 +621,8 @@
             static ConstString g_sect_name_text (".text");
             static ConstString g_sect_name_data (".data");
             static ConstString g_sect_name_bss (".bss");
+            static ConstString g_sect_name_tdata (".tdata");
+            static ConstString g_sect_name_tbss (".tbss");
             static ConstString g_sect_name_dwarf_debug_abbrev (".debug_abbrev");
             static ConstString g_sect_name_dwarf_debug_aranges (".debug_aranges");
             static ConstString g_sect_name_dwarf_debug_frame (".debug_frame");
@@ -636,9 +638,21 @@
 
             SectionType sect_type = eSectionTypeOther;
 
+            bool is_thread_specific = false;
+            
             if      (name == g_sect_name_text)                  sect_type = eSectionTypeCode;
             else if (name == g_sect_name_data)                  sect_type = eSectionTypeData;
             else if (name == g_sect_name_bss)                   sect_type = eSectionTypeZeroFill;
+            else if (name == g_sect_name_tdata)
+            {
+                sect_type = eSectionTypeData;
+                is_thread_specific = true;   
+            }
+            else if (name == g_sect_name_tbss)
+            {
+                sect_type = eSectionTypeZeroFill;   
+                is_thread_specific = true;   
+            }
             else if (name == g_sect_name_dwarf_debug_abbrev)    sect_type = eSectionTypeDWARFDebugAbbrev;
             else if (name == g_sect_name_dwarf_debug_aranges)   sect_type = eSectionTypeDWARFDebugAranges;
             else if (name == g_sect_name_dwarf_debug_frame)     sect_type = eSectionTypeDWARFDebugFrame;
@@ -653,7 +667,7 @@
             else if (name == g_sect_name_eh_frame)              sect_type = eSectionTypeEHFrame;
             
             
-            SectionSP section(new Section(
+            SectionSP section_sp(new Section(
                 GetModule(),        // Module to which this section belongs.
                 SectionIndex(I),    // Section ID.
                 name,               // Section name.
@@ -664,7 +678,9 @@
                 file_size,          // Size of the section as found in the file.
                 header.sh_flags));  // Flags for this section.
 
-            m_sections_ap->AddSection(section);
+            if (is_thread_specific)
+                section_sp->SetIsThreadSpecific (is_thread_specific);
+            m_sections_ap->AddSection(section_sp);
         }
     }
 

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=153537&r1=153536&r2=153537&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Tue Mar 27 16:10:07 2012
@@ -1957,45 +1957,6 @@
     result.GetImmediateErrorStream()->Flush();
 }
 
-bool 
-Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
-{
-    bool changed = false;
-    if (module)
-    {
-        ObjectFile *object_file = module->GetObjectFile();
-        if (object_file)
-        {
-            SectionList *section_list = 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)
-                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)
-                    {
-                        if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
-                            changed = true;
-                    }
-                }
-            }
-        }
-    }
-    return changed;
-}
-
 
 //--------------------------------------------------------------
 // class Target::StopHook





More information about the lldb-commits mailing list