gdbstub: Fix i386/x86_64 machine description and add control registers
PATCH 1/1 gdbstub: Fix i386/x86_64 machine description and add control registers
--- configure | 4 +- gdb-xml/i386-32bit-core.xml | 65 ----------- gdb-xml/i386-32bit-sse.xml | 52 --------- gdb-xml/i386-32bit.xml | 184 ++++++++++++++++++++++++++++++- gdb-xml/i386-64bit-core.xml | 73 ------------- gdb-xml/i386-64bit-sse.xml | 60 ----------- gdb-xml/i386-64bit.xml | 210 +++++++++++++++++++++++++++++++++++- target/i386/cpu.c | 4 +- target/i386/gdbstub.c | 186 +++++++++++++++++++++++++++++++- 9 files changed, 573 insertions(+), 265 deletions(-) delete mode 100644 gdb-xml/i386-32bit-core.xml delete mode 100644 gdb-xml/i386-32bit-sse.xml delete mode 100644 gdb-xml/i386-64bit-core.xml delete mode 100644 gdb-xml/i386-64bit-sse.xml
configure +2 -2
@@ -7121,14 +7121,14 @@ TARGET_ABI_DIR="" case "$target_name" in i386) mttcg="yes" - gdb_xml_files="i386-32bit.xml i386-32bit-core.xml i386-32bit-sse.xml" + gdb_xml_files="i386-32bit.xml" target_compiler=$cross_cc_i386 target_compiler_cflags=$cross_cc_ccflags_i386 ;; x86_64) TARGET_BASE_ARCH=i386 mttcg="yes" - gdb_xml_files="i386-64bit.xml i386-64bit-core.xml i386-64bit-sse.xml" + gdb_xml_files="i386-64bit.xml" target_compiler=$cross_cc_x86_64 ;; alpha)
gdb-xml/i386-32bit-core.xml deleted +0 -65
65 lines not on this page · raw message
gdb-xml/i386-32bit-sse.xml deleted +0 -52
52 lines not on this page · raw message
gdb-xml/i386-32bit.xml +181 -3
188 lines not on this page · raw message
gdb-xml/i386-64bit-core.xml deleted +0 -73
73 lines not on this page · raw message
gdb-xml/i386-64bit-sse.xml deleted +0 -60
60 lines not on this page · raw message
gdb-xml/i386-64bit.xml +206 -4
216 lines not on this page · raw message
target/i386/cpu.c +2 -2
@@ -5826,10 +5826,10 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->gdb_arch_name = x86_gdb_arch_name;#ifdef TARGET_X86_64 cc->gdb_core_xml_file ="i386-64bit.xml" ; - cc->gdb_num_core_regs =57 ; + cc->gdb_num_core_regs =66 ;#else cc->gdb_core_xml_file ="i386-32bit.xml" ; - cc->gdb_num_core_regs =41 ; + cc->gdb_num_core_regs =50 ;#endif #if defined(CONFIG_TCG ) && !defined(CONFIG_USER_ONLY ) cc->debug_excp_handler = breakpoint_handler;
target/i386/gdbstub.c +182 -4
224 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 17 lines · Doug Gale
Signed-off-by Doug Gale <[email protected]>--- configure | 4 +- gdb-xml/i386-32bit-core.xml | 65 ----------- gdb-xml/i386-32bit-sse.xml | 52 --------- gdb-xml/i386-32bit.xml | 184 ++++++++++++++++++++++++++++++- gdb-xml/i386-64bit-core.xml | 73 ------------- gdb-xml/i386-64bit-sse.xml | 60 ----------- gdb-xml/i386-64bit.xml | 210 +++++++++++++++++++++++++++++++++++- target/i386/cpu.c | 4 +- target/i386/gdbstub.c | 186 +++++++++++++++++++++++++++++++- 9 files changed, 573 insertions(+), 265 deletions(-) delete mode 100644 gdb-xml/i386-32bit-core.xml delete mode 100644 gdb-xml/i386-32bit-sse.xml delete mode 100644 gdb-xml/i386-64bit-core.xml delete mode 100644 gdb-xml/i386-64bit-sse.xml
Could you provide a commit message that explains what's wrong with the machine description we have (ie what bug or bugs this change is fixing) and why deleting half the xml files is the right way to fix it, please?
Does the "add control registers" part need to be in the same patch, or is it a separate feature which could be in its own patch ?
thanks
-- PMM
The machine description we send is being (silently) thrown on the floor by GDB and GDB silently uses the default machine description.
With current QEMU, if you debug gdb, and set debug_xml=1 and continue, then attach to qemu gdbstub from the debugged gdb, you will see the xml parse fail completely, and gdb will fall back to the default machine description, silently, and changes to our xml (in qemu source code) have no effect. They might as well be empty.
The point of fixing the machine description was IDE's with GDB integration will break on QEMU. The default machine description has fs_base, which fails to be retrieved, whick breaks the whole register window (in qt-creator at least, likely others). With my patch the register window works perfectly.
I didn't delete anything, I removed the superfluous nesting of files by xi:include and moved the description into a single xml file. I added fs_base, gs_base, k_gs_base, cr0/2/3/4/6, efer.
Removing the nesting into xml includes fixes it because the xml parse fails on <feature nested within <feature, so I solved it by removing unnecessary include indirections and placed the data inline.
I tried lots of things to fix the nesting. After a while I asked, why bother? It doesn't need to go through that include level of indirection does it?
This patch leads to another patch I want to submit later, which fixes the broken real mode and protected mode debugging on x86_64. I want to add the ability to turn off the "always 64 bit registers" hack that works around 'g' packet too large. You fix that by patching gdb (which then reacts to packet to large with realloc instead of freaking out), not by breaking real and protected mode debugging on x86_64 target by forcing always-64-bit. My intention is to default to current behavior and have a command line switch that enables changing register sizes (fixing real and protected mode debugging on x86_64).
This patch includes a FORCE_64 define that will be replaced by a check for the option that indicates patched gdb and "register size change ok mode".
Quoted 31 lines · Peter Maydell
Quoted 17 lines · Doug Gale
Signed-off-by Doug Gale <[email protected]>--- configure | 4 +- gdb-xml/i386-32bit-core.xml | 65 ----------- gdb-xml/i386-32bit-sse.xml | 52 --------- gdb-xml/i386-32bit.xml | 184 ++++++++++++++++++++++++++++++- gdb-xml/i386-64bit-core.xml | 73 ------------- gdb-xml/i386-64bit-sse.xml | 60 ----------- gdb-xml/i386-64bit.xml | 210 +++++++++++++++++++++++++++++++++++- target/i386/cpu.c | 4 +- target/i386/gdbstub.c | 186 +++++++++++++++++++++++++++++++- 9 files changed, 573 insertions(+), 265 deletions(-) delete mode 100644 gdb-xml/i386-32bit-core.xml delete mode 100644 gdb-xml/i386-32bit-sse.xml delete mode 100644 gdb-xml/i386-64bit-core.xml delete mode 100644 gdb-xml/i386-64bit-sse.xmlCould you provide a commit message that explains what's wrong with the machine description we have (ie what bug or bugs this change is fixing) and why deleting half the xml files is the right way to fix it, please?
Does the "add control registers" part need to be in the same patch, or is it a separate feature which could be in its own patch ?
thanks
-- PMM
Here is the sequence that led to this patch:
- Debugging my kernel, I wished I could use conditional breapoints to put a condition on CR3 to make breakpoints in user processes only break when they are the active address space.
- Knew it was no problem to add a register to GDB stub
- Added CR3. While there, added CR0 and CR2 and CR4 and CR8 and EFER
- Attempted to use it. Dreaded g packet error.
- Setup to debug GDB. Step tdesc code. Find it failing and silently dropping description.
- Changed register count in gdbstub to match what default machine description would want. No more error. GDB definitely dropping to default.
- Learn more about GDB XML parser. Find it has a verbose parser log. set debug_xml=1
- Watch in horror as parser gets messed up parsing nesting due to feature including feature
- Wonder if any QEMU machine descriptions xi:include actually work or if all architectures are lined up to coincidentally use the same register numbers as the default.
- Run everything through XML validators that strictly enforce DTD and everything, no problem, totally valid.
- Try several changes to make include work. Not working.
- Move the content of the includes into the top level file so no include. Bingo, works.
- Discover that fsbase and gsbase now working because the entire machine description is correctly implemented, makes the register window in qtcreator suddenly work great
- Make sure 32 bit works too. Find a couple of issues. Fix.
- Submit
Quoted 76 lines · Doug Gale
The machine description we send is being (silently) thrown on the floor by GDB and GDB silently uses the default machine description.
With current QEMU, if you debug gdb, and set debug_xml=1 and continue, then attach to qemu gdbstub from the debugged gdb, you will see the xml parse fail completely, and gdb will fall back to the default machine description, silently, and changes to our xml (in qemu source code) have no effect. They might as well be empty.
The point of fixing the machine description was IDE's with GDB integration will break on QEMU. The default machine description has
fs_base, which fails to be retrieved, whick breaks the whole register window (in qt-creator at least, likely others). With my patch the register window works perfectly.I didn't delete anything, I removed the superfluous nesting of files by xi:include and moved the description into a single xml file. I added
fs_base,gs_base,k_gs_base, cr0/2/3/4/6, efer.Removing the nesting into xml includes fixes it because the xml parse fails on <feature nested within <feature, so I solved it by removing unnecessary include indirections and placed the data inline.
I tried lots of things to fix the nesting. After a while I asked, why bother? It doesn't need to go through that include level of indirection does it?
This patch leads to another patch I want to submit later, which fixes the broken real mode and protected mode debugging on
x86_64. I want to add the ability to turn off the "always 64 bit registers" hack that works around 'g' packet too large. You fix that by patching gdb (which then reacts to packet to large with realloc instead of freaking out), not by breaking real and protected mode debugging onx86_64target by forcing always-64-bit. My intention is to default to current behavior and have a command line switch that enables changing register sizes (fixing real and protected mode debugging onx86_64).This patch includes a
FORCE_64define that will be replaced by a check for the option that indicates patched gdb and "register size change ok mode".Quoted 31 lines · Peter Maydell
Quoted 17 lines · Doug Gale
Signed-off-by Doug Gale <[email protected]>--- configure | 4 +- gdb-xml/i386-32bit-core.xml | 65 ----------- gdb-xml/i386-32bit-sse.xml | 52 --------- gdb-xml/i386-32bit.xml | 184 ++++++++++++++++++++++++++++++- gdb-xml/i386-64bit-core.xml | 73 ------------- gdb-xml/i386-64bit-sse.xml | 60 ----------- gdb-xml/i386-64bit.xml | 210 +++++++++++++++++++++++++++++++++++- target/i386/cpu.c | 4 +- target/i386/gdbstub.c | 186 +++++++++++++++++++++++++++++++- 9 files changed, 573 insertions(+), 265 deletions(-) delete mode 100644 gdb-xml/i386-32bit-core.xml delete mode 100644 gdb-xml/i386-32bit-sse.xml delete mode 100644 gdb-xml/i386-64bit-core.xml delete mode 100644 gdb-xml/i386-64bit-sse.xmlCould you provide a commit message that explains what's wrong with the machine description we have (ie what bug or bugs this change is fixing) and why deleting half the xml files is the right way to fix it, please?
Does the "add control registers" part need to be in the same patch, or is it a separate feature which could be in its own patch ?
thanks
-- PMM
Quoted 9 lines · Doug Gale
The machine description we send is being (silently) thrown on the floor by GDB and GDB silently uses the default machine description.
With current QEMU, if you debug gdb, and set debug_xml=1 and continue, then attach to qemu gdbstub from the debugged gdb, you will see the xml parse fail completely, and gdb will fall back to the default machine description, silently, and changes to our xml (in qemu source code) have no effect. They might as well be empty.
The point of fixing the machine description was IDE's with GDB integration will break on QEMU. The default machine description has
fs_base, which fails to be retrieved, whick breaks the whole register window (in qt-creator at least, likely others). With my patch the register window works perfectly.I didn't delete anything, I removed the superfluous nesting of files by xi:include and moved the description into a single xml file. I added
fs_base,gs_base,k_gs_base, cr0/2/3/4/6, efer.Removing the nesting into xml includes fixes it because the xml parse fails on <feature nested within <feature, so I solved it by removing unnecessary include indirections and placed the data inline.
Thanks for this explanation -- the patch makes a lot more sense with it. I'm confused though -- the XML we ship is basically what gdb itself ships and uses internally:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/features/i386/i386.xml;h=beb1496d9773efcf0e0526dc540a5e206a2e21fc;hb=HEAD
and that uses xi:include to pull in the other files. So it seems odd that gdb can't parse the XML it is using itself internally. Maybe QEMU is doing something else wrong somewhere?
thanks
-- PMM
Quoted 5 lines · Peter Maydell
Thanks for this explanation -- the patch makes a lot more sense with it. I'm confused though -- the XML we ship is basically what gdb itself ships and uses internally:
Quoted 8 lines
and that uses xi:include to pull in the other files. So it seems odd that gdb can't parse the XML it is using itself internally. Maybe QEMU is doing something else wrong somewhere?
I thought that too. I implemented gdbstub tracing a while ago and had it enabled (-trace gdb*). The binary data it sends is exactly what I expect. When I break into gdb, I checked the data and it looked correct. debug_xml even prints out what it's going to parse. Looks fine. GDB calls into an XML parser library, which I don't have built from source, so I didn't find precisely where it fails, only the high level log showing unexpected elements at nested feature.
Quoted 15 lines · Doug Gale
The machine description we send is being (silently) thrown on the floor by GDB and GDB silently uses the default machine description.
With current QEMU, if you debug gdb, and set debug_xml=1 and continue, then attach to qemu gdbstub from the debugged gdb, you will see the xml parse fail completely, and gdb will fall back to the default machine description, silently, and changes to our xml (in qemu source code) have no effect. They might as well be empty.
The point of fixing the machine description was IDE's with GDB integration will break on QEMU. The default machine description has
fs_base, which fails to be retrieved, whick breaks the whole register window (in qt-creator at least, likely others). With my patch the register window works perfectly.
Quoted 7 lines
I didn't delete anything, I removed the superfluous nesting of files by xi:include and moved the description into a single xml file. I added
fs_base,gs_base,k_gs_base, cr0/2/3/4/6, efer.Removing the nesting into xml includes fixes it because the xml parse fails on <feature nested within <feature, so I solved it by removing unnecessary include indirections and placed the data inline.
Thanks, I put this as a commit message:
The machine description we send is being (silently) thrown on the floor by GDB and GDB silently uses the default machine description, because the xml parse fails on <feature> nested within <feature>. Changes to the xml in qemu source code have no effect.
In addition, the default machine description has fs_base, which fails to be retrieved, which breaks the whole register window. Add it and the other control registers.
Thanks,
Paolo