Skip to content

Commit 0f296f6

Browse files
authored
Merge pull request #7204 from jasonmolenda/cp/show-error-messages-from-DBGShellCommand
Show error messages from DebugSymbols DBGShellCommand agent
2 parents f6503d2 + 6fb8c82 commit 0f296f6

File tree

4 files changed

+91
-18
lines changed

4 files changed

+91
-18
lines changed

lldb/source/Core/DynamicLoader.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "lldb/Target/DynamicLoader.h"
1010

11+
#include "lldb/Core/Debugger.h"
1112
#include "lldb/Core/Module.h"
1213
#include "lldb/Core/ModuleList.h"
1314
#include "lldb/Core/ModuleSpec.h"
@@ -235,6 +236,9 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
235236
force_symbol_search);
236237
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
237238
module_sp = std::make_shared<Module>(module_spec);
239+
} else if (force_symbol_search && error.AsCString("") &&
240+
error.AsCString("")[0] != '\0') {
241+
target.GetDebugger().GetErrorStream() << error.AsCString();
238242
}
239243
}
240244

@@ -267,26 +271,26 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
267271
if (value != LLDB_INVALID_ADDRESS) {
268272
LLDB_LOGF(log,
269273
"DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
270-
"binary UUID %s at %s 0x%" PRIx64,
271-
uuid.GetAsString().c_str(),
274+
"binary %s UUID %s at %s 0x%" PRIx64,
275+
name.str().c_str(), uuid.GetAsString().c_str(),
272276
value_is_offset ? "offset" : "address", value);
273277
module_sp->SetLoadAddress(target, value, value_is_offset, changed);
274278
} else {
275279
// No address/offset/slide, load the binary at file address,
276280
// offset 0.
277281
LLDB_LOGF(log,
278282
"DynamicLoader::LoadBinaryWithUUIDAndAddress Loading "
279-
"binary UUID %s at file address",
280-
uuid.GetAsString().c_str());
283+
"binary %s UUID %s at file address",
284+
name.str().c_str(), uuid.GetAsString().c_str());
281285
module_sp->SetLoadAddress(target, 0, true /* value_is_slide */,
282286
changed);
283287
}
284288
} else {
285289
// In-memory image, load at its true address, offset 0.
286290
LLDB_LOGF(log,
287291
"DynamicLoader::LoadBinaryWithUUIDAndAddress Loading binary "
288-
"UUID %s from memory at address 0x%" PRIx64,
289-
uuid.GetAsString().c_str(), value);
292+
"%s UUID %s from memory at address 0x%" PRIx64,
293+
name.str().c_str(), uuid.GetAsString().c_str(), value);
290294
module_sp->SetLoadAddress(target, 0, true /* value_is_slide */,
291295
changed);
292296
}
@@ -298,10 +302,26 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(
298302
target.ModulesDidLoad(added_module);
299303
}
300304
} else {
301-
LLDB_LOGF(log, "Unable to find binary with UUID %s and load it at "
302-
"%s 0x%" PRIx64,
303-
uuid.GetAsString().c_str(),
304-
value_is_offset ? "offset" : "address", value);
305+
if (force_symbol_search) {
306+
Stream &s = target.GetDebugger().GetErrorStream();
307+
s.Printf("Unable to find file");
308+
if (!name.empty())
309+
s.Printf(" %s", name.str().c_str());
310+
if (uuid.IsValid())
311+
s.Printf(" with UUID %s", uuid.GetAsString().c_str());
312+
if (value != LLDB_INVALID_ADDRESS) {
313+
if (value_is_offset)
314+
s.Printf(" with slide 0x%" PRIx64, value);
315+
else
316+
s.Printf(" at address 0x%" PRIx64, value);
317+
}
318+
s.Printf("\n");
319+
}
320+
LLDB_LOGF(log,
321+
"Unable to find binary %s with UUID %s and load it at "
322+
"%s 0x%" PRIx64,
323+
name.str().c_str(), uuid.GetAsString().c_str(),
324+
value_is_offset ? "offset" : "address", value);
305325
}
306326

