Skip to content

When ProcessMachCore has metadata for a binary, don't scan #7203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,20 @@ void ProcessMachCore::CreateMemoryRegions() {
}
}

void ProcessMachCore::LoadBinariesViaMetadata() {
bool ProcessMachCore::LoadBinariesViaMetadata() {
Log *log(GetLog(LLDBLog::DynamicLoader | LLDBLog::Process));
ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
bool found_main_binary_definitively = false;

addr_t objfile_binary_value;
bool objfile_binary_value_is_offset;
UUID objfile_binary_uuid;
ObjectFile::BinaryType type;

// This will be set to true if we had a metadata hint
// specifying a UUID or address -- and we should not fall back
// to doing an exhaustive search.
bool found_binary_spec_in_metadata = false;

if (core_objfile->GetCorefileMainBinaryInfo(objfile_binary_value,
objfile_binary_value_is_offset,
objfile_binary_uuid, type)) {
Expand All @@ -244,14 +248,14 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
objfile_binary_uuid.GetAsString().c_str(),
objfile_binary_value, objfile_binary_value_is_offset, type);
}
found_binary_spec_in_metadata = true;

// If this is the xnu kernel, don't load it now. Note the correct
// DynamicLoader plugin to use, and the address of the kernel, and
// let the DynamicLoader handle the finding & loading of the binary.
if (type == ObjectFile::eBinaryTypeKernel) {
m_mach_kernel_addr = objfile_binary_value;
m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic();
found_main_binary_definitively = true;
} else if (type == ObjectFile::eBinaryTypeUser) {
m_dyld_addr = objfile_binary_value;
m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic();
Expand All @@ -265,7 +269,6 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
objfile_binary_value, objfile_binary_value_is_offset,
force_symbol_search, notify, set_address_in_target,
allow_memory_image_last_resort)) {
found_main_binary_definitively = true;
m_dyld_plugin_name = DynamicLoaderStatic::GetPluginNameStatic();
}
}
Expand All @@ -276,7 +279,6 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
// load command is present, let's use the contents.
UUID ident_uuid;
addr_t ident_binary_addr = LLDB_INVALID_ADDRESS;
if (!found_main_binary_definitively) {
std::string corefile_identifier = core_objfile->GetIdentifierString();

// Search for UUID= and stext= strings in the identifier str.
Expand All @@ -287,6 +289,7 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
if (log)
log->Printf("Got a UUID from LC_IDENT/kern ver str LC_NOTE: %s",
ident_uuid.GetAsString().c_str());
found_binary_spec_in_metadata = true;
}
if (corefile_identifier.find("stext=") != std::string::npos) {
size_t p = corefile_identifier.find("stext=") + strlen("stext=");
Expand All @@ -297,6 +300,7 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
log->Printf("Got a load address from LC_IDENT/kern ver str "
"LC_NOTE: 0x%" PRIx64,
ident_binary_addr);
found_binary_spec_in_metadata = true;
}
}

Expand All @@ -309,7 +313,7 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
"ProcessMachCore::LoadBinariesViaMetadata: Found kernel binary via "
"LC_IDENT/kern ver str LC_NOTE");
m_mach_kernel_addr = ident_binary_addr;
found_main_binary_definitively = true;
found_binary_spec_in_metadata = true;
} else if (ident_uuid.IsValid()) {
// We have no address specified, only a UUID. Load it at the file
// address.
Expand All @@ -322,16 +326,15 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
this, llvm::StringRef(), ident_uuid, ident_binary_addr,
value_is_offset, force_symbol_search, notify,
set_address_in_target, allow_memory_image_last_resort)) {
found_main_binary_definitively = true;
found_binary_spec_in_metadata = true;
m_dyld_plugin_name = DynamicLoaderStatic::GetPluginNameStatic();
}
}
}

// Finally, load any binaries noted by "load binary" LC_NOTEs in the
// corefile
if (core_objfile->LoadCoreFileImages(*this)) {
found_main_binary_definitively = true;
found_binary_spec_in_metadata = true;
m_dyld_plugin_name = DynamicLoaderStatic::GetPluginNameStatic();
}

Expand All @@ -341,6 +344,8 @@ void ProcessMachCore::LoadBinariesViaMetadata() {
// un-set it later.
if (m_dyld_up)
m_dyld_plugin_name = GetDynamicLoader()->GetPluginName();

return found_binary_spec_in_metadata;
}

void ProcessMachCore::LoadBinariesViaExhaustiveSearch() {
Expand Down Expand Up @@ -417,8 +422,8 @@ void ProcessMachCore::LoadBinariesViaExhaustiveSearch() {
void ProcessMachCore::LoadBinariesAndSetDYLD() {
Log *log(GetLog(LLDBLog::DynamicLoader | LLDBLog::Process));

LoadBinariesViaMetadata();
if (m_dyld_plugin_name.empty())
bool found_binary_spec_in_metadata = LoadBinariesViaMetadata();
if (!found_binary_spec_in_metadata)
LoadBinariesViaExhaustiveSearch();

if (m_dyld_plugin_name.empty()) {
Expand Down
8 changes: 7 additions & 1 deletion lldb/source/Plugins/Process/mach-core/ProcessMachCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ class ProcessMachCore : public lldb_private::PostMortemProcess {

private:
void CreateMemoryRegions();
void LoadBinariesViaMetadata();

/// \return
/// True if any metadata were found indicating the binary that should
/// be loaded, regardless of whether the specified binary could be found.
/// False if no metadata were present.
bool LoadBinariesViaMetadata();

void LoadBinariesViaExhaustiveSearch();
void LoadBinariesAndSetDYLD();
void CleanupMemoryRegionPermissions();
Expand Down