1 GDB to LLDB command map
2 =======================
4 Below is a table of GDB commands with their LLDB counterparts. The built in
5 GDB-compatibility aliases in LLDB are also listed. The full lldb command names
6 are often long, but any unique short form can be used. Instead of "**breakpoint
7 set**", "**br se**" is also acceptable.
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`_
21 Launch a process no arguments
22 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 Launch a process with arguments ``<args>``
36 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46 (lldb) process launch -- <args>
50 Launch process ``a.out`` with arguments ``1 2 3`` by passing the args to the debugger
51 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55 % gdb --args a.out 1 2 3
70 Launch process a.out with arguments ``1 2 3`` by setting the args in the debugger
71 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83 (lldb) settings set target.run-args 1 2 3
89 Launch a process with arguments in new terminal window (macOS only)
90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94 (lldb) process launch --tty -- <args>
95 (lldb) pro la -t -- <args>
97 Launch a process with arguments ``<args>`` in existing terminal ``/dev/ttys006``
98 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100 .. code-block:: shell
102 (lldb) process launch --tty=/dev/ttys006 -- <args>
103 (lldb) pro la -t/dev/ttys006 -- <args>
106 Set environment variables for process before launching
107 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109 .. code-block:: shell
111 (gdb) set env DEBUG 1
113 .. code-block:: shell
115 (lldb) settings set target.env-vars DEBUG=1
116 (lldb) set se target.env-vars DEBUG=1
120 Unset environment variables for process before launching
121 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123 .. code-block:: shell
125 (gdb) unset env DEBUG
127 .. code-block:: shell
129 (lldb) settings remove target.env-vars DEBUG
130 (lldb) set rem target.env-vars DEBUG
132 Show the arguments that will be or were passed to the program when run
133 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135 .. code-block:: shell
138 Argument list to give program being debugged when it is started is "1 2 3".
140 .. code-block:: shell
142 (lldb) settings show target.run-args
143 target.run-args (array of strings) =
148 Set environment variables for process and launch process in one command
149 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151 .. code-block:: shell
153 (lldb) process launch -E DEBUG=1
155 Attach to the process with process ID 123
156 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158 .. code-block:: shell
162 .. code-block:: shell
164 (lldb) process attach --pid 123
167 Attach to the process named ``a.out``
168 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
170 .. code-block:: shell
174 .. code-block:: shell
176 (lldb) process attach --name a.out
177 (lldb) pro at -n a.out
179 Wait for a process named ``a.out`` to launch and attach
180 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182 .. code-block:: shell
184 (gdb) attach -waitfor a.out
186 .. code-block:: shell
188 (lldb) process attach --name a.out --waitfor
189 (lldb) pro at -n a.out -w
191 Attach to a remote gdb protocol server running on system ``eorgadd``, port ``8000``
192 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194 .. code-block:: shell
196 (gdb) target remote eorgadd:8000
198 .. code-block:: shell
200 (lldb) gdb-remote eorgadd:8000
202 Attach to a remote gdb protocol server running on the local system, port ``8000``
203 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205 .. code-block:: shell
207 (gdb) target remote localhost:8000
209 .. code-block:: shell
211 (lldb) gdb-remote 8000
213 Attach to a Darwin kernel in kdp mode on system ``eorgadd``
214 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
216 .. code-block:: shell
218 (gdb) kdp-reattach eorgadd
220 .. code-block:: shell
222 (lldb) kdp-remote eorgadd
224 Do a source level single step in the currently selected thread
225 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
227 .. code-block:: shell
232 .. code-block:: shell
234 (lldb) thread step-in
238 Do a source level single step over in the currently selected thread
239 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
241 .. code-block:: shell
246 .. code-block:: shell
248 (lldb) thread step-over
252 Do an instruction level single step in the currently selected thread
253 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
255 .. code-block:: shell
260 .. code-block:: shell
262 (lldb) thread step-inst
265 Do an instruction level single step over in the currently selected thread
266 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
268 .. code-block:: shell
273 .. code-block:: shell
275 (lldb) thread step-inst-over
278 Step out of the currently selected frame
279 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281 .. code-block:: shell
285 .. code-block:: shell
287 (lldb) thread step-out
290 Return immediately from the currently selected frame, with an optional return value
291 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
293 .. code-block:: shell
295 (gdb) return <RETURN EXPRESSION>
297 .. code-block:: shell
299 (lldb) thread return <RETURN EXPRESSION>
301 Backtrace and disassemble every time you stop
302 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
304 .. code-block:: shell
306 (lldb) target stop-hook add
307 Enter your stop hook command(s). Type 'DONE' to end.
313 Run until we hit line 12 or control leaves the current function
314 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
316 .. code-block:: shell
320 .. code-block:: shell
322 (lldb) thread until 12
324 Show the current frame and source line
325 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
327 .. code-block:: shell
331 .. code-block:: shell
335 (lldb) process status
340 Set a breakpoint at all functions named main
341 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
343 .. code-block:: shell
347 .. code-block:: shell
349 (lldb) breakpoint set --name main
353 Set a breakpoint in file ``test.c`` at line ``12``
354 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
356 .. code-block:: shell
358 (gdb) break test.c:12
360 .. code-block:: shell
362 (lldb) breakpoint set --file test.c --line 12
363 (lldb) br s -f test.c -l 12
366 Set a breakpoint at all C++ methods whose basename is ``main``
367 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
369 .. code-block:: shell
372 (Hope that there are no C functions named main)
374 .. code-block:: shell
376 (lldb) breakpoint set --method main
379 Set a breakpoint at an Objective-C function ``-[NSString stringWithFormat:]``
380 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
382 .. code-block:: shell
384 (gdb) break -[NSString stringWithFormat:]
386 .. code-block:: shell
388 (lldb) breakpoint set --name "-[NSString stringWithFormat:]"
389 (lldb) b -[NSString stringWithFormat:]
391 Set a breakpoint at all Objective-C methods whose selector is ``count``
392 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394 .. code-block:: shell
397 (Hope that there are no C or C++ functions named count)
399 .. code-block:: shell
401 (lldb) breakpoint set --selector count
404 Set a breakpoint by regular expression on function name
405 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
407 .. code-block:: shell
409 (gdb) rbreak regular-expression
411 .. code-block:: shell
413 (lldb) breakpoint set --func-regex regular-expression
414 (lldb) br s -r regular-expression
416 Ensure that breakpoints by file and line work for ``#include .c/.cpp/.m`` files
417 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
419 .. code-block:: shell
423 .. code-block:: shell
425 (lldb) settings set target.inline-breakpoint-strategy always
426 (lldb) br s -f foo.c -l 12
428 Set a breakpoint by regular expression on source file contents
429 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
431 .. code-block:: shell
433 (gdb) shell grep -e -n pattern source-file
434 (gdb) break source-file:CopyLineNumbers
436 .. code-block:: shell
438 (lldb) breakpoint set --source-pattern regular-expression --file SourceFile
439 (lldb) br s -p regular-expression -f file
441 Set a conditional breakpoint
442 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
444 .. code-block:: shell
446 (gdb) break foo if strcmp(y,"hello") == 0
448 .. code-block:: shell
450 (lldb) breakpoint set --name foo --condition '(int)strcmp(y,"hello") == 0'
451 (lldb) br s -n foo -c '(int)strcmp(y,"hello") == 0'
456 .. code-block:: shell
460 .. code-block:: shell
462 (lldb) breakpoint list
468 .. code-block:: shell
472 .. code-block:: shell
474 (lldb) breakpoint delete 1
480 .. code-block:: shell
484 .. code-block:: shell
486 (lldb) breakpoint disable 1
492 .. code-block:: shell
496 .. code-block:: shell
498 (lldb) breakpoint enable 1
505 Set a watchpoint on a variable when it is written to
506 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
507 .. code-block:: shell
509 (gdb) watch global_var
511 .. code-block:: shell
513 (lldb) watchpoint set variable global_var
514 (lldb) wa s v global_var
516 Set a watchpoint on a memory location when it is written into
517 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
519 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.
521 .. code-block:: shell
523 (gdb) watch -location g_char_ptr
525 .. code-block:: shell
527 (lldb) watchpoint set expression -- my_ptr
528 (lldb) wa s e -- my_ptr
530 Set a condition on a watchpoint
531 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
533 .. code-block:: shell
535 (lldb) watch set var global
536 (lldb) watchpoint modify -c '(global==5)'
540 * thread #1: tid = 0x1c03, 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16, stop reason = watchpoint 1
541 frame #0: 0x0000000100000ef5 a.out`modify + 21 at main.cpp:16
542 frame #1: 0x0000000100000eac a.out`main + 108 at main.cpp:25
543 frame #2: 0x00007fff8ac9c7e1 libdyld.dylib`start + 1
544 (lldb) frame var global
550 .. code-block:: shell
554 .. code-block:: shell
556 (lldb) watchpoint list
562 .. code-block:: shell
566 .. code-block:: shell
568 (lldb) watchpoint delete 1
575 Show the arguments and local variables for the current frame
576 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
578 .. code-block:: shell
583 .. code-block:: shell
585 (lldb) frame variable
588 Show the local variables for the current frame
589 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
591 .. code-block:: shell
595 .. code-block:: shell
597 (lldb) frame variable --no-args
600 Show the contents of local variable ``bar``
601 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
603 .. code-block:: shell
607 .. code-block:: shell
609 (lldb) frame variable bar
613 Show the contents of local variable ``bar`` formatted as hex
614 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
616 .. code-block:: shell
620 .. code-block:: shell
622 (lldb) frame variable --format x bar
625 Show the contents of global variable ``baz``
626 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
628 .. code-block:: shell
632 .. code-block:: shell
634 (lldb) target variable baz
637 Show the global/static variables defined in the current source file
638 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
640 .. code-block:: shell
642 (lldb) target variable
645 Display the variables ``argc`` and ``argv`` every time you stop
646 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
648 .. code-block:: shell
653 .. code-block:: shell
655 (lldb) target stop-hook add --one-liner "frame variable argc argv"
656 (lldb) ta st a -o "fr v argc argv"
660 Display the variables ``argc`` and ``argv`` only when you stop in the function named ``main``
661 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
663 .. code-block:: shell
665 (lldb) target stop-hook add --name main --one-liner "frame variable argc argv"
666 (lldb) ta st a -n main -o "fr v argc argv"
668 Display the variable ``*this`` only when you stop in c class named ``MyClass``
669 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
671 .. code-block:: shell
673 (lldb) target stop-hook add --classname MyClass --one-liner "frame variable *this"
674 (lldb) ta st a -c MyClass -o "fr v *this"
676 Print an array of integers in memory, assuming we have a pointer like ``int *ptr``
677 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
679 .. code-block:: shell
683 .. code-block:: shell
687 Evaluating Expressions
688 ----------------------
690 Evaluating a generalized expression in the current frame
691 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
693 .. code-block:: shell
695 (gdb) print (int) printf ("Print nine: %d.", 4 + 5)
697 or if you don't want to see void returns:
699 .. code-block:: shell
701 (gdb) call (int) printf ("Print nine: %d.", 4 + 5)
703 .. code-block:: shell
705 (lldb) expr (int) printf ("Print nine: %d.", 4 + 5)
707 or using the print alias:
709 .. code-block:: shell
711 (lldb) print (int) printf ("Print nine: %d.", 4 + 5)
713 Creating and assigning a value to a convenience variable
714 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
716 .. code-block:: shell
719 (gdb) set variable $foo = 5
721 or using the print command
723 .. code-block:: shell
727 or using the call command
729 .. code-block:: shell
733 and if you want to specify the type of the variable:
735 .. code-block:: shell
737 (gdb) set $foo = (unsigned int) 5
739 In lldb you evaluate a variable declaration expression as you would write it in C:
741 .. code-block:: shell
743 (lldb) expr unsigned int $foo = 5
745 Printing the ObjC "description" of an object
746 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
748 .. code-block:: shell
750 (gdb) po [SomeClass returnAnObject]
752 .. code-block:: shell
754 (lldb) expr -o -- [SomeClass returnAnObject]
756 or using the po alias:
758 .. code-block:: shell
760 (lldb) po [SomeClass returnAnObject]
762 Print the dynamic type of the result of an expression
763 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
765 .. code-block:: shell
767 (gdb) set print object 1
768 (gdb) p someCPPObjectPtrOrReference
769 (Only works for C++ objects)
771 .. code-block:: shell
773 (lldb) expr -d 1 -- [SomeClass returnAnObject]
774 (lldb) expr -d 1 -- someCPPObjectPtrOrReference
776 or set dynamic type printing to be the default:
778 .. code-block:: shell
780 (lldb) settings set target.prefer-dynamic run-target
782 Call a function so you can stop at a breakpoint in it
783 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
785 .. code-block:: shell
787 (gdb) set unwindonsignal 0
788 (gdb) p function_with_a_breakpoint()
790 .. code-block:: shell
792 (lldb) expr -i 0 -- function_with_a_breakpoint()
794 Call a function that crashes, then stop when it does
795 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
797 .. code-block:: shell
799 (gdb) set unwindonsignal 0
800 (gdb) p function_which_crashes()
802 .. code-block:: shell
804 (lldb) expr -u 0 -- function_which_crashes()
806 Examining Thread State
807 ----------------------
809 List the threads in your program
810 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
812 .. code-block:: shell
816 .. code-block:: shell
820 Select thread ``1`` as the default thread for subsequent commands
821 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
823 .. code-block:: shell
827 .. code-block:: shell
829 (lldb) thread select 1
832 Show the stack backtrace for the current thread
833 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
835 .. code-block:: shell
839 .. code-block:: shell
841 (lldb) thread backtrace
844 Show the stack backtraces for all threads
845 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
847 .. code-block:: shell
849 (gdb) thread apply all bt
851 .. code-block:: shell
853 (lldb) thread backtrace all
856 Backtrace the first five frames of the current thread
857 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
859 .. code-block:: shell
863 .. code-block:: shell
865 (lldb) thread backtrace -c 5
868 Select a different stack frame by index for the current thread
869 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
871 .. code-block:: shell
875 .. code-block:: shell
877 (lldb) frame select 12
881 List information about the currently selected frame in the current thread
882 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
884 .. code-block:: shell
888 Select the stack frame that called the current stack frame
889 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
891 .. code-block:: shell
895 .. code-block:: shell
898 (lldb) frame select --relative=1
900 Select the stack frame that is called by the current stack frame
901 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
903 .. code-block:: shell
907 .. code-block:: shell
910 (lldb) frame select --relative=-1
913 Select a different stack frame using a relative offset
914 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
916 .. code-block:: shell
921 .. code-block:: shell
923 (lldb) frame select --relative 2
926 (lldb) frame select --relative -3
929 show the general purpose registers for the current thread
930 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
932 .. code-block:: shell
936 .. code-block:: shell
940 Write a new decimal value ``123`` to the current thread register ``rax``
941 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
943 .. code-block:: shell
947 .. code-block:: shell
949 (lldb) register write rax 123
951 Skip 8 bytes ahead of the current program counter (instruction pointer)
952 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
954 Note that we use backticks to evaluate an expression and insert the scalar result in LLDB.
957 .. code-block:: shell
961 .. code-block:: shell
963 (lldb) register write pc `$pc+8`
965 Show the general purpose registers for the current thread formatted as signed decimal
966 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
968 LLDB tries to use the same format characters as printf(3) when possible. Type "help format" to see the full list of format specifiers.
970 .. code-block:: shell
972 (lldb) register read --format i
975 LLDB now supports the GDB shorthand format syntax but there can't be space after the command:
977 .. code-block:: shell
979 (lldb) register read/d
981 Show all registers in all register sets for the current thread
982 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
984 .. code-block:: shell
986 (gdb) info all-registers
988 .. code-block:: shell
990 (lldb) register read --all
993 Show the values for the registers named ``rax``, ``rsp`` and ``rbp`` in the current thread
994 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
996 .. code-block:: shell
998 (gdb) info all-registers rax rsp rbp
1000 .. code-block:: shell
1002 (lldb) register read rax rsp rbp
1004 Show the values for the register named ``rax`` in the current thread formatted as binary
1005 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1007 .. code-block:: shell
1011 .. code-block:: shell
1013 (lldb) register read --format binary rax
1014 (lldb) re r -f b rax
1016 LLDB now supports the GDB shorthand format syntax but there can't be space after the command
1018 .. code-block:: shell
1020 (lldb) register read/t rax
1023 Read memory from address ``0xbffff3c0`` and show 4 hex ``uint32_t`` values
1024 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1026 .. code-block:: shell
1028 (gdb) x/4xw 0xbffff3c0
1030 .. code-block:: shell
1032 (lldb) memory read --size 4 --format x --count 4 0xbffff3c0
1033 (lldb) me r -s4 -fx -c4 0xbffff3c0
1034 (lldb) x -s4 -fx -c4 0xbffff3c0
1036 LLDB now supports the GDB shorthand format syntax but there can't be space after the command:
1038 .. code-block:: shell
1040 (lldb) memory read/4xw 0xbffff3c0
1041 (lldb) x/4xw 0xbffff3c0
1042 (lldb) memory read --gdb-format 4xw 0xbffff3c0
1044 Read memory starting at the expression ``argv[0]``
1045 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1047 .. code-block:: shell
1051 .. code-block:: shell
1053 (lldb) memory read `argv[0]`
1055 NOTE: any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression:
1057 .. code-block:: shell
1059 (lldb) memory read --size `sizeof(int)` `argv[0]`
1061 Read ``512`` bytes of memory from address ``0xbffff3c0`` and save the results to a local file as text
1062 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1064 .. code-block:: shell
1066 (gdb) set logging on
1067 (gdb) set logging file /tmp/mem.txt
1068 (gdb) x/512bx 0xbffff3c0
1069 (gdb) set logging off
1071 .. code-block:: shell
1073 (lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0
1074 (lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0
1075 (lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0
1077 Save binary memory data starting at ``0x1000`` and ending at ``0x2000`` to a file
1078 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1080 .. code-block:: shell
1082 (gdb) dump memory /tmp/mem.bin 0x1000 0x2000
1084 .. code-block:: shell
1086 (lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x2000
1087 (lldb) me r -o /tmp/mem.bin -b 0x1000 0x2000
1089 Get information about a specific heap allocation (macOS only)
1090 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1092 .. code-block:: shell
1094 (gdb) info malloc 0x10010d680
1096 .. code-block:: shell
1098 (lldb) command script import lldb.macosx.heap
1099 (lldb) process launch --environment MallocStackLogging=1 -- [ARGS]
1100 (lldb) malloc_info --stack-history 0x10010d680
1102 Get information about a specific heap allocation and cast the result to any dynamic type that can be deduced (macOS only)
1103 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1105 .. code-block:: shell
1107 (lldb) command script import lldb.macosx.heap
1108 (lldb) malloc_info --type 0x10010d680
1110 Find all heap blocks that contain a pointer specified by an expression ``EXPR`` (macOS only)
1111 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1113 .. code-block:: shell
1115 (lldb) command script import lldb.macosx.heap
1116 (lldb) ptr_refs EXPR
1118 Find all heap blocks that contain a C string anywhere in the block (macOS only)
1119 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1121 .. code-block:: shell
1123 (lldb) command script import lldb.macosx.heap
1124 (lldb) cstr_refs CSTRING
1126 Disassemble the current function for the current frame
1127 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1129 .. code-block:: shell
1133 .. code-block:: shell
1135 (lldb) disassemble --frame
1138 Disassemble any functions named main
1139 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1141 .. code-block:: shell
1143 (gdb) disassemble main
1146 .. code-block:: shell
1148 (lldb) disassemble --name main
1151 Disassemble an address range
1152 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1154 .. code-block:: shell
1156 (gdb) disassemble 0x1eb8 0x1ec3
1158 .. code-block:: shell
1160 (lldb) disassemble --start-address 0x1eb8 --end-address 0x1ec3
1161 (lldb) di -s 0x1eb8 -e 0x1ec3
1163 Disassemble ``20`` instructions from a given address
1164 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1166 .. code-block:: shell
1170 .. code-block:: shell
1172 (lldb) disassemble --start-address 0x1eb8 --count 20
1173 (lldb) di -s 0x1eb8 -c 20
1175 Show mixed source and disassembly for the current function for the current frame
1176 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1178 .. code-block:: shell
1180 (lldb) disassemble --frame --mixed
1183 Disassemble the current function for the current frame and show the opcode bytes
1184 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1186 .. code-block:: shell
1188 (lldb) disassemble --frame --bytes
1191 Disassemble the current source line for the current frame
1192 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1194 .. code-block:: shell
1196 (lldb) disassemble --line
1199 Executable and Shared Library Query Commands
1200 --------------------------------------------
1202 List the main executable and all dependent shared libraries
1203 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1205 .. code-block:: shell
1209 .. code-block:: shell
1213 Look up information for a raw address in the executable or any shared libraries
1214 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1216 .. code-block:: shell
1218 (gdb) info symbol 0x1ec4
1220 .. code-block:: shell
1222 (lldb) image lookup --address 0x1ec4
1223 (lldb) im loo -a 0x1ec4
1225 Look up functions matching a regular expression in a binary
1226 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1228 .. code-block:: shell
1230 (gdb) info function <FUNC_REGEX>
1232 This one finds debug symbols:
1234 .. code-block:: shell
1236 (lldb) image lookup -r -n <FUNC_REGEX>
1238 This one finds non-debug symbols:
1240 .. code-block:: shell
1242 (lldb) image lookup -r -s <FUNC_REGEX>
1244 Provide a list of binaries as arguments to limit the search.
1246 Find full source line information
1247 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1249 .. code-block:: shell
1251 (gdb) info line 0x1ec4
1253 This one is a bit messy at present. Do:
1255 .. code-block:: shell
1257 (lldb) image lookup -v --address 0x1ec4
1259 and look for the LineEntry line, which will have the full source path and line range information.
1261 Look up information for an address in ``a.out`` only
1262 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1264 .. code-block:: shell
1266 (lldb) image lookup --address 0x1ec4 a.out
1267 (lldb) im loo -a 0x1ec4 a.out
1269 Look up information for for a type ``Point`` by name
1270 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1272 .. code-block:: shell
1276 .. code-block:: shell
1278 (lldb) image lookup --type Point
1279 (lldb) im loo -t Point
1281 Dump all sections from the main executable and any shared libraries
1282 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1284 .. code-block:: shell
1286 (gdb) maintenance info sections
1288 .. code-block:: shell
1290 (lldb) image dump sections
1292 Dump all sections in the ``a.out`` module
1293 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1295 .. code-block:: shell
1297 (lldb) image dump sections a.out
1299 Dump all symbols from the main executable and any shared libraries
1300 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1302 .. code-block:: shell
1304 (lldb) image dump symtab
1306 Dump all symbols in ``a.out`` and ``liba.so``
1307 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1309 .. code-block:: shell
1311 (lldb) image dump symtab a.out liba.so
1316 Search command help for a keyword
1317 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1319 .. code-block:: shell
1321 (gdb) apropos keyword
1323 .. code-block:: shell
1325 (lldb) apropos keyword
1327 Echo text to the screen
1328 ~~~~~~~~~~~~~~~~~~~~~~~
1330 .. code-block:: shell
1332 (gdb) echo Here is some text\n
1334 .. code-block:: shell
1336 (lldb) script print "Here is some text"
1338 Remap source file pathnames for the debug session
1339 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1341 If your source files are no longer located in the same location as when the
1342 program was built (for example, if the program was built on a different
1343 computer) you need to tell the debugger how to find the sources at their local
1344 file path instead of the build system's file path.
1346 .. code-block:: shell
1348 (gdb) set pathname-substitutions /buildbot/path /my/path
1350 .. code-block:: shell
1352 (lldb) settings set target.source-map /buildbot/path /my/path
1354 Supply a catchall directory to search for source files in.
1356 .. code-block:: shell
1358 (gdb) directory /my/path