tools/gdbsx: fix 'g' packet response for 64bit guests
PATCH 1/1 tools/gdbsx: fix 'g' packet response for 64bit guests
gdb 8.0 fixed bounds checking for 'g' packet (commit 9dc193c3be85aafa60ceff57d3b0430af607b4ce "Check for truncated registers in process_g_packet"). This revealed that gdbsx did not properly formatted 'g' packet - segment registers and eflags are expected to be 32-bit fields in the response (according to gdb/features/i386/64bit-core.xml in gdb sources). Specific error is:
Truncated register 26 in remote 'g' packet
instead of silently truncating part of register.
Additionally, it looks like segment registers of 64bit guests were never reported correctly, because of type mismatch.
--- tools/debugger/gdbsx/gx/gx_local.c | 6 +++--- tools/debugger/gdbsx/xg/xg_main.c | 20 ++++++++++---------- tools/debugger/gdbsx/xg/xg_public.h | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-)
tools/debugger/gdbsx/gx/gx_local.c +3 -3
@@ -45,8 +45,8 @@ prnt_32regs(struct xg_gdb_regs32 *r32p)static void prnt_64regs (struct xg_gdb_regs64 *r64p) { -printf ("rip:" XGF64 " rsp:" XGF64 " flags:" XGF64 "\n" , r64p->rip, r64p->rsp, - r64p->rflags); +printf ("rip:" XGF64 " rsp:" XGF64 " flags:%08x\n" , r64p->rip, r64p->rsp, + r64p->eflags);printf ("rax:" XGF64 " rbx:" XGF64 " rcx:" XGF64 "\n" , r64p->rax, r64p->rbx, r64p->rcx); printf("rdx:"XGF64" rsi:"XGF64" rdi:"XGF64"\n", r64p->rdx, r64p->rsi,
@@ -57,7 +57,7 @@ prnt_64regs(struct xg_gdb_regs64 *r64p) r64p->r13);printf ("r14:" XGF64 " r15:" XGF64 " rbp:" XGF64 "\n" , r64p->r14, r64p->r15, r64p->rbp); -printf ("cs:" XGF64 " ds:" XGF64 " fs:" XGF64 " gs:" XGF64 "\n" , r64p->cs, +printf ("cs:%08x ds:%08x fs:%08x gs:%08x\n" , r64p->cs, r64p->ds, r64p->fs, r64p->gs);printf ("\n" ); }
tools/debugger/gdbsx/xg/xg_main.c +10 -10
@@ -580,14 +580,14 @@ _cp_64ctxt_to_64gdb(struct cpu_user_regs_x86_64 *cp, struct xg_gdb_regs64 *rp) rp->rax = cp->rax; rp->rip = cp->rip; rp->rsp = cp->rsp; - rp->rflags = cp->rflags; - - rp->cs = (uint64_t )cp->cs; - rp->ss = (uint64_t )cp->ss; - rp->es = (uint64_t )cp->es; - rp->ds = (uint64_t )cp->ds; - rp->fs = (uint64_t )cp->fs; - rp->gs = (uint64_t )cp->gs; + rp->eflags = cp->rflags; + + rp->cs = cp->cs; + rp->ss = cp->ss; + rp->es = cp->es; + rp->ds = cp->ds; + rp->fs = cp->fs; + rp->gs = cp->gs;#if 0 printf ("cp:%llx bp:%llx rip:%llx\n" , rp->rsp, rp->rbp, rp->rip);printf ("rax:%llx rbx:%llx\n" , rp->rax, rp->rbx);
@@ -635,7 +635,7 @@ _cp_32gdb_to_64ctxt(struct xg_gdb_regs32 *rp, struct cpu_user_regs_x86_64 *cp) cp->ds = rp->ds; cp->fs = rp->fs; cp->gs = rp->gs; - cp->rflags = rp->eflags; + cp->eflags = rp->eflags; } static void
@@ -658,7 +658,7 @@ _cp_64gdb_to_64ctxt(struct xg_gdb_regs64 *rp, struct cpu_user_regs_x86_64 *cp) cp->rax = rp->rax; cp->rip = rp->rip; cp->rsp = rp->rsp; - cp->rflags = rp->rflags; + cp->rflags = rp->eflags; cp->cs = (uint16_t )rp->cs; cp->ss = (uint16_t )rp->ss;
tools/debugger/gdbsx/xg/xg_public.h +9 -9
@@ -61,7 +61,7 @@ struct xg_gdb_regs32 {uint32_t gs; }; -/* this from: regformats/reg-x86-64.dat in gdbserver */ +/* based on gdb/features/i386/64bit-core.xml in gdb */ struct xg_gdb_regs64 {uint64_t rax;uint64_t rbx;
@@ -80,14 +80,14 @@ struct xg_gdb_regs64 {uint64_t r14;uint64_t r15;uint64_t rip; -uint64_t rflags; -uint64_t cs; -uint64_t ss; -uint64_t ds; -uint64_t es; -uint64_t fs; -uint64_t gs; -}; +uint32_t eflags; +uint32_t cs; +uint32_t ss; +uint32_t ds; +uint32_t es; +uint32_t fs; +uint32_t gs; +} __attribute__((__packed__));union xg_gdb_regs {struct xg_gdb_regs32 gregs_32;
Signature · 7 lines
2.17.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 31.07.18 at 04:30, <[email protected]> wrote:
Marek,
looks like all of the patches you've sent early this morning local time here came through twice on xen-devel: Would you please avoid having xen-devel on both the To and the Cc lists (just with different domains)?
Thanks, Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 31.07.18 at 04:30, <[email protected]> wrote:
Marek,
looks like all of the patches you've sent early this morning local time here came through twice on xen-devel: Would you please avoid having xen-devel on both the To and the Cc lists (just with different domains)?
I've only got a single copy, and the list archives only show a single copy.
Are you sure that's not just something local to you?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 31.07.18 at 10:09, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 31.07.18 at 04:30, <[email protected]> wrote:
Marek,
Quoted 8 lines
Quoted 4 lines
looks like all of the patches you've sent early this morning local time here came through twice on xen-devel: Would you please avoid having xen-devel on both the To and the Cc lists (just with different domains)?
I've only got a single copy, and the list archives only show a single copy.
Are you sure that's not just something local to you?
Well, I don't see how there can be only a single copy with xen-devel on both the To and Cc lists, unless de-duplication happens at the receiver end (which I could imagine happens in list archiving).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 8 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 31.07.18 at 04:30, <[email protected]> wrote:
Marek,
looks like all of the patches you've sent early this morning local time here came through twice on xen-devel: Would you please avoid having xen-devel on both the To and the Cc lists (just with different domains)?
Sorry about that, now fixed my setup.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 26 lines · Marek Marczykowski-Górecki
gdb 8.0 fixed bounds checking for 'g' packet (commit
9dc193c3be85aafa60ceff57d3b0430af607b4ce"Check for truncated registers inprocess_g_packet"). This revealed that gdbsx did not properly formatted 'g' packet - segment registers and eflags are expected to be 32-bit fields in the response (according togdb/features/i386/64bit-core.xmlin gdb sources). Specific error is:Truncated register 26 in remote 'g' packet
instead of silently truncating part of register.
Additionally, it looks like segment registers of 64bit guests were never reported correctly, because of type mismatch.
Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/debugger/gdbsx/gx/gx_local.c | 6 +++--- tools/debugger/gdbsx/xg/xg_main.c | 20 ++++++++++---------- tools/debugger/gdbsx/xg/xg_public.h | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-)tools/debugger/gdbsx/gx/gx_local.c +0
-0
tools/debugger/gdbsx/gx/gx_local.c prnt_32regs(struct xg_gdb_regs32 *r32p) · line 49
Quoted 7 lines
tools/debugger/gdbsx/gx/gx_local.c +2
-2@@ -45,8 +45,8 @@ prnt_32regs(struct xg_gdb_regs32 *r32p)static void prnt_64regs (struct xg_gdb_regs64 *r64p) { -printf ("rip:" XGF64 " rsp:" XGF64 " flags:" XGF64 "\n" , r64p->rip, r64p->rsp, - r64p->rflags); +printf ("rip:" XGF64 " rsp:" XGF64 " flags:%08x\n" , r64p->rip, r64p->rsp, + r64p->eflags);
I think it would be better to introduce XGF32 and XGFM32 in the header.
The rest looks good to me.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 22 lines · Wei Liu
Quoted 21 lines · Marek Marczykowski-Górecki
gdb 8.0 fixed bounds checking for 'g' packet (commit
9dc193c3be85aafa60ceff57d3b0430af607b4ce"Check for truncated registers inprocess_g_packet"). This revealed that gdbsx did not properly formatted 'g' packet - segment registers and eflags are expected to be 32-bit fields in the response (according togdb/features/i386/64bit-core.xmlin gdb sources). Specific error is:Truncated register 26 in remote 'g' packet
instead of silently truncating part of register.
Additionally, it looks like segment registers of 64bit guests were never reported correctly, because of type mismatch.
Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/debugger/gdbsx/gx/gx_local.c | 6 +++--- tools/debugger/gdbsx/xg/xg_main.c | 20 ++++++++++---------- tools/debugger/gdbsx/xg/xg_public.h | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-)
Quoted 13 lines
tools/debugger/gdbsx/gx/gx_local.c prnt_32regs(struct xg_gdb_regs32 *r32p) · line 49
Quoted 12 lines
tools/debugger/gdbsx/gx/gx_local.c +2
-2@@ -45,8 +45,8 @@ prnt_32regs(struct xg_gdb_regs32 *r32p)static void prnt_64regs (struct xg_gdb_regs64 *r64p) { -printf ("rip:" XGF64 " rsp:" XGF64 " flags:" XGF64 "\n" , r64p->rip, r64p->rsp, - r64p->rflags); +printf ("rip:" XGF64 " rsp:" XGF64 " flags:%08x\n" , r64p->rip, r64p->rsp, + r64p->eflags);I think it would be better to introduce XGF32 and XGFM32 in the header.
??? inttypes.h is a standard header for a reason...
I'd suggest instead that, if cleanup were being done, purging these nonstandard PRIx64's would be a much better option.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 37 lines · Andrew Cooper
Quoted 22 lines · Wei Liu
Quoted 21 lines · Marek Marczykowski-Górecki
gdb 8.0 fixed bounds checking for 'g' packet (commit
9dc193c3be85aafa60ceff57d3b0430af607b4ce"Check for truncated registers inprocess_g_packet"). This revealed that gdbsx did not properly formatted 'g' packet - segment registers and eflags are expected to be 32-bit fields in the response (according togdb/features/i386/64bit-core.xmlin gdb sources). Specific error is:Truncated register 26 in remote 'g' packet
instead of silently truncating part of register.
Additionally, it looks like segment registers of 64bit guests were never reported correctly, because of type mismatch.
Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/debugger/gdbsx/gx/gx_local.c | 6 +++--- tools/debugger/gdbsx/xg/xg_main.c | 20 ++++++++++---------- tools/debugger/gdbsx/xg/xg_public.h | 18 +++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-)Quoted 13 lines
tools/debugger/gdbsx/gx/gx_local.c prnt_32regs(struct xg_gdb_regs32 *r32p) · line 49
Quoted 12 lines
tools/debugger/gdbsx/gx/gx_local.c +2
-2@@ -45,8 +45,8 @@ prnt_32regs(struct xg_gdb_regs32 *r32p)static void prnt_64regs (struct xg_gdb_regs64 *r64p) { -printf ("rip:" XGF64 " rsp:" XGF64 " flags:" XGF64 "\n" , r64p->rip, r64p->rsp, - r64p->rflags); +printf ("rip:" XGF64 " rsp:" XGF64 " flags:%08x\n" , r64p->rip, r64p->rsp, + r64p->eflags);I think it would be better to introduce XGF32 and XGFM32 in the header.
Quoted 5 lines
???
inttypes.his a standard header for a reason...I'd suggest instead that, if cleanup were being done, purging these nonstandard PRIx64's would be a much better option.
This works too.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines · Wei Liu
tools/debugger/gdbsx/gx/gx_local.c prnt_32regs(struct xg_gdb_regs32 *r32p) · line 49
Quoted 10 lines · Marek Marczykowski-Górecki
tools/debugger/gdbsx/gx/gx_local.c +2
-2@@ -45,8 +45,8 @@ prnt_32regs(struct xg_gdb_regs32 *r32p)static void prnt_64regs (struct xg_gdb_regs64 *r64p) { -printf ("rip:" XGF64 " rsp:" XGF64 " flags:" XGF64 "\n" , r64p->rip, r64p->rsp, - r64p->rflags); +printf ("rip:" XGF64 " rsp:" XGF64 " flags:%08x\n" , r64p->rip, r64p->rsp, + r64p->eflags);I think it would be better to introduce XGF32 and XGFM32 in the header.
I was inspired by prnt_32regs function, which use explicit %08x. Should it be changed there too (to PRIx32)? Otherwise that would be inconsistent (and maybe warrant a totally separate cleanup).
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 15 lines · Marek Marczykowski-Górecki
Quoted 13 lines · Wei Liu
tools/debugger/gdbsx/gx/gx_local.c prnt_32regs(struct xg_gdb_regs32 *r32p) · line 49
Quoted 10 lines · Marek Marczykowski-Górecki
tools/debugger/gdbsx/gx/gx_local.c +2
-2@@ -45,8 +45,8 @@ prnt_32regs(struct xg_gdb_regs32 *r32p)static void prnt_64regs (struct xg_gdb_regs64 *r64p) { -printf ("rip:" XGF64 " rsp:" XGF64 " flags:" XGF64 "\n" , r64p->rip, r64p->rsp, - r64p->rflags); +printf ("rip:" XGF64 " rsp:" XGF64 " flags:%08x\n" , r64p->rip, r64p->rsp, + r64p->eflags);I think it would be better to introduce XGF32 and XGFM32 in the header.
Quoted 3 lines
I was inspired by
prnt_32regsfunction, which use explicit %08x. Should it be changed there too (to PRIx32)? Otherwise that would be inconsistent (and maybe warrant a totally separate cleanup).
See Andrew's suggestion to switch to PRIx*.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines · Marek Marczykowski-Górecki
Quoted 12 lines · Wei Liu
tools/debugger/gdbsx/gx/gx_local.c prnt_32regs(struct xg_gdb_regs32 *r32p) · line 49
Quoted 10 lines · Marek Marczykowski-Górecki
tools/debugger/gdbsx/gx/gx_local.c +2
-2@@ -45,8 +45,8 @@ prnt_32regs(struct xg_gdb_regs32 *r32p)static void prnt_64regs (struct xg_gdb_regs64 *r64p) { -printf ("rip:" XGF64 " rsp:" XGF64 " flags:" XGF64 "\n" , r64p->rip, r64p->rsp, - r64p->rflags); +printf ("rip:" XGF64 " rsp:" XGF64 " flags:%08x\n" , r64p->rip, r64p->rsp, + r64p->eflags);I think it would be better to introduce XGF32 and XGFM32 in the header.
Quoted 3 lines
I was inspired by
prnt_32regsfunction, which use explicit %08x. Should it be changed there too (to PRIx32)? Otherwise that would be inconsistent (and maybe warrant a totally separate cleanup).
Tbh, I'd stick with %08x because that's what we'd expect in the hypervisor. If you'd like clean things up then please do, but it would be rude to block this bugfix on cleanup.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel