# Use the debugger
The LLDB debugger debugs C and C++ programs written for the Hexagon processor.
## Start the debugger
To start LLDB from a command line, enter:
hexagon-lldb program [option...]
Copy to clipboard
Where:
- program is the name of an executable Hexagon file
- option indicates the LLDB options <use-the-debugger-debug-options>
Note
The program file can alternatively be specified on the command line using the LLDB `--file` option.
### Command line arguments
Command line arguments in LLDB are complicated by the fact that
arguments might be required to be passed to three different entities:
- The LLDB itself
- The Hexagon simulator (which is launched by LLDB)
- The program that is being debugged
To distinguish these sets of command line items, all the LLDB
arguments and options are specified first on the command line,
followed by all the simulator arguments and options, followed by all
the program arguments and options. Each set of items is separated on
the command line by an instance of the – character sequence. For
example:
hexagon-lldb program [option...] -- sim_args --program_args
Copy to clipboard
Note
The program name specified for LLDB is automatically passed
to the simulator, so you can specify it only once on the command
line.
In the following example, – is used to separate the LLDB foo.elf
argument from the simulator -mv5 command option from the program bar
argument.
hexagon-lldb foo.elf -- -mv5 -- bar
Copy to clipboard
foo.elf is automatically passed to the simulator as the name of the
file to run.
### Command files
When LLDB starts up, it reads debug settings, commands, and command
aliases from the following three command files, in the specified
order:
1. .lldbinit-debugger
When using a command line interface, this file is named
.lldbinit-hexagon-lldb. When using LLDB in Eclipse, it is named
.lldbinit-hexagon-lldb-mi.
This file is a useful place for storing settings that you want to
apply only when a given command interpreter is used.
2. ~/.lldbinit
3. .lldbinit
This file is assumed to be stored in the current working directory
(that is, where LLDB was started).
### Debug a remote application
LLDB can debug an application already running on the Hexagon
simulator, if the simulator was launched with a unique port number.
1. Launch the simulator that is running the application to be debugged,
using the -G switch to identify a unique port number:
hexagon-sim -G Port# program sim_args
Copy to clipboard
The simulator loads the program with the sim\_args, but it pauses the
program at the beginning.
2. Start LLDB from the command line in a separate terminal or machine:
hexagon-lldb program [option...]
Copy to clipboard
Where program is the same file loaded by the simulator.
3. At the (lldb) prompt, enter the command:
(lldb) gdb-remote host:Port#
Copy to clipboard
Where:
- host: is the name of the machine on which hexagon-sim is running, if the machine is
different from where LLDB is running
- Port# is the port number used when launching the simulator
4. When the debugger establishes a connection to the simulator, proceed
with typical debug operations.
Note
All input and output performed by the application occurs where the simulator is running.
## Debug options
LLDB supports the following debug options to control various LLDB
features from the command line when LLDB is first launched.
-e | --editor
-f filename | --file filename
-h | --help
-o cmdname | --one-line cmdname
-O cmdname | --one-line-before-file cmdname
-Q | --source-quietly
-s filename | --source filename
-S filename | --source-before-file filename
-v | --version
-x | --no-lldbinit
Copy to clipboard
### Descriptions
- **-e** | **–editor**
- Open all program source files using the host’s external editor
mechanism.
- **-f** *filename* | **-file** *filename*
- Specify the executable file to launch.
If this option is not specified, LLDB uses the first argument on the
command line as the name of the executable file to launch.
- **-h** | **–help**
- Print the usage information for the debugger.
- **-o** *cmdname* | **–one-line** *cmdname*
- Execute the specified LLDB command immediately *after* LLDB loads the
executable file specified on the command line.
The specified command must fit on one line.
You can use this option multiple times. The specified commands are
executed in the order (from left to right) that they appear on the
command line.
- **-O** *cmdname* | **–one-line-before-file** *cmdname*
- Execute the specified LLDB command immediately *before* LLDB loads
the executable file specified on the command line.
The specified command must fit on one line.
You can use this option multiple times. The specified commands are
executed in the order (from left to right) that they appear on the
command line.
- **-Q** | **–source-quietly**
- Suppress the display output generated by any LLDB commands that are
specified with the -o, -O, -s, or -S commands.
- **-s** *filename* | **-source** *filename*
- Execute the specified LLDB commands immediately *after* LLDB loads
the executable file specified on the command line.
The specified file is a text file containing a list of the command
names to execute.
You can use this option multiple times. The specified commands are
executed in the order (from left to right) that they appear on the
command line.
- **-S** *filename* | **-source-before-file** *filename*
- Execute the specified LLDB commands immediately *before* LLDB loads
the executable file specified on the command line.
The specified file is a text file containing a list of the command
names to execute.
You can use this option multiple times. The specified commands are
executed in the order (from left to right) that they appear on the
command line.
- **-v** | **–version**
- Print the version number of the debugger.
- **-x** | **–no-lldbinit**
- Do not automatically parse any.lldbinit files.
## Debug commands
This section lists the LLDB commands by category, along with their
GDB equivalents (which in many cases are identical).
Command names can be shortened in LLDB if they uniquely identify the
command. For example, to invoke the breakpoint set command, enter br
se.
Note
The tlb, pagetable, pv8, pv16, and pv32 commands are
specific to the Hexagon version of LLDB. They are implemented in the
hexagon\_utils.py script.
### Command options
Many LLDB debug commands accept options that resemble the command
line options used to start the debugger itself. These options are
command-specific: they work only with the debug commands for which
they are defined.
You can specify debug command options anywhere on the command line,
but if any command arguments begin with a - character, LLDB will not
be able to distinguish the command options from the command
arguments. In this case, all the options must be specified before the
arguments, and the two sets of items must be separated with the –
character sequence.
In this example, – is used to separate the –stop-at-entry command
option from the -program-arg command argument:
(lldb) process launch --stop-at-entry -- -program_arg
Copy to clipboard
### Execution commands
| **GDB** | **LLDB** |
| --- | --- |
| **Launch process with arguments** | **Launch process with arguments** |
| (gdb) run args
(gdb) r args
Copy to clipboard | (lldb) process launch -- args
(lldb) r args
Copy to clipboard |
| **Launch process with arguments a.out 1 2 3, without supplying arguments every time** | **Launch process with arguments a.out 1 2 3, without supplying arguments every time** |
| % gdb --args a.out 1 2 3
(gdb) run
...
(gdb) run
...
Copy to clipboard | % lldb -- a.out 1 2 3
(lldb) run
...
(lldb) run
...
Copy to clipboard |
| **Or** | **Or** |
| (gdb) set args 1 2 3
(gdb) run
...
(gdb) run
...
Copy to clipboard | (lldb) settings set target.run-args 1 2 3
(lldb) run
...
(lldb) run
...
Copy to clipboard |
| **Set the nvironment variables for process before launching** | **Set the nvironment variables for process before launching** |
| (gdb) set env DEBUG 1
Copy to clipboard | (lldb) settings set target.env-vars DEBUG=1
(lldb) set se target.env-vars DEBUG=1
(lldb) env DEBUG=1
Copy to clipboard |
| **Unset the environment variables for process before launching** | **Unset the environment variables for process before launching** |
| (gdb) unset env DEBUG
Copy to clipboard | (lldb) settings remove target.env-vars DEBUG
(lldb) set rem target.env-vars DEBUG
Copy to clipboard |
| **Show the arguments that will be or were passed to the program when run** | **Show the arguments that will be or were passed to the program when run** |
| (gdb) show args
Argument list to give a program being debugged when it is started is 1 2 3.
Copy to clipboard | (lldb) settings show target.run-args
target.run-args (array of strings) =
[0]: "1"
[1]: "2"
[2]: "3"
Copy to clipboard |
| **Set the environment variables for process, and launch process in one command** | **Set the environment variables for process, and launch process in one command** |
| | (lldb) process launch -v DEBUG=1
Copy to clipboard |
| **Attach to the remote GDB protocol server running on system eorgadd, port 8000** | **Attach to the remote GDB protocol server running on system eorgadd, port 8000** |
| (gdb) target remote eorgadd:8000
Copy to clipboard | (lldb) gdb-remote eorgadd:8000
Copy to clipboard |
| **Attach to the remote GDB protocol server running on local system, port 8000** | **Attach to the remote GDB protocol server running on local system, port 8000** |
| (gdb) target remote localhost:8000
Copy to clipboard | (lldb) gdb-remote 8000
Copy to clipboard |
| **Attach to the Darwin kernel in kdp mode on system eorgadd** | **Attach to the Darwin kernel in kdp mode on system eorgadd** |
| (gdb) kdp-reattach eorgadd
Copy to clipboard | (lldb) kdp-remote eorgadd
Copy to clipboard |
| **Launch the simulator with the current target, and connect to it** | **Launch the simulator with the current target, and connect to it** |
| | (lldb) run
Copy to clipboard |
| **Do a source level single step in the currently selected thread** | **Do a source level single step in the currently selected thread** |
| (gdb) step
(gdb) s
Copy to clipboard | (lldb) thread step-in
(lldb) step
(lldb) s
Copy to clipboard |
| **Do a source level single step over in the currently selected thread** | **Do a source level single step over in the currently selected thread** |
| (gdb) next
(gdb) n
Copy to clipboard | (lldb) thread step-over
(lldb) next
(lldb) n
Copy to clipboard |
| **Do an instruction-level single step in the currently selected thread** | **Do an instruction-level single step in the currently selected thread** |
| (gdb) stepi
(gdb) si
Copy to clipboard | (lldb) thread step-inst
(lldb) si
Copy to clipboard |
| **Do an instruction-level single step over in the currently selected thread** | **Do an instruction-level single step over in the currently selected thread** |
| (gdb) nexti
(gdb) ni
Copy to clipboard | (lldb) thread step-inst-over
(lldb) ni
Copy to clipboard |
| **Step out of the currently selected frame** | **Step out of the currently selected frame** |
| (gdb) finish
Copy to clipboard | (lldb) thread step-out
(lldb) finish
Copy to clipboard |
| **Return immediately from the currently selected frame, with an optional return value** | **Return immediately from the currently selected frame, with an optional return value** |
| (gdb) return expression
Copy to clipboard | (lldb) thread return expression
Copy to clipboard |
| **Backtrace and disassemble every time you stop** | **Backtrace and disassemble every time you stop** |
| | (lldb) target stop-hook add
Enter your stop hook commands. Enter DONE to end.
> bt
> disassemble --pc
> DONE
Stop hook #1 added.
Copy to clipboard |
### Breakpoint commands
| **GDB** | **LLDB** |
| --- | --- |
| **Set a breakpoint at all functions named main** | **Set a breakpoint at all functions named main** |
| (gdb) break main
Copy to clipboard | (lldb) breakpoint set --name main
(lldb) br s -n main
(lldb) b main
Copy to clipboard |
| **Set a breakpoint in the test.c file at line 12** | **Set a breakpoint in the test.c file at line 12** |
| (gdb) break test.c:12
Copy to clipboard | (lldb) breakpoint set --file test.c --line 12
(lldb) br s -f test.c -l 12
(lldb) b test.c:12
Copy to clipboard |
| **Set a breakpoint at all C++ methods whose base name is main** | **Set a breakpoint at all C++ methods whose base name is main** |
| (gdb) break main
(Hope that no C functions are named main)
Copy to clipboard | (lldb) breakpoint set --method main
(lldb) br s -M main
Copy to clipboard |
| **Set a breakpoint by a regular expression on the function name** | **Set a breakpoint by a regular expression on the function name** |
| (gdb) rbreak regular-expression
Copy to clipboard | (lldb) breakpoint set --func-regex regularexpression
(lldb) br s -r regular-expression
Copy to clipboard |
| **Ensure that breakpoints by file and line work for #included .c/.cpp/.m files** | **Ensure that breakpoints by file and line work for #included .c/.cpp/.m files** |
| (gdb) b foo.c:12
Copy to clipboard | (lldb) settings set target.inline-breakpointstrategy always
(lldb) br s -f foo.c -l 12
Copy to clipboard |
| **Set a breakpoint by a regular expression on the source file contents** | **Set a breakpoint by a regular expression on the source file contents** |
| (gdb) shell grep -e -n pattern sourcefile
(gdb) break source-file:CopyLineNumbers
Copy to clipboard | (lldb) breakpoint set --source-pattern
regular-expression --file SourceFile
(lldb) br s -p regular-expression -f file
Copy to clipboard |
| **Set a conditional breakpoint** | **Set a conditional breakpoint** |
| (gdb) break foo if strcmp(y,"hello") == 0
Copy to clipboard | (lldb) breakpoint set --name foo --condition (int)strcmp(y,"hello") == 0
(lldb) br s -n foo -c '(int)strcmp(y,"hello") == 0'
Copy to clipboard |
| **List all breakpoints** | **List all breakpoints** |
| (gdb) info break
Copy to clipboard | (lldb) breakpoint list
(lldb) br l
Copy to clipboard |
| **Delete a breakpoint** | **Delete a breakpoint** |
| (gdb) delete 1 (lldb) breakpoint delete 1
Copy to clipboard | (lldb) br del 1
Copy to clipboard |
### Watchpoint commands
| **GDB** | **LLDB** |
| --- | --- |
| **Set a watchpoint on a variable when it is written to** | **Set a watchpoint on a variable when it is written to** |
| (gdb) watch global_var
Copy to clipboard | (lldb) watchpoint set variable global_var
(lldb) wa s v global_var
Copy to clipboard |
| **Set a watchpoint on a memory location when it is written to** | **Set a watchpoint on a memory location when it is written to** |
| (gdb) watch -location g_char_ptr
Copy to clipboard | (lldb) watchpoint set expression -- my_ptr
(lldb) wa s e -- my_ptr
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.
Copy to clipboard |
| **Set a condition on a watchpoint** | **Set a condition on a watchpoint** |
| N/A
Copy to clipboard | (lldb) watch set var global
(lldb) watchpoint modify -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) frame var global
(int32_t) global = 5
Copy to clipboard |
| **List all watchpoints** | **List all watchpoints** |
| (gdb) info break
Copy to clipboard | (lldb) watchpoint list
(lldb) watch l
Copy to clipboard |
| **Delete a watchpoint** | **Delete a watchpoint** |
| (gdb) delete 1
Copy to clipboard | (lldb) watchpoint delete 1
(lldb) watch del 1
Copy to clipboard |
### Examine the variables
| **GDB** | **LLDB** |
| --- | --- |
| **Show arguments and local variables for the current frame** | **Show arguments and local variables for the current frame** |
| (gdb) info args
And:
(gdb) info locals
Copy to clipboard | (lldb) frame variable
(lldb) fr v
Copy to clipboard |
| **Show the local variables for the current frame]** | **Show the local variables for the current frame]** |
| (gdb) info locals
Copy to clipboard | (lldb) frame variable --no-args
(lldb) fr v -a
Copy to clipboard |
| **Show the contents of the bar local variable** | **Show the contents of the bar local variable** |
| (gdb) p bar
Copy to clipboard | (lldb) frame variable bar
(lldb) fr v bar
(lldb) p bar
Copy to clipboard |
| **Show contents of the bar local variable formatted as hex** | **Show contents of the bar local variable formatted as hex** |
| (gdb) p/x bar
Copy to clipboard | (lldb) frame variable --format x bar
(lldb) fr v -f x bar
Copy to clipboard |
| **Show the contents of the baz global variable** | **Show the contents of the baz global variable** |
| (gdb) p baz
Copy to clipboard | (lldb) target variable baz
(lldb) ta v baz
Copy to clipboard |
| **Show the global/static variables defined in the current source file** | **Show the global/static variables defined in the current source file** |
| N/A
Copy to clipboard | (lldb) target variable
(lldb) ta v
Copy to clipboard |
| **Display the argc and argv variables every time you stop** | **Display the argc and argv variables every time you stop** |
| (gdb) display argc
(gdb) display argv
Copy to clipboard | (lldb) target stop-hook add --one-liner "frame variable argc argv"
(lldb) ta st a -o "fr v argc argv"
(lldb) display argc
(lldb) display argv
Copy to clipboard |
| **Display the argc and argv variables only when you stop in the main function** | **Display the argc and argv variables only when you stop in the main function** |
| N/A
Copy to clipboard | (lldb) target stop-hook add --name main --one- liner "frame variable argc argv"
(lldb) ta st a -n main -o "fr v argc argv"
Copy to clipboard |
| **Display the \*this variable only when you stop in the MyClass C class** | **Display the \*this variable only when you stop in the MyClass C class** |
| N/A
Copy to clipboard | (lldb) target stop-hook add --classname MyClass --one-liner "frame variable *this"
(lldb) ta st a -c MyClass -o "fr v *this"
Copy to clipboard |
### Evaluate the expressions
| **GDB** | **LLDB** |
| --- | --- |
| **Evaluate a generalized expression in the current frame** | **Evaluate a generalized expression in the current frame** |
| (gdb) print (int) printf ("Print nine: %d.", 4 + 5)
Or, if you do not want to see void returns:
(gdb) call (int) printf ("Print nine: %d.", 4 + 5)
Copy to clipboard | (lldb) expr (int) printf ("Print nine: %d.", 4 + 5)
Or, using the print alias:
(lldb) print (int) printf ("Print nine: %d.", 4 + 5)
Copy to clipboard |
| **Create and assign a value to the convenience variable** | **Create and assign a value to the convenience variable** |
| (gdb) set $foo = 5
(gdb) set variable $foo = 5
Or, using the print command:
(gdb) print $foo = 5
Or, using the call command
(gdb) call $foo = 5
To specify the type of the variable:
(gdb) set $foo = (unsigned int) 5
Copy to clipboard | In LLDB, evaluate a variable declaration expression as you would write it in C:
(lldb) expr unsigned int $foo = 5
Copy to clipboard |
| **Print the dynamic type of the result of an expression** | **Print the dynamic type of the result of an expression** |
| (gdb) set print object 1
(gdb) p someCPPObjectPtrOrReference
.. note:: Only works for C++ objects
Copy to clipboard | (lldb) expr -d 1 -- [SomeClass returnAnObject]
(lldb) expr -d 1 -- someCPPObjectPtrOrReference
Or, set dynamic type printing to be the default:
(lldb) settings set target.prefer-dynamic runtarget
Copy to clipboard |
| **Call a function so you can stop at a breakpoint in the function** | **Call a function so you can stop at a breakpoint in the function** |
| (gdb) set unwindonsignal 0
(gdb) p function_with_a_breakpoint()
Copy to clipboard | (lldb) expr -i 0 --function_with_a_breakpoint()
Copy to clipboard |
| **Call a function that crashes, and stop when the function crashes** | **Call a function that crashes, and stop when the function crashes** |
| (gdb) set unwindonsignal 0
(gdb) p function_which_crashes()
Copy to clipboard | (lldb) expr -u 0 -- function_which_crashes()
Copy to clipboard |
### Examine the thread state
| **GDB** | **LLDB** |
| --- | --- |
| **Show the stack backtrace for the current thread** | **Show the stack backtrace for the current thread** |
| (gdb) bt
Copy to clipboard | (lldb) thread backtrace
(lldb) bt
Copy to clipboard |
| **Show the stack backtraces for all threads** | **Show the stack backtraces for all threads** |
| (gdb) thread apply all bt
Copy to clipboard | (lldb) thread backtrace all
(lldb) bt all
Copy to clipboard |
| **Backtrace the first five frames of the current thread** | **Backtrace the first five frames of the current thread** |
| (gdb) bt 5
Copy to clipboard | (lldb) thread backtrace -c 5
(lldb) bt 5 (lldb-169 and later)
(lldb) bt -c 5 (lldb-168 and earlier)
Copy to clipboard |
| **Select a different stack frame by index for the current thread** | **Select a different stack frame by index for the current thread** |
| (gdb) frame 12
Copy to clipboard | (lldb) frame select 12
(lldb) fr s 12
(lldb) f 12
Copy to clipboard |
| **List information about the currently selected frame in the current thread** | **List information about the currently selected frame in the current thread** |
| N/A
Copy to clipboard | (lldb) frame info
Copy to clipboard |
| **Select the stack frame that called the current stack frame** | **Select the stack frame that called the current stack frame** |
| (gdb) up
Copy to clipboard | (lldb) up
(lldb) frame select --relative=1
Copy to clipboard |
| **Select the stack frame that is called by the current stack frame** | **Select the stack frame that is called by the current stack frame** |
| (gdb) down
Copy to clipboard | (lldb) down
(lldb) frame select --relative=-1
(lldb) fr s -r-1
Copy to clipboard |
| **Select a different stack frame using relative offset** | **Select a different stack frame using relative offset** |
| (gdb) up 2
(gdb) down 3
Copy to clipboard | (lldb) frame select --relative 2
(lldb) fr s -r2
(lldb) frame select --relative -3
(lldb) fr s -r-3
Copy to clipboard |
| **Show the general purpose registers for the current thread** | **Show the general purpose registers for the current thread** |
| (gdb) info registers
Copy to clipboard | (lldb) register read
Copy to clipboard |
| **Write a new decimal value 123 to the current rax thread register** | **Write a new decimal value 123 to the current rax thread register** |
| (gdb) p $rax = 123
Copy to clipboard | (lldb) register write rax 123
Copy to clipboard |
| **Skip 8 bytes ahead of the current program counter (instruction pointer)** | **Skip 8 bytes ahead of the current program counter (instruction pointer)** |
| (gdb) jump *$pc+8
Copy to clipboard | (lldb) register write pc `$pc+8`
.. note:: Use backticks to evaluate an expression and insert the scalar result in the LLDB.
Copy to clipboard |
| **Show the general purpose registers for the current thread, formatted as signed decimal** | **Show the general purpose registers for the current thread, formatted as signed decimal** |
| N/A
Copy to clipboard | LLDB tries to use the same format characters as printf(3) when possible. Enter help format to see a full list of format specifiers:
(lldb) register read --format i
(lldb) re r -f i
LLDB now supports the GDB shorthand format syntax, but no space can appear after the command:
(lldb) register read/d
Copy to clipboard |
| **Show all registers in all register sets for the current thread** | **Show all registers in all register sets for the current thread** |
| (gdb) info all-registers
Copy to clipboard | (lldb) register read --all
(lldb) re r -a
Copy to clipboard |
| **Show values for the rax, rsp, and rbp registers in the current thread** | **Show values for the rax, rsp, and rbp registers in the current thread** |
| (gdb) info all-registers rax rsp rbp
Copy to clipboard | (lldb) register read rax rsp rbp
Copy to clipboard |
| **Show values for the rax register in the current thread, formatted as binary** | **Show values for the rax register in the current thread, formatted as binary** |
| (gdb) p/t $rax
Copy to clipboard | (lldb) register read --format binary rax
(lldb) re r -f b rax
LLDB now supports the GDB shorthand format syntax but no space can appear after the command:
(lldb) register read/t rax
(lldb) p/t $rax
Copy to clipboard |
| **Show values for the rax vector register in the current thread, formatted as data array** | **Show values for the rax vector register in the current thread, formatted as data array** |
| N/A
Copy to clipboard | (lldb) pv8 rax (8-bit array)
(lldb) pv16 rax (16-bit array)
(lldb) pv32 rax (32-bit array)
Copy to clipboard |
| **Show values for tlb in the current thread** | **Show values for tlb in the current thread** |
| (gdb) info tlb
Copy to clipboard | (lldb) get tlb info
Copy to clipboard |
| **Show values for pagetable in the current thread** | **Show values for pagetable in the current thread** |
| (gdb) info pagetable
Copy to clipboard | (lldb) get pagetable info
Copy to clipboard |
| **Read memory from address 0xbffff3c0 and show 4 hex uint32\_t values** | **Read memory from address 0xbffff3c0 and show 4 hex uint32\_t values** |
| (gdb) x/4xw 0xbffff3c0
Copy to clipboard | (lldb) memory read --size 4 --format x --count 4 0xbffff3c0
(lldb) me r -s4 -fx -c4 0xbffff3c0
(lldb) x -s4 -fx -c4 0xbffff3c0
LLDB now supports the GDB shorthand format syntax but no space can appear after the command:
(lldb) memory read/4xw 0xbffff3c0
(lldb) x/4xw 0xbffff3c0
(lldb) memory read --gdb-format 4xw 0xbffff3c0
Copy to clipboard |
| **Read memory starting at expression argv[0]** | **Read memory starting at expression argv[0]** |
| (gdb) x argv[0]
Copy to clipboard | (lldb) memory read `argv[0]`
Any command can inline a scalar expression result (if the target is stopped) by using backticks around any expression:
(lldb) memory read --size `sizeof(int)` `argv[0]`
Copy to clipboard |
| **Read 512 bytes of memory from address 0xbffff3c0 and save the results to a local file as text** | **Read 512 bytes of memory from address 0xbffff3c0 and save the results to a local file as text** |
| (gdb) set logging on
(gdb) set logging file /tmp/mem.txt
(gdb) x/512bx 0xbffff3c0
(gdb) set logging off
Copy to clipboard | (lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0
(lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0
(lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0
Copy to clipboard |
| **Save binary memory data starting at 0x1000 and ending at 0x2000 to a file** | **Save binary memory data starting at 0x1000 and ending at 0x2000 to a file** |
| (gdb) dump memory /tmp/mem.bin 0x10000x2000
Copy to clipboard | (lldb) memory read --outfile /tmp/mem.bin --binary 0x1000 0x2000
(lldb) me r -o /tmp/mem.bin -b 0x1000 0x2000
Copy to clipboard |
| **Disassemble the current function for the current frame** | **Disassemble the current function for the current frame** |
| (gdb) disassemble
Copy to clipboard | (lldb) disassemble --frame
(lldb) di -f
Copy to clipboard |
| **Disassemble any functions named main** | **Disassemble any functions named main** |
| (gdb) disassemble main
Copy to clipboard | (lldb) disassemble --name main
(lldb) di -n main
Copy to clipboard |
| **Disassemble an address range** | **Disassemble an address range** |
| (gdb) disassemble 0x1eb8 0x1ec3
Copy to clipboard | (lldb) disassemble --start-address 0x1eb8 --end-address 0x1ec3
(lldb) di -s 0x1eb8 -e 0x1ec3
Copy to clipboard |
| **Disassemble 20 instructions from a given address** | **Disassemble 20 instructions from a given address** |
| (gdb) x/20i 0x1eb8
Copy to clipboard | (lldb) disassemble --start-address 0x1eb8 --count 20
(lldb) di -s 0x1eb8 -c 20
Copy to clipboard |
| **Show mixed source and disassembly for the current function for the current frame** | **Show mixed source and disassembly for the current function for the current frame** |
| N/A
Copy to clipboard | (lldb) disassemble --frame --mixed
(lldb) di -f -m
Copy to clipboard |
| **Disassemble the current function for the current frame and show the opcode bytes** | **Disassemble the current function for the current frame and show the opcode bytes** |
| N/A
Copy to clipboard | (lldb) disassemble --frame --bytes
(lldb) di -f -b
Copy to clipboard |
| **Disassemble the current source line for the current frame** | **Disassemble the current source line for the current frame** |
| N/A
Copy to clipboard | (lldb) disassemble --line
(lldb) di -l
Copy to clipboard |
### Executable and shared library query commands
| **GDB** | **LLDB** |
| --- | --- |
| **List the main executable and all dependent shared libraries** | **List the main executable and all dependent shared libraries** |
| (gdb) info shared
Copy to clipboard | (lldb) image list
Copy to clipboard |
| **Look up information for the raw address in the executable or any shared libraries** | **Look up information for the raw address in the executable or any shared libraries** |
| (gdb) info symbol 0x1ec4
Copy to clipboard | (lldb) image lookup --address 0x1ec4
(lldb) im loo -a 0x1ec4
Copy to clipboard |
| **Look up functions matching the regular expression in a binary** | **Look up functions matching the regular expression in a binary** |
| (gdb) info function
Copy to clipboard | This command finds debug symbols:
(lldb) image lookup -r -n
This command finds non-debug symbols:
(lldb) image lookup -r -s
Provide a list of binaries as arguments to limit the search.
Copy to clipboard |
| **Find full source line information** | **Find full source line information** |
| (gdb) info line 0x1ec4 This command is a bit messy, currently. Enter:
Copy to clipboard | (lldb) image lookup -v --address 0x1ec4
Look for the LineEntry line, which will have the full source path and line range information.
Copy to clipboard |
| **Look up information for an address in a.out only** | **Look up information for an address in a.out only** |
| N/A
Copy to clipboard | (lldb) image lookup --address 0x1ec4 a.out
(lldb) im loo -a 0x1ec4 a.out
Copy to clipboard |
| **Look up information for a type Point by name** | **Look up information for a type Point by name** |
| (gdb) ptype Point
Copy to clipboard | (lldb) image lookup --type Point
(lldb) im loo -t Point
Copy to clipboard |
| **Dump all sections from the main executable and any shared libraries** | **Dump all sections from the main executable and any shared libraries** |
| (gdb) maintenance info sections
Copy to clipboard | (lldb) image dump sections
Copy to clipboard |
| **Dump all sections in module a.out** | **Dump all sections in module a.out** |
| N/A
Copy to clipboard | (lldb) image dump sections a.out
Copy to clipboard |
| **Dump all symbols from the main executable and any shared libraries** | **Dump all symbols from the main executable and any shared libraries** |
| N/A
Copy to clipboard | (lldb) image dump symtab
Copy to clipboard |
| **Dump all symbols in a.out and liba.so** | **Dump all symbols in a.out and liba.so** |
| N/A
Copy to clipboard | (lldb) image dump symtab a.out liba.so
Copy to clipboard |
### Miscellaneous commands
| **GDB** | **LLDB** |
| --- | --- |
| **Echo text to the screen** | **Echo text to the screen** |
| (gdb) echo Here is some text
Copy to clipboard | (lldb) script print "Here is some text"
Copy to clipboard |
| **Remap the source file pathnames for the debug session** | **Remap the source file pathnames for the debug session** |
| (gdb) set pathname-substitutions /buildbot/path /my/path
Copy to clipboard | (lldb) settings set target.source-map /buildbot/path /my/path
If your source files are no longer in the same location as when the program was built (typically because the program was built on a different computer), LLDB must know how to find the sources at their local file path instead of the build system’s file path.
Copy to clipboard |
| **Supply a catchall directory to search for source files in** | **Supply a catchall directory to search for source files in** |
| (gdb) directory /my/path
Copy to clipboard | No equivalent command; use the source-map instead.
Copy to clipboard |
Last Published: Oct 06, 2026
[Previous Topic
Examine the stack frame state](https://docs.qualcomm.com/bundle/publicresource/80-N2040-31/topics/lldb-debugger-get-started.md) [Next Topic
Frame and thread formatting](https://docs.qualcomm.com/bundle/publicresource/80-N2040-31/topics/frame-and-thread-formatting.md)
Source: [https://docs.qualcomm.com/doc/80-N2040-31/topic/use-the-debugger.html](https://docs.qualcomm.com/doc/80-N2040-31/topic/use-the-debugger.html)