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@invisiblethingslab.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
Marek Marczykowski-Górecki authored and Wei Liu committed 2018-08-01 10:26:11 +01:00
1 parent 01dfa3378f
commit 0c9821d5c8
3 files changed
+21 -21

No files matched your search

+3 -3
View File
@@ -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");
}
+9 -9
View File
@@ -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->eflags = 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->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;
+9 -9
View File
@@ -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;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.