qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] linux-user/i386: Emulate orig_ax
@ 2024-08-02  9:59 Ilya Leoshkevich
  2024-08-02  9:59 ` [PATCH 1/5] include/exec: Introduce env_cpu_const() Ilya Leoshkevich
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Ilya Leoshkevich @ 2024-08-02  9:59 UTC (permalink / raw)
  To: Laurent Vivier, Alex Bennée, Philippe Mathieu-Daudé,
	Paolo Bonzini, Richard Henderson
  Cc: qemu-devel, Ilya Leoshkevich

Hi,

Currently gdbstub is barely usable with i386-linux-user: GDB cannot
even parse a shared library list, so no symbols are available. This
boils down to unavailability of info proc, which is gated behind
org.gnu.gdb.i386.linux. See amd64_linux_init_abi(); info proc is
enabled by amd64_linux_init_abi_common() -> linux_init_abi().

This series adds orig_ax support to the emulator and gdbstub, and
enables the existing test-proc-mappings.py on i386.

Best regards,
Ilya

Ilya Leoshkevich (5):
  include/exec: Introduce env_cpu_const()
  linux-user/i386: Emulate orig_ax
  target/i386/gdbstub: Factor out gdb_get_reg() and gdb_write_reg()
  target/i386/gdbstub: Expose orig_ax
  tests/tcg: Run test-proc-mappings.py on i386

 configs/targets/i386-linux-user.mak           |   2 +-
 configs/targets/x86_64-linux-user.mak         |   2 +-
 gdb-xml/i386-32bit-linux.xml                  |  11 ++
 gdb-xml/i386-64bit-linux.xml                  |  11 ++
 include/exec/cpu-common.h                     |  13 ++-
 linux-user/elfload.c                          |   6 +-
 linux-user/i386/cpu_loop.c                    |   3 +
 linux-user/qemu.h                             |   5 +
 target/i386/cpu.c                             |   1 +
 target/i386/cpu.h                             |   1 +
 target/i386/gdbstub.c                         | 103 ++++++++++++++----
 .../multiarch/gdbstub/test-proc-mappings.py   |  17 +--
 12 files changed, 137 insertions(+), 38 deletions(-)
 create mode 100644 gdb-xml/i386-32bit-linux.xml
 create mode 100644 gdb-xml/i386-64bit-linux.xml

-- 
2.45.2



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/5] include/exec: Introduce env_cpu_const()
  2024-08-02  9:59 [PATCH 0/4] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
@ 2024-08-02  9:59 ` Ilya Leoshkevich
  2024-09-08 19:46   ` Richard Henderson
  2024-08-02  9:59 ` [PATCH 2/5] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Ilya Leoshkevich @ 2024-08-02  9:59 UTC (permalink / raw)
  To: Laurent Vivier, Alex Bennée, Philippe Mathieu-Daudé,
	Paolo Bonzini, Richard Henderson
  Cc: qemu-devel, Ilya Leoshkevich

It's the same as env_cpu(), but for const objects.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 include/exec/cpu-common.h | 13 ++++++++++++-
 linux-user/elfload.c      |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 2e1b499cb71..638dc806a5f 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -238,6 +238,17 @@ static inline ArchCPU *env_archcpu(CPUArchState *env)
     return (void *)env - sizeof(CPUState);
 }
 
