2
gdbsx: gdbserver for xen
5
Welcome to gdbsx. gdbsx is a gdbserver program to debug guest kernels and
6
kernel modules. It runs on dom0 running on xen hypervisor and allows debug
7
of 32 or 64bit PV or HVM elf guest binaries. It can also be run standalone,
8
without remote gdb, to dump context of any/all VCPUs of any guest.
10
It is divided in two parts, gx and xg. The former interacts with remote gdb,
11
while latter interacts with xen and exports public APIs that can be used to
12
create a plug in for any other debugger or binary type.
16
- boot with gdbsx enabled hypervisor (eg, on OVM: xen-64bit-debug.gz)
17
- copy gdbsx binary to the dom0 (assume hostname is "dom0"), then:
20
- dom0> gdbsx -c 1 64 : displays VCPU contexts for 64bit guest with domid 1
23
- dom0> gdbsx -a 2 64 9999
24
connects to a 64bit guest with domid 2 and waits for gdb connection
25
- now, connect to the above gdbsx from a remote system or dom0 as:
26
bash> gdb ./vmlinux (exact matching vmlinux of guest kernel)
27
(gdb) target remote dom0:9999
29
- Additionally, to debug loadable kernel modules, please do following:
30
(gdb) p init_mm.pgd[3]
31
$1 = {pgd = 0x1b874f027}
32
(gdb) monitor pgd3 0x1b874f027 (Make sure value is in HEX)
33
pgd3val set to: 0x1b874f027
35
- use gdb as normal, breakpoints, single step, etc...
36
- when need to break into gdb, instead of ctrl-c, just do "xm pause <domid>"
37
on dom0 to pause the guest. this will break into gdb right away.
38
- detach/quit from gdb (leave gdbsx alone) to gracefully exit.
39
- if ctrl-c or core-dumped, make sure to do xm unpause if guest still paused.
42
o gdb>set scheduler-locking on : for single step of correct vcpu.
44
o since gdb is not kernel debugger, vcpus are emulated via threads
45
Thus, gdb>info threads : will show all vcpus. Then, switch thread
46
to get to another vcpu, etc... Remember, gdb has it's own [thread]
49
- See below for some useful gdb macros. Please email me if you've more.
53
- For now, it is not possible to run gdbsx on a guest and gdb inside
54
the same guest at the same time.
55
- To report problems, please run gdbsx with -d and collect output.
56
- VCPU offlining is not supported. Thus [0-NUMVCPUs] are all assumed active.
59
- make sure firewall is disabled on dom0 if running gdb on a different host.
60
- Must be at least gdb version 6.5-16.x to debug el5 kernels.
62
BUILD: (if you don't have access to binary):
63
- first compile the hypervisor: xen> make gdbsx=y
64
To have both kdb and gdbsx, xen> make kdb=y gdbsx=y
65
(NOTE: kdb is not required for gdbsx)
66
- install the hypervisor and reboot
67
- now go to, tools/debugger/gdbsx and do make
68
On 32bit system, a 32bit binary will be built with support for both 32
69
and 64bit guests. On 64bit system, a 64bit binary will be built with
75
Redwood Shores, CA USA
76
mukesh[dot]rathor[at]oracle[dot]com
79
------------------------------------------------------------------------------
83
# Courtesy Zhigang W (http://10.182.120.78/tech/vt/ovm/debug/gdbinit.macros):
87
set $tasks = (struct list_head *)init_task->tasks
88
set $offset = (unsigned long)&init_task->tasks - (unsigned long)&init_task
90
set $task_entry = (struct task_struct *)((unsigned long)$task - $offset)
91
printf "Pointer PID Command\n"
92
printf "%-14p%-9d%s\n", $task_entry, $task_entry->pid, $task_entry->comm
93
set $task = $task->next
95
set $task_entry = (struct task_struct *)((unsigned long)$task - $offset)
96
if ($task_entry->pid) != 0
97
printf "%-14p%-9d%s\n", $task_entry, $task_entry->pid, $task_entry->comm
99
set $task = $task->next
104
Report a snapshot of the current processes.
110
# 4 for 32bit kernels. 8 for 64bit kernels.
111
set $sz = sizeof(long)
112
set $mod = (struct list_head *)modules
113
printf "modptr address name\n"
115
set $mod_entry = (struct module *)((unsigned long)$mod - $sz)
117
printf "%08lx %08lx %s\n", $mod_entry, \
118
$mod_entry->module_core, $mod_entry->name
120
printf "%016lx %016lx %s\n", $mod_entry, \
121
$mod_entry->module_core, $mod_entry->name
123
set $mod = $mod->next
124
if ($mod == &modules)
131
Show the list of modules loaded in the Linux kernel.
140
Dump system message buffer.
143
------------------------------------------------------------------------------