[Lldb-commits] [lldb] r203350 - Implement ObjectFilePECOFF::SetLoadAddress().
Virgile Bello
virgile.bello at gmail.com
Sat Mar 8 09:17:20 PST 2014
Author: xen2
Date: Sat Mar 8 11:17:20 2014
New Revision: 203350
URL: http://llvm.org/viewvc/llvm-project?rev=203350&view=rev
Log:
Implement ObjectFilePECOFF::SetLoadAddress().
Modified:
lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp?rev=203350&r1=203349&r2=203350&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp Sat Mar 8 11:17:20 2014
@@ -24,6 +24,8 @@
#include "lldb/Core/Timer.h"
#include "lldb/Core/UUID.h"
#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/SectionLoadList.h"
+#include "lldb/Target/Target.h"
#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
@@ -173,6 +175,43 @@ ObjectFilePECOFF::ParseHeader ()
return false;
}
+bool
+ObjectFilePECOFF::SetLoadAddress(Target &target, addr_t value, bool value_is_offset)
+{
+ bool changed = false;
+ ModuleSP module_sp = GetModule();
+ if (module_sp)
+ {
+ size_t num_loaded_sections = 0;
+ SectionList *section_list = GetSectionList ();
+ if (section_list)
+ {
+ if (!value_is_offset)
+ {
+ value -= m_image_base;
+ }
+
+ 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 all
+ // of the sections that have SHF_ALLOC in their flag bits.
+ SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
+ if (section_sp && !section_sp->IsThreadSpecific())
+ {
+ if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + value))
+ ++num_loaded_sections;
+ }
+ }
+ changed = num_loaded_sections > 0;
+ return num_loaded_sections > 0;
+ }
+ }
+ return changed;
+}
+
ByteOrder
ObjectFilePECOFF::GetByteOrder () const
@@ -351,6 +390,9 @@ ObjectFilePECOFF::ParseCOFFOptionalHeade
m_coff_header_opt.data_dirs[i].vmaddr = m_data.GetU32(offset_ptr);
m_coff_header_opt.data_dirs[i].vmsize = m_data.GetU32(offset_ptr);
}
+
+ m_file_offset = m_coff_header_opt.image_base;
+ m_image_base = m_coff_header_opt.image_base;
}
}
}
Modified: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h?rev=203350&r1=203349&r2=203350&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h Sat Mar 8 11:17:20 2014
@@ -73,6 +73,9 @@ public:
virtual bool
ParseHeader ();
+ virtual bool
+ SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, bool value_is_offset);
+
virtual lldb::ByteOrder
GetByteOrder () const;
@@ -262,6 +265,7 @@ private:
coff_header_t m_coff_header;
coff_opt_header_t m_coff_header_opt;
SectionHeaderColl m_sect_headers;
+ lldb::addr_t m_image_base;
};
#endif // #ifndef liblldb_ObjectFilePECOFF_h_
More information about the lldb-commits
mailing list