VOOZH about

URL: https://lldb.llvm.org/use/map.html

⇱ GDB to LLDB command map - 🐛 LLDB


Back to top

GDB to LLDB command map#

Below is a table of GDB commands with their LLDB counterparts. The built in GDB-compatibility aliases in LLDB are also listed. The full lldb command names are often long, but any unique short form can be used. Instead of “breakpoint set”, “br se” is also acceptable.

Execution Commands#

Launch a process no arguments#

(gdb)run
(gdb)r
(lldb)processlaunch
(lldb)run
(lldb)r

Launch a process with arguments <args>#

(gdb)run<args>
(gdb)r<args>
(lldb)processlaunch--<args>
(lldb)run<args>
(lldb)r<args>

Launch process a.out with arguments 1 2 3 by passing the args to the debugger#

%gdb--argsa.out123
(gdb)run
...
(gdb)run
...
%lldb--a.out123
(lldb)run
...
(lldb)run
...

Launch process a.out with arguments 1 2 3 by setting the args in the debugger#

(gdb)setargs123
(gdb)run
...
(gdb)run
...
(lldb)settingssettarget.run-args123
(lldb)run
...
(lldb)run
...

Launch a process with arguments in new terminal window (macOS only)#

(lldb)processlaunch--tty--<args>
(lldb)prola-t--<args>

Launch a process with arguments <args> in existing terminal /dev/ttys006#

(lldb)processlaunch--tty=/dev/ttys006--<args>
(lldb)prola-t/dev/ttys006--<args>

Set environment variables for process before launching#

(gdb)setenvDEBUG1
(lldb)settingssettarget.env-varsDEBUG=1
(lldb)setsetarget.env-varsDEBUG=1
(lldb)envDEBUG=1

Unset environment variables for process before launching#

(gdb)unsetenvDEBUG
(lldb)settingsremovetarget.env-varsDEBUG
(lldb)setremtarget.env-varsDEBUG

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

(gdb)showargs
Argumentlisttogiveprogrambeingdebuggedwhenitisstartedis"1 2 3".
(lldb)settingsshowtarget.run-args
target.run-args(arrayofstrings)=
[0]:"1"
[1]:"2"
[2]:"3"

Set environment variables for process and launch process in one command#

(lldb)processlaunch-EDEBUG=1

Attach to the process with process ID 123#

(gdb)attach123
(lldb)processattach--pid123
(lldb)attach-p123

Attach to the process named a.out#

(gdb)attacha.out
(lldb)processattach--namea.out
(lldb)proat-na.out

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

(gdb)attach-waitfora.out
(lldb)processattach--namea.out--waitfor
(lldb)proat-na.out-w

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

(gdb)targetremoteeorgadd:8000
(lldb)gdb-remoteeorgadd:8000

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

(gdb)targetremotelocalhost:8000
(lldb)gdb-remote8000

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

(gdb)kdp-reattacheorgadd
(lldb)kdp-remoteeorgadd

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

(gdb)step
(gdb)s
(lldb)threadstep-in
(lldb)step
(lldb)s

Ignore a function when doing a source level single step in#

(gdb)skipabc
Functionabcwillbeskippedwhenstepping.
(lldb)settingsshowtarget.process.thread.step-avoid-regexp
target.process.thread.step-avoid-regexp(regex)=^std::
(lldb)settingssettarget.process.thread.step-avoid-regexp^std::|^abc

You can ignore a function once using:

(lldb)threadstep-in-r^abc

Or you can do the opposite, only step into functions matching a certain name:

# Step in if abc is a substring of the function name.
(lldb)sifabc
# Which is equivalent to:
(lldb)threadstep-in-tabc

thread step-in has more options which cover some of skip’s other features. See help thread step-in for details.

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

(gdb)next
(gdb)n
(lldb)threadstep-over
(lldb)next
(lldb)n

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

