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