0

How to debug a custom Linux Kernel on a remote machine?

I have a remote machine with a custom-built Linux Kernel originally from 5.6.8. The system under the kernel is running into problems which I want to fix. The kgdb-related options are

CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
# CONFIG_KGDB_TESTS is not set
CONFIG_KGDB_LOW_LEVEL_TRAP=y
CONFIG_KGDB_KDB=y

The kgdboc module is compiled builtin. The documentation of kgdb describes how to use terminal with a serial port. Here is how it is configured on the remote machine:

root@remote-pc:# cat /sys/module/kgdboc/parameters/kgdboc
ttyS0,115200

Using ssh I issued

root@remote-pc:~# echo g > /proc/sysrq-trigger

And after running gdb vminux what port should I use to connect to the remote Kernel?

(gdb) target remote remote-pc:__what_port?__
Some Name
  • 8,555
  • 5
  • 27
  • 77
  • What do you mean, what port? You started the debugger on a serial console, so whatever you connected the other side of the serial port to. Did you connect the serial ports, or did you mean to use `kgdboe`? – Cheatah May 04 '20 at 21:16
  • @Cheatah Actually have not heard about `kgdboe` (only `kgdboc` is not documented under the doc page I linked) – Some Name May 04 '20 at 21:21
  • @Cheatah Is it even possible to connect to a serial port remotely? – Some Name May 04 '20 at 21:22
  • That depends on what you define as "remotely". If you have an embedded system, connect the serial port to another system, I consider that to be remote, in a way. On a virtualised system you could tunnel it over SSH or something. – Cheatah May 04 '20 at 21:29

1 Answers1

1

You cannot connect to a literally remote machine through a serial port. What you want to use is KGDB Over Ethernet (kdgboe). See How to use kgdb over ethernet (kgdboe)?

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
  • Just found this: https://github.com/b1f6c1c4/ttyssh. It seems it is possible to tunnel it. – Some Name May 04 '20 at 21:39
  • 1
    @SomeName well, I suppose you can tunnel it through SSH as you can do for basically anything. Didn't think about that possibility, not sure how easy it is though. Hope it works! – Marco Bonelli May 04 '20 at 21:41