gdbstub: Unbreak i386 with gdb remote
v2 cover gdbstub: Unbreak i386 with gdb remote
v2:
- use "goto" in patch 1 [Phil]
- pick some tags
Thanks,
Peter Xu (2):
gdbstub: Assert len read from each register
gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
gdbstub.c | 12 +++++++++--- target/i386/gdbstub.c | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.24.1
PATCH v2 1/2 gdbstub: Assert len read from each register
This can expose the issue earlier on which register returned the wrong result.
--- gdbstub.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
gdbstub.c +9 -3
@@ -911,17 +911,23 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)CPUClass *cc =CPU_GET_CLASS (cpu);CPUArchState *env = cpu->env_ptr;GDBRegisterState *r; +int len =0 , orig_len = buf->len;if (reg < cc->gdb_num_core_regs) { -return cc->gdb_read_register (cpu, buf, reg); + len = cc->gdb_read_register (cpu, buf, reg); + goto out; }for (r = cpu->gdb_regs; r; r = r->next) {if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { -return r->get_reg (env, buf, reg - r->base_reg); + len = r->get_reg (env, buf, reg - r->base_reg); +break ; } } -return 0 ; + +out: +assert (len == buf->len - orig_len); +return len; }static int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg)
Signature · 1 line
2.24.1
PATCH v2 2/2 gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
In reply to Peter XuWe should only pass in gdb_get_reg16() with the GByteArray* object itself, no need to shift. Without this patch, gdb remote attach will crash QEMU.
--- target/i386/gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/gdbstub.c +1 -1
@@ -106,7 +106,7 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) }else if (n >=IDX_FP_REGS && n <IDX_FP_REGS +8 ) {floatx80 *fp = (floatx80 *) &env->fpregs[n -IDX_FP_REGS ];int len =gdb_get_reg64 (mem_buf,cpu_to_le64 (fp->low)); - len +=gdb_get_reg16 (mem_buf + len,cpu_to_le16 (fp->high)); + len +=gdb_get_reg16 (mem_buf,cpu_to_le16 (fp->high));return len; }else if (n >=IDX_XMM_REGS && n <IDX_XMM_REGS +CPU_NB_REGS ) { n -=IDX_XMM_REGS ;
Signature · 1 line
2.24.1
Re: [PATCH v2 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
Quoted 7 lines · Peter Xu
We should only pass in
gdb_get_reg16()with the GByteArray* object itself, no need to shift. Without this patch, gdb remote attach will crash QEMU.Cc Alex Bennée <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Fixes b7b8756a9c ("target/i386: use gdb_get_reg helpers", 2020-03-17)
So I think this should still be:
As Phil & Laurent pointed out.
Quoted 22 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Peter Xu <[email protected]>--- target/i386/gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/i386/gdbstub.c +1
-1@@ -106,7 +106,7 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) }else if (n >=IDX_FP_REGS && n <IDX_FP_REGS +8 ) {floatx80 *fp = (floatx80 *) &env->fpregs[n -IDX_FP_REGS ];int len =gdb_get_reg64 (mem_buf,cpu_to_le64 (fp->low)); - len +=gdb_get_reg16 (mem_buf + len,cpu_to_le16 (fp->high)); + len +=gdb_get_reg16 (mem_buf,cpu_to_le16 (fp->high));return len; }else if (n >=IDX_XMM_REGS && n <IDX_XMM_REGS +CPU_NB_REGS ) { n -=IDX_XMM_REGS ;Signature · 1 line
2.24.1
Signature · 1 line
Peter Xu