title: How to debug Linux dom0 kernel in Xen
body: <p>I have been hacking on the Xen block driver backend and have been having some difficulty debugging using kgdb over serial. Here is my setup. I'm running MacOS X as host OS. I have two VirtualBox VMs, call them dev and test. VirtualBox is configured to give each of them a COM1 port connected to a named host pipe. I then use <code>socat -d -d ./test-com1 ./dev-com1</code> to connect the two ports. I have verified after doing this that I can send text plain text from one VM to the other either by doing <code>echo hi &gt; /dev/[ttyS0|hvc0]</code> or using socat. I can also get console output coming out of test during bootup by using socat on dev.</p>
  
  <p>Here's my grub entry for the test kernel:</p>
  
  <pre><code>menuentry 'Debian GNU/Linux, with Linux 3.3.6-xen-ljx-g6304e82 and XEN 4.1.2' --class debian --class gnu-linux --class gnu --class os --class xen {
          insmod part_msdos
          insmod ext2
          set root='(hd0,msdos1)'
          search --no-floppy --fs-uuid --set 0c98efb4-f40e-4f0e-a2d3-2ed39b0a5070
          echo    'Loading Linux 3.3.6-xen-ljx-g6304e82 ...'
          multiboot       /boot/xen-4.1.2.gz placeholder loglvl=all guest_loglvl=all com1=115200,8n1,0x3f8,4 console=com1,vga 
          module  /boot/vmlinuz-3.3.6-xen-ljx-g6304e82 placeholder root=UUID=0c98efb4-f40e-4f0e-a2d3-2ed39b0a5070 ro console=hvc0 console=tty0 earlyprintk=xen nopat quiet
          echo    'Loading initial ramdisk ...'
          module  /boot/initrd.img-3.3.6-xen-ljx-g6304e82
  }
  </code></pre>
  
  <p>This is from dev:</p>
  
  <pre><code>user@jimmy:~/workspace/linux-3.3.6$ stty -F /dev/ttyS0 -a
  speed 38400 baud; rows 0; columns 0; line = 0;
  intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = &lt;undef&gt;; eol2 = &lt;undef&gt;; swtch = &lt;undef&gt;; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 0; time = 10;
  -parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
  -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
  -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
  -isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke
  </code></pre>
  
  <p>This is from test:</p>
  
  <pre><code>root@sqtest:~# stty -F /dev/tty0  -a
  speed 38400 baud; rows 25; columns 80; line = 0;
  intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = &lt;undef&gt;; eol2 = &lt;undef&gt;; swtch = &lt;undef&gt;; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
  -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
  ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8
  -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
  -isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke
  root@sqtest:~# stty -F /dev/hvc0  -a
  speed 38400 baud; rows 0; columns 0; line = 0;
  intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = &lt;undef&gt;; eol2 = &lt;undef&gt;; swtch = &lt;undef&gt;; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
  -parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts
  -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
  opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
  isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
  </code></pre>
  
  <p>An example dev session (after doing <code>echo hvc0,38400 &gt; /sys/module/kgdboc/parameters/kgdboc; echo g &gt; /proc/sysrq-trigger</code> on test):</p>
  
  <pre><code>user@jimmy:~/workspace/linux-3.3.6$ gdb vmlinux 
  GNU gdb (GDB) 7.0.1-debian
  Copyright (C) 2009 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  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 "i486-linux-gnu".
  For bug reporting instructions, please see:
  &lt;http://www.gnu.org/software/gdb/bugs/&gt;...
  Reading symbols from /home/paton/workspace/linux-3.3.6/vmlinux...done.
  (gdb) set remotebaud 38400
  (gdb) target remote /dev/ttyS0
  Remote debugging using /dev/ttyS0
  Ignoring packet error, continuing...
  warning: unrecognized item "timeout" in "qSupported" response
  Ignoring packet error, continuing...
  </code></pre>
  
  <p>Same thing happens when I use tty0 instead of hvc0 above.</p>
  
  <p>I have been able to successfully connect the debugger when using my kernel without Xen, although the serial TTY settings are different. I have a feeling it has something to do with the options as reported by STTY, but I'm hoping someone who knows more about those things can point out the problem so I understand.</p>
  
  <p>Thank you!</p>