Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title How to use GDB to debug a process
Ref. No. QNX.000009464
Category(ies) Utilities, Development
Issue Is there a technote available that outlines the steps involved in debugging a QNX Neutrino process using GDB?


Solution Using GDB
=========

The '-g' option to gcc/qcc must be used in compiling an
application for debugging purposes.

The current supported method for using gdb is with two separate
machines.  One QNX 4 host machine, and one QNX Neutrino target
machine.  The machines can be connected with either TCP/IP or a
direct serial connection.

On the QNX Neutrino machine devc-pty must be running, and
pdebug must be available to run, either on a mounted filesystem
or built into the boot image.

There are 6 basic steps to using gdb:

1. run pdebug on Neutrino
2. run gdb on QNX4
3. load symbols under gdb
4. establish a connection
5. launch/attach to binary to be debugged
6. debug process


1. Running pdebug on Neutrino
  ==========================

In order to launch pdebug, it must be available to run.  This can be
done on a hard drive or a NFS mount point.  If access to a filesystem
on the QNX Neutrino machine is not available, pdebug must be built into
the boot image.

Both pdebug and gdb have to agree on the connection type, either TCP/IP
or direct serial. (at this time, baud rates greater than 57600 are not
recommended, especially for slow NTO targets).

For a TCP/IP connection:
    pdebug <port> &

For a Direct Serial connection:
    pdebug /dev/serN<,baudrate> &

If the baudrate is not set on the command line, it defaults to 57600.

2. Running GDB on QNX 4
  ====================

The QNX 4 hosted gdb's are found in /usr/gcc/bin:

- ntox86 target : i386-qnx-gdb
- ntoppc target : powerpc-nto-gdb
- ntomips target: mips-nto-gdb

Select the appropriate Neutrino target (e.g. x86), and run
the binary:
                /usr/gcc/bin/i386-qnx-gdb

*note:  If using a direct serial connection, the baud rate on the QNX 4
machine must be set using the stty utility.
                stty baud=<baud> < /dev/serX


3. Loading Symbol Information
  ==========================

Now that gdb is running on the QNX 4 host, the symbol information from
the binary needs to be loaded:

        symbol-file <path>/binaryname

If gdb and pdebug have the same path to the binary, the 'file' command can
be used to load the symbol information and set the path to the binary.

        file <path>/binaryname


4. Establish a Connection
  ======================

To establish a direct serial connection, at the gdb prompt type:
        target qnx /dev/serN

To establish a TCP/IP connection, at the gdb prompt type:
        target qnx <IP>:<PORT>


5. Launch/Attach-to binary for debugging
  =====================================

Launching binary
----------------

If gdb and pdebug do not have the same path to the binary:

        run <pdebugpath>/binaryname args

If gdb and pdebug have the same path to the binary, the above
can be used, or substituted with:

        run args

If the binary does not exist on the Neutrino machine, it can be uploaded:

        upload <gdbpath>/binaryname <pdebugpath>/binaryname
        run <pdebugpath>/binaryname args

"/dev/shmem" is the easiest place to upload the binary to.  As well, the
gdb command "set qnxremotecwd <path>" can be used to shorten the path:

        set qnxremotecwd /my/really/long/path/to/the/binary/
        run ./binaryname args


Attaching to an already running process
---------------------------------------

If the PID of the running process is known, the following command can be used
to attach to it:

        attach <PID>

6. Debugging the Neutrino Process
  ==============================

At this point, there is a process in memory being executed on the Neutrino machine,
being controlled by pdebug in response to gdb messages.

The main commands at this point are:

        break    - breakpoint
        step    - step into
        next    - step over
        continue - continue execution
        detach  - detach from pdebug
        quit    - exit gdb


For more/detailed information see:
http://qdn.qnx.com/support/docs/neutrino_2.11_en/prog/using_gdb.html#id1