307327
return module_sp;

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,10 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
766766
// to do anything useful. This will force a call to dsymForUUID if it
767767
// exists, instead of depending on the DebugSymbols preferences being
768768
// set.
769+
Status kernel_search_error;
769770
if (IsKernel()) {
770-
Status error;
771-
if (Symbols::DownloadObjectAndSymbolFile(module_spec, error, true)) {
771+
if (Symbols::DownloadObjectAndSymbolFile(module_spec,
772+
kernel_search_error, true)) {
772773
if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
773774
m_module_sp = std::make_shared<Module>(module_spec.GetFileSpec(),
774775
target.GetArchitecture());
@@ -806,9 +807,13 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
806807
}
807808

808809
if (IsKernel() && !m_module_sp) {
809-
Stream &s = target.GetDebugger().GetOutputStream();
810+
Stream &s = target.GetDebugger().GetErrorStream();
810811
s.Printf("WARNING: Unable to locate kernel binary on the debugger "
811812
"system.\n");
813+
if (kernel_search_error.Fail() && kernel_search_error.AsCString("") &&
814+
kernel_search_error.AsCString("")[0] != '\0') {
815+
s << kernel_search_error.AsCString();
816+
}
812817
}
813818
}
814819

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5460,6 +5460,8 @@ uint32_t ObjectFileMachO::GetNumThreadContexts() {
54605460

54615461
std::string ObjectFileMachO::GetIdentifierString() {
54625462
std::string result;
5463+
Log *log(
5464+
GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
54635465
ModuleSP module_sp(GetModule());
54645466
if (module_sp) {
54655467
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
@@ -5495,6 +5497,8 @@ std::string ObjectFileMachO::GetIdentifierString() {
54955497
result = buf;
54965498
if (buf)
54975499
free(buf);
5500+
LLDB_LOGF(log, "LC_NOTE 'kern ver str' found with text '%s'",
5501+
result.c_str());
54985502
return result;
54995503
}
55005504
}
@@ -5518,6 +5522,7 @@ std::string ObjectFileMachO::GetIdentifierString() {
55185522
buf) == ident_command.cmdsize) {
55195523
buf[ident_command.cmdsize - 1] = '\0';
55205524
result = buf;
5525+
LLDB_LOGF(log, "LC_IDENT found with text '%s'", result.c_str());
55215526
}
55225527
if (buf)
55235528
free(buf);
@@ -5530,6 +5535,7 @@ std::string ObjectFileMachO::GetIdentifierString() {
55305535

55315536
addr_t ObjectFileMachO::GetAddressMask() {
55325537
addr_t mask = 0;
5538+
Log *log(GetLog(LLDBLog::Process));
55335539
ModuleSP module_sp(GetModule());
55345540
if (module_sp) {
55355541
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
@@ -5557,6 +5563,10 @@ addr_t ObjectFileMachO::GetAddressMask() {
55575563
if (num_addr_bits != 0) {
55585564
mask = ~((1ULL << num_addr_bits) - 1);
55595565
}
5566+
LLDB_LOGF(log,
5567+
"LC_NOTE 'addrable bits' found, value %d bits, "
5568+
"mask 0x%" PRIx64,
5569+
num_addr_bits, mask);
55605570
break;
55615571
}
55625572
}
@@ -5572,6 +5582,8 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t &value,
55725582
bool &value_is_offset,
55735583
UUID &uuid,
55745584
ObjectFile::BinaryType &type) {
5585+
Log *log(
5586+
GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
55755587
value = LLDB_INVALID_ADDRESS;
55765588
value_is_offset = false;
55775589
uuid.Clear();
@@ -5651,20 +5663,31 @@ bool ObjectFileMachO::GetCorefileMainBinaryInfo(addr_t &value,
56515663
uuid = UUID(raw_uuid, sizeof(uuid_t));
56525664
// convert the "main bin spec" type into our
56535665
// ObjectFile::BinaryType enum
5666+
const char *typestr = "unrecognized type";
56545667
switch (binspec_type) {
56555668
case 0:
56565669
type = eBinaryTypeUnknown;
5670+
typestr = "uknown";
56575671
break;
56585672
case 1:
56595673
type = eBinaryTypeKernel;
5674+
typestr = "xnu kernel";
56605675
break;
56615676
case 2:
56625677
type = eBinaryTypeUser;
5678+
typestr = "userland dyld";
56635679
break;
56645680
case 3:
56655681
type = eBinaryTypeStandalone;
5682+
typestr = "standalone";
56665683
break;
56675684
}
5685+
LLDB_LOGF(log,
5686+
"LC_NOTE 'main bin spec' found, version %d type %d "
5687+
"(%s), value 0x%" PRIx64 " value-is-slide==%s uuid %s",
5688+
version, type, typestr, value,
5689+
value_is_offset ? "true" : "false",
5690+
uuid.GetAsString().c_str());
56685691
if (!m_data.GetU32(&offset, &log2_pagesize, 1))
56695692
return false;
56705693
if (version > 1 && !m_data.GetU32(&offset, &platform, 1))
@@ -6942,6 +6965,8 @@ bool ObjectFileMachO::CanContainSwiftReflectionData(const Section &section) {
69426965
ObjectFileMachO::MachOCorefileAllImageInfos
69436966
ObjectFileMachO::GetCorefileAllImageInfos() {
69446967
MachOCorefileAllImageInfos image_infos;
6968+
Log *log(
6969+
GetLog(LLDBLog::Symbols | LLDBLog::Process | LLDBLog::DynamicLoader));
69456970

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

6999+
LLDB_LOGF(log,
7000+
"LC_NOTE 'all image infos' found version %d with %d images",
7001+
version, imgcount);
69747002
offset = entries_fileoff;
69757003
for (uint32_t i = 0; i < imgcount; i++) {
69767004
// Read the struct image_entry.
@@ -7002,6 +7030,12 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
70027030
vmaddr};
70037031
image_entry.segment_load_addresses.push_back(new_seg);
70047032
}
7033+
LLDB_LOGF(
7034+
log, " image entry: %s %s 0x%" PRIx64 " %s",
7035+
image_entry.filename.c_str(),
7036+
image_entry.uuid.GetAsString().c_str(), image_entry.load_address,
7037+
image_entry.currently_executing ? "currently executing"
7038+
: "not currently executing");
70057039
image_infos.all_image_infos.push_back(image_entry);
70067040
}
70077041
} else if (strcmp("load binary", data_owner) == 0) {
@@ -7021,6 +7055,14 @@ ObjectFileMachO::GetCorefileAllImageInfos() {
70217055
image_entry.slide = slide;
70227056
image_entry.currently_executing = true;
70237057
image_infos.all_image_infos.push_back(image_entry);
7058+
LLDB_LOGF(log,
7059+
"LC_NOTE 'load binary' found, filename %s uuid %s load "
7060+
"address 0x%" PRIx64 " slide 0x%" PRIx64,
7061+
filename.c_str(),
7062+
image_entry.uuid.IsValid()
7063+
? image_entry.uuid.GetAsString().c_str()
7064+
: "00000000-0000-0000-0000-000000000000",
7065+
load_address, slide);
70247066
}
70257067
}
70267068
}

lldb/source/Symbol/LocateSymbolFileMacOSX.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ FileSpec Symbols::FindSymbolFileInBundle(const FileSpec &dsym_bundle_fspec,
330330

331331
static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
332332
ModuleSpec &module_spec,
333-
Status &error) {
333+
Status &error,
334+
const std::string &command) {
334335
Log *log = GetLog(LLDBLog::Host);
335336
bool success = false;
336337
if (uuid_dict != NULL && CFGetTypeID(uuid_dict) == CFDictionaryGetTypeID()) {
@@ -342,7 +343,10 @@ static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
342343
CFSTR("DBGError"));
343344
if (cf_str && CFGetTypeID(cf_str) == CFStringGetTypeID()) {
344345
if (CFCString::FileSystemRepresentation(cf_str, str)) {
345-
error.SetErrorString(str);
346+
std::string errorstr = command;
347+
errorstr += ":\n";
348+
errorstr += str;
349+
error.SetErrorString(errorstr);
346350
}
347351
}
348352

@@ -652,7 +656,8 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
652656
CFCString uuid_cfstr(uuid_str.c_str());
653657
CFDictionaryRef uuid_dict =
654658
(CFDictionaryRef)CFDictionaryGetValue(plist.get(), uuid_cfstr.get());
655-
return GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec, error);
659+
return GetModuleSpecInfoFromUUIDDictionary(uuid_dict, module_spec, error,
660+
command.GetData());
656661
}
657662

658663
if (const CFIndex num_values = ::CFDictionaryGetCount(plist.get())) {
@@ -661,13 +666,14 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
661666
::CFDictionaryGetKeysAndValues(plist.get(), NULL,
662667
(const void **)&values[0]);
663668
if (num_values == 1) {
664-
return GetModuleSpecInfoFromUUIDDictionary(values[0], module_spec, error);
669+
return GetModuleSpecInfoFromUUIDDictionary(values[0], module_spec, error,
670+
command.GetData());
665671
}
666672

667673
for (CFIndex i = 0; i < num_values; ++i) {
668674
ModuleSpec curr_module_spec;
669675
if (GetModuleSpecInfoFromUUIDDictionary(values[i], curr_module_spec,
670-
error)) {
676+
error, command.GetData())) {
671677
if (module_spec.GetArchitecture().IsCompatibleMatch(
672678
curr_module_spec.GetArchitecture())) {
673679
module_spec = curr_module_spec;

0 commit comments

Comments
 (0)