1424 lines · plain
1GDB to LLDB command map2=======================3 4Below is a table of GDB commands with their LLDB counterparts. The built in5GDB-compatibility aliases in LLDB are also listed. The full lldb command names6are often long, but any unique short form can be used. Instead of "**breakpoint7set**", "**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 Commands19------------------20 21Launch a process no arguments22~~~~~~~~~~~~~~~~~~~~~~~~~~~~~23 24.. code-block:: shell25 26 (gdb) run27 (gdb) r28 29.. code-block:: shell30 31 (lldb) process launch32 (lldb) run33 (lldb) r34 35Launch a process with arguments ``<args>``36~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~37 38.. code-block:: shell39 40 (gdb) run <args>41 (gdb) r <args>42 43 44.. code-block:: shell45 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 debugger51~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~52 53.. code-block:: shell54 55 % gdb --args a.out 1 2 356 (gdb) run57 ...58 (gdb) run59 ...60 61.. code-block:: shell62 63 % lldb -- a.out 1 2 364 (lldb) run65 ...66 (lldb) run67 ...68 69 70Launch process a.out with arguments ``1 2 3`` by setting the args in the debugger71~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~72 73.. code-block:: shell74 75 (gdb) set args 1 2 376 (gdb) run77 ...78 (gdb) run79 ...80 81.. code-block:: shell82 83 (lldb) settings set target.run-args 1 2 384 (lldb) run85 ...86 (lldb) run87 ...88 89Launch a process with arguments in new terminal window (macOS only)90~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~91 92.. code-block:: shell93 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:: shell101 102 (lldb) process launch --tty=/dev/ttys006 -- <args>103 (lldb) pro la -t/dev/ttys006 -- <args>104 105 106Set environment variables for process before launching107~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~108 109.. code-block:: shell110 111 (gdb) set env DEBUG 1112 113.. code-block:: shell114 115 (lldb) settings set target.env-vars DEBUG=1116 (lldb) set se target.env-vars DEBUG=1117 (lldb) env DEBUG=1118 119 120Unset environment variables for process before launching121~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~122 123.. code-block:: shell124 125 (gdb) unset env DEBUG126 127.. code-block:: shell128 129 (lldb) settings remove target.env-vars DEBUG130 (lldb) set rem target.env-vars DEBUG131 132Show the arguments that will be or were passed to the program when run133~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~134 135.. code-block:: shell136 137 (gdb) show args138 Argument list to give program being debugged when it is started is "1 2 3".139 140.. code-block:: shell141 142 (lldb) settings show target.run-args143 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 command149~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~150 151.. code-block:: shell152 153 (lldb) process launch -E DEBUG=1154 155Attach to the process with process ID 123156~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~157 158.. code-block:: shell159 160 (gdb) attach 123161 162.. code-block:: shell163 164 (lldb) process attach --pid 123165 (lldb) attach -p 123166 167Attach to the process named ``a.out``168~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~169 170.. code-block:: shell171 172 (gdb) attach a.out173 174.. code-block:: shell175 176 (lldb) process attach --name a.out177 (lldb) pro at -n a.out178 179Wait for a process named ``a.out`` to launch and attach180~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~181 182.. code-block:: shell183 184 (gdb) attach -waitfor a.out185 186.. code-block:: shell187 188 (lldb) process attach --name a.out --waitfor189 (lldb) pro at -n a.out -w190 191Attach to a remote gdb protocol server running on system ``eorgadd``, port ``8000``192~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~193 194.. code-block:: shell195 196 (gdb) target remote eorgadd:8000197 198.. code-block:: shell199 200 (lldb) gdb-remote eorgadd:8000201 202Attach to a remote gdb protocol server running on the local system, port ``8000``203~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~204 205.. code-block:: shell206 207 (gdb) target remote localhost:8000208 209.. code-block:: shell210 211 (lldb) gdb-remote 8000212 213Attach to a Darwin kernel in kdp mode on system ``eorgadd``214~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~215 216.. code-block:: shell217 218 (gdb) kdp-reattach eorgadd219 220.. code-block:: shell221 222 (lldb) kdp-remote eorgadd223 224Do a source level single step in the currently selected thread225~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~226 227.. code-block:: shell228 229 (gdb) step230 (gdb) s231 232.. code-block:: shell233 234 (lldb) thread step-in235 (lldb) step236 (lldb) s237 238Ignore a function when doing a source level single step in239~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~240 241.. code-block:: shell242 243 (gdb) skip abc244 Function abc will be skipped when stepping.245 246.. code-block:: shell247 248 (lldb) settings show target.process.thread.step-avoid-regexp249 target.process.thread.step-avoid-regexp (regex) = ^std::250 (lldb) settings set target.process.thread.step-avoid-regexp ^std::|^abc251 252You can ignore a function once using:253 254.. code-block:: shell255 256 (lldb) thread step-in -r ^abc257 258Or you can do the opposite, only step into functions matching a certain name:259 260.. code-block:: shell261 262 # Step in if abc is a substring of the function name.263 (lldb) sif abc264 # Which is equivalent to:265 (lldb) thread step-in -t abc266 267``thread step-in`` has more options which cover some of ``skip``'s other268features. See ``help thread step-in`` for details.269 270Do a source level single step over in the currently selected thread271~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~272 273.. code-block:: shell274 275 (gdb) next276 (gdb) n277 278.. code-block:: shell279 280 (lldb) thread step-over281 (lldb) next282 (lldb) n283 284Do an instruction level single step in the currently selected thread285~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~286 287.. code-block:: shell288 289 (gdb) stepi290 (gdb) si291 292.. code-block:: shell293 294 (lldb) thread step-inst295 (lldb) si296 297Do an instruction level single step over in the currently selected thread298~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~299 300.. code-block:: shell301 302 (gdb) nexti303 (gdb) ni304 305.. code-block:: shell306 307 (lldb) thread step-inst-over308 (lldb) ni309 310Step out of the currently selected frame311~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~312 313.. code-block:: shell314 315 (gdb) finish316 317.. code-block:: shell318 319 (lldb) thread step-out320 (lldb) finish321 322Return immediately from the currently selected frame, with an optional return value323~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~324 325.. code-block:: shell326 327 (gdb) return <RETURN EXPRESSION>328 329.. code-block:: shell330 331 (lldb) thread return <RETURN EXPRESSION>332 333Backtrace and disassemble every time you stop334~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~335 336.. code-block:: shell337 338 (lldb) target stop-hook add339 Enter your stop hook command(s). Type 'DONE' to end.340 > bt341 > disassemble --pc342 > DONE343 Stop hook #1 added.344 345Run until we hit line 12 or control leaves the current function346~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~347 348.. code-block:: shell349 350 (gdb) until 12351 352.. code-block:: shell353 354 (lldb) thread until 12355 356Show the current frame and source line357~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~358 359.. code-block:: shell360 361 (gdb) frame362 363.. code-block:: shell364 365 (lldb) frame select366 (lldb) f367 (lldb) process status368 369Breakpoint Commands370-------------------371 372Set a breakpoint at all functions named main373~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~374 375.. code-block:: shell376 377 (gdb) break main378 379.. code-block:: shell380 381 (lldb) breakpoint set --name main382 (lldb) br s -n main383 (lldb) b main384 385Set a breakpoint in file ``test.c`` at line ``12``386~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~387 388.. code-block:: shell389 390 (gdb) break test.c:12391 392.. code-block:: shell393 394 (lldb) breakpoint set --file test.c --line 12395 (lldb) br s -f test.c -l 12396 (lldb) b test.c:12397 398Set a breakpoint at all C++ methods whose basename is ``main``399~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~400 401.. code-block:: shell402 403 (gdb) break main404 (Hope that there are no C functions named main)405 406.. code-block:: shell407 408 (lldb) breakpoint set --method main409 (lldb) br s -M main410 411Set a breakpoint at an Objective-C function ``-[NSString stringWithFormat:]``412~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~413 414.. code-block:: shell415 416 (gdb) break -[NSString stringWithFormat:]417 418.. code-block:: shell419 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:: shell427 428 (gdb) break count429 (Hope that there are no C or C++ functions named count)430 431.. code-block:: shell432 433 (lldb) breakpoint set --selector count434 (lldb) br s -S count435 436Set a breakpoint by regular expression on function name437~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~438 439.. code-block:: shell440 441 (gdb) rbreak regular-expression442 443.. code-block:: shell444 445 (lldb) breakpoint set --func-regex regular-expression446 (lldb) br s -r regular-expression447 448Ensure that breakpoints by file and line work for ``#include .c/.cpp/.m`` files449~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~450 451.. code-block:: shell452 453 (gdb) b foo.c:12454 455.. code-block:: shell456 457 (lldb) settings set target.inline-breakpoint-strategy always458 (lldb) br s -f foo.c -l 12459 460Set a breakpoint by regular expression on source file contents461~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~462 463.. code-block:: shell464 465 (gdb) shell grep -e -n pattern source-file466 (gdb) break source-file:CopyLineNumbers467 468.. code-block:: shell469 470 (lldb) breakpoint set --source-pattern regular-expression --file SourceFile471 (lldb) br s -p regular-expression -f file472 473Set a conditional breakpoint474~~~~~~~~~~~~~~~~~~~~~~~~~~~~475 476.. code-block:: shell477 478 (gdb) break foo if strcmp(y,"hello") == 0479 480.. code-block:: shell481 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 breakpoints486~~~~~~~~~~~~~~~~~~~~487 488.. code-block:: shell489 490 (gdb) info break491 492.. code-block:: shell493 494 (lldb) breakpoint list495 (lldb) br l496 497Delete a breakpoint498~~~~~~~~~~~~~~~~~~~499 500.. code-block:: shell501 502 (gdb) delete 1503 504.. code-block:: shell505 506 (lldb) breakpoint delete 1507 (lldb) br del 1508 509Disable a breakpoint510~~~~~~~~~~~~~~~~~~~~511 512.. code-block:: shell513 514 (gdb) disable 1515 516.. code-block:: shell517 518 (lldb) breakpoint disable 1519 (lldb) br dis 1520 521Enable a breakpoint522~~~~~~~~~~~~~~~~~~~523 524.. code-block:: shell525 526 (gdb) enable 1527 528.. code-block:: shell529 530 (lldb) breakpoint enable 1531 (lldb) br en 1532 533 534Watchpoint Commands535-------------------536 537Set a watchpoint on a variable when it is written to538~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~539.. code-block:: shell540 541 (gdb) watch global_var542 543.. code-block:: shell544 545 (lldb) watchpoint set variable global_var546 (lldb) wa s v global_var547 548Set a watchpoint on a memory location when it is written into549~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~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:: shell554 555 (gdb) watch -location g_char_ptr556 557.. code-block:: shell558 559 (lldb) watchpoint set expression -- my_ptr560 (lldb) wa s e -- my_ptr561 562Set a condition on a watchpoint563~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~564 565.. code-block:: shell566 567 (lldb) watch set var global568 (lldb) watchpoint modify -c '(global==5)'569 (lldb) c570 ...571 (lldb) bt572 * thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1573 frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16574 frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25575 frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1576 (lldb) frame var global577 (int32_t) global = 5578 579List all watchpoints580~~~~~~~~~~~~~~~~~~~~581 582.. code-block:: shell583 584 (gdb) info break585 586.. code-block:: shell587 588 (lldb) watchpoint list589 (lldb) watch l590 591Delete a watchpoint592~~~~~~~~~~~~~~~~~~~593 594.. code-block:: shell595 596 (gdb) delete 1597 598.. code-block:: shell599 600 (lldb) watchpoint delete 1601 (lldb) watch del 1602 603 604Examining Variables605-------------------606 607Show the arguments and local variables for the current frame608~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~609 610.. code-block:: shell611 612 (gdb) info args613 (gdb) info locals614 615.. code-block:: shell616 617 (lldb) frame variable618 (lldb) fr v619 620Show the local variables for the current frame621~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~622 623.. code-block:: shell624 625 (gdb) info locals626 627.. code-block:: shell628 629 (lldb) frame variable --no-args630 (lldb) fr v -a631 632Show the contents of local variable ``bar``633~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~634 635.. code-block:: shell636 637 (gdb) p bar638 639.. code-block:: shell640 641 (lldb) frame variable bar642 (lldb) fr v bar643 (lldb) p bar644 645Show the contents of local variable ``bar`` formatted as hex646~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~647 648.. code-block:: shell649 650 (gdb) p/x bar651 652.. code-block:: shell653 654 (lldb) frame variable --format x bar655 (lldb) fr v -f x bar656 657Show the contents of global variable ``baz``658~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~659 660.. code-block:: shell661 662 (gdb) p baz663 664.. code-block:: shell665 666 (lldb) target variable baz667 (lldb) ta v baz668 669Show the global/static variables defined in the current source file670~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~671 672.. code-block:: shell673 674 (lldb) target variable675 (lldb) ta v676 677Display the variables ``argc`` and ``argv`` every time you stop678~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~679 680.. code-block:: shell681 682 (gdb) display argc683 (gdb) display argv684 685.. code-block:: shell686 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 argc690 (lldb) display argv691 692Display the variables ``argc`` and ``argv`` only when you stop in the function named ``main``693~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~694 695.. code-block:: shell696 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:: shell704 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:: shell712 713 (gdb) p *ptr@10714 715.. code-block:: shell716 717 (lldb) parray 10 ptr718 719Evaluating Expressions720----------------------721 722Evaluating a generalized expression in the current frame723~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~724 725.. code-block:: shell726 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:: shell732 733 (gdb) call (int) printf ("Print nine: %d.", 4 + 5)734 735.. code-block:: shell736 737 (lldb) expr (int) printf ("Print nine: %d.", 4 + 5)738 739or using the print alias:740 741.. code-block:: shell742 743 (lldb) print (int) printf ("Print nine: %d.", 4 + 5)744 745Creating and assigning a value to a convenience variable746~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~747 748.. code-block:: shell749 750 (gdb) set $foo = 5751 (gdb) set variable $foo = 5752 753or using the print command754 755.. code-block:: shell756 757 (gdb) print $foo = 5758 759or using the call command760 761.. code-block:: shell762 763 (gdb) call $foo = 5764 765and if you want to specify the type of the variable:766 767.. code-block:: shell768 769 (gdb) set $foo = (unsigned int) 5770 771In lldb you evaluate a variable declaration expression as you would write it in C:772 773.. code-block:: shell774 775 (lldb) expr unsigned int $foo = 5776 777Printing the ObjC "description" of an object778~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~779 780.. code-block:: shell781 782 (gdb) po [SomeClass returnAnObject]783 784.. code-block:: shell785 786 (lldb) expr -o -- [SomeClass returnAnObject]787 788or using the po alias:789 790.. code-block:: shell791 792 (lldb) po [SomeClass returnAnObject]793 794Print the dynamic type of the result of an expression795~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~796 797.. code-block:: shell798 799 (gdb) set print object 1800 (gdb) p someCPPObjectPtrOrReference801 (Only works for C++ objects)802 803LLDB does this automatically if determining the dynamic type does not require804running the target (in C++, running the target is never needed). This default is805controlled by the `target.prefer-dynamic-value` setting. If that is disabled, it806can be re-enabled on a per-command basis:807 808.. code-block:: shell809 810 (lldb) settings set target.prefer-dynamic-value no-dynamic-values811 (lldb) frame variable -d no-run-target someCPPObjectPtrOrReference812 (lldb) expr -d no-run-target -- someCPPObjectPtr813 814Note that printing of the dynamic type of references is not possible with the815`expr` command. The workaround is to take the address of the reference and816instruct lldb to print the children of the resulting pointer.817 818.. code-block:: shell819 820 (lldb) expr -P1 -d no-run-target -- &someCPPObjectReference821 822Call a function so you can stop at a breakpoint in it823~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~824 825.. code-block:: shell826 827 (gdb) set unwindonsignal 0828 (gdb) p function_with_a_breakpoint()829 830.. code-block:: shell831 832 (lldb) expr -i 0 -- function_with_a_breakpoint()833 834Call a function that crashes, then stop when it does835~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~836 837.. code-block:: shell838 839 (gdb) set unwindonsignal 0840 (gdb) p function_which_crashes()841 842.. code-block:: shell843 844 (lldb) expr -u 0 -- function_which_crashes()845 846Examining Thread State847----------------------848 849List the threads in your program850~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~851 852.. code-block:: shell853 854 (gdb) info threads855 856.. code-block:: shell857 858 (lldb) thread list859 860Select thread ``1`` as the default thread for subsequent commands861~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~862 863.. code-block:: shell864 865 (gdb) thread 1866 867.. code-block:: shell868 869 (lldb) thread select 1870 (lldb) t 1871 872Show the stack backtrace for the current thread873~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~874 875.. code-block:: shell876 877 (gdb) bt878 879.. code-block:: shell880 881 (lldb) thread backtrace882 (lldb) bt883 884Show the stack backtraces for all threads885~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~886 887.. code-block:: shell888 889 (gdb) thread apply all bt890 891.. code-block:: shell892 893 (lldb) thread backtrace all894 (lldb) bt all895 896Backtrace the first five frames of the current thread897~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~898 899.. code-block:: shell900 901 (gdb) bt 5902 903.. code-block:: shell904 905 (lldb) thread backtrace -c 5906 (lldb) bt 5907 908Select a different stack frame by index for the current thread909~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~910 911.. code-block:: shell912 913 (gdb) frame 12914 915.. code-block:: shell916 917 (lldb) frame select 12918 (lldb) fr s 12919 (lldb) f 12920 921List information about the currently selected frame in the current thread922~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~923 924.. code-block:: shell925 926 (lldb) frame info927 928Select the stack frame that called the current stack frame929~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~930 931.. code-block:: shell932 933 (gdb) up934 935.. code-block:: shell936 937 (lldb) up938 (lldb) frame select --relative=1939 940Select the stack frame that is called by the current stack frame941~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~942 943.. code-block:: shell944 945 (gdb) down946 947.. code-block:: shell948 949 (lldb) down950 (lldb) frame select --relative=-1951 (lldb) fr s -r-1952 953Select a different stack frame using a relative offset954~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~955 956.. code-block:: shell957 958 (gdb) up 2959 (gdb) down 3960 961.. code-block:: shell962 963 (lldb) frame select --relative 2964 (lldb) fr s -r2965 966 (lldb) frame select --relative -3967 (lldb) fr s -r-3968 969show the general purpose registers for the current thread970~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~971 972.. code-block:: shell973 974 (gdb) info registers975 976.. code-block:: shell977 978 (lldb) register read979 980Write a new decimal value ``123`` to the current thread register ``rax``981~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~982 983.. code-block:: shell984 985 (gdb) p $rax = 123986 987.. code-block:: shell988 989 (lldb) register write rax 123990 991Skip 8 bytes ahead of the current program counter (instruction pointer)992~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~993 994Note that we use backticks to evaluate an expression and insert the scalar result in LLDB.995 996 997.. code-block:: shell998 999 (gdb) jump *$pc+81000 1001.. code-block:: shell1002 1003 (lldb) register write pc `$pc+8`1004 1005Show the general purpose registers for the current thread formatted as signed decimal1006~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1007 1008LLDB tries to use the same format characters as printf(3) when possible. Type "help format" to see the full list of format specifiers.1009 1010.. code-block:: shell1011 1012 (lldb) register read --format i1013 (lldb) re r -f i1014 1015LLDB now supports the GDB shorthand format syntax but there can't be space after the command:1016 1017.. code-block:: shell1018 1019 (lldb) register read/d1020 1021Show all registers in all register sets for the current thread1022~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1023 1024.. code-block:: shell1025 1026 (gdb) info all-registers1027 1028.. code-block:: shell1029 1030 (lldb) register read --all1031 (lldb) re r -a1032 1033Show the values for the registers named ``rax``, ``rsp`` and ``rbp`` in the current thread1034~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1035 1036.. code-block:: shell1037 1038 (gdb) info all-registers rax rsp rbp1039 1040.. code-block:: shell1041 1042 (lldb) register read rax rsp rbp1043 1044Show the values for the register named ``rax`` in the current thread formatted as binary1045~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1046 1047.. code-block:: shell1048 1049 (gdb) p/t $rax1050 1051.. code-block:: shell1052 1053 (lldb) register read --format binary rax1054 (lldb) re r -f b rax1055 1056LLDB now supports the GDB shorthand format syntax but there can't be space after the command1057 1058.. code-block:: shell1059 1060 (lldb) register read/t rax1061 (lldb) p/t $rax1062 1063Read memory from address ``0xbffff3c0`` and show 4 hex ``uint32_t`` values1064~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1065 1066.. code-block:: shell1067 1068 (gdb) x/4xw 0xbffff3c01069 1070.. code-block:: shell1071 1072 (lldb) memory read --size 4 --format x --count 4 0xbffff3c01073 (lldb) me r -s4 -fx -c4 0xbffff3c01074 (lldb) x -s4 -fx -c4 0xbffff3c01075 1076LLDB now supports the GDB shorthand format syntax but there can't be space after the command:1077 1078.. code-block:: shell1079 1080 (lldb) memory read/4xw 0xbffff3c01081 (lldb) x/4xw 0xbffff3c01082 (lldb) memory read --gdb-format 4xw 0xbffff3c01083 1084Read memory starting at the expression ``argv[0]``1085~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1086 1087.. code-block:: shell1088 1089 (gdb) x argv[0]1090 1091.. code-block:: shell1092 1093 (lldb) memory read `argv[0]`1094 1095NOTE: any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression:1096 1097.. code-block:: shell1098 1099 (lldb) memory read --size `sizeof(int)` `argv[0]`1100 1101Read ``512`` bytes of memory from address ``0xbffff3c0`` and save the results to a local file as text1102~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1103 1104.. code-block:: shell1105 1106 (gdb) set logging on1107 (gdb) set logging file /tmp/mem.txt1108 (gdb) x/512bx 0xbffff3c01109 (gdb) set logging off1110 1111.. code-block:: shell1112 1113 (lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c01114 (lldb) me r -o/tmp/mem.txt -c512 0xbffff3c01115 (lldb) x/512bx -o/tmp/mem.txt 0xbffff3c01116 1117Save binary memory data starting at ``0x1000`` and ending at ``0x2000`` to a file1118~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1119 1120.. code-block:: shell1121 1122 (gdb) dump memory /tmp/mem.bin 0x1000 0x20001123 1124.. code-block:: shell1125 1126 (lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x20001127 (lldb) me r -o /tmp/mem.bin -b 0x1000 0x20001128 1129 1130Print information about memory regions1131~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1132 1133.. code-block:: shell1134 1135 (gdb) info proc mappings1136 1137.. code-block:: shell1138 1139 (lldb) memory region --all1140 (lldb) me reg --all1141 1142 1143Get information about a specific heap allocation (macOS only)1144~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1145 1146.. code-block:: shell1147 1148 (gdb) info malloc 0x10010d6801149 1150.. code-block:: shell1151 1152 (lldb) command script import lldb.macosx.heap1153 (lldb) process launch --environment MallocStackLogging=1 -- [ARGS]1154 (lldb) malloc_info --stack-history 0x10010d6801155 1156Get information about a specific heap allocation and cast the result to any dynamic type that can be deduced (macOS only)1157~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1158 1159.. code-block:: shell1160 1161 (lldb) command script import lldb.macosx.heap1162 (lldb) malloc_info --type 0x10010d6801163 1164Find all heap blocks that contain a pointer specified by an expression ``EXPR`` (macOS only)1165~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1166 1167.. code-block:: shell1168 1169 (lldb) command script import lldb.macosx.heap1170 (lldb) ptr_refs EXPR1171 1172Find all heap blocks that contain a C string anywhere in the block (macOS only)1173~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1174 1175.. code-block:: shell1176 1177 (lldb) command script import lldb.macosx.heap1178 (lldb) cstr_refs CSTRING1179 1180Disassemble the current function for the current frame1181~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1182 1183.. code-block:: shell1184 1185 (gdb) disassemble1186 1187.. code-block:: shell1188 1189 (lldb) disassemble --frame1190 (lldb) di -f1191 1192Disassemble any functions named main1193~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1194 1195.. code-block:: shell1196 1197 (gdb) disassemble main1198 1199 1200.. code-block:: shell1201 1202 (lldb) disassemble --name main1203 (lldb) di -n main1204 1205Disassemble an address range1206~~~~~~~~~~~~~~~~~~~~~~~~~~~~1207 1208.. code-block:: shell1209 1210 (gdb) disassemble 0x1eb8 0x1ec31211 1212.. code-block:: shell1213 1214 (lldb) disassemble --start-address 0x1eb8 --end-address 0x1ec31215 (lldb) di -s 0x1eb8 -e 0x1ec31216 1217Disassemble ``20`` instructions from a given address1218~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1219 1220.. code-block:: shell1221 1222 (gdb) x/20i 0x1eb81223 1224.. code-block:: shell1225 1226 (lldb) disassemble --start-address 0x1eb8 --count 201227 (lldb) di -s 0x1eb8 -c 201228 1229Show mixed source and disassembly for the current function for the current frame1230~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1231 1232.. code-block:: shell1233 1234 (lldb) disassemble --frame --mixed1235 (lldb) di -f -m1236 1237Disassemble the current function for the current frame and show the opcode bytes1238~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1239 1240.. code-block:: shell1241 1242 (lldb) disassemble --frame --bytes1243 (lldb) di -f -b1244 1245Disassemble the current source line for the current frame1246~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1247 1248.. code-block:: shell1249 1250 (lldb) disassemble --line1251 (lldb) di -l1252 1253Executable and Shared Library Query Commands1254--------------------------------------------1255 1256List the main executable and all dependent shared libraries1257~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1258 1259.. code-block:: shell1260 1261 (gdb) info shared1262 1263.. code-block:: shell1264 1265 (lldb) image list1266 1267Look up information for a raw address in the executable or any shared libraries1268~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1269 1270.. code-block:: shell1271 1272 (gdb) info symbol 0x1ec41273 1274.. code-block:: shell1275 1276 (lldb) image lookup --address 0x1ec41277 (lldb) im loo -a 0x1ec41278 1279Look up functions matching a regular expression in a binary1280~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1281 1282.. code-block:: shell1283 1284 (gdb) info function <FUNC_REGEX>1285 1286This one finds debug symbols:1287 1288.. code-block:: shell1289 1290 (lldb) image lookup -r -n <FUNC_REGEX>1291 1292This one finds non-debug symbols:1293 1294.. code-block:: shell1295 1296 (lldb) image lookup -r -s <FUNC_REGEX>1297 1298Provide a list of binaries as arguments to limit the search.1299 1300Find full source line information1301~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1302 1303.. code-block:: shell1304 1305 (gdb) info line 0x1ec41306 1307This one is a bit messy at present. Do:1308 1309.. code-block:: shell1310 1311 (lldb) image lookup -v --address 0x1ec41312 1313and look for the LineEntry line, which will have the full source path and line range information.1314 1315Look up information for an address in ``a.out`` only1316~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1317 1318.. code-block:: shell1319 1320 (lldb) image lookup --address 0x1ec4 a.out1321 (lldb) im loo -a 0x1ec4 a.out1322 1323Look up information for for a type ``Point`` by name1324~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1325 1326.. code-block:: shell1327 1328 (gdb) ptype Point1329 1330.. code-block:: shell1331 1332 (lldb) image lookup --type Point1333 (lldb) im loo -t Point1334 1335Dump all sections from the main executable and any shared libraries1336~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1337 1338.. code-block:: shell1339 1340 (gdb) maintenance info sections1341 1342.. code-block:: shell1343 1344 (lldb) image dump sections1345 1346Dump all sections in the ``a.out`` module1347~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1348 1349.. code-block:: shell1350 1351 (lldb) image dump sections a.out1352 1353Dump all symbols from the main executable and any shared libraries1354~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1355 1356.. code-block:: shell1357 1358 (lldb) image dump symtab1359 1360Dump all symbols in ``a.out`` and ``liba.so``1361~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1362 1363.. code-block:: shell1364 1365 (lldb) image dump symtab a.out liba.so1366 1367Save current process as a core file1368~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1369 1370.. code-block:: shell1371 1372 (gdb) gcore filename1373 1374.. code-block:: shell1375 1376 (lldb) process save-core filename1377 1378Miscellaneous1379-------------1380 1381Search command help for a keyword1382~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1383 1384.. code-block:: shell1385 1386 (gdb) apropos keyword1387 1388.. code-block:: shell1389 1390 (lldb) apropos keyword1391 1392Echo text to the screen1393~~~~~~~~~~~~~~~~~~~~~~~1394 1395.. code-block:: shell1396 1397 (gdb) echo Here is some text\n1398 1399.. code-block:: shell1400 1401 (lldb) script print "Here is some text"1402 1403Remap source file pathnames for the debug session1404~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1405 1406If your source files are no longer located in the same location as when the1407program was built (for example, if the program was built on a different1408computer) you need to tell the debugger how to find the sources at their local1409file path instead of the build system's file path.1410 1411.. code-block:: shell1412 1413 (gdb) set pathname-substitutions /buildbot/path /my/path1414 1415.. code-block:: shell1416 1417 (lldb) settings set target.source-map /buildbot/path /my/path1418 1419Supply a catchall directory to search for source files in.1420 1421.. code-block:: shell1422 1423 (gdb) directory /my/path1424