[lldb] Introduce new SymbolFileJSON and ObjectFileJSON
authorJonas Devlieghere <jonas@devlieghere.com>
Thu, 9 Mar 2023 02:28:50 +0000 (18:28 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Thu, 9 Mar 2023 04:56:11 +0000 (20:56 -0800)
commitcf3524a5746f9498280b3a9180b75575c0065d1a
tree8656caaac35964271d0c631cfb8e3d1f70163098
parent8cf85a0cadb033fed3d96aa5283deb4bfbbaf2c8
[lldb] Introduce new SymbolFileJSON and ObjectFileJSON

Introduce a new object and symbol file format with the goal of mapping
addresses to symbol names. I'd like to think of is as an extremely
simple textual symtab. The file format consists of a triple, a UUID and
a list of symbols. JSON is used for the encoding, but that's mostly an
implementation detail. The goal of the format was to be simple and human
readable.

The new file format is motivated by two use cases:

 - Stripped binaries: when a binary is stripped, you lose the ability to
   do thing like setting symbolic breakpoints. You can keep the
   unstripped binary around, but if all you need is the stripped
   symbols then that's a lot of overhead. Instead, we could save the
   stripped symbols to a file and load them in the debugger when
   needed. I want to extend llvm-strip to have a mode where it emits
   this new file format.

 - Interactive crashlogs: with interactive crashlogs, if we don't have
   the binary or the dSYM for a particular module, we currently show an
   unnamed symbol for those frames. This is a regression compared to the
   textual format, that has these frames pre-symbolicated. Given that
   this information is available in the JSON crashlog, we need a way to
   tell LLDB about it. With the new symbol file format, we can easily
   synthesize a symbol file for each of those modules and load them to
   symbolicate those frames.

Here's an example of the file format:

 {
     "triple": "arm64-apple-macosx13.0.0",
     "uuid": "36D0CCE7-8ED2-3CA3-96B0-48C1764DA908",
     "symbols": [
         {
             "name": "main",
             "type": "code",
             "size": 32,
             "address": 4294983568
         },
         {
             "name": "foo",
             "type": "code",
             "size": 8,
             "address": 4294983560
         }
     ]
 }

Differential revision: https://reviews.llvm.org/D145180
15 files changed:
lldb/include/lldb/Symbol/Symbol.h
lldb/source/Plugins/ObjectFile/CMakeLists.txt
lldb/source/Plugins/ObjectFile/JSON/CMakeLists.txt [new file with mode: 0644]
lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp [new file with mode: 0644]
lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h [new file with mode: 0644]
lldb/source/Plugins/SymbolFile/CMakeLists.txt
lldb/source/Plugins/SymbolFile/JSON/CMakeLists.txt [new file with mode: 0644]
lldb/source/Plugins/SymbolFile/JSON/SymbolFileJSON.cpp [new file with mode: 0644]
lldb/source/Plugins/SymbolFile/JSON/SymbolFileJSON.h [new file with mode: 0644]
lldb/source/Symbol/Symbol.cpp
lldb/test/API/macosx/symbols/Makefile [new file with mode: 0644]
lldb/test/API/macosx/symbols/TestSymbolFileJSON.py [new file with mode: 0644]
lldb/test/API/macosx/symbols/main.c [new file with mode: 0644]
lldb/unittests/Symbol/CMakeLists.txt
lldb/unittests/Symbol/JSONSymbolTest.cpp [new file with mode: 0644]