+/**
+ * env_cpu_const(env)
+ * @env: The architecture environment
+ *
+ * Return the CPUState associated with the environment.
+ */
+static inline const CPUState *env_cpu_const(const CPUArchState *env)
+{
+    return (void *)env - sizeof(CPUState);
+}
+
 /**
  * env_cpu(env)
  * @env: The architecture environment
@@ -246,7 +257,7 @@ static inline ArchCPU *env_archcpu(CPUArchState *env)
  */
 static inline CPUState *env_cpu(CPUArchState *env)
 {
-    return (void *)env - sizeof(CPUState);
+    return (CPUState *)env_cpu_const(env);
 }
 
 #ifndef CONFIG_USER_ONLY
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0861f115fc4..05292c27776 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -4329,7 +4329,7 @@ static int wmr_write_region(void *opaque, target_ulong start,
  */
 static int elf_core_dump(int signr, const CPUArchState *env)
 {
-    const CPUState *cpu = env_cpu((CPUArchState *)env);
+    const CPUState *cpu = env_cpu_const(env);
     const TaskState *ts = (const TaskState *)get_task_state((CPUState *)cpu);
     struct rlimit dumpsize;
     CountAndSizeRegions css;
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/5] linux-user/i386: Emulate orig_ax
  2024-08-02  9:59 [PATCH 0/4] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
  2024-08-02  9:59 ` [PATCH 1/5] include/exec: Introduce env_cpu_const() Ilya Leoshkevich
@ 2024-08-02  9:59 ` Ilya Leoshkevich
  2024-09-08 20:50   ` Richard Henderson
  2024-08-02  9:59 ` [PATCH 3/5] target/i386/gdbstub: Factor out gdb_get_reg() and gdb_write_reg() Ilya Leoshkevich
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Ilya Leoshkevich @ 2024-08-02  9:59 UTC (permalink / raw)
  To: Laurent Vivier, Alex Bennée, Philippe Mathieu-Daudé,
	Paolo Bonzini, Richard Henderson
  Cc: qemu-devel, Ilya Leoshkevich

The kernel uses orig_rax/orig_eax to store the syscall number before
a syscall. One can see this value in core dumps and ptrace.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 linux-user/elfload.c       | 4 ++--
 linux-user/i386/cpu_loop.c | 3 +++
 linux-user/qemu.h          | 5 +++++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 05292c27776..2d73382ae6b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -203,7 +203,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
     (*regs)[12] = tswapreg(env->regs[R_EDX]);
     (*regs)[13] = tswapreg(env->regs[R_ESI]);
     (*regs)[14] = tswapreg(env->regs[R_EDI]);
-    (*regs)[15] = tswapreg(env->regs[R_EAX]); /* XXX */
+    (*regs)[15] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax);
     (*regs)[16] = tswapreg(env->eip);
     (*regs)[17] = tswapreg(env->segs[R_CS].selector & 0xffff);
     (*regs)[18] = tswapreg(env->eflags);
@@ -306,7 +306,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
     (*regs)[8] = tswapreg(env->segs[R_ES].selector & 0xffff);
     (*regs)[9] = tswapreg(env->segs[R_FS].selector & 0xffff);
     (*regs)[10] = tswapreg(env->segs[R_GS].selector & 0xffff);
-    (*regs)[11] = tswapreg(env->regs[R_EAX]); /* XXX */
+    (*regs)[11] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax);
     (*regs)[12] = tswapreg(env->eip);
     (*regs)[13] = tswapreg(env->segs[R_CS].selector & 0xffff);
     (*regs)[14] = tswapreg(env->eflags);
diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index 92beb6830cc..7a35215278a 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -172,6 +172,7 @@ static void emulate_vsyscall(CPUX86State *env)
     /*
      * Perform the syscall.  None of the vsyscalls should need restarting.
      */
+    get_task_state(env_cpu(env))->orig_ax = syscall;
     ret = do_syscall(env, syscall, env->regs[R_EDI], env->regs[R_ESI],
                      env->regs[R_EDX], env->regs[10], env->regs[8],
                      env->regs[9], 0, 0);
@@ -221,6 +222,7 @@ void cpu_loop(CPUX86State *env)
         case EXCP_SYSCALL:
 #endif
             /* linux syscall from int $0x80 */
