This how-to describes the process of debugging an application on the target with GDB.
Task Dependencies (Pre-requisites)
- GDB server on the target filesystem
- GDB client on the host
Input Files Required
Output Files Produced
Preparing for debug
GDB will need the application binary to contain debugging information. For this, the application needs to be compiled with the '-g' flag:
host> <toolchain>-gcc app.c -g -o app
The application binary needs to be copied over to the target filesystem. If the GDB server is not present on the target filesystem, gdbserver will also need to be compiled and transferred to the target filesystem. The instructions on the Add Files to Running Linux
page may be followed for this task.
The IP of the target machine will need to be used later:
Starting the debug server
In order to debug the application a GDB server must be run on the target machine. Execute the following command to start a GDB server for the given application:
zynq> chmod u+x app
zynq> gdbserver HOST:<port> app
The <port> used to connect to the GDB server may be set to 1234 (or any other free port).
Debugging the application
Now that the server is running a GDB client can connect to the server to perform debugging:
host> <toolchain>-gdb app
Once the GDB client is running instruct it to connect to a remote server:
Set a breakpoint on "main" and "cont"inue the application:At this point the host machine terminal should look similar to the following:
(gdb) target remote <IP of the target>:<port>
The next line of code can be run with the "next" or "n" command:
host> arm-xilinxa9-linux-gnueabi-gdb app
GNU gdb (Sourcery G++ Lite 2010.09-62) 126.96.36.19900908-cvs
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-xilinx-linux-gnueabi".
For bug reporting instructions, please see:
Reading symbols from /<path to>/app ...done.
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x400aa7a0 in ?? ()
(gdb) b main
Cannot access memory at address 0x0
Breakpoint 1 at 0x8434: file app.c, line 5.
warning: Could not load shared library symbols for 3 libraries, e.g. /lib/libgcc_s.so.1.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
Breakpoint 1, main () at app.c:5
5 printf("Hello World!\n");