From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: jan.kiszka@web.de
Cc: gdb@sourceware.org, drow@false.org
Subject: Re: Towards better x86 system debugging support
Date: Mon, 05 Jan 2009 20:20:00 -0000 [thread overview]
Message-ID: <200901052020.n05KKg3d014109@brahms.sibelius.xs4all.nl> (raw)
In-Reply-To: <4960BAC8.7020801@web.de> (message from Jan Kiszka on Sun, 04 Jan 2009 14:34:00 +0100)
> Date: Sun, 04 Jan 2009 14:34:00 +0100
> From: Jan Kiszka <jan.kiszka@web.de>
>
> Hi,
>
> 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:
Yes there are some limitations. What's there is mostly adequeate for
debugging traditional C kernel code. And I for myself have always
considered implementing the bits needed for more low-level code an
effort too big to be worth it (how much 16-bit code is there in the
Linux kernel?). But if you think otherwise, feel free to contribute
the appropriate code.
> o Current code bit width (16, 32 or 64) is unknown to the debugger,
> so correct disassembling is not automatically possible
It's tricky to figure this out when running on real hardware, but I
suppose it would be trivial for an emulator like QEMU to tell GDB what
mode it's in. The idea has always been that GDB would become
multi-arch and that every frame would have an architecture associated
with it. Perhaps that's the way to go.
> o Real mode cannot be detected, which would include setting 16 bit
> disassembly mode and calculating segment bases appropriately
Sorry, what are you trying to say here?
> 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)
Even worse, it changes the layout of GDB's internal register cache.
And I'm not even sure it is feasable to unify the i386 and amd64
layouts in a meaningful way.
> 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)
This problem is not unique to the i386/amd64 targets. There are other
architectures that have more than one address space. Unfortunately, I
believe nobody has really implemented a satisfactory solution to
implement them properly in GDB.
Not that the TLS problem has been solved already (in a satisfactory
way I think). I'm not sure making GDB aware of %gs and %fs would
really help here. Systems use those registers in different ways, and
they don't really help when you want to look at variables in a
different thread than the one you're running isn't it?
> 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:
Sorry, but I think you're starting at the wrong end here. You should
probably first add support for additional registers to GDB's internal
register cache. It doen't make sense to worry about the remote
protocol until that's done.
> 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!
I don't think it is a good idea to start adding MSRs to GDB's internal
register cache. There are zillions of them. It is probably a better
idea to implement them as a seperate address space.
One thing that's probably a good idea before starting hacking on all
this is to fully decouple the layout of the internal register cache
from the remote protocol such that when you change things there, you
don't have to worry about breaking existing remote stubs.
next prev parent reply other threads:[~2009-01-05 20:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-04 13:34 Jan Kiszka
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 [this message]
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=200901052020.n05KKg3d014109@brahms.sibelius.xs4all.nl \
--to=mark.kettenis@xs4all.nl \
--cc=drow@false.org \
--cc=gdb@sourceware.org \
--cc=jan.kiszka@web.de \
/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