This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Make ObjectFileJSON loadable as a module
ClosedPublic

Authored by JDevlieghere on Apr 11 2023, 4:03 PM.

Details

Summary

This patch adds support for creating modules from JSON object files. This is necessary for crashlogs (see rGc17a1f3df70b for more details) where we don't have neither the module nor the symbol file.

Diff Detail

Event Timeline

JDevlieghere created this revision.Apr 11 2023, 4:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 11 2023, 4:03 PM
JDevlieghere requested review of this revision.Apr 11 2023, 4:03 PM
  • Improve error reporting
  • Fix bug

Fix bug in ObjectFileJSON where we wouldn't read the rest of the file and fail parsing.

mib added inline comments.Apr 12 2023, 6:32 PM
lldb/lldb/test/API/macosx/symbols/TestObjectFileJSON.py
12 ↗(On Diff #512963)

nit

lldb/source/Core/Section.cpp
683–684

We should use o.mapOptional here since the address, size and type are marked optional.

lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
110

I guess this is due to the fact that we only read the first 512 bytes from the binary the first time we load it ? It would be good to mention it in a comment.

209

ditto

lldb/test/API/macosx/symbols/TestObjectFileJSON.py
13

It looks like you've included this test twice.

JDevlieghere marked an inline comment as done.Apr 12 2023, 7:31 PM
JDevlieghere added inline comments.
lldb/source/Core/Section.cpp
683–684

They're not exactly the same: map with a std::optional lets you deal with whether the value was set outside of the deserialization method, while mapOptional requires you to have initialized the variable to the default value previously, or pass it as a third argument. In this particular case it doesn't really matter, as the default value is pretty trivial, but I'd rather preserve that a value wasn't set. That's different from the call to mapOptional for the symbol and section vectors, where I don't care whether the vector is empty or was omitted completely.

JDevlieghere marked 4 inline comments as done.

Address @mib's code review feedback

mib accepted this revision.Apr 12 2023, 7:53 PM

LGTM! Thanks

This revision is now accepted and ready to land.Apr 12 2023, 7:53 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 13 2023, 2:08 PM
labath added a subscriber: labath.Apr 14 2023, 5:43 AM
labath added inline comments.
lldb/test/API/macosx/symbols/TestObjectFileJSON.py
82

The test was (95%!) flaky because the two generated files had the same timestamp (and so lldb considered them identical and did not reload). I fixed that by adding a sleep, but your intention was not to test file reloading then it would be better to just use different filenames.

(There could also be a bug somewhere, because I was under the impression that we should treat files with different UUIDs as distinct even if they happen to have the same timestamp.)

FYI this test is failing on our Windows on Arm bot due to not finding strip: https://lab.llvm.org/buildbot/#/builders/219/builds/2164/steps/6/logs/stdio

I see other uses so not sure why this one isn't working. Maybe it can use llvm-strip instead? @omjavaid

I didn't see this until now. I'll update the test. We shouldn't need strip for this test but we're sharing the Makefile for SymbolFileJSON. I'll see if it makes more sense to split up the test.