summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2014-06-24 22:22:43 +0000
committerGreg Clayton <gclayton@apple.com>2014-06-24 22:22:43 +0000
commit48672afb662f4b23e1934debdb84ad9a20dd9ced (patch)
tree97771c2bbe2d8ef118c19cf9cc36b56aa8c10502 /lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
parent257d48d22cadb5677b1be4a756b5bc74f286139b (diff)
downloadbcm5719-llvm-48672afb662f4b23e1934debdb84ad9a20dd9ced.tar.gz
bcm5719-llvm-48672afb662f4b23e1934debdb84ad9a20dd9ced.zip
Patch from Keno Fischer to enable JITLoaderGDB with mach-o file support.
The patch is as is with the functionality left disabled for apple vendors because of performance regressions. If this is enabled it ends up searching for symbols in all shared libraries that are loadeded. llvm-svn: 211638
Diffstat (limited to 'lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp')
-rw-r--r--lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp84
1 files changed, 76 insertions, 8 deletions
diff --git a/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp b/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
index d95271ec14d..905984d3341 100644
--- a/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
+++ b/lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
@@ -102,13 +102,15 @@ JITLoaderGDB::SetJITBreakpoint(lldb_private::ModuleList &module_list)
log->Printf("JITLoaderGDB::%s looking for JIT register hook",
__FUNCTION__);
- addr_t jit_addr = GetSymbolAddress(
- module_list, ConstString("__jit_debug_register_code"), eSymbolTypeAny);
+ addr_t jit_addr = GetSymbolAddress(module_list,
+ ConstString("__jit_debug_register_code"),
+ eSymbolTypeAny);
if (jit_addr == LLDB_INVALID_ADDRESS)
return;
- m_jit_descriptor_addr = GetSymbolAddress(
- module_list, ConstString("__jit_debug_descriptor"), eSymbolTypeData);
+ m_jit_descriptor_addr = GetSymbolAddress(module_list,
+ ConstString("__jit_debug_descriptor"),
+ eSymbolTypeData);
if (m_jit_descriptor_addr == LLDB_INVALID_ADDRESS)
{
if (log)
@@ -144,6 +146,55 @@ JITLoaderGDB::JITDebugBreakpointHit(void *baton,
return instance->ReadJITDescriptor(false);
}
+static void updateSectionLoadAddress(const SectionList &section_list,
+ Target &target,
+ uint64_t symbolfile_addr,
+ uint64_t symbolfile_size,
+ uint64_t &vmaddrheuristic,
+ uint64_t &min_addr,
+ uint64_t &max_addr)
+{
+ const uint32_t num_sections = section_list.GetSize();
+ for (uint32_t i = 0; i<num_sections; ++i)
+ {
+ SectionSP section_sp(section_list.GetSectionAtIndex(i));
+ if (section_sp)
+ {
+ if(section_sp->IsFake()) {
+ uint64_t lower = (uint64_t)-1;
+ uint64_t upper = 0;
+ updateSectionLoadAddress(section_sp->GetChildren(), target, symbolfile_addr, symbolfile_size, vmaddrheuristic,
+ lower, upper);
+ if (lower < min_addr)
+ min_addr = lower;
+ if (upper > max_addr)
+ max_addr = upper;
+ const lldb::addr_t slide_amount = lower - section_sp->GetFileAddress();
+ section_sp->Slide(slide_amount, false);
+ section_sp->GetChildren().Slide(-slide_amount, false);
+ section_sp->SetByteSize (upper - lower);
+ } else {
+ vmaddrheuristic += 2<<section_sp->GetLog2Align();
+ uint64_t lower;
+ if (section_sp->GetFileAddress() > vmaddrheuristic)
+ lower = section_sp->GetFileAddress();
+ else {
+ lower = symbolfile_addr+section_sp->GetFileOffset();
+ section_sp->SetFileAddress(symbolfile_addr+section_sp->GetFileOffset());
+ }
+ target.SetSectionLoadAddress(section_sp, lower, true);
+ uint64_t upper = lower + section_sp->GetByteSize();
+ if (lower < min_addr)
+ min_addr = lower;
+ if (upper > max_addr)
+ max_addr = upper;
+ // This is an upper bound, but a good enough heuristic
+ vmaddrheuristic += section_sp->GetByteSize();
+ }
+ }
+ }
+}
+
bool
JITLoaderGDB::ReadJITDescriptor(bool all_entries)
{
@@ -209,10 +260,27 @@ JITLoaderGDB::ReadJITDescriptor(bool all_entries)
if (module_sp && module_sp->GetObjectFile())
{
bool changed;
- m_jit_objects.insert(
- std::pair<lldb::addr_t, const lldb::ModuleSP>(
- symbolfile_addr, module_sp));
- module_sp->SetLoadAddress(target, 0, true, changed);
+ m_jit_objects.insert(std::make_pair(symbolfile_addr, module_sp));
+ if (module_sp->GetObjectFile()->GetPluginName() == ConstString("mach-o"))
+ {
+ ObjectFile *image_object_file = module_sp->GetObjectFile();
+ if (image_object_file)
+ {
+ const SectionList *section_list = image_object_file->GetSectionList ();
+ if (section_list)
+ {
+ uint64_t vmaddrheuristic = 0;
+ uint64_t lower = (uint64_t)-1;
+ uint64_t upper = 0;
+ updateSectionLoadAddress(*section_list, target, symbolfile_addr, symbolfile_size,
+ vmaddrheuristic, lower, upper);
+ }
+ }
+ }
+ else
+ {
+ module_sp->SetLoadAddress(target, 0, true, changed);
+ }
// load the symbol table right away
module_sp->GetObjectFile()->GetSymtab();
OpenPOWER on IntegriCloud