Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: gdb@sourceware.org
Cc: Daniel Jacobowitz <drow@false.org>
Subject: Towards better x86 system debugging support
Date: Sun, 04 Jan 2009 13:34:00 -0000	[thread overview]
Message-ID: <4960BAC8.7020801@web.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 3521 bytes --]

Hi,

as many of you may know, there is a gdb server in QEMU that allows to
debug kernels, boot loaders and other low-level stuff without real
target hardware. I'm e.g. using it heavily for analyzing Linux kernel
issues on x86 targets (thanks to KVM, you can even debug weird SMP races
in NMI-using kernel debuggers...).

Unfortunately, the x86 support is incomplete in so far that neither the
gdb remote protocol nor the gdb backend are aware of most special
registers x86 system-level software uses. This comes with several drawbacks:

 o Current code bit width (16, 32 or 64) is unknown to the debugger,
   so correct disassembling is not automatically possible
 o Real mode cannot be detected, which would include setting 16 bit
   disassembly mode and calculating segment bases appropriately
 o Manually setting the architecture (set arch i8086/i386/i386:x86-64)
   influences the register set layout of the remote protocol, preventing
   straightforward switches from 16-bit bootloader/BIOS code to 64-bit
   kernel code (to give just one example)
 o Only flat memory models are supported and debugging becomes very
   hairy when some segment uses a non-zero base address - note that this
   also prevents support for TLS variable lookup (which is GS or
   FS-based)

As a first step toward enhanced x86 support, I think there is a need for
an extended register set in the remote protocol. The following registers
should be added:

 o GDTR, LDTR, IDTR, TR (visible part, ie. selector value)
 o CR0..4
 o DR0..7
 o selected MSRs, at least
    - IA32_EFER (64-bit mode detection)
    - IA32_FS_Base (TLS)
    - IA32_GS_Base (TLS)
    - IA32_KernelGSbase (TLS)
 o Shadow states of segment registers, GDTR, LDTR, IDTR and TR
   (relevant for virtual targets where the VM often has access to these
   hidden states, helpful when debugging targets that modify in-use
   descriptor table entries)

If anyone thinks that there should be more registers or MSRs included,
please extend this list!

The question for me is how to extend the protocol precisely. I guess we
need some new qSupported feature. But should we then, if both sides
agreed on it, switch to a completely new register set or rather exchange
those additional registers separately, ie. via some new packet?

A related issue that was already the source of a lot of pain is the
register width. For 16 and 32 bit mode, gdb uses 32 bit registers in the
remote protocol. But we have a fairly different set for 64 bit mode. Now
I wonder if we should go for a full 64 bit set unconditionally with this
extension (even if the target only supports 32 bit), avoiding all
protocol problems related to switching from 64 bit to lower modes (*).
The only minor issue I see is suboptimal performance with 32 bit targets
over real serial lines - if that still matters...

Looking forward to comments, suggestions, (gdb) insights!

Jan

(*) QEMU recently decided to stick with 64 bit layout even if the x86-64
target is running in 16 or 32 bit mode. Before that the remote protocol
used to be switched between 32 and 64 bit dynamically, depending on the
current target mode. That solved many issues, but not all (manual 'set
arch' was required, and gdb became confused in a few cases). We are now
discussing again on qemu-devel how to deal with 16/32 bit system-level
debugging in 64 bit emulation environment: either try to improve gdb
quickly or reintroduce the old workaround, at least temporarily.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]

             reply	other threads:[~2009-01-04 13:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-04 13:34 Jan Kiszka [this message]
2009-01-05  3:44 ` Daniel Jacobowitz
2009-01-05  8:52   ` GDB MI and actual type of a pointer or reference Elmenthaler, Jens
2009-01-05  9:36   ` Towards better x86 system debugging support Jan Kiszka
2009-01-06 15:14     ` Daniel Jacobowitz
2009-01-05 20:20 ` Mark Kettenis
2009-01-06 12:13   ` Jan Kiszka
2009-05-29 19:20     ` Samuel Bronson
2009-05-31  9:36       ` Jan Kiszka
2009-01-06 23:59 ` Doug Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4960BAC8.7020801@web.de \
    --to=jan.kiszka@web.de \
    --cc=drow@false.org \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox