[Lldb-commits] [lldb] r201003 - Modified ObjectFile::SetLoadAddress() to now be:
Greg Clayton
gclayton at apple.com
Fri Feb 7 14:54:47 PST 2014
Author: gclayton
Date: Fri Feb 7 16:54:47 2014
New Revision: 201003
URL: http://llvm.org/viewvc/llvm-project?rev=201003&view=rev
Log:
Modified ObjectFile::SetLoadAddress() to now be:
ObjectFile::SetLoadAddress (Target &target,
lldb::addr_t value,
bool value_is_offset);
Now "value" is a slide if "value_is_offset" is true, and "value" is an image base address otherwise. All previous usage of this API was using slides.
Updated the ObjectFileELF and ObjectFileMachO SetLoadAddress methods to do the right thing.
Also updated the ObjectFileMachO::SetLoadAddress() function to not load __LINKEDIT when it isn't needed and to only load sections that belong to the executable object file.
Modified:
lldb/trunk/include/lldb/Core/Module.h
lldb/trunk/include/lldb/Symbol/ObjectFile.h
lldb/trunk/source/API/SBModule.cpp
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/source/Commands/CommandObjectTarget.cpp
lldb/trunk/source/Core/DynamicLoader.cpp
lldb/trunk/source/Core/Module.cpp
lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Fri Feb 7 16:54:47 2014
@@ -113,10 +113,18 @@ public:
/// @param[in] target
/// The target in which to apply the section load addresses.
///
- /// @param[in] offset
- /// The offset to apply to all file addresses for all top
- /// level sections in the object file as each section load
- /// address is being set.
+ /// @param[in] value
+ /// if \a value_is_offset is true, then value is the offset to
+ /// apply to all file addresses for all top level sections in
+ /// the object file as each section load address is being set.
+ /// If \a value_is_offset is false, then "value" is the new
+ /// absolute base address for the image.
+ ///
+ /// @param[in] value_is_offset
+ /// If \b true, then \a value is an offset to apply to each
+ /// file address of each top level section.
+ /// If \b false, then \a value is the image base address that
+ /// will be used to rigidly slide all loadable sections.
///
/// @param[out] changed
/// If any section load addresses were changed in \a target,
@@ -133,7 +141,8 @@ public:
//------------------------------------------------------------------
bool
SetLoadAddress (Target &target,
- lldb::addr_t offset,
+ lldb::addr_t value,
+ bool value_is_offset,
bool &changed);
//------------------------------------------------------------------
Modified: lldb/trunk/include/lldb/Symbol/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ObjectFile.h?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ObjectFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/ObjectFile.h Fri Feb 7 16:54:47 2014
@@ -458,7 +458,9 @@ public:
/// Returns true iff any section's load address changed.
//------------------------------------------------------------------
virtual bool
- SetLoadAddress(Target &target, lldb::addr_t base_addr)
+ SetLoadAddress(Target &target,
+ lldb::addr_t value,
+ bool value_is_offset)
{
return false;
}
Modified: lldb/trunk/source/API/SBModule.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBModule.cpp?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/API/SBModule.cpp (original)
+++ lldb/trunk/source/API/SBModule.cpp Fri Feb 7 16:54:47 2014
@@ -69,7 +69,7 @@ SBModule::SBModule (lldb::SBProcess &pro
{
Target &target = process_sp->GetTarget();
bool changed = false;
- m_opaque_sp->SetLoadAddress(target, 0, changed);
+ m_opaque_sp->SetLoadAddress(target, 0, true, changed);
target.GetImages().Append(m_opaque_sp);
}
}
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Fri Feb 7 16:54:47 2014
@@ -2499,7 +2499,7 @@ SBTarget::SetModuleLoadAddress (lldb::SB
if (module_sp)
{
bool changed = false;
- if (module_sp->SetLoadAddress (*target_sp, slide_offset, changed))
+ if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed))
{
// The load was successful, make sure that at least some sections
// changed before we notify that our module was loaded.
Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri Feb 7 16:54:47 2014
@@ -2894,7 +2894,8 @@ protected:
if (m_slide_option.GetOptionValue().OptionWasSet())
{
const addr_t slide = m_slide_option.GetOptionValue().GetCurrentValue();
- module->SetLoadAddress (*target, slide, changed);
+ const bool slide_is_offset = true;
+ module->SetLoadAddress (*target, slide, slide_is_offset, changed);
}
else
{
Modified: lldb/trunk/source/Core/DynamicLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DynamicLoader.cpp?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/Core/DynamicLoader.cpp (original)
+++ lldb/trunk/source/Core/DynamicLoader.cpp Fri Feb 7 16:54:47 2014
@@ -128,7 +128,8 @@ void
DynamicLoader::UpdateLoadedSectionsCommon(ModuleSP module, addr_t base_addr)
{
bool changed;
- module->SetLoadAddress(m_process->GetTarget(), base_addr, changed);
+ const bool base_addr_is_offset = true;
+ module->SetLoadAddress(m_process->GetTarget(), base_addr, base_addr_is_offset, changed);
}
void
Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Fri Feb 7 16:54:47 2014
@@ -1500,12 +1500,12 @@ Module::SetArchitecture (const ArchSpec
}
bool
-Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed)
+Module::SetLoadAddress (Target &target, lldb::addr_t value, bool value_is_offset, bool &changed)
{
ObjectFile *object_file = GetObjectFile();
if (object_file)
{
- changed = object_file->SetLoadAddress(target, offset);
+ changed = object_file->SetLoadAddress(target, value, value_is_offset);
return true;
}
else
Modified: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp Fri Feb 7 16:54:47 2014
@@ -542,7 +542,7 @@ DynamicLoaderDarwinKernel::KextImageInfo
if (m_module_sp)
{
bool changed = false;
- if (m_module_sp->SetLoadAddress (process->GetTarget(), 0, changed))
+ if (m_module_sp->SetLoadAddress (process->GetTarget(), 0, true, changed))
m_load_process_stop_id = process->GetStopID();
}
return false;
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=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Fri Feb 7 16:54:47 2014
@@ -464,7 +464,9 @@ ObjectFileELF::IsExecutable() const
}
bool
-ObjectFileELF::SetLoadAddress(Target &target, addr_t base_addr)
+ObjectFileELF::SetLoadAddress (Target &target,
+ lldb::addr_t value,
+ bool value_is_offset)
{
bool changed = false;
ModuleSP module_sp = GetModule();
@@ -474,23 +476,32 @@ ObjectFileELF::SetLoadAddress(Target &ta
SectionList *section_list = GetSectionList ();
if (section_list)
{
- const size_t num_sections = section_list->GetSize();
- size_t sect_idx = 0;
- for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
+ if (value_is_offset)
{
- // 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 (section_sp && section_sp->Test(SHF_ALLOC))
+ const size_t num_sections = section_list->GetSize();
+ size_t sect_idx = 0;
+
+ for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
{
- if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + base_addr))
- ++num_loaded_sections;
+ // 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 (section_sp && section_sp->Test(SHF_ALLOC))
+ {
+ if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + value))
+ ++num_loaded_sections;
+ }
}
+ changed = num_loaded_sections > 0;
+ return num_loaded_sections > 0;
+ }
+ else
+ {
+ // Not sure how to slide an ELF file given the base address
+ // of the ELF file in memory
}
}
- changed = num_loaded_sections > 0;
- return num_loaded_sections > 0;
}
return changed;
}
Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h?rev=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.h Fri Feb 7 16:54:47 2014
@@ -119,7 +119,9 @@ public:
ParseHeader();
virtual bool
- SetLoadAddress(lldb_private::Target &target, lldb::addr_t base_addr);
+ SetLoadAddress (lldb_private::Target &target,
+ lldb::addr_t value,
+ bool value_is_offset);
virtual lldb::ByteOrder
GetByteOrder() const;
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=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Fri Feb 7 16:54:47 2014
@@ -4706,7 +4706,9 @@ ObjectFileMachO::GetPluginVersion()
bool
-ObjectFileMachO::SetLoadAddress(Target &target, addr_t base_addr)
+ObjectFileMachO::SetLoadAddress (Target &target,
+ lldb::addr_t value,
+ bool value_is_offset)
{
bool changed = false;
ModuleSP module_sp = GetModule();
@@ -4719,36 +4721,95 @@ ObjectFileMachO::SetLoadAddress(Target &
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)
+ const bool is_memory_image = (bool)m_process_wp.lock();
+ const Strata strata = GetStrata();
+ static ConstString g_linkedit_segname ("__LINKEDIT");
+ if (value_is_offset)
{
- // 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)
+ // "value" is an offset to apply to each top level segment
+ for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
{
- mach_base_file_addr = section->GetFileAddress();
+ // 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() == false &&
+ module_sp.get() == section_sp->GetModule().get())
+ {
+ // Ignore __LINKEDIT and __DWARF segments
+ if (section_sp->GetName() == g_linkedit_segname)
+ {
+ // Only map __LINKEDIT if we have an in memory image and this isn't
+ // a kernel binary like a kext or mach_kernel.
+ if (is_memory_image == false || strata == eStrataKernel)
+ continue;
+ }
+ if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() + value))
+ ++num_loaded_sections;
+ }
}
}
-
- if (mach_base_file_addr != LLDB_INVALID_ADDRESS)
+ else
{
- for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
+ // "value" is the new base address of the mach_header, adjust each
+ // section accordingly
+
+ // 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
- SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
- if (section_sp && section_sp->GetFileSize() > 0 && !section_sp->IsThreadSpecific())
+ Section *section = section_list->GetSectionAtIndex (sect_idx).get();
+ if (section &&
+ section->GetFileSize() > 0 &&
+ section->GetFileOffset() == 0 &&
+ section->IsThreadSpecific() == false &&
+ module_sp.get() == section->GetModule().get())
{
- if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() - mach_base_file_addr + base_addr))
- ++num_loaded_sections;
+ // Ignore __LINKEDIT and __DWARF segments
+ if (section->GetName() == g_linkedit_segname)
+ {
+ // Only map __LINKEDIT if we have an in memory image and this isn't
+ // a kernel binary like a kext or mach_kernel.
+ if (is_memory_image == false || strata == eStrataKernel)
+ continue;
+ }
+ 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() == false &&
+ module_sp.get() == section_sp->GetModule().get())
+ {
+ // Ignore __LINKEDIT and __DWARF segments
+ if (section_sp->GetName() == g_linkedit_segname)
+ {
+ // Only map __LINKEDIT if we have an in memory image and this isn't
+ // a kernel binary like a kext or mach_kernel.
+ if (is_memory_image == false || strata == eStrataKernel)
+ continue;
+ }
+ if (target.GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress() - mach_base_file_addr + value))
+ ++num_loaded_sections;
+ }
}
}
}
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=201003&r1=201002&r2=201003&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h Fri Feb 7 16:54:47 2014
@@ -90,7 +90,9 @@ public:
ParseHeader ();
virtual bool
- SetLoadAddress(lldb_private::Target &target, lldb::addr_t base_addr);
+ SetLoadAddress(lldb_private::Target &target,
+ lldb::addr_t value,
+ bool value_is_offset);
virtual lldb::ByteOrder
GetByteOrder () const;
More information about the lldb-commits
mailing list