Skip to contentSkip to conversation

gdbstub: Fix segment fault for i386 and m68k

PATCH Superseded Changbin Du 2 participants 3 messages Apr 12, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gdbstub: Fix segment fault for i386 and m68k

With GByteArray, we should pass the object itself but not to plus an offset.

gdb log:
Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:384
384 ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file or directory.

Fixes a010bdbe71 ("gdbstub: extend GByteArray to read register helpers")
---
 target/i386/gdbstub.c | 2 +-
 target/m68k/helper.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
target/i386/gdbstub.c +1 -1
index f3d23b614e..b98a99500a 100644
@@ -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;
target/m68k/helper.c +2 -2
index 014657c637..cad4083895 100644
@@ -109,8 +109,8 @@ static int m68k_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, int n)
 {
     if (n < 8) {
         int len = gdb_get_reg16(mem_buf, env->fregs[n].l.upper);
-        len += gdb_get_reg16(mem_buf + len, 0);
-        len += gdb_get_reg64(mem_buf + len, env->fregs[n].l.lower);
+        len += gdb_get_reg16(mem_buf, 0);
+        len += gdb_get_reg64(mem_buf, env->fregs[n].l.lower);
         return len;
     }
     switch (n) {
Signature · 1 line
2.25.1
#1 lore raw
CC Alex Bennée

The one for m68k is already queued by Alex.

Thanks,
Laurent

Le 12/04/2020 à 12:44, Changbin Du a écrit :

Quoted 43 lines

With GByteArray, we should pass the object itself but not to plus an offset.

gdb log:
Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. __memmove_avx_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:384
384 ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file or directory.

Fixes a010bdbe71 ("gdbstub: extend GByteArray to read register helpers")
---
 target/i386/gdbstub.c | 2 +-
 target/m68k/helper.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
target/i386/gdbstub.c +1 -1
index f3d23b614e..b98a99500a 100644
@@ -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;
target/m68k/helper.c +2 -2
index 014657c637..cad4083895 100644
@@ -109,8 +109,8 @@ static int m68k_fpu_gdb_get_reg(CPUM68KState *env, GByteArray *mem_buf, int n)
 {
     if (n < 8) {
         int len = gdb_get_reg16(mem_buf, env->fregs[n].l.upper);
-        len += gdb_get_reg16(mem_buf + len, 0);
-        len += gdb_get_reg64(mem_buf + len, env->fregs[n].l.lower);
+        len += gdb_get_reg16(mem_buf, 0);
+        len += gdb_get_reg64(mem_buf, env->fregs[n].l.lower);
         return len;
     }
     switch (n) {
#2 lore raw
Quoted 4 lines · Laurent Vivier
CC Alex Bennée

The one for m68k is already queued by Alex.

Great. I will send x86 fix only. Thanks!

Quoted 3 lines

Thanks,
Laurent

Signature · 2 lines
Cheers,
Changbin Du