gdbserver

QNX SDP8.0Utilities ReferenceUtilities

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).

Warning:
The gdbserver remote debugger doesn't have any built-in security.

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.

As mentioned on https://sourceware.org/gdb/current/onlinedocs/gdb.html/Server.html, use the following syntax to start the communication between the server and the GDB:
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:
    target> gdbserver /dev/com1 emacs foo.txt
    The /dev/com1 device name is a serial port to debug emacs using the foo.txt argument.
  • Using a TCP connection:
    target> gdbserver host:2345 emacs foo.txt
    The host:2345 argument means that gdbserver expects a TCP connection from the host machine to the local TCP port 2345.
    Note:
    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.

    (gdb) target remote | ssh -T hostname gdbserver - hello
    The -T option to ssh specifies that you don’t need a remote pseudo-terminal (pty) or escape-character handling.

Connecting to a GDB Server

To connect to the remote target, follow these steps:
  1. Run GDB on the host system.
  2. Load the necessary symbols for your application using the file command. Use the set sysroot command to locate the target libraries, which are typically the same as $QNX_TARGET.
  3. Connect to your target. For the TCP connections, make sure to restart the gdbserver remote debugger before using the target command. Otherwise, you may get a connection error.
    Note:
    Don’t use the load command 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.

Note:

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.

If gdbserver is available on the target and on the path, use the following command to start the debugging:
target remote | ssh -T hostname gdbserver - hello
If the debugger is not available on the path, pass the absolute path to the ssh command.

Contributing author:

Sourceware

Page updated: