diff mbox series

[v1,09/11] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb

Message ID 20200409211529.5269-10-alex.bennee@linaro.org
State Superseded
Headers show
Series more random fixes | expand

Commit Message

Alex Bennée April 9, 2020, 9:15 p.m. UTC
From: Peter Xu <peterx@redhat.com>


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.

Fixes: a010bdbe719 ("extend GByteArray to read register helpers")
Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

Message-Id: <20200409164954.36902-3-peterx@redhat.com>
---
 target/i386/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.20.1

Comments

Stefano Garzarella April 10, 2020, 1:08 p.m. UTC | #1
On Thu, Apr 09, 2020 at 10:15:27PM +0100, Alex Bennée wrote:
> From: Peter Xu <peterx@redhat.com>

> 

> 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.

> 

> Fixes: a010bdbe719 ("extend GByteArray to read register helpers")

> Signed-off-by: Peter Xu <peterx@redhat.com>

> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> Message-Id: <20200409164954.36902-3-peterx@redhat.com>

> ---

>  target/i386/gdbstub.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c

> index f3d23b614ee..b98a99500ae 100644

> --- a/target/i386/gdbstub.c

> +++ b/target/i386/gdbstub.c

> @@ -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;

> -- 

> 2.20.1

> 

>


I had the following issue while attaching to qemu started with gdbserver
listening:

(gdb) target remote :1234
Remote debugging using :1234
Remote communication error.  Target disconnected.: Connection reset by peer.

$ qemu-system-x86_64 -m 1G -smp 4 ... -s
ERROR:qemu/gdbstub.c:1843:handle_read_all_regs: assertion failed: (len == gdbserver_state.mem_buf->len)
Bail out! ERROR:qemu/gdbstub.c:1843:handle_read_all_regs: assertion failed: (len == gdbserver_state.mem_buf->len)


Thanks to Philippe, I tried this patch and it solves my issue:

Tested-by: Stefano Garzarella <sgarzare@redhat.com>


Thanks,
Stefano
Richard Henderson April 10, 2020, 2:44 p.m. UTC | #2
On 4/9/20 2:15 PM, Alex Bennée wrote:
> From: Peter Xu <peterx@redhat.com>

> 

> 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.

> 

> Fixes: a010bdbe719 ("extend GByteArray to read register helpers")

> Signed-off-by: Peter Xu <peterx@redhat.com>

> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> Message-Id: <20200409164954.36902-3-peterx@redhat.com>

> ---

>  target/i386/gdbstub.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)


Reviewed-by: Richard Henderson <richard.henderson@linaro.org>



r~
Alex Bennée April 11, 2020, 12:58 p.m. UTC | #3
Stefano Garzarella <sgarzare@redhat.com> writes:

> On Thu, Apr 09, 2020 at 10:15:27PM +0100, Alex Bennée wrote:

>> From: Peter Xu <peterx@redhat.com>

>> 

>> 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.

>> 

>> Fixes: a010bdbe719 ("extend GByteArray to read register helpers")

>> Signed-off-by: Peter Xu <peterx@redhat.com>

>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

>> Message-Id: <20200409164954.36902-3-peterx@redhat.com>

>> ---

>>  target/i386/gdbstub.c | 2 +-

>>  1 file changed, 1 insertion(+), 1 deletion(-)

>> 

>> diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c

>> index f3d23b614ee..b98a99500ae 100644

>> --- a/target/i386/gdbstub.c

>> +++ b/target/i386/gdbstub.c

>> @@ -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;

>> -- 

>> 2.20.1

>> 

>>

>

> I had the following issue while attaching to qemu started with gdbserver

> listening:

>

> (gdb) target remote :1234

> Remote debugging using :1234

> Remote communication error.  Target disconnected.: Connection reset by peer.

>

> $ qemu-system-x86_64 -m 1G -smp 4 ... -s

> ERROR:qemu/gdbstub.c:1843:handle_read_all_regs: assertion failed: (len == gdbserver_state.mem_buf->len)

> Bail out! ERROR:qemu/gdbstub.c:1843:handle_read_all_regs: assertion

> failed: (len == gdbserver_state.mem_buf->len)


I'll see if the new gdb testcases can be generalised - they would have
caught these snafus.

