[Lldb-commits] [PATCH 2/8] Implement GetEntryPoint, GetImageInfoAddress and GetArchitecture for ObjectFileELF.

Stephen Wilson wilsons at start.ca
Fri Jan 14 13:12:16 PST 2011


---
 source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp |   78 ++++++++++++++++++++++-
 source/Plugins/ObjectFile/ELF/ObjectFileELF.h   |    9 +++
 2 files changed, 85 insertions(+), 2 deletions(-)

diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 3f6dd20..5b99d01 100644
--- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -12,6 +12,7 @@
 #include <cassert>
 #include <algorithm>
 
+#include "lldb/Core/ArchSpec.h"
 #include "lldb/Core/DataBuffer.h"
 #include "lldb/Core/Error.h"
 #include "lldb/Core/FileSpecList.h"
@@ -70,9 +71,10 @@ ObjectFileELF::CreateInstance(Module *module,
             unsigned address_size = ELFHeader::AddressSizeInBytes(magic);
             if (address_size == 4 || address_size == 8)
             {
-                std::auto_ptr<ObjectFile> objfile_ap(
+                std::auto_ptr<ObjectFileELF> objfile_ap(
                     new ObjectFileELF(module, data_sp, file, offset, length));
-                if (objfile_ap->ParseHeader())
+                ArchSpec spec = objfile_ap->GetArchitecture();
+                if (spec.IsValid() && objfile_ap->SetModulesArchitecture(spec))
                     return objfile_ap.release();
             }
         }
@@ -80,6 +82,15 @@ ObjectFileELF::CreateInstance(Module *module,
     return NULL;
 }
 
+ArchSpec
+ObjectFileELF::GetArchitecture()
+{
+    if (!ParseHeader())
+        return ArchSpec();
+
+    return ArchSpec(eArchTypeELF, m_header.e_machine, m_header.e_flags);
+}
+
 //------------------------------------------------------------------
 // PluginInterface protocol
 //------------------------------------------------------------------
@@ -151,6 +162,15 @@ ObjectFileELF::IsExecutable() const
     return m_header.e_type == ET_EXEC;
 }
 
+Address
+ObjectFileELF::GetEntryPoint() const
+{
+    if (m_header.e_entry)
+        return Address(NULL, m_header.e_entry);
+    else
+        return Address();
+}
+
 ByteOrder
 ObjectFileELF::GetByteOrder() const
 {
@@ -208,6 +228,60 @@ ObjectFileELF::GetDependentModules(FileSpecList &files)
     return num_specs;
 }
 
+Address
+ObjectFileELF::GetImageInfoAddress()
+{
+    if (!ParseSectionHeaders())
+        return Address();
+
+    user_id_t dynsym_id = 0;
+    for (SectionHeaderCollIter sh_pos = m_section_headers.begin();
+         sh_pos != m_section_headers.end(); ++sh_pos) 
+    {
+        if (sh_pos->sh_type == SHT_DYNAMIC)
+        {
+            dynsym_id = SectionIndex(sh_pos);
+            break;
+        }
+    }
+
+    if (!dynsym_id)
+        return Address();
+
+    SectionList *section_list = GetSectionList();
+    if (!section_list)
+        return Address();
+
+    // Resolve the dynamic table entries.
+    Section *dynsym = section_list->FindSectionByID(dynsym_id).get();
+    if (!dynsym)
+        return Address();
+
+    DataExtractor dynsym_data;
+    if (dynsym->ReadSectionDataFromObjectFile(this, dynsym_data))
+    {
+        ELFDynamic symbol;
+        const unsigned section_size = dynsym_data.GetByteSize();
+        unsigned offset = 0;
+        unsigned cursor = 0;
+
+        // Look for a DT_DEBUG entry.
+        while (cursor < section_size)
+        {
+            offset = cursor;
+            if (!symbol.Parse(dynsym_data, &cursor))
+                break;
+
+            if (symbol.d_tag != DT_DEBUG)
+                continue;
+
+            return Address(dynsym, offset + sizeof(symbol.d_tag));
+        }
+    }
+
+    return Address();
+}
+
 //----------------------------------------------------------------------
 // ParseDependentModules
 //----------------------------------------------------------------------
diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index e91fabb..69a9a68 100644
--- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -89,6 +89,9 @@ public:
     virtual bool
     IsExecutable () const;
 
+    virtual lldb_private::Address
+    GetEntryPoint() const;
+
     virtual size_t
     GetAddressByteSize() const;
 
@@ -110,6 +113,12 @@ public:
     virtual uint32_t
     GetDependentModules(lldb_private::FileSpecList& files);
 
+    virtual lldb_private::Address
+    GetImageInfoAddress();
+
+    lldb_private::ArchSpec 
+    GetArchitecture();
+
 private:
     ObjectFileELF(lldb_private::Module* module,
                   lldb::DataBufferSP& dataSP,
-- 
1.7.3.5




More information about the lldb-commits mailing list