Skip to content

Commit ea45421

Browse files
committed
[lldb] Document SymbolFileJSON
I've had multiple request for documentation about the JSON symbol file format that LLDB supports. This patch documents the structure and fields, shows a handful of examples and explains how to use it in LLDB.
1 parent e13f1d1 commit ea45421

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
JSON Symbol File Format
2+
=======================
3+
4+
The JSON symbol file format encodes symbols in a text based, human readable
5+
format. JSON symbol files can be used to symbolicate programs that miss symbol
6+
information, for example because they have been stripped.
7+
8+
Format
9+
------
10+
11+
The symbol file contains of a single JSON object with the following top level
12+
keys:
13+
14+
* ``triple``
15+
* ``uuid``
16+
* ``type``
17+
* ``sections``
18+
* ``symbols``
19+
20+
The ``triple``, ``uuid`` and ``type`` form the header and should therefore come
21+
first. The ``type`` field is optional. The body consists ``sections`` and
22+
``symbols``, each represented as a JSON array. Both arrays are optional, and
23+
can be omitted and are allowed to be empty.
24+
25+
triple
26+
``````
27+
28+
The triple is a string with the triple of the object file it corresponds to.
29+
The triple follows the same format as used by LLVM:
30+
``<arch><sub>-<vendor>-<sys>-<env>``.
31+
32+
.. code-block:: JSON
33+
34+
{ "triple": "arm64-apple-darwin22.0.0" }
35+
36+
uuid
37+
````
38+
39+
The UUID is a string with the textual representation of the UUID of the object
40+
file it corresponds to. The UUID is represented as outlined in RFC 4122: with
41+
32 hexadecimal digits, displayed in five groups separated by hyphens, in the
42+
form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and
43+
four hyphens).
44+
45+
.. code-block:: JSON
46+
47+
{ "uuid": "2107157B-6D7E-39F6-806D-AECDC15FC533" }
48+
49+
type
50+
````
51+
The optional ``type`` field allows you to specify the type of object file the
52+
JSON file represent. This is often unnecessary, and can be omitted, in which
53+
case the file is considered of the type ``DebugInfo``.
54+
55+
Valid values for the ``type`` field are:
56+
57+
* ``CoreFile``: A core file that has a checkpoint of a program's execution state.
58+
* ``Executable``: A normal executable.
59+
* ``DebugInfo``: An object file that contains only debug information.
60+
* ``DynamicLinker``: The platform's dynamic linker executable.
61+
* ``ObjectFile``: An intermediate object file.
62+
* ``SharedLibrary``: A shared library that can be used during execution.
63+
* ``StubLibrary``: A library that can be linked against but not used for execution.
64+
* ``JIT``: JIT code that has symbols, sections and possibly debug info.
65+
66+
67+
sections
68+
````````
69+
70+
* ``name``: a string representing the section name.
71+
* ``type``: a string representing the section type (see below).
72+
* ``address``: a number representing the section file address.
73+
* ``size``: a number representing the section size in bytes.
74+
75+
.. code-block:: JSON
76+
77+
{
78+
"name": "__TEXT",
79+
"type": "code",
80+
"address": 0,
81+
"size": 546,
82+
}
83+
84+
The ``type`` field accepts the following values: ``code``, ``container``,
85+
``data``, ``debug``.
86+
87+
symbols
88+
```````
89+
90+
Symbols are JSON objects with the following keys:
91+
92+
* ``name``: a string representing the string name.
93+
* ``value``: a number representing the symbol value.
94+
* ``address``: a number representing the symbol address in a section.
95+
* ``size``: a number representing the symbol size.
96+
* ``type``: an optional string representing the symbol type (see below).
97+
98+
A symbol must contain either a ``value`` or an ``address``. The ``type`` is
99+
optional.
100+
101+
.. code-block:: JSON
102+
103+
{
104+
"name": "foo",
105+
"type": "code",
106+
"size": 10,
107+
"address": 4294983544,
108+
}
109+
110+
The ``type`` field accepts any type in the ``lldb::SymbolType`` enum in
111+
`lldb-enumerations.h <https://lldb.llvm.org/cpp_reference/lldb-enumerations_8h.html>`_
112+
, without the ``eSymbolType``. For example ``code`` maps to ``eSymbolTypeCode``
113+
and ``variableType`` to ``eSymbolTypeVariableType``.
114+
115+
Usage
116+
-----
117+
118+
Symbol files can be added with the ``target symbol add`` command. The triple
119+
and UUID will be used to match it to the correct module.
120+
121+
.. code-block:: shell
122+
123+
(lldb) target symbol add /path/to/symbol.json
124+
symbol file '/path/to/symbol.json' has been added to '/path/to/executable'
125+
126+
You can use ``image list`` to confirm that the symbol file has been associated
127+
with the module.
128+
129+
.. code-block:: shell
130+
131+
(lldb) image list
132+
[ 0] A711AB38-1FB1-38B1-B38B-859352ED2A20 0x0000000100000000 /path/to/executable
133+
/path/to/symbol.json
134+
[ 1] 4BF76A72-53CC-3E42-8945-4E314C101535 0x00000001800c6000 /usr/lib/dyld
135+
136+
137+
Example
138+
-------
139+
140+
The simplest valid JSON symbol file consists of just a triple and UUID:
141+
142+
.. code-block:: JSON
143+
144+
{
145+
"triple": "arm64-apple-macosx15.0.0",
146+
"uuid": "A711AB38-1FB1-38B1-B38B-859352ED2A20"
147+
}
148+
149+
A JSON symbol file with symbols for ``main``, ``foo``, and ``bar``.
150+
151+
.. code-block:: JSON
152+
153+
{
154+
"triple": "arm64-apple-macosx15.0.0",
155+
"uuid": "321C6225-2378-3E6D-B6C1-6374DEC6D81A",
156+
"symbols": [
157+
{
158+
"name": "main",
159+
"type": "code",
160+
"size": 32,
161+
"address": 4294983552
162+
},
163+
{
164+
"name": "foo",
165+
"type": "code",
166+
"size": 8,
167+
"address": 4294983544
168+
},
169+
{
170+
"name": "bar",
171+
"type": "code",
172+
"size": 0,
173+
"value": 255
174+
}
175+
]
176+
}
177+
178+
A symbol file with a symbol ``foo`` belonging to the ``__TEXT`` section.
179+
180+
.. code-block:: JSON
181+
182+
{
183+
"triple": "arm64-apple-macosx15.0.0",
184+
"uuid": "58489DB0-F9FF-4E62-ABD1-A7CCE5DFB879",
185+
"type": "sharedlibrary",
186+
"sections": [
187+
{
188+
"name": "__TEXT",
189+
"type": "code",
190+
"address": 0,
191+
"size": 546
192+
}
193+
],
194+
"symbols": [
195+
{
196+
"name": "foo",
197+
"address": 256,
198+
"size": 17
199+
}
200+
]
201+
}

0 commit comments

Comments
 (0)