diff options
author | Jason Molenda <jmolenda@apple.com> | 2019-07-17 21:44:05 +0000 |
---|---|---|
committer | Jason Molenda <jmolenda@apple.com> | 2019-07-17 21:44:05 +0000 |
commit | be4be6120f10f557d32de5e33ff8233e17fe61de (patch) | |
tree | fa53fd9bbddc575ae6d03bf25bd1d6ddd03e609d /lldb/source/Plugins | |
parent | d0ac007f9a93d577f3e829812444bdae8b26269d (diff) | |
download | bcm5719-llvm-be4be6120f10f557d32de5e33ff8233e17fe61de.tar.gz bcm5719-llvm-be4be6120f10f557d32de5e33ff8233e17fe61de.zip |
Add support to ProcessMachCore::DoLoadCore to handle an EFI UUID str.
If a core file has an EFI version string which includes a UUID
(similar to what it returns for the kdp KDP_KERNELVERSION packet)
in the LC_IDENT or LC_NOTE 'kern ver str' load command. In that
case, we should try to find the binary and dSYM for the UUID
listed. The dSYM may have python code which knows how to relocate
the binary to the correct address in lldb's target section load
list and loads other ancillary binaries.
The test case is a little involved,
1. it compiles an inferior hello world apple (a.out),
2. it compiles a program which can create a corefile manually
with a specific binary's UUID encoded in it,
3. it gets the UUID of the a.out binary,
4. it creates a shell script, dsym-for-uuid.sh, which will
return the full path to the a.out + a.out.dSYM when called
with teh correct UUID,
5. it sets the LLDB_APPLE_DSYMFORUUID_EXECUTABLE env var before
creating the lldb target, to point to this dsym-for-uuid.sh,
6. runs the create-corefile binary we compiled in step #2,
7. loads the corefile from step #6 into lldb,
8. verifies that lldb loaded a.out by reading the LC_NOTE
load command from the corefile, calling dsym-for-uuid.sh with
that UUID, got back the path to a.out and loaded it.
whew!
<rdar://problem/47562911>
llvm-svn: 366378
Diffstat (limited to 'lldb/source/Plugins')
-rw-r--r-- | lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp index cdb7aa00624..11b9e4588a8 100644 --- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp +++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp @@ -19,6 +19,7 @@ #include "lldb/Core/PluginManager.h" #include "lldb/Core/Section.h" #include "lldb/Host/Host.h" +#include "lldb/Symbol/LocateSymbolFile.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/MemoryRegionInfo.h" #include "lldb/Target/Target.h" @@ -323,6 +324,60 @@ Status ProcessMachCore::DoLoadCore() { addr, corefile_identifier.c_str()); } } + if (found_main_binary_definitively == false + && corefile_identifier.find("EFI ") != std::string::npos) { + UUID uuid; + if (corefile_identifier.find("UUID=") != std::string::npos) { + size_t p = corefile_identifier.find("UUID=") + strlen("UUID="); + std::string uuid_str = corefile_identifier.substr(p, 36); + uuid.SetFromStringRef(uuid_str); + } + if (uuid.IsValid()) { + if (log) + log->Printf("ProcessMachCore::DoLoadCore: Using the EFI " + "from LC_IDENT/LC_NOTE 'kern ver str' string: '%s'", + corefile_identifier.c_str()); + + // We're only given a UUID here, not a load address. + // But there are python scripts in the EFI binary's dSYM which + // know how to relocate the binary to the correct load address. + // lldb only needs to locate & load the binary + dSYM. + ModuleSpec module_spec; + module_spec.GetUUID() = uuid; + module_spec.GetArchitecture() = GetTarget().GetArchitecture(); + + // Lookup UUID locally, before attempting dsymForUUID like action + FileSpecList search_paths = + Target::GetDefaultDebugFileSearchPaths(); + module_spec.GetSymbolFileSpec() = + Symbols::LocateExecutableSymbolFile(module_spec, search_paths); + if (module_spec.GetSymbolFileSpec()) { + ModuleSpec executable_module_spec = + Symbols::LocateExecutableObjectFile(module_spec); + if (FileSystem::Instance().Exists(executable_module_spec.GetFileSpec())) { + module_spec.GetFileSpec() = + executable_module_spec.GetFileSpec(); + } + } + + // Force a a dsymForUUID lookup, if that tool is available. + if (!module_spec.GetSymbolFileSpec()) + Symbols::DownloadObjectAndSymbolFile(module_spec, true); + + if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) { + ModuleSP module_sp(new Module(module_spec)); + if (module_sp.get() && module_sp->GetObjectFile()) { + // Get the current target executable + ModuleSP exe_module_sp(GetTarget().GetExecutableModule()); + + // Make sure you don't already have the right module loaded + // and they will be uniqued + if (exe_module_sp.get() != module_sp.get()) + GetTarget().SetExecutableModule(module_sp, eLoadDependentsNo); + } + } + } + } if (!found_main_binary_definitively && (m_dyld_addr == LLDB_INVALID_ADDRESS || |