Debugger (GNU)
Syntax:
gdb_variant [options] [executable] [ core_file | pid ]
gdb_variant [options] set args executable [ inferior-arguments ...]
where gdb_variant depends on the target platform, as follows:
Target platform |
gdb_variant |
ARMv7 |
ntoarmv7-gdb |
AArch64 |
ntoaarch64-gdb |
x86 64-bit |
ntox86_64-gdb |
Runs on:
Linux, Mac, Microsoft Windows
Description:
Invoke the GNU Debugger by running gdb. Once started,
gdb reads commands from the terminal until you tell it to exit.
Note:
- GDB parses the ~/.gdbinit file if it exists.
An existing configuration for the development host may cause conflicts.
-
QEMU doesn't emulate the DBGAUTHSTATUS register on ARMLE-v7 virtual machines,
so when gdb tries to access it, an exception occurs, and the kernel crashes.
-
GDB only supports up to 100 environment variables. If additional arguments are provided, they are dropped.
For more information about GDB, see
https://www.gnu.org/software/gdb/documentation/.
QNX Neutrino extensions
The QNX Neutrino implementation of GDB includes some extensions:
- target qnx com_port_specifier | host:port
- Specify the target to use.
Note:
The
devc-pty manager must be running on the machine that's
running
pdebug
or
qconn,
and a ptyp/ttyp pair must be available.
- set nto-executable path_on_target
- Point GDB at an existing remote executable. You can do this instead of uploading a copy to the
target. For example, to debug echo on the target you can start
gdb on the host, and then point it to the target executable:
# ntoaarch64-gdb $QNX_TARGET/aarch64le/bin/echo
(gdb) set nto-executable /bin/echo
(gdb) run hello
Note: The upload command implicitly sets the nto-executable value.
This behavior can be controlled with the option upload-sets-exec.
- set nto-inherit-env value
- Set where the remote process inherits its environment from, based on the value argument:
- 0 — the process inherits its environment from GDB.
- 1 (the default) — the process inherits its environment from pdebug.
In this case, you can't set LD_LIBRARY_PATH through gdb.
The env command works but it doesn't have an effect.
Note:
The QNX Neutrino implementation of GDB only supports up to 100 environment variables and any additional environment
variables are dropped without warning. This is important to note because running pdebug in debug mode uses over 100
environment variables and generates a terminal message that says, incorrectly, that the target has run out of memory.
The real issue is that the limit on the number of environment variables was exceeded.
- set nto-cwd path
- Specify the remote process's working directory. You should do this
before starting your program.
- set nto-debug
-
Provides debug-specific information when given a positive non-zero value.
Different information is displayed for various positive non-zero values.
- set nto-stop-on-thread-events stop
- Stop on thread events.
When stop is 1, gdb stops on thread created and
thread destroyed events. The default is 0 (disabled).
- set nto-timeout time
- If your communication line is slow, you might need to set the timeout for remote reads;
time is the timeout, in seconds.
The default is 10 seconds.
- upload local_path remote_path
- Send a file to a remote target system.
- upload-sets-exec
-
A flag that controls if nto-executable is set by using upload.
- download remote_path local_path
- Retrieve a file from a remote target system.
- info pidlist
- List processes on the target. You can use an optional argument to filter out process names that do not contain an argument string (case insensitive).
For example, running it in the GDB console with pdebug as its argument generates the following output:
(gdb) info pidlist pdebug
usr/bin/pdebug - 872540/1
Running it in the GDB console with slog as its argument generates the following output:
(gdb) info pidlist slog
proc/boot/slogger2 - 12296/1
You can also use
pidin
or
ps
on the target system to get this information.
- info meminfo
- Display a list of memory-region mappings (shared objects) for the current
process being debugged.
Here is sample output from running it on the GDB console:
(gdb) info meminfo
/proc/boot/libc.so.4
text=00053000 bytes @ 0x01000000
flags=00010571
debug=00000000
offset=00000000002b1000
data=00002000 bytes @ 0x010af000
flags=00010372
debug=000af000
offset=0000000000350000
dev=0x802
ino=0x80000010
/dev/zero
text=00010000 bytes @ 0x0109b000
flags=080800a2
debug=0109b000
offset=000000000009b000
data=00009000 bytes @ 0x100db000
flags=01080302
debug=100db000
offset=0000000000000000
dev=0x1
ino=0x3
/usr/bin/sleep
text=00001000 bytes @ 0x100c8000
flags=00010572
debug=00000000
offset=0000000006275000
data=00001000 bytes @ 0x100da000
flags=00010332
debug=00012000
offset=0000000006277000
dev=0x802
ino=0x80001786
- info tidinfo
-
Displays the threads for the current process.
For example, when run against a process with a pid of 884827 it outputs:
(gdb) info tidinfo
Threads for pid 884827 (/bins/sleep)
Tid: State: Flags:
*1 3 131
A quick overview of starting the debugger
To debug an application, do the following:
- Start GDB, optionally the application as an argument:
gdb_variant
or:
gdb_variant local_path/my_application
- If you didn't specify the application when you started GDB, load the symbol information for the application:
file my_application
- Set the target:
target qnx com_port_specifier | host:port
- Send the application to the target:
upload my_application /tmp/my_application
- Set any breakpoints.
For example, to set a breakpoint in main():
set break main
- Start the application:
run
To remote start and debug a binary with GDB, do the following:
-
Start GDB using env-i and setting the target:
env -i \
QNX_TARGET=${QNX_TARGET} \
ntoaarch64-gdb \
target qnx target_ip:port \
-
To search for symbols, manually set solib-search-path:
set solib-search-path /host/symbol/search/path:/path2/
-
At this point, if you choose to not inherit the enviroment from pdebug or qconn, the environment variables to apply on the target need to be set manually. For example:
set nto-inherit-env 0
unset environment QNX_TARGET
set environment PATH=/proc/boot:/bin:/usr/bin:/sbin:/usr/sbin
set environment LD_LIBRARY_PATH=/proc/boot:/lib:/usr/lib
set environment BOARD_SHUTDOWN_DLL=libshutdown.so
set environment GRAPHICS_ROOT=/usr/lib/graphics/...
file /host/path/to/executable/symbol/file
-
Lastly, set the nto-executable:
set nto-executable /target/path/to/execuable
-
Start the application:
run arg1 arg2