├── LLDB Commands.docset └── Contents │ ├── Info.plist │ └── Resources │ ├── Documents │ ├── cheatset_resources │ │ ├── Open_Sans.woff │ │ ├── Open_Sans_Bold.woff │ │ ├── Open_Sans_Bold_Italic.woff │ │ ├── Open_Sans_Extrabold.woff │ │ ├── Open_Sans_Extrabold_Italic.woff │ │ ├── Open_Sans_Italic.woff │ │ ├── Open_Sans_Semibold.woff │ │ └── Open_Sans_Semibold_Italic.woff │ ├── index.html │ └── style.css │ └── docSet.dsidx ├── README.md └── lldb-commands.rb /LLDB Commands.docset/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleIdentifier 6 | cheatsheet 7 | CFBundleName 8 | LLDB Commands 9 | DashDocSetFamily 10 | cheatsheet 11 | DashDocSetKeyword 12 | lldb 13 | DashDocSetPluginKeyword 14 | lldb 15 | DocSetPlatformFamily 16 | cheatsheet 17 | dashIndexFilePath 18 | index.html 19 | isDashDocset 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans.woff -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Bold.woff -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Bold_Italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Bold_Italic.woff -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Extrabold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Extrabold.woff -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Extrabold_Italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Extrabold_Italic.woff -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Italic.woff -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Semibold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Semibold.woff -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Semibold_Italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/Documents/cheatset_resources/Open_Sans_Semibold_Italic.woff -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LLDB Commands 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 |
113 |

LLDB Commands

114 |
115 |
116 |

117 |
118 |

119 | Execution Commands 120 |

121 | 122 | 123 | 127 | 128 | 129 | 133 | 134 | 135 | 144 | 145 | 146 | 150 | 151 | 152 | 156 | 157 | 158 | 162 | 163 | 164 | 168 | 169 | 170 | 174 | 175 | 176 | 180 | 181 | 182 | 186 | 187 | 188 | 192 | 193 | 194 | 198 | 199 | 200 | 204 | 205 | 206 | 210 | 211 | 212 | 216 | 217 | 218 | 222 | 223 | 224 | 228 | 229 | 230 | 234 | 235 | 236 | 240 | 241 | 242 | 246 | 247 | 248 | 252 | 253 | 254 | 258 | 259 |
124 |

Launch a process no arguments

125 |
(lldb) process launch
(lldb) run
(lldb) r
126 |
130 |

Launch a process with arguments

131 |
(lldb) process launch -- <args>
(lldb) r <args>
132 |
136 |

Launch a process for with arguments a.out 1 2 3 without having to supply the args every time

137 |
138 |
% lldb -- a.out 1 2 3
(lldb) run
...
(lldb) run
...
139 | 140 |

or
141 | (lldb) settings set target.run-args 1 2 3 (lldb) run ... (lldb) run ...

142 |
143 |
147 |

Launch a process with arguments in new terminal window (Mac OS X only)

148 |
(lldb) process launch --tty -- <args>
(lldb) pro la -t -- <args>
149 |
153 |

Launch a process with arguments in existing terminal /dev/ttys006 (Mac OS X only)

154 |
(lldb) process launch --tty=/dev/ttys006 -- <args>
(lldb) pro la -t/dev/ttys006 -- <args>
155 |
159 |

Set environment variables for process before launching

160 |
(lldb) settings set target.env-vars DEBUG=1
(lldb) set se target.env-vars DEBUG=1
(lldb) env DEBUG=1
161 |
165 |

Unset environment variables for process before launching

166 |
(lldb) settings remove target.env-vars DEBUG
(lldb) set rem target.env-vars DEBUG
167 |
171 |

Show the arguments that will be or were passed to the program when run

172 |
(lldb) settings show target.run-args
target.run-args (array of strings) = [0]: "1" [1]: "2" [2]: "3"
173 |
177 |

Set environment variables for process and launch process in one command

178 |
(lldb) process launch -v DEBUG=1
179 |
183 |

Attach to a process with process ID 123

184 |
(lldb) process attach --pid 123  
(lldb) attach -p 123
185 |
189 |

Attach to a process named "a.out"

190 |
(lldb) process attach --name a.out
(lldb) pro at -n a.out
191 |
195 |

Wait for a process named "a.out" to launch and attach

196 |
(lldb) process attach --name a.out --waitfor
(lldb) pro at -n a.out -w
197 |
201 |

Attach to a remote gdb protocol server running on system "eorgadd", port 8000.

202 |
(lldb) gdb-remote eorgadd:8000
203 |
207 |

Attach to a remote gdb protocol server running on the local system, port 8000

208 |
(lldb) gdb-remote 8000
209 |
213 |

Attach to a Darwin kernel in kdp mode on system "eorgadd"

214 |
(lldb) kdp-remote eorgadd
215 |
219 |

Do a source level single step in the currently selected thread

220 |
(lldb) thread step-in
(lldb) step
(lldb) s
221 |
225 |

Do a source level single step over in the currently selected thread

226 |
(lldb) thread step-over
(lldb) next
(lldb) n
227 |
231 |

Do an instruction level single step in the currently selected thread

232 |
(lldb) thread step-inst
(lldb) si
233 |
237 |

Do an instruction level single step over in the currently selected thread

238 |
(lldb) thread step-inst-over
(lldb) ni
239 |
243 |

Step out of the currently selected frame

244 |
(lldb) thread step-out
(lldb) finish
245 |
249 |

Return immediately from the currently selected frame, with an optional return value

250 |
(lldb) thread return <RETURN EXPRESSION>
251 |
255 |

Backtrace and disassemble every time you stop

256 |
(lldb) target stop-hook add
Enter your stop hook command(s). Type 'DONE' to end.
> bt
> disassemble --pc
> DONE
Stop hook #1 added.
257 |
260 |
261 |
262 |

263 | Breakpoint Commands 264 |

265 | 266 | 267 | 271 | 272 | 273 | 277 | 278 | 279 | 283 | 284 | 285 | 289 | 290 | 291 | 295 | 296 | 297 | 301 | 302 | 303 | 307 | 308 | 309 | 313 | 314 | 315 | 319 | 320 | 321 | 325 | 326 | 327 | 331 | 332 |
268 |

Set a breakpoint at all functions named main

269 |
(lldb) breakpoint set --name main
(lldb) br s -n main
(lldb) b main
270 |
274 |

Set a breakpoint in file test.c at line 12

275 |
(lldb) breakpoint set --file test.c --line 12
(lldb) br s -f test.c -l 12
(lldb) b test.c:12
276 |
280 |

Set a breakpoint at all C++ methods whose basename is main

281 |
(lldb) breakpoint set --method main
(lldb) br s -M main
282 |
286 |

Set a breakpoint at and object C function: -[NSString stringWithFormat:]

287 |
(lldb) breakpoint set --name "-[NSString stringWithFormat:]"
(lldb) b -[NSString stringWithFormat:]
288 |
292 |

Set a breakpoint at all Objective C methods whose selector is count

293 |
(lldb) breakpoint set --selector count
(lldb) br s -S count
294 |
298 |

Set a breakpoint by regular expression on function name

299 |
(lldb) breakpoint set --func-regex regular-expression
(lldb) br s -r regular-expression
300 |
304 |

Ensure that breakpoints by file and line work for #included .c/.cpp/.m files

305 |
(lldb) settings set target.inline-breakpoint-strategy always
(lldb) br s -f foo.c -l 12
306 |
310 |

Set a breakpoint by regular expression on source file contents

311 |
(lldb) breakpoint set --source-pattern regular-expression --file SourceFile
(lldb) br s -p regular-expression -f file
312 |
316 |

Set a conditional breakpoint

317 |
(lldb) breakpoint set --name foo --condition '(int)strcmp(y,"hello") == 0'
(lldb) br s -n foo -c '(int)strcmp(y,"hello") == 0'
318 |
322 |

