Skip to contentSkip to conversation

gdbstub: Fix segment fault for i386 target

PATCH In review Changbin Du 3 participants 3 messages Apr 12, 2020 – Apr 13, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gdbstub: Fix segment fault for i386 target

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")

---
v2: remove m68k fix since it's already queued.

---
 target/i386/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
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;
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw

Le 13/04/2020 à 01:32, Changbin Du a écrit :

Quoted 22 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")

---
v2: remove m68k fix since it's already queued.

---
 target/i386/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/gdbstub.c +0 -0
index f3d23b614e..b98a99500a 100644

target/i386/gdbstub.c int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) · line 112

Quoted 8 lines
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;
#2 lore raw
In reply to Changbin Du
Quoted 7 lines · Changbin Du

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.

Quoted 5 lines
Fixes a010bdbe71 ("gdbstub: extend GByteArray to read register helpers")

---
v2: remove m68k fix since it's already queued.

I also have Peter Xu's fix for i386:

https://patchew.org/QEMU/[email protected]/[email protected]/

But I'll happily add your Reported-by credit to that patch.

Quoted 17 lines
---
 target/i386/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
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;
Signature · 1 line
Alex Bennée