gdbstub re-factor and SVE support
cover gdbstub re-factor and SVE support
Hi,
This RFC is for supporting SVE registers in QEMU's gdbstub.
However on the way to that there is a bunch of re-factoring to the core gdbstub code to remove some of the hardcoded size limits from its various buffers. By using dynamically sized buffers we are less likely to trip up as we potentially push these large registers into the staging memory before transmission. Ultimately we end up touching all guest gdbstub register code to make them push bytes into a GByteArray rather than directly poking memory. For the most part this is a mechanical process although PPC makes it a little uglier as it can dynamically change endianess and therefor has its own custom byte swapping routine after the fact.
One other thing to note is that currently we don't match the existing gdbstub XML (org.gnu.gdb.aarch64.sve) opting instead to send our own register layout (org.qemu.gdb.aarch64.sve). The principle difference is we report the registers in quads (e.g. z0p0 -> z0pN) depending on the configured size of the machine. It could be changed easily enough but I was having trouble getting gdbstub on the current master to work so went with something I could understand more easily.
Alex Bennée (11):
gdbstub: move allocation of GDBState to one place
gdbstub: stop passing GDBState * around
gdbstub: move str_buf to GDBState and use GString
gdbstub: move mem_buf to GDBState and use GByteArray
gdbstub: add helper for 128 bit registers target/arm: use gdb_get_reg helpers
target/m68k: use gdb_get_reg helpers
gdbstub: extend GByteArray to read register helpers target/arm: prepare for multiple dynamic XMLs target/arm: explicitly encode regnum in our XML target/arm: generate xml description of our SVE registers
include/exec/gdbstub.h | 41 ++- include/hw/core/cpu.h | 2 +- target/alpha/cpu.h | 2 +- target/arm/cpu.h | 34 +- target/cris/cpu.h | 4 +- target/hppa/cpu.h | 2 +- target/i386/cpu.h | 2 +- target/lm32/cpu.h | 2 +- target/m68k/cpu.h | 2 +- target/microblaze/cpu.h | 2 +- target/mips/internal.h | 2 +- target/openrisc/cpu.h | 2 +- target/ppc/cpu.h | 4 +- target/riscv/cpu.h | 2 +- target/s390x/internal.h | 2 +- target/sh4/cpu.h | 2 +- target/sparc/cpu.h | 2 +- target/xtensa/cpu.h | 2 +- gdbstub.c | 520 +++++++++++++++------------- hw/core/cpu.c | 2 +- target/alpha/gdbstub.c | 2 +- target/arm/gdbstub.c | 137 +++++++- target/arm/gdbstub64.c | 2 +- target/arm/helper.c | 108 ++++-- target/cris/gdbstub.c | 4 +- target/hppa/gdbstub.c | 2 +- target/i386/gdbstub.c | 2 +- target/lm32/gdbstub.c | 2 +- target/m68k/gdbstub.c | 2 +- target/m68k/helper.c | 33 +- target/microblaze/gdbstub.c | 2 +- target/mips/gdbstub.c | 2 +- target/nios2/cpu.c | 2 +- target/openrisc/gdbstub.c | 2 +- target/ppc/gdbstub.c | 48 +-- target/ppc/translate_init.inc.c | 54 +-- target/riscv/gdbstub.c | 18 +- target/s390x/gdbstub.c | 30 +- target/sh4/gdbstub.c | 2 +- target/sparc/gdbstub.c | 2 +- target/xtensa/gdbstub.c | 2 +- tests/tcg/multiarch/float_helpers.c | 7 +- 42 files changed, 659 insertions(+), 439 deletions(-)
Signature · 1 line
2.20.1
RFC PATCH 1/11 gdbstub: move allocation of GDBState to one place
We use g_new0() as it is the preferred form for such allocations. We can also ensure that gdbserver_state is reset in one place.
--- gdbstub.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
gdbstub.c +9 -5
@@ -374,6 +374,13 @@ static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER;static GDBState *gdbserver_state; +static GDBState *gdb_allocate_state (void ) +{ +g_assert (!gdbserver_state); + gdbserver_state =g_new0 (GDBState,1 ); +return gdbserver_state; +} +bool gdb_has_xml;#ifdef CONFIG_USER_ONLY
@@ -3083,15 +3090,13 @@ static bool gdb_accept(void)return false; } - s =g_malloc0 (sizeof (GDBState)); + s =gdb_allocate_state ();create_default_process (s); s->processes[0 ].attached = true; s->c_cpu =gdb_first_attached_cpu (s); s->g_cpu = s->c_cpu; s->fd = fd; gdb_has_xml = false; - - gdbserver_state = s;return true; }
@@ -3359,8 +3364,7 @@ int gdbserver_start(const char *device) s = gdbserver_state;if (!s) { - s =g_malloc0 (sizeof (GDBState)); - gdbserver_state = s; + s =gdb_allocate_state ();qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL );
Signature · 1 line
2.20.1
Re: [RFC PATCH 01/11] gdbstub: move allocation of GDBState to one place
Quoted 7 lines · Alex Bennée
We use
g_new0()as it is the preferred form for such allocations. We can also ensure thatgdbserver_stateis reset in one place.Signed-off-by Alex Bennée <[email protected]>--- gdbstub.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
r~
Re: [RFC PATCH 01/11] gdbstub: move allocation of GDBState to one place
In reply to Alex Bennéegdbstub.c static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; · line 383
Quoted 10 lines · Alex Bennée
static GDBState
*gdbserver_state;gdbstub.c +7
-0+static GDBState *gdb_allocate_state (void ) +{ +g_assert (!gdbserver_state); + gdbserver_state =g_new0 (GDBState,1 ); +return gdbserver_state; +} +
Actually, if we're only going to have one, why are we allocating it dynamically? We might as well allocate it statically and drop the pointer indirection.
r~
Re: [RFC PATCH 01/11] gdbstub: move allocation of GDBState to one place
Quoted 4 lines · Richard Henderson
Quoted 3 lines · Alex Bennée
static GDBState
*gdbserver_state;
Quoted 11 lines
gdbstub.c static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; · line 383
Quoted 7 lines
gdbstub.c +7
-0+static GDBState *gdb_allocate_state (void ) +{ +g_assert (!gdbserver_state); + gdbserver_state =g_new0 (GDBState,1 ); +return gdbserver_state; +} +Actually, if we're only going to have one, why are we allocating it dynamically? We might as well allocate it statically and drop the pointer indirection.
In use_gdb_syscalls(), we check if gdbserver_state is NULL:
| /* -semihosting-config target=auto */
| /* On the first call check if gdb is connected and remember. */
| if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
| gdb_syscall_mode = (gdbserver_state ? GDB_SYS_ENABLED
| : GDB_SYS_DISABLED);
| }So we cannot drop the pointer or we have to add some flag to do this test.
Damien
Re: [RFC PATCH 01/11] gdbstub: move allocation of GDBState to one place
Quoted 20 lines · Damien Hedde
Quoted 4 lines · Richard Henderson
Quoted 3 lines · Alex Bennée
static GDBState
*gdbserver_state;Quoted 11 lines
gdbstub.c static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; · line 383
Quoted 7 lines
gdbstub.c +7
-0+static GDBState *gdb_allocate_state (void ) +{ +g_assert (!gdbserver_state); + gdbserver_state =g_new0 (GDBState,1 ); +return gdbserver_state; +} +Actually, if we're only going to have one, why are we allocating it dynamically? We might as well allocate it statically and drop the pointer indirection.
In
use_gdb_syscalls(), we check ifgdbserver_stateis NULL:
Quoted 8 lines
| /* -semihosting-config target=auto */ | /* On the first call check if gdb is connected and remember. */ | if (gdb_syscall_mode == GDB_SYS_UNKNOWN) { | gdb_syscall_mode = (gdbserver_state ? GDB_SYS_ENABLED | : GDB_SYS_DISABLED); | }So we cannot drop the pointer or we have to add some flag to do this test.
True, but perhaps a bool gdbserver_state.in_use is a clearer way to do this?
r~
Re: [RFC PATCH 01/11] gdbstub: move allocation of GDBState to one place
In reply to Alex BennéeQuoted 7 lines · Alex Bennée
We use
g_new0()as it is the preferred form for such allocations. We can also ensure thatgdbserver_stateis reset in one place.Signed-off-by Alex Bennée <[email protected]>--- gdbstub.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
--
Damien
RFC PATCH 2/11 gdbstub: stop passing GDBState * around
In reply to Alex BennéeWe only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier.
--- gdbstub.c | 307 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 177 insertions(+), 130 deletions(-)
gdbstub.c +177 -130
@@ -1399,7 +1399,6 @@ static int cmd_parse_params(const char *data, const char *schema, } typedef struct GdbCmdContext { - GDBState *s; GdbCmdVariant *params; int num_params; uint8_t mem_buf[MAX_PACKET_LENGTH];
@@ -1480,7 +1479,7 @@ static int process_string_cmd(GDBState *s, void *user_ctx, const char *data,return -1 ; } - gdb_ctx.s = s; +g_assert (s == gdbserver_state); cmd->handler (&gdb_ctx, user_ctx);return 0 ; }
@@ -1505,7 +1504,7 @@ static void run_cmd_parser(GDBState *s, const char *data,static void handle_detach (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBProcess *process; -GDBState *s = gdb_ctx->s; +GDBState *s = gdbserver_state;uint32_t pid =1 ;if (s->multiprocess) {
@@ -1540,40 +1539,44 @@ static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_thread_alive (GdbCmdContext *gdb_ctx,void *user_ctx) {CPUState *cpu; +GDBState *s = gdbserver_state;if (!gdb_ctx->num_params) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }if (gdb_ctx->params[0 ].thread_id.kind ==GDB_READ_THREAD_ERR ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; } - cpu =gdb_get_cpu (gdb_ctx->s, gdb_ctx->params[0 ].thread_id.pid, + cpu =gdb_get_cpu (s, gdb_ctx->params[0 ].thread_id.pid, gdb_ctx->params[0 ].thread_id.tid);if (!cpu) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; } -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" ); }static void handle_continue (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +if (gdb_ctx->num_params) { -gdb_set_cpu_pc (gdb_ctx->s, gdb_ctx->params[0 ].val_ull); +gdb_set_cpu_pc (s, gdb_ctx->params[0 ].val_ull); } - gdb_ctx->s->signal =0 ; -gdb_continue (gdb_ctx->s); + s->signal =0 ; +gdb_continue (s); }static void handle_cont_with_sig (GdbCmdContext *gdb_ctx,void *user_ctx) {unsigned long signal =0 ; +GDBState *s = gdbserver_state;/* * Note: C sig;[addr] is currently unsupported and we simply
@@ -1583,36 +1586,37 @@ static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) signal = gdb_ctx->params[0 ].val_ul; } - gdb_ctx->s->signal =gdb_signal_to_target (signal); -if (gdb_ctx->s->signal ==-1 ) { - gdb_ctx->s->signal =0 ; + s->signal =gdb_signal_to_target (signal); +if (s->signal ==-1 ) { + s->signal =0 ; } -gdb_continue (gdb_ctx->s); +gdb_continue (s); }static void handle_set_thread (GdbCmdContext *gdb_ctx,void *user_ctx) {CPUState *cpu; +GDBState *s = gdbserver_state;if (gdb_ctx->num_params !=2 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }if (gdb_ctx->params[1 ].thread_id.kind ==GDB_READ_THREAD_ERR ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }if (gdb_ctx->params[1 ].thread_id.kind !=GDB_ONE_THREAD ) { -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" );return ; } - cpu =gdb_get_cpu (gdb_ctx->s, gdb_ctx->params[1 ].thread_id.pid, + cpu =gdb_get_cpu (s, gdb_ctx->params[1 ].thread_id.pid, gdb_ctx->params[1 ].thread_id.tid);if (!cpu) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }
@@ -1622,15 +1626,15 @@ static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx)*/ switch (gdb_ctx->params[0 ].opcode) {case 'c' : - gdb_ctx->s->c_cpu = cpu; -put_packet (gdb_ctx->s,"OK" ); + s->c_cpu = cpu; +put_packet (s,"OK" );break ;case 'g' : - gdb_ctx->s->g_cpu = cpu; -put_packet (gdb_ctx->s,"OK" ); + s->g_cpu = cpu; +put_packet (s,"OK" );break ;default : -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );break ; } }
@@ -1638,9 +1642,10 @@ static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_insert_bp (GdbCmdContext *gdb_ctx,void *user_ctx) {int res; +GDBState *s = gdbserver_state;if (gdb_ctx->num_params !=3 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }
@@ -1648,22 +1653,23 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx, void *user_ctx) gdb_ctx->params[1 ].val_ull, gdb_ctx->params[2].val_ull);if (res >=0 ) { -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" );return ; }else if (res == -ENOSYS ) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" );return ; } -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" ); }static void handle_remove_bp (GdbCmdContext *gdb_ctx,void *user_ctx) {int res; +GDBState *s = gdbserver_state;if (gdb_ctx->num_params !=3 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }
@@ -1671,14 +1677,14 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) gdb_ctx->params[1 ].val_ull, gdb_ctx->params[2].val_ull);if (res >=0 ) { -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" );return ; }else if (res == -ENOSYS ) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" );return ; } -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" ); }/*
@@ -1695,100 +1701,107 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_set_reg (GdbCmdContext *gdb_ctx,void *user_ctx) {int reg_size; +GDBState *s = gdbserver_state;if (!gdb_has_xml) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" );return ; }if (gdb_ctx->num_params !=2 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; } reg_size =strlen (gdb_ctx->params[1 ].data) /2 ;hextomem (gdb_ctx->mem_buf, gdb_ctx->params[1 ].data, reg_size); -gdb_write_register (gdb_ctx->s->g_cpu, gdb_ctx->mem_buf, +gdb_write_register (s->g_cpu, gdb_ctx->mem_buf, gdb_ctx->params[0 ].val_ull); -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" ); }static void handle_get_reg (GdbCmdContext *gdb_ctx,void *user_ctx) {int reg_size; +GDBState *s = gdbserver_state;if (!gdb_has_xml) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" );return ; }if (!gdb_ctx->num_params) { -put_packet (gdb_ctx->s,"E14" ); +put_packet (s,"E14" );return ; } - reg_size =gdb_read_register (gdb_ctx->s->g_cpu, gdb_ctx->mem_buf, + reg_size =gdb_read_register (s->g_cpu, gdb_ctx->mem_buf, gdb_ctx->params[0 ].val_ull);if (!reg_size) { -put_packet (gdb_ctx->s,"E14" ); +put_packet (s,"E14" );return ; }memtohex (gdb_ctx->str_buf, gdb_ctx->mem_buf, reg_size); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_write_mem (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +if (gdb_ctx->num_params !=3 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }/* hextomem() reads 2*len bytes */ if (gdb_ctx->params[1 ].val_ull >strlen (gdb_ctx->params[2 ].data) /2 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }hextomem (gdb_ctx->mem_buf, gdb_ctx->params[2 ].data, gdb_ctx->params[1 ].val_ull); -if (target_memory_rw_debug (gdb_ctx->s->g_cpu, gdb_ctx->params[0 ].val_ull, +if (target_memory_rw_debug (s->g_cpu, gdb_ctx->params[0 ].val_ull, gdb_ctx->mem_buf, gdb_ctx->params[1 ].val_ull, true)) { -put_packet (gdb_ctx->s,"E14" ); +put_packet (s,"E14" );return ; } -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" ); }static void handle_read_mem (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +if (gdb_ctx->num_params !=2 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }/* memtohex() doubles the required space */ if (gdb_ctx->params[1 ].val_ull >MAX_PACKET_LENGTH /2 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; } -if (target_memory_rw_debug (gdb_ctx->s->g_cpu, gdb_ctx->params[0 ].val_ull, +if (target_memory_rw_debug (s->g_cpu, gdb_ctx->params[0 ].val_ull, gdb_ctx->mem_buf, gdb_ctx->params[1 ].val_ull, false)) { -put_packet (gdb_ctx->s,"E14" ); +put_packet (s,"E14" );return ; }memtohex (gdb_ctx->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1 ].val_ull); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_write_all_regs (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;target_ulong addr, len;uint8_t *registers;int reg_size;
@@ -1797,37 +1810,40 @@ static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx)return ; } -cpu_synchronize_state (gdb_ctx->s->g_cpu); +cpu_synchronize_state (s->g_cpu); registers = gdb_ctx->mem_buf; len =strlen (gdb_ctx->params[0 ].data) /2 ;hextomem (registers, gdb_ctx->params[0 ].data, len); -for (addr =0 ; addr < gdb_ctx->s->g_cpu->gdb_num_g_regs && len >0 ; +for (addr =0 ; addr < s->g_cpu->gdb_num_g_regs && len >0 ; addr++) { - reg_size =gdb_write_register (gdb_ctx->s->g_cpu, registers, addr); + reg_size =gdb_write_register (s->g_cpu, registers, addr); len -= reg_size; registers += reg_size; } -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" ); }static void handle_read_all_regs (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;target_ulong addr, len; -cpu_synchronize_state (gdb_ctx->s->g_cpu); +cpu_synchronize_state (s->g_cpu); len =0 ; -for (addr =0 ; addr < gdb_ctx->s->g_cpu->gdb_num_g_regs; addr++) { - len +=gdb_read_register (gdb_ctx->s->g_cpu, gdb_ctx->mem_buf + len, +for (addr =0 ; addr < s->g_cpu->gdb_num_g_regs; addr++) { + len +=gdb_read_register (s->g_cpu, gdb_ctx->mem_buf + len, addr); }memtohex (gdb_ctx->str_buf, gdb_ctx->mem_buf, len); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_file_io (GdbCmdContext *gdb_ctx,void *user_ctx) { -if (gdb_ctx->num_params >=1 && gdb_ctx->s->current_syscall_cb) { +GDBState *s = gdbserver_state; + +if (gdb_ctx->num_params >=1 && s->current_syscall_cb) {target_ulong ret, err; ret = (target_ulong )gdb_ctx->params[0 ].val_ull;
@@ -1836,51 +1852,56 @@ static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) }else { err =0 ; } - gdb_ctx->s->current_syscall_cb (gdb_ctx->s->c_cpu, ret, err); - gdb_ctx->s->current_syscall_cb =NULL ; + s->current_syscall_cb (s->c_cpu, ret, err); + s->current_syscall_cb =NULL ; }if (gdb_ctx->num_params >=3 && gdb_ctx->params[2 ].opcode == (uint8_t )'C' ) { -put_packet (gdb_ctx->s,"T02" ); +put_packet (s,"T02" );return ; } -gdb_continue (gdb_ctx->s); +gdb_continue (s); }static void handle_step (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +if (gdb_ctx->num_params) { -gdb_set_cpu_pc (gdb_ctx->s, (target_ulong )gdb_ctx->params[0 ].val_ull); +gdb_set_cpu_pc (s, (target_ulong )gdb_ctx->params[0 ].val_ull); } -cpu_single_step (gdb_ctx->s->c_cpu, sstep_flags); -gdb_continue (gdb_ctx->s); +cpu_single_step (s->c_cpu, sstep_flags); +gdb_continue (s); }static void handle_v_cont_query (GdbCmdContext *gdb_ctx,void *user_ctx) { -put_packet (gdb_ctx->s,"vCont;c;C;s;S" ); +GDBState *s = gdbserver_state; +put_packet (s,"vCont;c;C;s;S" ); }static void handle_v_cont (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;int res;if (!gdb_ctx->num_params) {return ; } - res =gdb_handle_vcont (gdb_ctx->s, gdb_ctx->params[0 ].data); + res =gdb_handle_vcont (s, gdb_ctx->params[0 ].data);if ((res == -EINVAL ) || (res == -ERANGE )) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" ); }else if (res) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" ); } }static void handle_v_attach (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;GDBProcess *process;CPUState *cpu;char thread_id[16 ];
@@ -1890,31 +1911,33 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx) goto cleanup; } - process =gdb_get_process (gdb_ctx->s, gdb_ctx->params[0 ].val_ul); + process =gdb_get_process (s, gdb_ctx->params[0 ].val_ul);if (!process) { goto cleanup; } - cpu =get_first_cpu_in_process (gdb_ctx->s, process); + cpu =get_first_cpu_in_process (s, process);if (!cpu) { goto cleanup; } process->attached = true; - gdb_ctx->s->g_cpu = cpu; - gdb_ctx->s->c_cpu = cpu; + s->g_cpu = cpu; + s->c_cpu = cpu; -gdb_fmt_thread_id (gdb_ctx->s, cpu, thread_id,sizeof (thread_id)); +gdb_fmt_thread_id (s, cpu, thread_id,sizeof (thread_id));snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"T%02xthread:%s;" ,GDB_SIGNAL_TRAP , thread_id); cleanup: -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_v_kill (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +/* Kill the target */ -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" );error_report ("QEMU: Terminated via GDBstub" );exit (0 ); }
@@ -1947,43 +1970,52 @@ static GdbCmdParseEntry gdb_v_commands_table[] = {static void handle_v_commands (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +if (!gdb_ctx->num_params) {return ; } -if (process_string_cmd (gdb_ctx->s,NULL , gdb_ctx->params[0 ].data, +if (process_string_cmd (s,NULL , gdb_ctx->params[0 ].data, gdb_v_commands_table,ARRAY_SIZE (gdb_v_commands_table))) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" ); } }static void handle_query_qemu_sstepbits (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"ENABLE=%x,NOIRQ=%x,NOTIMER=%x" ,SSTEP_ENABLE ,SSTEP_NOIRQ ,SSTEP_NOTIMER ); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_set_qemu_sstep (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +if (!gdb_ctx->num_params) {return ; } sstep_flags = gdb_ctx->params[0 ].val_ul; -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" ); }static void handle_query_qemu_sstep (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"0x%x" , sstep_flags); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_query_curr_tid (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;CPUState *cpu;GDBProcess *process;char thread_id[16 ];
@@ -1993,48 +2025,51 @@ static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx)* the first thread of the current process (gdb returns the * first thread). */ - process =gdb_get_cpu_process (gdb_ctx->s, gdb_ctx->s->g_cpu); - cpu =get_first_cpu_in_process (gdb_ctx->s, process); -gdb_fmt_thread_id (gdb_ctx->s, cpu, thread_id,sizeof (thread_id)); + process =gdb_get_cpu_process (s, s->g_cpu); + cpu =get_first_cpu_in_process (s, process); +gdb_fmt_thread_id (s, cpu, thread_id,sizeof (thread_id));snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"QC%s" , thread_id); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_query_threads (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;char thread_id[16 ]; -if (!gdb_ctx->s->query_cpu) { -put_packet (gdb_ctx->s,"l" ); +if (!s->query_cpu) { +put_packet (s,"l" );return ; } -gdb_fmt_thread_id (gdb_ctx->s, gdb_ctx->s->query_cpu, thread_id, +gdb_fmt_thread_id (s, s->query_cpu, thread_id,sizeof (thread_id));snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"m%s" , thread_id); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); - gdb_ctx->s->query_cpu = -gdb_next_attached_cpu (gdb_ctx->s, gdb_ctx->s->query_cpu); +put_packet (s, gdb_ctx->str_buf); + s->query_cpu = +gdb_next_attached_cpu (s, s->query_cpu); }static void handle_query_first_threads (GdbCmdContext *gdb_ctx,void *user_ctx) { - gdb_ctx->s->query_cpu =gdb_first_attached_cpu (gdb_ctx->s); +GDBState *s = gdbserver_state; + s->query_cpu =gdb_first_attached_cpu (s);handle_query_threads (gdb_ctx, user_ctx); }static void handle_query_thread_extra (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;CPUState *cpu;int len;if (!gdb_ctx->num_params || gdb_ctx->params[0 ].thread_id.kind ==GDB_READ_THREAD_ERR ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; } - cpu =gdb_get_cpu (gdb_ctx->s, gdb_ctx->params[0 ].thread_id.pid, + cpu =gdb_get_cpu (s, gdb_ctx->params[0 ].thread_id.pid, gdb_ctx->params[0 ].thread_id.tid);if (!cpu) {return ;
@@ -2042,7 +2077,7 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx)cpu_synchronize_state (cpu); -if (gdb_ctx->s->multiprocess && (gdb_ctx->s->process_num >1 )) { +if (s->multiprocess && (s->process_num >1 )) {/* Print the CPU model and name in multiprocess mode */ ObjectClass *oc =object_get_class (OBJECT (cpu));const char *cpu_model =object_class_get_name (oc);
@@ -2059,50 +2094,53 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) }trace_gdbstub_op_extra_info ((char *)gdb_ctx->mem_buf);memtohex (gdb_ctx->str_buf, gdb_ctx->mem_buf, len); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }#ifdef CONFIG_USER_ONLY static void handle_query_offsets (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;TaskState *ts; - ts = gdb_ctx->s->c_cpu->opaque; + ts = s->c_cpu->opaque;snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"Text=" TARGET_ABI_FMT_lx";Data=" TARGET_ABI_FMT_lx";Bss=" TARGET_ABI_FMT_lx, ts->info->code_offset, ts->info->data_offset, ts->info->data_offset); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }#else static void handle_query_rcmd (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;int len;if (!gdb_ctx->num_params) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; } len =strlen (gdb_ctx->params[0 ].data);if (len %2 ) { -put_packet (gdb_ctx->s,"E01" ); +put_packet (s,"E01" );return ; } len = len /2 ;hextomem (gdb_ctx->mem_buf, gdb_ctx->params[0 ].data, len); gdb_ctx->mem_buf[len++] =0 ; -qemu_chr_be_write (gdb_ctx->s->mon_chr, gdb_ctx->mem_buf, len); -put_packet (gdb_ctx->s,"OK" ); +qemu_chr_be_write (s->mon_chr, gdb_ctx->mem_buf, len); +put_packet (s,"OK" ); }#endif static void handle_query_supported (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;CPUClass *cc; snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "PacketSize=%x",
@@ -2115,15 +2153,16 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx)if (gdb_ctx->num_params &&strstr (gdb_ctx->params[0 ].data,"multiprocess+" )) { - gdb_ctx->s->multiprocess = true; + s->multiprocess = true; }pstrcat (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),";multiprocess+" ); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_query_xfer_features (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;GDBProcess *process;CPUClass *cc;unsigned long len, total_len, addr;
@@ -2131,22 +2170,22 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx)const char *p;if (gdb_ctx->num_params <3 ) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; } - process =gdb_get_cpu_process (gdb_ctx->s, gdb_ctx->s->g_cpu); - cc =CPU_GET_CLASS (gdb_ctx->s->g_cpu); + process =gdb_get_cpu_process (s, s->g_cpu); + cc =CPU_GET_CLASS (s->g_cpu);if (!cc->gdb_core_xml_file) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" );return ; } gdb_has_xml = true; p = gdb_ctx->params[0 ].data; - xml =get_feature_xml (gdb_ctx->s, p, &p, process); + xml =get_feature_xml (s, p, &p, process);if (!xml) { -put_packet (gdb_ctx->s,"E00" ); +put_packet (s,"E00" );return ; }
@@ -2154,7 +2193,7 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) len = gdb_ctx->params[2 ].val_ul; total_len =strlen (xml);if (addr > total_len) { -put_packet (gdb_ctx->s,"E00" ); +put_packet (s,"E00" );return ; }
@@ -2170,35 +2209,39 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) len =memtox (gdb_ctx->str_buf +1 , xml + addr, total_len - addr); } -put_packet_binary (gdb_ctx->s, gdb_ctx->str_buf, len +1 , true); +put_packet_binary (s, gdb_ctx->str_buf, len +1 , true); }static void handle_query_attached (GdbCmdContext *gdb_ctx,void *user_ctx) { -put_packet (gdb_ctx->s,GDB_ATTACHED ); +GDBState *s = gdbserver_state; +put_packet (s,GDB_ATTACHED ); }static void handle_query_qemu_supported (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"sstepbits;sstep" );#ifndef CONFIG_USER_ONLY pstrcat (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),";PhyMemMode" );#endif -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }#ifndef CONFIG_USER_ONLY static void handle_query_qemu_phy_mem_mode (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"%d" , phy_memory_mode); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf); }static void handle_set_qemu_phy_mem_mode (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;if (!gdb_ctx->num_params) { -put_packet (gdb_ctx->s,"E22" ); +put_packet (s,"E22" );return ; }
@@ -2207,7 +2250,7 @@ static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) } else { phy_memory_mode =1 ; } -put_packet (gdb_ctx->s,"OK" ); +put_packet (s,"OK" ); }#endif
@@ -2319,51 +2362,56 @@ static GdbCmdParseEntry gdb_gen_set_table[] = {static void handle_gen_query (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +if (!gdb_ctx->num_params) {return ; } -if (!process_string_cmd (gdb_ctx->s,NULL , gdb_ctx->params[0 ].data, +if (!process_string_cmd (s,NULL , gdb_ctx->params[0 ].data, gdb_gen_query_set_common_table,ARRAY_SIZE (gdb_gen_query_set_common_table))) {return ; } -if (process_string_cmd (gdb_ctx->s,NULL , gdb_ctx->params[0 ].data, +if (process_string_cmd (s,NULL , gdb_ctx->params[0 ].data, gdb_gen_query_table,ARRAY_SIZE (gdb_gen_query_table))) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" ); } }static void handle_gen_set (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state; +if (!gdb_ctx->num_params) {return ; } -if (!process_string_cmd (gdb_ctx->s,NULL , gdb_ctx->params[0 ].data, +if (!process_string_cmd (s,NULL , gdb_ctx->params[0 ].data, gdb_gen_query_set_common_table,ARRAY_SIZE (gdb_gen_query_set_common_table))) {return ; } -if (process_string_cmd (gdb_ctx->s,NULL , gdb_ctx->params[0 ].data, +if (process_string_cmd (s,NULL , gdb_ctx->params[0 ].data, gdb_gen_set_table,ARRAY_SIZE (gdb_gen_set_table))) { -put_packet (gdb_ctx->s,"" ); +put_packet (s,"" ); } }static void handle_target_halt (GdbCmdContext *gdb_ctx,void *user_ctx) { +GDBState *s = gdbserver_state;char thread_id[16 ]; -gdb_fmt_thread_id (gdb_ctx->s, gdb_ctx->s->c_cpu, thread_id, +gdb_fmt_thread_id (s, s->c_cpu, thread_id,sizeof (thread_id));snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"T%02xthread:%s;" ,GDB_SIGNAL_TRAP , thread_id); -put_packet (gdb_ctx->s, gdb_ctx->str_buf); +put_packet (s, gdb_ctx->str_buf);/* * Remove all the breakpoints when this query is issued, * because gdb is doing an initial connect and the state
@@ -3052,10 +3100,9 @@ gdb_handlesig(CPUState *cpu, int sig)/* Tell the remote gdb that the process has exited due to SIG. */ void gdb_signalled (CPUArchState *env,int sig) { -GDBState *s; +GDBState *s = gdbserver_state;char buf[4 ]; - s = gdbserver_state;if (gdbserver_fd <0 || s->fd <0 ) {return ; }
Signature · 1 line
2.20.1
Re: [RFC PATCH 02/11] gdbstub: stop passing GDBState * around
Quoted 30 lines · Alex Bennée
We only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier.
Signed-off-by Alex Bennée <[email protected]>--- gdbstub.c | 307 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 177 insertions(+), 130 deletions(-)gdbstub.c +1
-2@@ -1399,7 +1399,6 @@ static int cmd_parse_params(const char *data, const char *schema, } typedef struct GdbCmdContext { - GDBState *s; GdbCmdVariant *params; int num_params; uint8_t mem_buf[MAX_PACKET_LENGTH];@@ -1480,7 +1479,7 @@ static int process_string_cmd(GDBState *s, void *user_ctx, const char *data,return -1 ; } - gdb_ctx.s = s; +g_assert (s == gdbserver_state); cmd->handler (&gdb_ctx, user_ctx);return 0 ; }
gdbstub.c static void run_cmd_parser(GDBState *s, const char *data, · line 1510
Quoted 8 lines
gdbstub.c +1
-1@@ -1505,7 +1504,7 @@ static void run_cmd_parser(GDBState *s, const char *data,static void handle_detach (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBProcess *process; -GDBState *s = gdb_ctx->s; +GDBState *s = gdbserver_state;uint32_t pid =1 ;if (s->multiprocess) {
[...]
Modulo my question about why not use a non-pointer variable,
r~
Re: [RFC PATCH 02/11] gdbstub: stop passing GDBState * around
Quoted 38 lines · Richard Henderson
Quoted 37 lines · Alex Bennée
We only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier.
Signed-off-by Alex Bennée <[email protected]>--- gdbstub.c | 307 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 177 insertions(+), 130 deletions(-)gdbstub.c +2
-3@@ -1399,7 +1399,6 @@ static int cmd_parse_params(const char *data, const char *schema, } typedef struct GdbCmdContext { - GDBState *s; GdbCmdVariant *params; int num_params; uint8_t mem_buf[MAX_PACKET_LENGTH];@@ -1480,7 +1479,7 @@ static int process_string_cmd(GDBState *s, void *user_ctx, const char *data,return -1 ; } - gdb_ctx.s = s; +g_assert (s == gdbserver_state); cmd->handler (&gdb_ctx, user_ctx);return 0 ; }@@ -1505,7 +1504,7 @@ static void run_cmd_parser(GDBState *s, const char *data,static void handle_detach (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBProcess *process; -GDBState *s = gdb_ctx->s; +GDBState *s = gdbserver_state;uint32_t pid =1 ;
Quoted 6 lines
gdbstub.c static void run_cmd_parser(GDBState *s, const char *data, · line 1510
Quoted 1 line
gdbstub.c +0
-0if (s->multiprocess) {[...]
Modulo my question about why not use a non-pointer variable,
Reviewed-by Richard Henderson <[email protected]>
Sure - we might as well go for static assignment. My main worry was overly long lines but we could shorten the global to compensate or wrap a helper around.
Quoted 3 lines
r~
--
Alex Bennée
Re: [RFC PATCH 02/11] gdbstub: stop passing GDBState * around
Quoted 7 lines · Alex Bennée
Quoted 3 lines
Modulo my question about why not use a non-pointer variable,
Reviewed-by Richard Henderson <[email protected]>Sure - we might as well go for static assignment. My main worry was overly long lines but we could shorten the global to compensate or wrap a helper around.
You could use a shorter variable name, I suppose, though a good name is not immediately leaping to mind...
r~
Re: [RFC PATCH 02/11] gdbstub: stop passing GDBState * around
In reply to Alex BennéeQuoted 7 lines · Alex Bennée
We only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier.
Signed-off-by Alex Bennée <[email protected]>--- gdbstub.c | 307 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 177 insertions(+), 130 deletions(-)
Do we know why we choose to pass GDBState * everywhere ?
It sounds like a way to eventually handle multiple gdb connections but I don't know if it has some sense.
Damien
Re: [RFC PATCH 02/11] gdbstub: stop passing GDBState * around
Quoted 4 lines · Damien Hedde
Quoted 3 lines · Alex Bennée
We only have one GDBState which should be allocated at the time we process any commands. This will make further clean-up a bit easier.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Alex Bennée <[email protected]>--- gdbstub.c | 307 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 177 insertions(+), 130 deletions(-)Do we know why we choose to pass GDBState * everywhere ?
It sounds like a way to eventually handle multiple gdb connections but I don't know if it has some sense.
I'm not sure it does. The gdbserver has quite a degree of control on the running of the system state. I'm not sure how having two connections would work in that regard.
The only reference to multiple gdbservers the manual makes is having --one to allow port sharing between multiple instances (with their own inferiors).
--
Alex Bennée
RFC PATCH 3/11 gdbstub: move str_buf to GDBState and use GString
In reply to Alex BennéeRather than having a static buffer replace str_buf with a GString which we know can grow on demand. Convert the internal functions to take a GString instead of a char * and length.
--- gdbstub.c | 194 ++++++++++++++++++++++++------------------------------ 1 file changed, 85 insertions(+), 109 deletions(-)
gdbstub.c +85 -109
@@ -365,6 +365,7 @@ typedef struct GDBState {int process_num;char syscall_buf[256 ];gdb_syscall_complete_cb current_syscall_cb; +GString *str_buf; } GDBState;/* By default use no IRQs and no timers while single stepping so as to
@@ -378,6 +379,7 @@ static GDBState *gdb_allocate_state(void) {g_assert (!gdbserver_state); gdbserver_state =g_new0 (GDBState,1 ); + gdbserver_state->str_buf =g_string_new (NULL );return gdbserver_state; }
@@ -553,17 +555,15 @@ static inline int tohex(int v) }/* writes 2*len+1 bytes in buf */ -static void memtohex (char *buf,const uint8_t *mem,int len) +static void memtohex (GString *buf,const uint8_t *mem,int len) {int i, c; -char *q; - q = buf;for (i =0 ; i < len; i++) { c = mem[i]; - *q++ =tohex (c >>4 ); - *q++ =tohex (c &0xf ); +g_string_append_c (buf,tohex (c >>4 )); +g_string_append_c (buf,tohex (c &0xf )); } - *q ='\0' ; +g_string_append_c (buf,'\0' ); }static void hextomem (uint8_t *mem,const char *buf,int len)
@@ -657,24 +657,22 @@ static int put_packet(GDBState *s, const char *buf) }/* Encode data using the encoding for 'x' packets. */ -static int memtox (char *buf,const char *mem,int len) +static void memtox (GString *buf,const char *mem,int len) { -char *p = buf;char c;while (len--) { c = *(mem++);switch (c) {case '#' :case '$' :case '*' :case '}' : - *(p++) ='}' ; - *(p++) = c ^0x20 ; +g_string_append_c (buf,'}' ); +g_string_append_c (buf, c ^0x20 );break ;default : - *(p++) = c; +g_string_append_c (buf, c);break ; } } -return p - buf; }static uint32_t gdb_get_cpu_pid (const GDBState *s,CPUState *cpu)
@@ -1098,17 +1096,14 @@ static void gdb_set_cpu_pc(GDBState *s, target_ulong pc)cpu_set_pc (cpu, pc); } -static char *gdb_fmt_thread_id (const GDBState *s,CPUState *cpu, -char *buf,size_t buf_size) +static void gdb_append_thread_id (const GDBState *s,CPUState *cpu,GString *buf) {if (s->multiprocess) { -snprintf (buf, buf_size,"p%02x.%02x" , -gdb_get_cpu_pid (s, cpu),cpu_gdb_index (cpu)); +g_string_append_printf (buf,"p%02x.%02x" , +gdb_get_cpu_pid (s, cpu),cpu_gdb_index (cpu)); }else { -snprintf (buf, buf_size,"%02x" ,cpu_gdb_index (cpu)); +g_string_append_printf (buf,"%02x" ,cpu_gdb_index (cpu)); } - -return buf; } typedef enum GDBThreadIdKind {
@@ -1402,7 +1397,6 @@ typedef struct GdbCmdContext {GdbCmdVariant *params;int num_params;uint8_t mem_buf[MAX_PACKET_LENGTH ]; -char str_buf[MAX_PACKET_LENGTH +1 ]; } GdbCmdContext;typedef void (*GdbCmdHandler )(GdbCmdContext *gdb_ctx,void *user_ctx);
@@ -1494,6 +1488,8 @@ static void run_cmd_parser(GDBState *s, const char *data,return ; } +g_string_set_size (s->str_buf,0 ); +/* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */ if (process_string_cmd (s,NULL , data, cmd,1 )) {
@@ -1742,8 +1738,8 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx)return ; } -memtohex (gdb_ctx->str_buf, gdb_ctx->mem_buf, reg_size); -put_packet (s, gdb_ctx->str_buf); +memtohex (s->str_buf, gdb_ctx->mem_buf, reg_size); +put_packet (s, s->str_buf->str); }static void handle_write_mem (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -1795,8 +1791,8 @@ static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx)return ; } -memtohex (gdb_ctx->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1 ].val_ull); -put_packet (s, gdb_ctx->str_buf); +memtohex (s->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1 ].val_ull); +put_packet (s, s->str_buf->str); }static void handle_write_all_regs (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -1835,8 +1831,8 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) addr); } -memtohex (gdb_ctx->str_buf, gdb_ctx->mem_buf, len); -put_packet (s, gdb_ctx->str_buf); +memtohex (s->str_buf, gdb_ctx->mem_buf, len); +put_packet (s, s->str_buf->str); }static void handle_file_io (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -1904,9 +1900,8 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx)GDBState *s = gdbserver_state;GDBProcess *process;CPUState *cpu; -char thread_id[16 ]; -pstrcpy (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"E22" ); +g_string_assign (s->str_buf,"E22" );if (!gdb_ctx->num_params) { goto cleanup; }
@@ -1925,11 +1920,11 @@ static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx) s->g_cpu = cpu; s->c_cpu = cpu; -gdb_fmt_thread_id (s, cpu, thread_id,sizeof (thread_id)); -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"T%02xthread:%s;" , -GDB_SIGNAL_TRAP , thread_id); +g_string_printf (s->str_buf,"T%02xthread:" ,GDB_SIGNAL_TRAP ); +gdb_append_thread_id (s, cpu, s->str_buf); +g_string_append_c (s->str_buf,';' ); cleanup: -put_packet (s, gdb_ctx->str_buf); +put_packet (s, s->str_buf->str); }static void handle_v_kill (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -1986,11 +1981,9 @@ static void handle_v_commands(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_query_qemu_sstepbits (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBState *s = gdbserver_state; - -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf), -"ENABLE=%x,NOIRQ=%x,NOTIMER=%x" ,SSTEP_ENABLE , -SSTEP_NOIRQ ,SSTEP_NOTIMER ); -put_packet (s, gdb_ctx->str_buf); +g_string_printf (s->str_buf,"ENABLE=%x,NOIRQ=%x,NOTIMER=%x" , +SSTEP_ENABLE ,SSTEP_NOIRQ ,SSTEP_NOTIMER ); +put_packet (s, s->str_buf->str); }static void handle_set_qemu_sstep (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -2008,9 +2001,8 @@ static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_query_qemu_sstep (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBState *s = gdbserver_state; - -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"0x%x" , sstep_flags); -put_packet (s, gdb_ctx->str_buf); +g_string_printf (s->str_buf,"0x%x" , sstep_flags); +put_packet (s, s->str_buf->str); }static void handle_query_curr_tid (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -2018,7 +2010,6 @@ static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx)GDBState *s = gdbserver_state;CPUState *cpu;GDBProcess *process; -char thread_id[16 ];/* * "Current thread" remains vague in the spec, so always return
@@ -2027,27 +2018,24 @@ static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx)*/ process =gdb_get_cpu_process (s, s->g_cpu); cpu =get_first_cpu_in_process (s, process); -gdb_fmt_thread_id (s, cpu, thread_id,sizeof (thread_id)); -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"QC%s" , thread_id); -put_packet (s, gdb_ctx->str_buf); +g_string_assign (s->str_buf,"QC" ); +gdb_append_thread_id (s, cpu, s->str_buf); +put_packet (s, s->str_buf->str); }static void handle_query_threads (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBState *s = gdbserver_state; -char thread_id[16 ];if (!s->query_cpu) {put_packet (s,"l" );return ; } -gdb_fmt_thread_id (s, s->query_cpu, thread_id, -sizeof (thread_id)); -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"m%s" , thread_id); -put_packet (s, gdb_ctx->str_buf); - s->query_cpu = -gdb_next_attached_cpu (s, s->query_cpu); +g_string_assign (s->str_buf,"m" ); +gdb_append_thread_id (s, s->query_cpu, s->str_buf); +put_packet (s, s->str_buf->str); + s->query_cpu =gdb_next_attached_cpu (s, s->query_cpu); }static void handle_query_first_threads (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -2060,8 +2048,8 @@ static void handle_query_first_threads(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_query_thread_extra (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBState *s = gdbserver_state; +g_autoptr (GString) rs =g_string_new (NULL );CPUState *cpu; -int len;if (!gdb_ctx->num_params || gdb_ctx->params[0 ].thread_id.kind ==GDB_READ_THREAD_ERR ) {
@@ -2081,20 +2069,17 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx)/* Print the CPU model and name in multiprocess mode */ ObjectClass *oc =object_get_class (OBJECT (cpu));const char *cpu_model =object_class_get_name (oc); -char *cpu_name =object_get_canonical_path_component (OBJECT (cpu)); - len =snprintf ((char *)gdb_ctx->mem_buf,sizeof (gdb_ctx->str_buf) /2 , -"%s %s [%s]" , cpu_model, cpu_name, - cpu->halted ?"halted " :"running" ); -g_free (cpu_name); + g_autofree char *cpu_name; + cpu_name =object_get_canonical_path_component (OBJECT (cpu)); +g_string_printf (rs,"%s %s [%s]" , cpu_model, cpu_name, + cpu->halted ?"halted " :"running" ); }else { -/* memtohex() doubles the required space */ - len =snprintf ((char *)gdb_ctx->mem_buf,sizeof (gdb_ctx->str_buf) /2 , -"CPU#%d [%s]" , cpu->cpu_index, +g_string_printf (rs,"CPU#%d [%s]" , cpu->cpu_index, cpu->halted ?"halted " :"running" ); } -trace_gdbstub_op_extra_info ((char *)gdb_ctx->mem_buf); -memtohex (gdb_ctx->str_buf, gdb_ctx->mem_buf, len); -put_packet (s, gdb_ctx->str_buf); +trace_gdbstub_op_extra_info (rs->str); +memtohex (s->str_buf, (uint8_t *)rs->str, rs->len); +put_packet (s, s->str_buf->str); }#ifdef CONFIG_USER_ONLY
@@ -2104,13 +2089,14 @@ static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx)TaskState *ts; ts = s->c_cpu->opaque; -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf), -"Text=" TARGET_ABI_FMT_lx";Data=" TARGET_ABI_FMT_lx -";Bss=" TARGET_ABI_FMT_lx, - ts->info->code_offset, - ts->info->data_offset, - ts->info->data_offset); - put_packet(s, gdb_ctx->str_buf); +g_string_printf (s->str_buf, +"Text=" TARGET_ABI_FMT_lx +";Data=" TARGET_ABI_FMT_lx +";Bss=" TARGET_ABI_FMT_lx, + ts->info->code_offset, + ts->info->data_offset, + ts->info->data_offset); + put_packet(s, s->str_buf->str); }#else static void handle_query_rcmd (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -2143,12 +2129,10 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx)GDBState *s = gdbserver_state;CPUClass *cc; -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"PacketSize=%x" , -MAX_PACKET_LENGTH ); +g_string_printf (s->str_buf,"PacketSize=%x" ,MAX_PACKET_LENGTH ); cc =CPU_GET_CLASS (first_cpu);if (cc->gdb_core_xml_file) { -pstrcat (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf), -";qXfer:features:read+" ); +g_string_append (s->str_buf,";qXfer:features:read+" ); } if (gdb_ctx->num_params &&
@@ -2156,8 +2140,8 @@ static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) s->multiprocess = true; } -pstrcat (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),";multiprocess+" ); -put_packet (s, gdb_ctx->str_buf); +g_string_append (s->str_buf,";multiprocess+" ); +put_packet (s, s->str_buf->str); }static void handle_query_xfer_features (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -2202,14 +2186,14 @@ static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_ctx) }if (len < total_len - addr) { - gdb_ctx->str_buf[0 ] ='m' ; - len =memtox (gdb_ctx->str_buf +1 , xml + addr, len); +g_string_assign (s->str_buf,"m" ); +memtox (s->str_buf, xml + addr, len); }else { - gdb_ctx->str_buf[0 ] ='l' ; - len =memtox (gdb_ctx->str_buf +1 , xml + addr, total_len - addr); +g_string_assign (s->str_buf,"l" ); +memtox (s->str_buf, xml + addr, total_len - addr); } -put_packet_binary (s, gdb_ctx->str_buf, len +1 , true); +put_packet_binary (s, s->str_buf->str, s->str_buf->len, true); }static void handle_query_attached (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -2221,11 +2205,11 @@ static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_query_qemu_supported (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBState *s = gdbserver_state; -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"sstepbits;sstep" ); +g_string_printf (s->str_buf,"sstepbits;sstep" );#ifndef CONFIG_USER_ONLY -pstrcat (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),";PhyMemMode" ); +g_string_append (s->str_buf,";PhyMemMode" );#endif -put_packet (s, gdb_ctx->str_buf); +put_packet (s, s->str_buf->str); }#ifndef CONFIG_USER_ONLY
@@ -2233,8 +2217,8 @@ static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *user_ctx) {GDBState *s = gdbserver_state; -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"%d" , phy_memory_mode); -put_packet (s, gdb_ctx->str_buf); +g_string_printf (s->str_buf,"%d" , phy_memory_mode); +put_packet (s, s->str_buf->str); }static void handle_set_qemu_phy_mem_mode (GdbCmdContext *gdb_ctx,void *user_ctx)
@@ -2405,13 +2389,10 @@ static void handle_gen_set(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_target_halt (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBState *s = gdbserver_state; -char thread_id[16 ]; - -gdb_fmt_thread_id (s, s->c_cpu, thread_id, -sizeof (thread_id)); -snprintf (gdb_ctx->str_buf,sizeof (gdb_ctx->str_buf),"T%02xthread:%s;" , -GDB_SIGNAL_TRAP , thread_id); -put_packet (s, gdb_ctx->str_buf); +g_string_printf (s->str_buf,"T%02xthread:" ,GDB_SIGNAL_TRAP ); +gdb_append_thread_id (s, s->c_cpu, s->str_buf); +g_string_append_c (s->str_buf,';' ); +put_packet (s, s->str_buf->str);/* * Remove all the breakpoints when this query is issued, * because gdb is doing an initial connect and the state
@@ -2675,8 +2656,8 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) {GDBState *s = gdbserver_state;CPUState *cpu = s->c_cpu; -char buf[256 ]; -char thread_id[16 ]; +g_autoptr (GString) buf =g_string_new (NULL ); +g_autoptr (GString) tid =g_string_new (NULL );const char *type;int ret;
@@ -2694,7 +2675,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)return ; } -gdb_fmt_thread_id (s, cpu, thread_id,sizeof (thread_id)); +gdb_append_thread_id (s, cpu, tid);switch (state) {case RUN_STATE_DEBUG :
@@ -2712,10 +2693,9 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) }trace_gdbstub_hit_watchpoint (type,cpu_gdb_index (cpu), (target_ulong )cpu->watchpoint_hit->vaddr); -snprintf (buf,sizeof (buf), -"T%02xthread:%s;%swatch:" TARGET_FMT_lx";" , -GDB_SIGNAL_TRAP , thread_id, type, - (target_ulong )cpu->watchpoint_hit->vaddr); +g_string_printf (buf,"T%02xthread:%s;%swatch:" TARGET_FMT_lx";" , +GDB_SIGNAL_TRAP , tid->str, type, + (target_ulong )cpu->watchpoint_hit->vaddr); cpu->watchpoint_hit =NULL ; goto send_packet; }else {
@@ -2756,10 +2736,10 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)break ; }gdb_set_stop_cpu (cpu); -snprintf (buf,sizeof (buf),"T%02xthread:%s;" , ret, thread_id); +g_string_printf (buf,"T%02xthread:%s;" , ret, tid->str); send_packet: -put_packet (s, buf); +put_packet (s, buf->str);/* disable single step if it was enabled */ cpu_single_step (cpu,0 );
@@ -3248,13 +3228,9 @@ static void gdb_chr_event(void *opaque, int event)static void gdb_monitor_output (GDBState *s,const char *msg,int len) { -char buf[MAX_PACKET_LENGTH ]; - - buf[0 ] ='O' ; -if (len > (MAX_PACKET_LENGTH /2 ) -1 ) - len = (MAX_PACKET_LENGTH /2 ) -1 ; -memtohex (buf +1 , (uint8_t *)msg, len); -put_packet (s, buf); +g_autoptr (GString) buf =g_string_new ("O" ); +memtohex (buf, (uint8_t *)msg, len); +put_packet (s, buf->str); }static int gdb_monitor_write (Chardev *chr,const uint8_t *buf,int len)
Signature · 1 line
2.20.1
Re: [RFC PATCH 03/11] gdbstub: move str_buf to GDBState and use GString
Quoted 8 lines · Alex Bennée
Rather than having a static buffer replace
str_bufwith a GString which we know can grow on demand. Convert the internal functions to take a GString instead of a char * and length.Signed-off-by Alex Bennée <[email protected]>--- gdbstub.c | 194 ++++++++++++++++++++++++------------------------------ 1 file changed, 85 insertions(+), 109 deletions(-)
r~
RFC PATCH 4/11 gdbstub: move mem_buf to GDBState and use GByteArray
In reply to Alex BennéeThis is in preparation for further re-factoring of the register API with the rest of the code. Theoretically the read register function could overwrite the MAX_PACKET_LENGTH buffer although currently all registers are well within the size range.
--- gdbstub.c | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-)
gdbstub.c +31 -21
@@ -366,6 +366,7 @@ typedef struct GDBState {char syscall_buf[256 ];gdb_syscall_complete_cb current_syscall_cb;GString *str_buf; +GByteArray *mem_buf; } GDBState;/* By default use no IRQs and no timers while single stepping so as to
@@ -380,6 +381,7 @@ static GDBState *gdb_allocate_state(void)g_assert (!gdbserver_state); gdbserver_state =g_new0 (GDBState,1 ); gdbserver_state->str_buf =g_string_new (NULL ); + gdbserver_state->mem_buf =g_byte_array_sized_new (MAX_PACKET_LENGTH );return gdbserver_state; }
@@ -566,12 +568,13 @@ static void memtohex(GString *buf, const uint8_t *mem, int len)g_string_append_c (buf,'\0' ); } -static void hextomem (uint8_t *mem,const char *buf,int len) +static void hextomem (GByteArray *mem,const char *buf,int len) {int i;for (i =0 ; i < len; i++) { - mem[i] = (fromhex (buf[0 ]) <<4 ) |fromhex (buf[1 ]); +guint8 byte =fromhex (buf[0 ]) <<4 |fromhex (buf[1 ]); +g_byte_array_append (mem, &byte,1 ); buf +=2 ; } }
@@ -1396,7 +1399,6 @@ static int cmd_parse_params(const char *data, const char *schema,typedef struct GdbCmdContext {GdbCmdVariant *params;int num_params; -uint8_t mem_buf[MAX_PACKET_LENGTH ]; }GdbCmdContext ;typedef void (*GdbCmdHandler )(GdbCmdContext *gdb_ctx,void *user_ctx);
@@ -1489,6 +1491,7 @@ static void run_cmd_parser(GDBState *s, const char *data, }g_string_set_size (s->str_buf,0 ); +g_byte_array_set_size (s->mem_buf,0 );/* In case there was an error during the command parsing we must * send a NULL packet to indicate the command is not supported */
@@ -1710,8 +1713,8 @@ static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx) } reg_size =strlen (gdb_ctx->params[1 ].data) /2 ; -hextomem (gdb_ctx->mem_buf, gdb_ctx->params[1 ].data, reg_size); -gdb_write_register (s->g_cpu, gdb_ctx->mem_buf, +hextomem (s->mem_buf, gdb_ctx->params[1 ].data, reg_size); +gdb_write_register (s->g_cpu, s->mem_buf->data, gdb_ctx->params[0 ].val_ull);put_packet (s,"OK" ); }
@@ -1731,14 +1734,16 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx)return ; } - reg_size =gdb_read_register (s->g_cpu, gdb_ctx->mem_buf, + reg_size =gdb_read_register (s->g_cpu, s->mem_buf->data, gdb_ctx->params[0 ].val_ull);if (!reg_size) {put_packet (s,"E14" );return ; + }else { +g_byte_array_set_size (s->mem_buf, reg_size); } -memtohex (s->str_buf, gdb_ctx->mem_buf, reg_size); +memtohex (s->str_buf, s->mem_buf->data, reg_size);put_packet (s, s->str_buf->str); }
@@ -1757,11 +1762,11 @@ static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx)return ; } -hextomem (gdb_ctx->mem_buf, gdb_ctx->params[2 ].data, +hextomem (s->mem_buf, gdb_ctx->params[2 ].data, gdb_ctx->params[1 ].val_ull);if (target_memory_rw_debug (s->g_cpu, gdb_ctx->params[0 ].val_ull, - gdb_ctx->mem_buf, - gdb_ctx->params[1 ].val_ull, true)) { + s->mem_buf->data, + s->mem_buf->len, true)) {put_packet (s,"E14" );return ; }
@@ -1784,14 +1789,16 @@ static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx)return ; } +g_byte_array_set_size (s->mem_buf, gdb_ctx->params[1 ].val_ull); +if (target_memory_rw_debug (s->g_cpu, gdb_ctx->params[0 ].val_ull, - gdb_ctx->mem_buf, - gdb_ctx->params[1 ].val_ull, false)) { + s->mem_buf->data, + s->mem_buf->len, false)) {put_packet (s,"E14" );return ; } -memtohex (s->str_buf, gdb_ctx->mem_buf, gdb_ctx->params[1 ].val_ull); +memtohex (s->str_buf, s->mem_buf->data, s->mem_buf->len);put_packet (s, s->str_buf->str); }
@@ -1807,9 +1814,9 @@ static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) }cpu_synchronize_state (s->g_cpu); - registers = gdb_ctx->mem_buf; len =strlen (gdb_ctx->params[0 ].data) /2 ; -hextomem (registers, gdb_ctx->params[0 ].data, len); +hextomem (s->mem_buf, gdb_ctx->params[0 ].data, len); + registers = s->mem_buf->data;for (addr =0 ; addr < s->g_cpu->gdb_num_g_regs && len >0 ; addr++) { reg_size =gdb_write_register (s->g_cpu, registers, addr);
@@ -1827,11 +1834,13 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx)cpu_synchronize_state (s->g_cpu); len =0 ;for (addr =0 ; addr < s->g_cpu->gdb_num_g_regs; addr++) { - len +=gdb_read_register (s->g_cpu, gdb_ctx->mem_buf + len, + len +=gdb_read_register (s->g_cpu, s->mem_buf->data + len, addr); } +/* FIXME: This is after the fact sizing */ +g_byte_array_set_size (s->mem_buf, len); -memtohex (s->str_buf, gdb_ctx->mem_buf, len); +memtohex (s->str_buf, s->mem_buf->data, len);put_packet (s, s->str_buf->str); }
@@ -2102,6 +2111,7 @@ static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx)static void handle_query_rcmd (GdbCmdContext *gdb_ctx,void *user_ctx) {GDBState *s = gdbserver_state; +const guint8 zero =0 ;int len;if (!gdb_ctx->num_params) {
@@ -2116,11 +2126,11 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) } len = len /2 ; -hextomem (gdb_ctx->mem_buf, gdb_ctx->params[0 ].data, len); - gdb_ctx->mem_buf[len++] =0 ; -qemu_chr_be_write (s->mon_chr, gdb_ctx->mem_buf, len); +g_byte_array_set_size (s->mem_buf, len); +hextomem (s->mem_buf, gdb_ctx->params[0 ].data, len); +g_byte_array_append (s->mem_buf, &zero,1 ); +qemu_chr_be_write (s->mon_chr, s->mem_buf->data, s->mem_buf->len);put_packet (s,"OK" ); - }#endif
Signature · 1 line
2.20.1
Re: [RFC PATCH 04/11] gdbstub: move mem_buf to GDBState and use GByteArray
Quoted 9 lines · Alex Bennée
This is in preparation for further re-factoring of the register API with the rest of the code. Theoretically the read register function could overwrite the
MAX_PACKET_LENGTHbuffer although currently all registers are well within the size range.Signed-off-by Alex Bennée <[email protected]>--- gdbstub.c | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-)
r~
RFC PATCH 5/11 gdbstub: add helper for 128 bit registers
In reply to Alex Bennée--- include/exec/gdbstub.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/exec/gdbstub.h +8 -0
@@ -102,6 +102,14 @@ static inline int gdb_get_reg64(uint8_t *mem_buf, uint64_t val)return 8 ; } +static inline int gdb_get_reg128 (uint8_t *mem_buf,uint64_t val_hi, +uint64_t val_lo) +{ +stq_p (mem_buf, val_hi); +stq_p (mem_buf +8 , val_lo); +return 16 ; +} +#if TARGET_LONG_BITS ==64 #define gdb_get_regl (buf, val) gdb_get_reg64(buf, val)#define ldtul_p (addr) ldq_p(addr)
Signature · 1 line
2.20.1
Re: [RFC PATCH 05/11] gdbstub: add helper for 128 bit registers
include/exec/gdbstub.h static inline int gdb_get_reg64(uint8_t *mem_buf, uint64_t val) · line 110
Quoted 6 lines · Alex Bennée
include/exec/gdbstub.h +6
-0+static inline int gdb_get_reg128 (uint8_t *mem_buf,uint64_t val_hi, +uint64_t val_lo) +{ +stq_p (mem_buf, val_hi); +stq_p (mem_buf +8 , val_lo); +return 16 ;
Since stq_p itself depends on TARGET_WORDS_BIGENDIAN, I think the word ordering here should as well.
r~
RFC PATCH 6/11 target/arm: use gdb_get_reg helpers
In reply to Alex BennéeThis is cleaner than poking memory directly and will make later clean-ups easier.
--- target/arm/helper.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
target/arm/helper.c +6 -10
@@ -105,21 +105,17 @@ static int aarch64_fpu_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) {switch (reg) { case 0 ... 31: + {/* 128 bit FP register */ - { -uint64_t *q =aa64_vfp_qreg (env, reg); -stq_le_p (buf, q[0 ]); -stq_le_p (buf +8 , q[1 ]); -return 16 ; - } +uint64_t *q =aa64_vfp_qreg (env, reg); +return gdb_get_reg128 (buf, q[0 ], q[1 ]); + }case 32 :/* FPSR */ -stl_p (buf,vfp_get_fpsr (env)); -return 4 ; +return gdb_get_reg32 (buf,vfp_get_fpsr (env));case 33 :/* FPCR */ -stl_p (buf,vfp_get_fpcr (env)); -return 4 ; +return gdb_get_reg32 (buf,vfp_get_fpcr (env));default :return 0 ; }
Signature · 1 line
2.20.1
Re: [RFC PATCH 06/11] target/arm: use gdb_get_reg helpers
Quoted 16 lines · Alex Bennée
This is cleaner than poking memory directly and will make later clean-ups easier.
Signed-off-by Alex Bennée <[email protected]>--- target/arm/helper.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)target/arm/helper.c +0
-0@@ -105,21 +105,17 @@ static int aarch64_fpu_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) {switch (reg) { case 0 ... 31:
target/arm/helper.c static int aarch64_fpu_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) · line 111
Quoted 10 lines
target/arm/helper.c +3
-6+ {/* 128 bit FP register */ - { -uint64_t *q =aa64_vfp_qreg (env, reg); -stq_le_p (buf, q[0 ]); -stq_le_p (buf +8 , q[1 ]); -return 16 ; - } +uint64_t *q =aa64_vfp_qreg (env, reg); +return gdb_get_reg128 (buf, q[0 ], q[1 ]);
The elements of aa64_vfp_qreg are explicitly little-endian. Since you defined gdb_get_reg128 as (buf, hi, lo), these arguments are in the wrong order.
r~
RFC PATCH 7/11 target/m68k: use gdb_get_reg helpers
In reply to Alex BennéeThis is cleaner than poking memory directly and will make later clean-ups easier.
--- target/m68k/helper.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
target/m68k/helper.c +11 -18
@@ -72,19 +72,15 @@ static int cf_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) {if (n <8 ) {float_status s; -stfq_p (mem_buf,floatx80_to_float64 (env->fregs[n].d, &s)); -return 8 ; +return gdb_get_reg64 (buf,floatx80_to_float64 (env->fregs[n].d, &s)); }switch (n) {case 8 :/* fpcontrol */ -stl_be_p (mem_buf, env->fpcr); -return 4 ; +return gdb_get_reg32 (buf, env->fpcr);case 9 :/* fpstatus */ -stl_be_p (mem_buf, env->fpsr); -return 4 ; +return gdb_get_reg32 (buf, env->fpsr);case 10 :/* fpiar, not implemented */ -memset (mem_buf,0 ,4 ); -return 4 ; +return gdb_get_reg32 (buf,0 ); }return 0 ; }
@@ -112,21 +108,18 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)static int m68k_fpu_gdb_get_reg (CPUM68KState *env,uint8_t *mem_buf,int n) {if (n <8 ) { -stw_be_p (mem_buf, env->fregs[n].l.upper); -memset (mem_buf +2 ,0 ,2 ); -stq_be_p (mem_buf +4 , env->fregs[n].l.lower); -return 12 ; +int len =gdb_get_reg16 (buf, env->fregs[n].l.upper); + len +=gdb_get_reg16 (buf,0 ); + len +=gdb_get_reg64 (buf, env->fregs[n].l.lower); +return len; }switch (n) {case 8 :/* fpcontrol */ -stl_be_p (mem_buf, env->fpcr); -return 4 ; +return gdb_get_reg32 (buf, env->fpcr);case 9 :/* fpstatus */ -stl_be_p (mem_buf, env->fpsr); -return 4 ; +return gdb_get_reg32 (buf, env->fpsr);case 10 :/* fpiar, not implemented */ -memset (mem_buf,0 ,4 ); -return 4 ; +return gdb_get_reg32 (buf,0 ); }return 0 ; }
Signature · 1 line
2.20.1
Re: [RFC PATCH 07/11] target/m68k: use gdb_get_reg helpers
Quoted 7 lines · Alex Bennée
This is cleaner than poking memory directly and will make later clean-ups easier.
Signed-off-by Alex Bennée <[email protected]>--- target/m68k/helper.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-)
r~
RFC PATCH 8/11 gdbstub: extend GByteArray to read register helpers
In reply to Alex BennéeInstead of passing a pointer to memory now just extend the GByteArray to all the read register helpers. They can then safely append their data through the normal way. We don't bother with this abstraction for write registers as we have already ensured the buffer being copied from is the correct size.
--- include/exec/gdbstub.h | 39 ++++++++++++--------- include/hw/core/cpu.h | 2 +- target/alpha/cpu.h | 2 +- target/arm/cpu.h | 4 +-- target/cris/cpu.h | 4 +-- target/hppa/cpu.h | 2 +- target/i386/cpu.h | 2 +- target/lm32/cpu.h | 2 +- target/m68k/cpu.h | 2 +- target/microblaze/cpu.h | 2 +- target/mips/internal.h | 2 +- target/openrisc/cpu.h | 2 +- target/ppc/cpu.h | 4 +-- target/riscv/cpu.h | 2 +- target/s390x/internal.h | 2 +- target/sh4/cpu.h | 2 +- target/sparc/cpu.h | 2 +- target/xtensa/cpu.h | 2 +- gdbstub.c | 21 ++++++----- hw/core/cpu.c | 2 +- target/alpha/gdbstub.c | 2 +- target/arm/gdbstub.c | 2 +- target/arm/gdbstub64.c | 2 +- target/arm/helper.c | 19 +++++----- target/cris/gdbstub.c | 4 +-- target/hppa/gdbstub.c | 2 +- target/i386/gdbstub.c | 2 +- target/lm32/gdbstub.c | 2 +- target/m68k/gdbstub.c | 2 +- target/m68k/helper.c | 4 +-- target/microblaze/gdbstub.c | 2 +- target/mips/gdbstub.c | 2 +- target/nios2/cpu.c | 2 +- target/openrisc/gdbstub.c | 2 +- target/ppc/gdbstub.c | 48 +++++++++++++------------ target/ppc/translate_init.inc.c | 54 ++++++++++++++++------------- target/riscv/gdbstub.c | 18 +++++----- target/s390x/gdbstub.c | 30 ++++++++-------- target/sh4/gdbstub.c | 2 +- target/sparc/gdbstub.c | 2 +- target/xtensa/gdbstub.c | 2 +- tests/tcg/multiarch/float_helpers.c | 7 +--- 42 files changed, 161 insertions(+), 153 deletions(-)
include/exec/gdbstub.h +23 -16
@@ -68,45 +68,52 @@ void gdb_signalled(CPUArchState *, int);void gdbserver_fork (CPUState *);#endif /* Get or set a register. Returns the size of the register. */ -typedef int (*gdb_reg_cb )(CPUArchState *env,uint8_t *buf,int reg); +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);void gdb_register_coprocessor (CPUState *cpu, -gdb_reg_cb get_reg,gdb_reg_cb set_reg, +gdb_get_reg_cb get_reg,gdb_set_reg_cb set_reg,int num_regs,const char *xml,int g_pos); -/* The GDB remote protocol transfers values in target byte order. This means -* we can use the raw memory access routines to access the value buffer. -* Conveniently, these also handle the case where the buffer is mis-aligned. +/* +* 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 (uint8_t *mem_buf,uint8_t val) +static inline int gdb_get_reg8 (GByteArray *buf,uint8_t val) { -stb_p (mem_buf, val); +g_byte_array_append (buf, &val,1 );return 1 ; } -static inline int gdb_get_reg16 (uint8_t *mem_buf,uint16_t val) +static inline int gdb_get_reg16 (GByteArray *buf,uint16_t val) { -stw_p (mem_buf, 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 (uint8_t *mem_buf,uint32_t val) +static inline int gdb_get_reg32 (GByteArray *buf,uint32_t val) { -stl_p (mem_buf, 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 (uint8_t *mem_buf,uint64_t val) +static inline int gdb_get_reg64 (GByteArray *buf,uint64_t val) { -stq_p (mem_buf, 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 (uint8_t *mem_buf,uint64_t val_hi, +static inline int gdb_get_reg128 (GByteArray *buf,uint64_t val_hi,uint64_t val_lo) { -stq_p (mem_buf, val_hi); -stq_p (mem_buf +8 , val_lo); +uint64_t 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 );return 16 ; }
include/hw/core/cpu.h +1 -1
@@ -195,7 +195,7 @@ typedef struct CPUClass {hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu,vaddr addr,MemTxAttrs *attrs);int (*asidx_from_attrs)(CPUState *cpu,MemTxAttrs attrs); -int (*gdb_read_register)(CPUState *cpu,uint8_t *buf,int reg); +int (*gdb_read_register)(CPUState *cpu,GByteArray *buf,int reg);int (*gdb_write_register)(CPUState *cpu,uint8_t *buf,int reg);bool (*debug_check_watchpoint)(CPUState *cpu,CPUWatchpoint *wp);void (*debug_excp_handler)(CPUState *cpu);
target/alpha/cpu.h +1 -1
@@ -282,7 +282,7 @@ void alpha_cpu_do_interrupt(CPUState *cpu);bool alpha_cpu_exec_interrupt (CPUState *cpu,int int_req);void alpha_cpu_dump_state (CPUState *cs,FILE *f,int flags);hwaddr alpha_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int alpha_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int alpha_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int alpha_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); void alpha_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type,
target/arm/cpu.h +2 -2
@@ -952,7 +952,7 @@ bool arm_cpu_exec_interrupt(CPUState *cpu, int int_req);hwaddr arm_cpu_get_phys_page_attrs_debug (CPUState *cpu,vaddr addr,MemTxAttrs *attrs); -int arm_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int arm_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int arm_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);/* Dynamically generates for gdb stub an XML description of the sysregs from
@@ -972,7 +972,7 @@ int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque);#ifdef TARGET_AARCH64 -int aarch64_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int aarch64_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int aarch64_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);void aarch64_sve_narrow_vq (CPUARMState *env,unsigned vq); void aarch64_sve_change_el(CPUARMState *env, int old_el,
target/cris/cpu.h +2 -2
@@ -194,8 +194,8 @@ void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags);hwaddr cris_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int crisv10_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); -int cris_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int crisv10_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg); +int cris_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int cris_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);/* you can call this signal handler from your SIGBUS and SIGSEGV
target/hppa/cpu.h +1 -1
@@ -321,7 +321,7 @@ void cpu_hppa_change_prot_id(CPUHPPAState *env);int cpu_hppa_signal_handler (int host_signum,void *pinfo,void *puc);hwaddr hppa_cpu_get_phys_page_debug (CPUState *cs,vaddr addr); -int hppa_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int hppa_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int hppa_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);void hppa_cpu_do_interrupt (CPUState *cpu);bool hppa_cpu_exec_interrupt (CPUState *cpu,int int_req);
target/i386/cpu.h +1 -1
@@ -1752,7 +1752,7 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags);hwaddr x86_cpu_get_phys_page_attrs_debug (CPUState *cpu,vaddr addr,MemTxAttrs *attrs); -int x86_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int x86_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int x86_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);void x86_cpu_exec_enter (CPUState *cpu);
target/lm32/cpu.h +1 -1
@@ -202,7 +202,7 @@ void lm32_cpu_do_interrupt(CPUState *cpu);bool lm32_cpu_exec_interrupt (CPUState *cs,int int_req);void lm32_cpu_dump_state (CPUState *cpu,FILE *f,int flags);hwaddr lm32_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int lm32_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int lm32_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int lm32_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); typedef enum {
target/m68k/cpu.h +1 -1
@@ -168,7 +168,7 @@ void m68k_cpu_do_interrupt(CPUState *cpu);bool m68k_cpu_exec_interrupt (CPUState *cpu,int int_req);void m68k_cpu_dump_state (CPUState *cpu,FILE *f,int flags);hwaddr m68k_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int m68k_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int m68k_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int m68k_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);void m68k_tcg_init (void );
target/microblaze/cpu.h +1 -1
@@ -313,7 +313,7 @@ void mb_cpu_do_interrupt(CPUState *cs);bool mb_cpu_exec_interrupt (CPUState *cs,int int_req);void mb_cpu_dump_state (CPUState *cpu,FILE *f,int flags);hwaddr mb_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int mb_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int mb_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int mb_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);void mb_tcg_init (void );
target/mips/internal.h +1 -1
@@ -82,7 +82,7 @@ void mips_cpu_do_interrupt(CPUState *cpu);bool mips_cpu_exec_interrupt (CPUState *cpu,int int_req);void mips_cpu_dump_state (CPUState *cpu,FILE *f,int flags);hwaddr mips_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int mips_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int mips_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int mips_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); void mips_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type,
target/openrisc/cpu.h +1 -1
@@ -320,7 +320,7 @@ void openrisc_cpu_do_interrupt(CPUState *cpu);bool openrisc_cpu_exec_interrupt (CPUState *cpu,int int_req);void openrisc_cpu_dump_state (CPUState *cpu,FILE *f,int flags);hwaddr openrisc_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int openrisc_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int openrisc_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int openrisc_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);void openrisc_translate_init (void ); bool openrisc_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
target/ppc/cpu.h +2 -2
@@ -1258,8 +1258,8 @@ bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req);void ppc_cpu_dump_state (CPUState *cpu,FILE *f,int flags);void ppc_cpu_dump_statistics (CPUState *cpu,int flags);hwaddr ppc_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int ppc_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); -int ppc_cpu_gdb_read_register_apple (CPUState *cpu,uint8_t *buf,int reg); +int ppc_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg); +int ppc_cpu_gdb_read_register_apple (CPUState *cpu,GByteArray *buf,int reg);int ppc_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);int ppc_cpu_gdb_write_register_apple (CPUState *cpu,uint8_t *buf,int reg);#ifndef CONFIG_USER_ONLY
target/riscv/cpu.h +1 -1
@@ -243,7 +243,7 @@ extern const char * const riscv_excp_names[];extern const char *const riscv_intr_names[];void riscv_cpu_do_interrupt (CPUState *cpu); -int riscv_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int riscv_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int riscv_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);bool riscv_cpu_exec_interrupt (CPUState *cs,int interrupt_request);bool riscv_cpu_fp_enabled (CPURISCVState *env);
target/s390x/internal.h +1 -1
@@ -292,7 +292,7 @@ uint16_t float128_dcmask(CPUS390XState *env, float128 f1);/* gdbstub.c */ -int s390_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int s390_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int s390_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);void s390_cpu_gdb_init (CPUState *cs);
target/sh4/cpu.h +1 -1
@@ -208,7 +208,7 @@ void superh_cpu_do_interrupt(CPUState *cpu);bool superh_cpu_exec_interrupt (CPUState *cpu,int int_req);void superh_cpu_dump_state (CPUState *cpu,FILE *f,int flags);hwaddr superh_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int superh_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int superh_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int superh_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); void superh_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type,
target/sparc/cpu.h +1 -1
@@ -571,7 +571,7 @@ extern const VMStateDescription vmstate_sparc_cpu;void sparc_cpu_do_interrupt (CPUState *cpu);void sparc_cpu_dump_state (CPUState *cpu,FILE *f,int flags);hwaddr sparc_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr); -int sparc_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int sparc_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int sparc_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); void QEMU_NORETURN sparc_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type,
target/xtensa/cpu.h +1 -1
@@ -569,7 +569,7 @@ void xtensa_cpu_dump_state(CPUState *cpu, FILE *f, int flags);hwaddr xtensa_cpu_get_phys_page_debug (CPUState *cpu,vaddr addr);void xtensa_count_regs (const XtensaConfig *config,unsigned *n_regs,unsigned *n_core_regs); -int xtensa_cpu_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg); +int xtensa_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int xtensa_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); void xtensa_cpu_do_unaligned_access(CPUState *cpu, vaddr addr, MMUAccessType access_type,
gdbstub.c +10 -11
@@ -319,8 +319,8 @@ static int gdb_signal_to_target (int sig)typedef struct GDBRegisterState {int base_reg;int num_regs; -gdb_reg_cb get_reg; -gdb_reg_cb set_reg; +gdb_get_reg_cb get_reg; +gdb_set_reg_cb set_reg;const char *xml;struct GDBRegisterState *next; }GDBRegisterState ;
@@ -889,19 +889,19 @@ static const char *get_feature_xml(const GDBState *s, const char *p,return name ? xml_builtin[i][1 ] :NULL ; } -static int gdb_read_register (CPUState *cpu,uint8_t *mem_buf,int reg) +static int gdb_read_register (CPUState *cpu,GByteArray *buf,int reg) {CPUClass *cc =CPU_GET_CLASS (cpu);CPUArchState *env = cpu->env_ptr;GDBRegisterState *r;if (reg < cc->gdb_num_core_regs) { -return cc->gdb_read_register (cpu, mem_buf, reg); +return cc->gdb_read_register (cpu, buf, reg); }for (r = cpu->gdb_regs; r; r = r->next) {if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { -return r->get_reg (env, mem_buf, reg - r->base_reg); +return r->get_reg (env, buf, reg - r->base_reg); } }return 0 ;
@@ -932,7 +932,7 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)*/ void gdb_register_coprocessor (CPUState *cpu, -gdb_reg_cb get_reg,gdb_reg_cb set_reg, +gdb_get_reg_cb get_reg,gdb_set_reg_cb set_reg,int num_regs,const char *xml,int g_pos) {GDBRegisterState *s;
@@ -1734,7 +1734,7 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx)return ; } - reg_size =gdb_read_register (s->g_cpu, s->mem_buf->data, + reg_size =gdb_read_register (s->g_cpu, s->mem_buf, gdb_ctx->params[0 ].val_ull);if (!reg_size) {put_packet (s,"E14" );
@@ -1832,13 +1832,12 @@ static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx)target_ulong addr, len;cpu_synchronize_state (s->g_cpu); +g_byte_array_set_size (s->mem_buf,0 ); len =0 ;for (addr =0 ; addr < s->g_cpu->gdb_num_g_regs; addr++) { - len +=gdb_read_register (s->g_cpu, s->mem_buf->data + len, - addr); + len +=gdb_read_register (s->g_cpu, s->mem_buf, addr); } -/* FIXME: This is after the fact sizing */ -g_byte_array_set_size (s->mem_buf, len); +g_assert (len == s->mem_buf->len);memtohex (s->str_buf, s->mem_buf->data, len);put_packet (s, s->str_buf->str);
hw/core/cpu.c +1 -1
@@ -177,7 +177,7 @@ static int cpu_common_write_elf64_note(WriteCoreDumpFunction f, } -static int cpu_common_gdb_read_register (CPUState *cpu,uint8_t *buf,int reg) +static int cpu_common_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg) {return 0 ; }
target/alpha/gdbstub.c +1 -1
@@ -21,7 +21,7 @@#include "cpu.h" #include "exec/gdbstub.h" -int alpha_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int alpha_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {AlphaCPU *cpu =ALPHA_CPU (cs);CPUAlphaState *env = &cpu->env;
target/arm/gdbstub.c +1 -1
@@ -32,7 +32,7 @@ typedef struct RegisterSysregXmlParam {We hack round this by giving the FPA regs zero size when talking to a newer gdb. */ -int arm_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int arm_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env;
target/arm/gdbstub64.c +1 -1
@@ -20,7 +20,7 @@#include "cpu.h" #include "exec/gdbstub.h" -int aarch64_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int aarch64_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env;
target/arm/helper.c +8 -11
@@ -47,30 +47,27 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,static void switch_mode (CPUARMState *env,int mode); -static int vfp_gdb_get_reg (CPUARMState *env,uint8_t *buf,int reg) +static int vfp_gdb_get_reg (CPUARMState *env,GByteArray *buf,int reg) {int nregs;/* VFP data registers are always little-endian. */ nregs =arm_feature (env,ARM_FEATURE_VFP3 ) ?32 :16 ;if (reg < nregs) { -stq_le_p (buf, *aa32_vfp_dreg (env, reg)); -return 8 ; +return gdb_get_reg64 (buf, *aa32_vfp_dreg (env, reg)); }if (arm_feature (env,ARM_FEATURE_NEON )) {/* Aliases for Q regs. */ nregs +=16 ;if (reg < nregs) {uint64_t *q =aa32_vfp_qreg (env, reg -32 ); -stq_le_p (buf, q[0 ]); -stq_le_p (buf +8 , q[1 ]); -return 16 ; +return gdb_get_reg128 (buf, q[0 ], q[1 ]); } }switch (reg - nregs) { -case 0 :stl_p (buf, env->vfp.xregs[ARM_VFP_FPSID ]);return 4 ; -case 1 :stl_p (buf,vfp_get_fpscr (env));return 4 ; -case 2 :stl_p (buf, env->vfp.xregs[ARM_VFP_FPEXC ]);return 4 ; +case 0 :return gdb_get_reg32 (buf, env->vfp.xregs[ARM_VFP_FPSID ]);break ; +case 1 :return gdb_get_reg32 (buf,vfp_get_fpscr (env));break ; +case 2 :return gdb_get_reg32 (buf, env->vfp.xregs[ARM_VFP_FPEXC ]);break ; }return 0 ; }
@@ -101,7 +98,7 @@ static int vfp_gdb_set_reg(CPUARMState *env, uint8_t *buf, int reg)return 0 ; } -static int aarch64_fpu_gdb_get_reg (CPUARMState *env,uint8_t *buf,int reg) +static int aarch64_fpu_gdb_get_reg (CPUARMState *env,GByteArray *buf,int reg) {switch (reg) { case 0 ... 31:
@@ -204,7 +201,7 @@ static void write_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri, } } -static int arm_gdb_get_sysreg (CPUARMState *env,uint8_t *buf,int reg) +static int arm_gdb_get_sysreg (CPUARMState *env,GByteArray *buf,int reg) {ARMCPU *cpu =env_archcpu (env);const ARMCPRegInfo *ri;
target/cris/gdbstub.c +2 -2
@@ -21,7 +21,7 @@#include "cpu.h" #include "exec/gdbstub.h" -int crisv10_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int crisv10_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {CRISCPU *cpu =CRIS_CPU (cs);CPUCRISState *env = &cpu->env;
@@ -53,7 +53,7 @@ int crisv10_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)return 0 ; } -int cris_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int cris_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {CRISCPU *cpu =CRIS_CPU (cs);CPUCRISState *env = &cpu->env;
target/hppa/gdbstub.c +1 -1
@@ -21,7 +21,7 @@#include "cpu.h" #include "exec/gdbstub.h" -int hppa_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int hppa_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {HPPACPU *cpu =HPPA_CPU (cs);CPUHPPAState *env = &cpu->env;
target/i386/gdbstub.c +1 -1
@@ -79,7 +79,7 @@ static const int gpr_map32[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };#endif -int x86_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int x86_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env;
target/lm32/gdbstub.c +1 -1
@@ -22,7 +22,7 @@#include "exec/gdbstub.h" #include "hw/lm32/lm32_pic.h" -int lm32_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int lm32_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {LM32CPU *cpu =LM32_CPU (cs);CPULM32State *env = &cpu->env;
target/m68k/gdbstub.c +1 -1
@@ -21,7 +21,7 @@#include "cpu.h" #include "exec/gdbstub.h" -int m68k_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int m68k_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {M68kCPU *cpu =M68K_CPU (cs);CPUM68KState *env = &cpu->env;
target/m68k/helper.c +2 -2
@@ -68,7 +68,7 @@ void m68k_cpu_list(void)g_slist_free (list); } -static int cf_fpu_gdb_get_reg (CPUM68KState *env,uint8_t *mem_buf,int n) +static int cf_fpu_gdb_get_reg (CPUM68KState *env,GByteArray *buf,int n) {if (n <8 ) {float_status s;
@@ -105,7 +105,7 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)return 0 ; } -static int m68k_fpu_gdb_get_reg (CPUM68KState *env,uint8_t *mem_buf,int n) +static int m68k_fpu_gdb_get_reg (CPUM68KState *env,GByteArray *buf,int n) {if (n <8 ) {int len =gdb_get_reg16 (buf, env->fregs[n].l.upper);
target/microblaze/gdbstub.c +1 -1
@@ -21,7 +21,7 @@#include "cpu.h" #include "exec/gdbstub.h" -int mb_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int mb_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {MicroBlazeCPU *cpu =MICROBLAZE_CPU (cs);CPUMBState *env = &cpu->env;
target/mips/gdbstub.c +1 -1
@@ -22,7 +22,7 @@#include "internal.h" #include "exec/gdbstub.h" -int mips_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int mips_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {MIPSCPU *cpu =MIPS_CPU (cs);CPUMIPSState *env = &cpu->env;
target/nios2/cpu.c +1 -1
@@ -124,7 +124,7 @@ static void nios2_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)#endif } -static int nios2_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +static int nios2_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {Nios2CPU *cpu =NIOS2_CPU (cs);CPUClass *cc =CPU_GET_CLASS (cs);
target/openrisc/gdbstub.c +1 -1
@@ -21,7 +21,7 @@#include "cpu.h" #include "exec/gdbstub.h" -int openrisc_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int openrisc_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {OpenRISCCPU *cpu =OPENRISC_CPU (cs);CPUOpenRISCState *env = &cpu->env;
target/ppc/gdbstub.c +26 -22
128 lines not on this page · raw message
target/ppc/translate_init.inc.c +30 -24
124 lines not on this page · raw message
target/riscv/gdbstub.c +9 -9
@@ -269,7 +269,7 @@ static int csr_register_map[] = { CSR_MHCOUNTEREN, }; -int riscv_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int riscv_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {RISCVCPU *cpu =RISCV_CPU (cs);CPURISCVState *env = &cpu->env;
@@ -300,10 +300,10 @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)return 0 ; } -static int riscv_gdb_get_fpu (CPURISCVState *env,uint8_t *mem_buf,int n) +static int riscv_gdb_get_fpu (CPURISCVState *env,GByteArray *buf,int n) {if (n <32 ) { -return gdb_get_reg64 (mem_buf, env->fpr[n]); +return gdb_get_reg64 (buf, env->fpr[n]);/* there is hole between ft11 and fflags in fpu.xml */ }else if (n <36 && n >32 ) {target_ulong val =0 ;
@@ -316,7 +316,7 @@ static int riscv_gdb_get_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) result =riscv_csrrw_debug (env, n -33 + csr_register_map[8 ], &val,0 ,0 );if (result ==0 ) { -return gdb_get_regl (mem_buf, val); +return gdb_get_regl (buf, val); } }return 0 ;
@@ -345,7 +345,7 @@ static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n)return 0 ; } -static int riscv_gdb_get_csr (CPURISCVState *env,uint8_t *mem_buf,int n) +static int riscv_gdb_get_csr (CPURISCVState *env,GByteArray *buf,int n) {if (n <ARRAY_SIZE (csr_register_map)) {target_ulong val =0 ;
@@ -353,7 +353,7 @@ static int riscv_gdb_get_csr(CPURISCVState *env, uint8_t *mem_buf, int n) result =riscv_csrrw_debug (env, csr_register_map[n], &val,0 ,0 );if (result ==0 ) { -return gdb_get_regl (mem_buf, val); +return gdb_get_regl (buf, val); } }return 0 ;
@@ -373,13 +373,13 @@ static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n)return 0 ; } -static int riscv_gdb_get_virtual (CPURISCVState *cs,uint8_t *mem_buf,int n) +static int riscv_gdb_get_virtual (CPURISCVState *cs,GByteArray *buf,int n) {if (n ==0 ) {#ifdef CONFIG_USER_ONLY -return gdb_get_regl (mem_buf,0 ); +return gdb_get_regl (buf,0 );#else -return gdb_get_regl (mem_buf, cs->priv); +return gdb_get_regl (buf, cs->priv);#endif }return 0 ;
target/s390x/gdbstub.c +15 -15
@@ -27,7 +27,7 @@#include "sysemu/hw_accel.h" #include "sysemu/tcg.h" -int s390_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int s390_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {S390CPU *cpu =S390_CPU (cs);CPUS390XState *env = &cpu->env;
@@ -82,11 +82,11 @@ int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)/* total number of registers in s390-acr.xml */ #define S390_NUM_AC_REGS 16 -static int cpu_read_ac_reg (CPUS390XState *env,uint8_t *mem_buf,int n) +static int cpu_read_ac_reg (CPUS390XState *env,GByteArray *buf,int n) {switch (n) { case S390_A0_REGNUM ... S390_A15_REGNUM: -return gdb_get_reg32 (mem_buf, env->aregs[n]); +return gdb_get_reg32 (buf, env->aregs[n]);default :return 0 ; }
@@ -111,13 +111,13 @@ static int cpu_write_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n)/* total number of registers in s390-fpr.xml */ #define S390_NUM_FP_REGS 17 -static int cpu_read_fp_reg (CPUS390XState *env,uint8_t *mem_buf,int n) +static int cpu_read_fp_reg (CPUS390XState *env,GByteArray *buf,int n) {switch (n) {case S390_FPC_REGNUM : -return gdb_get_reg32 (mem_buf, env->fpc); +return gdb_get_reg32 (buf, env->fpc); case S390_F0_REGNUM ... S390_F15_REGNUM: -return gdb_get_reg64 (mem_buf, *get_freg (env, n -S390_F0_REGNUM )); +return gdb_get_reg64 (buf, *get_freg (env, n -S390_F0_REGNUM ));default :return 0 ; }
@@ -145,17 +145,17 @@ static int cpu_write_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n)/* total number of registers in s390-vx.xml */ #define S390_NUM_VREGS 32 -static int cpu_read_vreg (CPUS390XState *env,uint8_t *mem_buf,int n) +static int cpu_read_vreg (CPUS390XState *env,GByteArray *buf,int n) {int ret;switch (n) { case S390_V0L_REGNUM ... S390_V15L_REGNUM: - ret =gdb_get_reg64 (mem_buf, env->vregs[n][1 ]); + ret =gdb_get_reg64 (buf, env->vregs[n][1 ]);break ; case S390_V16_REGNUM ... S390_V31_REGNUM: - ret =gdb_get_reg64 (mem_buf, env->vregs[n][0 ]); - ret +=gdb_get_reg64 (mem_buf +8 , env->vregs[n][1 ]); + ret =gdb_get_reg64 (buf, env->vregs[n][0 ]); + ret +=gdb_get_reg64 (buf, env->vregs[n][1 ]);break ;default : ret =0 ;
@@ -186,11 +186,11 @@ static int cpu_write_vreg(CPUS390XState *env, uint8_t *mem_buf, int n)#define S390_NUM_C_REGS 16#ifndef CONFIG_USER_ONLY -static int cpu_read_c_reg (CPUS390XState *env,uint8_t *mem_buf,int n) +static int cpu_read_c_reg (CPUS390XState *env,GByteArray *buf,int n) {switch (n) { case S390_C0_REGNUM ... S390_C15_REGNUM: -return gdb_get_regl (mem_buf, env->cregs[n]); +return gdb_get_regl (buf, env->cregs[n]);default :return 0 ; }
@@ -223,7 +223,7 @@ static int cpu_write_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n)/* total number of registers in s390-virt.xml */ #define S390_NUM_VIRT_REGS 8 -static int cpu_read_virt_reg (CPUS390XState *env,uint8_t *mem_buf,int n) +static int cpu_read_virt_reg (CPUS390XState *env,GByteArray *mem_buf,int n) {switch (n) {case S390_VIRT_CKC_REGNUM :
@@ -296,9 +296,9 @@ static int cpu_write_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n)/* total number of registers in s390-gs.xml */ #define S390_NUM_GS_REGS 4 -static int cpu_read_gs_reg (CPUS390XState *env,uint8_t *mem_buf,int n) +static int cpu_read_gs_reg (CPUS390XState *env,GByteArray *buf,int n) { -return gdb_get_regl (mem_buf, env->gscb[n]); +return gdb_get_regl (buf, env->gscb[n]); }static int cpu_write_gs_reg (CPUS390XState *env,uint8_t *mem_buf,int n)
target/sh4/gdbstub.c +1 -1
@@ -24,7 +24,7 @@/* Hint: Use "set architecture sh4" in GDB to see fpu registers */ /* FIXME: We should use XML for this. */ -int superh_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int superh_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {SuperHCPU *cpu =SUPERH_CPU (cs);CPUSH4State *env = &cpu->env;
target/sparc/gdbstub.c +1 -1
@@ -27,7 +27,7 @@#define gdb_get_rega (buf, val) gdb_get_regl(buf, val)#endif -int sparc_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int sparc_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {SPARCCPU *cpu =SPARC_CPU (cs);CPUSPARCState *env = &cpu->env;
target/xtensa/gdbstub.c +1 -1
@@ -63,7 +63,7 @@ void xtensa_count_regs(const XtensaConfig *config, } } -int xtensa_cpu_gdb_read_register (CPUState *cs,uint8_t *mem_buf,int n) +int xtensa_cpu_gdb_read_register (CPUState *cs,GByteArray *mem_buf,int n) {XtensaCPU *cpu =XTENSA_CPU (cs);CPUXtensaState *env = &cpu->env;
tests/tcg/multiarch/float_helpers.c +1 -6
@@ -78,12 +78,7 @@ char *fmt_16(uint16_t num)*/ #ifndef SNANF -/* Signaling NaN macros, if supported. */ -# if __GNUC_PREREQ (3 ,3 ) -# define SNANF (__builtin_nansf ("")) -# define SNAN (__builtin_nans ("")) -# define SNANL (__builtin_nansl ("")) -# endif +#error no SNANF - what happened?#endif static float f32_numbers[] = {
Signature · 1 line
2.20.1
Re: [RFC PATCH 08/11] gdbstub: extend GByteArray to read register helpers
Quoted 17 lines · Alex Bennée
+++
b/target/arm/helper.ctarget/arm/helper.c +2
-3@@ -47,30 +47,27 @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,static void switch_mode (CPUARMState *env,int mode); -static int vfp_gdb_get_reg (CPUARMState *env,uint8_t *buf,int reg) +static int vfp_gdb_get_reg (CPUARMState *env,GByteArray *buf,int reg) {int nregs;/* VFP data registers are always little-endian. */ nregs =arm_feature (env,ARM_FEATURE_VFP3 ) ?32 :16 ;if (reg < nregs) { -stq_le_p (buf, *aa32_vfp_dreg (env, reg)); -return 8 ; +return gdb_get_reg64 (buf, *aa32_vfp_dreg (env, reg)); }
target/arm/helper.c static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, · line 65
Quoted 10 lines
target/arm/helper.c +1
-3if (arm_feature (env,ARM_FEATURE_NEON )) {/* Aliases for Q regs. */ nregs +=16 ;if (reg < nregs) {uint64_t *q =aa32_vfp_qreg (env, reg -32 ); -stq_le_p (buf, q[0 ]); -stq_le_p (buf +8 , q[1 ]); -return 16 ; +return gdb_get_reg128 (buf, q[0 ], q[1 ]); }
Mostly ok, except for this change, which has the same endianness problem that the other ARM change did. Why is this not done in patch 6 with the other?
r~
RFC PATCH 9/11 target/arm: prepare for multiple dynamic XMLs
In reply to Alex BennéeWe will want to generate similar dynamic XML for gdbstub support of SVE registers (the upstream doesn't use XML). To that end lightly rename a few things to make the distinction.
--- target/arm/cpu.h | 20 +++++++++++++------- target/arm/gdbstub.c | 30 +++++++++++++++--------------- target/arm/helper.c | 4 ++-- 3 files changed, 30 insertions(+), 24 deletions(-)
target/arm/cpu.h +13 -7
@@ -128,14 +128,20 @@ enum {/** * DynamicGDBXMLInfo: * @desc: Contains the XML descriptions. -* @num_cpregs: Number of the Coprocessor registers seen by GDB. -* @cpregs_keys: Array that contains the corresponding Key of -* a given cpreg with the same order of the cpreg in the XML description. +* @num: Number of the registers in this XML seen by GDB. +* @data: A union with data specific to the set of registers +* @cpregs_keys: Array that contains the corresponding Key of +* a given cpreg with the same order of the cpreg +* in the XML description. */ typedef struct DynamicGDBXMLInfo {char *desc; -int num_cpregs; -uint32_t *cpregs_keys; +int num; +union { +struct { +uint32_t *keys; + } cpregs; + } data; }DynamicGDBXMLInfo ;/* CPU state for each instance of a generic timer (in cp15 c14) */
@@ -751,7 +757,7 @@ struct ARMCPU {uint64_t *cpreg_vmstate_values;int32_t cpreg_vmstate_array_len; -DynamicGDBXMLInfo dyn_xml; +DynamicGDBXMLInfo dyn_sysreg_xml;/* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS ];
@@ -958,7 +964,7 @@ int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);/* Dynamically generates for gdb stub an XML description of the sysregs from * the cp_regs hashtable. Returns the registered sysregs number. */ -int arm_gen_dynamic_xml (CPUState *cpu); +int arm_gen_dynamic_sysreg_xml (CPUState *cpu);/* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL
target/arm/gdbstub.c +15 -15
@@ -106,15 +106,15 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)return 0 ; } -static void arm_gen_one_xml_reg_tag (GString *s,DynamicGDBXMLInfo *dyn_xml, -ARMCPRegInfo *ri,uint32_t ri_key, -int bitsize) +static void arm_gen_one_xml_sysreg_tag (GString *s,DynamicGDBXMLInfo *dyn_xml, +ARMCPRegInfo *ri,uint32_t ri_key, +int bitsize) {g_string_append_printf (s,"<reg name=\"%s\"" , ri->name);g_string_append_printf (s," bitsize=\"%d\"" , bitsize);g_string_append_printf (s," group=\"cp_regs\"/>" ); - dyn_xml->num_cpregs++; - dyn_xml->cpregs_keys[dyn_xml->num_cpregs -1 ] = ri_key; + dyn_xml->data.cpregs.keys[dyn_xml->num] = ri_key; + dyn_xml->num++; } static void arm_register_sysreg_for_xml(gpointer key, gpointer value,
@@ -126,12 +126,12 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value,GString *s = param->s;ARMCPU *cpu =ARM_CPU (param->cs);CPUARMState *env = &cpu->env; -DynamicGDBXMLInfo *dyn_xml = &cpu->dyn_xml; +DynamicGDBXMLInfo *dyn_xml = &cpu->dyn_sysreg_xml;if (!(ri->type & (ARM_CP_NO_RAW |ARM_CP_NO_GDB ))) {if (arm_feature (env,ARM_FEATURE_AARCH64 )) {if (ri->state ==ARM_CP_STATE_AA64 ) { -arm_gen_one_xml_reg_tag (s , dyn_xml, ri, ri_key,64 ); +arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,64 ); } }else {if (ri->state ==ARM_CP_STATE_AA32 ) {
@@ -140,30 +140,30 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value,return ; }if (ri->type &ARM_CP_64BIT ) { -arm_gen_one_xml_reg_tag (s , dyn_xml, ri, ri_key,64 ); +arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,64 ); }else { -arm_gen_one_xml_reg_tag (s , dyn_xml, ri, ri_key,32 ); +arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,32 ); } } } } } -int arm_gen_dynamic_xml (CPUState *cs) +int arm_gen_dynamic_sysreg_xml (CPUState *cs) {ARMCPU *cpu =ARM_CPU (cs);GString *s =g_string_new (NULL );RegisterSysregXmlParam param = {cs, s}; - cpu->dyn_xml.num_cpregs =0 ; - cpu->dyn_xml.cpregs_keys =g_new (uint32_t,g_hash_table_size (cpu->cp_regs)); + cpu->dyn_sysreg_xml.num =0 ; + cpu->dyn_sysreg_xml.data.cpregs.keys =g_new (uint32_t,g_hash_table_size (cpu->cp_regs));g_string_printf (s,"<?xml version=\"1.0\"?>" );g_string_append_printf (s,"<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" );g_string_append_printf (s,"<feature name=\"org.qemu.gdb.arm.sys.regs\">" );g_hash_table_foreach (cpu->cp_regs, arm_register_sysreg_for_xml, ¶m);g_string_append_printf (s,"</feature>" ); - cpu->dyn_xml.desc =g_string_free (s, false); -return cpu->dyn_xml.num_cpregs; + cpu->dyn_sysreg_xml.desc =g_string_free (s, false); +return cpu->dyn_sysreg_xml.num; }const char *arm_gdb_get_dynamic_xml (CPUState *cs,const char *xmlname)
@@ -171,7 +171,7 @@ const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname)ARMCPU *cpu =ARM_CPU (cs);if (strcmp (xmlname,"system-registers.xml" ) ==0 ) { -return cpu->dyn_xml.desc; +return cpu->dyn_sysreg_xml.desc; }return NULL ; }
target/arm/helper.c +2 -2
@@ -207,7 +207,7 @@ static int arm_gdb_get_sysreg(CPUARMState *env, GByteArray *buf, int reg)const ARMCPRegInfo *ri;uint32_t key; - key = cpu->dyn_xml.cpregs_keys[reg]; + key = cpu->dyn_sysreg_xml.data.cpregs.keys[reg]; ri =get_arm_cp_reginfo (cpu->cp_regs, key);if (ri) {if (cpreg_field_is_64bit (ri)) {
@@ -6911,7 +6911,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) 19, "arm-vfp.xml", 0); }gdb_register_coprocessor (cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, -arm_gen_dynamic_xml (cs), +arm_gen_dynamic_sysreg_xml (cs),"system-registers.xml" ,0 ); }
Signature · 1 line
2.20.1
RFC PATCH 10/11 target/arm: explicitly encode regnum in our XML
In reply to Alex BennéeThis is described as optional but I'm not convinced of the numbering when multiple target fragments are sent.
--- target/arm/cpu.h | 2 +- target/arm/gdbstub.c | 16 ++++++++++------ target/arm/helper.c | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-)
target/arm/cpu.h +1 -1
@@ -964,7 +964,7 @@ int arm_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);/* Dynamically generates for gdb stub an XML description of the sysregs from * the cp_regs hashtable. Returns the registered sysregs number. */ -int arm_gen_dynamic_sysreg_xml (CPUState *cpu); +int arm_gen_dynamic_sysreg_xml (CPUState *cpu,int base_reg);/* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL
target/arm/gdbstub.c +10 -6
@@ -24,6 +24,7 @@typedef struct RegisterSysregXmlParam {CPUState *cs;GString *s; +int n; }RegisterSysregXmlParam ;/* Old gdb always expect FPA registers. Newer (xml-aware) gdb only expect
@@ -108,10 +109,11 @@ int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)static void arm_gen_one_xml_sysreg_tag (GString *s,DynamicGDBXMLInfo *dyn_xml,ARMCPRegInfo *ri,uint32_t ri_key, -int bitsize) +int bitsize,int regnum) {g_string_append_printf (s,"<reg name=\"%s\"" , ri->name);g_string_append_printf (s," bitsize=\"%d\"" , bitsize); +g_string_append_printf (s," regnum=\"%d\"" , regnum);g_string_append_printf (s," group=\"cp_regs\"/>" ); dyn_xml->data.cpregs.keys[dyn_xml->num] = ri_key; dyn_xml->num++;
@@ -124,6 +126,7 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value,ARMCPRegInfo *ri = value;RegisterSysregXmlParam *param = (RegisterSysregXmlParam *)p;GString *s = param->s; +int n = param->n;ARMCPU *cpu =ARM_CPU (param->cs);CPUARMState *env = &cpu->env;DynamicGDBXMLInfo *dyn_xml = &cpu->dyn_sysreg_xml;
@@ -131,7 +134,7 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value,if (!(ri->type & (ARM_CP_NO_RAW |ARM_CP_NO_GDB ))) {if (arm_feature (env,ARM_FEATURE_AARCH64 )) {if (ri->state ==ARM_CP_STATE_AA64 ) { -arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,64 ); +arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,64 , n); } }else {if (ri->state ==ARM_CP_STATE_AA32 ) {
@@ -140,20 +143,21 @@ static void arm_register_sysreg_for_xml(gpointer key, gpointer value,return ; }if (ri->type &ARM_CP_64BIT ) { -arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,64 ); +arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,64 , n); }else { -arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,32 ); +arm_gen_one_xml_sysreg_tag (s , dyn_xml, ri, ri_key,32 , n); } } } } + param->n++; } -int arm_gen_dynamic_sysreg_xml (CPUState *cs) +int arm_gen_dynamic_sysreg_xml (CPUState *cs,int base_reg) {ARMCPU *cpu =ARM_CPU (cs);GString *s =g_string_new (NULL ); -RegisterSysregXmlParam param = {cs, s}; +RegisterSysregXmlParam param = {cs, s, base_reg}; cpu->dyn_sysreg_xml.num =0 ; cpu->dyn_sysreg_xml.data.cpregs.keys =g_new (uint32_t,g_hash_table_size (cpu->cp_regs));
target/arm/helper.c +1 -1
@@ -6911,7 +6911,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) 19, "arm-vfp.xml", 0); }gdb_register_coprocessor (cs, arm_gdb_get_sysreg, arm_gdb_set_sysreg, -arm_gen_dynamic_sysreg_xml (cs), +arm_gen_dynamic_sysreg_xml (cs, cs->gdb_num_regs),"system-registers.xml" ,0 ); }
Signature · 1 line
2.20.1
Re: [RFC PATCH 10/11] target/arm: explicitly encode regnum in our XML
Quoted 9 lines · Alex Bennée
This is described as optional but I'm not convinced of the numbering when multiple target fragments are sent.
Signed-off-by Alex Bennée <[email protected]>--- target/arm/cpu.h | 2 +- target/arm/gdbstub.c | 16 ++++++++++------ target/arm/helper.c | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-)
r~
RFC PATCH 11/11 target/arm: generate xml description of our SVE registers
In reply to Alex Bennée--- target/arm/cpu.h | 10 ++++- target/arm/gdbstub.c | 99 ++++++++++++++++++++++++++++++++++++++++++++ target/arm/helper.c | 69 ++++++++++++++++++++++++++++-- 3 files changed, 173 insertions(+), 5 deletions(-)
target/arm/cpu.h +8 -2
@@ -141,6 +141,9 @@ typedef struct DynamicGDBXMLInfo {struct {uint32_t *keys; } cpregs; +struct { +int fpsr_pos; + } sve; } data; } DynamicGDBXMLInfo;
@@ -758,6 +761,7 @@ struct ARMCPU {int32_t cpreg_vmstate_array_len;DynamicGDBXMLInfo dyn_sysreg_xml; +DynamicGDBXMLInfo dyn_svereg_xml;/* Timers used by the generic (architected) timer */ QEMUTimer *gt_timer[NUM_GTIMERS ];
@@ -961,10 +965,12 @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,int arm_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int arm_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); -/* Dynamically generates for gdb stub an XML description of the sysregs from -* the cp_regs hashtable. Returns the registered sysregs number. +/* +* Helpers to dynamically generates XML descriptions of the sysregs +* and SVE registers. Returns the number of registers in each set. */ int arm_gen_dynamic_sysreg_xml (CPUState *cpu,int base_reg); +int arm_gen_dynamic_svereg_xml (CPUState *cpu,int base_reg);/* Returns the dynamically generated XML for the gdb stub. * Returns a pointer to the XML contents for the specified XML file or NULL
target/arm/gdbstub.c +99 -0
111 lines not on this page · raw message
target/arm/helper.c +66 -3
93 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [RFC PATCH 11/11] target/arm: generate xml description of our SVE registers
Quoted 11 lines · Alex Bennée
target/arm/gdbstub.c +11
-0+int arm_gen_dynamic_svereg_xml (CPUState *cs,int base_reg) +{ +ARMCPU *cpu =ARM_CPU (cs); +GString *s =g_string_new (NULL ); +DynamicGDBXMLInfo *info = &cpu->dyn_svereg_xml; +g_autoptr (GString) ts =g_string_new ("" ); +g_autoptr (GString) us =g_string_new ("" ); +int i, j; + info->num =0 ; +g_string_printf (s,"<?xml version=\"1.0\"?>" ); +g_string_append_printf (s,"<!DOCTYPE target SYSTEM \"gdb-target.dtd\">" );
target/arm/gdbstub.c int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg) · line 216
Quoted 10 lines
target/arm/gdbstub.c +10
-0+g_string_append_printf (s,"<feature name=\"org.qemu.gdb.aarch64.sve\">" ); +/* first define types and the union they belong to */ +for (i =0 ; i <ARRAY_SIZE (vec_lanes); i++) { +int count =128 / vec_lanes[i].size; +g_string_printf (ts,"vq%d%s" , count, vec_lanes[i].suffix); +g_string_append_printf (s,"<vector id=\"%s\" type=\"%s\" count=\"%d\"/>" , + ts->str, vec_lanes[i].gdb_type, count); +g_string_append_printf (us,"<field name=\"%s\" type=\"%s\"/>" , + vec_lanes[i].suffix, ts->str); + }
Really? Separate 128-bit registers for each Zreg lane? Surely that's not what gdb does...
r~