target/s390x: Fix SQXBR
[qemu/ar7.git] / docs / system / gdb.rst
bloba40145fcf849bf4ee42197d25bbcabe1dec75914
1 .. _gdb_005fusage:
3 GDB usage
4 ---------
6 QEMU supports working with gdb via gdb's remote-connection facility
7 (the "gdbstub"). This allows you to debug guest code in the same
8 way that you might with a low-level debug facility like JTAG
9 on real hardware. You can stop and start the virtual machine,
10 examine state like registers and memory, and set breakpoints and
11 watchpoints.
13 In order to use gdb, launch QEMU with the ``-s`` and ``-S`` options.
14 The ``-s`` option will make QEMU listen for an incoming connection
15 from gdb on TCP port 1234, and ``-S`` will make QEMU not start the
16 guest until you tell it to from gdb. (If you want to specify which
17 TCP port to use or to use something other than TCP for the gdbstub
18 connection, use the ``-gdb dev`` option instead of ``-s``.)
20 .. parsed-literal::
22    |qemu_system| -s -S -kernel bzImage -hda rootdisk.img -append "root=/dev/hda"
24 QEMU will launch but will silently wait for gdb to connect.
26 Then launch gdb on the 'vmlinux' executable::
28    > gdb vmlinux
30 In gdb, connect to QEMU::
32    (gdb) target remote localhost:1234
34 Then you can use gdb normally. For example, type 'c' to launch the
35 kernel::
37    (gdb) c
39 Here are some useful tips in order to use gdb on system code:
41 1. Use ``info reg`` to display all the CPU registers.
43 2. Use ``x/10i $eip`` to display the code at the PC position.
45 3. Use ``set architecture i8086`` to dump 16 bit code. Then use
46    ``x/10i $cs*16+$eip`` to dump the code at the PC position.
48 Advanced debugging options:
50 The default single stepping behavior is step with the IRQs and timer
51 service routines off. It is set this way because when gdb executes a
52 single step it expects to advance beyond the current instruction. With
53 the IRQs and timer service routines on, a single step might jump into
54 the one of the interrupt or exception vectors instead of executing the
55 current instruction. This means you may hit the same breakpoint a number
56 of times before executing the instruction gdb wants to have executed.
57 Because there are rare circumstances where you want to single step into
58 an interrupt vector the behavior can be controlled from GDB. There are
59 three commands you can query and set the single step behavior:
61 ``maintenance packet qqemu.sstepbits``
62    This will display the MASK bits used to control the single stepping
63    IE:
65    ::
67       (gdb) maintenance packet qqemu.sstepbits
68       sending: "qqemu.sstepbits"
69       received: "ENABLE=1,NOIRQ=2,NOTIMER=4"
71 ``maintenance packet qqemu.sstep``
72    This will display the current value of the mask used when single
73    stepping IE:
75    ::
77       (gdb) maintenance packet qqemu.sstep
78       sending: "qqemu.sstep"
79       received: "0x7"
81 ``maintenance packet Qqemu.sstep=HEX_VALUE``
82    This will change the single step mask, so if wanted to enable IRQs on
83    the single step, but not timers, you would use:
85    ::
87       (gdb) maintenance packet Qqemu.sstep=0x5
88       sending: "qemu.sstep=0x5"
89       received: "OK"