+            get_task_state(cs)->orig_ax = env->regs[R_EAX];
             ret = do_syscall(env,
                              env->regs[R_EAX],
                              env->regs[R_EBX],
@@ -239,6 +241,7 @@ void cpu_loop(CPUX86State *env)
 #ifdef TARGET_X86_64
         case EXCP_SYSCALL:
             /* linux syscall from syscall instruction.  */
+            get_task_state(cs)->orig_ax = env->regs[R_EAX];
             ret = do_syscall(env,
                              env->regs[R_EAX],
                              env->regs[R_EDI],
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index a2961f503f4..85ba5a53869 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -159,6 +159,11 @@ struct TaskState {
 
     /* Start time of task after system boot in clock ticks */
     uint64_t start_boottime;
+
+#if defined(TARGET_I386)
+    /* Last syscall number. */
+    target_ulong orig_ax;
+#endif
 };
 
 abi_long do_brk(abi_ulong new_brk);
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/5] target/i386/gdbstub: Factor out gdb_get_reg() and gdb_write_reg()
  2024-08-02  9:59 [PATCH 0/4] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
  2024-08-02  9:59 ` [PATCH 1/5] include/exec: Introduce env_cpu_const() Ilya Leoshkevich
  2024-08-02  9:59 ` [PATCH 2/5] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
@ 2024-08-02  9:59 ` Ilya Leoshkevich
  2024-09-08 20:57   ` Richard Henderson
  2024-08-02  9:59 ` [PATCH 4/5] target/i386/gdbstub: Expose orig_ax Ilya Leoshkevich
  2024-08-02  9:59 ` [PATCH 5/5] tests/tcg: Run test-proc-mappings.py on i386 Ilya Leoshkevich
  4 siblings, 1 reply; 11+ messages in thread
From: Ilya Leoshkevich @ 2024-08-02  9:59 UTC (permalink / raw)
  To: Laurent Vivier, Alex Bennée, Philippe Mathieu-Daudé,
	Paolo Bonzini, Richard Henderson
  Cc: qemu-devel, Ilya Leoshkevich

i386 gdbstub handles both i386 and x86_64. Factor out two functions
for reading and writing registers without knowing their bitness.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 target/i386/gdbstub.c | 52 ++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 21 deletions(-)

diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c
index 4acf485879e..ec64ab6c53f 100644
--- a/target/i386/gdbstub.c
+++ b/target/i386/gdbstub.c
@@ -96,6 +96,19 @@ static int gdb_write_reg_cs64(uint32_t hflags, uint8_t *buf, target_ulong *val)
     return 4;
 }
 
