summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2017-04-06 01:50:11 +0000
committerJason Molenda <jmolenda@apple.com>2017-04-06 01:50:11 +0000
commit3533cec58b93ed9cb6d6df9a7ab0213f33be0371 (patch)
treeea4b17d17388c8371c4ba2e0c2e3fd15477b29aa /lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
parent0b2331b5e7c248eed402b18e03e1383ebac11f57 (diff)
downloadbcm5719-llvm-3533cec58b93ed9cb6d6df9a7ab0213f33be0371.tar.gz
bcm5719-llvm-3533cec58b93ed9cb6d6df9a7ab0213f33be0371.zip
Some old mach-o core files have an LC_IDENT load command
and there's a string in there that can be helpful in locating the kernel binary. Use it. <rdar://problem/31444711> llvm-svn: 299612
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp')
-rw-r--r--lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 4084e57938c..1bcffaafa90 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5353,6 +5353,37 @@ uint32_t ObjectFileMachO::GetNumThreadContexts() {
return m_thread_context_offsets.GetSize();
}
+// The LC_IDENT load command has been obsoleted for a very
+// long time and it should not occur in Mach-O files. But
+// if it is there, it may contain a hint about where to find
+// the main binary in a core file, so we'll use it.
+std::string ObjectFileMachO::GetIdentifierString() {
+ std::string result;
+ ModuleSP module_sp(GetModule());
+ if (module_sp) {
+ std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+ lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+ for (uint32_t i = 0; i < m_header.ncmds; ++i) {
+ const uint32_t cmd_offset = offset;
+ struct ident_command ident_command;
+ if (m_data.GetU32(&offset, &ident_command, 2) == NULL)
+ break;
+ if (ident_command.cmd == LC_IDENT && ident_command.cmdsize != 0) {
+ char *buf = (char *)malloc (ident_command.cmdsize);
+ if (buf != nullptr
+ && m_data.CopyData (offset, ident_command.cmdsize, buf) == ident_command.cmdsize) {
+ buf[ident_command.cmdsize - 1] = '\0';
+ result = buf;
+ }
+ if (buf)
+ free (buf);
+ }
+ offset = cmd_offset + ident_command.cmdsize;
+ }
+ }
+ return result;
+}
+
lldb::RegisterContextSP
ObjectFileMachO::GetThreadContextAtIndex(uint32_t idx,
lldb_private::Thread &thread) {
OpenPOWER on IntegriCloud