Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-Type" content="text/html; |
| 5 | charset=ISO-8859-1"> |
| 6 | <link href="style.css" rel="stylesheet" type="text/css"> |
| 7 | <title>LLDB Homepage</title> |
| 8 | </head> |
| 9 | <body> |
| 10 | <div class="www_title"> The <strong>LLDB</strong> Debugger </div> |
| 11 | <div id="container"> |
| 12 | <div id="content"> |
| 13 | <!--#include virtual="sidebar.incl"--> |
| 14 | <div id="middle"> |
| 15 | <div class="post"> |
| 16 | <h1 class="postheader">Variable display</h1> |
| 17 | <div class="postcontent"> |
| 18 | |
| 19 | <p>LLDB was recently modified to allow users to define custom |
| 20 | formatting options for the variables display.</p> |
| 21 | |
| 22 | <p>Usually, when you type <code>frame variable</code> or |
| 23 | run some <code>expression</code> LLDB will |
| 24 | automatically choose a format to display your results on |
| 25 | a per-type basis, as in the following example:</p> |
| 26 | |
| 27 | <p> <code> <b>(lldb)</b> frame variable -T sp<br> |
| 28 | (SimpleWithPointers) sp = {<br> |
| 29 | (int *) x = 0x0000000100100120<br> |
| 30 | (float *) y = |
| 31 | 0x0000000100100130<br> |
| 32 | (char *) z = |
| 33 | 0x0000000100100140 "6"<br> |
| 34 | }<br> |
| 35 | </code> </p> |
| 36 | |
| 37 | <p>However, in certain cases, you may want to associate a |
| 38 | different format to the display for certain datatypes. |
| 39 | To do so, you need to give hints to the debugger as to |
| 40 | how datatypes should be displayed.<br> |
| 41 | A new <b>type</b> command has been introduced in LLDB |
| 42 | which allows to do just that.<br> |
| 43 | </p> |
| 44 | |
| 45 | <p>Using it you can obtain a format like this one for <code>sp</code>, |
| 46 | instead of the default shown above: </p> |
| 47 | |
| 48 | <p> <code> <b>(lldb)</b> frame variable sp<br> |
| 49 | (SimpleWithPointers) sp = |
| 50 | (x=0x0000000100100120 -> -1, y=0x0000000100100130 |
| 51 | -> -2, z="3")<br> |
| 52 | </code> </p> |
| 53 | |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 54 | <p>There are several features related to data visualization: <span |
| 55 | style="font-style: italic;">formats</span>, <span |
| 56 | style="font-style: italic;">summaries</span>, <span |
| 57 | style="font-style: italic;">filters</span>, <span |
| 58 | style="font-style: italic;">synthetic children</span>.</p> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 59 | |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 60 | <p>To reflect this, the the <b>type</b> command has four |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 61 | subcommands:<br> |
| 62 | </p> |
| 63 | |
| 64 | <p><code>type format</code></p> |
| 65 | <p><code>type summary</code></p> |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 66 | <p><code>type filter</code></p> |
| 67 | <p><code>type synthetic</code></p> |
| 68 | |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 69 | |
| 70 | <p>These commands are meant to bind printing options to |
| 71 | types. When variables are printed, LLDB will first check |
| 72 | if custom printing options have been associated to a |
| 73 | variable's type and, if so, use them instead of picking |
| 74 | the default choices.<br> |
| 75 | </p> |
| 76 | |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 77 | <p>Each of the commands has four subcommands available:<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 78 | </p> |
| 79 | <p><code>add</code>: associates a new printing option to one |
| 80 | or more types</p> |
| 81 | <p><code>delete</code>: deletes an existing association</p> |
| 82 | <p><code>list</code>: provides a listing of all |
| 83 | associations</p> |
| 84 | <p><code>clear</code>: deletes all associations</p> |
| 85 | </div> |
| 86 | </div> |
| 87 | |
| 88 | <div class="post"> |
| 89 | <h1 class="postheader">type format</h1> |
| 90 | <div class="postcontent"> |
| 91 | |
| 92 | <p>Type formats enable you to quickly override the default |
| 93 | format for displaying primitive types (the usual basic |
| 94 | C/C++/ObjC types: int, float, char, ...).</p> |
| 95 | |
| 96 | <p>If for some reason you want all <code>int</code> |
| 97 | variables in your program to print out as hex, you can add |
| 98 | a format to the <code>int</code> type.<br></p> |
| 99 | |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 100 | <p>This is done by typing |
| 101 | <table class="stats" width="620" cellspacing="0"> |
| 102 | <td class="content"> |
| 103 | <b>(lldb)</b> type format add -f hex int |
| 104 | </td> |
| 105 | <table> |
| 106 | at the LLDB command line.</p> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 107 | |
| 108 | <p>The <code>-f</code> option accepts a <a |
| 109 | href="#formatstable">format name</a>, and a list of |
| 110 | types to which you want the new format applied.</p> |
| 111 | |
| 112 | <p>A frequent scenario is that your program has a <code>typedef</code> |
| 113 | for a numeric type that you know represents something |
| 114 | that must be printed in a certain way. Again, you can |
| 115 | add a format just to that typedef by using <code>type |
| 116 | format add</code> with the name alias.</p> |
| 117 | |
| 118 | <p>But things can quickly get hierarchical. Let's say you |
| 119 | have a situation like the following:</p> |
| 120 | |
| 121 | <p><code>typedef int A;<br> |
| 122 | typedef A B;<br> |
| 123 | typedef B C;<br> |
| 124 | typedef C D;<br> |
| 125 | </code></p> |
| 126 | |
| 127 | <p>and you want to show all <code>A</code>'s as hex, all |
| 128 | <code>C'</code>s as pointers and leave the defaults |
| 129 | untouched for other types.</p> |
| 130 | |
| 131 | <p>If you simply type <br> |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 132 | <table class="stats" width="620" cellspacing="0"> |
| 133 | <td class="content"> |
| 134 | <b>(lldb)</b> type format add -f hex A<br> |
| 135 | <b>(lldb)</b> type format add -f pointer C |
| 136 | </td> |
| 137 | <table> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 138 | <br> |
| 139 | values of type <code>B</code> will be shown as hex |
| 140 | and values of type <code>D</code> as pointers.</p> |
| 141 | |
| 142 | <p>This is because by default LLDB <i>cascades</i> |
| 143 | formats through typedef chains. In order to avoid that |
| 144 | you can use the option <code>-C no</code> to prevent |
| 145 | cascading, thus making the two commands required to |
| 146 | achieve your goal:<br> |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 147 | <table class="stats" width="620" cellspacing="0"> |
| 148 | <td class="content"> |
| 149 | <b>(lldb)</b> type format add -C no -f hex A<br> |
| 150 | <b>(lldb)</b> type format add -C no -f pointer C |
| 151 | </td> |
| 152 | <table> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 153 | |
| 154 | <p>Two additional options that you will want to look at |
| 155 | are <code>-p</code> and <code>-r</code>. These two |
| 156 | options prevent LLDB from applying a format for type <code>T</code> |
| 157 | to values of type <code>T*</code> and <code>T&</code> |
| 158 | respectively.</p> |
| 159 | |
| 160 | <p> <code> <b>(lldb)</b> type format add -f float32[] |
| 161 | int<br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 162 | <b>(lldb)</b> frame variable pointer *pointer -T<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 163 | (int *) pointer = {1.46991e-39 1.4013e-45}<br> |
| 164 | (int) *pointer = {1.53302e-42}<br> |
| 165 | <b>(lldb)</b> type format add -f float32[] int -p<br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 166 | <b>(lldb)</b> frame variable pointer *pointer -T<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 167 | (int *) pointer = 0x0000000100100180<br> |
| 168 | (int) *pointer = {1.53302e-42}<br> |
| 169 | </code> </p> |
| 170 | |
| 171 | <p>As the previous example highlights, you will most |
| 172 | probably want to use <code>-p</code> for your formats.</p> |
| 173 | |
| 174 | <p>If you need to delete a custom format simply type <code>type |
| 175 | format delete</code> followed by the name of the type |
| 176 | to which the format applies. To delete ALL formats, use |
| 177 | <code>type format clear</code>. To see all the formats |
| 178 | defined, type <code>type format list</code>.<br> |
| 179 | </p> |
| 180 | |
| 181 | <p>If all you need to do, however, is display one variable |
| 182 | in a custom format, while leaving the others of the same |
| 183 | type untouched, you can simply type:<br> |
| 184 | <br> |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 185 | <table class="stats" width="620" cellspacing="0"> |
| 186 | <td class="content"> |
| 187 | <b>(lldb)</b> frame variable counter -f hex |
| 188 | </td> |
| 189 | <table> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 190 | |
| 191 | <p>This has the effect of displaying the value of <code>counter</code> |
| 192 | as an hexadecimal number, and will keep showing it this |
| 193 | way until you either pick a different format or till you |
| 194 | let your program run again.</p> |
| 195 | |
| 196 | <p>Finally, this is a list of formatting options available |
| 197 | out of |
| 198 | which you can pick:</p><a name="formatstable"></a> |
| 199 | <table border="1"> |
| 200 | <tbody> |
| 201 | <tr valign="top"> |
| 202 | <td width="23%"><b>Format name</b></td> |
| 203 | <td><b>Abbreviation</b></td> |
| 204 | <td><b>Description</b></td> |
| 205 | </tr> |
| 206 | <tr valign="top"> |
| 207 | <td><b>default</b></td> |
| 208 | <td><br> |
| 209 | </td> |
| 210 | <td>the default LLDB algorithm is used to pick a |
| 211 | format</td> |
| 212 | </tr> |
| 213 | <tr valign="top"> |
| 214 | <td><b>boolean</b></td> |
| 215 | <td>B</td> |
| 216 | <td>show this as a true/false boolean, using the |
| 217 | customary rule that 0 is false and everything else |
| 218 | is true</td> |
| 219 | </tr> |
| 220 | <tr valign="top"> |
| 221 | <td><b>binary</b></td> |
| 222 | <td>b</td> |
| 223 | <td>show this as a sequence of bits</td> |
| 224 | </tr> |
| 225 | <tr valign="top"> |
| 226 | <td><b>bytes</b></td> |
| 227 | <td>y</td> |
| 228 | <td>show the bytes one after the other<br> |
| 229 | e.g. <code>(int) s.x = 07 00 00 00</code></td> |
| 230 | </tr> |
| 231 | <tr valign="top"> |
| 232 | <td><b>bytes with ASCII</b></td> |
| 233 | <td>Y</td> |
| 234 | <td>show the bytes, but try to print them as ASCII |
| 235 | characters<br> |
| 236 | e.g. <code>(int *) c.sp.x = 50 f8 bf 5f ff 7f 00 |
| 237 | 00 P.._....</code></td> |
| 238 | </tr> |
| 239 | <tr valign="top"> |
| 240 | <td><b>character</b></td> |
| 241 | <td>c</td> |
| 242 | <td>show the bytes printed as ASCII characters<br> |
| 243 | e.g. <code>(int *) c.sp.x = |
| 244 | P\xf8\xbf_\xff\x7f\0\0</code></td> |
| 245 | </tr> |
| 246 | <tr valign="top"> |
| 247 | <td><b>printable character</b></td> |
| 248 | <td>C</td> |
| 249 | <td>show the bytes printed as printable ASCII |
| 250 | characters<br> |
| 251 | e.g. <code>(int *) c.sp.x = P.._....</code></td> |
| 252 | </tr> |
| 253 | <tr valign="top"> |
| 254 | <td><b>complex float</b></td> |
| 255 | <td>F</td> |
| 256 | <td>interpret this value as the real and imaginary |
| 257 | part of a complex floating-point number<br> |
| 258 | e.g. <code>(int *) c.sp.x = 2.76658e+19 + |
| 259 | 4.59163e-41i</code></td> |
| 260 | </tr> |
| 261 | <tr valign="top"> |
| 262 | <td><b>c-string</b></td> |
| 263 | <td>s</td> |
| 264 | <td>show this as a 0-terminated C string</td> |
| 265 | </tr> |
| 266 | <tr valign="top"> |
| 267 | <td><b>signed decimal</b></td> |
| 268 | <td>i</td> |
| 269 | <td>show this as a signed integer number (this does |
| 270 | not perform a cast, it simply shows the bytes as |
| 271 | signed integer)</td> |
| 272 | </tr> |
| 273 | <tr valign="top"> |
| 274 | <td><b>enumeration</b></td> |
| 275 | <td>E</td> |
| 276 | <td>show this as an enumeration, printing the |
| 277 | value's name if available or the integer value |
| 278 | otherwise<br> |
| 279 | e.g. <code>(enum enumType) val_type = eValue2</code></td> |
| 280 | </tr> |
| 281 | <tr valign="top"> |
| 282 | <td><b>hex</b></td> |
| 283 | <td>x</td> |
| 284 | <td>show this as in hexadecimal notation (this does |
| 285 | not perform a cast, it simply shows the bytes as |
| 286 | hex)</td> |
| 287 | </tr> |
| 288 | <tr valign="top"> |
| 289 | <td><b>float</b></td> |
| 290 | <td>f</td> |
| 291 | <td>show this as a floating-point number (this does |
| 292 | not perform a cast, it simply interprets the bytes |
| 293 | as an IEEE754 floating-point value)</td> |
| 294 | </tr> |
| 295 | <tr valign="top"> |
| 296 | <td><b>octal</b></td> |
| 297 | <td>o</td> |
| 298 | <td>show this in octal notation</td> |
| 299 | </tr> |
| 300 | <tr valign="top"> |
| 301 | <td><b>OSType</b></td> |
| 302 | <td>O</td> |
| 303 | <td>show this as a MacOS OSType<br> |
| 304 | e.g. <code>(float) *c.sp.y = '\n\x1f\xd7\n'</code></td> |
| 305 | </tr> |
| 306 | <tr valign="top"> |
| 307 | <td><b>unicode16</b></td> |
| 308 | <td>U</td> |
| 309 | <td>show this as UTF-16 characters<br> |
| 310 | e.g. <code>(float) *c.sp.y = 0xd70a 0x411f</code></td> |
| 311 | </tr> |
| 312 | <tr valign="top"> |
| 313 | <td><b>unicode32</b></td> |
| 314 | <td><br> |
| 315 | </td> |
| 316 | <td>show this as UTF-32 characters<br> |
| 317 | e.g. <code>(float) *c.sp.y = 0x411fd70a</code></td> |
| 318 | </tr> |
| 319 | <tr valign="top"> |
| 320 | <td><b>unsigned decimal</b></td> |
| 321 | <td>u</td> |
| 322 | <td>show this as an unsigned integer number (this |
| 323 | does not perform a cast, it simply shows the bytes |
| 324 | as unsigned integer)</td> |
| 325 | </tr> |
| 326 | <tr valign="top"> |
| 327 | <td><b>pointer</b></td> |
| 328 | <td>p</td> |
| 329 | <td>show this as a native pointer (unless this is |
| 330 | really a pointer, the resulting address will |
| 331 | probably be invalid)</td> |
| 332 | </tr> |
| 333 | <tr valign="top"> |
| 334 | <td><b>char[]</b></td> |
| 335 | <td><br> |
| 336 | </td> |
| 337 | <td>show this as an array of characters<br> |
| 338 | e.g. <code>(char) *c.sp.z = {X}</code></td> |
| 339 | </tr> |
| 340 | <tr valign="top"> |
| 341 | <td><b>int8_t[], uint8_t[]<br> |
| 342 | int16_t[], uint16_t[]<br> |
| 343 | int32_t[], uint32_t[]<br> |
| 344 | int64_t[], uint64_t[]<br> |
| 345 | uint128_t[]</b></td> |
| 346 | <td><br> |
| 347 | </td> |
| 348 | <td>show this as an array of the corresponding |
| 349 | integer type<br> |
| 350 | e.g.<br> |
| 351 | <code>(int) sarray[0].x = {1 0 0 0}</code><br> |
| 352 | <code>(int) sarray[0].x = {0x00000001}</code></td> |
| 353 | </tr> |
| 354 | <tr valign="top"> |
| 355 | <td><b>float32[], float64[]</b></td> |
| 356 | <td><br> |
| 357 | </td> |
| 358 | <td>show this as an array of the corresponding |
| 359 | floating-point type<br> |
| 360 | e.g. <code>(int *) pointer = {1.46991e-39 |
| 361 | 1.4013e-45}</code></td> |
| 362 | </tr> |
| 363 | <tr valign="top"> |
| 364 | <td><b>complex integer</b></td> |
| 365 | <td>I</td> |
| 366 | <td>interpret this value as the real and imaginary |
| 367 | part of a complex integer number<br> |
| 368 | e.g. <code>(int *) pointer = 1048960 + 1i</code></td> |
| 369 | </tr> |
| 370 | <tr valign="top"> |
| 371 | <td><b>character array</b></td> |
| 372 | <td>a</td> |
| 373 | <td>show this as a character array<br> |
| 374 | e.g. <code>(int *) pointer = |
| 375 | \x80\x01\x10\0\x01\0\0\0</code></td> |
| 376 | </tr> |
| 377 | </tbody> |
| 378 | </table> |
| 379 | </div> |
| 380 | </div> |
| 381 | |
| 382 | <div class="post"> |
| 383 | <h1 class="postheader">type summary</h1> |
| 384 | <div class="postcontent"> |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 385 | <p>Type formats work by showing a different kind of display for |
| 386 | the value of a variable. However, they only work for basic types. |
| 387 | When you want to display a class or struct in a custom format, you |
| 388 | cannot do that using formats.</p> |
| 389 | <p>A different feature, type summaries, works by extracting |
| 390 | information from classes, structures, ... (<i>aggregate types</i>) |
| 391 | and arranging it in a user-defined format, as in the following example:</p> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 392 | <p> <i>before adding a summary...</i><br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 393 | <code> <b>(lldb)</b> frame variable -T one<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 394 | (i_am_cool) one = {<br> |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 395 | (int) integer = 3<br> |
| 396 | (float) floating = 3.14159<br> |
| 397 | (char) character = 'E'<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 398 | }<br> |
| 399 | </code> <br> |
| 400 | <i>after adding a summary...</i><br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 401 | <code> <b>(lldb)</b> frame variable one<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 402 | (i_am_cool) one = int = 3, float = 3.14159, char = 69<br> |
| 403 | </code> </p> |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 404 | |
| 405 | <p>There are two ways to use type summaries: the first one is to bind a <i> |
| 406 | summary string</i> to the datatype; the second is to bind a Python script to the |
| 407 | datatype. Both options are enabled by the <code>type summary add</code> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 408 | command.</p> |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 409 | <p>In the example, the command we type was:</p> |
| 410 | <table class="stats" width="620" cellspacing="0"> |
| 411 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 412 | <b>(lldb)</b> type summary add --summary-string "int = ${var.integer}, float = ${var.floating}, char = ${var.character%u}" i_am_cool |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 413 | </td> |
| 414 | <table> |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 415 | |
| 416 | <p>Initially, we will focus on summary strings, and then describe the Python binding |
| 417 | mechanism.</p> |
| 418 | |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 419 | </div> |
| 420 | </div> |
| 421 | <div class="post"> |
| 422 | <h1 class="postheader">Summary Strings</h1> |
| 423 | <div class="postcontent"> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 424 | <p>While you may already have guessed a lot about the format of |
| 425 | summary strings from the above example, a detailed description |
| 426 | of their format follows.</p> |
| 427 | |
| 428 | <p>Summary strings can contain plain text, control characters and |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 429 | special symbols that have access to information about |
| 430 | the current object and the overall program state.</p> |
| 431 | <p>Normal characters are any text that doesn't contain a <code><b>'{'</b></code>, |
| 432 | <code><b>'}'</b></code>, <code><b>'$'</b></code>, or <code><b>'\'</b></code> |
| 433 | character.</p> |
| 434 | <p>Variable names are found in between a <code><b>"${"</b></code> |
| 435 | prefix, and end with a <code><b>"}"</b></code> suffix. |
| 436 | In other words, a variable looks like <code>"<b>${frame.pc}</b>"</code>.</p> |
| 437 | <p>Basically, all the variables described in <a |
| 438 | href="formats.html">Frame and Thread Formatting</a> |
| 439 | are accepted. Also acceptable are the control characters |
| 440 | and scoping features described in that page. |
| 441 | Additionally, <code>${var</code> and <code>${*var</code> |
| 442 | become acceptable symbols in this scenario.</p> |
| 443 | <p>The simplest thing you can do is grab a member variable |
| 444 | of a class or structure by typing its <i>expression |
| 445 | path</i>. In the previous example, the expression path |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 446 | for the floating member is simply <code>.floating</code>. |
| 447 | Thus, to ask the summary string to display <code>floating</code> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 448 | you would type <code>${var.floating}</code> (<code>${var</code> |
| 449 | is a placeholder token replaced with whatever variable |
| 450 | is being displayed).</p> |
| 451 | <p>If you have code like the following: <br> |
| 452 | <code> struct A {<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 453 | int x;<br> |
| 454 | int y;<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 455 | };<br> |
| 456 | struct B {<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 457 | A x;<br> |
| 458 | A y;<br> |
| 459 | int z;<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 460 | };<br> |
| 461 | </code> the expression path for the <code>y</code> |
| 462 | member of the <code>x</code> member of an object of |
| 463 | type <code>B</code> would be <code>.x.y</code> and you |
| 464 | would type <code>${var.x.y}</code> to display it in a |
| 465 | summary string for type <code>B</code>. </p> |
| 466 | <p>As you could be using a summary string for both |
| 467 | displaying objects of type <code>T</code> or <code>T*</code> |
| 468 | (unless <code>-p</code> is used to prevent this), the |
| 469 | expression paths do not differentiate between <code>.</code> |
| 470 | and <code>-></code>, and the above expression path <code>.x.y</code> |
| 471 | would be just as good if you were displaying a <code>B*</code>, |
| 472 | or even if the actual definition of <code>B</code> |
| 473 | were: <code><br> |
| 474 | struct B {<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 475 | A *x;<br> |
| 476 | A y;<br> |
| 477 | int z;<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 478 | };<br> |
| 479 | </code> </p> |
| 480 | <p>This is unlike the behaviour of <code>frame variable</code> |
| 481 | which, on the contrary, will enforce the distinction. As |
| 482 | hinted above, the rationale for this choice is that |
| 483 | waiving this distinction enables one to write a summary |
| 484 | string once for type <code>T</code> and use it for both |
| 485 | <code>T</code> and <code>T*</code> instances. As a |
| 486 | summary string is mostly about extracting nested |
| 487 | members' information, a pointer to an object is just as |
| 488 | good as the object itself for the purpose.</p> |
| 489 | <p>Of course, you can have multiple entries in one summary |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 490 | string, as shown in the previous example.</p> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 491 | <p>As you can see, the last expression path also contains |
| 492 | a <code>%u</code> symbol which is nowhere to be found |
| 493 | in the actual member variable name. The symbol is |
| 494 | reminding of a <code>printf()</code> format symbol, and |
| 495 | in fact it has a similar effect. If you add a % sign |
| 496 | followed by any one format name or abbreviation from the |
| 497 | above table after an expression path, the resulting |
Enrico Granata | e4e3e2c | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 498 | object will be displyed using the chosen format.</p> |
| 499 | |
| 500 | <p>You can also use some other special format markers, not available |
| 501 | for type formatters, but which carry a special meaning when used in this |
| 502 | context:</p> |
| 503 | |
| 504 | <table border="1"> |
| 505 | <tbody> |
| 506 | <tr valign="top"> |
| 507 | <td width="23%"><b>Symbol</b></td> |
| 508 | <td><b>Description</b></td> |
| 509 | </tr> |
| 510 | <tr valign="top"> |
| 511 | <td><b>%S</b></td> |
| 512 | <td>Use this object's summary (the default for aggregate types)</td> |
| 513 | </tr> |
| 514 | <tr valign="top"> |
| 515 | <td><b>%V</b></td> |
| 516 | <td>Use this object's value (the default for non-aggregate types)</td> |
| 517 | </tr> |
| 518 | <tr valign="top"> |
| 519 | <td><b>%@</b></td> |
| 520 | <td>Use a language-runtime specific description (for C++ this does nothing, |
| 521 | for Objective-C it calls the NSPrintForDebugger API)</td> |
| 522 | </tr> |
| 523 | <tr valign="top"> |
| 524 | <td><b>%L</b></td> |
| 525 | <td>Use this object's location (memory address, register name, ...)</td> |
| 526 | </tr> |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 527 | <tr valign="top"> |
| 528 | <td><b>%#</b></td> |
| 529 | <td>Use the count of the children of this object</td> |
| 530 | </tr> |
| 531 | <tr valign="top"> |
| 532 | <td><b>%T</b></td> |
| 533 | <td>Use this object's datatype name</td> |
| 534 | </tr> |
Enrico Granata | e4e3e2c | 2011-07-22 00:16:08 +0000 | [diff] [blame] | 535 | </tbody> |
| 536 | </table> |
| 537 | |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 538 | <p>As previously said, pointers and values are treated the |
| 539 | same way when getting to their members in an expression |
| 540 | path. However, if your expression path leads to a |
| 541 | pointer, LLDB will not automatically dereference it. In |
| 542 | order to obtain The deferenced value for a pointer, your |
| 543 | expression path must start with <code>${*var</code> |
| 544 | instead of <code>${var</code>. Because there is no need |
| 545 | to dereference pointers along your way, the |
| 546 | dereferencing symbol only applies to the result of the |
| 547 | whole expression path traversing. <br> |
| 548 | e.g. <code> <br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 549 | <b>(lldb)</b> frame variable -T c<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 550 | (Couple) c = {<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 551 | (SimpleWithPointers) sp = {<br> |
| 552 | (int *) x = 0x00000001001000b0<br> |
| 553 | (float *) y = 0x00000001001000c0<br> |
| 554 | (char *) z = 0x00000001001000d0 "X"<br> |
| 555 | }<br> |
| 556 | (Simple *) s = 0x00000001001000e0<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 557 | }<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 558 | </code><br> |
| 559 | |
| 560 | If one types the following commands: |
| 561 | |
| 562 | <table class="stats" width="620" cellspacing="0"> |
| 563 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 564 | <b>(lldb)</b> type summary add --summary-string "int = ${*var.sp.x}, |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 565 | float = ${*var.sp.y}, char = ${*var.sp.z%u}, Simple = |
| 566 | ${*var.s}" Couple<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 567 | <b>(lldb)</b> type summary add -c -p Simple<br> |
| 568 | </td> |
| 569 | <table><br> |
| 570 | |
| 571 | the output becomes: <br><code> |
| 572 | |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 573 | <b>(lldb)</b> frame variable c<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 574 | (Couple) c = int = 9, float = 9.99, char = 88, Simple |
| 575 | = (x=9, y=9.99, z='X')<br> |
| 576 | </code> </p> |
| 577 | <p>Option <code>-c</code> to <code>type summary add</code> |
| 578 | tells LLDB not to look for a summary string, but instead |
| 579 | to just print a listing of all the object's children on |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 580 | one line, as shown in the summary for object Simple.</p> |
| 581 | <p> We are using the <code>-p</code> flag here to show that |
| 582 | aggregate types can be dereferenced as well as basic types. |
| 583 | The following command sequence would work just as well and |
| 584 | produce the same output: |
| 585 | <table class="stats" width="620" cellspacing="0"> |
| 586 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 587 | <b>(lldb)</b> type summary add --summary-string "int = ${*var.sp.x}, |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 588 | float = ${*var.sp.y}, char = ${*var.sp.z%u}, Simple = |
| 589 | ${var.s}" Couple<br> |
| 590 | <b>(lldb)</b> type summary add -c Simple<br> |
| 591 | </td> |
| 592 | <table><br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 593 | </div> |
| 594 | </div> |
| 595 | <div class="post"> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 596 | <h1 class="postheader">Bitfields and array syntax</h1> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 597 | <div class="postcontent"> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 598 | <p>Sometimes, a basic type's value actually represents |
| 599 | several different values packed together in a bitfield. |
| 600 | With the classical view, there is no way to look at |
| 601 | them. Hexadecimal display can help, but if the bits |
| 602 | actually span byte boundaries, the help is limited. |
| 603 | Binary view would show it all without ambiguity, but is |
| 604 | often too detailed and hard to read for real-life |
| 605 | scenarios. To cope with the issue, LLDB supports native |
| 606 | bitfield formatting in summary strings. If your |
| 607 | expression paths leads to a so-called <i>scalar type</i> |
| 608 | (the usual int, float, char, double, short, long, long |
| 609 | long, double, long double and unsigned variants), you |
| 610 | can ask LLDB to only grab some bits out of the value and |
| 611 | display them in any format you like. The syntax is |
| 612 | similar to that used for arrays, just you can also give |
| 613 | a pair of indices separated by a <code>-</code>. <br> |
| 614 | e.g. <br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 615 | <code> <b>(lldb)</b> frame variable float_point<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 616 | (float) float_point = -3.14159<br> </code> |
| 617 | <table class="stats" width="620" cellspacing="0"> |
| 618 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 619 | <b>(lldb)</b> type summary add --summary-string "Sign: ${var[31]%B} |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 620 | Exponent: ${var[30-23]%x} Mantissa: ${var[0-22]%u}" |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 621 | float |
| 622 | </td> |
| 623 | <table><br> |
| 624 | |
| 625 | <code> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 626 | <b>(lldb)</b> frame variable float_point<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 627 | (float) float_point = -3.14159 Sign: true Exponent: |
| 628 | 0x00000080 Mantissa: 4788184<br> |
| 629 | </code> In this example, LLDB shows the internal |
| 630 | representation of a <code>float</code> variable by |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 631 | extracting bitfields out of a float object.</p> |
| 632 | |
| 633 | <p> As far as the syntax is concerned, it looks |
| 634 | much like the normal C array syntax, but also allows you |
| 635 | to specify 2 indices, separated by a - symbol (a range). |
| 636 | Ranges can be given either with the lower or the higher index |
| 637 | first, and range extremes are always included in the bits extracted. </p> |
| 638 | |
| 639 | <p>LLDB also allows to use a similar syntax to display |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 640 | array members inside a summary string. For instance, you |
| 641 | may want to display all arrays of a given type using a |
| 642 | more compact notation than the default, and then just |
| 643 | delve into individual array members that prove |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 644 | interesting to your debugging task. You can tell |
| 645 | LLDB to format arrays in special ways, possibly |
| 646 | independent of the way the array members' datatype is formatted. <br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 647 | e.g. <br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 648 | <code> <b>(lldb)</b> frame variable sarray<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 649 | (Simple [3]) sarray = {<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 650 | [0] = {<br> |
| 651 | x = 1<br> |
| 652 | y = 2<br> |
| 653 | z = '\x03'<br> |
| 654 | }<br> |
| 655 | [1] = {<br> |
| 656 | x = 4<br> |
| 657 | y = 5<br> |
| 658 | z = '\x06'<br> |
| 659 | }<br> |
| 660 | [2] = {<br> |
| 661 | x = 7<br> |
| 662 | y = 8<br> |
| 663 | z = '\t'<br> |
| 664 | }<br> |
| 665 | }<br></code> |
| 666 | |
| 667 | <table class="stats" width="620" cellspacing="0"> |
| 668 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 669 | <b>(lldb)</b> type summary add --summary-string "${var[].x}" "Simple |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 670 | [3]" |
| 671 | </td> |
| 672 | <table><br> |
| 673 | |
| 674 | <code> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 675 | <b>(lldb)</b> frame variable sarray<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 676 | (Simple [3]) sarray = [1,4,7]<br></code></p> |
| 677 | |
| 678 | <p>The <code>[]</code> symbol amounts to: <i>if <code>var</code> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 679 | is an array and I knows its size, apply this summary |
| 680 | string to every element of the array</i>. Here, we are |
| 681 | asking LLDB to display <code>.x</code> for every |
| 682 | element of the array, and in fact this is what happens. |
| 683 | If you find some of those integers anomalous, you can |
| 684 | then inspect that one item in greater detail, without |
| 685 | the array format getting in the way: <br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 686 | <code> <b>(lldb)</b> frame variable sarray[1]<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 687 | (Simple) sarray[1] = {<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 688 | x = 4<br> |
| 689 | y = 5<br> |
| 690 | z = '\x06'<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 691 | }<br> |
| 692 | </code> </p> |
| 693 | <p>You can also ask LLDB to only print a subset of the |
| 694 | array range by using the same syntax used to extract bit |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 695 | for bitfields: |
| 696 | <table class="stats" width="620" cellspacing="0"> |
| 697 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 698 | <b>(lldb)</b> type summary add --summary-string "${var[1-2].x}" "Simple |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 699 | [3]" |
| 700 | </td> |
| 701 | <table><br> |
| 702 | <code> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 703 | <b>(lldb)</b> frame variable sarray<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 704 | (Simple [3]) sarray = [4,7]<br></code></p> |
| 705 | |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 706 | <p>The same logic works if you are printing a pointer |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 707 | instead of an array, however in this latter case, the empty |
| 708 | square brackets operator <code>[]</code> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 709 | cannot be used and you need to give exact range limits.</p> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 710 | |
| 711 | <p>In general, LLDB needs the square brackets operator <code>[]</code> in |
| 712 | order to handle arrays and pointers correctly, and for pointers it also |
| 713 | needs a range. However, a few special cases are defined to make your life easier: |
| 714 | <ul> |
| 715 | <li>you can print a 0-terminated string (<i>C-string</i>) using the %s format, |
| 716 | omitting square brackets, as in: |
| 717 | <table class="stats" width="620" cellspacing="0"> |
| 718 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 719 | <b>(lldb)</b> type summary add --summary-string "${var%s}" "char *" |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 720 | </td> |
| 721 | <table> |
Enrico Granata | de51233 | 2011-08-24 01:49:09 +0000 | [diff] [blame] | 722 | <p> |
| 723 | This syntax works for <code>char*</code> as well as for <code>char[]</code> |
| 724 | because LLDB can rely on the final <code>\0</code> terminator to know when the string |
| 725 | has ended.</p> |
| 726 | LLDB has default summary strings for <code>char*</code> and <code>char[]</code> that use |
| 727 | this special case. On debugger startup, the following are defined automatically: |
| 728 | <table class="stats" width="620" cellspacing="0"> |
| 729 | <td class="content"> |
| 730 | <b>(lldb)</b> type summary add --summary-string "${var%s}" "char *"<br/> |
| 731 | <b>(lldb)</b> type summary add --summary-string "${var%s}" -x "char \[[0-9]+]"<br/> |
| 732 | </td> |
| 733 | <table> |
| 734 | </li> |
| 735 | </ul> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 736 | <ul> |
| 737 | |
Enrico Granata | de51233 | 2011-08-24 01:49:09 +0000 | [diff] [blame] | 738 | <li>any of the array formats (<code>int8_t[]</code>, |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 739 | <code>float32{}</code>, ...), and the <code>y</code>, <code>Y</code> |
| 740 | and <code>a</code> formats |
| 741 | work to print an array of a non-aggregate |
| 742 | type, even if square brackets are omitted. |
| 743 | <table class="stats" width="620" cellspacing="0"> |
| 744 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 745 | <b>(lldb)</b> type summary add --summary-string "${var%int32_t[]}" "int [10]" |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 746 | </td> |
| 747 | <table> |
| 748 | |
| 749 | </ul> |
| 750 | This feature, however, is not enabled for pointers because there is no |
| 751 | way for LLDB to detect the end of the pointed data. |
| 752 | <br> |
| 753 | This also does not work for other formats (e.g. <code>boolean</code>), and you must |
| 754 | specify the square brackets operator to get the expected output. |
| 755 | </p> |
| 756 | </div> |
| 757 | </div> |
| 758 | |
| 759 | <div class="post"> |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 760 | <h1 class="postheader">Python scripting</h1> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 761 | <div class="postcontent"> |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 762 | |
| 763 | <p>Most of the times, summary strings prove good enough for the job of summarizing |
| 764 | the contents of a variable. However, as soon as you need to do more than picking |
| 765 | some values and rearranging them for display, summary strings stop being an |
| 766 | effective tool. This is because summary strings lack the power to actually perform |
| 767 | some computation on the value of variables.</p> |
| 768 | <p>To solve this issue, you can bind some Python scripting code as a summary for |
| 769 | your datatype, and that script has the ability to both extract children variables |
| 770 | as the summary strings do and to perform active computation on the extracted |
| 771 | values. As a small example, let's say we have a Rectangle class:</p> |
| 772 | |
| 773 | <code> |
| 774 | class Rectangle<br/> |
| 775 | {<br/> |
| 776 | private:<br/> |
| 777 | int height;<br/> |
| 778 | int width;<br/> |
| 779 | public:<br/> |
| 780 | Rectangle() : height(3), width(5) {}<br/> |
| 781 | Rectangle(int H) : height(H), width(H*2-1) {}<br/> |
| 782 | Rectangle(int H, int W) : height(H), width(W) {}<br/> |
| 783 | |
| 784 | int GetHeight() { return height; }<br/> |
| 785 | int GetWidth() { return width; }<br/> |
| 786 | |
| 787 | };<br/> |
| 788 | </code> |
| 789 | |
| 790 | <p>Summary strings are effective to reduce the screen real estate used by |
| 791 | the default viewing mode, but are not effective if we want to display the |
| 792 | area, perimeter and length of diagonal of <code>Rectangle</code> objects</p> |
| 793 | |
| 794 | <p>To obtain this, we can simply attach a small Python script to the <code>Rectangle</code> |
| 795 | class, as shown in this example:</p> |
| 796 | |
| 797 | <table class="stats" width="620" cellspacing="0"> |
| 798 | <td class="content"> |
| 799 | <b>(lldb)</b> type summary add -P Rectangle<br/> |
| 800 | Enter your Python command(s). Type 'DONE' to end.<br/> |
| 801 | def function (valobj,dict):<br/> |
| 802 | height_val = valobj.GetChildMemberWithName('height')<br/> |
| 803 | width_val = valobj.GetChildMemberWithName('width')<br/> |
| 804 | height_str = height_val.GetValue()<br/> |
| 805 | width_str = width_val.GetValue()<br/> |
| 806 | height = int(height_str)<br/> |
| 807 | width = int(width_str)<br/> |
| 808 | area = height*width<br/> |
| 809 | perimeter = 2*height + 2*width<br/> |
| 810 | diag = sqrt(height*height+width*width)<br/> |
| 811 | return 'Area: ' + str(area) + ', Perimeter: ' + str(perimeter) + ', Diagonal: ' + str(diag)<br/> |
| 812 | DONE<br/> |
| 813 | <b>(lldb)</b> script<br/> |
| 814 | Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.<br/> |
| 815 | >>> from math import sqrt<br/> |
| 816 | >>> quit()<br/> |
| 817 | <b>(lldb)</b> frame variable<br/> |
| 818 | (Rectangle) r1 = Area: 20, Perimeter: 18, Diagonal: 6.40312423743<br/> |
| 819 | (Rectangle) r2 = Area: 72, Perimeter: 36, Diagonal: 13.416407865<br/> |
| 820 | (Rectangle) r3 = Area: 16, Perimeter: 16, Diagonal: 5.65685424949<br/> |
| 821 | </td> |
| 822 | </table> |
| 823 | |
| 824 | <p>In this scenario, you need to enter the interactive interpreter to import the |
| 825 | function sqrt() from the math library. As the example shows, everything you enter |
| 826 | into the interactive interpreter is saved for you to use it in scripts. This way |
| 827 | you can define your own utility functions and use them in your summary scripts if |
| 828 | necessary.</p> |
| 829 | |
| 830 | <p>In order to write effective summary scripts, you need to know the LLDB public |
| 831 | API, which is the way Python code can access the LLDB object model. For further |
| 832 | details on the API you should look at <a href="scripting.html">this page</a>, or at |
| 833 | the LLDB <a href="docs.html">doxygen documentation</a> when it becomes available.</p> |
| 834 | |
| 835 | <p>As a brief introduction, your script is encapsulated into a function that is |
| 836 | passed two parameters: <code>valobj</code> and <code>dict</code>.</p> |
| 837 | |
| 838 | <p><code>dict</code> is an internal support parameter used by LLDB and you should |
| 839 | not use it.<br/><code>valobj</code> is the object encapsulating the actual |
| 840 | variable being displayed, and its type is SBValue. The most important thing you can |
| 841 | do with an SBValue is retrieve its children objects, by calling |
| 842 | <code>GetChildMemberWithName()</code>, passing it the child's name as a string, or ask |
| 843 | it for its value, by calling <code>GetValue()</code>, which returns a Python string. |
| 844 | </p> |
| 845 | |
| 846 | <p>If you need to delve into several levels of hierarchy, as you can do with summary |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 847 | strings, you can use the method <code>GetValueForExpressionPath()</code>, passing it |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 848 | an expression path just like those you could use for summary strings. However, if you need |
| 849 | to access array slices, you cannot do that (yet) via this method call, and you must |
| 850 | use <code>GetChildMemberWithName()</code> querying it for the array items one by one. |
| 851 | |
| 852 | <p>Other than interactively typing a Python script there are two other ways for you |
| 853 | to input a Python script as a summary: |
| 854 | |
| 855 | <ul> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 856 | <li> using the --python-script option to <code>type summary add </code> and typing the script |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 857 | code as an option argument; as in: </ul> |
| 858 | |
| 859 | <table class="stats" width="620" cellspacing="0"> |
| 860 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 861 | <b>(lldb)</b> type summary add --python-script "height = |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 862 | int(valobj.GetChildMemberWithName('height').GetValue());width = |
| 863 | int(valobj.GetChildMemberWithName('width').GetValue()); |
| 864 | return 'Area: ' + str(height*width)" Rectangle<br/> |
| 865 | </td> |
| 866 | </table> |
| 867 | <ul> |
| 868 | <li> using the -F option to <code>type summary add </code> and giving the name of a |
| 869 | Python function with the correct prototype. Most probably, you will define (or have |
| 870 | already defined) the function in the interactive interpreter, or somehow |
| 871 | loaded it from a file. |
| 872 | </ul> |
| 873 | |
| 874 | </p> |
| 875 | |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 876 | </div> |
| 877 | </div> |
| 878 | |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 879 | <div class="post"> |
| 880 | <h1 class="postheader">Regular expression typenames</h1> |
| 881 | <div class="postcontent"> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 882 | <p>As you noticed, in order to associate the custom |
| 883 | summary string to the array types, one must give the |
| 884 | array size as part of the typename. This can long become |
| 885 | tiresome when using arrays of different sizes, <code>Simple |
| 886 | |
| 887 | [3]</code>, <code>Simple [9]</code>, <code>Simple |
| 888 | [12]</code>, ...</p> |
| 889 | <p>If you use the <code>-x</code> option, type names are |
| 890 | treated as regular expressions instead of type names. |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 891 | This would let you rephrase the above example |
| 892 | for arrays of type <code>Simple [3]</code> as: <br> |
| 893 | |
| 894 | <table class="stats" width="620" cellspacing="0"> |
| 895 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 896 | <b>(lldb)</b> type summary add --summary-string "${var[].x}" |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 897 | -x "Simple \[[0-9]+\]" |
| 898 | </td> |
| 899 | <table> |
| 900 | |
| 901 | <code> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 902 | <b>(lldb)</b> frame variable sarray<br> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 903 | (Simple [3]) sarray = [1,4,7]<br> |
| 904 | </code> The above scenario works for <code>Simple [3]</code> |
| 905 | as well as for any other array of <code>Simple</code> |
| 906 | objects. </p> |
| 907 | <p>While this feature is mostly useful for arrays, you |
| 908 | could also use regular expressions to catch other type |
| 909 | sets grouped by name. However, as regular expression |
| 910 | matching is slower than normal name matching, LLDB will |
| 911 | first try to match by name in any way it can, and only |
| 912 | when this fails, will it resort to regular expression |
| 913 | matching. Thus, if your type has a base class with a |
| 914 | cascading summary, this will be preferred over any |
| 915 | regular expression match for your type itself.</p> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 916 | |
| 917 | <p>The regular expression language used by LLDB is <a href="http://en.wikipedia.org/wiki/Regular_expression#POSIX_Extended_Regular_Expressions">the POSIX extended regular expression language</a>, as defined by <a href="http://pubs.opengroup.org/onlinepubs/7908799/xsh/regex.h.html">the SUS</a>. |
| 918 | |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 919 | </div> |
| 920 | </div> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 921 | |
| 922 | <div class="post"> |
| 923 | <h1 class="postheader">Named summaries</h1> |
| 924 | <div class="postcontent"> |
| 925 | <p>For a given datatype, there may be different meaningful summary |
| 926 | representations. However, currently, only one summary can be associated |
| 927 | to a given datatype. If you need to temporarily override the association |
| 928 | for a variable, without changing the summary string bound to the datatype, |
| 929 | you can use named summaries.</p> |
| 930 | |
| 931 | <p>Named summaries work by attaching a name to a summary string when creating |
| 932 | it. Then, when there is a need to attach the summary string to a variable, the |
| 933 | <code>frame variable</code> command, supports a <code>--summary</code> option |
| 934 | that tells LLDB to use the named summary given instead of the default one.</p> |
| 935 | |
| 936 | <table class="stats" width="620" cellspacing="0"> |
| 937 | <td class="content"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 938 | <b>(lldb)</b> type summary add --summary-string "x=${var.integer}" --name NamedSummary |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 939 | </td> |
| 940 | <table> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 941 | <code> <b>(lldb)</b> frame variable one<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 942 | (i_am_cool) one = int = 3, float = 3.14159, char = 69<br> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 943 | <b>(lldb)</b> frame variable one --summary NamedSummary<br> |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 944 | (i_am_cool) one = x=3<br> |
| 945 | </code> </p> |
| 946 | |
Enrico Granata | f7a9b14 | 2011-07-15 02:26:42 +0000 | [diff] [blame] | 947 | <p>When defining a named summmary, binding it to one or more types becomes optional. |
| 948 | Even if you bind the named summary to a type, and later change the summary string |
| 949 | for that type, the named summary will not be changed by that. You can delete |
| 950 | named summaries by using the <code>type summary delete</code> command, as if the |
| 951 | summary name was the datatype that the summary is applied to</p> |
| 952 | |
| 953 | <p>A summary attached to a variable using the </code>--summary</code> option, |
| 954 | has the same semantics that a custom format attached using the <code>-f</code> |
| 955 | option has: it stays attached till you attach a new one, or till you let |
| 956 | your program run again.</p> |
| 957 | |
Enrico Granata | ede7bdf | 2011-07-13 00:00:57 +0000 | [diff] [blame] | 958 | </div> |
| 959 | </div> |
| 960 | |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 961 | <div class="post"> |
| 962 | <h1 class="postheader">Synthetic children</h1> |
| 963 | <div class="postcontent"> |
| 964 | <p>Summaries work well when one is able to navigate through an expression path. |
| 965 | In order for LLDB to do so, appropriate debugging information must be available.</p> |
| 966 | <p>Some types are <i>opaque</i>, i.e. no knowledge of their internals is provided. |
| 967 | When that's the case, expression paths do not work correctly.</p> |
| 968 | <p>In other cases, the internals are available to use in expression paths, but they |
| 969 | do not provide a user-friendly representation of the object's value.</p> |
| 970 | <p>For instance, consider an STL vector:</p> |
| 971 | <code> |
| 972 | <b>(lldb)</b> frame variable numbers -T<br/> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 973 | (std::vector<int>) numbers = {<br/> |
| 974 | (std::_Vector_base<int, std::allocator<int> >) std::_Vector_base<int, std::allocator<int> > = {<br/> |
| 975 | (std::_Vector_base<int, std::allocator&tl;int> >::_Vector_impl) _M_impl = {<br/> |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 976 | (int *) _M_start = 0x00000001001008a0<br/> |
| 977 | (int *) _M_finish = 0x00000001001008a8<br/> |
| 978 | (int *) _M_end_of_storage = 0x00000001001008a8<br/> |
| 979 | }<br/> |
| 980 | }<br/> |
| 981 | }<br/> |
| 982 | </code> |
| 983 | <p>Here, you can see how the type is implemented, and you can write a summary for that implementation |
| 984 | but that is not going to help you infer what items are actually stored in the vector.</p> |
| 985 | <p>What you would like to see is probably something like:</p> |
| 986 | <code> |
| 987 | <b>(lldb)</b> frame variable numbers -T<br/> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 988 | (std::vector<int>) numbers = {<br/> |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 989 | (int) [0] = 1<br/> |
| 990 | (int) [1] = 12<br/> |
| 991 | (int) [2] = 123<br/> |
| 992 | (int) [3] = 1234<br/> |
| 993 | }<br/> |
| 994 | </code> |
| 995 | <p>Synthetic children are a way to get that result.</p> |
| 996 | <p>The feature is based upon the idea of providing a new set of children for a variable that replaces the ones |
| 997 | available by default through the debug information. In the example, we can use synthetic children to provide |
| 998 | the vector items as children for the std::vector object.</p> |
| 999 | <p>In order to create synthetic children, you need to provide a Python class that adheres to a given <i>interface</i> |
| 1000 | (the word is italicized because Python has no explicit notion of interface. By that word we mean a given set of methods |
| 1001 | must be implemented by the Python class):</p> |
| 1002 | <code> |
| 1003 | <font color=blue>class</font> SyntheticChildrenProvider:<br/> |
| 1004 | <font color=blue>def</font> __init__(self, valobj, dict):<br/> |
| 1005 | this call should initialize the Python object using valobj as the variable to provide synthetic children for <br/> |
| 1006 | <font color=blue>def</font> num_children(self): <br/> |
| 1007 | this call should return the number of children that you want your object to have <br/> |
| 1008 | <font color=blue>def</font> get_child_index(self,name): <br/> |
| 1009 | this call should return the index of the synthetic child whose name is given as argument <br/> |
| 1010 | <font color=blue>def</font> get_child_at_index(self,index): <br/> |
| 1011 | this call should return a new LLDB SBValue object representing the child at the index given as argument <br/> |
| 1012 | <font color=blue>def</font> update(self): <br/> |
| 1013 | this call should be used to update the internal state of this Python object whenever the state of the variables in LLDB changes. |
| 1014 | Currently this method is optional, because the internal state of synthetic children providers will not be preserved. However, this is meant to change in future versions |
| 1015 | of LLDB.<br/> |
| 1016 | </code> |
Enrico Granata | 7e65503 | 2011-08-24 01:32:46 +0000 | [diff] [blame] | 1017 | <p>For examples of how synthetic children are created, you are encouraged to look at <a href="http://llvm.org/svn/llvm-project/lldb/trunk/examples/synthetic/">examples/synthetic</a> in the LLDB trunk. |
| 1018 | You may especially want to begin looking at <a href="http://llvm.org/svn/llvm-project/lldb/trunk/examples/synthetic/StdVectorSynthProvider.py">StdVector</a> to get |
| 1019 | a feel for this feature.</p> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1020 | |
| 1021 | <p>Once a synthetic children provider is written, one must load it into LLDB before it can be used. |
| 1022 | Currently, one can use the LLDB <code>script</code> command to type Python code interactively, |
| 1023 | or use the <code>script import <i>module</i></code> command to load Python code from a Python module |
| 1024 | (ordinary rules apply to importing modules this way). A third option is to type the code for |
| 1025 | the provider class interactively while adding it.</p> |
| 1026 | |
| 1027 | <p>For example, let's pretend we have a class Foo for which a synthetic children provider class Foo_Provider |
| 1028 | is available, in a Python module named Foo_Tools. The following interaction sets Foo_Provider as a synthetic |
| 1029 | children provider in LLDB:</p> |
| 1030 | |
| 1031 | <table class="stats" width="620" cellspacing="0"> |
| 1032 | <td class="content"> |
| 1033 | <b>(lldb)</b> script import Foo_Tools<br/> |
| 1034 | <b>(lldb)</b> type synthetic add Foo --python-class Foo_Tools.Foo_Provider |
| 1035 | </td> |
| 1036 | <table> |
| 1037 | <code> <b>(lldb)</b> frame variable a_foo<br/> |
| 1038 | (Foo) a_foo = {<br/> |
| 1039 | x = 1<br/> |
| 1040 | y = "Hello world"<br/> |
| 1041 | } <br/> |
| 1042 | </code> </p> |
| 1043 | |
| 1044 | <p>Currently, in LLDB <a href="http://llvm.org/svn/llvm-project/lldb/trunk/">top of tree</a>, synthetic children providers are enabled for |
| 1045 | <code>std::vector<T></code>, <code>std::list<T></code> and <code>std::map<K,V></code>.</p> |
| 1046 | |
| 1047 | <p>Synthetic children enable a new symbol for summary strings, <code>${svar</code>. This symbol tells LLDB to refer expression paths to the |
| 1048 | synthetic children instead of the real ones. While in certain cases, you can use <code>${var.<i>synthetic-child-path</i>}</code> and LLDB will |
| 1049 | access the synthetic child correctly, it is best to always use <code>${svar</code> to refer to synthetic children. For instance,</p> |
| 1050 | |
| 1051 | <table class="stats" width="620" cellspacing="0"> |
| 1052 | <td class="content"> |
| 1053 | <b>(lldb)</b> type summary add --expand -x "std::vector<" --summary-string "${svar%#} items" |
| 1054 | </td> |
| 1055 | <table> |
| 1056 | <code> <b>(lldb)</b> frame variable numbers<br/> |
| 1057 | (std::vector<int>) numbers = 4 items {<br/> |
| 1058 | (int) [0] = 1<br/> |
| 1059 | (int) [1] = 12<br/> |
| 1060 | (int) [2] = 123<br/> |
| 1061 | (int) [3] = 1234<br/> |
| 1062 | }<br/> |
| 1063 | </code> </p> |
| 1064 | |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 1065 | </div> |
| 1066 | </div> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1067 | |
| 1068 | <div class="post"> |
| 1069 | <h1 class="postheader">Filters</h1> |
| 1070 | <div class="postcontent"> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1071 | <p>Filters are a solution to the display of complex classes. |
| 1072 | At times, classes have many member variables but not all of these are actually |
| 1073 | necessary for the user to see.</p> |
| 1074 | <p>A filter will solve this issue by only letting the user see those member |
| 1075 | variables he cares about. Of course, the equivalent of a filter can be implemented easily |
| 1076 | using synthetic children, but a filter lets you get the job done without having to write |
| 1077 | Python code.</p> |
| 1078 | <p>For instance, if your class <code>Foobar</code> has member variables named <code>A</code> thru <code>Z</code>, but you only need to see |
| 1079 | the ones named <code>B</code>, <code>H</code> and <code>Q</code>, you can define a filter: |
| 1080 | <table class="stats" width="620" cellspacing="0"> |
| 1081 | <td class="content"> |
| 1082 | <b>(lldb)</b> type filter add Foo --child B --child H --child Q |
| 1083 | </td> |
Enrico Granata | 097e555 | 2011-08-24 04:53:31 +0000 | [diff] [blame^] | 1084 | </table> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1085 | <code> <b>(lldb)</b> frame variable a_foobar<br/> |
| 1086 | (Foobar) a_foobar = {<br/> |
| 1087 | (int) B = 1<br/> |
| 1088 | (char) H = 'H'<br/> |
| 1089 | (std::string) Q = "Hello world"<br/> |
| 1090 | }<br/> |
| 1091 | </code> </p> |
Enrico Granata | 097e555 | 2011-08-24 04:53:31 +0000 | [diff] [blame^] | 1092 | </div> |
| 1093 | </div> |
| 1094 | |
| 1095 | <div class="post"> |
| 1096 | <h1 class="postheader">Objective-C dynamic type discovery</h1> |
| 1097 | <div class="postcontent"> |
| 1098 | <p>When doing Objective-C development, you may notice that some of your variables |
| 1099 | come out as of type <code>id</code>. While this does not influence the ability |
| 1100 | of the runtime to send messages to them, it can make it impossible for LLDB |
| 1101 | to determine the actual formatters for that object.</p> |
| 1102 | <p>The debugger, however, can dynamically discover the type of an Objective-C |
| 1103 | variable, much like the runtime itself does when invoking a selector. In order |
| 1104 | to let LLDB do that, however, a special option to <code>frame variable</code> is |
| 1105 | required: <code>--dynamic-type</code>.</p> |
| 1106 | <p><code>--dynamic-type</code> can have one of three values: |
| 1107 | <ul> |
| 1108 | <li><code>no-dynamic-values</code>: the default, prevents dynamic type discovery</li> |
| 1109 | <li><code>no-run-target</code>: enables dynamic type discovery as long as running |
| 1110 | code on the target is not required</li> |
| 1111 | <li><code>run-target</code>: enables code execution on the target in order to perform |
| 1112 | dynamic type discovery</li> |
| 1113 | </ul> |
| 1114 | </p> |
| 1115 | <p> |
| 1116 | If you specify a value of either <code>no-run-target</code> or <code>run-target</code>, |
| 1117 | LLDB will detect the dynamic type of your variables and show the appropriate formatters |
| 1118 | for them. As an example: |
| 1119 | </p> |
| 1120 | <p><table class="stats" width="620" cellspacing="0"> |
| 1121 | <td class="content"> |
| 1122 | <b>(lldb)</b> frame variable ns_string --dynamic-type no-run-target --show-types |
| 1123 | </td> |
| 1124 | </table> |
| 1125 | <code>(id, dynamic type: __NSCFString) ns_string = 0x00000001001183d0 @"An NSString saying hello world"<br/> |
| 1126 | </code> |
| 1127 | <p> |
| 1128 | Because LLDB uses a detection algorithm that does not need to invoke any functions |
| 1129 | on the target process, <code>no-run-target</code> is enough for this to work. |
| 1130 | As a final sidenote on this, LLDB is currently able to provide a summary string for <code>NSString</code> |
| 1131 | that shows the content of the string, without requiring you to run code on the target |
| 1132 | process. <a href="http://llvm.org/svn/llvm-project/lldb/trunk/examples/synthetic/CFString.py"> |
| 1133 | CFString.py</a> contains the code for such a Python summary provider (the code is well commented, |
| 1134 | but you may find it hard to follow if it is your first time dealing with LLDB formatting features) |
| 1135 | and <a href="http://llvm.org/svn/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-objc/"> |
| 1136 | this test case</a> contains an usage example. |
| 1137 | </p> |
Enrico Granata | ef1923d | 2011-08-23 21:26:09 +0000 | [diff] [blame] | 1138 | </div> |
| 1139 | </div> |
| 1140 | |
Enrico Granata | 7e65503 | 2011-08-24 01:32:46 +0000 | [diff] [blame] | 1141 | <div class="post"> |
| 1142 | <h1 class="postheader">Categories</h1> |
| 1143 | <div class="postcontent"> |
| 1144 | <p>Categories are a way to group related formatters. For instance, LLDB itself groups |
| 1145 | the formatters for the C++ STL objects in a category named <code>gnu-libstdc++</code>. |
| 1146 | Basically, categories act like containers in which to store formatters for a same library |
| 1147 | or OS release.</p> |
| 1148 | <p>By default, three categories are created in LLDB: <code>system</code>, <code>gnu-libstdc++</code> and <code>default</code>. |
| 1149 | Every formatter that is not created inside a category, is by default a part of the <code>default</code> category. |
| 1150 | If you want to use a custom category for your formatters, all the <code>type ... add</code> (except for <code>type format add</code>), |
| 1151 | provide a <code>--category</code> (<code>-w</code>) option, that names the category to add the formatter to. |
| 1152 | To delete the formatter, you then have to specify the correct category.</p> |
| 1153 | <p>Categories can be in one of two states: enabled and disabled. A category is initially disabled, |
| 1154 | and can be enabled using the <code>type category enable</code> command. To disable an enabled category, |
| 1155 | the command to use is <code>type category disable</code>. The order in which categories are enabled or disabled |
| 1156 | is significant, in that LLDB uses that order when looking for formatters. Therefore, when you enable a category, it becomes |
| 1157 | the first one to be searched. The default categories are enabled in the order: <code>default</code> as first, then |
| 1158 | <code>gnu-libstdc++</code>, and finally <code>system</code>. As said, <code>gnu-libstdc++</code> contains formatters for C++ STL |
| 1159 | data types. <code>system</code> contains formatters for <code>char*</code> and <code>char[]</code>, which are expected to be |
| 1160 | consistent throughout libraries and systems, and replace </p> |
| 1161 | <p>Categories are a way to group related formatters. For instance, LLDB itself groups |
| 1162 | the formatters for the C++ STL objects in a category named <code>gnu-libstdc++</code></p> |
| 1163 | </div> |
| 1164 | </div> |
| 1165 | |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1166 | <div class="post"> |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 1167 | <h1 class="postheader">Finding formatters 101</h1> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1168 | <div class="postcontent"> |
| 1169 | <p>While the rules for finding an appropriate format for a |
| 1170 | type are relatively simple (just go through typedef |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 1171 | hierarchies), searching formatters for a type goes through |
Enrico Granata | 7e65503 | 2011-08-24 01:32:46 +0000 | [diff] [blame] | 1172 | a rather intricate set of rules. Namely, what happens is that LLDB |
| 1173 | starts looking in each enabled category, according to the order in which |
| 1174 | they were enabled (latest enabled first). In each category, LLDB does |
| 1175 | the following:</p> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1176 | <ul> |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 1177 | <li>If there is a formatter for the type of the variable, |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1178 | use it</li> |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 1179 | <li>If this object is a pointer, and there is a formatter |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1180 | for the pointee type that does not skip pointers, use |
| 1181 | it</li> |
| 1182 | <li>If this object is a reference, and there is a |
| 1183 | summary for the pointee type that does not skip |
| 1184 | references, use it</li> |
| 1185 | <li>If this object is an Objective-C class with a parent |
| 1186 | class, look at the parent class (and parent of parent, |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 1187 | ...). This phase can be based upon the actual type of |
| 1188 | the object as inferred by the value of its <code>isa</code> |
| 1189 | pointer, or upon the debugging information inferred by the |
| 1190 | debugger. The user can use the dynamic typing settings to |
| 1191 | elect one or the other behavior.</li> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1192 | <li>If this object is a C++ class with base classes, |
| 1193 | look at base classes (and bases of bases, ...)</li> |
| 1194 | <li>If this object is a C++ class with virtual base |
| 1195 | classes, look at the virtual base classes (and bases |
| 1196 | of bases, ...)</li> |
| 1197 | <li>If this object's type is a typedef, go through |
Enrico Granata | 86e7c3e | 2011-07-12 22:56:10 +0000 | [diff] [blame] | 1198 | typedef hierarchy (LLDB might not be able to do this if |
| 1199 | the compiler has not emitted enough information. If the |
| 1200 | required information to traverse typedef hierarchies is |
| 1201 | missing, type cascading will not work. The |
| 1202 | <a href="http://clang.llvm.org/">clang compiler</a>, |
| 1203 | part of the LLVM project, emits the correct debugging |
| 1204 | information for LLDB to cascade)</li> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1205 | <li>If everything has failed, repeat the above search, |
| 1206 | looking for regular expressions instead of exact |
| 1207 | matches</li> |
| 1208 | </ul> |
Enrico Granata | 7e65503 | 2011-08-24 01:32:46 +0000 | [diff] [blame] | 1209 | <p>If any of those attempts returned a valid formatter to be used, |
| 1210 | that one is used, and the search is terminated (without going to look |
| 1211 | in other categories). If nothing was found in the current category, the next |
| 1212 | enabled category is scanned according to the same algorithm. If there are no |
| 1213 | more enabled categories, the search has failed.</p> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1214 | </div> |
| 1215 | </div> |
| 1216 | <div class="post"> |
| 1217 | <h1 class="postheader">TODOs</h1> |
| 1218 | <div class="postcontent"> |
| 1219 | <ul> |
| 1220 | <li>There's no way to do multiple dereferencing, and you |
| 1221 | need to be careful what the dereferencing operation is |
| 1222 | binding to in complicated scenarios</li> |
Enrico Granata | 68506fb | 2011-08-22 16:10:25 +0000 | [diff] [blame] | 1223 | <li>Synthetic children providers cannot have a permanent state</li> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1224 | <li><code>type format add</code> does not support the <code>-x</code> |
| 1225 | option</li> |
Enrico Granata | 8a717e5 | 2011-07-19 02:34:21 +0000 | [diff] [blame] | 1226 | <strike><li>Object location cannot be printed in the summary |
| 1227 | string</li></strike> |
Enrico Granata | ff78238 | 2011-07-08 02:51:01 +0000 | [diff] [blame] | 1228 | </ul> |
| 1229 | </div> |
| 1230 | </div> |
| 1231 | </div> |
| 1232 | </div> |
| 1233 | </div> |
| 1234 | </body> |
| 1235 | </html> |