252 lines · plain
1JSON Symbol File Format2=======================3 4The JSON symbol file format encodes symbols in a text based, human readable5format. JSON symbol files can be used to symbolicate programs that lack symbol6information, for example because they have been stripped.7 8Under the hood, the JSON symbol file format is also used by the crashlog9script, specifically to provide symbol information for interactive crashlogs.10 11Format12------13 14The symbol file consists of a single JSON object with the following top level15keys:16 17* ``triple`` (string)18* ``uuid`` (string)19* ``type`` (string, optional)20* ``sections`` (array, optional)21* ``symbols`` (array, optional)22 23The ``triple``, ``uuid`` and ``type`` form the header and should therefore come24first. The ``type`` field is optional. The body consists ``sections`` and25``symbols``. Both arrays are optional, and can be omitted and are allowed to be26empty.27 28triple29``````30 31The triple is a string with the triple of the object file it corresponds to.32The triple follows the same format as used by LLVM:33``<arch><sub>-<vendor>-<sys>-<env>``.34 35.. code-block:: JSON36 37 { "triple": "arm64-apple-darwin22.0.0" }38 39uuid40````41 42The UUID is a string with the textual representation of the UUID of the object43file it corresponds to. The UUID is represented as outlined in RFC 4122: with4432 hexadecimal digits, displayed in five groups separated by hyphens, in the45form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and46four hyphens).47 48.. code-block:: JSON49 50 { "uuid": "2107157B-6D7E-39F6-806D-AECDC15FC533" }51 52type53````54The optional ``type`` field allows you to specify the type of object file the55JSON file represent. This is often unnecessary, and can be omitted, in which56case the file is considered of the type ``DebugInfo``.57 58Valid values for the ``type`` field are:59 60* ``corefile``: A core file that has a checkpoint of a program's execution state.61* ``executable``: A normal executable.62* ``debuginfo``: An object file that contains only debug information.63* ``dynamiclinker``: The platform's dynamic linker executable.64* ``objectfile``: An intermediate object file.65* ``sharedlibrary``: A shared library that can be used during execution.66* ``stublibrary``: A library that can be linked against but not used for execution.67* ``jit``: JIT code that has symbols, sections and possibly debug info.68 69 70sections71````````72 73* ``name``: a string representing the section name.74* ``type``: a string representing the section type (see below).75* ``address``: a number representing the section file address.76* ``size``: a number representing the section size in bytes.77* ``read``: a boolean value indicating if the section has read permissions.78* ``write``: a boolean value indicating if the section has write permissions.79* ``execute``: a boolean value indicating if the section has execute permissions.80* ``subsections``: An array of child sections in the same format.81* ``user_id``: a number representing the section identifier.82* ``file_offset``: a number that represents the offset in the file for this section's contents.83* ``file_size``: a number that represents the size in bytes in the file for this section's contents.84* ``alignment``: a boolean value indicating if the section has execute permissions.85* ``fake``: a boolean value indicating if the section is fake.86* ``encrypted``: a boolean value indicating if the section is encrypted.87* ``thread_specific``: a boolean value indicating if the section is thread specific.88 89.. code-block:: JSON90 91 {92 "user_id": 256,93 "name": "__TEXT",94 "type": "code",95 "address": 0,96 "size": 546,97 "file_offset": 0,98 "file_size": 4096,99 "read": true,100 "write": false,101 "executable": true,102 "subsections": [103 {104 "name": "__text",105 "type": "code",106 "address": 0,107 "size": 200,108 "alignment": 2,109 "read": true,110 "write": false,111 "execute": true112 },113 {114 "name": "__fake",115 "address": 200,116 "size": 10,117 "fake": true118 },119 {120 "name": "__encrypted",121 "address": 210,122 "size": 20,123 "encrypted": true124 },125 {126 "name": "__tls",127 "address": 230,128 "size": 30,129 "thread_specific": true130 }131 ]132 }133 134The ``type`` field accepts the following values: ``code``, ``container``,135``data``, ``debug``.136 137symbols138```````139 140Symbols are JSON objects with the following keys:141 142* ``name``: a string representing the string name.143* ``value``: a number representing the symbol value.144* ``address``: a number representing the symbol address in a section.145* ``size``: a number representing the symbol size.146* ``type``: an optional string representing the symbol type (see below).147 148A symbol must contain either a ``value`` or an ``address``. The ``type`` is149optional.150 151.. code-block:: JSON152 153 {154 "name": "foo",155 "type": "code",156 "size": 10,157 "address": 4294983544,158 }159 160The ``type`` field accepts any type in the ``lldb::SymbolType`` enum in161`lldb-enumerations.h <https://lldb.llvm.org/cpp_reference/lldb-enumerations_8h.html>`_162, without the ``eSymbolType``. For example ``code`` maps to ``eSymbolTypeCode``163and ``variableType`` to ``eSymbolTypeVariableType``.164 165Usage166-----167 168Symbol files can be added with the ``target symbol add`` command. The triple169and UUID will be used to match it to the correct module.170 171.. code-block:: shell172 173 (lldb) target symbol add /path/to/symbol.json174 symbol file '/path/to/symbol.json' has been added to '/path/to/executable'175 176You can use ``image list`` to confirm that the symbol file has been associated177with the module.178 179.. code-block:: shell180 181 (lldb) image list182 [ 0] A711AB38-1FB1-38B1-B38B-859352ED2A20 0x0000000100000000 /path/to/executable183 /path/to/symbol.json184 [ 1] 4BF76A72-53CC-3E42-8945-4E314C101535 0x00000001800c6000 /usr/lib/dyld185 186 187Example188-------189 190The simplest valid JSON symbol file consists of just a triple and UUID:191 192.. code-block:: JSON193 194 {195 "triple": "arm64-apple-macosx15.0.0",196 "uuid": "A711AB38-1FB1-38B1-B38B-859352ED2A20"197 }198 199A JSON symbol file with symbols for ``main``, ``foo``, and ``bar``.200 201.. code-block:: JSON202 203 {204 "triple": "arm64-apple-macosx15.0.0",205 "uuid": "321C6225-2378-3E6D-B6C1-6374DEC6D81A",206 "symbols": [207 {208 "name": "main",209 "type": "code",210 "size": 32,211 "address": 4294983552212 },213 {214 "name": "foo",215 "type": "code",216 "size": 8,217 "address": 4294983544218 },219 {220 "name": "bar",221 "type": "code",222 "size": 0,223 "value": 255224 }225 ]226 }227 228A symbol file with a symbol ``foo`` belonging to the ``__TEXT`` section.229 230.. code-block:: JSON231 232 {233 "triple": "arm64-apple-macosx15.0.0",234 "uuid": "58489DB0-F9FF-4E62-ABD1-A7CCE5DFB879",235 "type": "sharedlibrary",236 "sections": [237 {238 "name": "__TEXT",239 "type": "code",240 "address": 0,241 "size": 546242 }243 ],244 "symbols": [245 {246 "name": "foo",247 "address": 256,248 "size": 17249 }250 ]251 }252