Performing a Debug Session - 2020.2 English

PetaLinux Tools Documentation Reference Guide (UG1144)

Document ID
UG1144
Release Date
2020-11-24
Version
2020.2 English
  1. Boot your board (or QEMU) with the new image created above.
  2. Run gdbserver with the user application on the target system console (set to listening on port 1534):
    root@plnx_aarch64:~# gdbserver host:1534 /usr/bin/myapp
    Process /bin/myapp created; pid = 73
    Listening on port 1534

    1534 is the gdbserver port - it can be any unused port number

  3. On the workstation, navigate to the compiled user application’s directory:
    $ cd <<TMPDIR>/work/aarch64-xilinx-linux/myapp1/1.0-r0/image/usr/bin/myapp
    
  4. Run GDB client.
    $ petalinux-util --gdb myapp

    The GDB console starts:

    ...
    GNU gdb (crosstool-NG 1.18.0) 7.6.0.20130721-cvs
    ...
    (gdb)
  5. In the GDB console, connect to the target machine using the command:
    • Use the IP address of the target system, for example: 192.168.0.10. If you are not sure about the IP address, run ifconfig on the target console to check.
    • Use the port 1534. If you select a different GDB server port number in the earlier step, use that value instead.
    Important: If debugging on QEMU, refer to the QEMU Virtual Networking Modes for information regarding IP and port redirection when testing in non-root (default) or root mode. For example, if testing in non-root mode, you should use localhost as the target IP in the subsequent steps.
    (gdb) target remote 192.168.0.10:1534

    The GDB console attaches to the remote target. The GDB server on the target console displays the following confirmation, where the host IP is displayed:

    Remote Debugging from host 192.168.0.9
  6. Before starting the execution of the program, create some breakpoints. Using the GDB console you can create breakpoints throughout your code using function names and line numbers. For example, create a breakpoint for the main function:
    (gdb) break main
    Breakpoint 1 at 0x10000444: file myapp.c, line 10.
  7. Run the program by executing the continue command in the GDB console. GDB begins the execution of the program.
    (gdb) continue
    Continuing.
    Breakpoint 1, main (argc=1, argv=0xbffffe64) at myapp.c:10
    10  printf("Hello, PetaLinux World!\n");
  8. To print a list of the code at current program location, use the list command.
    (gdb) list
    5 */
    6 #include <stdio.h>
    7
    8 int main(int argc, char *argv[])
    9 {
    10 printf("Hello, PetaLinux World!\n");
    11 printf("cmdline args:\n");
    12 while(argc--)
    13 printf("%s\n",*argv++);
    14
  9. Try the step, next and continue commands. Breakpoints can be set and removed using the break command. More information on the commands can be obtained using the GDB console help command.
  10. The GDB server application on the target system exits when the program has finished running. Here is an example of messages shown on the console:
    Hello, PetaLinux World!
    cmdline args:
    /usr/bin/myapp
    Child exited with status 0
    GDBserver exiting
    root@plnx_aarch64:~#
Tip: A .gdbinit file is automatically created to setup paths to libraries. You may add your own GDB initialization commands at the end of this file.