(gdb)stepi
(gdb)si
(lldb)threadstep-inst
(lldb)si

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

(gdb)nexti
(gdb)ni
(lldb)threadstep-inst-over
(lldb)ni

Step out of the currently selected frame#

(gdb)finish
(lldb)threadstep-out
(lldb)finish

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

(gdb)return<RETURNEXPRESSION>
(lldb)threadreturn<RETURNEXPRESSION>

Backtrace and disassemble every time you stop#

(lldb)targetstop-hookadd
Enteryourstophookcommand(s).Type'DONE'toend.
>bt
>disassemble--pc
>DONE
Stophook#1 added.

Run until we hit line 12 or control leaves the current function#

(gdb)until12
(lldb)threaduntil12

Show the current frame and source line#

(gdb)frame
(lldb)frameselect
(lldb)f
(lldb)processstatus

Breakpoint Commands#

Set a breakpoint at all functions named main#

(gdb)breakmain
(lldb)breakpointset--namemain
(lldb)brs-nmain
(lldb)bmain

Set a breakpoint in file test.c at line 12#

(gdb)breaktest.c:12
(lldb)breakpointset--filetest.c--line12
(lldb)brs-ftest.c-l12
(lldb)btest.c:12

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

(gdb)breakmain
(HopethattherearenoCfunctionsnamedmain)
(lldb)breakpointset--methodmain
(lldb)brs-Mmain

Set a breakpoint at an Objective-C function -[NSString stringWithFormat:]#

(gdb)break-[NSStringstringWithFormat:]
(lldb)breakpointset--name"-[NSString stringWithFormat:]"
(lldb)b-[NSStringstringWithFormat:]

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

(gdb)breakcount
(HopethattherearenoCorC++functionsnamedcount)
(lldb)breakpointset--selectorcount
(lldb)brs-Scount

Set a breakpoint by regular expression on function name#

(gdb)rbreakregular-expression
(lldb)breakpointset--func-regexregular-expression
(lldb)brs-rregular-expression

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

(gdb)bfoo.c:12
(lldb)settingssettarget.inline-breakpoint-strategyalways
(lldb)brs-ffoo.c-l12

Set a breakpoint by regular expression on source file contents#

(gdb)shellgrep-e-npatternsource-file
(gdb)breaksource-file:CopyLineNumbers
(lldb)breakpointset--source-patternregular-expression--fileSourceFile
(lldb)brs-pregular-expression-ffile

Set a conditional breakpoint#

(gdb)breakfooifstrcmp(y,"hello")==0
(lldb)breakpointset--namefoo--condition'(int)strcmp(y,"hello") == 0'
(lldb)brs-nfoo-c'(int)strcmp(y,"hello") == 0'

List all breakpoints#

(gdb)infobreak
(lldb)breakpointlist
(lldb)brl

Delete a breakpoint#

(gdb)delete1
(lldb)breakpointdelete1
(lldb)brdel1

Disable a breakpoint#

(gdb)disable1
(lldb)breakpointdisable1
(lldb)brdis1

Enable a breakpoint#

(gdb)enable1
(lldb)breakpointenable1
(lldb)bren1

Watchpoint Commands#

Set a watchpoint on a variable when it is written to#

(gdb)watchglobal_var
(lldb)watchpointsetvariableglobal_var
(lldb)wasvglobal_var

Set a watchpoint on a memory location when it is written into#

The size of the region to watch for defaults to the pointer size if no ‘-x byte_size’ is specified. This command takes raw input, evaluated as an expression returning an unsigned integer pointing to the start of the region, after the ‘–’ option terminator.

(gdb)watch-locationg_char_ptr
(lldb)watchpointsetexpression--my_ptr
(lldb)wase--my_ptr

Set a condition on a watchpoint#

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

List all watchpoints#

(gdb)infobreak
(lldb)watchpointlist
(lldb)watchl

Delete a watchpoint#

