[Lldb-commits] [lldb] r200943 - Implement ObjectFileMachO::SetLoadAddress().
Greg Clayton
gclayton at apple.com
Thu Feb 6 12:10:16 PST 2014
Author: gclayton
Date: Thu Feb 6 14:10:16 2014
New Revision: 200943
URL: http://llvm.org/viewvc/llvm-project?rev=200943&view=rev
Log:
Implement ObjectFileMachO::SetLoadAddress().
Modified:
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=200943&r1=200942&r2=200943&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Thu Feb 6 14:10:16 2014
@@ -1505,7 +1505,12 @@ Module::SetLoadAddress (Target &target,
ObjectFile *object_file = GetObjectFile();
if (object_file)
{
- return object_file->SetLoadAddress(target, offset);
+ changed = object_file->SetLoadAddress(target, offset);
+ return true;
+ }
+ else
+ {
+ changed = false;
}
return false;
}
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=200943&r1=200942&r2=200943&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Thu Feb 6 14:10:16 2014
@@ -34,6 +34,7 @@
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
+#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "Plugins/Process/Utility/RegisterContextDarwin_arm.h"
#include "Plugins/Process/Utility/RegisterContextDarwin_i386.h"
@@ -4703,3 +4704,58 @@ ObjectFileMachO::GetPluginVersion()
return 1;
}
+
+bool
+ObjectFileMachO::SetLoadAddress(Target &target, addr_t base_addr)
+{
+ bool changed = false;
+ ModuleSP module_sp = GetModule();
+ if (module_sp)
+ {
+ size_t num_loaded_sections = 0;
+ SectionList *section_list = GetSectionList ();
+ if (section_list)
+ {
+ lldb::addr_t mach_base_file_addr = LLDB_INVALID_ADDRESS;
+ const size_t num_sections = section_list->GetSize();
+
+ // First find the address of the mach header which is the first non-zero
+ // file sized section whose file offset is zero as this will be subtracted
+ // from each other valid section's vmaddr and then get "base_addr" added to
+ // it when loading the module in the target
+ for (size_t sect_idx = 0;
+ sect_idx < num_sections && mach_base_file_addr == LLDB_INVALID_ADDRESS;
+ ++sect_idx)
+ {
+ // Iterate through the object file sections to find all
+ // of the sections that size on disk (to avoid __PAGEZERO)
+ // and load them
+ Section *section = section_list->GetSectionAtIndex (sect_idx).get();
+ if (section && section->GetFileSize() > 0 && section->GetFileOffset() == 0)
+ {
+ mach_base_file_addr = section->GetFileAddress();
+ }
+ }
+
+ if (mach_base_file_addr != LLDB_INVALID_ADDRESS)
+ {
+ for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
+ {
+ // Iterate through the object file sections to find all
+ // of the sections that size on disk (to avoid __PAGEZERO)
+ // and load them
+ SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
+ if (section_sp && section_sp->GetFileSize() > 0 && !section_sp->IsThreadSpecific())
+ {
+ if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() - mach_base_file_addr + base_addr))
+ ++num_loaded_sections;
+ }
+ }
+ }
+ }
+ changed = num_loaded_sections > 0;
+ return num_loaded_sections > 0;
+ }
+ return changed;
+}
+
Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h?rev=200943&r1=200942&r2=200943&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h Thu Feb 6 14:10:16 2014
@@ -89,6 +89,9 @@ public:
virtual bool
ParseHeader ();
+ virtual bool
+ SetLoadAddress(lldb_private::Target &target, lldb::addr_t base_addr);
+
virtual lldb::ByteOrder
GetByteOrder () const;
More information about the lldb-commits
mailing list