>

>

> Thanks to Philippe, I tried this patch and it solves my issue:

>

> Tested-by: Stefano Garzarella <sgarzare@redhat.com>

>

> Thanks,

> Stefano



-- 
Alex Bennée
Philippe Mathieu-Daudé April 11, 2020, 5:14 p.m. UTC | #4
On 4/10/20 3:08 PM, Stefano Garzarella wrote:
> On Thu, Apr 09, 2020 at 10:15:27PM +0100, Alex Bennée wrote:

>> From: Peter Xu <peterx@redhat.com>

>>

>> 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.

>>

>> Fixes: a010bdbe719 ("extend GByteArray to read register helpers")

>> Signed-off-by: Peter Xu <peterx@redhat.com>

>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

>> Message-Id: <20200409164954.36902-3-peterx@redhat.com>

>> ---

>>   target/i386/gdbstub.c | 2 +-

>>   1 file changed, 1 insertion(+), 1 deletion(-)

>>

>> diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c

>> index f3d23b614ee..b98a99500ae 100644

>> --- a/target/i386/gdbstub.c

>> +++ b/target/i386/gdbstub.c

>> @@ -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;

>> -- 

>> 2.20.1

>>

>>

> 

> I had the following issue while attaching to qemu started with gdbserver

> listening:

> 


Alex, if possible can you amend this info please?

<---

> (gdb) target remote :1234

> Remote debugging using :1234

> Remote communication error.  Target disconnected.: Connection reset by peer.

> 

> $ qemu-system-x86_64 -m 1G -smp 4 ... -s

> ERROR:qemu/gdbstub.c:1843:handle_read_all_regs: assertion failed: (len == gdbserver_state.mem_buf->len)

> Bail out! ERROR:qemu/gdbstub.c:1843:handle_read_all_regs: assertion failed: (len == gdbserver_state.mem_buf->len)


--->

Thanks!

> 

> 

> Thanks to Philippe, I tried this patch and it solves my issue:

> 

> Tested-by: Stefano Garzarella <sgarzare@redhat.com>

> 

> Thanks,

> Stefano

> 

>
Stefano Garzarella April 14, 2020, 7:48 a.m. UTC | #5
On Sat, Apr 11, 2020 at 01:58:07PM +0100, Alex Bennée wrote:
> 

> Stefano Garzarella <sgarzare@redhat.com> writes:

> 

> > On Thu, Apr 09, 2020 at 10:15:27PM +0100, Alex Bennée wrote:

> >> From: Peter Xu <peterx@redhat.com>

> >> 

> >> 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.

> >> 

> >> Fixes: a010bdbe719 ("extend GByteArray to read register helpers")

> >> Signed-off-by: Peter Xu <peterx@redhat.com>

> >> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> >> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> >> Message-Id: <20200409164954.36902-3-peterx@redhat.com>

> >> ---

> >>  target/i386/gdbstub.c | 2 +-

> >>  1 file changed, 1 insertion(+), 1 deletion(-)

> >> 

> >> diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c

> >> index f3d23b614ee..b98a99500ae 100644

> >> --- a/target/i386/gdbstub.c

> >> +++ b/target/i386/gdbstub.c

> >> @@ -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;

> >> -- 

> >> 2.20.1

> >> 

> >>

> >

> > I had the following issue while attaching to qemu started with gdbserver

> > listening:

> >

> > (gdb) target remote :1234

> > Remote debugging using :1234

> > Remote communication error.  Target disconnected.: Connection reset by peer.

> >

> > $ qemu-system-x86_64 -m 1G -smp 4 ... -s

> > ERROR:qemu/gdbstub.c:1843:handle_read_all_regs: assertion failed: (len == gdbserver_state.mem_buf->len)

> > Bail out! ERROR:qemu/gdbstub.c:1843:handle_read_all_regs: assertion

> > failed: (len == gdbserver_state.mem_buf->len)

> 

> I'll see if the new gdb testcases can be generalised - they would have

> caught these snafus.


Yeah, that would be great!

Thanks,
Stefano
diff mbox series

Patch

diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c
index f3d23b614ee..b98a99500ae 100644
--- a/target/i386/gdbstub.c
+++ b/target/i386/gdbstub.c
@@ -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;