(gdb)delete1
(lldb)watchpointdelete1
(lldb)watchdel1

Examining Variables#

Show the arguments and local variables for the current frame#

(gdb)infoargs
(gdb)infolocals
(lldb)framevariable
(lldb)frv

Show the local variables for the current frame#

(gdb)infolocals
(lldb)framevariable--no-args
(lldb)frv-a

Show the contents of local variable bar#

(gdb)pbar
(lldb)framevariablebar
(lldb)frvbar
(lldb)pbar

Show the contents of local variable bar formatted as hex#

(gdb)p/xbar
(lldb)framevariable--formatxbar
(lldb)frv-fxbar

Show the contents of global variable baz#

(gdb)pbaz
(lldb)targetvariablebaz
(lldb)tavbaz

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

(lldb)targetvariable
(lldb)tav

Display the variables argc and argv every time you stop#

(gdb)displayargc
(gdb)displayargv
(lldb)targetstop-hookadd--one-liner"frame variable argc argv"
(lldb)tasta-o"fr v argc argv"
(lldb)displayargc
(lldb)displayargv

Display the variables argc and argv only when you stop in the function named main#

(lldb)targetstop-hookadd--namemain--one-liner"frame variable argc argv"
(lldb)tasta-nmain-o"fr v argc argv"

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

(lldb)targetstop-hookadd--classnameMyClass--one-liner"frame variable *this"
(lldb)tasta-cMyClass-o"fr v *this"

Print an array of integers in memory, assuming we have a pointer like int *ptr#

(gdb)p*ptr@10
(lldb)parray10ptr

Evaluating Expressions#

Evaluating a generalized expression in the current frame#

(gdb)print(int)printf("Print nine: %d.",4+5)

or if you don’t want to see void returns:

(gdb)call(int)printf("Print nine: %d.",4+5)
(lldb)expr(int)printf("Print nine: %d.",4+5)

or using the print alias:

(lldb)print(int)printf("Print nine: %d.",4+5)

Creating and assigning a value to a convenience variable#

(gdb)set$foo=5
(gdb)setvariable$foo=5

or using the print command

(gdb)print$foo=5

or using the call command

(gdb)call$foo=5

and if you want to specify the type of the variable:

(gdb)set$foo=(unsignedint)5

In lldb you evaluate a variable declaration expression as you would write it in C:

(lldb)exprunsignedint$foo=5

Printing the ObjC “description” of an object#

(gdb)po[SomeClassreturnAnObject]
(lldb)expr-o--[SomeClassreturnAnObject]

or using the po alias:

(lldb)po[SomeClassreturnAnObject]

Print the dynamic type of the result of an expression#

(gdb)setprintobject1
(gdb)psomeCPPObjectPtrOrReference
(OnlyworksforC++objects)

LLDB does this automatically if determining the dynamic type does not require running the target (in C++, running the target is never needed). This default is controlled by the target.prefer-dynamic-value setting. If that is disabled, it can be re-enabled on a per-command basis:

(lldb)settingssettarget.prefer-dynamic-valueno-dynamic-values
(lldb)framevariable-dno-run-targetsomeCPPObjectPtrOrReference
(lldb)expr-dno-run-target--someCPPObjectPtr

Note that printing of the dynamic type of references is not possible with the expr command. The workaround is to take the address of the reference and instruct lldb to print the children of the resulting pointer.

(lldb)expr-P1-dno-run-target--&someCPPObjectReference

Call a function so you can stop at a breakpoint in it#

(gdb)setunwindonsignal0
(gdb)pfunction_with_a_breakpoint()
(lldb)expr-i0--function_with_a_breakpoint()

Call a function that crashes, then stop when it does#

(gdb)setunwindonsignal0
(gdb)pfunction_which_crashes()
(lldb)expr-u0--function_which_crashes()

Examining Thread State#

List the threads in your program#

(gdb)infothreads
(lldb)threadlist