+static int gdb_get_reg(CPUX86State *env, GByteArray *mem_buf, target_ulong val)
+{
+    if (TARGET_LONG_BITS == 64) {
+        if (env->hflags & HF_CS64_MASK) {
+            return gdb_get_reg64(mem_buf, val);
+        } else {
+            return gdb_get_reg64(mem_buf, val & 0xffffffffUL);
+        }
+    } else {
+        return gdb_get_reg32(mem_buf, val);
+    }
+}
+
 int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -137,15 +150,7 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
     } else {
         switch (n) {
         case IDX_IP_REG:
-            if (TARGET_LONG_BITS == 64) {
-                if (env->hflags & HF_CS64_MASK) {
-                    return gdb_get_reg64(mem_buf, env->eip);
-                } else {
-                    return gdb_get_reg64(mem_buf, env->eip & 0xffffffffUL);
-                }
-            } else {
-                return gdb_get_reg32(mem_buf, env->eip);
-            }
+            return gdb_get_reg(env, mem_buf, env->eip);
         case IDX_FLAGS_REG:
             return gdb_get_reg32(mem_buf, env->eflags);
 
@@ -248,6 +253,22 @@ static int x86_cpu_gdb_load_seg(X86CPU *cpu, X86Seg sreg, uint8_t *mem_buf)
     return 4;
 }
 
+static int gdb_write_reg(CPUX86State *env, uint8_t *mem_buf, target_ulong *val)
+{
+    if (TARGET_LONG_BITS == 64) {
+        if (env->hflags & HF_CS64_MASK) {
+            *val = ldq_p(mem_buf);
+        } else {
+            *val = ldq_p(mem_buf) & 0xffffffffUL;
+        }
+        return 8;
+    } else {
+        *val &= ~0xffffffffUL;
+        *val |= (uint32_t)ldl_p(mem_buf);
+        return 4;
+    }
+}
+
 int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -288,18 +309,7 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     } else {
         switch (n) {
         case IDX_IP_REG:
-            if (TARGET_LONG_BITS == 64) {
-                if (env->hflags & HF_CS64_MASK) {
-                    env->eip = ldq_p(mem_buf);
-                } else {
-                    env->eip = ldq_p(mem_buf) & 0xffffffffUL;
-                }
-                return 8;
-            } else {
-                env->eip &= ~0xffffffffUL;
-                env->eip |= (uint32_t)ldl_p(mem_buf);
-                return 4;
-            }
+            return gdb_write_reg(env, mem_buf, &env->eip);
         case IDX_FLAGS_REG:
             env->eflags = ldl_p(mem_buf);
             return 4;
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/5] target/i386/gdbstub: Expose orig_ax
  2024-08-02  9:59 [PATCH 0/4] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
                   ` (2 preceding siblings ...)
  2024-08-02  9:59 ` [PATCH 3/5] target/i386/gdbstub: Factor out gdb_get_reg() and gdb_write_reg() Ilya Leoshkevich
@ 2024-08-02  9:59 ` Ilya Leoshkevich
  2024-09-08 21:00   ` Richard Henderson
  2024-08-02  9:59 ` [PATCH 5/5] tests/tcg: Run test-proc-mappings.py on i386 Ilya Leoshkevich
  4 siblings, 1 reply; 11+ messages in thread
From: Ilya Leoshkevich @ 2024-08-02  9:59 UTC (permalink / raw)
  To: Laurent Vivier, Alex Bennée, Philippe Mathieu-Daudé,
	Paolo Bonzini, Richard Henderson
  Cc: qemu-devel, Ilya Leoshkevich

Copy XML files describing orig_ax from GDB and glue them with
CPUX86State.orig_ax.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 configs/targets/i386-linux-user.mak   |  2 +-
 configs/targets/x86_64-linux-user.mak |  2 +-
 gdb-xml/i386-32bit-linux.xml          | 11 ++++++
 gdb-xml/i386-64bit-linux.xml          | 11 ++++++
 target/i386/cpu.c                     |  1 +
 target/i386/cpu.h                     |  1 +
 target/i386/gdbstub.c                 | 51 +++++++++++++++++++++++++++
 7 files changed, 77 insertions(+), 2 deletions(-)
 create mode 100644 gdb-xml/i386-32bit-linux.xml
 create mode 100644 gdb-xml/i386-64bit-linux.xml

diff --git a/configs/targets/i386-linux-user.mak b/configs/targets/i386-linux-user.mak
index 5b2546a4309..b72a156473a 100644
--- a/configs/targets/i386-linux-user.mak
+++ b/configs/targets/i386-linux-user.mak
@@ -1,4 +1,4 @@
 TARGET_ARCH=i386
 TARGET_SYSTBL_ABI=i386
 TARGET_SYSTBL=syscall_32.tbl
-TARGET_XML_FILES= gdb-xml/i386-32bit.xml
+TARGET_XML_FILES= gdb-xml/i386-32bit.xml gdb-xml/i386-32bit-linux.xml
diff --git a/configs/targets/x86_64-linux-user.mak b/configs/targets/x86_64-linux-user.mak
index 9ceefbb615a..86042814d39 100644
--- a/configs/targets/x86_64-linux-user.mak
+++ b/configs/targets/x86_64-linux-user.mak
@@ -2,4 +2,4 @@ TARGET_ARCH=x86_64
 TARGET_BASE_ARCH=i386
 TARGET_SYSTBL_ABI=common,64
 TARGET_SYSTBL=syscall_64.tbl
-TARGET_XML_FILES= gdb-xml/i386-64bit.xml
+TARGET_XML_FILES= gdb-xml/i386-64bit.xml gdb-xml/i386-64bit-linux.xml
diff --git a/gdb-xml/i386-32bit-linux.xml b/gdb-xml/i386-32bit-linux.xml
new file mode 100644
index 00000000000..5ffe5616e63
--- /dev/null
+++ b/gdb-xml/i386-32bit-linux.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2010-2024 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.i386.linux">
+  <reg name="orig_eax" bitsize="32" type="int"/>
+</feature>
diff --git a/gdb-xml/i386-64bit-linux.xml b/gdb-xml/i386-64bit-linux.xml
new file mode 100644
index 00000000000..0f26990d2f7
--- /dev/null
+++ b/gdb-xml/i386-64bit-linux.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2010-2024 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.i386.linux">
+  <reg name="orig_rax" bitsize="64" type="int"/>
+</feature>
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 85ef7452c04..52788e6170d 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7831,6 +7831,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
 
     mce_init(cpu);
 
+    x86_cpu_gdb_init(cs);
     qemu_init_vcpu(cs);
 
     /*
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index c6cc035df3d..f2819e91007 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2226,6 +2226,7 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags);
 
 int x86_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
 int x86_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
+void x86_cpu_gdb_init(CPUState *cs);
 
 void x86_cpu_list(void);
 int cpu_x86_support_mca_broadcast(CPUX86State *env);
diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c
index ec64ab6c53f..ff688bd26ed 100644
--- a/target/i386/gdbstub.c
+++ b/target/i386/gdbstub.c
@@ -18,8 +18,13 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
+#include "accel/tcg/vcpu-state.h"
 #include "cpu.h"
+#include "exec/gdbstub.h"
 #include "gdbstub/helpers.h"
+#ifdef CONFIG_LINUX_USER
+#include "linux-user/qemu.h"
+#endif
 
 #ifdef TARGET_X86_64
 static const int gpr_map[16] = {
@@ -407,3 +412,49 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     /* Unrecognised register.  */
     return 0;
 }
+
+#ifdef CONFIG_LINUX_USER
+
+#define IDX_ORIG_AX 0
+
+static int x86_cpu_gdb_read_linux_register(CPUState *cs, GByteArray *mem_buf,
+                                           int n)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    CPUX86State *env = &cpu->env;
+
+    switch (n) {
+    case IDX_ORIG_AX:
+        return gdb_get_reg(env, mem_buf, get_task_state(cs)->orig_ax);
+    }
+    return 0;
+}
+
+static int x86_cpu_gdb_write_linux_register(CPUState *cs, uint8_t *mem_buf,
+                                            int n)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    CPUX86State *env = &cpu->env;
+
+    switch (n) {
+    case IDX_ORIG_AX:
+        return gdb_write_reg(env, mem_buf, &get_task_state(cs)->orig_ax);
+    }
+    return 0;
+}
+
+#endif
+
+void x86_cpu_gdb_init(CPUState *cs)
+{
+#ifdef CONFIG_LINUX_USER
+    gdb_register_coprocessor(cs, x86_cpu_gdb_read_linux_register,
+                             x86_cpu_gdb_write_linux_register,
+#ifdef TARGET_X86_64
+                             gdb_find_static_feature("i386-64bit-linux.xml"),
+#else
+                             gdb_find_static_feature("i386-32bit-linux.xml"),
+#endif
+                             0);
+#endif
+}
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/5] tests/tcg: Run test-proc-mappings.py on i386
  2024-08-02  9:59 [PATCH 0/4] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
                   ` (3 preceding siblings ...)
  2024-08-02  9:59 ` [PATCH 4/5] target/i386/gdbstub: Expose orig_ax Ilya Leoshkevich
@ 2024-08-02  9:59 ` Ilya Leoshkevich
  2024-08-02 10:40   ` Alex Bennée
  4 siblings, 1 reply; 11+ messages in thread
From: Ilya Leoshkevich @ 2024-08-02  9:59 UTC (permalink / raw)
  To: Laurent Vivier, Alex Bennée, Philippe Mathieu-Daudé,
	Paolo Bonzini, Richard Henderson
  Cc: qemu-devel, Ilya Leoshkevich

Now that orig_ax is exposed and GDB is happy, don't skip
test-proc-mappings.py on i386. In fact, it's broken only on
m68k now, so skip only this architecture.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 .../tcg/multiarch/gdbstub/test-proc-mappings.py | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/tests/tcg/multiarch/gdbstub/test-proc-mappings.py b/tests/tcg/multiarch/gdbstub/test-proc-mappings.py
index 564613fabf0..0f687f3284a 100644
--- a/tests/tcg/multiarch/gdbstub/test-proc-mappings.py
+++ b/tests/tcg/multiarch/gdbstub/test-proc-mappings.py
@@ -8,17 +8,12 @@
 
 def run_test():
     """Run through the tests one by one"""
-    try:
-        mappings = gdb.execute("info proc mappings", False, True)
-    except gdb.error as exc:
-        exc_str = str(exc)
-        if "Not supported on this target." in exc_str:
-            # Detect failures due to an outstanding issue with how GDB handles
-            # the x86_64 QEMU's target.xml, which does not contain the
-            # definition of orig_rax. Skip the test in this case.
-            print("SKIP: {}".format(exc_str))
-            return
-        raise
+    if gdb.selected_inferior().architecture().name() == "m68k":
+        # m68k GDB supports only GDB_OSABI_SVR4, but GDB_OSABI_LINUX is
+        # required for the info proc support (see set_gdbarch_info_proc()).
+        print("SKIP: m68k GDB does not support GDB_OSABI_LINUX")
+        exit(0)
+    mappings = gdb.execute("info proc mappings", False, True)
     report(isinstance(mappings, str), "Fetched the mappings from the inferior")
     # Broken with host page size > guest page size
     # report("/sha1" in mappings, "Found the test binary name in the mappings")
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 5/5] tests/tcg: Run test-proc-mappings.py on i386
  2024-08-02  9:59 ` [PATCH 5/5] tests/tcg: Run test-proc-mappings.py on i386 Ilya Leoshkevich
@ 2024-08-02 10:40   ` Alex Bennée
  0 siblings, 0 replies; 11+ messages in thread
From: Alex Bennée @ 2024-08-02 10:40 UTC (permalink / raw)
  To: Ilya Leoshkevich
  Cc: Laurent Vivier, Philippe Mathieu-Daudé, Paolo Bonzini,
	Richard Henderson, qemu-devel

Ilya Leoshkevich <iii@linux.ibm.com> writes:

> Now that orig_ax is exposed and GDB is happy, don't skip
> test-proc-mappings.py on i386. In fact, it's broken only on
> m68k now, so skip only this architecture.
>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

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

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] include/exec: Introduce env_cpu_const()
  2024-08-02  9:59 ` [PATCH 1/5] include/exec: Introduce env_cpu_const() Ilya Leoshkevich
@ 2024-09-08 19:46   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2024-09-08 19:46 UTC (permalink / raw)
  To: Ilya Leoshkevich, Laurent Vivier, Alex Bennée,
	Philippe Mathieu-Daudé, Paolo Bonzini
  Cc: qemu-devel

On 8/2/24 02:59, Ilya Leoshkevich wrote:
> It's the same as env_cpu(), but for const objects.
> 
> Signed-off-by: Ilya Leoshkevich<iii@linux.ibm.com>
> ---
>   include/exec/cpu-common.h | 13 ++++++++++++-
>   linux-user/elfload.c      |  2 +-
>   2 files changed, 13 insertions(+), 2 deletions(-)

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

r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/5] linux-user/i386: Emulate orig_ax
  2024-08-02  9:59 ` [PATCH 2/5] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
@ 2024-09-08 20:50   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2024-09-08 20:50 UTC (permalink / raw)
  To: Ilya Leoshkevich, Laurent Vivier, Alex Bennée,
	Philippe Mathieu-Daudé, Paolo Bonzini
  Cc: qemu-devel

On 8/2/24 02:59, Ilya Leoshkevich wrote:
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index a2961f503f4..85ba5a53869 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -159,6 +159,11 @@ struct TaskState {
>   
>       /* Start time of task after system boot in clock ticks */
>       uint64_t start_boottime;
> +
> +#if defined(TARGET_I386)
> +    /* Last syscall number. */
> +    target_ulong orig_ax;
> +#endif

Maybe place this higher, in the existing TARGET_I386 block?

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


r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/5] target/i386/gdbstub: Factor out gdb_get_reg() and gdb_write_reg()
  2024-08-02  9:59 ` [PATCH 3/5] target/i386/gdbstub: Factor out gdb_get_reg() and gdb_write_reg() Ilya Leoshkevich
