Skip to content

Show error messages from DebugSymbols DBGShellCommand agent #7204

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
40 changes: 30 additions & 10 deletions lldb/source/Core/DynamicLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "lldb/Target/DynamicLoader.h"

#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
Expand Down Expand Up @@ -235,6 +236,9 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
force_symbol_search);
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
module_sp = std::make_shared<Module>(module_spec);
} else if (force_symbol_search && error.AsCString("") &&
error.AsCString("")[0] != '\0') {
target.GetDebugger().GetErrorStream() << error.AsCString();
}
}

Expand Down Expand Up @@ -267,26 +271,26 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
if (value != LLDB_INVALID_ADDRESS) {
LLDB_LOGF(log,
"DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
"binary UUID %s at %s 0x%" PRIx64,
uuid.GetAsString().c_str(),
"binary %s UUID %s at %s 0x%" PRIx64,
name.str().c_str(), uuid.GetAsString().c_str(),
value_is_offset ? "offset" : "address", value);
module_sp->SetLoadAddress(target, value, value_is_offset, changed);
} else {
// No address/offset/slide, load the binary at file address,
// offset 0.
LLDB_LOGF(log,
"DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
"binary UUID %s at file address",
uuid.GetAsString().c_str());
"binary %s UUID %s at file address",
name.str().c_str(), uuid.GetAsString().c_str());
module_sp->SetLoadAddress(target, 0, true /* value_is_slide */,
changed);
}
} else {
// In-memory image, load at its true address, offset 0.
LLDB_LOGF(log,
"DynamicLoader::LoadBinaryWithUUIDAndAddress Loading binary "
"UUID %s from memory at address 0x%" PRIx64,
uuid.GetAsString().c_str(), value);
"%s UUID %s from memory at address 0x%" PRIx64,
name.str().c_str(), uuid.GetAsString().c_str(), value);
module_sp->SetLoadAddress(target, 0, true /* value_is_slide */,
changed);
}
Expand All @@ -298,10 +302,26 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
target.ModulesDidLoad(added_module);
}
} else {
LLDB_LOGF(log, "Unable to find binary with UUID %s and load it at "
"%s 0x%" PRIx64,
uuid.GetAsString().c_str(),
value_is_offset ? "offset" : "address", value);
if (force_symbol_search) {
Stream &s = target.GetDebugger().GetErrorStream();
s.Printf("Unable to find file");
if (!name.empty())
s.Printf(" %s", name.str().c_str());
if (uuid.IsValid())
s.Printf(" with UUID %s", uuid.GetAsString().c_str());
if (value != LLDB_INVALID_ADDRESS) {
if (value_is_offset)
s.Printf(" with slide 0x%" PRIx64, value);
else
s.Printf(" at address 0x%" PRIx64, value);
}
s.Printf("\n");
}
LLDB_LOGF(log,
"Unable to find binary %s with UUID %s and load it at "
"%s 0x%" PRIx64,
name.str().c_str(), uuid.GetAsString().c_str(),
value_is_offset ? "offset" : "address", value);
}

return module_sp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,10 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
// to do anything useful. This will force a call to dsymForUUID if it
// exists, instead of depending on the DebugSymbols preferences being
// set.
Status kernel_search_error;
if (IsKernel()) {
Status error;
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error, true)) {
if (Symbols::DownloadObjectAndSymbolFile(module_spec,
kernel_search_error, true)) {
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
target.GetArchitecture());
Expand Down Expand Up @@ -806,9 +807,13 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
}

if (IsKernel() && !m_module_sp) {
Stream &s = target.GetDebugger().GetOutputStream();
Stream &s = target.GetDebugger().GetErrorStream();
s.Printf("WARNING: Unable to locate kernel binary on the debugger "
"system.\n");
if (kernel_search_error.Fail() && kernel_search_error.AsCString("") &&
kernel_search_error.AsCString("")[0] != '\0') {
s << kernel_search_error.AsCString();
}
}
}