Select thread 1 as the default thread for subsequent commands#

(gdb)thread1
(lldb)threadselect1
(lldb)t1

Show the stack backtrace for the current thread#

(gdb)bt
(lldb)threadbacktrace
(lldb)bt

Show the stack backtraces for all threads#

(gdb)threadapplyallbt
(lldb)threadbacktraceall
(lldb)btall

Backtrace the first five frames of the current thread#

(gdb)bt5
(lldb)threadbacktrace-c5
(lldb)bt5

Select a different stack frame by index for the current thread#

(gdb)frame12
(lldb)frameselect12
(lldb)frs12
(lldb)f12

List information about the currently selected frame in the current thread#

(lldb)frameinfo

Select the stack frame that called the current stack frame#

(gdb)up
(lldb)up
(lldb)frameselect--relative=1

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

(gdb)down
(lldb)down
(lldb)frameselect--relative=-1
(lldb)frs-r-1

Select a different stack frame using a relative offset#

(gdb)up2
(gdb)down3
(lldb)frameselect--relative2
(lldb)frs-r2

(lldb)frameselect--relative-3
(lldb)frs-r-3

show the general purpose registers for the current thread#

(gdb)inforegisters
(lldb)registerread

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

(gdb)p$rax=123
(lldb)registerwriterax123

Skip 8 bytes ahead of the current program counter (instruction pointer)#

Note that we use backticks to evaluate an expression and insert the scalar result in LLDB.

(gdb)jump*$pc+8
(lldb)registerwritepc`$pc+8`

Show the general purpose registers for the current thread formatted as signed decimal#

LLDB tries to use the same format characters as printf(3) when possible. Type “help format” to see the full list of format specifiers.

(lldb)registerread--formati
(lldb)rer-fi

LLDB now supports the GDB shorthand format syntax but there can’t be space after the command:

(lldb)registerread/d

Show all registers in all register sets for the current thread#

(gdb)infoall-registers
(lldb)registerread--all
(lldb)rer-a

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

(gdb)infoall-registersraxrsprbp
(lldb)registerreadraxrsprbp

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

(gdb)p/t$rax
(lldb)registerread--formatbinaryrax
(lldb)rer-fbrax

LLDB now supports the GDB shorthand format syntax but there can’t be space after the command

(lldb)registerread/trax
(lldb)p/t$rax

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

(gdb)x/4xw0xbffff3c0
(lldb)memoryread--size4--formatx--count40xbffff3c0
(lldb)mer-s4-fx-c40xbffff3c0
(lldb)x-s4-fx-c40xbffff3c0

LLDB now supports the GDB shorthand format syntax but there can’t be space after the command:

(lldb)memoryread/4xw0xbffff3c0
(lldb)x/4xw0xbffff3c0
(lldb)memoryread--gdb-format4xw0xbffff3c0

Read memory starting at the expression argv[0]#

(gdb)xargv[0]
(lldb)memoryread`argv[0]`

NOTE: any command can inline a scalar expression result (as long as the target is stopped) using backticks around any expression:

(lldb)memoryread--size`sizeof(int)``argv[0]`

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

(gdb)setloggingon
(gdb)setloggingfile/tmp/mem.txt
(gdb)x/512bx0xbffff3c0
(gdb)setloggingoff
(lldb)memoryread--outfile/tmp/mem.txt--count5120xbffff3c0
(lldb)mer-o/tmp/mem.txt-c5120xbffff3c0
(lldb)x/512bx-o/tmp/mem.txt0xbffff3c0

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

(gdb)dumpmemory/tmp/mem.bin0x10000x2000
(lldb)memoryread--outfile/tmp/mem.bin--binary0x10000x2000
(lldb)mer-o/tmp/mem.bin-b0x10000x2000

Print information about memory regions#

(gdb)infoprocmappings
(lldb)memoryregion--all
(lldb)mereg--all

Get information about a specific heap allocation (macOS only)#

