[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen staging] tools/gdbsx: fix 'g' packet response for 64bit guests



commit 0c9821d5c870c35aa38df7bb5e2ff54da2169b5b
Author:     Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
AuthorDate: Tue Jul 31 04:30:42 2018 +0200
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Wed Aug 1 10:26:11 2018 +0100

    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.
    
    Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
    Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 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(-)

diff --git a/tools/debugger/gdbsx/gx/gx_local.c 
b/tools/debugger/gdbsx/gx/gx_local.c
index 1bec03d49c..33556a582d 100644
--- a/tools/debugger/gdbsx/gx/gx_local.c
+++ b/tools/debugger/gdbsx/gx/gx_local.c
@@ -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");
 }
diff --git a/tools/debugger/gdbsx/xg/xg_main.c 
b/tools/debugger/gdbsx/xg/xg_main.c
index cc640d1d82..a4e8653168 100644
--- a/tools/debugger/gdbsx/xg/xg_main.c
+++ b/tools/debugger/gdbsx/xg/xg_main.c
@@ -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;
diff --git a/tools/debugger/gdbsx/xg/xg_public.h 
b/tools/debugger/gdbsx/xg/xg_public.h
index 3f905a2f0d..cffb2f7532 100644
--- a/tools/debugger/gdbsx/xg/xg_public.h
+++ b/tools/debugger/gdbsx/xg/xg_public.h
@@ -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;
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.