Skip to content
systemcoding.dev
Debugging

GDB to LLDB Command Map for Switching Debuggers

A GDB-to-LLDB command map by task: running, breakpoints, stepping, variables, memory, registers, threads and settings, with the cases where the two differ.

6 min read
Summarize in AI
Flat illustration of a debugger stopped at a breakpoint beside the register values, with the GNU, LLVM and Arm logos.

Moving from GDB to LLDB, or the other way, is mostly a matter of vocabulary. Both debuggers read the same DWARF, stop programs with the same breakpoint instruction and show the same stacks, so the concepts carry across completely. What changes is the spelling of commands and the shape of the output. This is a map from one to the other, grouped by task. Each entry gives the GDB form, the LLDB form, and, since a map without exceptions misleads, the place where the two stop being equivalent. LLDB has built-in GDB-style aliases for the commonest commands (b, c, n, s, bt, p, r, fin, i r), so many of these work unchanged. The LLDB forms are for LLDB 21, and the GDB forms for GDB 16.3. The project's own table lives in the LLDB documentation as the "GDB to LLDB command map", which is worth keeping open for the rest.

Starting and running

TaskGDBLLDB
Load a programgdb ./proglldb ./prog
Load with argumentsgdb --args ./prog a blldb -- ./prog a b
Runrun or rprocess launch or run or r
Run with argumentsrun a brun a b
Run and stop at mainstartprocess launch --stop-at-entry, or breakpoint set -n main then run
Attach to a pidgdb -p 123, attach 123lldb -p 123, process attach --pid 123
Attach by namegdb -p $(pidof prog)process attach --name prog
Detachdetachprocess detach
Killkillprocess kill
Quitquitquit

Where they differ. GDB's start sets a temporary breakpoint on main; LLDB has no one-word equivalent, and --stop-at-entry stops at the program's very first instruction, before main and before the dynamic loader has run, which is not the same thing. On macOS, process attach --name can also wait for a process with --waitfor, which GDB does not do natively.

Breakpoints

TaskGDBLLDB
On a functionbreak mainbreakpoint set --name main or b main
On file and linebreak file.c:12breakpoint set --file file.c --line 12 or b file.c:12
On an addressbreak *0x4005d0breakpoint set --address 0x4005d0
By regexrbreak ^parse_breakpoint set --func-regex '^parse_'
Temporarytbreak mainbreakpoint set --name main --one-shot true
Conditionalbreak f if x > 3breakpoint set --name f --condition 'x > 3'
Listinfo breakpointsbreakpoint list
Disable, enabledisable 2, enable 2breakpoint disable 2, breakpoint enable 2
Deletedelete 2breakpoint delete 2
Ignore first N hitsignore 2 5breakpoint modify --ignore-count 5 2
Commands on hitcommands 2 ... endbreakpoint command add 2 ... DONE

Where they differ. A GDB commands list ends with end and LLDB's with DONE, which catches people in scripts. GDB's commands can start with silent; in LLDB use --auto-continue and a one-line command with -o. GDB's rbreak sets breakpoints for each match immediately and lists them, while LLDB's regex breakpoint is one breakpoint with many locations. GDB's dprintf has no LLDB twin; use a breakpoint command that prints and auto-continues.

Stepping and execution

TaskGDBLLDB
Continuecontinue or cprocess continue or c
Step over a linenext or nthread step-over or next or n
Step intostep or sthread step-in or step or s
Step outfinishthread step-out or finish
One instructionstepi or sithread step-inst or si
One instruction, over callsnexti or nithread step-inst-over or ni
Run to a lineuntil 20 or advance 20thread until --address ADDR, or a one-shot breakpoint
Jump to a linejump 20thread jump --line 20
Return nowreturnthread return

Where they differ. LLDB's finish prints Return value: (int) $1 = 108, which GDB prints as Value returned is $1 = 108; scripts that parse them need both patterns. GDB's until LINE has no direct LLDB command; set a one-shot breakpoint on the line and continue. By default LLDB's step does not enter functions that have no debug information, controlled by settings set target.step-avoid-regexp, and GDB does the same unless set step-mode on.

Looking at variables and expressions

TaskGDBLLDB
Print an expressionprint x * 2expression x * 2 or p x * 2
Print a variable, no codeprint xframe variable x or v x
Hex formatprint/x xp/x x
All localsinfo localsframe variable
Argumentsinfo argsframe variable --arguments
Type of an expressionwhatis x, ptype ximage lookup --type T, or expression -T -- x
Show a struct's definitionptype struct stype lookup s
Display each stopdisplay xtarget stop-hook add --one-liner "frame variable x"
Set a variableset var x = 5expression x = 5
Call a functioncall f(2)expression f(2)

