kernel debugging - kdbg + gdb between two Linux VM's

Discussions related to using VirtualBox on Windows hosts.

kernel debugging - kdbg + gdb between two Linux VM's

Postby gwbdopesmoker » 13. Aug 2013, 21:04

Hi,

I am running two RH ( 2.6.32 kernels ) VM's on Windows and would like to debug one of the VM's kernel with the other
VM running gdb using the kdbg serial link .

I have seen some other references to debugging Windows VM's using windbg serial connection and it appears some folks may have
gotten that to work.



Thanks .
gwbdopesmoker
 
Posts: 5
Joined: 17. Nov 2011, 19:30
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: linux

Re: kernel debugging - kdbg + gdb between two Linux VM's

Postby gwbdopesmoker » 14. Aug 2013, 18:34

I am able to connect to gdb on a 2.6.32 kernel, but there are some issues :cry: (see the tail of the msg)

Terms :
debugger: is the VM running gdb ; It needs access to the vmlinux (symbols) and source ;
debuggie: is the target VM to debug

1. On each Linux VM, create a named pipe associated with the serial port with the following format :

\\.\pipe\com1

This is found under the virtbox " Settings->Serial Port" for each VM

2. Build a kernel with GKDB enabled ( basic kernel build ) :

- copy /boot/config<uname -r> .config
- make oldconfig
- make menuconfig
- kernel hacking -> GKDB enabled
- make clean all install modules_install


3. On the target machine (debuggie) you want to debug with the kernel you built , add to the kernel boot params :
kgdboc=ttyS0,115200

There are other options for kdb that don't appear to work ( yet ):

kdb=yes kdb=on kdb=early

kdg=early is suppose to have the debuggie wait for a gdb to connect during early boot so you.
can debug start up issues.

4. On the debugger VM, create a gdbinit file :

[root@rh62-x86 linux-2.6.32-220.4.2.el6]# cat gdbinit
set remotebaud 115200
target remote /dev/ttyS0

( I doubt the baud rate is needed because there is no actual serial port - it's a virtual :D )

5. Boot the target/debuggie ;

6. Start gdb on the debugger:

gdb -x gdbinit vmlinux

7. On the debuggie

echo g > /proc/sysrq-trigger

And you will wake up the debugger:
Code: Select all   Expand viewCollapse view
Reading symbols from /home2/l2.6.32/linux-2.6.32-220.4.2.el6/vmlinux...done.
kgdb_breakpoint (key=<value optimized out>, tty=<value optimized out>) at kernel/kgdb.c:1718
1718            wmb(); /* Sync point after breakpoint */
(gdb) bt
#0  kgdb_breakpoint (key=<value optimized out>, tty=<value optimized out>)
    at kernel/kgdb.c:1718
#1  sysrq_handle_gdb (key=<value optimized out>, tty=<value optimized out>)
    at kernel/kgdb.c:1578
#2  0xc0696ac1 in __handle_sysrq (key=103, tty=0x0, check_mask=0)
    at drivers/char/sysrq.c:521
#3  0xc0696b5f in write_sysrq_trigger (file=<value optimized out>,
    buf=<value optimized out>, count=2, ppos=0xe8361f98)
    at drivers/char/sysrq.c:599
#4  0xc05762ef in proc_reg_write (file=<value optimized out>,
    buf=0xb773f000 "g\n0;root@RH63-x86:/proc\a", count=<value optimized out>,
    ppos=0xe8361f98) at fs/proc/inode.c:207
#5  0xc052891a in vfs_write (file=0xefbdab40,
    buf=0xb773f000 "g\n0;root@RH63-x86:/proc\a", count=2, pos=0xe8361f98)
    at fs/read_write.c:347
#6  0xc052930d in sys_write (fd=1,
    buf=0xb773f000 "g\n0;root@RH63-x86:/proc\a", count=2)
    at fs/read_write.c:399
#7  0xc0409b1f in ?? () at arch/x86/kernel/entry_32.S:459



tricks

1. My source tree is on the debugger : /home2/<src>
2. I share that via nfs; > /etc/exports ; /home2 *(rw,no_root_squash,sync)
3. The debuggie mounts the src by a nfs mount at /work : mount <debugger_ip>:/home2 /work
4. I build the kernel on the debuggie, but I can peruse and
edit files from the debugger VM

These way I have access to the kernel source and my project files on both machines.



Issues

1. the hotkey sequence on the console : alt-fn-sysrq-g on the debuggie console
doesn't invoke the gdb . Could virtbox be eating the seqeunces ?

2. The options to wait for gdb on boot ( kdb=early on the kernel arg list) which is
suppose to wait for a gdb connect, isn't working .

If I cure these I'll post a update.

jd

donnjohn at us ibm com
gwbdopesmoker
 
Posts: 5
Joined: 17. Nov 2011, 19:30
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: linux


Return to VirtualBox on Windows Hosts

Who is online

Users browsing this forum: Google [Bot] and 41 guests