Expand Down
42 changes: 42 additions & 0 deletions lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5460,6 +5460,8 @@ uint32_t ObjectFileMachO::GetNumThreadContexts() {

std::string ObjectFileMachO::GetIdentifierString() {
std::string result;
Log *log(
GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
Expand Down Expand Up @@ -5495,6 +5497,8 @@ std::string ObjectFileMachO::GetIdentifierString() {
result = buf;
if (buf)
free(buf);
LLDB_LOGF(log, "LC_NOTE 'kern ver str' found with text '%s'",
result.c_str());
return result;
}
}
Expand All @@ -5518,6 +5522,7 @@ std::string ObjectFileMachO::GetIdentifierString() {
buf) == ident_command.cmdsize) {
buf[ident_command.cmdsize - 1] = '\0';
result = buf;
LLDB_LOGF(log, "LC_IDENT found with text '%s'", result.c_str());
}
if (buf)
free(buf);
Expand All @@ -5530,6 +5535,7 @@ std::string ObjectFileMachO::GetIdentifierString() {

addr_t ObjectFileMachO::GetAddressMask() {
addr_t mask = 0;
Log *log(GetLog(LLDBLog::Process));
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
Expand Down Expand Up @@ -5557,6 +5563,10 @@ addr_t ObjectFileMachO::GetAddressMask() {
if (num_addr_bits != 0) {
mask = ~((1ULL << num_addr_bits) - 1);
}
LLDB_LOGF(log,
"LC_NOTE 'addrable bits' found, value %d bits, "
"mask 0x%" PRIx64,
num_addr_bits, mask);
break;
}
}
Expand All @@ -5572,6 +5582,8 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t &value,
bool &value_is_offset,
UUID &uuid,
ObjectFile::BinaryType &type) {
Log *log(
GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
value = LLDB_INVALID_ADDRESS;
value_is_offset = false;
uuid.Clear();
Expand Down Expand Up @@ -5651,20 +5663,31 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t &value,
uuid = UUID(raw_uuid, sizeof(uuid_t));
// convert the "main bin spec" type into our
// ObjectFile::BinaryType enum
const char *typestr = "unrecognized type";
switch (binspec_type) {
case 0:
type = eBinaryTypeUnknown;
typestr = "uknown";
break;
case 1:
type = eBinaryTypeKernel;
typestr = "xnu kernel";
break;
case 2:
type = eBinaryTypeUser;
typestr = "userland dyld";
break;
case 3:
type = eBinaryTypeStandalone;
typestr = "standalone";
break;
}
LLDB_LOGF(log,
"LC_NOTE 'main bin spec' found, version %d type %d "
"(%s), value 0x%" PRIx64 " value-is-slide==%s uuid %s",
version, type, typestr, value,
value_is_offset ? "true" : "false",
uuid.GetAsString().c_str());
if (!m_data.GetU32(&offset, &log2_pagesize, 1))
return false;
if (version > 1 && !m_data.GetU32(&offset, &platform, 1))
Expand Down Expand Up @@ -6942,6 +6965,8 @@ bool ObjectFileMachO::CanContainSwiftReflectionData(const Section &section) {
ObjectFileMachO::MachOCorefileAllImageInfos
ObjectFileMachO::GetCorefileAllImageInfos() {
MachOCorefileAllImageInfos image_infos;
Log *log(
GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));

// Look for an "all image infos" LC_NOTE.
lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
Expand Down Expand Up @@ -6971,6 +6996,9 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
// offset += 4; // uint32_t entries_size;
// offset += 4; // uint32_t unused;

LLDB_LOGF(log,
"LC_NOTE 'all image infos' found version %d with %d images",
version, imgcount);
offset = entries_fileoff;
for (uint32_t i = 0; i < imgcount; i++) {
// Read the struct image_entry.
Expand Down Expand Up @@ -7002,6 +7030,12 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
vmaddr};
image_entry.segment_load_addresses.push_back(new_seg);
}
LLDB_LOGF(
log, " image entry: %s %s 0x%" PRIx64 " %s",
image_entry.filename.c_str(),
image_entry.uuid.GetAsString().c_str(), image_entry.load_address,
image_entry.currently_executing ? "currently executing"
: "not currently executing");
image_infos.all_image_infos.push_back(image_entry);
}
} else if (strcmp("load binary", data_owner) == 0) {
Expand All @@ -7021,6 +7055,14 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
image_entry.slide = slide;
image_entry.currently_executing = true;
image_infos.all_image_infos.push_back(image_entry);
LLDB_LOGF(log,
"LC_NOTE 'load binary' found, filename %s uuid %s load "
"address 0x%" PRIx64 " slide 0x%" PRIx64,
filename.c_str(),
image_entry.uuid.IsValid()
? image_entry.uuid.GetAsString().c_str()
: "00000000-0000-0000-0000-000000000000",
load_address, slide);
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions lldb/source/Symbol/LocateSymbolFileMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ FileSpec Symbols::FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,

static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
ModuleSpec &module_spec,
Status &error) {
Status &error,
const std::string &command) {
Log *log = GetLog(LLDBLog::Host);
bool success = false;
if (uuid_dict != NULL && CFGetTypeID(uuid_dict) == CFDictionaryGetTypeID()) {
Expand All @@ -342,7 +343,10 @@ static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
CFSTR("DBGError"));
if (cf_str && CFGetTypeID(cf_str) == CFStringGetTypeID()) {
if (CFCString::FileSystemRepresentation(cf_str, str)) {
error.SetErrorString(str);
std::string errorstr = command;
errorstr += ":\n";
errorstr += str;
error.SetErrorString(errorstr);
}
}

Expand Down Expand Up @@ -652,7 +656,8 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
CFCString uuid_cfstr(uuid_str.c_str());
CFDictionaryRef uuid_dict =
(CFDictionaryRef)CFDictionaryGetValue(plist.get(), uuid_cfstr.get());
return GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec, error);
return GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec, error,
command.GetData());
}

if (const CFIndex num_values = ::CFDictionaryGetCount(plist.get())) {
Expand All @@ -661,13 +666,14 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
::CFDictionaryGetKeysAndValues(plist.get(), NULL,
(const void **)&values[0]);
if (num_values == 1) {
return GetModuleSpecInfoFromUUIDDictionary(values[0], module_spec, error);
return GetModuleSpecInfoFromUUIDDictionary(values[0], module_spec, error,
command.GetData());
}

for (CFIndex i = 0; i < num_values; ++i) {
ModuleSpec curr_module_spec;
if (GetModuleSpecInfoFromUUIDDictionary(values[i], curr_module_spec,
error)) {
error, command.GetData())) {
if (module_spec.GetArchitecture().IsCompatibleMatch(
curr_module_spec.GetArchitecture())) {
module_spec = curr_module_spec;
Expand Down