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. GDB can also be used to run and debug programs with QEMU, a simulator that runs on your host system.
When starting GDB, give it the pathname to the program you want to debug as a command-line argument. For example, if you have built the factorial program as described in Section 4.1, “Building an Application”, enter:
> mips-sde-elf-gdb factorial
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
Sourcery CodeBench Lite includes the QEMU emulator. This is a program which runs on your host computer and allows you to run and debug MIPS ELF applications without target hardware.
To start and connect to the emulator from within GDB, use this command:
(gdb) target qemu
This starts QEMU with the appropriate options to emulate a bare-board target and accept the connection from GDB.
You can optionally pass an argument to specify the CPU that QEMU should emulate:
(gdb) target qemu cpu
The default is 24Kf
. Additional supported CPU
emulations include 4Kc
, 4Km
,
4KEcR1
,
4KEmR1
, 4KEc
, 4KEm
,
24Kc
, 34Kf
,
M14K
, and M14Kc
.
In order to use QEMU as a debugging target, you must build your program with a QEMU linker script. Refer to Section 5.5, “Supported Boards for MIPS ELF” for details. You must also compile your code with options that are consistent with the processor you specify when invoking QEMU.
The version of QEMU included with Sourcery CodeBench Lite for MIPS ELF is configured to run in system emulation mode only, and other QEMU features not documented here are not supported in Sourcery CodeBench Lite. For additional information about QEMU, visit the QEMU web site.
The Sourcery CodeBench Debug Sprite is a program that runs on the host system to support hardware debugging devices. You can use the Debug Sprite to run and debug programs on a target board without an operating system, or to debug an operating system kernel. See Chapter 6, “Sourcery CodeBench Debug Sprite” for detailed information about the supported devices.
You can start the Sprite directly from within GDB:
(gdb) target remote | mips-sde-elf-sprite arguments
Refer to Section 6.3, “Invoking Sourcery CodeBench Debug Sprite” for a full description of the Sprite arguments.
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.
Connecting to a bare-metal target or simulator from GDB does not cause your program to be loaded into target memory. You must do this explicitly from GDB after you connect:
(gdb) load
Alternatively, you can use third-party tools to load your application into flash memory before starting GDB.
To begin execution of your application, you should generally use the
continue
command:
(gdb) continue
However, you should use run
instead of
continue
to start your program if you used
target sim
to connect:
(gdb) run