List all breakpoints

323 |
(lldb) breakpoint list
(lldb) br l
324 |
328 |

Delete a breakpoint

329 |
(lldb) breakpoint delete 1
(lldb) br del 1
330 |
333 |
334 |
335 |

336 | Watchpoint Commands 337 |

338 | 339 | 340 | 344 | 345 | 346 | 350 | 351 | 352 | 356 | 357 | 358 | 362 | 363 | 364 | 368 | 369 |
341 |

Set a watchpoint on a variable when it is written to

342 |
(lldb) watchpoint set variable global_var
(lldb) wa s v global_var
343 |
347 |

Set a watchpoint on a memory location when it is written into. The size of the region to watch for defaults to the pointer size if no '-x byte_size' is specified. This command takes raw input, evaluated as an expression returning an unsigned integer pointing to the start of the region, after the '--' option terminator

348 |
(lldb) watchpoint set expression -- my_ptr
(lldb) wa s e -- my_ptr
349 |
353 |

Set a condition on a watchpoint

354 |
(lldb) watch set var global
(lldb) watchpoint modify -c '(global==5)'
(lldb) c
...
(lldb) bt
* thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1
frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16
frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25
frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1
(lldb) frame var global
(int32_t) global = 5
355 |
359 |

List all watchpoints

360 |
(lldb) watchpoint list
(lldb) watch l
361 |
365 |

Delete a watchpoint

366 |
(lldb) watchpoint delete 1
(lldb) watch del 1
367 |
370 |
371 |
372 |

373 | Examining Variables 374 |

375 | 376 | 377 | 381 | 382 | 383 | 387 | 388 | 389 | 393 | 394 | 395 | 399 | 400 | 401 | 405 | 406 | 407 | 411 | 412 | 413 | 417 | 418 | 419 | 423 | 424 | 425 | 429 | 430 |
378 |

Show the arguments and local variables for the current frame

379 |
(lldb) frame variable
(lldb) fr v
380 |
384 |

Show the local variables for the current frame

385 |
(lldb) frame variable --no-args
(lldb) fr v -a
386 |
390 |

Show the contents of local variable "bar"

391 |
(lldb) frame variable bar
(lldb) fr v bar
(lldb) p bar
392 |
396 |

Show the contents of local variable "bar" formatted as hex

397 |
(lldb) frame variable --format x bar
(lldb) fr v -f x bar
398 |
402 |

Show the contents of global variable "baz"

403 |
(lldb) target variable baz
(lldb) ta v baz
404 |
408 |

Show the global/static variables defined in the current source file

409 |
(lldb) target variable
(lldb) ta v
410 |
414 |

Display a the variable "argc" and "argv" every time you stop

415 |
(lldb) target stop-hook add --one-liner "frame variable argc argv"
(lldb) ta st a -o "fr v argc argv"
(lldb) display argc
(lldb) display argv
416 |
420 |

Display a the variable "argc" and "argv" only when you stop in the function named main

421 |
(lldb) target stop-hook add --name main --one-liner "frame variable argc argv"
(lldb) ta st a -n main -o "fr v argc argv"
422 |
426 |

Display the variable "this" only when you stop in c class named *MyClass**

427 |
(lldb) target stop-hook add --classname MyClass --one-liner "frame variable *this"
(lldb) ta st a -c MyClass -o "fr v *this"
428 |
431 |
432 |
433 |

434 | Evaluating Expressions 435 |

436 | 437 | 438 | 447 | 448 | 449 | 456 | 457 | 458 | 467 | 468 | 469 | 478 | 479 | 480 | 484 | 485 | 486 | 490 | 491 |
439 |

Evaluating a generalized expression in the current frame

440 |
441 |
(lldb) expr (int) printf ("Print nine: %d.", 4 + 5)
442 | 443 |

or using the print alias:
444 | (lldb) print (int) printf ("Print nine: %d.", 4 + 5)

445 |
446 |
450 |

Creating and assigning a value to a convenience variable

451 |
452 |

In lldb you evaluate a variable declaration expression as you would write it in C: 453 | (lldb) expr unsigned int $foo = 5

454 |
455 |
459 |

Printing the ObjC "description" of an object

460 |
461 |
(lldb) expr -o -- [SomeClass returnAnObject]
462 | 463 |

or using the po alias:
464 | (lldb) po [SomeClass returnAnObject]

465 |
466 |
470 |

Print the dynamic type of the result of an expression

471 |
472 |
(lldb) expr -d 1 -- [SomeClass returnAnObject]
(lldb) expr -d 1 -- someCPPObjectPtrOrReference
473 | 474 |

or set dynamic type printing to be the default:
475 | (lldb) settings set target.prefer-dynamic run-target

476 |
477 |
481 |

Calling a function so you can stop at a breakpoint in the function

482 |
(lldb) expr -i 0 -- function_with_a_breakpoint()
483 |
487 |

Calling a function that crashes, and stopping when the function crashes

488 |
(lldb) expr -u 0 -- function_which_crashes()
489 |
492 |
493 |
494 |

495 | Examining Thread State 496 |

497 | 498 | 499 | 503 | 504 | 505 | 509 | 510 | 511 | 515 | 516 | 517 | 521 | 522 | 523 | 527 | 528 | 529 | 533 | 534 | 535 | 539 | 540 | 541 | 545 | 546 | 547 | 551 | 552 | 553 | 557 | 558 | 559 | 563 | 564 | 565 | 574 | 575 | 576 | 580 | 581 | 582 | 586 | 587 | 588 | 597 | 598 | 599 | 608 | 609 | 610 | 619 | 620 | 621 | 625 | 626 | 627 | 631 | 632 | 633 | 637 | 638 | 639 | 643 | 644 | 645 | 649 | 650 | 651 | 655 | 656 | 657 | 661 | 662 | 663 | 667 | 668 | 669 | 673 | 674 | 675 | 679 | 680 | 681 | 685 | 686 | 687 | 691 | 692 | 693 | 697 | 698 |
500 |

Show the stack backtrace for the current thread

501 |
(lldb) thread backtrace
(lldb) bt
502 |
506 |

Show the stack backtraces for all threads

507 |
(lldb) thread backtrace all
(lldb) bt all
508 |
512 |

Backtrace the first five frames of the current thread

513 |
(lldb) thread backtrace -c 5
(lldb) bt 5 (lldb-169 and later)
(lldb) bt -c 5 (lldb-168 and earlier)
514 |
518 |

Select a different stack frame by index for the current thread

519 |
(lldb) frame select 12
(lldb) fr s 12
(lldb) f 12
520 |
524 |

List information about the currently selected frame in the current thread

525 |
(lldb) frame info
526 |
530 |

Select the stack frame that called the current stack frame

531 |
(lldb) up
(lldb) frame select --relative=1
532 |
536 |

Select the stack frame that is called by the current stack frame

537 |
(lldb) down
(lldb) frame select --relative=-1
(lldb) fr s -r-1
538 |
542 |

Select a different stack frame using a relative offset

543 |
(lldb) frame select --relative 2
(lldb) fr s -r2

(lldb) frame select --relative -3
(lldb) fr s -r-3
544 |
548 |

Show the general purpose registers for the current thread

549 |
(lldb) register read
550 |
554 |

Write a new decimal value '123' to the current thread register 'rax'

555 |
(lldb) register write rax 123
556 |
560 |

Skip 8 bytes ahead of the current program counter (instruction pointer). Note that we use backticks to evaluate an expression and insert the scalar result in LLDB

561 |
(lldb) register write pc `$pc+8`
562 |
566 |

Show the general purpose registers for the current thread formatted as signed decimal. LLDB tries to use the same format characters as printf(3) when possible. Type "help format" to see the full list of format specifiers.

