gdbserver
Remote server for the GNU debugger
Syntax:
gdbserver comm prog [args...]
gdbserver --attach comm pid
gdbserver --multi comm
Runs on:
QNX OS
Description:
The gdbserver remote debugger allows you to connect your program to a remote
GNU debugger (GDB) via the target extended-remote or target
remote commands (mentioned below in the Connecting to a GDB Server,
section).
For more information about GDB Server, refer to https://sourceware.org/gdb/current/onlinedocs/gdb.html/Server.html.
Running a GDB Server
To run the gdbserver remote debugger on the target system, you need a copy of the program you want to debug (including the required libraries). This server doesn't need a symbol table, as GDB handles all the symbols for the host system.
target> gdbserver comm program [ args … ]Here,
target> is the Target system. The comm variable is
either a device name (to use a serial line or port) or a TCP hostname and port number.- Using a serial
port:
The /dev/com1 device name is a serial port to debug emacs using the foo.txt argument.target> gdbserver /dev/com1 emacs foo.txt - Using a TCP
connection:
The host:2345 argument means that gdbserver expects a TCP connection from the host machine to the local TCP port 2345.target> gdbserver host:2345 emacs foo.txtNote:Choose a TCP port that isn't in use already on the target system (for example, port 23 is reserved for telnet). Make sure the port number in the host’s target remote command matches the port used by gdbserver on the target. - Using an SSH connection:
The stdio connection is useful when starting gdbserver with ssh.
The -T option to ssh specifies that you don’t need a remote pseudo-terminal (pty) or escape-character handling.(gdb) target remote | ssh -T hostname gdbserver - hello
Connecting to a GDB Server
- Run GDB on the host system.
- Load the necessary symbols for your application using the
filecommand. Use theset sysrootcommand to locate the target libraries, which are typically the same as $QNX_TARGET. - Connect to your target. For the TCP connections, make sure to restart the
gdbserver remote debugger before using the
targetcommand. Otherwise, you may get a connection error.Note:Don’t use theloadcommand in GDB when using target remote mode, as the program is already on the target.
For more information about target connections, refer to https://sourceware.org/gdb/current/onlinedocs/gdb.html/Connecting.html.
Monitor Commands for a GDB Server
Use the monitor command to send special requests to gdbserver. For the complete list, refer to https://sourceware.org/gdb/current/onlinedocs/gdb.html/Server.html.
GDB Server for QNX OS
The monitor set debug threads on option (gdb) and the --debug command line option (gdbserver) enable verbose and debug output for QNX-specific functionality within gdbserver.
GDB Server is similar to the process debugger of QNX (pdebug). Unlike pdebug, the gdbserver remote debugger for QNX uses the remote protocol (refer to https://sourceware.org/gdb/current/onlinedocs/gdb.html/Server.html) instead of the QNX protocol described in the gdb documentation. In addition, the qconn service doesn't start gdbserver automatically; you need to start it manually on a target.
Use the --multi option to start gdbserver as a part of a buildfile for the target on a particular port. GDB Server is then available via TCP on the chosen port.
target remote | ssh -T hostname gdbserver - helloIf
the debugger is not available on the path, pass the absolute path to the
ssh command.Contributing author:
Sourceware
