Linux Debug infrastructure (Kernel debugging using KGDB)

Enabling KGDB with Petalinux

  • Pre-requisites
    • Petalinux environment (set the required environment set for petalinux)
    • Petalinux (source from Petalinux daily)
    • Petalinux project (create). petalinux-create -t project -s <hardware_specific.bsp>
    • $ petalinux-create -t kgdb -s /proj/petalinux/2018.3/petalinux-v2018.3_daily_latest/bsp/release/xilinx-zcu102-v2018.3-final.bsp

  • Modifying Linux-kernel This step is to enable Kernel-configs for KGDB (module can be enabled by selecting that module and pressing ‘y’)
    • To configure kernel use Petalinux-config. This will open kernel menu-config.
    • $ petalinux-config -c kernel

check project-spec/meta-user/recipes-kernel/linux/linux-xlnx/user_xx.cfg for following configs-

    • CONFIG_CONSOLE_POLL=y
    • CONFIG_KGDB=y
    • CONFIG_KGDB_SERIAL_CONSOLE=y
  • Building Project the boot images. To build the project use petalinux-build
      • $ petalinux-build

Working with ARM-DCC

  • On development hardware-
    • Boot the hardware
    • select the console for debugging. echo ttyPS0 > /sys/module/kgdboc/parameters/kgdboc. Following logs should show up-

      • [   60.352486] KGDB: Registered I/O driver kgdboc
      • [   60.372279] KGDB: Waiting for connection from remote gdb...
  • On host PC-
    • change to the images directory of the project. cd images/linux/. locate vmlinux binary
    • launch gdb with vmlinux
    • aarch64-linux-gnu-gdb -b 115200 ./vmlinux
    • Once gdb prompt is up. select the host-remote tty interface. 
    • target remote /dev/ttyUSB0
    • Once connection is established, carry on with debugging. Set breakpoints, run kernel etc..


root@xhdkperepu40:/work/dmaEXP/uartPs1/images/linux# aarch64-linux-gnu-gdb -b 115200 ./vmlinux
GNU gdb (Linaro GDB 2018.04) 8.0.50.20171128-git
Copyright (C) 2017 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-unknown-linux-gnu --target=aarch64-linux-gnu".
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"...
Reading symbols from ./vmlinux...done.
(gdb)
(gdb)
(gdb) target remote /dev/ttyUSB0
Remote debugging using /dev/ttyUSB0
arch_kgdb_breakpoint () at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/arch/arm64/include/asm/kgdb.h:32
32  asm ("brk %0" : : "I" (KGDB_COMPILED_DBG_BRK_IMM));
(gdb)
(gdb)
(gdb) break addrconf_notify
Breakpoint 1 at 0xffffff80088abb40: file /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/ipv6/addrconf.c, line 3352.
(gdb) continue
Continuing.
[Switching to Thread 2376]
Thread 86 "" hit Breakpoint 1, addrconf_notify (this=0xffffff8008e2f398, event=4, ptr=0xffffff800d543d30) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/ipv6/addrconf.c:3352
3352 {
(gdb)
Continuing.
Thread 86 "" hit Breakpoint 1, addrconf_notify (this=0xffffff8008e2f398, event=4, ptr=0xffffff800d543d30) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/ipv6/addrconf.c:3352
3352 {
(gdb) list
3347  write_unlock_bh(&idev->lock);
3348 }
3349
3350 static int addrconf_notify(struct notifier_block *this, unsigned long event,
3351       void *ptr)
3352 {
3353  struct net_device *dev = netdev_notifier_info_to_dev(ptr);
3354  struct netdev_notifier_changeupper_info *info;
3355  struct inet6_dev *idev = __in6_dev_get(dev);
3356  struct net *net = dev_net(dev);
(gdb) bt
#0  addrconf_notify (this=0xffffff8008e2f398, event=4, ptr=0xffffff800d543d30) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/ipv6/addrconf.c:3352
#1  0xffffff80080b9ab0 in notifier_call_chain (nl=<optimized out>, val=4, v=0xffffff800d543d30, nr_to_call=143309632, nr_calls=0x1043) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/kernel/notifier.c:93
#2  0xffffff80080b9c64 in __raw_notifier_call_chain (nr_calls=<optimized out>, nr_to_call=<optimized out>, v=<optimized out>, val=<optimized out>, nh=<optimized out>)
    at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/kernel/notifier.c:394
#3  raw_notifier_call_chain (nh=<optimized out>, val=<optimized out>, v=<optimized out>) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/kernel/notifier.c:401
#4  0xffffff80087e4bd0 in call_netdevice_notifiers_info (val=4, dev=0xffffffc86b0d8000, info=0xffffff800d543d30) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/core/dev.c:1671
#5  0xffffff80087e8344 in netdev_state_change (dev=0xffffffc86b0d8000) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/core/dev.c:1318
#6  0xffffff8008802884 in linkwatch_do_dev (dev=0xffffffc86b0d8000) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/core/link_watch.c:164
#7  0xffffff8008802b24 in __linkwatch_run_queue (urgent_only=149091224) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/core/link_watch.c:202
#8  0xffffff8008802bf8 in linkwatch_event (dummy=<optimized out>) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/net/core/link_watch.c:237
#9  0xffffff80080b279c in process_one_work (worker=0xffffffc87098b500, work=0xffffff8008e28600) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/kernel/workqueue.c:2113
#10 0xffffff80080b2950 in worker_thread (__worker=0xffffffc87098b500) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/kernel/workqueue.c:2247
#11 0xffffff80080b85e4 in kthread (_create=0xffffffc86b6b2d00) at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/kernel/kthread.c:231
#12 0xffffff8008084a90 in ret_from_fork () at /work/dmaEXP/uartPs1/components/extSrc/linux-xlnx/arch/arm64/kernel/entry.S:946
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) print event
$1 = 4
(gdb) print ptr
$2 = (void *) 0xffffff800d543d30
(gdb)