- Launch QEMU with the currently built Linux by running the
$ petalinux-boot --qemu --kernel
- Watch the QEMU console. You should see the details of the QEMU command. Get the GDB TCP port from -gdb tcp:<TCP_PORT>.
- Open another command console (ensuring the PetaLinux settings
script has been sourced), and change to the Linux directory:
$ cd "<plnx-proj-root>/images/linux"
- Start GDB on the vmlinux kernel image in command mode:
$ petalinux-util --gdb vmlinux
You should see the GDB prompt. For example:
GNU gdb (GDB) 8.3.1 Copyright (C) 2019 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=x86_64-oesdk-linux --target=aarch64-xilinx-elf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... vmlinux: No such file or directory. (gdb)
- Attach to the QEMU target in GDB by running the following GDB
(gdb) target remote :9000
- To let QEMU continue execution:
- You can use
Ctrl+Cto interrupt the kernel and get back the GDB prompt.
- You can set break points and run other GDB commands to debug the kernel.
If another process is using port 9000,
petalinux-bootattempts to use a different port. See the output of
petalinux-bootto determine what port was used. In the following example, port 9001 is used:
INFO: qemu-system-arm ... -gdb tcp::9001 ...
Tip: It may be helpful to enable kernel debugging in the kernel configuration menu ( ), so that kernel debug symbols are present in the image.