Skip to content

Commit ac2fb86

Browse files
iii-irth7680
authored andcommitted
target/i386/gdbstub: Expose orig_ax
Copy XML files describing orig_ax from GDB and glue them with CPUX86State.orig_ax. Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Ilya Leoshkevich <[email protected]> Message-ID: <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent e7a4427 commit ac2fb86

File tree

7 files changed

+77
-2
lines changed

7 files changed

+77
-2
lines changed

configs/targets/i386-linux-user.mak

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
TARGET_ARCH=i386
22
TARGET_SYSTBL_ABI=i386
33
TARGET_SYSTBL=syscall_32.tbl
4-
TARGET_XML_FILES= gdb-xml/i386-32bit.xml
4+
TARGET_XML_FILES= gdb-xml/i386-32bit.xml gdb-xml/i386-32bit-linux.xml

configs/targets/x86_64-linux-user.mak

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ TARGET_ARCH=x86_64
22
TARGET_BASE_ARCH=i386
33
TARGET_SYSTBL_ABI=common,64
44
TARGET_SYSTBL=syscall_64.tbl
5-
TARGET_XML_FILES= gdb-xml/i386-64bit.xml
5+
TARGET_XML_FILES= gdb-xml/i386-64bit.xml gdb-xml/i386-64bit-linux.xml

gdb-xml/i386-32bit-linux.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!-- Copyright (C) 2010-2024 Free Software Foundation, Inc.
3+
4+
Copying and distribution of this file, with or without modification,
5+
are permitted in any medium without royalty provided the copyright
6+
notice and this notice are preserved. -->
7+
8+
<!DOCTYPE feature SYSTEM "gdb-target.dtd">
9+
<feature name="org.gnu.gdb.i386.linux">
10+
<reg name="orig_eax" bitsize="32" type="int"/>
11+
</feature>

gdb-xml/i386-64bit-linux.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<!-- Copyright (C) 2010-2024 Free Software Foundation, Inc.
3+
4+
Copying and distribution of this file, with or without modification,
5+
are permitted in any medium without royalty provided the copyright
6+
notice and this notice are preserved. -->
7+
8+
<!DOCTYPE feature SYSTEM "gdb-target.dtd">
9+
<feature name="org.gnu.gdb.i386.linux">
10+
<reg name="orig_rax" bitsize="64" type="int"/>
11+
</feature>

target/i386/cpu.c

+1
Original file line numberDiff line numberDiff line change
@@ -7831,6 +7831,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
78317831

78327832
mce_init(cpu);
78337833

7834+
x86_cpu_gdb_init(cs);
78347835
qemu_init_vcpu(cs);
78357836

78367837
/*

target/i386/cpu.h

+1
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,7 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags);
22262226

22272227
int x86_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
22282228
int x86_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
2229+
void x86_cpu_gdb_init(CPUState *cs);
22292230

22302231
void x86_cpu_list(void);
22312232
int cpu_x86_support_mca_broadcast(CPUX86State *env);

target/i386/gdbstub.c

+51
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@
1818
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
1919
*/
2020
#include "qemu/osdep.h"
21+
#include "accel/tcg/vcpu-state.h"
2122
#include "cpu.h"
23+
#include "exec/gdbstub.h"
2224
#include "gdbstub/helpers.h"
25+
#ifdef CONFIG_LINUX_USER
26+
#include "linux-user/qemu.h"
27+
#endif
2328

2429
#ifdef TARGET_X86_64
2530
static const int gpr_map[16] = {
@@ -406,3 +411,49 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
406411
/* Unrecognised register. */
407412
return 0;
408413
}
414+
415+
#ifdef CONFIG_LINUX_USER
416+
417+
#define IDX_ORIG_AX 0
418+
419+
static int x86_cpu_gdb_read_linux_register(CPUState *cs, GByteArray *mem_buf,
420+
int n)
421+
{
422+
X86CPU *cpu = X86_CPU(cs);
423+
CPUX86State *env = &cpu->env;
424+
425+
switch (n) {
426+
case IDX_ORIG_AX:
427+
return gdb_get_reg(env, mem_buf, get_task_state(cs)->orig_ax);
428+
}
429+
return 0;
430+
}
431+
432+
static int x86_cpu_gdb_write_linux_register(CPUState *cs, uint8_t *mem_buf,
433+
int n)
434+
{
435+
X86CPU *cpu = X86_CPU(cs);
436+
CPUX86State *env = &cpu->env;
437+
438+
switch (n) {
439+
case IDX_ORIG_AX:
440+
return gdb_write_reg(env, mem_buf, &get_task_state(cs)->orig_ax);
441+
}
442+
return 0;
443+
}
444+
445+
#endif
446+
447+
void x86_cpu_gdb_init(CPUState *cs)
448+
{
449+
#ifdef CONFIG_LINUX_USER
450+
gdb_register_coprocessor(cs, x86_cpu_gdb_read_linux_register,
451+
x86_cpu_gdb_write_linux_register,
452+
#ifdef TARGET_X86_64
453+
gdb_find_static_feature("i386-64bit-linux.xml"),
454+
#else
455+
gdb_find_static_feature("i386-32bit-linux.xml"),
456+
#endif
457+
0);
458+
#endif
459+
}

0 commit comments

Comments
 (0)