|
|
 |
Getting Started Guide
User mode debugging
Cross debugging with GDB
|
|
Cross debugging with GDB
To set up a cross debug session using GDB, it is necessary to run debugging tools both on the target Linux system and the host system.
-
On the target Linux system, the GDB debug server needs to be told how to receive communications from the host (which network socket to listen to), and which program to debug. The server is run with the command:
gdbserver localhost:<socket> <application> |
|
|
-
where <socket> is the TCP/IP port number to use (this should be chosen so as not to conflict with any other sockets in use) and <application> is the user mode program to be debugged. For example, to debug program /home/<user>/hello using socket 3278:
target% gdbserver localhost:3278 /home/<user>/hello Process application created: pid = 184 Listening on port 3278 |
|
|
Note: To support symbolic debugging the application must have been compiled with the -g option passed to the GNU compiler. This causes DWARF debugging information to be included in the executable to support the debugger. See the GDB documentation for details.
-
On the host Linux system, run the appropriate STLinux cross GDB program. For example (for the ST40 target), run sh4-linux-gdb, naming the program to be debugged so that GDB can access the DWARF symbolic debug information it contains.
-
Once the host debugger is running, connect to the gdbserver using the GDB target remote command:
target remote <targetip>:<socket> |
|
|
-
In this command <targetip> specifies the target name or IP address, and <socket> is the port number specified when gdbserver was started.
-
Using the example above, and supposing the target is at address 192.168.1.2:
host% sh4-linux-gdb /opt/STM/STLinux2.0/devkit/sh4/target/usr/home/<user>/hello GNU gdb 6.3 Copyright 2004 Free Software Foundation, Inc. ...................................................................... This GDB was configured as "--host=i686-pc-linux-gnu --target=sh4-linux"... (gdb) target remote 192.168.1.2:3278 Remote debugging using 192.168.1.2:3278 0x29558080 in ??() (gdb) |
|
|
-
Initially the program is stopped at its entry point in the C run-time library and so the first step to perform is to advance to main():
(gdb) break main Breakpoint 1 at 0x400656: file main.c, line 20. (gdb) continue Continuing. Breakpoint 1, main() at main.c:20 20 printf("Welcome to the application\n"); (gdb) |
|
|
The target can now be debugged in the same way as you would debug a native program on the host. It is not the purpose of this guide to provide a tutorial in debugging, instead the reader is referred to the extensive GDB documentation on the web for details.
To avoid entering these commands manually every time GDB is invoked, they can be automated by creating a GDB startup script file. When GDB is started, it looks for files named .gdbinit in the home directory of the user, and in the current directory, and runs them if they are found. The user can specify another startup script to be run, by starting GDB with the command line option -command=<script>.
|