1GDB to LLDB command map 2======================= 3 4Below is a table of GDB commands with their LLDB counterparts. The built in 5GDB-compatibility aliases in LLDB are also listed. The full lldb command names 6are often long, but any unique short form can be used. Instead of "**breakpoint 7set**", "**br se**" is also acceptable. 8 9* `Execution Commands`_ 10* `Breakpoint Commands`_ 11* `Watchpoint Commands`_ 12* `Examining Variables`_ 13* `Evaluating Expressions`_ 14* `Examining Thread State`_ 15* `Executable and Shared Library Query Commands`_ 16* `Miscellaneous`_ 17 18Execution Commands 19------------------ 20 21Launch a process no arguments 22~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 24.. code-block:: shell 25 26 (gdb) run 27 (gdb) r 28 29.. code-block:: shell 30 31 (lldb) process launch 32 (lldb) run 33 (lldb) r 34 35Launch a process with arguments ``<args>`` 36~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37 38.. code-block:: shell 39 40 (gdb) run <args> 41 (gdb) r <args> 42 43 44.. code-block:: shell 45 46 (lldb) process launch -- <args> 47 (lldb) run <args> 48 (lldb) r <args> 49 50Launch process ``a.out`` with arguments ``1 2 3`` by passing the args to the debugger 51~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 53.. code-block:: shell 54 55 % gdb --args a.out 1 2 3 56 (gdb) run 57 ... 58 (gdb) run 59 ... 60 61.. code-block:: shell 62 63 % lldb -- a.out 1 2 3 64 (lldb) run 65 ... 66 (lldb) run 67 ... 68 69 70Launch process a.out with arguments ``1 2 3`` by setting the args in the debugger 71~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 72 73.. code-block:: shell 74 75 (gdb) set args 1 2 3 76 (gdb) run 77 ... 78 (gdb) run 79 ... 80 81.. code-block:: shell 82 83 (lldb) settings set target.run-args 1 2 3 84 (lldb) run 85 ... 86 (lldb) run 87 ... 88 89Launch a process with arguments in new terminal window (macOS only) 90~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 91 92.. code-block:: shell 93 94 (lldb) process launch --tty -- <args> 95 (lldb) pro la -t -- <args> 96 97Launch a process with arguments ``<args>`` in existing terminal ``/dev/ttys006`` 98~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 99 100.. code-block:: shell 101 102 (lldb) process launch --tty=/dev/ttys006 -- <args> 103 (lldb) pro la -t/dev/ttys006 -- <args> 104 105 106Set environment variables for process before launching 107~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 108 109.. code-block:: shell 110 111 (gdb) set env DEBUG 1 112 113.. code-block:: shell 114 115 (lldb) settings set target.env-vars DEBUG=1 116 (lldb) set se target.env-vars DEBUG=1 117 (lldb) env DEBUG=1 118 119 120Unset environment variables for process before launching 121~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 122 123.. code-block:: shell 124 125 (gdb) unset env DEBUG 126 127.. code-block:: shell 128 129 (lldb) settings remove target.env-vars DEBUG 130 (lldb) set rem target.env-vars DEBUG 131 132Show the arguments that will be or were passed to the program when run 133~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 134 135.. code-block:: shell 136 137 (gdb) show args 138 Argument list to give program being debugged when it is started is "1 2 3". 139 140.. code-block:: shell 141 142 (lldb) settings show target.run-args 143 target.run-args (array of strings) = 144 [0]: "1" 145 [1]: "2" 146 [2]: "3" 147 148Set environment variables for process and launch process in one command 149~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 150 151.. code-block:: shell 152 153 (lldb) process launch -E DEBUG=1 154 155Attach to the process with process ID 123 156~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 157 158.. code-block:: shell 159 160 (gdb) attach 123 161 162.. code-block:: shell 163 164 (lldb) process attach --pid 123 165 (lldb) attach -p 123 166 167Attach to the process named ``a.out`` 168~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 169 170.. code-block:: shell 171 172 (gdb) attach a.out 173 174.. code-block:: shell 175 176 (lldb) process attach --name a.out 177 (lldb) pro at -n a.out 178 179Wait for a process named ``a.out`` to launch and attach 180~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 181 182.. code-block:: shell 183 184 (gdb) attach -waitfor a.out 185 186.. code-block:: shell 187 188 (lldb) process attach --name a.out --waitfor 189 (lldb) pro at -n a.out -w 190 191Attach to a remote gdb protocol server running on system ``eorgadd``, port ``8000`` 192~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 193 194.. code-block:: shell 195 196 (gdb) target remote eorgadd:8000 197 198.. code-block:: shell 199 200 (lldb) gdb-remote eorgadd:8000 201 202Attach to a remote gdb protocol server running on the local system, port ``8000`` 203~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 204 205.. code-block:: shell 206 207 (gdb) target remote localhost:8000 208 209.. code-block:: shell 210 211 (lldb) gdb-remote 8000 212 213Attach to a Darwin kernel in kdp mode on system ``eorgadd`` 214~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 215 216.. code-block:: shell 217 218 (gdb) kdp-reattach eorgadd 219 220.. code-block:: shell 221 222 (lldb) kdp-remote eorgadd 223 224Do a source level single step in the currently selected thread 225~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 226 227.. code-block:: shell 228 229 (gdb) step 230 (gdb) s 231 232.. code-block:: shell 233 234 (lldb) thread step-in 235 (lldb) step 236 (lldb) s 237 238Ignore a function when doing a source level single step in 239~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 240 241.. code-block:: shell 242 243 (gdb) skip abc 244 Function abc will be skipped when stepping. 245 246.. code-block:: shell 247 248 (lldb) settings show target.process.thread.step-avoid-regexp 249 target.process.thread.step-avoid-regexp (regex) = ^std:: 250 (lldb) settings set target.process.thread.step-avoid-regexp ^std::|^abc 251 252You can ignore a function once using: 253 254.. code-block:: shell 255 256 (lldb) thread step-in -r ^abc 257 258Or you can do the opposite, only step into functions matching a certain name: 259 260.. code-block:: shell 261 262 # Step in if abc is a substring of the function name. 263 (lldb) sif abc 264 # Which is equivalent to: 265 (lldb) thread step-in -t abc 266 267``thread step-in`` has more options which cover some of ``skip``'s other 268features. See ``help thread step-in`` for details. 269 270Do a source level single step over in the currently selected thread 271~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 272 273.. code-block:: shell 274 275 (gdb) next 276 (gdb) n 277 278.. code-block:: shell 279 280 (lldb) thread step-over 281 (lldb) next 282 (lldb) n 283 284Do an instruction level single step in the currently selected thread 285~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 286 287.. code-block:: shell 288 289 (gdb) stepi 290 (gdb) si 291 292.. code-block:: shell 293 294 (lldb) thread step-inst 295 (lldb) si 296 297Do an instruction level single step over in the currently selected thread 298~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 299 300.. code-block:: shell 301 302 (gdb) nexti 303 (gdb) ni 304 305.. code-block:: shell 306 307 (lldb) thread step-inst-over 308 (lldb) ni 309 310Step out of the currently selected frame 311~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 312 313.. code-block:: shell 314 315 (gdb) finish 316 317.. code-block:: shell 318 319 (lldb) thread step-out 320 (lldb) finish 321 322Return immediately from the currently selected frame, with an optional return value 323~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 324 325.. code-block:: shell 326 327 (gdb) return <RETURN EXPRESSION> 328 329.. code-block:: shell 330 331 (lldb) thread return <RETURN EXPRESSION> 332 333Backtrace and disassemble every time you stop 334~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 335 336.. code-block:: shell 337 338 (lldb) target stop-hook add 339 Enter your stop hook command(s). Type 'DONE' to end. 340 > bt 341 > disassemble --pc 342 > DONE 343 Stop hook #1 added. 344 345Run until we hit line 12 or control leaves the current function 346~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 347 348.. code-block:: shell 349 350 (gdb) until 12 351 352.. code-block:: shell 353 354 (lldb) thread until 12 355 356Show the current frame and source line 357~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 358 359.. code-block:: shell 360 361 (gdb) frame 362 363.. code-block:: shell 364 365 (lldb) frame select 366 (lldb) f 367 (lldb) process status 368 369Breakpoint Commands 370------------------- 371 372Set a breakpoint at all functions named main 373~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 374 375.. code-block:: shell 376 377 (gdb) break main 378 379.. code-block:: shell 380 381 (lldb) breakpoint set --name main 382 (lldb) br s -n main 383 (lldb) b main 384 385Set a breakpoint in file ``test.c`` at line ``12`` 386~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 387 388.. code-block:: shell 389 390 (gdb) break test.c:12 391 392.. code-block:: shell 393 394 (lldb) breakpoint set --file test.c --line 12 395 (lldb) br s -f test.c -l 12 396 (lldb) b test.c:12 397 398Set a breakpoint at all C++ methods whose basename is ``main`` 399~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 400 401.. code-block:: shell 402 403 (gdb) break main 404 (Hope that there are no C functions named main) 405 406.. code-block:: shell 407 408 (lldb) breakpoint set --method main 409 (lldb) br s -M main 410 411Set a breakpoint at an Objective-C function ``-[NSString stringWithFormat:]`` 412~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 413 414.. code-block:: shell 415 416 (gdb) break -[NSString stringWithFormat:] 417 418.. code-block:: shell 419 420 (lldb) breakpoint set --name "-[NSString stringWithFormat:]" 421 (lldb) b -[NSString stringWithFormat:] 422 423Set a breakpoint at all Objective-C methods whose selector is ``count`` 424~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 425 426.. code-block:: shell 427 428 (gdb) break count 429 (Hope that there are no C or C++ functions named count) 430 431.. code-block:: shell 432 433 (lldb) breakpoint set --selector count 434 (lldb) br s -S count 435 436Set a breakpoint by regular expression on function name 437~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 438 439.. code-block:: shell 440 441 (gdb) rbreak regular-expression 442 443.. code-block:: shell 444 445 (lldb) breakpoint set --func-regex regular-expression 446 (lldb) br s -r regular-expression 447 448Ensure that breakpoints by file and line work for ``#include .c/.cpp/.m`` files 449~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 450 451.. code-block:: shell 452 453 (gdb) b foo.c:12 454 455.. code-block:: shell 456 457 (lldb) settings set target.inline-breakpoint-strategy always 458 (lldb) br s -f foo.c -l 12 459 460Set a breakpoint by regular expression on source file contents 461~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 462 463.. code-block:: shell 464 465 (gdb) shell grep -e -n pattern source-file 466 (gdb) break source-file:CopyLineNumbers 467 468.. code-block:: shell 469 470 (lldb) breakpoint set --source-pattern regular-expression --file SourceFile 471 (lldb) br s -p regular-expression -f file 472 473Set a conditional breakpoint 474~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 475 476.. code-block:: shell 477 478 (gdb) break foo if strcmp(y,"hello") == 0 479 480.. code-block:: shell 481 482 (lldb) breakpoint set --name foo --condition '(int)strcmp(y,"hello") == 0' 483 (lldb) br s -n foo -c '(int)strcmp(y,"hello") == 0' 484 485List all breakpoints 486~~~~~~~~~~~~~~~~~~~~ 487 488.. code-block:: shell 489 490 (gdb) info break 491 492.. code-block:: shell 493 494 (lldb) breakpoint list 495 (lldb) br l 496 497Delete a breakpoint 498~~~~~~~~~~~~~~~~~~~ 499 500.. code-block:: shell 501 502 (gdb) delete 1 503 504.. code-block:: shell 505 506 (lldb) breakpoint delete 1 507 (lldb) br del 1 508 509Disable a breakpoint 510~~~~~~~~~~~~~~~~~~~~ 511 512.. code-block:: shell 513 514 (gdb) disable 1 515 516.. code-block:: shell 517 518 (lldb) breakpoint disable 1 519 (lldb) br dis 1 520 521Enable a breakpoint 522~~~~~~~~~~~~~~~~~~~ 523 524.. code-block:: shell 525 526 (gdb) enable 1 527 528.. code-block:: shell 529 530 (lldb) breakpoint enable 1 531 (lldb) br en 1 532 533 534Watchpoint Commands 535------------------- 536 537Set a watchpoint on a variable when it is written to 538~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 539.. code-block:: shell 540 541 (gdb) watch global_var 542 543.. code-block:: shell 544 545 (lldb) watchpoint set variable global_var 546 (lldb) wa s v global_var 547 548Set a watchpoint on a memory location when it is written into 549~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 550 551The 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. 552 553.. code-block:: shell 554 555 (gdb) watch -location g_char_ptr 556 557.. code-block:: shell 558 559 (lldb) watchpoint set expression -- my_ptr 560 (lldb) wa s e -- my_ptr 561 562Set a condition on a watchpoint 563~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 564 565.. code-block:: shell 566 567 (lldb) watch set var global 568 (lldb) watchpoint modify -c '(global==5)' 569 (lldb) c 570 ... 571 (lldb) bt 572 * thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1 573 frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16 574 frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25 575 frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1 576 (lldb) frame var global 577 (int32_t) global = 5 578 579List all watchpoints 580~~~~~~~~~~~~~~~~~~~~ 581 582.. code-block:: shell 583 584 (gdb) info break 585 586.. code-block:: shell 587 588 (lldb) watchpoint list 589 (lldb) watch l 590 591Delete a watchpoint 592~~~~~~~~~~~~~~~~~~~ 593 594.. code-block:: shell 595 596 (gdb) delete 1 597 598.. code-block:: shell 599 600 (lldb) watchpoint delete 1 601 (lldb) watch del 1 602 603 604Examining Variables 605------------------- 606 607Show the arguments and local variables for the current frame 608~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 609 610.. code-block:: shell 611 612 (gdb) info args 613 (gdb) info locals 614 615.. code-block:: shell 616 617 (lldb) frame variable 618 (lldb) fr v 619 620Show the local variables for the current frame 621~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 622 623.. code-block:: shell 624 625 (gdb) info locals 626 627.. code-block:: shell 628 629 (lldb) frame variable --no-args 630 (lldb) fr v -a 631 632Show the contents of local variable ``bar`` 633~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 634 635.. code-block:: shell 636 637 (gdb) p bar 638 639.. code-block:: shell 640 641 (lldb) frame variable bar 642 (lldb) fr v bar 643 (lldb) p bar 644 645Show the contents of local variable ``bar`` formatted as hex 646~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 647 648.. code-block:: shell 649 650 (gdb) p/x bar 651 652.. code-block:: shell 653 654 (lldb) frame variable --format x bar 655 (lldb) fr v -f x bar 656 657Show the contents of global variable ``baz`` 658~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 659 660.. code-block:: shell 661 662 (gdb) p baz 663 664.. code-block:: shell 665 666 (lldb) target variable baz 667 (lldb) ta v baz 668 669Show the global/static variables defined in the current source file 670~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 671 672.. code-block:: shell 673 674 (lldb) target variable 675 (lldb) ta v 676 677Display the variables ``argc`` and ``argv`` every time you stop 678~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 679 680.. code-block:: shell 681 682 (gdb) display argc 683 (gdb) display argv 684 685.. code-block:: shell 686 687 (lldb) target stop-hook add --one-liner "frame variable argc argv" 688 (lldb) ta st a -o "fr v argc argv" 689 (lldb) display argc 690 (lldb) display argv 691 692Display the variables ``argc`` and ``argv`` only when you stop in the function named ``main`` 693~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 694 695.. code-block:: shell 696 697 (lldb) target stop-hook add --name main --one-liner "frame variable argc argv" 698 (lldb) ta st a -n main -o "fr v argc argv" 699 700Display the variable ``*this`` only when you stop in c class named ``MyClass`` 701~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 702 703.. code-block:: shell 704 705 (lldb) target stop-hook add --classname MyClass --one-liner "frame variable *this" 706 (lldb) ta st a -c MyClass -o "fr v *this" 707 708Print an array of integers in memory, assuming we have a pointer like ``int *ptr`` 709~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 710 711.. code-block:: shell 712 713 (gdb) p *ptr@10 714 715.. code-block:: shell 716 717 (lldb) parray 10 ptr 718 719Evaluating Expressions 720---------------------- 721 722Evaluating a generalized expression in the current frame 723~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 724 725.. code-block:: shell 726 727 (gdb) print (int) printf ("Print nine: %d.", 4 + 5) 728 729or if you don't want to see void returns: 730 731.. code-block:: shell 732 733 (gdb) call (int) printf ("Print nine: %d.", 4 + 5) 734 735.. code-block:: shell 736 737 (lldb) expr (int) printf ("Print nine: %d.", 4 + 5) 738 739or using the print alias: 740 741.. code-block:: shell 742 743 (lldb) print (int) printf ("Print nine: %d.", 4 + 5) 744 745Creating and assigning a value to a convenience variable 746~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 747 748.. code-block:: shell 749 750 (gdb) set $foo = 5 751 (gdb) set variable $foo = 5 752 753or using the print command 754 755.. code-block:: shell 756 757 (gdb) print $foo = 5 758 759or using the call command 760 761.. code-block:: shell 762 763 (gdb) call $foo = 5 764 765and if you want to specify the type of the variable: 766 767.. code-block:: shell 768 769 (gdb) set $foo = (unsigned int) 5 770 771In lldb you evaluate a variable declaration expression as you would write it in C: 772 773.. code-block:: shell 774 775 (lldb) expr unsigned int $foo = 5 776 777Printing the ObjC "description" of an object 778~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 779 780.. code-block:: shell 781 782 (gdb) po [SomeClass returnAnObject] 783 784.. code-block:: shell 785 786 (lldb) expr -o -- [SomeClass returnAnObject] 787 788or using the po alias: 789 790.. code-block:: shell 791 792 (lldb) po [SomeClass returnAnObject] 793 794Print the dynamic type of the result of an expression 795~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 796 797.. code-block:: shell 798 799 (gdb) set print object 1 800 (gdb) p someCPPObjectPtrOrReference 801 (Only works for C++ objects) 802 803.. code-block:: shell 804 805 (lldb) expr -d 1 -- [SomeClass returnAnObject] 806 (lldb) expr -d 1 -- someCPPObjectPtrOrReference 807 808or set dynamic type printing to be the default: 809 810.. code-block:: shell 811 812 (lldb) settings set target.prefer-dynamic run-target 813 814Call a function so you can stop at a breakpoint in it 815~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 816 817.. code-block:: shell 818 819 (gdb) set unwindonsignal 0 820 (gdb) p function_with_a_breakpoint() 821 822.. code-block:: shell 823 824 (lldb) expr -i 0 -- function_with_a_breakpoint() 825 826Call a function that crashes, then stop when it does 827~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 828 829.. code-block:: shell 830 831 (gdb) set unwindonsignal 0 832 (gdb) p function_which_crashes() 833 834.. code-block:: shell 835 836 (lldb) expr -u 0 -- function_which_crashes() 837 838Examining Thread State 839---------------------- 840 841List the threads in your program 842~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 843 844.. code-block:: shell 845 846 (gdb) info threads 847 848.. code-block:: shell 849 850 (lldb) thread list 851 852Select thread ``1`` as the default thread for subsequent commands 853~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 854 855.. code-block:: shell 856 857 (gdb) thread 1 858 859.. code-block:: shell 860 861 (lldb) thread select 1 862 (lldb) t 1 863 864Show the stack backtrace for the current thread 865~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 866 867.. code-block:: shell 868 869 (gdb) bt 870 871.. code-block:: shell 872 873 (lldb) thread backtrace 874 (lldb) bt 875 876Show the stack backtraces for all threads 877~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 878 879.. code-block:: shell 880 881 (gdb) thread apply all bt 882 883.. code-block:: shell 884 885 (lldb) thread backtrace all 886 (lldb) bt all 887 888Backtrace the first five frames of the current thread 889~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 890 891.. code-block:: shell 892 893 (gdb) bt 5 894 895.. code-block:: shell 896 897 (lldb) thread backtrace -c 5 898 (lldb) bt 5 899 900Select a different stack frame by index for the current thread 901~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 902 903.. code-block:: shell 904 905 (gdb) frame 12 906 907.. code-block:: shell 908 909 (lldb) frame select 12 910 (lldb) fr s 12 911 (lldb) f 12 912 913List information about the currently selected frame in the current thread 914~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 915 916.. code-block:: shell 917 918 (lldb) frame info 919 920Select the stack frame that called the current stack frame 921~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 922 923.. code-block:: shell 924 925 (gdb) up 926 927.. code-block:: shell 928 929 (lldb) up 930 (lldb) frame select --relative=1 931 932Select the stack frame that is called by the current stack frame 933~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 934 935.. code-block:: shell 936 937 (gdb) down 938 939.. code-block:: shell 940 941 (lldb) down 942 (lldb) frame select --relative=-1 943 (lldb) fr s -r-1 944 945Select a different stack frame using a relative offset 946~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 947 948.. code-block:: shell 949 950 (gdb) up 2 951 (gdb) down 3 952 953.. code-block:: shell 954 955 (lldb) frame select --relative 2 956 (lldb) fr s -r2 957 958 (lldb) frame select --relative -3 959 (lldb) fr s -r-3 960 961show the general purpose registers for the current thread 962~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 963 964.. code-block:: shell 965 966 (gdb) info registers 967 968.. code-block:: shell 969 970 (lldb) register read 971 972Write a new decimal value ``123`` to the current thread register ``rax`` 973~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 974 975.. code-block:: shell 976 977 (gdb) p $rax = 123 978 979.. code-block:: shell 980 981 (lldb) register write rax 123 982 983Skip 8 bytes ahead of the current program counter (instruction pointer) 984~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 985 986Note that we use backticks to evaluate an expression and insert the scalar result in LLDB. 987 988 989.. code-block:: shell 990 991 (gdb) jump *$pc+8 992 993.. code-block:: shell 994 995 (lldb) register write pc `$pc+8` 996 997Show the general purpose registers for the current thread formatted as signed decimal 998~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 999 1000LLDB tries to use the same format characters as printf(3) when possible. Type "help format" to see the full list of format specifiers. 1001 1002.. code-block:: shell 1003 1004 (lldb) register read --format i 1005 (lldb) re r -f i 1006 1007LLDB now supports the GDB shorthand format syntax but there can't be space after the command: 1008 1009.. code-block:: shell 1010 1011 (lldb) register read/d 1012 1013Show all registers in all register sets for the current thread 1014~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1015 1016.. code-block:: shell 1017 1018 (gdb) info all-registers 1019 1020.. code-block:: shell 1021 1022 (lldb) register read --all 1023 (lldb) re r -a 1024 1025Show the values for the registers named ``rax``, ``rsp`` and ``rbp`` in the current thread 1026~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1027 1028.. code-block:: shell 1029 1030 (gdb) info all-registers rax rsp rbp 1031 1032.. code-block:: shell 1033 1034 (lldb) register read rax rsp rbp 1035 1036Show the values for the register named ``rax`` in the current thread formatted as binary 1037~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1038 1039.. code-block:: shell 1040 1041 (gdb) p/t $rax 1042 1043.. code-block:: shell 1044 1045 (lldb) register read --format binary rax 1046 (lldb) re r -f b rax 1047 1048LLDB now supports the GDB shorthand format syntax but there can't be space after the command 1049 1050.. code-block:: shell 1051 1052 (lldb) register read/t rax 1053 (lldb) p/t $rax 1054 1055Read memory from address ``0xbffff3c0`` and show 4 hex ``uint32_t`` values 1056~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1057 1058.. code-block:: shell 1059 1060 (gdb) x/4xw 0xbffff3c0 1061 1062.. code-block:: shell 1063 1064 (lldb) memory read --size 4 --format x --count 4 0xbffff3c0 1065 (lldb) me r -s4 -fx -c4 0xbffff3c0 1066 (lldb) x -s4 -fx -c4 0xbffff3c0 1067 1068LLDB now supports the GDB shorthand format syntax but there can't be space after the command: 1069 1070.. code-block:: shell 1071 1072 (lldb) memory read/4xw 0xbffff3c0 1073 (lldb) x/4xw 0xbffff3c0 1074 (lldb) memory read --gdb-format 4xw 0xbffff3c0 1075 1076Read memory starting at the expression ``argv[0]`` 1077~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1078 1079.. code-block:: shell 1080 1081 (gdb) x argv[0] 1082 1083.. code-block:: shell 1084 1085 (lldb) memory read `argv[0]` 1086 1087NOTE: any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression: 1088 1089.. code-block:: shell 1090 1091 (lldb) memory read --size `sizeof(int)` `argv[0]` 1092 1093Read ``512`` bytes of memory from address ``0xbffff3c0`` and save the results to a local file as text 1094~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1095 1096.. code-block:: shell 1097 1098 (gdb) set logging on 1099 (gdb) set logging file /tmp/mem.txt 1100 (gdb) x/512bx 0xbffff3c0 1101 (gdb) set logging off 1102 1103.. code-block:: shell 1104 1105 (lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0 1106 (lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0 1107 (lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0 1108 1109Save binary memory data starting at ``0x1000`` and ending at ``0x2000`` to a file 1110~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1111 1112.. code-block:: shell 1113 1114 (gdb) dump memory /tmp/mem.bin 0x1000 0x2000 1115 1116.. code-block:: shell 1117 1118 (lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x2000 1119 (lldb) me r -o /tmp/mem.bin -b 0x1000 0x2000 1120 1121Get information about a specific heap allocation (macOS only) 1122~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1123 1124.. code-block:: shell 1125 1126 (gdb) info malloc 0x10010d680 1127 1128.. code-block:: shell 1129 1130 (lldb) command script import lldb.macosx.heap 1131 (lldb) process launch --environment MallocStackLogging=1 -- [ARGS] 1132 (lldb) malloc_info --stack-history 0x10010d680 1133 1134Get information about a specific heap allocation and cast the result to any dynamic type that can be deduced (macOS only) 1135~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1136 1137.. code-block:: shell 1138 1139 (lldb) command script import lldb.macosx.heap 1140 (lldb) malloc_info --type 0x10010d680 1141 1142Find all heap blocks that contain a pointer specified by an expression ``EXPR`` (macOS only) 1143~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1144 1145.. code-block:: shell 1146 1147 (lldb) command script import lldb.macosx.heap 1148 (lldb) ptr_refs EXPR 1149 1150Find all heap blocks that contain a C string anywhere in the block (macOS only) 1151~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1152 1153.. code-block:: shell 1154 1155 (lldb) command script import lldb.macosx.heap 1156 (lldb) cstr_refs CSTRING 1157 1158Disassemble the current function for the current frame 1159~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1160 1161.. code-block:: shell 1162 1163 (gdb) disassemble 1164 1165.. code-block:: shell 1166 1167 (lldb) disassemble --frame 1168 (lldb) di -f 1169 1170Disassemble any functions named main 1171~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1172 1173.. code-block:: shell 1174 1175 (gdb) disassemble main 1176 1177 1178.. code-block:: shell 1179 1180 (lldb) disassemble --name main 1181 (lldb) di -n main 1182 1183Disassemble an address range 1184~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1185 1186.. code-block:: shell 1187 1188 (gdb) disassemble 0x1eb8 0x1ec3 1189 1190.. code-block:: shell 1191 1192 (lldb) disassemble --start-address 0x1eb8 --end-address 0x1ec3 1193 (lldb) di -s 0x1eb8 -e 0x1ec3 1194 1195Disassemble ``20`` instructions from a given address 1196~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1197 1198.. code-block:: shell 1199 1200 (gdb) x/20i 0x1eb8 1201 1202.. code-block:: shell 1203 1204 (lldb) disassemble --start-address 0x1eb8 --count 20 1205 (lldb) di -s 0x1eb8 -c 20 1206 1207Show mixed source and disassembly for the current function for the current frame 1208~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1209 1210.. code-block:: shell 1211 1212 (lldb) disassemble --frame --mixed 1213 (lldb) di -f -m 1214 1215Disassemble the current function for the current frame and show the opcode bytes 1216~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1217 1218.. code-block:: shell 1219 1220 (lldb) disassemble --frame --bytes 1221 (lldb) di -f -b 1222 1223Disassemble the current source line for the current frame 1224~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1225 1226.. code-block:: shell 1227 1228 (lldb) disassemble --line 1229 (lldb) di -l 1230 1231Executable and Shared Library Query Commands 1232-------------------------------------------- 1233 1234List the main executable and all dependent shared libraries 1235~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1236 1237.. code-block:: shell 1238 1239 (gdb) info shared 1240 1241.. code-block:: shell 1242 1243 (lldb) image list 1244 1245Look up information for a raw address in the executable or any shared libraries 1246~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1247 1248.. code-block:: shell 1249 1250 (gdb) info symbol 0x1ec4 1251 1252.. code-block:: shell 1253 1254 (lldb) image lookup --address 0x1ec4 1255 (lldb) im loo -a 0x1ec4 1256 1257Look up functions matching a regular expression in a binary 1258~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1259 1260.. code-block:: shell 1261 1262 (gdb) info function <FUNC_REGEX> 1263 1264This one finds debug symbols: 1265 1266.. code-block:: shell 1267 1268 (lldb) image lookup -r -n <FUNC_REGEX> 1269 1270This one finds non-debug symbols: 1271 1272.. code-block:: shell 1273 1274 (lldb) image lookup -r -s <FUNC_REGEX> 1275 1276Provide a list of binaries as arguments to limit the search. 1277 1278Find full source line information 1279~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1280 1281.. code-block:: shell 1282 1283 (gdb) info line 0x1ec4 1284 1285This one is a bit messy at present. Do: 1286 1287.. code-block:: shell 1288 1289 (lldb) image lookup -v --address 0x1ec4 1290 1291and look for the LineEntry line, which will have the full source path and line range information. 1292 1293Look up information for an address in ``a.out`` only 1294~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1295 1296.. code-block:: shell 1297 1298 (lldb) image lookup --address 0x1ec4 a.out 1299 (lldb) im loo -a 0x1ec4 a.out 1300 1301Look up information for for a type ``Point`` by name 1302~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1303 1304.. code-block:: shell 1305 1306 (gdb) ptype Point 1307 1308.. code-block:: shell 1309 1310 (lldb) image lookup --type Point 1311 (lldb) im loo -t Point 1312 1313Dump all sections from the main executable and any shared libraries 1314~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1315 1316.. code-block:: shell 1317 1318 (gdb) maintenance info sections 1319 1320.. code-block:: shell 1321 1322 (lldb) image dump sections 1323 1324Dump all sections in the ``a.out`` module 1325~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1326 1327.. code-block:: shell 1328 1329 (lldb) image dump sections a.out 1330 1331Dump all symbols from the main executable and any shared libraries 1332~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1333 1334.. code-block:: shell 1335 1336 (lldb) image dump symtab 1337 1338Dump all symbols in ``a.out`` and ``liba.so`` 1339~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1340 1341.. code-block:: shell 1342 1343 (lldb) image dump symtab a.out liba.so 1344 1345Miscellaneous 1346------------- 1347 1348Search command help for a keyword 1349~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1350 1351.. code-block:: shell 1352 1353 (gdb) apropos keyword 1354 1355.. code-block:: shell 1356 1357 (lldb) apropos keyword 1358 1359Echo text to the screen 1360~~~~~~~~~~~~~~~~~~~~~~~ 1361 1362.. code-block:: shell 1363 1364 (gdb) echo Here is some text\n 1365 1366.. code-block:: shell 1367 1368 (lldb) script print "Here is some text" 1369 1370Remap source file pathnames for the debug session 1371~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1372 1373If your source files are no longer located in the same location as when the 1374program was built (for example, if the program was built on a different 1375computer) you need to tell the debugger how to find the sources at their local 1376file path instead of the build system's file path. 1377 1378.. code-block:: shell 1379 1380 (gdb) set pathname-substitutions /buildbot/path /my/path 1381 1382.. code-block:: shell 1383 1384 (lldb) settings set target.source-map /buildbot/path /my/path 1385 1386Supply a catchall directory to search for source files in. 1387 1388.. code-block:: shell 1389 1390 (gdb) directory /my/path 1391