* [PATCH 0/2] gdbstub: Unbreak i386 with gdb remote
@ 2020-04-09 16:49 Peter Xu
2020-04-09 16:49 ` [PATCH 1/2] gdbstub: Assert len read from each register Peter Xu
2020-04-09 16:49 ` [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Peter Xu
0 siblings, 2 replies; 9+ messages in thread
From: Peter Xu @ 2020-04-09 16:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Alex Bennée, peterx
It's silently broken on master during an refactoring. Let's fix it.
Please feel free to drop patch 1 if it's not rc material, but I guess
we want patch 2...
Thanks,
Peter Xu (2):
gdbstub: Assert len read from each register
gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
gdbstub.c | 11 ++++++++---
target/i386/gdbstub.c | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)
--
2.24.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] gdbstub: Assert len read from each register
2020-04-09 16:49 [PATCH 0/2] gdbstub: Unbreak i386 with gdb remote Peter Xu
@ 2020-04-09 16:49 ` Peter Xu
2020-04-09 17:51 ` Philippe Mathieu-Daudé
2020-04-09 16:49 ` [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Peter Xu
1 sibling, 1 reply; 9+ messages in thread
From: Peter Xu @ 2020-04-09 16:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Alex Bennée, peterx
This can expose the issue earlier on which register returned the wrong
result.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
gdbstub.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/gdbstub.c b/gdbstub.c
index 171e150950..f763545e81 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -911,17 +911,22 @@ 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);
}
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;
+
+ assert(len == buf->len - orig_len);
+
+ return len;
}
static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)
--
2.24.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
2020-04-09 16:49 [PATCH 0/2] gdbstub: Unbreak i386 with gdb remote Peter Xu
2020-04-09 16:49 ` [PATCH 1/2] gdbstub: Assert len read from each register Peter Xu
@ 2020-04-09 16:49 ` Peter Xu
2020-04-09 17:21 ` Philippe Mathieu-Daudé
2020-04-09 20:36 ` Alex Bennée
1 sibling, 2 replies; 9+ messages in thread
From: Peter Xu @ 2020-04-09 16:49 UTC (permalink / raw)
To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Alex Bennée, peterx
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 <alex.bennee@linaro.org>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Peter Xu <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 f3d23b614e..b98a99500a 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.24.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
2020-04-09 16:49 ` [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Peter Xu
@ 2020-04-09 17:21 ` Philippe Mathieu-Daudé
2020-04-09 18:01 ` Peter Xu
2020-04-09 20:36 ` Alex Bennée
1 sibling, 1 reply; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-09 17:21 UTC (permalink / raw)
To: Peter Xu, qemu-devel; +Cc: Alex Bennée
On 4/9/20 6:49 PM, Peter Xu wrote:
> 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.
You are correct.
Fixes: a010bdbe719 ("extend GByteArray to read register helpers")
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Same problem in m68k_fpu_gdb_get_reg().
TODO for 5.1, rename mem_buf -> array.
>
> Cc: Alex Bennée <alex.bennee@linaro.org>
> Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Peter Xu <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 f3d23b614e..b98a99500a 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;
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] gdbstub: Assert len read from each register
2020-04-09 16:49 ` [PATCH 1/2] gdbstub: Assert len read from each register Peter Xu
@ 2020-04-09 17:51 ` Philippe Mathieu-Daudé
2020-04-09 18:12 ` Peter Xu
0 siblings, 1 reply; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-09 17:51 UTC (permalink / raw)
To: Peter Xu, qemu-devel; +Cc: Alex Bennée
On 4/9/20 6:49 PM, Peter Xu wrote:
> This can expose the issue earlier on which register returned the wrong
> result.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
> gdbstub.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 171e150950..f763545e81 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -911,17 +911,22 @@ 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);
This change the code flow. We could add ...:
goto out;
> }
... or use else?
>
> 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)
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
2020-04-09 17:21 ` Philippe Mathieu-Daudé
@ 2020-04-09 18:01 ` Peter Xu
2020-04-09 19:29 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 9+ messages in thread
From: Peter Xu @ 2020-04-09 18:01 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: Alex Bennée, qemu-devel
Hi, Phil,
On Thu, Apr 09, 2020 at 07:21:04PM +0200, Philippe Mathieu-Daudé wrote:
> On 4/9/20 6:49 PM, Peter Xu wrote:
> > 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.
>
> You are correct.
>
> Fixes: a010bdbe719 ("extend GByteArray to read register helpers")
Oh I forgot to paste the fix line. However, is it b7b8756a9c
("target/i386: use gdb_get_reg helpers", 2020-03-17) instead?
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Thanks!
>
> Same problem in m68k_fpu_gdb_get_reg().
>
> TODO for 5.1, rename mem_buf -> array.
--
Peter Xu
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] gdbstub: Assert len read from each register
2020-04-09 17:51 ` Philippe Mathieu-Daudé
@ 2020-04-09 18:12 ` Peter Xu
0 siblings, 0 replies; 9+ messages in thread
From: Peter Xu @ 2020-04-09 18:12 UTC (permalink / raw)
To: Philippe Mathieu-Daudé; +Cc: Alex Bennée, qemu-devel
On Thu, Apr 09, 2020 at 07:51:49PM +0200, Philippe Mathieu-Daudé wrote:
> On 4/9/20 6:49 PM, Peter Xu wrote:
> > This can expose the issue earlier on which register returned the wrong
> > result.
> >
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > gdbstub.c | 11 ++++++++---
> > 1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/gdbstub.c b/gdbstub.c
> > index 171e150950..f763545e81 100644
> > --- a/gdbstub.c
> > +++ b/gdbstub.c
> > @@ -911,17 +911,22 @@ 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);
>
> This change the code flow. We could add ...:
I didn't expect the "if" and "for" would collapse each other, but yeah
that could still be better.
Thanks,
>
> goto out;
>
> > }
>
> ... or use else?
> > 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)
> >
>
--
Peter Xu
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
2020-04-09 18:01 ` Peter Xu
@ 2020-04-09 19:29 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-04-09 19:29 UTC (permalink / raw)
To: Peter Xu; +Cc: Alex Bennée, qemu-devel
On 4/9/20 8:01 PM, Peter Xu wrote:
> Hi, Phil,
>
> On Thu, Apr 09, 2020 at 07:21:04PM +0200, Philippe Mathieu-Daudé wrote:
>> On 4/9/20 6:49 PM, Peter Xu wrote:
>>> 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.
>>
>> You are correct.
>>
>> Fixes: a010bdbe719 ("extend GByteArray to read register helpers")
>
> Oh I forgot to paste the fix line. However, is it b7b8756a9c
> ("target/i386: use gdb_get_reg helpers", 2020-03-17) instead?
b7b8756a9c is correct, at that time the codebase was using the correct
API. the next commit updated the API but missed to update the lines you
are fixed. So I think "fixes a010bdbe719" is correct.
>
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>
> Thanks!
>
>>
>> Same problem in m68k_fpu_gdb_get_reg().
>>
>> TODO for 5.1, rename mem_buf -> array.
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb
2020-04-09 16:49 ` [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Peter Xu
2020-04-09 17:21 ` Philippe Mathieu-Daudé
@ 2020-04-09 20:36 ` Alex Bennée
1 sibling, 0 replies; 9+ messages in thread
From: Alex Bennée @ 2020-04-09 20:36 UTC (permalink / raw)
To: Peter Xu; +Cc: Philippe Mathieu-Daudé, qemu-devel
Peter Xu <peterx@redhat.com> writes:
> 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 <alex.bennee@linaro.org>
> Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Peter Xu <peterx@redhat.com>
Queued to for-5.0/more-random-fixes, thanks.
> ---
> 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 f3d23b614e..b98a99500a 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;
--
Alex Bennée
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-04-09 20:36 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 16:49 [PATCH 0/2] gdbstub: Unbreak i386 with gdb remote Peter Xu
2020-04-09 16:49 ` [PATCH 1/2] gdbstub: Assert len read from each register Peter Xu
2020-04-09 17:51 ` Philippe Mathieu-Daudé
2020-04-09 18:12 ` Peter Xu
2020-04-09 16:49 ` [PATCH 2/2] gdbstub: i386: Fix gdb_get_reg16() parameter to unbreak gdb Peter Xu
2020-04-09 17:21 ` Philippe Mathieu-Daudé
2020-04-09 18:01 ` Peter Xu
2020-04-09 19:29 ` Philippe Mathieu-Daudé
2020-04-09 20:36 ` Alex Bennée
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.