567 |
568 |
(lldb) register read --format i
(lldb) re r -f i
569 | 570 |

LLDB now supports the GDB shorthand format syntax but there can't be space after the command:
571 | (lldb) register read/d

572 |
573 |
577 |

Show all registers in all register sets for the current thread

578 |
(lldb) register read --all
(lldb) re r -a
579 |
583 |

Show the values for the registers named "rax", "rsp" and "rbp" in the current thread

584 |
(lldb) register read rax rsp rbp
585 |
589 |

Show the values for the register named "rax" in the current thread formatted as binary

590 |
591 |
(lldb) register read --format binary rax
(lldb) re r -f b rax
592 | 593 |

LLDB now supports the GDB shorthand format syntax but there can't be space after the command:
594 | (lldb) register read/t rax (lldb) p/t $rax

595 |
596 |
600 |

Read memory from address 0xbffff3c0 and show 4 hex uint32_t values

601 |
602 |
(lldb) memory read --size 4 --format x --count 4 0xbffff3c0
(lldb) me r -s4 -fx -c4 0xbffff3c0
(lldb) x -s4 -fx -c4 0xbffff3c0
603 | 604 |

LLDB now supports the GDB shorthand format syntax but there can't be space after the command:
605 | (lldb) memory read/4xw 0xbffff3c0 (lldb) x/4xw 0xbffff3c0 (lldb) memory read --gdb-format 4xw 0xbffff3c0

606 |
607 |
611 |

Read memory starting at the expression "argv[0]"

612 |
613 |
(lldb) memory read `argv[0]`
614 | 615 |

NOTE: any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression:
616 | (lldb) memory read --size `sizeof(int)` `argv[0]`

617 |
618 |
622 |

Read 512 bytes of memory from address 0xbffff3c0 and save results to a local file as text

