blob: dadc7c73a46d7f4be7d0604252da8024ce8ee535 [file] [log] [blame]
Enrico Granataff782382011-07-08 02:51:01 +00001<!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 &nbsp;&nbsp;&nbsp;&nbsp;(int *) x = 0x0000000100100120<br>
30 &nbsp;&nbsp;&nbsp;&nbsp;(float *) y =
31 0x0000000100100130<br>
32 &nbsp;&nbsp;&nbsp;&nbsp;(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 -&gt; -1, y=0x0000000100100130
51 -&gt; -2, z="3")<br>
52 </code> </p>
53
54 <p>There are two kinds of printing options: <span
55 style="font-style: italic;">summary</span> and <span
56 style="font-style: italic;">format</span>. While a
57 detailed description of both will be given below, one
58 can briefly say that a summary is mainly used for
59 aggregate types, while a format is attached to primitive
60 types.</p>
61
62 <p>To reflect this, the the <b>type</b> command has two
63 subcommands:<br>
64 </p>
65
66 <p><code>type format</code></p>
67 <p><code>type summary</code></p>
68
69 <p>These commands are meant to bind printing options to
70 types. When variables are printed, LLDB will first check
71 if custom printing options have been associated to a
72 variable's type and, if so, use them instead of picking
73 the default choices.<br>
74 </p>
75
76 <p>The two commands <code>type format</code> and <code>type
77 summary</code> each have four subcommands:<br>
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
100 <p>This is done by typing <code>type format add -f hex
101 int</code> at the LLDB command line.</p>
102
103 <p>The <code>-f</code> option accepts a <a
104 href="#formatstable">format name</a>, and a list of
105 types to which you want the new format applied.</p>
106
107 <p>A frequent scenario is that your program has a <code>typedef</code>
108 for a numeric type that you know represents something
109 that must be printed in a certain way. Again, you can
110 add a format just to that typedef by using <code>type
111 format add</code> with the name alias.</p>
112
113 <p>But things can quickly get hierarchical. Let's say you
114 have a situation like the following:</p>
115
116 <p><code>typedef int A;<br>
117 typedef A B;<br>
118 typedef B C;<br>
119 typedef C D;<br>
120 </code></p>
121
122 <p>and you want to show all <code>A</code>'s as hex, all
123 <code>C'</code>s as pointers and leave the defaults
124 untouched for other types.</p>
125
126 <p>If you simply type <br>
127 <code>type format add -f hex A<br>
128 type format add -f pointer C</code><br>
129 <br>
130 values of type <code>B</code> will be shown as hex
131 and values of type <code>D</code> as pointers.</p>
132
133 <p>This is because by default LLDB <i>cascades</i>
134 formats through typedef chains. In order to avoid that
135 you can use the option <code>-C no</code> to prevent
136 cascading, thus making the two commands required to
137 achieve your goal:<br>
138 <code> type format add -f hex -C no A<br>
139 type format add -f pointer -C no C </code></p>
140
141 <p>Two additional options that you will want to look at
142 are <code>-p</code> and <code>-r</code>. These two
143 options prevent LLDB from applying a format for type <code>T</code>
144 to values of type <code>T*</code> and <code>T&amp;</code>
145 respectively.</p>
146
147 <p> <code> <b>(lldb)</b> type format add -f float32[]
148 int<br>
149 <b>(lldb)</b> fr var pointer *pointer -T<br>
150 (int *) pointer = {1.46991e-39 1.4013e-45}<br>
151 (int) *pointer = {1.53302e-42}<br>
152 <b>(lldb)</b> type format add -f float32[] int -p<br>
153 <b>(lldb)</b> fr var pointer *pointer -T<br>
154 (int *) pointer = 0x0000000100100180<br>
155 (int) *pointer = {1.53302e-42}<br>
156 </code> </p>
157
158 <p>As the previous example highlights, you will most
159 probably want to use <code>-p</code> for your formats.</p>
160
161 <p>If you need to delete a custom format simply type <code>type
162 format delete</code> followed by the name of the type
163 to which the format applies. To delete ALL formats, use
164 <code>type format clear</code>. To see all the formats
165 defined, type <code>type format list</code>.<br>
166 </p>
167
168 <p>If all you need to do, however, is display one variable
169 in a custom format, while leaving the others of the same
170 type untouched, you can simply type:<br>
171 <br>
172 <code>frame variable counter -f hex</code></p>
173
174 <p>This has the effect of displaying the value of <code>counter</code>
175 as an hexadecimal number, and will keep showing it this
176 way until you either pick a different format or till you
177 let your program run again.</p>
178
179 <p>Finally, this is a list of formatting options available
180 out of
181 which you can pick:</p><a name="formatstable"></a>
182 <table border="1">
183 <tbody>
184 <tr valign="top">
185 <td width="23%"><b>Format name</b></td>
186 <td><b>Abbreviation</b></td>
187 <td><b>Description</b></td>
188 </tr>
189 <tr valign="top">
190 <td><b>default</b></td>
191 <td><br>
192 </td>
193 <td>the default LLDB algorithm is used to pick a
194 format</td>
195 </tr>
196 <tr valign="top">
197 <td><b>boolean</b></td>
198 <td>B</td>
199 <td>show this as a true/false boolean, using the
200 customary rule that 0 is false and everything else
201 is true</td>
202 </tr>
203 <tr valign="top">
204 <td><b>binary</b></td>
205 <td>b</td>
206 <td>show this as a sequence of bits</td>
207 </tr>
208 <tr valign="top">
209 <td><b>bytes</b></td>
210 <td>y</td>
211 <td>show the bytes one after the other<br>
212 e.g. <code>(int) s.x = 07 00 00 00</code></td>
213 </tr>
214 <tr valign="top">
215 <td><b>bytes with ASCII</b></td>
216 <td>Y</td>
217 <td>show the bytes, but try to print them as ASCII
218 characters<br>
219 e.g. <code>(int *) c.sp.x = 50 f8 bf 5f ff 7f 00
220 00 P.._....</code></td>
221 </tr>
222 <tr valign="top">
223 <td><b>character</b></td>
224 <td>c</td>
225 <td>show the bytes printed as ASCII characters<br>
226 e.g. <code>(int *) c.sp.x =
227 P\xf8\xbf_\xff\x7f\0\0</code></td>
228 </tr>
229 <tr valign="top">
230 <td><b>printable character</b></td>
231 <td>C</td>
232 <td>show the bytes printed as printable ASCII
233 characters<br>
234 e.g. <code>(int *) c.sp.x = P.._....</code></td>
235 </tr>
236 <tr valign="top">
237 <td><b>complex float</b></td>
238 <td>F</td>
239 <td>interpret this value as the real and imaginary
240 part of a complex floating-point number<br>
241 e.g. <code>(int *) c.sp.x = 2.76658e+19 +
242 4.59163e-41i</code></td>
243 </tr>
244 <tr valign="top">
245 <td><b>c-string</b></td>
246 <td>s</td>
247 <td>show this as a 0-terminated C string</td>
248 </tr>
249 <tr valign="top">
250 <td><b>signed decimal</b></td>
251 <td>i</td>
252 <td>show this as a signed integer number (this does
253 not perform a cast, it simply shows the bytes as
254 signed integer)</td>
255 </tr>
256 <tr valign="top">
257 <td><b>enumeration</b></td>
258 <td>E</td>
259 <td>show this as an enumeration, printing the
260 value's name if available or the integer value
261 otherwise<br>
262 e.g. <code>(enum enumType) val_type = eValue2</code></td>
263 </tr>
264 <tr valign="top">
265 <td><b>hex</b></td>
266 <td>x</td>
267 <td>show this as in hexadecimal notation (this does
268 not perform a cast, it simply shows the bytes as
269 hex)</td>
270 </tr>
271 <tr valign="top">
272 <td><b>float</b></td>
273 <td>f</td>
274 <td>show this as a floating-point number (this does
275 not perform a cast, it simply interprets the bytes
276 as an IEEE754 floating-point value)</td>
277 </tr>
278 <tr valign="top">
279 <td><b>octal</b></td>
280 <td>o</td>
281 <td>show this in octal notation</td>
282 </tr>
283 <tr valign="top">
284 <td><b>OSType</b></td>
285 <td>O</td>
286 <td>show this as a MacOS OSType<br>
287 e.g. <code>(float) *c.sp.y = '\n\x1f\xd7\n'</code></td>
288 </tr>
289 <tr valign="top">
290 <td><b>unicode16</b></td>
291 <td>U</td>
292 <td>show this as UTF-16 characters<br>
293 e.g. <code>(float) *c.sp.y = 0xd70a 0x411f</code></td>
294 </tr>
295 <tr valign="top">
296 <td><b>unicode32</b></td>
297 <td><br>
298 </td>
299 <td>show this as UTF-32 characters<br>
300 e.g. <code>(float) *c.sp.y = 0x411fd70a</code></td>
301 </tr>
302 <tr valign="top">
303 <td><b>unsigned decimal</b></td>
304 <td>u</td>
305 <td>show this as an unsigned integer number (this
306 does not perform a cast, it simply shows the bytes
307 as unsigned integer)</td>
308 </tr>
309 <tr valign="top">
310 <td><b>pointer</b></td>
311 <td>p</td>
312 <td>show this as a native pointer (unless this is
313 really a pointer, the resulting address will
314 probably be invalid)</td>
315 </tr>
316 <tr valign="top">
317 <td><b>char[]</b></td>
318 <td><br>
319 </td>
320 <td>show this as an array of characters<br>
321 e.g. <code>(char) *c.sp.z = {X}</code></td>
322 </tr>
323 <tr valign="top">
324 <td><b>int8_t[], uint8_t[]<br>
325 int16_t[], uint16_t[]<br>
326 int32_t[], uint32_t[]<br>
327 int64_t[], uint64_t[]<br>
328 uint128_t[]</b></td>
329 <td><br>
330 </td>
331 <td>show this as an array of the corresponding
332 integer type<br>
333 e.g.<br>
334 <code>(int) sarray[0].x = {1 0 0 0}</code><br>
335 <code>(int) sarray[0].x = {0x00000001}</code></td>
336 </tr>
337 <tr valign="top">
338 <td><b>float32[], float64[]</b></td>
339 <td><br>
340 </td>
341 <td>show this as an array of the corresponding
342 floating-point type<br>
343 e.g. <code>(int *) pointer = {1.46991e-39
344 1.4013e-45}</code></td>
345 </tr>
346 <tr valign="top">
347 <td><b>complex integer</b></td>
348 <td>I</td>
349 <td>interpret this value as the real and imaginary
350 part of a complex integer number<br>
351 e.g. <code>(int *) pointer = 1048960 + 1i</code></td>
352 </tr>
353 <tr valign="top">
354 <td><b>character array</b></td>
355 <td>a</td>
356 <td>show this as a character array<br>
357 e.g. <code>(int *) pointer =
358 \x80\x01\x10\0\x01\0\0\0</code></td>
359 </tr>
360 </tbody>
361 </table>
362 </div>
363 </div>
364
365 <div class="post">
366 <h1 class="postheader">type summary</h1>
367 <div class="postcontent">
368 <p>Type summaries enable you to add more information to
369 the default viewing format for a type, or to completely
370 replace it with your own display option. Unlike formats
371 which only apply to basic types, summaries can be used
372 on every type (basic types, classes (C++ and
373 Objective-C), arrays, ...).</p>
374 <p>The basic idea beneath type summaries is extracting
375 information from variables and arranging it in a format
376 that is suitable for display:</p>
377 <p> <i>before adding a summary...</i><br>
378 <code> <b>(lldb)</b> fr var -T one<br>
379 (i_am_cool) one = {<br>
380 (int) integer = 3<br>
381 (float) floating = 3.14159<br>
382 (char) character = 'E'<br>
383 }<br>
384 </code> <br>
385 <i>after adding a summary...</i><br>
386 <code> <b>(lldb)</b> fr var one<br>
387 (i_am_cool) one = int = 3, float = 3.14159, char = 69<br>
388 </code> </p>
389 <p>Evidently, somehow we managed to tell LLDB to grab the
390 three member variables of the <code>i_am_cool</code>
391 datatype, mix their values with some text, and even ask
392 it to display the <code>character</code> member using a
393 custom format.</p>
394 <p>The way to do this is add a <i>summary string</i> to
395 the datatype using the <code>type summary add</code>
396 command.</p>
397 <p>Its syntax is similar to <code>type format add</code>,
398 but some more options are supported that will be
399 described in the follow-up.</p>
400 <p>The main option to <code>type summary add</code> is <code>-f</code>
401 which accepts as parameter a summary string. After that,
402 you can type as many type names as you want to associate
403 the given summary string to them.</p>
404 </div>
405 </div>
406 <div class="post">
407 <h1 class="postheader">Summary Strings</h1>
408 <div class="postcontent">
409 <p>So what is the format of the summary strings? Summary
410 strings can contain plain text, control characters and
411 special symbols that have access to information about
412 the current object and the overall program state.</p>
413 <p>Normal characters are any text that doesn't contain a <code><b>'{'</b></code>,
414 <code><b>'}'</b></code>, <code><b>'$'</b></code>, or <code><b>'\'</b></code>
415 character.</p>
416 <p>Variable names are found in between a <code><b>"${"</b></code>
417 prefix, and end with a <code><b>"}"</b></code> suffix.
418 In other words, a variable looks like <code>"<b>${frame.pc}</b>"</code>.</p>
419 <p>Basically, all the variables described in <a
420 href="formats.html">Frame and Thread Formatting</a>
421 are accepted. Also acceptable are the control characters
422 and scoping features described in that page.
423 Additionally, <code>${var</code> and <code>${*var</code>
424 become acceptable symbols in this scenario.</p>
425 <p>The simplest thing you can do is grab a member variable
426 of a class or structure by typing its <i>expression
427 path</i>. In the previous example, the expression path
428 for the floating member is simply <code>.floating</code>,
429 because all you have to do to get at it given an object
430 of type <code>i_am_cool</code> is access it straight
431 away. Thus, to ask the summary string to display <code>floating</code>
432 you would type <code>${var.floating}</code> (<code>${var</code>
433 is a placeholder token replaced with whatever variable
434 is being displayed).</p>
435 <p>If you have code like the following: <br>
436 <code> struct A {<br>
437 int x;<br>
438 int y;<br>
439 };<br>
440 struct B {<br>
441 A x;<br>
442 A y;<br>
443 int z;<br>
444 };<br>
445 </code> the expression path for the <code>y</code>
446 member of the <code>x</code> member of an object of
447 type <code>B</code> would be <code>.x.y</code> and you
448 would type <code>${var.x.y}</code> to display it in a
449 summary string for type <code>B</code>. </p>
450 <p>As you could be using a summary string for both
451 displaying objects of type <code>T</code> or <code>T*</code>
452 (unless <code>-p</code> is used to prevent this), the
453 expression paths do not differentiate between <code>.</code>
454 and <code>-&gt;</code>, and the above expression path <code>.x.y</code>
455 would be just as good if you were displaying a <code>B*</code>,
456 or even if the actual definition of <code>B</code>
457 were: <code><br>
458 struct B {<br>
459 A *x;<br>
460 A y;<br>
461 int z;<br>
462 };<br>
463 </code> </p>
464 <p>This is unlike the behaviour of <code>frame variable</code>
465 which, on the contrary, will enforce the distinction. As
466 hinted above, the rationale for this choice is that
467 waiving this distinction enables one to write a summary
468 string once for type <code>T</code> and use it for both
469 <code>T</code> and <code>T*</code> instances. As a
470 summary string is mostly about extracting nested
471 members' information, a pointer to an object is just as
472 good as the object itself for the purpose.</p>
473 <p>Of course, you can have multiple entries in one summary
474 string. For instance, the command used to produce the
475 above summary string for i_am_cool was: <br>
476 <code>type summary add -f "int = ${var.integer}, float =
477 ${var.floating}, char = ${var.character%u}" i_am_cool
478 </code> </p>
479 <p>As you can see, the last expression path also contains
480 a <code>%u</code> symbol which is nowhere to be found
481 in the actual member variable name. The symbol is
482 reminding of a <code>printf()</code> format symbol, and
483 in fact it has a similar effect. If you add a % sign
484 followed by any one format name or abbreviation from the
485 above table after an expression path, the resulting
486 object will be displyed using exactly that format
487 instead of the LLDB default one. </p>
488 <p>There are two more special format symbols that you can
489 use only as part of a summary string: <code>%V</code>
490 and <code>%@</code>. The first one tells LLDB to ignore
491 summary strings for the type of the object referred by
492 the expression path and instead print the object's
493 value. The second is only applicable to Objective-C
494 classes, and tells LLDB to get the object's description
495 from the Objective-C runtime. By default, if no format
496 is provided, LLDB will try to get the object's summary,
497 and if empty the object's value. If neither can be
498 obtained, nothing will be displayed.</p>
499 <p>As previously said, pointers and values are treated the
500 same way when getting to their members in an expression
501 path. However, if your expression path leads to a
502 pointer, LLDB will not automatically dereference it. In
503 order to obtain The deferenced value for a pointer, your
504 expression path must start with <code>${*var</code>
505 instead of <code>${var</code>. Because there is no need
506 to dereference pointers along your way, the
507 dereferencing symbol only applies to the result of the
508 whole expression path traversing. <br>
509 e.g. <code> <br>
510 <b>(lldb)</b> fr var -T c<br>
511 (Couple) c = {<br>
512 (SimpleWithPointers) sp = {<br>
513 (int *) x = 0x00000001001000b0<br>
514 (float *) y = 0x00000001001000c0<br>
515 (char *) z = 0x00000001001000d0 "X"<br>
516 }<br>
517 (Simple *) s = 0x00000001001000e0<br>
518 }<br>
519 <b>(lldb)</b> type summary add -f "int = ${*var.sp.x},
520 float = ${*var.sp.y}, char = ${*var.sp.z%u}, Simple =
521 ${*var.s}" Couple<br>
522 <b>(lldb)</b> type summary add -c -p Simple<br>
523 <b>(lldb)</b> fr var c<br>
524 (Couple) c = int = 9, float = 9.99, char = 88, Simple
525 = (x=9, y=9.99, z='X')<br>
526 </code> </p>
527 <p>Option <code>-c</code> to <code>type summary add</code>
528 tells LLDB not to look for a summary string, but instead
529 to just print a listing of all the object's children on
530 one line, lay out as in the previous example. The <code>-p</code>
531 flag is used as a trick to show that aggregate types can
532 be dereferenced as well as primitive ones. The above
533 output would be shown even by typing <code>type summary
534 add -f "int = ${*var.sp.x}, float = ${*var.sp.y}, char
535 = ${*var.sp.z%u}, Simple = ${var.s}" Couple</code> if
536 one took away the <code>-p</code> flag from the summary
537 for type <code>Simple</code>. </p>
538 </div>
539 </div>
540 <div class="post">
541 <h1 class="postheader">More on summary strings</h1>
542 <div class="postcontent">
543 <p>What was described above are the main features that you
544 can use in summary strings. However, there are three
545 more features to them.</p>
546 <p>Sometimes, a basic type's value actually represents
547 several different values packed together in a bitfield.
548 With the classical view, there is no way to look at
549 them. Hexadecimal display can help, but if the bits
550 actually span byte boundaries, the help is limited.
551 Binary view would show it all without ambiguity, but is
552 often too detailed and hard to read for real-life
553 scenarios. To cope with the issue, LLDB supports native
554 bitfield formatting in summary strings. If your
555 expression paths leads to a so-called <i>scalar type</i>
556 (the usual int, float, char, double, short, long, long
557 long, double, long double and unsigned variants), you
558 can ask LLDB to only grab some bits out of the value and
559 display them in any format you like. The syntax is
560 similar to that used for arrays, just you can also give
561 a pair of indices separated by a <code>-</code>. <br>
562 e.g. <br>
563 <code> <b>(lldb)</b> fr var float_point<br>
564 (float) float_point = -3.14159<br>
565 <b>(lldb)</b> type summary add -f "Sign: ${var[31]%B}
566 Exponent: ${var[30-23]%x} Mantissa: ${var[0-22]%u}"
567 float<br>
568 <b>(lldb)</b> fr var float_point<br>
569 (float) float_point = -3.14159 Sign: true Exponent:
570 0x00000080 Mantissa: 4788184<br>
571 </code> In this example, LLDB shows the internal
572 representation of a <code>float</code> variable by
573 extracting bitfields out of a float object. If you give
574 a single index, only that one bit will be extracted. If
575 you give a pair of indices, all the bits in the range
576 (extremes included) will be extracted. Ranges can be
577 specified either by giving the lower index first, or
578 higher index first (as is often customary in describing
579 packed data-type formats). </p>
580 <p>The second additional feature allows you to display
581 array members inside a summary string. For instance, you
582 may want to display all arrays of a given type using a
583 more compact notation than the default, and then just
584 delve into individual array members that prove
585 interesting to your debugging task. You can use a
586 similar syntax to the one used for bitfields to tell
587 LLDB to format arrays in special ways. <br>
588 e.g. <br>
589 <code> <b>(lldb)</b> fr var sarray<br>
590 (Simple [3]) sarray = {<br>
591 [0] = {<br>
592 x = 1<br>
593 y = 2<br>
594 z = '\x03'<br>
595 }<br>
596 [1] = {<br>
597 x = 4<br>
598 y = 5<br>
599 z = '\x06'<br>
600 }<br>
601 [2] = {<br>
602 x = 7<br>
603 y = 8<br>
604 z = '\t'<br>
605 }<br>
606 }<br>
607 <b>(lldb)</b> type summary add -f "${var[].x}" "Simple
608 [3]"<br>
609 <b>(lldb)</b> fr var sarray<br>
610 (Simple [3]) sarray = [1,4,7]<br>
611 </code> The <code>[]</code> symbol amounts to: <i>if <code>var</code>
612 is an array and I knows its size, apply this summary
613 string to every element of the array</i>. Here, we are
614 asking LLDB to display <code>.x</code> for every
615 element of the array, and in fact this is what happens.
616 If you find some of those integers anomalous, you can
617 then inspect that one item in greater detail, without
618 the array format getting in the way: <br>
619 <code> <b>(lldb)</b> fr var sarray[1]<br>
620 (Simple) sarray[1] = {<br>
621 x = 4<br>
622 y = 5<br>
623 z = '\x06'<br>
624 }<br>
625 </code> </p>
626 <p>You can also ask LLDB to only print a subset of the
627 array range by using the same syntax used to extract bit
628 for bitfields.</p>
629 <p>The same logic works if you are printing a pointer
630 instead of an array, however in this latter case, <code>[]</code>
631 cannot be used and you need to give exact range limits.</p>
632 <p>The third, and last, additional feature does not
633 directly apply to the summary strings themselves, but is
634 an additional option to the <code>type summary add</code>
635 command: <code>-x</code></p>
636 <p>As you noticed, in order to associate the custom
637 summary string to the array types, one must give the
638 array size as part of the typename. This can long become
639 tiresome when using arrays of different sizes, <code>Simple
640
641 [3]</code>, <code>Simple [9]</code>, <code>Simple
642 [12]</code>, ...</p>
643 <p>If you use the <code>-x</code> option, type names are
644 treated as regular expressions instead of type names.
645 This would let you rephrase the above example as: <br>
646 <code> <b>(lldb)</b> type summary add -f "${var[].x}"
647 -x "Simple \[[0-9]+\]"<br>
648 <b>(lldb)</b> fr var sarray<br>
649 (Simple [3]) sarray = [1,4,7]<br>
650 </code> The above scenario works for <code>Simple [3]</code>
651 as well as for any other array of <code>Simple</code>
652 objects. </p>
653 <p>While this feature is mostly useful for arrays, you
654 could also use regular expressions to catch other type
655 sets grouped by name. However, as regular expression
656 matching is slower than normal name matching, LLDB will
657 first try to match by name in any way it can, and only
658 when this fails, will it resort to regular expression
659 matching. Thus, if your type has a base class with a
660 cascading summary, this will be preferred over any
661 regular expression match for your type itself.</p>
662 </div>
663 </div>
664 <div class="post">
665 <h1 class="postheader">Finding summaries 101</h1>
666 <div class="postcontent">
667 <p>While the rules for finding an appropriate format for a
668 type are relatively simple (just go through typedef
669 hierarchies), summaries follow a more complicated
670 process in finding the right summary string for a
671 variable. Namely, what happens is:</p>
672 <ul>
673 <li>If there is a summary for the type of the variable,
674 use it</li>
675 <li>If this object is a pointer, and there is a summary
676 for the pointee type that does not skip pointers, use
677 it</li>
678 <li>If this object is a reference, and there is a
679 summary for the pointee type that does not skip
680 references, use it</li>
681 <li>If this object is an Objective-C class with a parent
682 class, look at the parent class (and parent of parent,
683 ...)</li>
684 <li>If this object is a C++ class with base classes,
685 look at base classes (and bases of bases, ...)</li>
686 <li>If this object is a C++ class with virtual base
687 classes, look at the virtual base classes (and bases
688 of bases, ...)</li>
689 <li>If this object's type is a typedef, go through
690 typedef hierarchy</li>
691 <li>If everything has failed, repeat the above search,
692 looking for regular expressions instead of exact
693 matches</li>
694 </ul>
695 </div>
696 </div>
697 <div class="post">
698 <h1 class="postheader">TODOs</h1>
699 <div class="postcontent">
700 <ul>
701 <li>There's no way to do multiple dereferencing, and you
702 need to be careful what the dereferencing operation is
703 binding to in complicated scenarios</li>
704 <li>There is no way to call functions inside summary
705 strings, not even <code>const</code> ones</li>
706 <li><code>type format add</code> does not support the <code>-x</code>
707 option</li>
708 <li>Object location cannot be printed in the summary
709 string</li>
710 </ul>
711 </div>
712 </div>
713 </div>
714 </div>
715 </div>
716 </body>
717</html>