This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add flag to DynamicLoader::LoadBinaryWithUUIDAndAddress to control whether we fall back to reading the binary out of memory
ClosedPublic

Authored by jasonmolenda on Aug 4 2023, 5:36 PM.

Details

Summary

DynamicLoader::LoadBinaryWithUUIDAndAddress() tries a few different ways of finding a binary, and if it can't find an actual binary (and symbol file) on the local computer, it will try to read a binary out of memory, with the thought that there may be a symbol table in memory so we'll get some symbol names. It will create a placeholder name of memory-image-0x.... It seemed like a good idea when I wrote this method, but in practice for binaries outside of userland binaries in a corefile, this hasn't been helpful.

This patch adds a flag to LoadBinaryWithUUIDAndAddress to control if we should create a memory image module, or not. The only case where we still enable this behavior is in ObjectFileMachO::LoadCoreFileImages() when a binary has segment load addresses. This is the case with the "all image infos" LC_NOTE that lldb creates for userland corefiles with binaries that typically have some symbols in their in-memory symbol tables.

The other type of userland corefiles (gcore-created) will not use this LC_NOTE but an entirely different codepath -- through the Darwin userland DynamicLoader plugin -- is taken in those cases, so we'll still read them out of memory.

This patch makes firmware/standalone binary loading not create these memory-image-0x... placeholder binaries with no symbols in them, the scenario where it is more annoying than useful.

The test case TestMultipleBinaryCorefile.py tests this standalone-binary corefile scenario, so it needed adjusting to the new setup where the binary image is not added to the target. I also cleaned up the fake dsym-for-uuid.sh it creates to return a properly formatted DBGError message for https://reviews.llvm.org/D157160

Diff Detail

Event Timeline

jasonmolenda created this revision.Aug 4 2023, 5:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 5:36 PM
jasonmolenda requested review of this revision.Aug 4 2023, 5:36 PM
JDevlieghere added inline comments.Aug 5 2023, 12:04 PM
lldb/include/lldb/Target/DynamicLoader.h
267

Nit: seems like either allow_memory_image_last_resort or use_memory_image_last_resort would convey the same thing.

lldb/test/API/macosx/lc-note/multiple-binary-corefile/TestMultipleBinaryCorefile.py
38–39

Out of curiosity what's the point of doing self.runCmd("script print ... vs printing the same thing directly? Does this run in another context or something? Do we save the command output somewhere?

122–123

I know this was moved and this goes beyond the scope of this patch, but we should be using the just-built llvm-dwarfdump instead of whatever happens to be on the system. Obviously no big deal for extracting the --uuid but it's relatively easy to hook up and what we do for other llvm tools such as dsymutil. objdump, etc.

I don't have any objections other than the questions Jonas has asked. LGTM otherwise

lldb/test/API/macosx/lc-note/multiple-binary-corefile/TestMultipleBinaryCorefile.py
38–39

I'm also curious. Printing directly is probably less expensive than running a print command through the lldb python script interpreter.

jasonmolenda added inline comments.Aug 7 2023, 10:55 AM
lldb/include/lldb/Target/DynamicLoader.h
267

Yes, good suggestion, my name wasn't very good here.

lldb/test/API/macosx/lc-note/multiple-binary-corefile/TestMultipleBinaryCorefile.py
38–39

In the past, when I had an SB API test print() directly, the trace output is buffered differently than STDOUT, so I've done this hack in a few places to get the print to happen exactly when the test is executing. Doing a if self.TraceOn(): self.runCmd("bt"); print("got here") will not print the two next to each other, iirc. I can switch to a print and confirm my memory of this.

122–123

I wasn't sure how do find & run that in the build dir; it's used in a few Shell tests but none in API.

Incorporate Jonas' feedback about the naming of the new DynamicLoader method argument.

jasonmolenda added inline comments.Aug 7 2023, 11:05 AM
lldb/test/API/macosx/lc-note/multiple-binary-corefile/TestMultipleBinaryCorefile.py
38–39

I switched this test to just print directly and works fine with lldb-dotest -t, I must have misremembered. I'll remove a few places where I do this in this test.

Fix my script print's to just print, I can't repo a buffering problem that I thought I had seen in the past.

This revision is now accepted and ready to land.Aug 7 2023, 1:25 PM