623 |
(lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0  
(lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0  
(lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0
624 |
628 |

Save binary memory data starting at 0x1000 and ending at 0x2000 to a file

629 |
(lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x2000
(lldb) me r -o /tmp/mem.bin -b 0x1000 0x2000
630 |
634 |

Get information about a specific heap allocation (available on Mac OS X only)

635 |
(lldb) command script import lldb.macosx.heap
(lldb) process launch --environment MallocStackLogging=1 -- [ARGS]
(lldb) malloc_info --stack-history 0x10010d680
636 |
640 |

Get information about a specific heap allocation and cast the result to any dynamic type that can be deduced (available on Mac OS X only)

641 |
(lldb) command script import lldb.macosx.heap
(lldb) malloc_info --type 0x10010d680
642 |
646 |

Find all heap blocks that contain a pointer specified by an expression EXPR (available on Mac OS X only)

647 |
(lldb) command script import lldb.macosx.heap
(lldb) ptr_refs EXPR 
648 |
652 |

Find all heap blocks that contain a C string anywhere in the block (available on Mac OS X only)

653 |
(lldb) command script import lldb.macosx.heap
(lldb) cstr_refs CSTRING
654 |
658 |

Disassemble the current function for the current frame

659 |
(lldb) disassemble --frame
(lldb) di -f
660 |
664 |

Disassemble any functions named main

665 |
(lldb) disassemble --name main
(lldb) di -n main
666 |
670 |

Disassemble an address range

671 |
(lldb) disassemble --start-address 0x1eb8 --end-address 0x1ec3
(lldb) di -s 0x1eb8 -e 0x1ec3
672 |
676 |

Disassemble 20 instructions from a given address

677 |
(lldb) disassemble --start-address 0x1eb8 --count 20
(lldb) di -s 0x1eb8 -c 20
678 |
682 |

Show mixed source and disassembly for the current function for the current frame

683 |
(lldb) disassemble --frame --mixed
(lldb) di -f -m
684 |
688 |

Disassemble the current function for the current frame and show the opcode bytes

689 |
(lldb) disassemble --frame --bytes
(lldb) di -f -b
690 |
694 |

Disassemble the current source line for the current frame

695 |
(lldb) disassemble --line
(lldb) di -l
696 |
699 |
700 |
701 |

702 | Executable and Shared Library Query Commands 703 |

704 | 705 | 706 | 710 | 711 | 712 | 716 | 717 | 718 | 730 | 731 | 732 | 741 | 742 | 743 | 747 | 748 | 749 | 753 | 754 | 755 | 759 | 760 | 761 | 765 | 766 | 767 | 771 | 772 | 773 | 777 | 778 |
707 |

List the main executable and all dependent shared libraries

708 |
(lldb) image list
709 |
713 |

Look up information for a raw address in the executable or any shared libraries

714 |
(lldb) image lookup --address 0x1ec4
(lldb) im loo -a 0x1ec4
715 |
719 |

Look up functions matching a regular expression in a binary

720 |
721 |

This one finds debug symbols:
722 | (lldb) image lookup -r -n <FUNC_REGEX>

723 | 724 |

This one finds non-debug symbols:
725 | (lldb) image lookup -r -s <FUNC_REGEX>

726 | 727 |

Provide a list of binaries as arguments to limit the search.

728 |
729 |
733 |

Find full souce line information

734 |
735 |

This one is a bit messy at present. Do:
736 | (lldb) image lookup -v --address 0x1ec4

737 | 738 |

and look for the LineEntry line, which will have the full source path and line range information.

739 |
740 |
744 |

Look up information for an address in a.out only

745 |
(lldb) image lookup --address 0x1ec4 a.out
 (lldb) im loo -a 0x1ec4 a.out
746 |
750 |

Look up information for for a type Point by name

751 |
(lldb) image lookup --type Point
(lldb) im loo -t Point
752 |
756 |

Dump all sections from the main executable and any shared libraries

757 |
(lldb) image dump sections
758 |
762 |

Dump all sections in the a.out module

763 |
(lldb) image dump sections a.out
764 |
768 |

Dump all symbols from the main executable and any shared libraries

769 |
(lldb) image dump symtab
770 |
774 |

Dump all symbols in a.out and liba.so

775 |
(lldb) image dump symtab a.out liba.so
776 |
779 |
780 |
781 |

782 | Miscellaneous 783 |

784 | 785 | 786 | 790 | 791 | 792 | 796 | 797 |
787 |

Echo text to the screen

788 |
(lldb) script print "Here is some text"
789 |
793 |

Remap source file pathnames for the debug session. If your source files are no longer located in the same location as when the program was built --- maybe the program was built on a different computer --- you need to tell the debugger how to find the sources at their local file path instead of the build system's file path.

794 |
(lldb) settings set target.source-map /buildbot/path /my/path
795 |
798 |
799 |
800 |

Notes

801 |

Based on the GDB to LLDB command map page on the LLVM website

802 |
803 |
804 | 807 | 808 | 809 | -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/Documents/style.css: -------------------------------------------------------------------------------- 1 | h1, h2, h3, p, blockquote { 2 | margin: 0; 3 | padding: 0; } 4 | 5 | @font-face { 6 | font-family: 'Open Sans'; 7 | font-style: normal; 8 | font-weight: 400; 9 | src: local("Open Sans"), local("OpenSans"), url(cheatset_resources/Open_Sans.woff) format("woff"); } 10 | @font-face { 11 | font-family: 'Open Sans'; 12 | font-style: normal; 13 | font-weight: 600; 14 | src: local("Open Sans Semibold"), local("OpenSans-Semibold"), url(cheatset_resources/Open_Sans_Semibold.woff) format("woff"); } 15 | @font-face { 16 | font-family: 'Open Sans'; 17 | font-style: normal; 18 | font-weight: 700; 19 | src: local("Open Sans Bold"), local("OpenSans-Bold"), url(cheatset_resources/Open_Sans_Bold.woff) format("woff"); } 20 | @font-face { 21 | font-family: 'Open Sans'; 22 | font-style: normal; 23 | font-weight: 800; 24 | src: local("Open Sans Extrabold"), local("OpenSans-Extrabold"), url(cheatset_resources/Open_Sans_Extrabold.woff) format("woff"); } 25 | @font-face { 26 | font-family: 'Open Sans'; 27 | font-style: italic; 28 | font-weight: 400; 29 | src: local("Open Sans Italic"), local("OpenSans-Italic"), url(cheatset_resources/Open_Sans_Italic.woff) format("woff"); } 30 | @font-face { 31 | font-family: 'Open Sans'; 32 | font-style: italic; 33 | font-weight: 600; 34 | src: local("Open Sans Semibold Italic"), local("OpenSans-SemiboldItalic"), url(cheatset_resources/Open_Sans_Semibold_Italic.woff) format("woff"); } 35 | @font-face { 36 | font-family: 'Open Sans'; 37 | font-style: italic; 38 | font-weight: 700; 39 | src: local("Open Sans Bold Italic"), local("OpenSans-BoldItalic"), url(cheatset_resources/Open_Sans_Bold_Italic.woff) format("woff"); } 40 | @font-face { 41 | font-family: 'Open Sans'; 42 | font-style: italic; 43 | font-weight: 800; 44 | src: local("Open Sans Extrabold Italic"), local("OpenSans-ExtraboldItalic"), url(cheatset_resources/Open_Sans_Extrabold_Italic.woff) format("woff"); } 45 | body { 46 | font-family: 'Open Sans', sans-serif; 47 | font-size: 14px; 48 | color: black; 49 | background-color: white; 50 | margin: 0; } 51 | 52 | code, pre { 53 | font-family: Menlo, Consolas, "Liberation Mono", Courier, monospace; 54 | font-size: 13px; } 55 | 56 | code { 57 | margin: 0; 58 | border: 1px solid #ddd; 59 | background-color: #f8f8f8; 60 | border-radius: 3px; } 61 | 62 | .name code { 63 | vertical-align: 1px; } 64 | 65 | code:before, code:after { 66 | content: "\00a0"; } 67 | 68 | header { 69 | color: #efefef; 70 | background-color: #666666; 71 | padding: 0px 10px 3px 10px; } 72 | 73 | h1 { 74 | font-size: 35px; 75 | font-weight: 600; } 76 | 77 | footer { 78 | background-color: #666666; 79 | color: #efefef; 80 | text-align: center; 81 | padding: 3px 0px; } 82 | footer a { 83 | color: #efefef; } 84 | 85 | section.notes { 86 | margin-top: 1em; } 87 | section.notes h2 { 88 | color: #666666; 89 | font-size: 1.5em; } 90 | 91 | article { 92 | margin: 2em 1em; } 93 | 94 | section.category { 95 | border: 2px solid #666666; 96 | border-radius: 6px 6px; 97 | background-color: #666666; 98 | margin: 2em 0; 99 | overflow: hidden; 100 | padding-bottom: 5px; } 101 | section.category h2 { 102 | color: white; 103 | font-size: 1.5em; 104 | text-align: center; 105 | margin-top: -2px; 106 | font-weight: 600; } 107 | 108 | table { 109 | background-color: white; 110 | border-collapse: collapse; 111 | width: 100%; } 112 | 113 | td { 114 | padding: 13px 8px 0px 8px; 115 | border-left: 1px solid #d7d7d7; } 116 | 117 | th { 118 | border-left: 1px solid #d7d7d7; } 119 | 120 | tr { 121 | border-bottom: 1px dotted #d7d7d7; } 122 | 123 | tr:last-child { 124 | border-bottom: none; } 125 | 126 | td.command, td.td_command { 127 | width: 1%; 128 | white-space: nowrap; 129 | vertical-align: top; 130 | padding: 9px 8px 4px 7px; 131 | text-align: right; } 132 | td.command code, td.td_command code { 133 | padding: .1em 0.2em; 134 | box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2), 0 0 0 2px white inset; 135 | border-radius: 3px; 136 | border: 1px solid #ccc; 137 | background-color: #efefef; 138 | color: #333; } 139 | 140 | td.td_command { 141 | text-align: center; } 142 | 143 | td.description .name { 144 | font-size: 1.2em; } 145 | 146 | th { 147 | background: #efefef; 148 | padding: 5px 12px 5px 8px; 149 | text-align: left; 150 | border-bottom: 1px solid #d7d7d7; 151 | font-weight: 600; } 152 | 153 | th:nth-child(1), td:nth-child(1) { 154 | border-left: none; } 155 | 156 | a { 157 | color: #666666; } 158 | 159 | p { 160 | margin: 0 0 7px; } 161 | 162 | .highlight { 163 | background-color: #f8f8f8; 164 | border: 1px solid #ccc; 165 | padding: 6px 10px; 166 | border-radius: 3px; 167 | margin-right: 1px; 168 | white-space: pre-wrap; 169 | word-wrap: break-word; } 170 | 171 | .c { 172 | color: #999988; 173 | font-style: italic; } 174 | 175 | .err { 176 | color: #a61717; 177 | background-color: #e3d2d2; } 178 | 179 | .k { 180 | font-weight: bold; } 181 | 182 | .o { 183 | font-weight: bold; } 184 | 185 | .cm { 186 | color: #999988; 187 | font-style: italic; } 188 | 189 | .cp { 190 | color: #999999; 191 | font-weight: bold; } 192 | 193 | .c1 { 194 | color: #999988; 195 | font-style: italic; } 196 | 197 | .cs { 198 | color: #999999; 199 | font-weight: bold; 200 | font-style: italic; } 201 | 202 | .gd { 203 | color: #000000; 204 | background-color: #ffdddd; } 205 | 206 | .gd .x { 207 | color: #000000; 208 | background-color: #ffaaaa; } 209 | 210 | .ge { 211 | font-style: italic; } 212 | 213 | .gr { 214 | color: #aa0000; } 215 | 216 | .gh { 217 | color: #999999; } 218 | 219 | .gi { 220 | color: #000000; 221 | background-color: #ddffdd; } 222 | 223 | .gi .x { 224 | color: #000000; 225 | background-color: #aaffaa; } 226 | 227 | .go { 228 | color: #888888; } 229 | 230 | .gp { 231 | color: #555555; } 232 | 233 | .gs { 234 | font-weight: bold; } 235 | 236 | .gu { 237 | color: #800080; 238 | font-weight: bold; } 239 | 240 | .gt { 241 | color: #aa0000; } 242 | 243 | .kc { 244 | font-weight: bold; } 245 | 246 | .kd { 247 | font-weight: bold; } 248 | 249 | .kn { 250 | font-weight: bold; } 251 | 252 | .kp { 253 | font-weight: bold; } 254 | 255 | .kr { 256 | font-weight: bold; } 257 | 258 | .kt { 259 | color: #445588; 260 | font-weight: bold; } 261 | 262 | .m { 263 | color: #009999; } 264 | 265 | .s { 266 | color: #dd1144; } 267 | 268 | .n { 269 | color: #333333; } 270 | 271 | .na { 272 | color: teal; } 273 | 274 | .nb { 275 | color: #0086b3; } 276 | 277 | .nc { 278 | color: #445588; 279 | font-weight: bold; } 280 | 281 | .no { 282 | color: teal; } 283 | 284 | .ni { 285 | color: purple; } 286 | 287 | .ne { 288 | color: #990000; 289 | font-weight: bold; } 290 | 291 | .nf { 292 | color: #990000; 293 | font-weight: bold; } 294 | 295 | .nn { 296 | color: #555555; } 297 | 298 | .nt { 299 | color: navy; } 300 | 301 | .nv { 302 | color: teal; } 303 | 304 | .ow { 305 | font-weight: bold; } 306 | 307 | .w { 308 | color: #bbbbbb; } 309 | 310 | .mf { 311 | color: #009999; } 312 | 313 | .mh { 314 | color: #009999; } 315 | 316 | .mi { 317 | color: #009999; } 318 | 319 | .mo { 320 | color: #009999; } 321 | 322 | .sb { 323 | color: #dd1144; } 324 | 325 | .sc { 326 | color: #dd1144; } 327 | 328 | .sd { 329 | color: #dd1144; } 330 | 331 | .s2 { 332 | color: #dd1144; } 333 | 334 | .se { 335 | color: #dd1144; } 336 | 337 | .sh { 338 | color: #dd1144; } 339 | 340 | .si { 341 | color: #dd1144; } 342 | 343 | .sx { 344 | color: #dd1144; } 345 | 346 | .sr { 347 | color: #009926; } 348 | 349 | .s1 { 350 | color: #dd1144; } 351 | 352 | .ss { 353 | color: #990073; } 354 | 355 | .bp { 356 | color: #999999; } 357 | 358 | .vc { 359 | color: teal; } 360 | 361 | .vg { 362 | color: teal; } 363 | 364 | .vi { 365 | color: teal; } 366 | 367 | .il { 368 | color: #009999; } 369 | 370 | .gc { 371 | color: #999; 372 | background-color: #EAF2F5; } 373 | 374 | pre { 375 | padding: 15px; 376 | line-height: 17px; 377 | margin-top: 0px; 378 | margin-bottom: 9px; } 379 | 380 | .name { 381 | margin-top: -4px; } 382 | 383 | ul { 384 | padding-left: 24px; } 385 | -------------------------------------------------------------------------------- /LLDB Commands.docset/Contents/Resources/docSet.dsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddeville/lldb-commands-cheat-sheet/5521e3bebaece015d4fa71030e53130cddbb5c39/LLDB Commands.docset/Contents/Resources/docSet.dsidx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## LLDB Commands Cheat Sheet for Dash 2 | 3 | In order to build the docset you first need to install the `cheatset` gem 4 | 5 | ``` 6 | > sudo gem install cheatset 7 | ``` 8 | 9 | You can then build the docset by running: 10 | 11 | ``` 12 | > cheatset generate lldb-commands.rb 13 | ``` 14 | 15 | -------------------------------------------------------------------------------- /lldb-commands.rb: -------------------------------------------------------------------------------- 1 | cheatsheet do 2 | title 'LLDB Commands' 3 | docset_file_name 'LLDB Commands' 4 | keyword 'lldb' 5 | 6 | category do 7 | id 'Execution Commands' 8 | 9 | entry do 10 | name 'Launch a process no arguments' 11 | notes ' 12 | ``` 13 | (lldb) process launch 14 | (lldb) run 15 | (lldb) r 16 | ``` 17 | ' 18 | end 19 | 20 | entry do 21 | name 'Launch a process with arguments ' 22 | notes ' 23 | ``` 24 | (lldb) process launch -- 25 | (lldb) r 26 | ``` 27 | ' 28 | end 29 | 30 | entry do 31 | name 'Launch a process for with arguments a.out 1 2 3 without having to supply the args every time' 32 | notes ' 33 | ``` 34 | % lldb -- a.out 1 2 3 35 | (lldb) run 36 | ... 37 | (lldb) run 38 | ... 39 | ``` 40 | or 41 | ``` 42 | (lldb) settings set target.run-args 1 2 3 43 | (lldb) run 44 | ... 45 | (lldb) run 46 | ... 47 | ``` 48 | ' 49 | end 50 | 51 | entry do 52 | name 'Launch a process with arguments in new terminal window (Mac OS X only)' 53 | notes ' 54 | ``` 55 | (lldb) process launch --tty -- 56 | (lldb) pro la -t -- 57 | ``` 58 | ' 59 | end 60 | 61 | entry do 62 | name 'Launch a process with arguments in existing terminal /dev/ttys006 (Mac OS X only)' 63 | notes ' 64 | ``` 65 | (lldb) process launch --tty=/dev/ttys006 -- 66 | (lldb) pro la -t/dev/ttys006 -- 67 | ``` 68 | ' 69 | end 70 | 71 | entry do 72 | name 'Set environment variables for process before launching' 73 | notes ' 74 | ``` 75 | (lldb) settings set target.env-vars DEBUG=1 76 | (lldb) set se target.env-vars DEBUG=1 77 | (lldb) env DEBUG=1 78 | ``` 79 | ' 80 | end 81 | 82 | entry do 83 | name 'Unset environment variables for process before launching' 84 | notes ' 85 | ``` 86 | (lldb) settings remove target.env-vars DEBUG 87 | (lldb) set rem target.env-vars DEBUG 88 | ``` 89 | ' 90 | end 91 | 92 | entry do 93 | name 'Show the arguments that will be or were passed to the program when run' 94 | notes ' 95 | ``` 96 | (lldb) settings show target.run-args 97 | target.run-args (array of strings) = [0]: "1" [1]: "2" [2]: "3" 98 | ``` 99 | ' 100 | end 101 | 102 | entry do 103 | name 'Set environment variables for process and launch process in one command' 104 | notes ' 105 | ``` 106 | (lldb) process launch -v DEBUG=1 107 | ``` 108 | ' 109 | end 110 | 111 | entry do 112 | name 'Attach to a process with process ID 123' 113 | notes ' 114 | ``` 115 | (lldb) process attach --pid 123 116 | (lldb) attach -p 123 117 | ``` 118 | ' 119 | end 120 | 121 | entry do 122 | name 'Attach to a process named "a.out"' 123 | notes ' 124 | ``` 125 | (lldb) process attach --name a.out 126 | (lldb) pro at -n a.out 127 | ``` 128 | ' 129 | end 130 | 131 | entry do 132 | name 'Wait for a process named "a.out" to launch and attach' 133 | notes ' 134 | ``` 135 | (lldb) process attach --name a.out --waitfor 136 | (lldb) pro at -n a.out -w 137 | ``` 138 | ' 139 | end 140 | 141 | entry do 142 | name 'Attach to a remote gdb protocol server running on system "eorgadd", port 8000.' 143 | notes ' 144 | ``` 145 | (lldb) gdb-remote eorgadd:8000 146 | ``` 147 | ' 148 | end 149 | 150 | entry do 151 | name 'Attach to a remote gdb protocol server running on the local system, port 8000' 152 | notes ' 153 | ``` 154 | (lldb) gdb-remote 8000 155 | ``` 156 | ' 157 | end 158 | 159 | entry do 160 | name 'Attach to a Darwin kernel in kdp mode on system "eorgadd"' 161 | notes ' 162 | ``` 163 | (lldb) kdp-remote eorgadd 164 | ``` 165 | ' 166 | end 167 | 168 | entry do 169 | name 'Do a source level single step in the currently selected thread' 170 | notes ' 171 | ``` 172 | (lldb) thread step-in 173 | (lldb) step 174 | (lldb) s 175 | ``` 176 | ' 177 | end 178 | 179 | entry do 180 | name 'Do a source level single step over in the currently selected thread' 181 | notes ' 182 | ``` 183 | (lldb) thread step-over 184 | (lldb) next 185 | (lldb) n 186 | ``` 187 | ' 188 | end 189 | 190 | entry do 191 | name 'Do an instruction level single step in the currently selected thread' 192 | notes ' 193 | ``` 194 | (lldb) thread step-inst 195 | (lldb) si 196 | ``` 197 | ' 198 | end 199 | 200 | entry do 201 | name 'Do an instruction level single step over in the currently selected thread' 202 | notes ' 203 | ``` 204 | (lldb) thread step-inst-over 205 | (lldb) ni 206 | ``` 207 | ' 208 | end 209 | 210 | entry do 211 | name 'Step out of the currently selected frame' 212 | notes ' 213 | ``` 214 | (lldb) thread step-out 215 | (lldb) finish 216 | ``` 217 | ' 218 | end 219 | 220 | entry do 221 | name 'Return immediately from the currently selected frame, with an optional return value' 222 | notes ' 223 | ``` 224 | (lldb) thread return 225 | ``` 226 | ' 227 | end 228 | 229 | entry do 230 | name 'Backtrace and disassemble every time you stop' 231 | notes " 232 | ``` 233 | (lldb) target stop-hook add 234 | Enter your stop hook command(s). Type 'DONE' to end. 235 | > bt 236 | > disassemble --pc 237 | > DONE 238 | Stop hook #1 added. 239 | ``` 240 | " 241 | end 242 | end 243 | 244 | category do 245 | id 'Breakpoint Commands' 246 | 247 | entry do 248 | name 'Set a breakpoint at all functions named **main**' 249 | notes ' 250 | ``` 251 | (lldb) breakpoint set --name main 252 | (lldb) br s -n main 253 | (lldb) b main 254 | ``` 255 | ' 256 | end 257 | 258 | entry do 259 | name 'Set a breakpoint in file **test.c** at line **12**' 260 | notes ' 261 | ``` 262 | (lldb) breakpoint set --file test.c --line 12 263 | (lldb) br s -f test.c -l 12 264 | (lldb) b test.c:12 265 | ``` 266 | ' 267 | end 268 | 269 | entry do 270 | name 'Set a breakpoint at all C++ methods whose basename is **main**' 271 | notes ' 272 | ``` 273 | (lldb) breakpoint set --method main 274 | (lldb) br s -M main 275 | ``` 276 | ' 277 | end 278 | 279 | entry do 280 | name 'Set a breakpoint at and object C function: `-[NSString stringWithFormat:]`' 281 | notes ' 282 | ``` 283 | (lldb) breakpoint set --name "-[NSString stringWithFormat:]" 284 | (lldb) b -[NSString stringWithFormat:] 285 | ``` 286 | ' 287 | end 288 | 289 | entry do 290 | name 'Set a breakpoint at all Objective C methods whose selector is **count**' 291 | notes ' 292 | ``` 293 | (lldb) breakpoint set --selector count 294 | (lldb) br s -S count 295 | ``` 296 | ' 297 | end 298 | 299 | entry do 300 | name 'Set a breakpoint by regular expression on function name' 301 | notes ' 302 | ``` 303 | (lldb) breakpoint set --func-regex regular-expression 304 | (lldb) br s -r regular-expression 305 | ``` 306 | ' 307 | end 308 | 309 | entry do 310 | name 'Ensure that breakpoints by file and line work for #included .c/.cpp/.m files' 311 | notes ' 312 | ``` 313 | (lldb) settings set target.inline-breakpoint-strategy always 314 | (lldb) br s -f foo.c -l 12 315 | ``` 316 | ' 317 | end 318 | 319 | entry do 320 | name 'Set a breakpoint by regular expression on source file contents' 321 | notes ' 322 | ``` 323 | (lldb) breakpoint set --source-pattern regular-expression --file SourceFile 324 | (lldb) br s -p regular-expression -f file 325 | ``` 326 | ' 327 | end 328 | 329 | entry do 330 | name 'Set a conditional breakpoint' 331 | notes " 332 | ``` 333 | (lldb) breakpoint set --name foo --condition '(int)strcmp(y,\"hello\") == 0' 334 | (lldb) br s -n foo -c '(int)strcmp(y,\"hello\") == 0' 335 | ``` 336 | " 337 | end 338 | 339 | entry do 340 | name 'List all breakpoints' 341 | notes ' 342 | ``` 343 | (lldb) breakpoint list 344 | (lldb) br l 345 | ``` 346 | ' 347 | end 348 | 349 | entry do 350 | name 'Delete a breakpoint' 351 | notes ' 352 | ``` 353 | (lldb) breakpoint delete 1 354 | (lldb) br del 1 355 | ``` 356 | ' 357 | end 358 | end 359 | 360 | category do 361 | id 'Watchpoint Commands' 362 | 363 | entry do 364 | name 'Set a watchpoint on a variable when it is written to' 365 | notes ' 366 | ``` 367 | (lldb) watchpoint set variable global_var 368 | (lldb) wa s v global_var 369 | ``` 370 | ' 371 | end 372 | 373 | entry do 374 | name "Set a watchpoint on a memory location when it is written into. The size of the region to watch for defaults to the pointer size if no '-x byte_size' is specified. This command takes raw input, evaluated as an expression returning an unsigned integer pointing to the start of the region, after the '--' option terminator" 375 | notes ' 376 | ``` 377 | (lldb) watchpoint set expression -- my_ptr 378 | (lldb) wa s e -- my_ptr 379 | ``` 380 | ' 381 | end 382 | 383 | entry do 384 | name 'Set a condition on a watchpoint' 385 | notes " 386 | ``` 387 | (lldb) watch set var global 388 | (lldb) watchpoint modify -c '(global==5)' 389 | (lldb) c 390 | ... 391 | (lldb) bt 392 | * thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1 393 | frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16 394 | frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25 395 | frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1 396 | (lldb) frame var global 397 | (int32_t) global = 5 398 | ``` 399 | " 400 | end 401 | 402 | entry do 403 | name 'List all watchpoints' 404 | notes ' 405 | ``` 406 | (lldb) watchpoint list 407 | (lldb) watch l 408 | ``` 409 | ' 410 | end 411 | 412 | entry do 413 | name 'Delete a watchpoint' 414 | notes ' 415 | ``` 416 | (lldb) watchpoint delete 1 417 | (lldb) watch del 1 418 | ``` 419 | ' 420 | end 421 | end 422 | 423 | category do 424 | id 'Examining Variables' 425 | 426 | entry do 427 | name 'Show the arguments and local variables for the current frame' 428 | notes ' 429 | ``` 430 | (lldb) frame variable 431 | (lldb) fr v 432 | ``` 433 | ' 434 | end 435 | 436 | entry do 437 | name 'Show the local variables for the current frame' 438 | notes ' 439 | ``` 440 | (lldb) frame variable --no-args 441 | (lldb) fr v -a 442 | ``` 443 | ' 444 | end 445 | 446 | entry do 447 | name 'Show the contents of local variable "bar"' 448 | notes ' 449 | ``` 450 | (lldb) frame variable bar 451 | (lldb) fr v bar 452 | (lldb) p bar 453 | ``` 454 | ' 455 | end 456 | 457 | entry do 458 | name 'Show the contents of local variable "bar" formatted as hex' 459 | notes ' 460 | ``` 461 | (lldb) frame variable --format x bar 462 | (lldb) fr v -f x bar 463 | ``` 464 | ' 465 | end 466 | 467 | entry do 468 | name 'Show the contents of global variable "baz"' 469 | notes ' 470 | ``` 471 | (lldb) target variable baz 472 | (lldb) ta v baz 473 | ``` 474 | ' 475 | end 476 | 477 | entry do 478 | name 'Show the global/static variables defined in the current source file' 479 | notes ' 480 | ``` 481 | (lldb) target variable 482 | (lldb) ta v 483 | ``` 484 | ' 485 | end 486 | 487 | entry do 488 | name 'Display a the variable "argc" and "argv" every time you stop' 489 | notes ' 490 | ``` 491 | (lldb) target stop-hook add --one-liner "frame variable argc argv" 492 | (lldb) ta st a -o "fr v argc argv" 493 | (lldb) display argc 494 | (lldb) display argv 495 | ``` 496 | ' 497 | end 498 | 499 | entry do 500 | name 'Display a the variable "argc" and "argv" only when you stop in the function named **main**' 501 | notes ' 502 | ``` 503 | (lldb) target stop-hook add --name main --one-liner "frame variable argc argv" 504 | (lldb) ta st a -n main -o "fr v argc argv" 505 | ``` 506 | ' 507 | end 508 | 509 | entry do 510 | name 'Display the variable "*this" only when you stop in c class named **MyClass**' 511 | notes ' 512 | ``` 513 | (lldb) target stop-hook add --classname MyClass --one-liner "frame variable *this" 514 | (lldb) ta st a -c MyClass -o "fr v *this" 515 | ``` 516 | ' 517 | end 518 | end 519 | 520 | category do 521 | id 'Evaluating Expressions' 522 | 523 | entry do 524 | name 'Evaluating a generalized expression in the current frame' 525 | notes ' 526 | ``` 527 | (lldb) expr (int) printf ("Print nine: %d.", 4 + 5) 528 | ``` 529 | or using the print alias: 530 | ``` 531 | (lldb) print (int) printf ("Print nine: %d.", 4 + 5) 532 | ``` 533 | ' 534 | end 535 | 536 | entry do 537 | name 'Creating and assigning a value to a convenience variable' 538 | notes ' 539 | In lldb you evaluate a variable declaration expression as you would write it in C: 540 | ``` 541 | (lldb) expr unsigned int $foo = 5 542 | ``` 543 | ' 544 | end 545 | 546 | entry do 547 | name 'Printing the ObjC "description" of an object' 548 | notes ' 549 | ``` 550 | (lldb) expr -o -- [SomeClass returnAnObject] 551 | ``` 552 | or using the po alias: 553 | ``` 554 | (lldb) po [SomeClass returnAnObject] 555 | ``` 556 | ' 557 | end 558 | 559 | entry do 560 | name 'Print the dynamic type of the result of an expression' 561 | notes ' 562 | ``` 563 | (lldb) expr -d 1 -- [SomeClass returnAnObject] 564 | (lldb) expr -d 1 -- someCPPObjectPtrOrReference 565 | ``` 566 | or set dynamic type printing to be the default: 567 | ``` 568 | (lldb) settings set target.prefer-dynamic run-target 569 | ``` 570 | ' 571 | end 572 | 573 | entry do 574 | name 'Calling a function so you can stop at a breakpoint in the function' 575 | notes ' 576 | ``` 577 | (lldb) expr -i 0 -- function_with_a_breakpoint() 578 | ``` 579 | ' 580 | end 581 | 582 | entry do 583 | name 'Calling a function that crashes, and stopping when the function crashes' 584 | notes ' 585 | ``` 586 | (lldb) expr -u 0 -- function_which_crashes() 587 | ``` 588 | ' 589 | end 590 | end 591 | 592 | category do 593 | id 'Examining Thread State' 594 | 595 | entry do 596 | name 'Show the stack backtrace for the current thread' 597 | notes ' 598 | ``` 599 | (lldb) thread backtrace 600 | (lldb) bt 601 | ``` 602 | ' 603 | end 604 | 605 | entry do 606 | name 'Show the stack backtraces for all threads' 607 | notes ' 608 | ``` 609 | (lldb) thread backtrace all 610 | (lldb) bt all 611 | ``` 612 | ' 613 | end 614 | 615 | entry do 616 | name 'Backtrace the first five frames of the current thread' 617 | notes ' 618 | ``` 619 | (lldb) thread backtrace -c 5 620 | (lldb) bt 5 (lldb-169 and later) 621 | (lldb) bt -c 5 (lldb-168 and earlier) 622 | ``` 623 | ' 624 | end 625 | 626 | entry do 627 | name 'Select a different stack frame by index for the current thread' 628 | notes ' 629 | ``` 630 | (lldb) frame select 12 631 | (lldb) fr s 12 632 | (lldb) f 12 633 | ``` 634 | ' 635 | end 636 | 637 | entry do 638 | name 'List information about the currently selected frame in the current thread' 639 | notes ' 640 | ``` 641 | (lldb) frame info 642 | ``` 643 | ' 644 | end 645 | 646 | entry do 647 | name 'Select the stack frame that called the current stack frame' 648 | notes ' 649 | ``` 650 | (lldb) up 651 | (lldb) frame select --relative=1 652 | ``` 653 | ' 654 | end 655 | 656 | entry do 657 | name 'Select the stack frame that is called by the current stack frame' 658 | notes ' 659 | ``` 660 | (lldb) down 661 | (lldb) frame select --relative=-1 662 | (lldb) fr s -r-1 663 | ``` 664 | ' 665 | end 666 | 667 | entry do 668 | name 'Select a different stack frame using a relative offset' 669 | notes ' 670 | ``` 671 | (lldb) frame select --relative 2 672 | (lldb) fr s -r2 673 | 674 | (lldb) frame select --relative -3 675 | (lldb) fr s -r-3 676 | ``` 677 | ' 678 | end 679 | 680 | entry do 681 | name 'Show the general purpose registers for the current thread' 682 | notes ' 683 | ``` 684 | (lldb) register read 685 | ``` 686 | ' 687 | end 688 | 689 | entry do 690 | name "Write a new decimal value '123' to the current thread register 'rax'" 691 | notes ' 692 | ``` 693 | (lldb) register write rax 123 694 | ``` 695 | ' 696 | end 697 | 698 | entry do 699 | name 'Skip 8 bytes ahead of the current program counter (instruction pointer). Note that we use backticks to evaluate an expression and insert the scalar result in LLDB' 700 | notes ' 701 | ``` 702 | (lldb) register write pc `$pc+8` 703 | ``` 704 | ' 705 | end 706 | 707 | entry do 708 | name 'Show the general purpose registers for the current thread formatted as **signed decimal**. LLDB tries to use the same format characters as `printf(3)` when possible. Type "help format" to see the full list of format specifiers.' 709 | notes " 710 | ``` 711 | (lldb) register read --format i 712 | (lldb) re r -f i 713 | ``` 714 | 715 | LLDB now supports the GDB shorthand format syntax but there can't be space after the command: 716 | ``` 717 | (lldb) register read/d 718 | ``` 719 | " 720 | end 721 | 722 | entry do 723 | name 'Show all registers in all register sets for the current thread' 724 | notes ' 725 | ``` 726 | (lldb) register read --all 727 | (lldb) re r -a 728 | ``` 729 | ' 730 | end 731 | 732 | entry do 733 | name 'Show the values for the registers named "rax", "rsp" and "rbp" in the current thread' 734 | notes ' 735 | ``` 736 | (lldb) register read rax rsp rbp 737 | ``` 738 | ' 739 | end 740 | 741 | entry do 742 | name 'Show the values for the register named "rax" in the current thread formatted as **binary**' 743 | notes " 744 | ``` 745 | (lldb) register read --format binary rax 746 | (lldb) re r -f b rax 747 | ``` 748 | 749 | LLDB now supports the GDB shorthand format syntax but there can't be space after the command: 750 | ``` 751 | (lldb) register read/t rax 752 | (lldb) p/t $rax 753 | ``` 754 | " 755 | end 756 | 757 | entry do 758 | name 'Read memory from address 0xbffff3c0 and show 4 hex uint32_t values' 759 | notes " 760 | ``` 761 | (lldb) memory read --size 4 --format x --count 4 0xbffff3c0 762 | (lldb) me r -s4 -fx -c4 0xbffff3c0 763 | (lldb) x -s4 -fx -c4 0xbffff3c0 764 | ``` 765 | 766 | LLDB now supports the GDB shorthand format syntax but there can't be space after the command: 767 | ``` 768 | (lldb) memory read/4xw 0xbffff3c0 769 | (lldb) x/4xw 0xbffff3c0 770 | (lldb) memory read --gdb-format 4xw 0xbffff3c0 771 | ``` 772 | " 773 | end 774 | 775 | entry do 776 | name 'Read memory starting at the expression "argv[0]"' 777 | notes ' 778 | ``` 779 | (lldb) memory read `argv[0]` 780 | ``` 781 | 782 | NOTE: any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression: 783 | ``` 784 | (lldb) memory read --size `sizeof(int)` `argv[0]` 785 | ``` 786 | ' 787 | end 788 | 789 | entry do 790 | name 'Read 512 bytes of memory from address 0xbffff3c0 and save results to a local file as **text**' 791 | notes ' 792 | ``` 793 | (lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0 794 | (lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0 795 | (lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0 796 | ``` 797 | ' 798 | end 799 | 800 | entry do 801 | name 'Save binary memory data starting at 0x1000 and ending at 0x2000 to a file' 802 | notes ' 803 | ``` 804 | (lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x2000 805 | (lldb) me r -o /tmp/mem.bin -b 0x1000 0x2000 806 | ``` 807 | ' 808 | end 809 | 810 | entry do 811 | name 'Get information about a specific heap allocation (available on Mac OS X only)' 812 | notes ' 813 | ``` 814 | (lldb) command script import lldb.macosx.heap 815 | (lldb) process launch --environment MallocStackLogging=1 -- [ARGS] 816 | (lldb) malloc_info --stack-history 0x10010d680 817 | ``` 818 | ' 819 | end 820 | 821 | entry do 822 | name 'Get information about a specific heap allocation and cast the result to any dynamic type that can be deduced (available on Mac OS X only)' 823 | notes ' 824 | ``` 825 | (lldb) command script import lldb.macosx.heap 826 | (lldb) malloc_info --type 0x10010d680 827 | ``` 828 | ' 829 | end 830 | 831 | entry do 832 | name 'Find all heap blocks that contain a pointer specified by an expression EXPR (available on Mac OS X only)' 833 | notes ' 834 | ``` 835 | (lldb) command script import lldb.macosx.heap 836 | (lldb) ptr_refs EXPR 837 | ``` 838 | ' 839 | end 840 | 841 | entry do 842 | name 'Find all heap blocks that contain a C string anywhere in the block (available on Mac OS X only)' 843 | notes ' 844 | ``` 845 | (lldb) command script import lldb.macosx.heap 846 | (lldb) cstr_refs CSTRING 847 | ``` 848 | ' 849 | end 850 | 851 | entry do 852 | name 'Disassemble the current function for the current frame' 853 | notes ' 854 | ``` 855 | (lldb) disassemble --frame 856 | (lldb) di -f 857 | ``` 858 | ' 859 | end 860 | 861 | entry do 862 | name 'Disassemble any functions named *main*' 863 | notes ' 864 | ``` 865 | (lldb) disassemble --name main 866 | (lldb) di -n main 867 | ``` 868 | ' 869 | end 870 | 871 | entry do 872 | name 'Disassemble an address range' 873 | notes ' 874 | ``` 875 | (lldb) disassemble --start-address 0x1eb8 --end-address 0x1ec3 876 | (lldb) di -s 0x1eb8 -e 0x1ec3 877 | ``` 878 | ' 879 | end 880 | 881 | entry do 882 | name 'Disassemble 20 instructions from a given address' 883 | notes ' 884 | ``` 885 | (lldb) disassemble --start-address 0x1eb8 --count 20 886 | (lldb) di -s 0x1eb8 -c 20 887 | ``` 888 | ' 889 | end 890 | 891 | entry do 892 | name 'Show mixed source and disassembly for the current function for the current frame' 893 | notes ' 894 | ``` 895 | (lldb) disassemble --frame --mixed 896 | (lldb) di -f -m 897 | ``` 898 | ' 899 | end 900 | 901 | entry do 902 | name 'Disassemble the current function for the current frame and show the opcode bytes' 903 | notes ' 904 | ``` 905 | (lldb) disassemble --frame --bytes 906 | (lldb) di -f -b 907 | ``` 908 | ' 909 | end 910 | 911 | entry do 912 | name 'Disassemble the current source line for the current frame' 913 | notes ' 914 | ``` 915 | (lldb) disassemble --line 916 | (lldb) di -l 917 | ``` 918 | ' 919 | end 920 | end 921 | 922 | category do 923 | id 'Executable and Shared Library Query Commands' 924 | 925 | entry do 926 | name 'List the main executable and all dependent shared libraries' 927 | notes ' 928 | ``` 929 | (lldb) image list 930 | ``` 931 | ' 932 | end 933 | 934 | entry do 935 | name 'Look up information for a raw address in the executable or any shared libraries' 936 | notes ' 937 | ``` 938 | (lldb) image lookup --address 0x1ec4 939 | (lldb) im loo -a 0x1ec4 940 | ``` 941 | ' 942 | end 943 | 944 | entry do 945 | name 'Look up functions matching a regular expression in a binary' 946 | notes ' 947 | This one finds debug symbols: 948 | ``` 949 | (lldb) image lookup -r -n 950 | ``` 951 | 952 | This one finds non-debug symbols: 953 | ``` 954 | (lldb) image lookup -r -s 955 | ``` 956 | 957 | Provide a list of binaries as arguments to limit the search. 958 | ' 959 | end 960 | 961 | entry do 962 | name 'Find full souce line information' 963 | notes ' 964 | This one is a bit messy at present. Do: 965 | ``` 966 | (lldb) image lookup -v --address 0x1ec4 967 | ``` 968 | 969 | and look for the LineEntry line, which will have the full source path and line range information. 970 | ' 971 | end 972 | 973 | entry do 974 | name 'Look up information for an address in **a.out** only' 975 | notes ' 976 | ``` 977 | (lldb) image lookup --address 0x1ec4 a.out 978 | (lldb) im loo -a 0x1ec4 a.out 979 | ``` 980 | ' 981 | end 982 | 983 | entry do 984 | name 'Look up information for for a type *Point* by name' 985 | notes ' 986 | ``` 987 | (lldb) image lookup --type Point 988 | (lldb) im loo -t Point 989 | ``` 990 | ' 991 | end 992 | 993 | entry do 994 | name 'Dump all sections from the main executable and any shared libraries' 995 | notes ' 996 | ``` 997 | (lldb) image dump sections 998 | ``` 999 | ' 1000 | end 1001 | 1002 | entry do 1003 | name 'Dump all sections in the **a.out** module' 1004 | notes ' 1005 | ``` 1006 | (lldb) image dump sections a.out 1007 | ``` 1008 | ' 1009 | end 1010 | 1011 | entry do 1012 | name 'Dump all symbols from the main executable and any shared libraries' 1013 | notes ' 1014 | ``` 1015 | (lldb) image dump symtab 1016 | ``` 1017 | ' 1018 | end 1019 | 1020 | entry do 1021 | name 'Dump all symbols in **a.out** and **liba.so**' 1022 | notes ' 1023 | ``` 1024 | (lldb) image dump symtab a.out liba.so 1025 | ``` 1026 | ' 1027 | end 1028 | end 1029 | 1030 | category do 1031 | id 'Miscellaneous' 1032 | 1033 | entry do 1034 | name 'Echo text to the screen' 1035 | notes ' 1036 | ``` 1037 | (lldb) script print "Here is some text" 1038 | ``` 1039 | ' 1040 | end 1041 | 1042 | entry do 1043 | name "Remap source file pathnames for the debug session. If your source files are no longer located in the same location as when the program was built --- maybe the program was built on a different computer --- you need to tell the debugger how to find the sources at their local file path instead of the build system's file path." 1044 | notes ' 1045 | ``` 1046 | (lldb) settings set target.source-map /buildbot/path /my/path 1047 | ``` 1048 | ' 1049 | end 1050 | end 1051 | 1052 | notes 'Based on the [GDB to LLDB command map](http://lldb.llvm.org/lldb-gdb.html) page on the [LLVM](http://llvm.org) website' 1053 | end 1054 | --------------------------------------------------------------------------------