This is an archive of the discontinued LLVM Phabricator instance.

Surface error messages from the DebugSymbols DBGShellCommands external agent; add logging for LC_NOTEs in Mach-O corefiles

Authored by jasonmolenda on Aug 4 2023, 4:46 PM.



On Darwin systems, lldb will call into the DebugSymbols framework to find the debug info (and/or binary) for a given UUID. The user may have set a DBGShellCommands preference in to find that binary by UUID. lldb will also try a binary that is set in the env var LLDB_APPLE_DSYMFORUUID_EXECUTABLE (mostly used by the testsuite) and for certain "force a binary load" binaries (e.g. the Darwin kernel binary/symbols, without which kernel debugging is largely useless), we have a special case in source/Symbol/LocateSymbolFileMacOSX.cpp that knows about a binary called /usr/local/bin/dsymForUUID that may be installed.

These DBGShellCommands programs return a plist (xml) output giving lldb the location of the dSYM and/or binary. They can also return an error message in that xml response. Today lldb does not print that error, making it difficult for users to understand why a binary was not successfully loaded.

I also added some simple logging as lldb processes LC_NOTEs in a mach-o corefile binary that can be enabled, to understand what lldb is seeing as it loads one of these.

I have another patch that I'll be uploading soon where I fix the DBGError return from a test case, although the error message is sent to the Debugger's Stdout channel so I'm not capturing/testing it in the API test right now. (the that this test case creates DOES emit a DBGError right now on an unknown uuid, but it doesn't format it correctly and lldb ignores it).

Diff Detail

Event Timeline

jasonmolenda created this revision.Aug 4 2023, 4:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 4:46 PM
jasonmolenda requested review of this revision.Aug 4 2023, 4:46 PM
JDevlieghere requested changes to this revision.Aug 5 2023, 11:54 AM
JDevlieghere added inline comments.

Please use LLDB_LOG(F):

LLDB_LOGF(log, "LC_NOTE 'kern ver str' found with text '%s'", result.c_str());
This revision now requires changes to proceed.Aug 5 2023, 11:54 AM

Change calls to Log::Printf to use LLDB_LOGF().

jasonmolenda marked an inline comment as done.Aug 7 2023, 5:18 PM
JDevlieghere added inline comments.Aug 7 2023, 5:35 PM

Shouldn't this be the error stream?

fix typeo


Ah good suggestion.

Update patch to send these error messages to the ErrorStream not OutputStream. Also change LocateSymbolFileMacOSX.cpp so the full command that was used to find the binary is included in the error message, to make it clearer exactly where the error message originated.

JDevlieghere accepted this revision.Aug 8 2023, 2:49 PM



If you don't need the Stream anymore you could do

target.GetDebugger().GetErrorStream() << error.AsCString();

LLDB_LOG could simplify this a lot ;-)

This revision is now accepted and ready to land.Aug 8 2023, 2:49 PM