Performing a Debug Session - 2023.2 English

PetaLinux Tools Documentation: Reference Guide (UG1144)

Document ID
UG1144
Release Date
2023-10-18
Version
2023.2 English
To perform a debug session, follow these steps:
  1. Boot your board (or QEMU) with the previously created new image.
  2. For the QEMU boot to redirect the host port, issue the following qemu-args.
    petalinux-boot --qemu --kernel --qemu-args "-net nic -net nic -net nic -net nic,netdev=gem3 -netdev user,id=gem3,hostfwd=tcp::1534-:1534"
    Note: Based on the gem number, provide the -net nic options. You can find the gem number in the <plnx-proj-root>/components/plnx_workspace/device-tree/device-tree/pcw.dtsi file.
  3. Run gdbserver with the user application on the target system console (set to listening on port 1534):
    root@plnx_aarch64:~# gdbserver :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

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

    The GDB console starts:

    ...
    GNU gdb (crosstool-NG 1.18.0) 7.6.0.20130721-cvs
    ...
    (gdb)
  6. 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 local host 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
  7. 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.
  8. 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");
  9. 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
  10. 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.
  11. 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 can add your own GDB initialization commands at the end of this file.