You can run GDB, the GNU Debugger, on your host system to debug programs running remotely on a target board or system. You can also run and debug programs using the GDB simulator.
While this section explains the alternatives for using GDB to run and debug application programs, explaining the use of the GDB command-line interface is beyond the scope of this document. Please refer to the GDB manual for further instructions.
GDB includes a simulator that allows you to debug MIPS ELF applications without target hardware. To start and connect to the simulator from within GDB, use this command:
(gdb) target sim
From within GDB, you can connect to a running gdbserver or other debugging stub that uses the GDB remote protocol using:
(gdb) target remotehost
:port
where host
is the host name or IP address of the
machine the stub is running on, and port
is the
port number it is listening on for TCP connections.
Sourcery G++ Lite for MIPS ELF supports debugging with third-party simulators and hardware debug devices that implement the MDI (Microprocessor Debug Interface) API.
Before you can connect to a target using the MDI API,
you must tell GDB which shared library or DLL to load for your
simulator or device, and set up parameters to select your MDI target.
This can be done either by means of environment variables or
GDB commands. For example, you may want to put the GDB configuration
commands in your .gdbinit
file, which
is loaded automatically when you start GDB.
This section describes the basic MDI usage; refer to the documentation for your MDI simulator or debug device for details specific to that target. Note, in particular, that some MDI targets may require you to set up a configuration file and/or license in addition to the steps given here.
In order to tell GDB which MDI library to load, on Linux hosts you
should add the directory containing the shared library files
to your LD_LIBRARY_PATH
environment variable.
On Windows hosts, add the directory containing the DLLs to your
PATH
environment variable.
Then, either set the environment variable
GDBMDILIB
to the base name of the MDI library
before starting GDB, or select the library within GDB using the command:
(gdb) set mdi library name
To verify that your shared library configuration is correct, you can query it from GDB for the devices it supports:
(gdb) show mdi devices
Each device is identified by a target number and device number. You can select the values you want to use with the following GDB commands:
(gdb) set mdi targettargetnum
(gdb) set mdi devicedevicenum
Alternatively, you can set the environment variables
GDBMDITARGET
and GDBMDIDEVICE
.
At this point, you can establish a connection to the selected MDI device using:
(gdb) target mdi
Then you can load and run your program on the target.