(gdb)infomalloc0x10010d680
(lldb)commandscriptimportlldb.macosx.heap
(lldb)processlaunch--environmentMallocStackLogging=1--[ARGS]
(lldb)malloc_info--stack-history0x10010d680

Get information about a specific heap allocation and cast the result to any dynamic type that can be deduced (macOS only)#

(lldb)commandscriptimportlldb.macosx.heap
(lldb)malloc_info--type0x10010d680

Find all heap blocks that contain a pointer specified by an expression EXPR (macOS only)#

(lldb)commandscriptimportlldb.macosx.heap
(lldb)ptr_refsEXPR

Find all heap blocks that contain a C string anywhere in the block (macOS only)#

(lldb)commandscriptimportlldb.macosx.heap
(lldb)cstr_refsCSTRING

Disassemble the current function for the current frame#

(gdb)disassemble
(lldb)disassemble--frame
(lldb)di-f

Disassemble any functions named main#

(gdb)disassemblemain
(lldb)disassemble--namemain
(lldb)di-nmain

Disassemble an address range#

(gdb)disassemble0x1eb80x1ec3
(lldb)disassemble--start-address0x1eb8--end-address0x1ec3
(lldb)di-s0x1eb8-e0x1ec3

Disassemble 20 instructions from a given address#

(gdb)x/20i0x1eb8
(lldb)disassemble--start-address0x1eb8--count20
(lldb)di-s0x1eb8-c20

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

(lldb)disassemble--frame--mixed
(lldb)di-f-m

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

(lldb)disassemble--frame--bytes
(lldb)di-f-b

Disassemble the current source line for the current frame#

(lldb)disassemble--line
(lldb)di-l

Executable and Shared Library Query Commands#

List the main executable and all dependent shared libraries#

(gdb)infoshared
(lldb)imagelist

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

(gdb)infosymbol0x1ec4
(lldb)imagelookup--address0x1ec4
(lldb)imloo-a0x1ec4

Look up functions matching a regular expression in a binary#

(gdb)infofunction<FUNC_REGEX>

This one finds debug symbols:

(lldb)imagelookup-r-n<FUNC_REGEX>

This one finds non-debug symbols:

(lldb)imagelookup-r-s<FUNC_REGEX>

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

Find full source line information#

(gdb)infoline0x1ec4

This one is a bit messy at present. Do:

(lldb)imagelookup-v--address0x1ec4

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

Look up information for an address in a.out only#

(lldb)imagelookup--address0x1ec4a.out
(lldb)imloo-a0x1ec4a.out

Look up information for for a type Point by name#

(gdb)ptypePoint
(lldb)imagelookup--typePoint
(lldb)imloo-tPoint

Dump all sections from the main executable and any shared libraries#

(gdb)maintenanceinfosections
(lldb)imagedumpsections

Dump all sections in the a.out module#

(lldb)imagedumpsectionsa.out

Dump all symbols from the main executable and any shared libraries#

(lldb)imagedumpsymtab

Dump all symbols in a.out and liba.so#

(lldb)imagedumpsymtaba.outliba.so

Save current process as a core file#

(gdb)gcorefilename
(lldb)processsave-corefilename

Miscellaneous#

Search command help for a keyword#

(gdb)aproposkeyword
(lldb)aproposkeyword

Echo text to the screen#

(gdb)echoHereissometext\n
(lldb)scriptprint("Here is some text")

Remap source file pathnames for the debug session#

If your source files are no longer located in the same location as when the program was built (for example, if the program was built on a different computer) you need to tell the debugger how to find the sources at their local file path instead of the build system’s file path.

(gdb)setpathname-substitutions/buildbot/path/my/path
(lldb)settingssettarget.source-map/buildbot/path/my/path

Supply a catchall directory to search for source files in#

(gdb)directory/my/path

There is no equivalent LLDB command, use target.source-map instead.