gdbstub/next: re-organise and split build
Subsystems (3)
v4 cover gdbstub/next: re-organise and split build
I was motivated to sort this out while working on my register API which is target agnostic but ran into the weeds when trying to link up with the gdbstub. This was due to us building gdbstub for every single target we support due to a few ABI sensitive bits that require CPU specific information. This series does a bunch of surgery to break the monolithic file apart into its constituent parts as well as simplify the headers to users can avoid bringing in more dependencies than they need.
I had hoped to go all the way and conditionally compile syscalls only for the two ABIs (32 and 64 bit) unfortunately I was unable to the appropriate meson-foo to make that happen.
This version is mostly just minor clean-ups and tag updates including a few extra code motion and checkpatch cleanup patches. The biggest change is replacing the probe shell script with a slightly smarter python one and adding Mad's accelops patch.
The following patches need review:
- gdbstub: split out softmmu/user specifics for syscall handling
- testing: probe gdb for supported architectures ahead of time
- gdbstub: only compile gdbstub twice for whole build
- gdbstub: clean-up indent on gdb_exit
Alex Bennée (24):
gdbstub/internals.h: clean up include guard
gdbstub: fix-up copyright and license files
gdbstub: clean-up indent on gdb_exit
gdbstub: define separate user/system structures
gdbstub: move GDBState to shared internals header
includes: move tb_flush into its own header
gdbstub: move fromhex/tohex routines to internals
gdbstub: make various helpers visible to the rest of the module
gdbstub: move chunk of softmmu functionality to own file
gdbstub: move chunks of user code into own files
gdbstub: rationalise signal mapping in softmmu
gdbstub: abstract target specific details from gdb_put_packet_binary
gdbstub: specialise handle_query_attached
gdbstub: specialise target_memory_rw_debug
gdbstub: introduce gdb_get_max_cpus
gdbstub: specialise stub_can_reverse
gdbstub: fix address type of gdb_set_cpu_pc
gdbstub: don't use target_ulong while handling registers
gdbstub: move register helpers into standalone include
gdbstub: move syscall handling to new file
gdbstub: only compile gdbstub twice for whole build
testing: probe gdb for supported architectures ahead of time
include: split target_long definition from cpu-defs
gdbstub: split out softmmu/user specifics for syscall handling
Mads Ynddal (1):
gdbstub: move update guest debug to accel ops
Philippe Mathieu-Daudé (1):
gdbstub: Make syscall_complete/[gs]et_reg target-agnostic typedefs
MAINTAINERS | 4 + configure | 8 + gdbstub/internals.h | 214 ++- include/exec/cpu-defs.h | 19 +- include/exec/exec-all.h | 1 - include/exec/gdbstub.h | 208 --- include/exec/target_long.h | 42 + include/exec/tb-flush.h | 26 + include/gdbstub/helpers.h | 103 + include/gdbstub/syscalls.h | 124 ++ include/gdbstub/user.h | 43 + include/sysemu/accel-ops.h | 1 + linux-user/user-internals.h | 1 + accel/kvm/kvm-accel-ops.c | 8 + accel/stubs/tcg-stub.c | 1 + accel/tcg/tb-maint.c | 1 + accel/tcg/translate-all.c | 1 + cpu.c | 12 +- gdbstub/gdbstub.c | 1655 ++--------------- gdbstub/softmmu.c | 613 +++++- gdbstub/syscalls.c | 221 +++ gdbstub/user-target.c | 283 +++ gdbstub/user.c | 433 ++++- hw/ppc/spapr_hcall.c | 1 + linux-user/exit.c | 2 +- linux-user/main.c | 1 + linux-user/signal.c | 2 +- plugins/core.c | 1 + plugins/loader.c | 2 +- semihosting/arm-compat-semi.c | 1 + semihosting/guestfd.c | 2 +- semihosting/syscalls.c | 3 +- softmmu/runstate.c | 2 +- target/alpha/gdbstub.c | 2 +- target/alpha/sys_helper.c | 1 + target/arm/gdbstub.c | 1 + target/arm/gdbstub64.c | 2 +- target/arm/tcg/helper-a64.c | 2 +- target/arm/tcg/m_helper.c | 1 + target/avr/gdbstub.c | 2 +- target/cris/gdbstub.c | 2 +- target/hexagon/gdbstub.c | 2 +- target/hppa/gdbstub.c | 2 +- target/i386/gdbstub.c | 2 +- target/i386/whpx/whpx-all.c | 2 +- target/loongarch/gdbstub.c | 1 + target/m68k/gdbstub.c | 2 +- target/m68k/helper.c | 1 + target/m68k/m68k-semi.c | 3 +- target/microblaze/gdbstub.c | 2 +- target/mips/gdbstub.c | 2 +- target/mips/tcg/sysemu/mips-semi.c | 3 +- target/nios2/cpu.c | 2 +- target/nios2/nios2-semi.c | 3 +- target/openrisc/gdbstub.c | 2 +- target/openrisc/interrupt.c | 2 +- target/openrisc/mmu.c | 2 +- target/ppc/cpu_init.c | 2 +- target/ppc/gdbstub.c | 1 + target/riscv/csr.c | 1 + target/riscv/gdbstub.c | 1 + target/rx/gdbstub.c | 2 +- target/s390x/gdbstub.c | 1 + target/s390x/helper.c | 2 +- target/sh4/gdbstub.c | 2 +- target/sparc/gdbstub.c | 2 +- target/tricore/gdbstub.c | 2 +- target/xtensa/core-dc232b.c | 2 +- target/xtensa/core-dc233c.c | 2 +- target/xtensa/core-de212.c | 2 +- target/xtensa/core-de233_fpu.c | 2 +- target/xtensa/core-dsp3400.c | 2 +- target/xtensa/core-fsf.c | 2 +- target/xtensa/core-lx106.c | 2 +- target/xtensa/core-sample_controller.c | 2 +- target/xtensa/core-test_kc705_be.c | 2 +- target/xtensa/core-test_mmuhifi_c3.c | 2 +- target/xtensa/gdbstub.c | 2 +- target/xtensa/helper.c | 2 +- gdbstub/meson.build | 35 +- gdbstub/trace-events | 4 +- scripts/probe-gdb-support.py | 88 + target/xtensa/import_core.sh | 2 +- tests/tcg/aarch64/Makefile.target | 2 +- tests/tcg/multiarch/Makefile.target | 5 + .../multiarch/system/Makefile.softmmu-target | 6 +- tests/tcg/s390x/Makefile.target | 2 +- 87 files changed, 2470 insertions(+), 1799 deletions(-) create mode 100644 include/exec/target_long.h create mode 100644 include/exec/tb-flush.h create mode 100644 include/gdbstub/helpers.h create mode 100644 include/gdbstub/syscalls.h create mode 100644 include/gdbstub/user.h create mode 100644 gdbstub/syscalls.c create mode 100644 gdbstub/user-target.c create mode 100755 scripts/probe-gdb-support.py
Signature · 1 line
2.39.2
PATCH v4 1/26 gdbstub/internals.h: clean up include guard
Use something more specific to avoid name clashes.
--- gdbstub/internals.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
gdbstub/internals.h +3 -3
@@ -6,8 +6,8 @@* SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef _INTERNALS_H_ -#define _INTERNALS_H_ +#ifndef GDBSTUB_INTERNALS_H +#define GDBSTUB_INTERNALS_H #include "exec/cpu-common.h"
@@ -16,4 +16,4 @@ int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len);int gdb_breakpoint_remove (CPUState *cs,int type,vaddr addr,vaddr len);void gdb_breakpoint_remove_all (CPUState *cs); -#endif /* _INTERNALS_H_ */ +#endif /* GDBSTUB_INTERNALS_H */
Signature · 1 line
2.39.2
PATCH v4 2/26 gdbstub: fix-up copyright and license files
In reply to Alex BennéeWhen I started splitting gdbstub apart I was a little too boilerplate with my file headers. Fix up to carry over Fabrice's copyright and the LGPL license header.
--- gdbstub/softmmu.c | 3 ++- gdbstub/user.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
gdbstub/softmmu.c +2 -1
@@ -4,9 +4,10 @@* Debug integration depends on support from the individual * accelerators so most of this involves calling the ops helpers. * +* Copyright (c) 2003-2005 Fabrice Bellard * Copyright (c) 2022 Linaro Ltd * -* SPDX-License-Identifier: GPL-2.0-or-later +* SPDX-License-Identifier: LGPL-2.0+ */ #include "qemu/osdep.h"
gdbstub/user.c +2 -1
@@ -3,9 +3,10 @@* * We know for user-mode we are using TCG so we can call stuff directly. * +* Copyright (c) 2003-2005 Fabrice Bellard * Copyright (c) 2022 Linaro Ltd * -* SPDX-License-Identifier: GPL-2.0-or-later +* SPDX-License-Identifier: LGPL-2.0+ */ #include "qemu/osdep.h"
Signature · 1 line
2.39.2
PATCH v4 3/26 gdbstub: Make syscall_complete/[gs]et_reg target-agnostic typedefs
In reply to Alex BennéeFrom: Philippe Mathieu-Daudé <[email protected]>
Prototypes using gdb_syscall_complete_cb() or gdb_?et_reg_cb() don't depend on "cpu.h", thus are not target-specific.
Message-Id: <[email protected]>
--- include/exec/gdbstub.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/exec/gdbstub.h +4 -3
@@ -71,9 +71,6 @@ struct gdb_timeval {uint64_t tv_usec;/* microsecond */ }QEMU_PACKED ; -#ifdef NEED_CPU_H -#include "cpu.h" -typedef void (*gdb_syscall_complete_cb )(CPUState *cpu,uint64_t ret,int err);/**
@@ -126,6 +123,7 @@ int gdb_handlesig(CPUState *, int);void gdb_signalled (CPUArchState *,int );void gdbserver_fork (CPUState *);#endif +/* Get or set a register. Returns the size of the register. */ typedef int (*gdb_get_reg_cb )(CPUArchState *env,GByteArray *buf,int reg);typedef int (*gdb_set_reg_cb )(CPUArchState *env,uint8_t *buf,int reg);
@@ -133,6 +131,9 @@ void gdb_register_coprocessor(CPUState *cpu, gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg, int num_regs, const char *xml, int g_pos); +#ifdef NEED_CPU_H +#include "cpu.h" +/* * The GDB remote protocol transfers values in target byte order. As * the gdbstub may be batching up several register values we always
Signature · 1 line
2.39.2
PATCH v4 4/26 gdbstub: clean-up indent on gdb_exit
In reply to Alex BennéeOtherwise checkpatch will throw a hissy fit on the later patches that split this function up.
--- gdbstub/gdbstub.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
gdbstub/gdbstub.c +14 -14
@@ -3021,27 +3021,27 @@ static void gdb_read_byte(uint8_t ch)/* Tell the remote gdb that the process has exited. */ void gdb_exit (int code) { -char buf[4 ]; +char buf[4 ]; -if (!gdbserver_state.init) { -return ; - } +if (!gdbserver_state.init) { +return ; + }#ifdef CONFIG_USER_ONLY -if (gdbserver_state.socket_path) { -unlink (gdbserver_state.socket_path); - } -if (gdbserver_state.fd <0 ) { -return ; - } +if (gdbserver_state.socket_path) { +unlink (gdbserver_state.socket_path); + } +if (gdbserver_state.fd <0 ) { +return ; + }#endif -trace_gdbstub_op_exiting ((uint8_t )code); +trace_gdbstub_op_exiting ((uint8_t )code); -snprintf (buf,sizeof (buf),"W%02x" , (uint8_t )code); -put_packet (buf); +snprintf (buf,sizeof (buf),"W%02x" , (uint8_t )code); +put_packet (buf);#ifndef CONFIG_USER_ONLY -qemu_chr_fe_deinit (&gdbserver_state.chr, true); +qemu_chr_fe_deinit (&gdbserver_state.chr, true);#endif }
Signature · 1 line
2.39.2
Re: [PATCH v4 04/26] gdbstub: clean-up indent on gdb_exit
Quoted 7 lines · Alex Bennée
Otherwise checkpatch will throw a hissy fit on the later patches that split this function up.
Signed-off-by Alex Bennée<[email protected]>--- gdbstub/gdbstub.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
r~
Re: [PATCH v4 04/26] gdbstub: clean-up indent on gdb_exit
In reply to Alex BennéeQuoted 5 lines · Alex Bennée
Otherwise checkpatch will throw a hissy fit on the later patches that split this function up.
Signed-off-by Alex Bennée <[email protected]>---
Quoted 49 lines
gdbstub/gdbstub.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)gdbstub/gdbstub.c +14
-14@@ -3021,27 +3021,27 @@ static void gdb_read_byte(uint8_t ch)/* Tell the remote gdb that the process has exited. */ void gdb_exit (int code) { -char buf[4 ]; +char buf[4 ]; -if (!gdbserver_state.init) { -return ; - } +if (!gdbserver_state.init) { +return ; + }#ifdef CONFIG_USER_ONLY -if (gdbserver_state.socket_path) { -unlink (gdbserver_state.socket_path); - } -if (gdbserver_state.fd <0 ) { -return ; - } +if (gdbserver_state.socket_path) { +unlink (gdbserver_state.socket_path); + } +if (gdbserver_state.fd <0 ) { +return ; + }#endif -trace_gdbstub_op_exiting ((uint8_t )code); +trace_gdbstub_op_exiting ((uint8_t )code); -snprintf (buf,sizeof (buf),"W%02x" , (uint8_t )code); -put_packet (buf); +snprintf (buf,sizeof (buf),"W%02x" , (uint8_t )code); +put_packet (buf);#ifndef CONFIG_USER_ONLY -qemu_chr_fe_deinit (&gdbserver_state.chr, true); +qemu_chr_fe_deinit (&gdbserver_state.chr, true);#endif }
PATCH v4 5/26 gdbstub: define separate user/system structures
In reply to Alex BennéeIn preparation for moving user/softmmu specific bits from the main gdbstub file we need to separate the connection details into a user/softmmu state. As these will eventually be defined in their own files we move them out of the common GDBState structure.
---
v3
- split into gdbserver_[user|system]_state now to avoid later hoop jumping
--- gdbstub/gdbstub.c | 94 ++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 41 deletions(-)
gdbstub/gdbstub.c +53 -41
@@ -341,6 +341,22 @@ enum RSState {RS_CHKSUM1 , RS_CHKSUM2, }; + +#ifdef CONFIG_USER_ONLY +typedef struct { +int fd; +char *socket_path; +int running_state; +}GDBUserState ; +static GDBUserState gdbserver_user_state; +#else +typedef struct { +CharBackend chr; +Chardev *mon_chr; +}GDBSystemState ; +static GDBSystemState gdbserver_system_state; +#endif + typedef struct GDBState { bool init; /* have we been initialised? */ CPUState *c_cpu; /* current CPU for step/continue ops */
@@ -353,14 +369,6 @@ typedef struct GDBState {int line_csum;/* checksum at the end of the packet */ GByteArray *last_packet;int signal; -#ifdef CONFIG_USER_ONLY -int fd; -char *socket_path; -int running_state; -#else -CharBackend chr; -Chardev *mon_chr; -#endif bool multiprocess;GDBProcess *processes;int process_num;
@@ -412,15 +420,17 @@ static int get_char(void)int ret;for (;;) { - ret =recv (gdbserver_state.fd, &ch,1 ,0 ); + ret =recv (gdbserver_user_state.fd, &ch,1 ,0 );if (ret <0 ) { -if (errno ==ECONNRESET ) - gdbserver_state.fd =-1 ; -if (errno !=EINTR ) +if (errno ==ECONNRESET ) { + gdbserver_user_state.fd =-1 ; + } +if (errno !=EINTR ) {return -1 ; + } }else if (ret ==0 ) { -close (gdbserver_state.fd); - gdbserver_state.fd =-1 ; +close (gdbserver_user_state.fd); + gdbserver_user_state.fd =-1 ;return -1 ; }else {break ;
@@ -479,7 +489,7 @@ static inline void gdb_continue(void) {#ifdef CONFIG_USER_ONLY - gdbserver_state.running_state =1 ; + gdbserver_user_state.running_state =1 ;trace_gdbstub_op_continue ();#else if (!runstate_needs_reset ()) {
@@ -508,7 +518,7 @@ static int gdb_continue_partial(char *newstates) cpu_single_step(cpu, gdbserver_state.sstep_flags); } } - gdbserver_state.running_state =1 ; + gdbserver_user_state.running_state =1 ;#else int flag =0 ;
@@ -560,7 +570,7 @@ static void put_buffer(const uint8_t *buf, int len)int ret;while (len >0 ) { - ret =send (gdbserver_state.fd, buf, len,0 ); + ret =send (gdbserver_user_state.fd, buf, len,0 );if (ret <0 ) {if (errno !=EINTR )return ;
@@ -572,7 +582,7 @@ static void put_buffer(const uint8_t *buf, int len)#else /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ -qemu_chr_fe_write_all (&gdbserver_state.chr, buf, len); +qemu_chr_fe_write_all (&gdbserver_system_state.chr, buf, len);#endif }
@@ -2094,7 +2104,8 @@ static void handle_query_rcmd(GArray *params, void *user_ctx) len = len /2 ;hextomem (gdbserver_state.mem_buf,get_param (params,0 )->data, len);g_byte_array_append (gdbserver_state.mem_buf, &zero,1 ); -qemu_chr_be_write (gdbserver_state.mon_chr, gdbserver_state.mem_buf->data, +qemu_chr_be_write (gdbserver_system_state.mon_chr, + gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len);put_packet ("OK" ); }
@@ -3027,10 +3038,10 @@ void gdb_exit(int code)return ; }#ifdef CONFIG_USER_ONLY -if (gdbserver_state.socket_path) { -unlink (gdbserver_state.socket_path); +if (gdbserver_user_state.socket_path) { +unlink (gdbserver_user_state.socket_path); } -if (gdbserver_state.fd <0 ) { +if (gdbserver_user_state.fd <0 ) {return ; }#endif
@@ -3041,7 +3052,7 @@ void gdb_exit(int code)put_packet (buf);#ifndef CONFIG_USER_ONLY -qemu_chr_fe_deinit (&gdbserver_state.chr, true); +qemu_chr_fe_deinit (&gdbserver_system_state.chr, true);#endif }
@@ -3077,7 +3088,7 @@ gdb_handlesig(CPUState *cpu, int sig)char buf[256 ];int n; -if (!gdbserver_state.init || gdbserver_state.fd <0 ) { +if (!gdbserver_state.init || gdbserver_user_state.fd <0 ) {return sig; }
@@ -3095,15 +3106,15 @@ gdb_handlesig(CPUState *cpu, int sig) }/* put_packet() might have detected that the peer terminated the connection. */ -if (gdbserver_state.fd <0 ) { +if (gdbserver_user_state.fd <0 ) {return sig; } sig =0 ; gdbserver_state.state =RS_IDLE ; - gdbserver_state.running_state =0 ; -while (gdbserver_state.running_state ==0 ) { - n =read (gdbserver_state.fd, buf,256 ); + gdbserver_user_state.running_state =0 ; +while (gdbserver_user_state.running_state ==0 ) { + n =read (gdbserver_user_state.fd, buf,256 );if (n >0 ) {int i;
@@ -3114,9 +3125,9 @@ gdb_handlesig(CPUState *cpu, int sig)/* XXX: Connection closed. Should probably wait for another connection before continuing. */ if (n ==0 ) { -close (gdbserver_state.fd); +close (gdbserver_user_state.fd); } - gdbserver_state.fd =-1 ; + gdbserver_user_state.fd =-1 ;return sig; } }
@@ -3130,7 +3141,7 @@ void gdb_signalled(CPUArchState *env, int sig) {char buf[4 ]; -if (!gdbserver_state.init || gdbserver_state.fd <0 ) { +if (!gdbserver_state.init || gdbserver_user_state.fd <0 ) {return ; }
@@ -3145,7 +3156,7 @@ static void gdb_accept_init(int fd) gdbserver_state.processes[0 ].attached = true; gdbserver_state.c_cpu =gdb_first_attached_cpu (); gdbserver_state.g_cpu = gdbserver_state.c_cpu; - gdbserver_state.fd = fd; + gdbserver_user_state.fd = fd; gdb_has_xml = false; }
@@ -3277,7 +3288,7 @@ int gdbserver_start(const char *port_or_path)if (port >0 &&gdb_accept_tcp (gdb_fd)) {return 0 ; }else if (gdb_accept_socket (gdb_fd)) { - gdbserver_state.socket_path =g_strdup (port_or_path); + gdbserver_user_state.socket_path =g_strdup (port_or_path);return 0 ; }
@@ -3289,11 +3300,11 @@ int gdbserver_start(const char *port_or_path)/* Disable gdb stub for child processes. */ void gdbserver_fork (CPUState *cpu) { -if (!gdbserver_state.init || gdbserver_state.fd <0 ) { +if (!gdbserver_state.init || gdbserver_user_state.fd <0 ) {return ; } -close (gdbserver_state.fd); - gdbserver_state.fd =-1 ; +close (gdbserver_user_state.fd); + gdbserver_user_state.fd =-1 ;cpu_breakpoint_remove_all (cpu,BP_GDB );cpu_watchpoint_remove_all (cpu,BP_GDB ); }
@@ -3487,21 +3498,22 @@ int gdbserver_start(const char *device) NULL, NULL, &error_abort);monitor_init_hmp (mon_chr, false, &error_abort); }else { -qemu_chr_fe_deinit (&gdbserver_state.chr, true); - mon_chr = gdbserver_state.mon_chr; +qemu_chr_fe_deinit (&gdbserver_system_state.chr, true); + mon_chr = gdbserver_system_state.mon_chr;reset_gdbserver_state (); }create_processes (&gdbserver_state);if (chr) { -qemu_chr_fe_init (&gdbserver_state.chr, chr, &error_abort); -qemu_chr_fe_set_handlers (&gdbserver_state.chr, gdb_chr_can_receive, +qemu_chr_fe_init (&gdbserver_system_state.chr, chr, &error_abort); +qemu_chr_fe_set_handlers (&gdbserver_system_state.chr, + gdb_chr_can_receive, gdb_chr_receive, gdb_chr_event,NULL , &gdbserver_state,NULL , true); } gdbserver_state.state = chr ?RS_IDLE :RS_INACTIVE ; - gdbserver_state.mon_chr = mon_chr; + gdbserver_system_state.mon_chr = mon_chr; gdbserver_state.current_syscall_cb =NULL ;return 0 ;
Signature · 1 line
2.39.2
PATCH v4 6/26 gdbstub: move GDBState to shared internals header
In reply to Alex BennéeWe are about to split softmmu and user mode helpers into different files. To facilitate this we will need to share access to the GDBState between those files.
---
v3
- as we split user/system state earlier we can remove the #define hack
--- gdbstub/internals.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ gdbstub/gdbstub.c | 42 ------------------------------------- 2 files changed, 50 insertions(+), 42 deletions(-)
gdbstub/internals.h +50 -0
@@ -11,6 +11,56 @@#include "exec/cpu-common.h" +#define MAX_PACKET_LENGTH 4096 + +/* +* Shared structures and definitions +*/ + +typedef struct GDBProcess { +uint32_t pid; +bool attached; + +char target_xml[1024 ]; +}GDBProcess ; + +enum RSState { +RS_INACTIVE , +RS_IDLE , +RS_GETLINE , +RS_GETLINE_ESC , +RS_GETLINE_RLE , +RS_CHKSUM1 , +RS_CHKSUM2 , +}; + +typedef struct GDBState { +bool init;/* have we been initialised? */ +CPUState *c_cpu;/* current CPU for step/continue ops */ +CPUState *g_cpu;/* current CPU for other ops */ +CPUState *query_cpu;/* for q{f|s}ThreadInfo */ +enum RSState state;/* parsing state */ +char line_buf[MAX_PACKET_LENGTH ]; +int line_buf_index; +int line_sum;/* running checksum */ +int line_csum;/* checksum at the end of the packet */ +GByteArray *last_packet; +int signal; +bool multiprocess; +GDBProcess *processes; +int process_num; +char syscall_buf[256 ]; +gdb_syscall_complete_cb current_syscall_cb; +GString *str_buf; +GByteArray *mem_buf; +int sstep_flags; +int supported_sstep_flags; +}GDBState ; + +/* +* Break/Watch point support - there is an implementation for softmmu +* and user mode. +*/ bool gdb_supports_guest_debug (void );int gdb_breakpoint_insert (CPUState *cs,int type,vaddr addr,vaddr len);int gdb_breakpoint_remove (CPUState *cs,int type,vaddr addr,vaddr len);
gdbstub/gdbstub.c +0 -42
60 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v4 7/26 includes: move tb_flush into its own header
In reply to Alex BennéeThis aids subsystems (like gdbstub) that want to trigger a flush without pulling target specific headers.
---
v2
- actually include the header and rename to tb-flush.h
- better kerneldoc style comment for the function
v4
- update MAINTAINERS
--- MAINTAINERS | 1 + include/exec/exec-all.h | 1 - include/exec/tb-flush.h | 26 ++++++++++++++++++++++++++ linux-user/user-internals.h | 1 + accel/stubs/tcg-stub.c | 1 + accel/tcg/tb-maint.c | 1 + accel/tcg/translate-all.c | 1 + cpu.c | 1 + gdbstub/gdbstub.c | 2 ++ hw/ppc/spapr_hcall.c | 1 + plugins/core.c | 1 + plugins/loader.c | 2 +- target/alpha/sys_helper.c | 1 + target/riscv/csr.c | 1 + 14 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 include/exec/tb-flush.h
MAINTAINERS +1 -0
@@ -136,6 +136,7 @@ F: docs/devel/decodetree.rst F: docs/devel/tcg* F: include/exec/cpu*.h F: include/exec/exec-all.h +F: include/exec/tb-flush.h F: include/exec/helper*.h F: include/sysemu/cpus.h F: include/sysemu/tcg.h
include/exec/exec-all.h +0 -1
@@ -677,7 +677,6 @@ void tb_invalidate_phys_addr(target_ulong addr);#else void tb_invalidate_phys_addr (AddressSpace *as,hwaddr addr,MemTxAttrs attrs);#endif -void tb_flush (CPUState *cpu);void tb_phys_invalidate (TranslationBlock *tb,tb_page_addr_t page_addr);void tb_invalidate_phys_range (tb_page_addr_t start,tb_page_addr_t end);void tb_set_jmp_target (TranslationBlock *tb,int n,uintptr_t addr);
include/exec/tb-flush.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* tb-flush prototype for use by the rest of the system. +* +* Copyright (c) 2022 Linaro Ltd +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef _TB_FLUSH_H_ +#define _TB_FLUSH_H_ + +/** +* tb_flush() - flush all translation blocks +* @cs: CPUState (must be valid, but treated as anonymous pointer) +* +* Used to flush all the translation blocks in the system. Sometimes +* it is simpler to flush everything than work out which individual +* translations are now invalid and ensure they are not called +* anymore. +* +* tb_flush() takes care of running the flush in an exclusive context +* if it is not already running in one. This means no guest code will +* run until this complete. +*/ +void tb_flush (CPUState *cs); + +#endif /* _TB_FLUSH_H_ */
linux-user/user-internals.h +1 -0
@@ -20,6 +20,7 @@#include "exec/user/thunk.h" #include "exec/exec-all.h" +#include "exec/tb-flush.h" #include "qemu/log.h" extern char *exec_path;
accel/stubs/tcg-stub.c +1 -0
@@ -11,6 +11,7 @@*/ #include "qemu/osdep.h" +#include "exec/tb-flush.h" #include "exec/exec-all.h" void tb_flush (CPUState *cpu)
accel/tcg/tb-maint.c +1 -0
@@ -22,6 +22,7 @@#include "exec/cputlb.h" #include "exec/log.h" #include "exec/exec-all.h" +#include "exec/tb-flush.h" #include "exec/translate-all.h" #include "sysemu/tcg.h" #include "tcg/tcg.h"
accel/tcg/translate-all.c +1 -0
@@ -47,6 +47,7 @@#include "exec/cputlb.h" #include "exec/translate-all.h" #include "exec/translator.h" +#include "exec/tb-flush.h" #include "qemu/bitmap.h" #include "qemu/qemu-print.h" #include "qemu/main-loop.h"
cpu.c +1 -0
@@ -36,6 +36,7 @@#include "exec/replay-core.h" #include "exec/cpu-common.h" #include "exec/exec-all.h" +#include "exec/tb-flush.h" #include "exec/translate-all.h" #include "exec/log.h" #include "hw/core/accel-cpu.h"
gdbstub/gdbstub.c +2 -0
@@ -47,6 +47,8 @@#include "semihosting/semihost.h" #include "exec/exec-all.h" #include "exec/replay-core.h" +#include "exec/tb-flush.h" +#include "exec/hwaddr.h" #include "internals.h"
hw/ppc/spapr_hcall.c +1 -0
@@ -8,6 +8,7 @@#include "qemu/module.h" #include "qemu/error-report.h" #include "exec/exec-all.h" +#include "exec/tb-flush.h" #include "helper_regs.h" #include "hw/ppc/ppc.h" #include "hw/ppc/spapr.h"
plugins/core.c +1 -0
@@ -24,6 +24,7 @@#include "exec/cpu-common.h" #include "exec/exec-all.h" +#include "exec/tb-flush.h" #include "exec/helper-proto.h" #include "tcg/tcg.h" #include "tcg/tcg-op.h"
plugins/loader.c +1 -1
@@ -29,7 +29,7 @@#include "qemu/plugin.h" #include "qemu/memalign.h" #include "hw/core/cpu.h" -#include "exec/exec-all.h" +#include "exec/tb-flush.h" #ifndef CONFIG_USER_ONLY #include "hw/boards.h" #endif
target/alpha/sys_helper.c +1 -0
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "exec/exec-all.h" +#include "exec/tb-flush.h" #include "exec/helper-proto.h" #include "sysemu/runstate.h" #include "sysemu/sysemu.h"
target/riscv/csr.c +1 -0
@@ -25,6 +25,7 @@#include "time_helper.h" #include "qemu/main-loop.h" #include "exec/exec-all.h" +#include "exec/tb-flush.h" #include "sysemu/cpu-timers.h" #include "qemu/guest-random.h" #include "qapi/error.h"
Signature · 1 line
2.39.2
PATCH v4 8/26 gdbstub: move fromhex/tohex routines to internals
In reply to Alex BennéeThese will be needed from multiple places in the code. They are declared as inline so move to the header and fix up to modern coding style.
The only other place that messes with hex stuff at the moment is the URI handling in utils but that would be more code churn so leave for now.
--- gdbstub/internals.h | 27 +++++++++++++++++++++++++++ gdbstub/gdbstub.c | 20 -------------------- 2 files changed, 27 insertions(+), 20 deletions(-)
gdbstub/internals.h +27 -0
@@ -57,6 +57,33 @@ typedef struct GDBState {int supported_sstep_flags; } GDBState; + +/* +* Inline utility function, convert from int to hex and back +*/ + +static inline int fromhex (int v) +{ +if (v >='0' && v <='9' ) { +return v -'0' ; + }else if (v >='A' && v <='F' ) { +return v -'A' +10 ; + }else if (v >='a' && v <='f' ) { +return v -'a' +10 ; + }else { +return 0 ; + } +} + +static inline int tohex (int v) +{ +if (v <10 ) { +return v +'0' ; + }else { +return v -10 +'a' ; + } +} +/* * Break/Watch point support - there is an implementation for softmmu * and user mode.
gdbstub/gdbstub.c +0 -20
@@ -546,26 +546,6 @@ static void put_buffer(const uint8_t *buf, int len)#endif } -static inline int fromhex (int v) -{ -if (v >='0' && v <='9' ) -return v -'0' ; -else if (v >='A' && v <='F' ) -return v -'A' +10 ; -else if (v >='a' && v <='f' ) -return v -'a' +10 ; -else -return 0 ; -} - -static inline int tohex (int v) -{ -if (v <10 ) -return v +'0' ; -else -return v -10 +'a' ; -} -/* writes 2*len+1 bytes in buf */ static void memtohex (GString *buf,const uint8_t *mem,int len) {
Signature · 1 line
2.39.2
PATCH v4 9/26 gdbstub: make various helpers visible to the rest of the module
In reply to Alex BennéeWe will be needing to use these helpers between the user and softmmu files so declare them in the headers, add a system prefix and remove static from the implementations.
---
v4
- checkpatch warnings
--- gdbstub/internals.h | 25 ++++ gdbstub/gdbstub.c | 276 ++++++++++++++++++++++---------------------- 2 files changed, 165 insertions(+), 136 deletions(-)
gdbstub/internals.h +25 -0
@@ -84,6 +84,31 @@ static inline int tohex(int v) } } +/* +* Connection helpers for both softmmu and user backends +*/ + +void gdb_put_strbuf (void ); +int gdb_put_packet (const char *buf); +int gdb_put_packet_binary (const char *buf,int len,bool dump); +void gdb_hextomem (GByteArray *mem,const char *buf,int len); +void gdb_memtohex (GString *buf,const uint8_t *mem,int len); +void gdb_memtox (GString *buf,const char *mem,int len); +void gdb_read_byte (uint8_t ch); + +/* utility helpers */ +CPUState *gdb_first_attached_cpu (void ); +void gdb_append_thread_id (CPUState *cpu,GString *buf); +int gdb_get_cpu_index (CPUState *cpu); + +void gdb_init_gdbserver_state (void ); +void gdb_create_default_process (GDBState *s); + +/* +* Helpers with separate softmmu and user implementations +*/ +void gdb_put_buffer (const uint8_t *buf,int len); +/* * Break/Watch point support - there is an implementation for softmmu * and user mode.
gdbstub/gdbstub.c +140 -136
902 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v4 10/26 gdbstub: move chunk of softmmu functionality to own file
In reply to Alex BennéeThis is mostly code motion but a number of things needed to be done for this minimal patch set:
- move shared structures to internals.h
- splitting some functions into user and softmmu versions
- fixing a few casting issues to keep softmmu common
More CONFIG_USER_ONLY stuff will be handled in a following patches.
---
v3
- rebase fixes
- move extern to internals.h
v4
- checkpatch updates
--- gdbstub/internals.h | 43 ++++- gdbstub/gdbstub.c | 421 +----------------------------------------- gdbstub/softmmu.c | 423 +++++++++++++++++++++++++++++++++++++++++++ gdbstub/trace-events | 4 +- 4 files changed, 478 insertions(+), 413 deletions(-)
gdbstub/internals.h +42 -1
@@ -17,6 +17,18 @@* Shared structures and definitions */ +enum { +GDB_SIGNAL_0 =0 , +GDB_SIGNAL_INT =2 , +GDB_SIGNAL_QUIT =3 , +GDB_SIGNAL_TRAP =5 , +GDB_SIGNAL_ABRT =6 , +GDB_SIGNAL_ALRM =14 , +GDB_SIGNAL_IO =23 , +GDB_SIGNAL_XCPU =24 , +GDB_SIGNAL_UNKNOWN =143 +}; + typedef struct GDBProcess { uint32_t pid; bool attached;
@@ -57,6 +69,8 @@ typedef struct GDBState {int supported_sstep_flags; } GDBState; +/* lives in main gdbstub.c */ +extern GDBState gdbserver_state;/* * Inline utility function, convert from int to hex and back
@@ -101,7 +115,6 @@ CPUState *gdb_first_attached_cpu(void);void gdb_append_thread_id (CPUState *cpu,GString *buf);int gdb_get_cpu_index (CPUState *cpu); -void gdb_init_gdbserver_state (void );void gdb_create_default_process (GDBState *s);/*
@@ -109,6 +122,34 @@ void gdb_create_default_process(GDBState *s);*/ void gdb_put_buffer (const uint8_t *buf,int len); +/* +* Command handlers - either softmmu or user only +*/ +void gdb_init_gdbserver_state (void ); + +typedef enum GDBThreadIdKind { +GDB_ONE_THREAD =0 , +GDB_ALL_THREADS ,/* One process, all threads */ +GDB_ALL_PROCESSES , +GDB_READ_THREAD_ERR +}GDBThreadIdKind ; + +typedef union GdbCmdVariant { +const char *data; +uint8_t opcode; +unsigned long val_ul; +unsigned long long val_ull; +struct { +GDBThreadIdKind kind; +uint32_t pid; +uint32_t tid; + } thread_id; +}GdbCmdVariant ; + +#define get_param (p, i) (&g_array_index(p, GdbCmdVariant, i)) + +void gdb_handle_query_rcmd (GArray *params,void *user_ctx);/* softmmu */ +/* * Break/Watch point support - there is an implementation for softmmu * and user mode.
gdbstub/gdbstub.c +10 -411
538 lines not on this page · raw message
gdbstub/softmmu.c +423 -0
433 lines not on this page · raw message
gdbstub/trace-events +3 -1
@@ -7,7 +7,6 @@ gdbstub_op_continue(void) "Continuing all CPUs" gdbstub_op_continue_cpu(int cpu_index) "Continuing CPU %d" gdbstub_op_stepping(int cpu_index) "Stepping CPU %d" gdbstub_op_extra_info(const char *info) "Thread extra info: %s" -gdbstub_hit_watchpoint(const char *type, int cpu_gdb_index, uint64_t vaddr) "Watchpoint hit, type=\"%s\" cpu=%d, vaddr=0x%" PRIx64 "" gdbstub_hit_internal_error(void) "RUN_STATE_INTERNAL_ERROR" gdbstub_hit_break(void) "RUN_STATE_DEBUG" gdbstub_hit_paused(void) "RUN_STATE_PAUSED"
@@ -27,3 +26,6 @@ gdbstub_err_invalid_repeat(uint8_t ch) "got invalid RLE count: 0x%02x" gdbstub_err_invalid_rle(void) "got invalid RLE sequence" gdbstub_err_checksum_invalid(uint8_t ch) "got invalid command checksum digit: 0x%02x" gdbstub_err_checksum_incorrect(uint8_t expected, uint8_t got) "got command packet with incorrect checksum, expected=0x%02x, received=0x%02x" + +# softmmu.c +gdbstub_hit_watchpoint(const char *type, int cpu_gdb_index, uint64_t vaddr) "Watchpoint hit, type=\"%s\" cpu=%d, vaddr=0x%" PRIx64 ""
Signature · 1 line
2.39.2
PATCH v4 11/26 gdbstub: move chunks of user code into own files
In reply to Alex BennéeThe process was pretty similar to the softmmu move except we take the time to split stuff between user.c and user-target.c to avoid as much target specific compilation as possible. We also start to make use of our shiny new header scheme so the user-only helpers can be included without the rest of the exec/gsbstub.h cruft.
As before we split some functions into user and softmmu versions
---
v2
- separate splitting of functions
- create user.h here
v3
- rebase cleanups
- bring forward hunk to ensure all user-mode targets covered
v4
- checkpatch cleanup
--- MAINTAINERS | 1 + gdbstub/internals.h | 18 ++ include/exec/gdbstub.h | 21 -- include/gdbstub/user.h | 43 +++ gdbstub/gdbstub.c | 678 +---------------------------------------- gdbstub/softmmu.c | 90 ++++++ gdbstub/user-target.c | 283 +++++++++++++++++ gdbstub/user.c | 344 +++++++++++++++++++++ linux-user/main.c | 1 + linux-user/signal.c | 2 +- gdbstub/meson.build | 3 + 11 files changed, 788 insertions(+), 696 deletions(-) create mode 100644 include/gdbstub/user.h create mode 100644 gdbstub/user-target.c
MAINTAINERS +1 -0
@@ -2735,6 +2735,7 @@ S: Maintained F: docs/system/gdb.rst F: gdbstub/* F: include/exec/gdbstub.h +F: include/gdbstub/* F: gdb-xml/ F: tests/tcg/multiarch/gdbstub/ F: scripts/feature_to_c.sh
gdbstub/internals.h +18 -0
@@ -117,6 +117,22 @@ int gdb_get_cpu_index(CPUState *cpu);void gdb_create_default_process (GDBState *s); +/* signal mapping, common for softmmu, specialised for user-mode */ +int gdb_signal_to_target (int sig); +int gdb_target_signal_to_gdb (int sig); + +int gdb_get_char (void );/* user only */ + +/** +* gdb_continue() - handle continue in mode specific way. +*/ +void gdb_continue (void ); + +/** +* gdb_continue_partial() - handle partial continue in mode specific way. +*/ +int gdb_continue_partial (char *newstates); +/* * Helpers with separate softmmu and user implementations */
@@ -149,6 +165,8 @@ typedef union GdbCmdVariant {#define get_param (p, i) (&g_array_index(p, GdbCmdVariant, i))void gdb_handle_query_rcmd (GArray *params,void *user_ctx);/* softmmu */ +void gdb_handle_query_offsets (GArray *params,void *user_ctx);/* user */ +void gdb_handle_query_xfer_auxv (GArray *params,void *user_ctx);/*user */ /* * Break/Watch point support - there is an implementation for softmmu
include/exec/gdbstub.h +0 -21
@@ -103,27 +103,6 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);void gdb_do_syscallv (gdb_syscall_complete_cb cb,const char *fmt,va_list va);int use_gdb_syscalls (void ); -#ifdef CONFIG_USER_ONLY -/** -* gdb_handlesig: yield control to gdb -* @cpu: CPU -* @sig: if non-zero, the signal number which caused us to stop -* -* This function yields control to gdb, when a user-mode-only target -* needs to stop execution. If @sig is non-zero, then we will send a -* stop packet to tell gdb that we have stopped because of this signal. -* -* This function will block (handling protocol requests from gdb) -* until gdb tells us to continue target execution. When it does -* return, the return value is a signal to deliver to the target, -* or 0 if no signal should be delivered, ie the signal that caused -* us to stop should be ignored. -*/ -int gdb_handlesig (CPUState *,int ); -void gdb_signalled (CPUArchState *,int ); -void gdbserver_fork (CPUState *); -#endif -/* Get or set a register. Returns the size of the register. */ typedef int (*gdb_get_reg_cb )(CPUArchState *env,GByteArray *buf,int reg);typedef int (*gdb_set_reg_cb )(CPUArchState *env,uint8_t *buf,int reg);
include/gdbstub/user.h new file +43 -0
43 lines not on this page · raw message
gdbstub/gdbstub.c +4 -674
752 lines not on this page · raw message
gdbstub/softmmu.c +90 -0
96 lines not on this page · raw message
gdbstub/user-target.c new file +283 -0
283 lines not on this page · raw message
gdbstub/user.c +344 -0
354 lines not on this page · raw message
linux-user/main.c +1 -0
@@ -40,6 +40,7 @@#include "qemu/plugin.h" #include "exec/exec-all.h" #include "exec/gdbstub.h" +#include "gdbstub/user.h" #include "tcg/tcg.h" #include "qemu/timer.h" #include "qemu/envlist.h"
linux-user/signal.c +1 -1
@@ -18,7 +18,7 @@*/ #include "qemu/osdep.h" #include "qemu/bitops.h" -#include "exec/gdbstub.h" +#include "gdbstub/user.h" #include "hw/core/tcg-cpu-ops.h" #include <sys/ucontext.h>
gdbstub/meson.build +3 -0
@@ -7,3 +7,6 @@ specific_ss.add(files('gdbstub.c')) softmmu_ss.add(files('softmmu.c')) user_ss.add(files('user.c')) + +# The user-target is specialised by the guest +specific_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-target.c'))
Signature · 1 line
2.39.2
PATCH v4 12/26 gdbstub: rationalise signal mapping in softmmu
In reply to Alex BennéeWe don't really need a table for mapping two symbols.
--- gdbstub/softmmu.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
gdbstub/softmmu.c +6 -12
@@ -506,20 +506,14 @@ enum { TARGET_SIGTRAP = 5 }; -static int gdb_signal_table[] = { --1 , --1 , -TARGET_SIGINT , --1 , --1 , -TARGET_SIGTRAP -}; -int gdb_signal_to_target (int sig) { -if (sig <ARRAY_SIZE (gdb_signal_table)) { -return gdb_signal_table[sig]; - }else { +switch (sig) { +case 2 : +return TARGET_SIGINT ; +case 5 : +return TARGET_SIGTRAP ; +default :return -1 ; } }
Signature · 1 line
2.39.2
PATCH v4 13/26 gdbstub: abstract target specific details from gdb_put_packet_binary
In reply to Alex BennéeWe unfortunately handle the checking of packet acknowledgement differently for user and softmmu modes. Abstract the user mode stuff behind gdb_got_immediate_ack with a stub for softmmu.
--- gdbstub/internals.h | 15 +++++++++++++++ gdbstub/gdbstub.c | 10 ++-------- gdbstub/softmmu.c | 8 ++++++++ gdbstub/user.c | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+), 8 deletions(-)
gdbstub/internals.h +15 -0
@@ -110,6 +110,21 @@ void gdb_memtohex(GString *buf, const uint8_t *mem, int len);void gdb_memtox (GString *buf,const char *mem,int len);void gdb_read_byte (uint8_t ch); +/* +* Packet acknowledgement - we handle this slightly differently +* between user and softmmu mode, mainly to deal with the differences +* between the flexible chardev and the direct fd approaches. +* +* We currently don't support a negotiated QStartNoAckMode +*/ + +/** +* gdb_got_immediate_ack() - check ok to continue +* +* Returns true to continue, false to re-transmit for user only, the +* softmmu stub always returns true. +*/ +bool gdb_got_immediate_ack (void );/* utility helpers */ CPUState *gdb_first_attached_cpu (void );void gdb_append_thread_id (CPUState *cpu,GString *buf);
gdbstub/gdbstub.c +2 -8
@@ -239,15 +239,9 @@ int gdb_put_packet_binary(const char *buf, int len, bool dump)gdb_put_buffer (gdbserver_state.last_packet->data, gdbserver_state.last_packet->len); -#ifdef CONFIG_USER_ONLY - i =gdb_get_char (); -if (i <0 ) -return -1 ; -if (i =='+' ) +if (gdb_got_immediate_ack ()) {break ; -#else -break ; -#endif + } }return 0 ; }
gdbstub/softmmu.c +8 -0
@@ -55,6 +55,14 @@ int gdb_get_cpu_index(CPUState *cpu)return cpu->cpu_index +1 ; } +/* +* We check the status of the last message in the chardev receive code +*/ +bool gdb_got_immediate_ack (void ) +{ +return true; +} +/* * GDB Connection management. For system emulation we do all of this * via our existing Chardev infrastructure which allows us to support
gdbstub/user.c +19 -0
@@ -54,6 +54,25 @@ int gdb_get_char(void)return ch; } +bool gdb_got_immediate_ack (void ) +{ +int i; + + i =gdb_get_char (); +if (i <0 ) { +/* no response, continue anyway */ +return true; + } + +if (i =='+' ) { +/* received correctly, continue */ +return true; + } + +/* anything else, including '-' then try again */ +return false; +} +void gdb_put_buffer (const uint8_t *buf,int len) {int ret;
Signature · 1 line
2.39.2
PATCH v4 14/26 gdbstub: specialise handle_query_attached
In reply to Alex BennéeIn both user and softmmu cases we are just replying with a constant.
---
v3
- remove allusions to possible linker optimisations
--- gdbstub/internals.h | 4 +++- gdbstub/gdbstub.c | 15 ++------------- gdbstub/softmmu.c | 5 +++++ gdbstub/user.c | 5 +++++ 4 files changed, 15 insertions(+), 14 deletions(-)
gdbstub/internals.h +3 -1
@@ -154,7 +154,7 @@ int gdb_continue_partial(char *newstates);void gdb_put_buffer (const uint8_t *buf,int len);/* -* Command handlers - either softmmu or user only +* Command handlers - either specialised or softmmu or user only */ void gdb_init_gdbserver_state (void );
@@ -183,6 +183,8 @@ void gdb_handle_query_rcmd(GArray *params, void *user_ctx); /* softmmu */void gdb_handle_query_offsets (GArray *params,void *user_ctx);/* user */ void gdb_handle_query_xfer_auxv (GArray *params,void *user_ctx);/*user */ +void gdb_handle_query_attached (GArray *params,void *user_ctx);/* both */ +/* * Break/Watch point support - there is an implementation for softmmu * and user mode.
gdbstub/gdbstub.c +2 -13
@@ -46,12 +46,6 @@#include "internals.h" -#ifdef CONFIG_USER_ONLY -#define GDB_ATTACHED "0" -#else -#define GDB_ATTACHED "1" -#endif -#ifndef CONFIG_USER_ONLY static int phy_memory_mode;#endif
@@ -1673,11 +1667,6 @@ static void handle_query_xfer_features(GArray *params, void *user_ctx) gdbserver_state.str_buf->len, true); } -static void handle_query_attached (GArray *params,void *user_ctx) -{ -gdb_put_packet (GDB_ATTACHED ); -} -static void handle_query_qemu_supported (GArray *params,void *user_ctx) {g_string_printf (gdbserver_state.str_buf,"sstepbits;sstep" );
@@ -1787,12 +1776,12 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = { },#endif { - .handler = handle_query_attached, + .handler = gdb_handle_query_attached, .cmd = "Attached:", .cmd_startswith = 1 }, { - .handler = handle_query_attached, + .handler = gdb_handle_query_attached, .cmd = "Attached", }, {
gdbstub/softmmu.c +5 -0
@@ -446,6 +446,11 @@ void gdb_handle_query_rcmd(GArray *params, void *user_ctx)* Execution state helpers */ +void gdb_handle_query_attached (GArray *params,void *user_ctx) +{ +gdb_put_packet ("1" ); +} +void gdb_continue (void ) {if (!runstate_needs_reset ()) {
gdbstub/user.c +5 -0
@@ -345,6 +345,11 @@ void gdbserver_fork(CPUState *cpu)* Execution state helpers */ +void gdb_handle_query_attached (GArray *params,void *user_ctx) +{ +gdb_put_packet ("0" ); +} +void gdb_continue (void ) { gdbserver_user_state.running_state =1 ;
Signature · 1 line
2.39.2
PATCH v4 15/26 gdbstub: specialise target_memory_rw_debug
In reply to Alex BennéeThe two implementations are different enough to encourage having a specialisation and we can move some of the softmmu only stuff out of gdbstub.
--- gdbstub/internals.h | 19 ++++++++++++ gdbstub/gdbstub.c | 73 +++++++-------------------------------------- gdbstub/softmmu.c | 51 +++++++++++++++++++++++++++++++ gdbstub/user.c | 15 ++++++++++ 4 files changed, 96 insertions(+), 62 deletions(-)
gdbstub/internals.h +19 -0
@@ -185,6 +185,10 @@ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */void gdb_handle_query_attached (GArray *params,void *user_ctx);/* both */ +/* softmmu only */ +void gdb_handle_query_qemu_phy_mem_mode (GArray *params,void *user_ctx); +void gdb_handle_set_qemu_phy_mem_mode (GArray *params,void *user_ctx); +/* * Break/Watch point support - there is an implementation for softmmu * and user mode.
@@ -194,4 +198,19 @@ int gdb_breakpoint_insert(CPUState *cs, int type, vaddr addr, vaddr len);int gdb_breakpoint_remove (CPUState *cs,int type,vaddr addr,vaddr len);void gdb_breakpoint_remove_all (CPUState *cs); +/** +* gdb_target_memory_rw_debug() - handle debug access to memory +* @cs: CPUState +* @addr: nominal address, could be an entire physical address +* @buf: data +* @len: length of access +* @is_write: is it a write operation +* +* This function is specialised depending on the mode we are running +* in. For softmmu guests we can switch the interpretation of the +* address to a physical address. +*/ +int gdb_target_memory_rw_debug (CPUState *cs,hwaddr addr, +uint8_t *buf,int len,bool is_write); +#endif /* GDBSTUB_INTERNALS_H */
gdbstub/gdbstub.c +11 -62
109 lines not on this page · raw message
gdbstub/softmmu.c +51 -0
60 lines not on this page · raw message
gdbstub/user.c +15 -0
@@ -378,6 +378,21 @@ int gdb_continue_partial(char *newstates)return res; } +/* +* Memory access helpers +*/ +int gdb_target_memory_rw_debug (CPUState *cpu,hwaddr addr, +uint8_t *buf,int len,bool is_write) +{ +CPUClass *cc; + + cc =CPU_GET_CLASS (cpu); +if (cc->memory_rw_debug) { +return cc->memory_rw_debug (cpu, addr, buf, len, is_write); + } +return cpu_memory_rw_debug (cpu, addr, buf, len, is_write); +} +/* * Break/Watch point helpers */
Signature · 1 line
2.39.2
PATCH v4 16/26 gdbstub: introduce gdb_get_max_cpus
In reply to Alex BennéeThis is needed for handling vcont packets as the way of calculating max cpus vhanges between user and softmmu mode.
---
v3
- rm out of date comment
--- gdbstub/internals.h | 1 + gdbstub/gdbstub.c | 11 +---------- gdbstub/softmmu.c | 9 +++++++++ gdbstub/user.c | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 10 deletions(-)
gdbstub/internals.h +1 -0
@@ -129,6 +129,7 @@ bool gdb_got_immediate_ack(void);CPUState *gdb_first_attached_cpu (void );void gdb_append_thread_id (CPUState *cpu,GString *buf);int gdb_get_cpu_index (CPUState *cpu); +unsigned int gdb_get_max_cpus (void );/* both */ void gdb_create_default_process (GDBState *s);
gdbstub/gdbstub.c +1 -10
@@ -624,16 +624,7 @@ static int gdb_handle_vcont(const char *p)GDBProcess *process;CPUState *cpu;GDBThreadIdKind kind; -#ifdef CONFIG_USER_ONLY -int max_cpus =1 ;/* global variable max_cpus exists only in system mode */ - -CPU_FOREACH (cpu) { - max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index +1 : max_cpus; - } -#else -MachineState *ms =MACHINE (qdev_get_machine ()); -unsigned int max_cpus = ms->smp.max_cpus; -#endif +unsigned int max_cpus =gdb_get_max_cpus ();/* uninitialised CPUs stay 0 */ newstates =g_new0 (char, max_cpus);
gdbstub/softmmu.c +9 -0
@@ -440,6 +440,15 @@ int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,return cpu_memory_rw_debug (cpu, addr, buf, len, is_write); } +/* +* cpu helpers +*/ + +unsigned int gdb_get_max_cpus (void ) +{ +MachineState *ms =MACHINE (qdev_get_machine ()); +return ms->smp.max_cpus; +}/* * Softmmu specific command helpers
gdbstub/user.c +17 -0
@@ -393,6 +393,23 @@ int gdb_target_memory_rw_debug(CPUState *cpu, hwaddr addr,return cpu_memory_rw_debug (cpu, addr, buf, len, is_write); } +/* +* cpu helpers +*/ + +unsigned int gdb_get_max_cpus (void ) +{ +CPUState *cpu; +unsigned int max_cpus =1 ; + +CPU_FOREACH (cpu) { + max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index +1 : max_cpus; + } + +return max_cpus; +} + +/* * Break/Watch point helpers */
Signature · 1 line
2.39.2
PATCH v4 17/26 gdbstub: specialise stub_can_reverse
In reply to Alex BennéeCurrently we only support replay for softmmu mode so it is a constant false for user-mode.
---
v3
- rename gdb_stub_can_revers -> gdb_can_reverse
--- gdbstub/internals.h | 1 + gdbstub/gdbstub.c | 13 ++----------- gdbstub/softmmu.c | 5 +++++ gdbstub/user.c | 5 +++++ 4 files changed, 13 insertions(+), 11 deletions(-)
gdbstub/internals.h +1 -0
@@ -130,6 +130,7 @@ CPUState *gdb_first_attached_cpu(void);void gdb_append_thread_id (CPUState *cpu,GString *buf);int gdb_get_cpu_index (CPUState *cpu);unsigned int gdb_get_max_cpus (void );/* both */ +bool gdb_can_reverse (void );/* softmmu, stub for user */ void gdb_create_default_process (GDBState *s);
gdbstub/gdbstub.c +2 -11
@@ -113,15 +113,6 @@ int use_gdb_syscalls(void)return gdb_syscall_mode ==GDB_SYS_ENABLED ; } -static bool stub_can_reverse (void ) -{ -#ifdef CONFIG_USER_ONLY -return false; -#else -return replay_mode ==REPLAY_MODE_PLAY ; -#endif -} -/* writes 2*len+1 bytes in buf */ void gdb_memtohex (GString *buf,const uint8_t *mem,int len) {
@@ -1308,7 +1299,7 @@ static void handle_step(GArray *params, void *user_ctx)static void handle_backward (GArray *params,void *user_ctx) { -if (!stub_can_reverse ()) { +if (!gdb_can_reverse ()) {gdb_put_packet ("E22" ); }if (params->len ==1 ) {
@@ -1559,7 +1550,7 @@ static void handle_query_supported(GArray *params, void *user_ctx)g_string_append (gdbserver_state.str_buf,";qXfer:features:read+" ); } -if (stub_can_reverse ()) { +if (gdb_can_reverse ()) {g_string_append (gdbserver_state.str_buf,";ReverseStep+;ReverseContinue+" ); }
gdbstub/softmmu.c +5 -0
@@ -450,6 +450,11 @@ unsigned int gdb_get_max_cpus(void)return ms->smp.max_cpus; } +bool gdb_can_reverse (void ) +{ +return replay_mode ==REPLAY_MODE_PLAY ; +} +/* * Softmmu specific command helpers */
gdbstub/user.c +5 -0
@@ -409,6 +409,11 @@ unsigned int gdb_get_max_cpus(void)return max_cpus; } +/* replay not supported for user-mode */ +bool gdb_can_reverse (void ) +{ +return false; +}/* * Break/Watch point helpers
Signature · 1 line
2.39.2
PATCH v4 18/26 gdbstub: fix address type of gdb_set_cpu_pc
In reply to Alex BennéeThe underlying call uses vaddr and the comms API uses unsigned long long which will always fit. We don't need to deal in target_ulong here.
--- gdbstub/gdbstub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
gdbstub/gdbstub.c +2 -2
@@ -535,7 +535,7 @@ static void gdb_process_breakpoint_remove_all(GDBProcess *p) } -static void gdb_set_cpu_pc (target_ulong pc) +static void gdb_set_cpu_pc (vaddr pc) {CPUState *cpu = gdbserver_state.c_cpu;
@@ -1290,7 +1290,7 @@ static void handle_file_io(GArray *params, void *user_ctx)static void handle_step (GArray *params,void *user_ctx) {if (params->len) { -gdb_set_cpu_pc ((target_ulong )get_param (params,0 )->val_ull); +gdb_set_cpu_pc (get_param (params,0 )->val_ull); }cpu_single_step (gdbserver_state.c_cpu, gdbserver_state.sstep_flags);
Signature · 1 line
2.39.2
PATCH v4 19/26 gdbstub: don't use target_ulong while handling registers
In reply to Alex BennéeThis is a hangover from the original code. addr is misleading as it is only really a register id. While len will never exceed MAX_PACKET_LENGTH I've used size_t as that is what strlen returns.
---
v3
- fix commit message
- use unsigned for regid
v4
- revert unsigned change
--- gdbstub/gdbstub.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
gdbstub/gdbstub.c +10 -7
@@ -1193,7 +1193,8 @@ static void handle_read_mem(GArray *params, void *user_ctx)static void handle_write_all_regs (GArray *params,void *user_ctx) { -target_ulong addr, len; +int reg_id; +size_t len;uint8_t *registers;int reg_size;
@@ -1205,9 +1206,10 @@ static void handle_write_all_regs(GArray *params, void *user_ctx) len =strlen (get_param (params,0 )->data) /2 ;gdb_hextomem (gdbserver_state.mem_buf,get_param (params,0 )->data, len); registers = gdbserver_state.mem_buf->data; -for (addr =0 ; addr < gdbserver_state.g_cpu->gdb_num_g_regs && len >0 ; - addr++) { - reg_size =gdb_write_register (gdbserver_state.g_cpu, registers, addr); +for (reg_id =0 ; + reg_id < gdbserver_state.g_cpu->gdb_num_g_regs && len >0 ; + reg_id++) { + reg_size =gdb_write_register (gdbserver_state.g_cpu, registers, reg_id); len -= reg_size; registers += reg_size; }
@@ -1216,15 +1218,16 @@ static void handle_write_all_regs(GArray *params, void *user_ctx)static void handle_read_all_regs (GArray *params,void *user_ctx) { -target_ulong addr, len; +int reg_id; +size_t len;cpu_synchronize_state (gdbserver_state.g_cpu);g_byte_array_set_size (gdbserver_state.mem_buf,0 ); len =0 ; -for (addr =0 ; addr < gdbserver_state.g_cpu->gdb_num_g_regs; addr++) { +for (reg_id =0 ; reg_id < gdbserver_state.g_cpu->gdb_num_g_regs; reg_id++) { len +=gdb_read_register (gdbserver_state.g_cpu, gdbserver_state.mem_buf, - addr); + reg_id); }g_assert (len == gdbserver_state.mem_buf->len);
Signature · 1 line
2.39.2
PATCH v4 20/26 gdbstub: move register helpers into standalone include
In reply to Alex BennéeThese inline helpers are all used by target specific code so move them out of the general header so we don't needlessly pollute the rest of the API with target specific stuff.
Note we have to include cpu.h in semihosting as it was relying on a side effect before.
---
v3
- update xtensa's import-core script as well
v4
- checkpatch cleanups
--- include/exec/gdbstub.h | 86 --------------------- include/gdbstub/helpers.h | 103 +++++++++++++++++++++++++ semihosting/syscalls.c | 1 + target/alpha/gdbstub.c | 2 +- target/arm/gdbstub.c | 1 + target/arm/gdbstub64.c | 2 +- target/arm/tcg/helper-a64.c | 2 +- target/arm/tcg/m_helper.c | 1 + target/avr/gdbstub.c | 2 +- target/cris/gdbstub.c | 2 +- target/hexagon/gdbstub.c | 2 +- target/hppa/gdbstub.c | 2 +- target/i386/gdbstub.c | 2 +- target/i386/whpx/whpx-all.c | 2 +- target/loongarch/gdbstub.c | 1 + target/m68k/gdbstub.c | 2 +- target/m68k/helper.c | 1 + target/m68k/m68k-semi.c | 1 + target/microblaze/gdbstub.c | 2 +- target/mips/gdbstub.c | 2 +- target/mips/tcg/sysemu/mips-semi.c | 1 + target/nios2/cpu.c | 2 +- target/nios2/nios2-semi.c | 1 + target/openrisc/gdbstub.c | 2 +- target/openrisc/interrupt.c | 2 +- target/openrisc/mmu.c | 2 +- target/ppc/cpu_init.c | 2 +- target/ppc/gdbstub.c | 1 + target/riscv/gdbstub.c | 1 + target/rx/gdbstub.c | 2 +- target/s390x/gdbstub.c | 1 + target/s390x/helper.c | 2 +- target/sh4/gdbstub.c | 2 +- target/sparc/gdbstub.c | 2 +- target/tricore/gdbstub.c | 2 +- target/xtensa/core-dc232b.c | 2 +- target/xtensa/core-dc233c.c | 2 +- target/xtensa/core-de212.c | 2 +- target/xtensa/core-de233_fpu.c | 2 +- target/xtensa/core-dsp3400.c | 2 +- target/xtensa/core-fsf.c | 2 +- target/xtensa/core-lx106.c | 2 +- target/xtensa/core-sample_controller.c | 2 +- target/xtensa/core-test_kc705_be.c | 2 +- target/xtensa/core-test_mmuhifi_c3.c | 2 +- target/xtensa/gdbstub.c | 2 +- target/xtensa/helper.c | 2 +- target/xtensa/import_core.sh | 2 +- 48 files changed, 149 insertions(+), 121 deletions(-) create mode 100644 include/gdbstub/helpers.h
include/exec/gdbstub.h +0 -86
@@ -110,92 +110,6 @@ void gdb_register_coprocessor(CPUState *cpu, gdb_get_reg_cb get_reg, gdb_set_reg_cb set_reg, int num_regs, const char *xml, int g_pos); -#ifdef NEED_CPU_H -#include "cpu.h" - -/* -* The GDB remote protocol transfers values in target byte order. As -* the gdbstub may be batching up several register values we always -* append to the array. -*/ - -static inline int gdb_get_reg8 (GByteArray *buf,uint8_t val) -{ -g_byte_array_append (buf, &val,1 ); -return 1 ; -} - -static inline int gdb_get_reg16 (GByteArray *buf,uint16_t val) -{ -uint16_t to_word =tswap16 (val); -g_byte_array_append (buf, (uint8_t *) &to_word,2 ); -return 2 ; -} - -static inline int gdb_get_reg32 (GByteArray *buf,uint32_t val) -{ -uint32_t to_long =tswap32 (val); -g_byte_array_append (buf, (uint8_t *) &to_long,4 ); -return 4 ; -} - -static inline int gdb_get_reg64 (GByteArray *buf,uint64_t val) -{ -uint64_t to_quad =tswap64 (val); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); -return 8 ; -} - -static inline int gdb_get_reg128 (GByteArray *buf,uint64_t val_hi, -uint64_t val_lo) -{ -uint64_t to_quad; -#if TARGET_BIG_ENDIAN - to_quad =tswap64 (val_hi); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); - to_quad =tswap64 (val_lo); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); -#else - to_quad =tswap64 (val_lo); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); - to_quad =tswap64 (val_hi); -g_byte_array_append (buf, (uint8_t *) &to_quad,8 ); -#endif -return 16 ; -} - -static inline int gdb_get_zeroes (GByteArray *array,size_t len) -{ -guint oldlen = array->len; -g_byte_array_set_size (array, oldlen + len); -memset (array->data + oldlen,0 , len); - -return len; -} - -/** -* gdb_get_reg_ptr: get pointer to start of last element -* @len: length of element -* -* This is a helper function to extract the pointer to the last -* element for additional processing. Some front-ends do additional -* dynamic swapping of the elements based on CPU state. -*/ -static inline uint8_t *gdb_get_reg_ptr (GByteArray *buf,int len) -{ -return buf->data + buf->len - len; -} - -#if TARGET_LONG_BITS ==64 -#define gdb_get_regl (buf, val) gdb_get_reg64(buf, val) -#define ldtul_p (addr) ldq_p(addr) -#else -#define gdb_get_regl (buf, val) gdb_get_reg32(buf, val) -#define ldtul_p (addr) ldl_p(addr) -#endif - -#endif /* NEED_CPU_H */ -/** * gdbserver_start: start the gdb server * @port_or_device: connection spec for gdb
include/gdbstub/helpers.h new file +103 -0
103 lines not on this page · raw message
semihosting/syscalls.c +1 -0
@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "exec/gdbstub.h" +#include "cpu.h" #include "semihosting/guestfd.h" #include "semihosting/syscalls.h" #include "semihosting/console.h"
target/alpha/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" int alpha_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {
target/arm/gdbstub.c +1 -0
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "internals.h" #include "cpregs.h"
target/arm/gdbstub64.c +1 -1
@@ -20,7 +20,7 @@#include "qemu/log.h" #include "cpu.h" #include "internals.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" int aarch64_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {
target/arm/tcg/helper-a64.c +1 -1
@@ -20,7 +20,7 @@#include "qemu/osdep.h" #include "qemu/units.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "exec/helper-proto.h" #include "qemu/host-utils.h" #include "qemu/log.h"
target/arm/tcg/m_helper.c +1 -0
@@ -9,6 +9,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "internals.h" +#include "gdbstub/helpers.h" #include "exec/helper-proto.h" #include "qemu/main-loop.h" #include "qemu/bitops.h"
target/avr/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" int avr_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {
target/cris/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" int crisv10_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {
target/hexagon/gdbstub.c +1 -1
@@ -16,7 +16,7 @@*/ #include "qemu/osdep.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "cpu.h" #include "internal.h"
target/hppa/gdbstub.c +1 -1
@@ -19,7 +19,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" int hppa_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {
target/i386/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "include/gdbstub/helpers.h" #ifdef TARGET_X86_64 static const int gpr_map[16] = {
target/i386/whpx/whpx-all.c +1 -1
@@ -12,7 +12,7 @@#include "cpu.h" #include "exec/address-spaces.h" #include "exec/ioport.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/accel.h" #include "sysemu/whpx.h" #include "sysemu/cpus.h"
target/loongarch/gdbstub.c +1 -0
@@ -10,6 +10,7 @@#include "cpu.h" #include "internals.h" #include "exec/gdbstub.h" +#include "gdbstub/helpers.h" uint64_t read_fcc (CPULoongArchState *env) {
target/m68k/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" int m68k_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {
target/m68k/helper.c +1 -0
@@ -23,6 +23,7 @@#include "exec/exec-all.h" #include "exec/gdbstub.h" #include "exec/helper-proto.h" +#include "gdbstub/helpers.h" #include "fpu/softfloat.h" #include "qemu/qemu-print.h"
target/m68k/m68k-semi.c +1 -0
@@ -21,6 +21,7 @@#include "cpu.h" #include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "semihosting/syscalls.h" #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h"
target/microblaze/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" /* * GDB expects SREGs in the following order:
target/mips/gdbstub.c +1 -1
@@ -20,7 +20,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "internal.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "fpu_helper.h" int mips_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n)
target/mips/tcg/sysemu/mips-semi.c +1 -0
@@ -21,6 +21,7 @@#include "cpu.h" #include "qemu/log.h" #include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h" #include "semihosting/console.h"
target/nios2/cpu.c +1 -1
@@ -23,7 +23,7 @@#include "qapi/error.h" #include "cpu.h" #include "exec/log.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "hw/qdev-properties.h" static void nios2_cpu_set_pc (CPUState *cs,vaddr value)
target/nios2/nios2-semi.c +1 -0
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "semihosting/syscalls.h" #include "semihosting/softmmu-uaccess.h" #include "qemu/log.h"
target/openrisc/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" int openrisc_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {
target/openrisc/interrupt.c +1 -1
@@ -21,7 +21,7 @@#include "qemu/log.h" #include "cpu.h" #include "exec/exec-all.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #ifndef CONFIG_USER_ONLY #include "hw/loader.h"
target/openrisc/mmu.c +1 -1
@@ -22,7 +22,7 @@#include "qemu/log.h" #include "cpu.h" #include "exec/exec-all.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "hw/loader.h"
target/ppc/cpu_init.c +1 -1
@@ -20,7 +20,7 @@#include "qemu/osdep.h" #include "disas/dis-asm.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "kvm_ppc.h" #include "sysemu/cpus.h" #include "sysemu/hw_accel.h"
target/ppc/gdbstub.c +1 -0
@@ -20,6 +20,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "internal.h" static int ppc_gdb_register_len_apple (int n)
target/riscv/gdbstub.c +1 -0
@@ -18,6 +18,7 @@#include "qemu/osdep.h" #include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "cpu.h" struct TypeSize {
target/rx/gdbstub.c +1 -1
@@ -17,7 +17,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" int rx_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {
target/s390x/gdbstub.c +1 -0
@@ -23,6 +23,7 @@#include "s390x-internal.h" #include "exec/exec-all.h" #include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/bitops.h" #include "sysemu/hw_accel.h" #include "sysemu/tcg.h"
target/s390x/helper.c +1 -1
@@ -21,7 +21,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "s390x-internal.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/timer.h" #include "hw/s390x/ioinst.h" #include "hw/s390x/pv.h"
target/sh4/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" /* Hint: Use "set architecture sh4" in GDB to see fpu registers */ /* FIXME: We should use XML for this. */
target/sparc/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #ifdef TARGET_ABI32 #define gdb_get_rega (buf, val) gdb_get_reg32(buf, val)
target/tricore/gdbstub.c +1 -1
@@ -18,7 +18,7 @@*/ #include "qemu/osdep.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #define LCX_REGNUM 32
target/xtensa/core-dc232b.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "qemu/timer.h"
target/xtensa/core-dc233c.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-dc233c/core-isa.h"
target/xtensa/core-de212.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-de212/core-isa.h"
target/xtensa/core-de233_fpu.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-de233_fpu/core-isa.h"
target/xtensa/core-dsp3400.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-dsp3400/core-isa.h"
target/xtensa/core-fsf.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-fsf/core-isa.h"
target/xtensa/core-lx106.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-lx106/core-isa.h"
target/xtensa/core-sample_controller.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-sample_controller/core-isa.h"
target/xtensa/core-test_kc705_be.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-test_kc705_be/core-isa.h"
target/xtensa/core-test_mmuhifi_c3.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-test_mmuhifi_c3/core-isa.h"
target/xtensa/gdbstub.c +1 -1
@@ -19,7 +19,7 @@*/ #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/log.h" enum {
target/xtensa/helper.c +1 -1
@@ -29,7 +29,7 @@#include "qemu/log.h" #include "cpu.h" #include "exec/exec-all.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "exec/helper-proto.h" #include "qemu/error-report.h" #include "qemu/qemu-print.h"
target/xtensa/import_core.sh +1 -1
@@ -41,7 +41,7 @@ tar -xf "$OVERLAY" -O binutils/xtensa-modules.c | \ cat <<EOF > "${TARGET}.c" #include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/helpers.h" #include "qemu/host-utils.h" #include "core-$NAME/core-isa.h"
Signature · 1 line
2.39.2
PATCH v4 21/26 gdbstub: move syscall handling to new file
In reply to Alex BennéeOur GDB syscall support is the last chunk of code that needs target specific support so move it to a new file. We take the opportunity to move the syscall state into its own singleton instance and add in a few helpers for the main gdbstub to interact with the module.
I also moved the gdb_exit() declaration into syscalls.h as it feels pretty related and most of the callers of it treat it as such.
---
v4
- checkpatch cleanups
--- gdbstub/internals.h | 8 +- include/exec/gdbstub.h | 102 ------------- include/gdbstub/syscalls.h | 124 +++++++++++++++ gdbstub/gdbstub.c | 177 +--------------------- gdbstub/softmmu.c | 7 +- gdbstub/syscalls.c | 234 +++++++++++++++++++++++++++++ gdbstub/user.c | 1 + linux-user/exit.c | 2 +- semihosting/arm-compat-semi.c | 1 + semihosting/guestfd.c | 2 +- semihosting/syscalls.c | 2 +- softmmu/runstate.c | 2 +- target/m68k/m68k-semi.c | 2 +- target/mips/tcg/sysemu/mips-semi.c | 2 +- target/nios2/nios2-semi.c | 2 +- gdbstub/meson.build | 4 + 16 files changed, 384 insertions(+), 288 deletions(-) create mode 100644 include/gdbstub/syscalls.h create mode 100644 gdbstub/syscalls.c
gdbstub/internals.h +6 -2
@@ -61,8 +61,6 @@ typedef struct GDBState {bool multiprocess;GDBProcess *processes;int process_num; -char syscall_buf[256 ]; -gdb_syscall_complete_cb current_syscall_cb;GString *str_buf;GByteArray *mem_buf;int sstep_flags;
@@ -191,6 +189,12 @@ void gdb_handle_query_attached(GArray *params, void *user_ctx); /* both */void gdb_handle_query_qemu_phy_mem_mode (GArray *params,void *user_ctx);void gdb_handle_set_qemu_phy_mem_mode (GArray *params,void *user_ctx); +/* sycall handling */ +void gdb_handle_file_io (GArray *params,void *user_ctx); +bool gdb_handled_syscall (void ); +void gdb_disable_syscalls (void ); +void gdb_syscall_reset (void ); +/* * Break/Watch point support - there is an implementation for softmmu * and user mode.
include/exec/gdbstub.h +0 -102
114 lines not on this page · raw message
include/gdbstub/syscalls.h new file +124 -0
124 lines not on this page · raw message
gdbstub/gdbstub.c +3 -174
219 lines not on this page · raw message
gdbstub/softmmu.c +4 -3
@@ -15,6 +15,7 @@#include "qemu/error-report.h" #include "qemu/cutils.h" #include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "exec/hwaddr.h" #include "exec/tb-flush.h" #include "sysemu/cpus.h"
@@ -113,9 +114,9 @@ static void gdb_vm_state_change(void *opaque, bool running, RunState state)if (running || gdbserver_state.state ==RS_INACTIVE ) {return ; } +/* Is there a GDB syscall waiting to be sent? */ -if (gdbserver_state.current_syscall_cb) { -gdb_put_packet (gdbserver_state.syscall_buf); +if (gdb_handled_syscall ()) {return ; }
@@ -384,7 +385,7 @@ int gdbserver_start(const char *device) } gdbserver_state.state = chr ?RS_IDLE :RS_INACTIVE ; gdbserver_system_state.mon_chr = mon_chr; - gdbserver_state.current_syscall_cb =NULL ; +gdb_syscall_reset ();return 0 ; }
gdbstub/syscalls.c new file +234 -0
234 lines not on this page · raw message
gdbstub/user.c +1 -0
@@ -15,6 +15,7 @@#include "exec/hwaddr.h" #include "exec/tb-flush.h" #include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "gdbstub/user.h" #include "hw/core/cpu.h" #include "trace.h"
linux-user/exit.c +1 -1
@@ -18,7 +18,7 @@*/ #include "qemu/osdep.h" #include "accel/tcg/perf.h" -#include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "qemu.h" #include "user-internals.h" #ifdef CONFIG_GPROF
semihosting/arm-compat-semi.c +1 -0
@@ -34,6 +34,7 @@#include "qemu/osdep.h" #include "qemu/timer.h" #include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "semihosting/semihost.h" #include "semihosting/console.h" #include "semihosting/common-semi.h"
semihosting/guestfd.c +1 -1
@@ -9,7 +9,7 @@*/ #include "qemu/osdep.h" -#include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "semihosting/semihost.h" #include "semihosting/guestfd.h" #ifdef CONFIG_USER_ONLY
semihosting/syscalls.c +1 -1
@@ -7,8 +7,8 @@*/ #include "qemu/osdep.h" -#include "exec/gdbstub.h" #include "cpu.h" +#include "gdbstub/syscalls.h" #include "semihosting/guestfd.h" #include "semihosting/syscalls.h" #include "semihosting/console.h"
softmmu/runstate.c +1 -1
@@ -30,7 +30,7 @@#include "crypto/cipher.h" #include "crypto/init.h" #include "exec/cpu-common.h" -#include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "hw/boards.h" #include "migration/misc.h" #include "migration/postcopy-ram.h"
target/m68k/m68k-semi.c +1 -1
@@ -20,7 +20,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "gdbstub/helpers.h" #include "semihosting/syscalls.h" #include "semihosting/softmmu-uaccess.h"
target/mips/tcg/sysemu/mips-semi.c +1 -1
@@ -20,7 +20,7 @@#include "qemu/osdep.h" #include "cpu.h" #include "qemu/log.h" -#include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "gdbstub/helpers.h" #include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h"
target/nios2/nios2-semi.c +1 -1
@@ -23,7 +23,7 @@#include "qemu/osdep.h" #include "cpu.h" -#include "exec/gdbstub.h" +#include "gdbstub/syscalls.h" #include "gdbstub/helpers.h" #include "semihosting/syscalls.h" #include "semihosting/softmmu-uaccess.h"
gdbstub/meson.build +4 -0
@@ -5,6 +5,10 @@ # specific_ss.add(files('gdbstub.c')) + +# These have to built to the target ABI +specific_ss.add(files('syscalls.c')) + softmmu_ss.add(files('softmmu.c')) user_ss.add(files('user.c'))
Signature · 1 line
2.39.2
PATCH v4 22/26 gdbstub: only compile gdbstub twice for whole build
In reply to Alex BennéeNow we have removed any target specific bits from the core gdbstub code we only need to build it twice. We have to jump a few meson hoops to manually define the CONFIG_USER_ONLY symbol but it seems to work.
---
v3
- also include user and softmmu bits in the library
v4
- include genh for config-poison.h
--- gdbstub/gdbstub.c | 4 +--- gdbstub/meson.build | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-)
gdbstub/gdbstub.c +1 -3
@@ -39,9 +39,7 @@#include "sysemu/hw_accel.h" #include "sysemu/runstate.h" -#include "exec/exec-all.h" #include "exec/replay-core.h" -#include "exec/tb-flush.h" #include "exec/hwaddr.h" #include "internals.h"
@@ -1612,7 +1610,7 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = { .cmd_startswith = 1, .schema = "s:l,l0" }, -#if defined(CONFIG_USER_ONLY ) && defined(CONFIG_LINUX_USER ) +#if defined(CONFIG_USER_ONLY ) && defined(CONFIG_LINUX ) { .handler = gdb_handle_query_xfer_auxv, .cmd = "Xfer:auxv:read::",
gdbstub/meson.build +26 -4
@@ -4,13 +4,35 @@ # types such as hwaddr. # -specific_ss.add(files('gdbstub.c')) +# We need to build the core gdb code via a library to be able to tweak +# cflags so: + +gdb_user_ss = ss.source_set() +gdb_softmmu_ss = ss.source_set() + +# We build two versions of gdbstub, one for each mode +gdb_user_ss.add(files('gdbstub.c', 'user.c')) +gdb_softmmu_ss.add(files('gdbstub.c', 'softmmu.c')) + +gdb_user_ss = gdb_user_ss.apply(config_host, strict: false) +gdb_softmmu_ss = gdb_softmmu_ss.apply(config_host, strict: false) + +libgdb_user = static_library('gdb_user', + gdb_user_ss.sources() + genh, + name_suffix: 'fa', + c_args: '-DCONFIG_USER_ONLY') + +libgdb_softmmu = static_library('gdb_softmmu', + gdb_softmmu_ss.sources() + genh, + name_suffix: 'fa') + +gdb_user = declare_dependency(link_whole: libgdb_user) +user_ss.add(gdb_user) +gdb_softmmu = declare_dependency(link_whole: libgdb_softmmu) +softmmu_ss.add(gdb_softmmu) # These have to built to the target ABI specific_ss.add(files('syscalls.c')) -softmmu_ss.add(files('softmmu.c')) -user_ss.add(files('user.c')) - # The user-target is specialised by the guest specific_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-target.c'))
Signature · 1 line
2.39.2
Re: [PATCH v4 22/26] gdbstub: only compile gdbstub twice for whole build
Quoted 11 lines · Alex Bennée
Now we have removed any target specific bits from the core gdbstub code we only need to build it twice. We have to jump a few meson hoops to manually define the
CONFIG_USER_ONLYsymbol but it seems to work.Signed-off-by Alex Bennée<[email protected]>---
v3
- also include user and softmmu bits in the library
v4
- include genh forconfig-poison.h
Quoted 4 lines
--- gdbstub/gdbstub.c | 4 +--- gdbstub/meson.build | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-)
r~
PATCH v4 23/26 testing: probe gdb for supported architectures ahead of time
In reply to Alex BennéeCurrently when we encounter a gdb that is old or not built with multiarch in mind we fail rather messily. Try and improve the situation by probing ahead of time and setting HOST_GDB_SUPPORTS_ARCH=y in the relevant tcg configs. We can then skip and give a more meaningful message if we don't run the test.
---
v4
- convert script to python, use mapping to set arches
- update MAINTAINERS
--- MAINTAINERS | 1 + configure | 8 ++ scripts/probe-gdb-support.py | 88 +++++++++++++++++++ tests/tcg/aarch64/Makefile.target | 2 +- tests/tcg/multiarch/Makefile.target | 5 ++ .../multiarch/system/Makefile.softmmu-target | 6 +- tests/tcg/s390x/Makefile.target | 2 +- 7 files changed, 109 insertions(+), 3 deletions(-) create mode 100755 scripts/probe-gdb-support.py
MAINTAINERS +1 -0
@@ -2739,6 +2739,7 @@ F: include/gdbstub/* F: gdb-xml/ F: tests/tcg/multiarch/gdbstub/ F: scripts/feature_to_c.sh +F: scripts/probe-gdb-support.py Memory API M: Paolo Bonzini <[email protected]>
configure +8 -0
@@ -230,6 +230,7 @@ stack_protector="" safe_stack="" use_containers="yes" gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb") +gdb_arches="" if test -e "$source_path/.git" then
@@ -2392,6 +2393,7 @@ if test -n "$gdb_bin"; then gdb_version=$($gdb_bin --version | head -n 1) if version_ge ${gdb_version##* } 9.1; then echo "HAVE_GDB_BIN=$gdb_bin" >> $config_host_mak + gdb_arches=$("$source_path/scripts/probe-gdb-support.py" $gdb_bin) else gdb_bin="" fi
@@ -2516,6 +2518,12 @@ for target in $target_list; do write_target_makefile "build-tcg-tests-$target" >> "$config_target_mak" echo "BUILD_STATIC=$build_static" >> "$config_target_mak" echo "QEMU=$PWD/$qemu" >> "$config_target_mak" + + # will GDB work with these binaries? + if test "${gdb_arches#*$arch}" != "$gdb_arches"; then + echo "HOST_GDB_SUPPORTS_ARCH=y" >> "$config_target_mak" + fi + echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs tcg_tests_targets="$tcg_tests_targets $target" fi
scripts/probe-gdb-support.py new file +88 -0
88 lines not on this page · raw message
tests/tcg/aarch64/Makefile.target +1 -1
@@ -81,7 +81,7 @@ sha512-vector: sha512.c TESTS += sha512-vector -ifneq ($(HAVE_GDB_BIN),) +ifeq ($(HOST_GDB_SUPPORTS_ARCH),y) GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py run-gdbstub-sysregs: sysregs
tests/tcg/multiarch/Makefile.target +5 -0
@@ -64,6 +64,7 @@ run-test-mmap-%: test-mmap $(call run-test, test-mmap-$*, $(QEMU) -p $* $<, $< ($* byte pages)) ifneq ($(HAVE_GDB_BIN),) +ifeq ($(HOST_GDB_SUPPORTS_ARCH),y) GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py run-gdbstub-sha1: sha1
@@ -87,6 +88,10 @@ run-gdbstub-thread-breakpoint: testthread --bin $< --test $(MULTIARCH_SRC)/gdbstub/test-thread-breakpoint.py, \ hitting a breakpoint on non-main thread) +else +run-gdbstub-%: + $(call skip-test, "gdbstub test $*", "no guest arch support") +endif else run-gdbstub-%: $(call skip-test, "gdbstub test $*", "need working gdb")
tests/tcg/multiarch/system/Makefile.softmmu-target +5 -1
@@ -15,6 +15,7 @@ MULTIARCH_TEST_SRCS=$(wildcard $(MULTIARCH_SYSTEM_SRC)/*.c) MULTIARCH_TESTS = $(patsubst $(MULTIARCH_SYSTEM_SRC)/%.c, %, $(MULTIARCH_TEST_SRCS)) ifneq ($(HAVE_GDB_BIN),) +ifeq ($(HOST_GDB_SUPPORTS_ARCH),y) GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py run-gdbstub-memory: memory
@@ -26,7 +27,10 @@ run-gdbstub-memory: memory "-monitor none -display none -chardev file$(COMMA)path=$<.out$(COMMA)id=output $(QEMU_OPTS)" \ --bin $< --test $(MULTIARCH_SRC)/gdbstub/memory.py, \ softmmu gdbstub support) - +else +run-gdbstub-%: + $(call skip-test, "gdbstub test $*", "no guest arch support") +endif else run-gdbstub-%: $(call skip-test, "gdbstub test $*", "need working gdb")
tests/tcg/s390x/Makefile.target +1 -1
@@ -51,7 +51,7 @@ $(Z15_TESTS): CFLAGS+=-march=z15 -O2 TESTS+=$(Z15_TESTS) endif -ifneq ($(HAVE_GDB_BIN),) +ifeq ($(HOST_GDB_SUPPORTS_ARCH),y) GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py run-gdbstub-signals-s390x: signals-s390x
Signature · 1 line
2.39.2
Re: [PATCH v4 23/26] testing: probe gdb for supported architectures ahead of time
scripts/probe-gdb-support.py line 32
Quoted 9 lines · Alex Bennée
scripts/probe-gdb-support.py new file +9
-0+# mappings from gdb arch to QEMU target +mappings = { + "alpha" : "alpha", + "aarch64" : ["aarch64", "aarch64_be"], + "armv7": "arm", + "armv8-a" : ["aarch64", "aarch64_be"], + "avr" : "avr", + "cris" : "cris", + # hexagon?
No hexagon in upstream gdb.
scripts/probe-gdb-support.py line 36
Quoted 4 lines
scripts/probe-gdb-support.py new file +4
-0+ "hppa1.0" : "hppa", + "i386" : "i386", + "i386:x86-64" : "x86_64", + # loongarch?
Loongarch64 in my recent gdb build.
r~
Re: [PATCH v4 23/26] testing: probe gdb for supported architectures ahead of time
In reply to Alex BennéeQuoted 1 line · Alex Bennée
+ "powerpc:common64" : "ppc64",
[ "ppc64", "ppc64le" ]
r~
PATCH v4 24/26 include: split target_long definition from cpu-defs
In reply to Alex BennéeWhile we will continue to include this via cpu-defs it is useful to be able to define this separately for 32 and 64 bit versions of an otherwise target independent compilation unit.
---
v4
- update MAINTAINERS
--- MAINTAINERS | 1 + include/exec/cpu-defs.h | 19 +---------------- include/exec/target_long.h | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 include/exec/target_long.h
MAINTAINERS +1 -0
@@ -137,6 +137,7 @@ F: docs/devel/tcg* F: include/exec/cpu*.h F: include/exec/exec-all.h F: include/exec/tb-flush.h +F: include/exec/target_long.h F: include/exec/helper*.h F: include/sysemu/cpus.h F: include/sysemu/tcg.h
include/exec/cpu-defs.h +1 -18
@@ -55,24 +55,7 @@# endif #endif -#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8) - -/* target_ulong is the type of a virtual address */ -#if TARGET_LONG_SIZE ==4 -typedef int32_t target_long ; -typedef uint32_t target_ulong ; -#define TARGET_FMT_lx "%08x" -#define TARGET_FMT_ld "%d" -#define TARGET_FMT_lu "%u" -#elif TARGET_LONG_SIZE ==8 -typedef int64_t target_long ; -typedef uint64_t target_ulong ; -#define TARGET_FMT_lx "%016" PRIx64 -#define TARGET_FMT_ld "%" PRId64 -#define TARGET_FMT_lu "%" PRIu64 -#else -#error TARGET_LONG_SIZE undefined -#endif +#include "exec/target_long.h" #if !defined(CONFIG_USER_ONLY ) && defined(CONFIG_TCG )
include/exec/target_long.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v4 25/26 gdbstub: split out softmmu/user specifics for syscall handling
In reply to Alex BennéeMost of the syscall code is config agnostic aside from the size of target_ulong. In preparation for the next patch move the final bits of specialisation into the appropriate user and softmmu helpers.
---
v4
- checkpatch cleanups
--- gdbstub/internals.h | 5 +++++ gdbstub/softmmu.c | 24 ++++++++++++++++++++++++ gdbstub/syscalls.c | 35 +++++++++++------------------------ gdbstub/user.c | 24 ++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 24 deletions(-)
gdbstub/internals.h +5 -0
@@ -195,6 +195,11 @@ bool gdb_handled_syscall(void);void gdb_disable_syscalls (void );void gdb_syscall_reset (void ); +/* user/softmmu specific signal handling */ +void gdb_pre_syscall_handling (void ); +bool gdb_send_syscall_now (void ); +void gdb_post_syscall_handling (void ); +/* * Break/Watch point support - there is an implementation for softmmu * and user mode.
gdbstub/softmmu.c +24 -0
@@ -103,6 +103,30 @@ static void gdb_chr_event(void *opaque, QEMUChrEvent event) } } +/* +* In softmmu mode we stop the VM and wait to send the syscall packet +* until notification that the CPU has stopped. This must be done +* because if the packet is sent now the reply from the syscall +* request could be received while the CPU is still in the running +* state, which can cause packets to be dropped and state transition +* 'T' packets to be sent while the syscall is still being processed. +*/ + +void gdb_pre_syscall_handling (void ) +{ +vm_stop (RUN_STATE_DEBUG ); +} + +bool gdb_send_syscall_now (void ) +{ +return false; +} + +void gdb_post_syscall_handling (void ) +{ +qemu_cpu_kick (gdbserver_state.c_cpu); +} +static void gdb_vm_state_change (void *opaque,bool running,RunState state) {CPUState *cpu = gdbserver_state.c_cpu;
gdbstub/syscalls.c +11 -24
@@ -104,9 +104,10 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) } gdbserver_syscall_state.current_syscall_cb = cb; -#ifndef CONFIG_USER_ONLY -vm_stop (RUN_STATE_DEBUG ); -#endif + +/* user/softmmu specific handling */ +gdb_pre_syscall_handling (); + p = &gdbserver_syscall_state.syscall_buf[0 ]; p_end = &gdbserver_syscall_state.syscall_buf[sizeof (gdbserver_syscall_state.syscall_buf)]; *(p++) ='F' ;
@@ -141,27 +142,13 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) } } *p =0 ; -#ifdef CONFIG_USER_ONLY -gdb_put_packet (gdbserver_syscall_state.syscall_buf); -/* -* Return control to gdb for it to process the syscall request. -* Since the protocol requires that gdb hands control back to us -* using a "here are the results" F packet, we don't need to check -* gdb_handlesig's return value (which is the signal to deliver if -* execution was resumed via a continue packet). -*/ -gdb_handlesig (gdbserver_state.c_cpu,0 ); -#else -/* -* In this case wait to send the syscall packet until notification that -* the CPU has stopped. This must be done because if the packet is sent -* now the reply from the syscall request could be received while the CPU -* is still in the running state, which can cause packets to be dropped -* and state transition 'T' packets to be sent while the syscall is still -* being processed. -*/ -qemu_cpu_kick (gdbserver_state.c_cpu); -#endif + +if (gdb_send_syscall_now ()) {/* true only for *-user */ +gdb_put_packet (gdbserver_syscall_state.syscall_buf); + } + +/* user/softmmu specific handling */ +gdb_post_syscall_handling (); }void gdb_do_syscall (gdb_syscall_complete_cb cb,const char *fmt, ...)
gdbstub/user.c +24 -0
@@ -472,3 +472,27 @@ void gdb_breakpoint_remove_all(CPUState *cs) {cpu_breakpoint_remove_all (cs,BP_GDB ); } + +/* +* For user-mode syscall support we send the system call immediately +* and then return control to gdb for it to process the syscall request. +* Since the protocol requires that gdb hands control back to us +* using a "here are the results" F packet, we don't need to check +* gdb_handlesig's return value (which is the signal to deliver if +* execution was resumed via a continue packet). +*/ + +void gdb_pre_syscall_handling (void ) +{ +return ; +} + +bool gdb_send_syscall_now (void ) +{ +return true; +} + +void gdb_post_syscall_handling (void ) +{ +gdb_handlesig (gdbserver_state.c_cpu,0 ); +}
Signature · 1 line
2.39.2
Re: [PATCH v4 25/26] gdbstub: split out softmmu/user specifics for syscall handling
gdbstub/syscalls.c void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) · line 109
Quoted 10 lines · Alex Bennée
gdbstub/syscalls.c +3
-3@@ -104,9 +104,10 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) } gdbserver_syscall_state.current_syscall_cb = cb; -#ifndef CONFIG_USER_ONLY -vm_stop (RUN_STATE_DEBUG ); -#endif + +/* user/softmmu specific handling */ +gdb_pre_syscall_handling ();
I think this placement of vm_stop is inconvenient, and that we don't need to continue. If we move it down below the construction of gdbserver_syscall_state.syscall_buf...
Quoted 25 lines
gdbstub/syscalls.c +0
-18p = &gdbserver_syscall_state.syscall_buf[0 ]; p_end = &gdbserver_syscall_state.syscall_buf[sizeof (gdbserver_syscall_state.syscall_buf)]; *(p++) ='F' ;@@ -141,27 +142,13 @@ void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) } } *p =0 ; -#ifdef CONFIG_USER_ONLY -gdb_put_packet (gdbserver_syscall_state.syscall_buf); -/* -* Return control to gdb for it to process the syscall request. -* Since the protocol requires that gdb hands control back to us -* using a "here are the results" F packet, we don't need to check -* gdb_handlesig's return value (which is the signal to deliver if -* execution was resumed via a continue packet). -*/ -gdb_handlesig (gdbserver_state.c_cpu,0 ); -#else -/* -* In this case wait to send the syscall packet until notification that -* the CPU has stopped. This must be done because if the packet is sent -* now the reply from the syscall request could be received while the CPU -* is still in the running state, which can cause packets to be dropped -* and state transition 'T' packets to be sent while the syscall is still -* being processed.
gdbstub/syscalls.c void gdb_do_syscallv(gdb_syscall_complete_cb cb, const char *fmt, va_list va) · line 151
Quoted 10 lines
gdbstub/syscalls.c +7
-3-*/ -qemu_cpu_kick (gdbserver_state.c_cpu); -#endif + +if (gdb_send_syscall_now ()) {/* true only for *-user */ +gdb_put_packet (gdbserver_syscall_state.syscall_buf); + } + +/* user/softmmu specific handling */ +gdb_post_syscall_handling ();
... then we don't need 3 separate hooks for user/softmmu.
softmmu:
void gdb_syscall_handling(const char *syscall_buf)
{
vm_stop(RUN_STATE_DEBUG);
qemu_cpu_kick(gdbserver_state.c_cpu);
}user:
void gdb_syscall_handling(const char *syscall_buf)
{
gdb_put_packet(syscall_buf);
gdb_handlesig(gdbserver_state.c_cpu, 0);
}r~
PATCH v4 26/26 gdbstub: move update guest debug to accel ops
In reply to Alex BennéeFrom: Mads Ynddal <[email protected]>
Continuing the refactor of a48e7d9e52 (gdbstub: move guest debug support check to ops) by removing hardcoded kvm_enabled() from generic cpu.c code, and replace it with a property of AccelOpsClass.
Message-Id: <[email protected]>
--- include/sysemu/accel-ops.h | 1 + accel/kvm/kvm-accel-ops.c | 8 ++++++++ cpu.c | 11 ++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-)
include/sysemu/accel-ops.h +1 -0
@@ -48,6 +48,7 @@ struct AccelOpsClass {/* gdbstub hooks */ bool (*supports_guest_debug)(void ); +int (*update_guest_debug)(CPUState *cpu);int (*insert_breakpoint)(CPUState *cpu,int type,vaddr addr,vaddr len);int (*remove_breakpoint)(CPUState *cpu,int type,vaddr addr,vaddr len);void (*remove_all_breakpoints)(CPUState *cpu);
accel/kvm/kvm-accel-ops.c +8 -0
@@ -86,6 +86,13 @@ static bool kvm_cpus_are_resettable(void)return !kvm_enabled () ||kvm_cpu_check_are_resettable (); } +#ifdef KVM_CAP_SET_GUEST_DEBUG +static int kvm_update_guest_debug_ops (CPUState *cpu) +{ +return kvm_update_guest_debug (cpu,0 ); +} +#endif +static void kvm_accel_ops_class_init (ObjectClass *oc,void *data) {AccelOpsClass *ops =ACCEL_OPS_CLASS (oc);
@@ -99,6 +106,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;#ifdef KVM_CAP_SET_GUEST_DEBUG + ops->update_guest_debug = kvm_update_guest_debug_ops; ops->supports_guest_debug = kvm_supports_guest_debug; ops->insert_breakpoint = kvm_insert_breakpoint; ops->remove_breakpoint = kvm_remove_breakpoint;
cpu.c +8 -3
@@ -31,8 +31,8 @@#include "hw/core/sysemu-cpu-ops.h" #include "exec/address-spaces.h" #endif +#include "sysemu/cpus.h" #include "sysemu/tcg.h" -#include "sysemu/kvm.h" #include "exec/replay-core.h" #include "exec/cpu-common.h" #include "exec/exec-all.h"
@@ -326,9 +326,14 @@ void cpu_single_step(CPUState *cpu, int enabled) {if (cpu->singlestep_enabled != enabled) { cpu->singlestep_enabled = enabled; -if (kvm_enabled ()) { -kvm_update_guest_debug (cpu,0 ); + +#if !defined(CONFIG_USER_ONLY ) +const AccelOpsClass *ops =cpus_get_accel (); +if (ops->update_guest_debug) { + ops->update_guest_debug (cpu); } +#endif +trace_breakpoint_singlestep (cpu->cpu_index, enabled); } }
Signature · 1 line
2.39.2