Kernel debugging through GDB on Jetson TK1

Hi ,

I am newbie and learning the things.I am trying to debug the kernel through GDB on jetson tk1. But not yet successful. I have installed arm-none-eabi-gdb on the Host PC and launching it as arm-none-eabi-gdb ./vmlinux . Then connecting to the jetson as target remote /dev/ttyS0. But i don’t get any response. What is it i am doing wrong? Is there any document which explains clearly. Any help would be really appreciated.

I’m not on my development system right now, but you want arm-linux-gnueabihf (“none” is for bare metal systems or boot loaders). “arm” because it is arm architecture, “linux” because it uses those calling conventions, “eabihf” because it uses hard-float calling convention on the E ABI. In general it seems sometimes debuggers have issues and end up needing custom compile (“–target=arm-linux-gnueabihf”), but I’m only familiar with the linaro tool chains run from Fedora…most of what I’ve seen on forums assumes a ready-built chain for running on Ubuntu through standard packages.

You also need to compile with the correct flags on your Jetson kernel, which I can’t remember without looking at my devel machine. kgdboc is “kgdb over console” and uses the serial console, so you can’t have a serial terminal attached while using this…it works fine up through boot but you need to disconnect it while debugging. You also have to use the right signals to enable debug over serial console followed by dropping into kgdboc…which I need my outside references to remember which they are. Check your kernel config for items related to kgdb and kgdboc, keep your vmlinux with a copy on remote host. It’s best if you use u-boot so you can boot to alternate kernels and configs more easily (you don’t want to always run the kgdboc version).

In general kernel debugging is difficult, I’ve found issues with being able to step through some kernel code…or sometimes just getting it to see the source code.

Here are some kernel options you might find useful, but not necessarily required (YMMV, I’m just going through some config file diffs and not really checking details on use with kgdboc):
CONFIG_KALLSYMS_ALL=y
CONFIG_ELF_CORE=y
CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
CONFIG_READABLE_ASM
CONFIG_LESS_GCC_OPT=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
CONFIG_KGDB_KDB=y
CONFIG_PID_IN_CONTEXTIDR=y

The ones I highlighted in color are directly required or useful in kernel debugging.

Hi ,

I have enabled the macros in the config file and modified the bootargs as “kgdbwait kgdboc=ttyS0,115200”. Expected behavior was that kernel boot process should display
“kgdb: Registered I/O driver kgdboc.
kgdb: Waiting for connection from remote gdb…” and kernel boot process should stop but i don’t see any of these logs and kernel normally boots. It looks like the driver is not getting registered.What is that i am missing? Any help would be really appreciated.

I’ve never had the kgdbwait succeed. I’ve also mostly used serial console for serial console up to the point where I wanted to drop into kgdboc. Typically I do this from an ssh session prompt:

echo ttyS0,115200n8 > /sys/module/kgdboc/parameters/kgdboc
echo g > /proc/sysrq-trigger

Then from the serial console (and you must not touch the serial console after this…I typically exit the serial console app):

# NOTE: $3#33 (or $D#44+) if needing to exit.
kgdboc

From there your remote debug session should be possible. There are a lot of flaws in debugging this way, I’ve never been able to get it to “just work” like a regular gdb session without a lot of issues. Unfortunately this is one of the few ways to do the job when adding printk won’t do. When using u-boot though you can at least have multiple boot choices using different debug options and boot to the kernel you want.

Here is how I set with usb rs232 cable for your reference.

=============

  1. Rebuild image with CONFIG_KGDB=y
  2. Device:
  3. sudo su                                                                                                                    
    echo ttyS0,115200 > /sys/module/kgdboc/parameters/kgdboc
    # Signal kgdb to break                                                                                                       
    echo -n g > /proc/sysrq-trigger
    
  4. Host Terminal: To run gdb
  5. arm-eabi-gdb ./vmlinux                                                                                                     
    set remotebaud 115200                                                      
    target remote /dev/ttyUSB0