Where they differ. LLDB has two ways to print, frame variable (direct memory read) and expression (compiles code), where GDB has only print. p in LLDB is expression. LLDB's ptype equivalent is type lookup, and whatis does not exist as such. GDB's display is a per-expression list that prints at every stop; LLDB's target stop-hook is more general, running any command list at each stop.

The call stack

TaskGDBLLDB
Backtracebacktrace or btthread backtrace or bt
Backtrace with localsbt fullbt plus frame variable per frame
Backtrace of all threadsthread apply all btthread backtrace all or bt all
Select a frameframe 2frame select 2 or f 2
Up, downup, downup, down
Frame detailsinfo frameframe info

Where they differ. GDB's bt full has no single-command LLDB twin, and the usual replacement is a short Python loop or a series of frame select and frame variable. LLDB marks the selected frame with * in a backtrace, and shows its frame number as frame #N.

Memory and registers

TaskGDBLLDB
Examine memoryx/4xw &vmemory read --size 4 --format x --count 4 &v or x/4xw &v
Examine a stringx/s pmemory read --format s p or x/s p
Disassemble a functiondisassemble fdisassemble --name f or di -n f
Disassemble at pcx/5i $pcdisassemble --pc --count 5
All registersinfo registersregister read
One registerinfo registers rip, p $ripregister read rip, p $rip
Write a registerset $rax = 1register write rax 1

Where they differ. Recent LLDB accepts GDB's x/NFU syntax as a built-in alias, so x/4xw &v works, but its output has a different layout: LLDB prints the address, a colon and the values, with a 0x on each. Disassembly syntax is AT&T on both by default for x86; GDB switches with set disassembly-flavor intel, LLDB with settings set target.x86-disassembly-flavor intel.

Watchpoints and signals

TaskGDBLLDB
Watch a variablewatch xwatchpoint set variable x or w s v x
Watch an addresswatch -l *(int*)0x...watchpoint set expression -- 0x...
Read or access watchrwatch x, awatch xwatchpoint set variable -w read x, -w read_write x
Listinfo watchpointswatchpoint list
Deletedelete 3watchpoint delete 3
Handle a signalhandle SIGPIPE nostop noprint passprocess handle SIGPIPE --notify false --stop false --pass true

Where they differ. An LLDB watchpoint has a size and type chosen with -s and -w, and defaults to a write watch. GDB's scoped watch on a local is deleted when the frame returns; LLDB behaves similarly but the wording of the message differs. The post on LLDB watchpoints covers the sizes and the four-register limit that both share.

Threads, shared libraries and settings

TaskGDBLLDB
List threadsinfo threadsthread list
Switch threadthread 2thread select 2
Shared librariesinfo sharedlibraryimage list
Find a symbolinfo address f, info symbol 0x...image lookup --name f, image lookup --address 0x...
Show sourcelist fsource list --name f or l f
Limit printed elementsset print elements 200settings set target.max-children-count 200
Show a settingshow print prettysettings show NAME
Search commandsapropos wordapropos word
Help on a commandhelp breakhelp breakpoint set

Where they differ. GDB's settings are flat and named by what they affect, while LLDB's live in a tree (target., target.process., frame-format), which settings list shows. LLDB's image command is the family that GDB spreads over info sharedlibrary, info address and info symbol.

Making LLDB feel like GDB

Put your habits into ~/.lldbinit, which LLDB reads at startup.

~/.lldbinitText
command alias bpl breakpoint list
command alias lo frame variable
settings set stop-line-count-before 5
settings set stop-line-count-after 5
settings set target.x86-disassembly-flavor intel

command alias creates a new command out of an existing one with fixed arguments. With -x on the command line, lldb -x ./prog skips the init file for a clean session. LLDB's own set of GDB-compatible short forms covers b, br, c, n, s, bt, p, po, r, fr v, up, down and i r (as register read's alias), so for daily stepping most of your GDB muscle memory works as typed.

When the map stops helping

The map covers commands, not output. Scripts that scrape GDB's text will not work on LLDB's, and the reverse; use the structured interfaces, GDB's MI or LLDB's Python API, for automation. And three things have no counterpart: GDB's reverse execution and rr, LLDB's Swift and Objective-C expression support, and GDB's define language, which LLDB replaces with Python commands.

Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.