@ 2024-09-08 20:57   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2024-09-08 20:57 UTC (permalink / raw)
  To: Ilya Leoshkevich, Laurent Vivier, Alex Bennée,
	Philippe Mathieu-Daudé, Paolo Bonzini
  Cc: qemu-devel

On 8/2/24 02:59, Ilya Leoshkevich wrote:
> @@ -248,6 +253,22 @@ static int x86_cpu_gdb_load_seg(X86CPU *cpu, X86Seg sreg, uint8_t *mem_buf)
>       return 4;
>   }
>   
> +static int gdb_write_reg(CPUX86State *env, uint8_t *mem_buf, target_ulong *val)
> +{
> +    if (TARGET_LONG_BITS == 64) {
> +        if (env->hflags & HF_CS64_MASK) {
> +            *val = ldq_p(mem_buf);
> +        } else {
> +            *val = ldq_p(mem_buf) & 0xffffffffUL;
> +        }
> +        return 8;
> +    } else {
> +        *val &= ~0xffffffffUL;
> +        *val |= (uint32_t)ldl_p(mem_buf);
> +        return 4;
> +    }
> +}
> +
>   int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
>   {
>       X86CPU *cpu = X86_CPU(cs);
> @@ -288,18 +309,7 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
>       } else {
>           switch (n) {
>           case IDX_IP_REG:
> -            if (TARGET_LONG_BITS == 64) {
> -                if (env->hflags & HF_CS64_MASK) {
> -                    env->eip = ldq_p(mem_buf);
> -                } else {
> -                    env->eip = ldq_p(mem_buf) & 0xffffffffUL;
> -                }
> -                return 8;
> -            } else {
> -                env->eip &= ~0xffffffffUL;
> -                env->eip |= (uint32_t)ldl_p(mem_buf);
> -                return 4;
> -            }
> +            return gdb_write_reg(env, mem_buf, &env->eip);

Existing bug, but the insert in the !(TARGET_LONG_BITS == 64) case is silly.
Because TARGET_LONG_BITS == 32, target_ulong eip is 32-bits, so the "insert" doesn't 
really insert anything.

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


r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] target/i386/gdbstub: Expose orig_ax
  2024-08-02  9:59 ` [PATCH 4/5] target/i386/gdbstub: Expose orig_ax Ilya Leoshkevich
@ 2024-09-08 21:00   ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2024-09-08 21:00 UTC (permalink / raw)
  To: Ilya Leoshkevich, Laurent Vivier, Alex Bennée,
	Philippe Mathieu-Daudé, Paolo Bonzini
  Cc: qemu-devel

On 8/2/24 02:59, Ilya Leoshkevich wrote:
> Copy XML files describing orig_ax from GDB and glue them with
> CPUX86State.orig_ax.
> 
> Signed-off-by: Ilya Leoshkevich<iii@linux.ibm.com>
> ---
>   configs/targets/i386-linux-user.mak   |  2 +-
>   configs/targets/x86_64-linux-user.mak |  2 +-
>   gdb-xml/i386-32bit-linux.xml          | 11 ++++++
>   gdb-xml/i386-64bit-linux.xml          | 11 ++++++
>   target/i386/cpu.c                     |  1 +
>   target/i386/cpu.h                     |  1 +
>   target/i386/gdbstub.c                 | 51 +++++++++++++++++++++++++++
>   7 files changed, 77 insertions(+), 2 deletions(-)
>   create mode 100644 gdb-xml/i386-32bit-linux.xml
>   create mode 100644 gdb-xml/i386-64bit-linux.xml

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

r~


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-09-08 21:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02  9:59 [PATCH 0/4] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
2024-08-02  9:59 ` [PATCH 1/5] include/exec: Introduce env_cpu_const() Ilya Leoshkevich
2024-09-08 19:46   ` Richard Henderson
2024-08-02  9:59 ` [PATCH 2/5] linux-user/i386: Emulate orig_ax Ilya Leoshkevich
2024-09-08 20:50   ` Richard Henderson
2024-08-02  9:59 ` [PATCH 3/5] target/i386/gdbstub: Factor out gdb_get_reg() and gdb_write_reg() Ilya Leoshkevich
2024-09-08 20:57   ` Richard Henderson
2024-08-02  9:59 ` [PATCH 4/5] target/i386/gdbstub: Expose orig_ax Ilya Leoshkevich
2024-09-08 21:00   ` Richard Henderson
2024-08-02  9:59 ` [PATCH 5/5] tests/tcg: Run test-proc-mappings.py on i386 Ilya Leoshkevich
2024-08-02 10:40   ` Alex Bennée

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).