Message ID | 20240307182623.1450717-4-gustavo.romero@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2,1/5] gdbstub: Rename back gdb_handlesig | expand |
On 3/7/24 08:26, Gustavo Romero wrote: > +void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx) > +{ > + unsigned long offset, len; > + uint8_t *siginfo_offset; > + > + offset = get_param(params, 0)->val_ul; > + len = get_param(params, 1)->val_ul; > + > + if (offset + len > sizeof(target_siginfo_t)) { If you save the siginfo_len from gdb_handlesig, you can place this in user.c. Is it really correct to reject (offset == 0) + (len == large), rather than truncate len? > + /* Reply */ > + g_string_assign(gdbserver_state.str_buf, "l"); > + gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len); It seems easy enough to reply with the exact length remaining... r~
Hi Richard! On 3/7/24 6:13 PM, Richard Henderson wrote: > On 3/7/24 08:26, Gustavo Romero wrote: >> +void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx) >> +{ >> + unsigned long offset, len; >> + uint8_t *siginfo_offset; >> + >> + offset = get_param(params, 0)->val_ul; >> + len = get_param(params, 1)->val_ul; >> + >> + if (offset + len > sizeof(target_siginfo_t)) { > > If you save the siginfo_len from gdb_handlesig, you can place this in user.c Shouldn't all user-only stubs be placed in user-target.c? Like gdb_handle_query_xfer_auxv and gdb_handle_query_xfer_exec_file, and since what controls the inclusion in the build of user-target.c is CONFIG_USER_ONLY? > Is it really correct to reject (offset == 0) + (len == large), rather than truncate len? I think this is correct. GDB mentions briefly that an invalid offset should be treated as an error. Thus, I think that a valid offset but a non-existing/invalid (large) length should be treated the same, cause in the end data on invalid offsets are being requested anyways. >> + /* Reply */ >> + g_string_assign(gdbserver_state.str_buf, "l"); >> + gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len); > > It seems easy enough to reply with the exact length remaining... I think the correct is to reply an error in case GDB asks a data we don't have rather than returning anything else to satisfy GDB. If offset+len is inside target_siginfo_t, than that's ok, otherwise that's an error. Cheers, Gustavo
On 3/8/24 08:30, Gustavo Romero wrote: > Hi Richard! > > On 3/7/24 6:13 PM, Richard Henderson wrote: >> On 3/7/24 08:26, Gustavo Romero wrote: >>> +void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx) >>> +{ >>> + unsigned long offset, len; >>> + uint8_t *siginfo_offset; >>> + >>> + offset = get_param(params, 0)->val_ul; >>> + len = get_param(params, 1)->val_ul; >>> + >>> + if (offset + len > sizeof(target_siginfo_t)) { >> >> If you save the siginfo_len from gdb_handlesig, you can place this in user.c > Shouldn't all user-only stubs be placed in user-target.c? Like > gdb_handle_query_xfer_auxv and gdb_handle_query_xfer_exec_file, and since > what controls the inclusion in the build of user-target.c is CONFIG_USER_ONLY? user.c is also build for CONFIG_USER_ONLY, except that it is compiled only once, and has no target-specific code in it. >> Is it really correct to reject (offset == 0) + (len == large), rather than truncate len? > > I think this is correct. GDB mentions briefly that an invalid offset > should be treated as an error. Thus, I think that a valid offset but > a non-existing/invalid (large) length should be treated the same, > cause in the end data on invalid offsets are being requested anyways. Ok. r~
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 2909bc8c69..ab38cea46b 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1651,6 +1651,8 @@ static void handle_query_supported(GArray *params, void *user_ctx) g_string_append(gdbserver_state.str_buf, ";qXfer:auxv:read+"); } g_string_append(gdbserver_state.str_buf, ";QCatchSyscalls+"); + + g_string_append(gdbserver_state.str_buf, ";qXfer:siginfo:read+"); #endif g_string_append(gdbserver_state.str_buf, ";qXfer:exec-file:read+"); #endif @@ -1799,6 +1801,12 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = { .cmd_startswith = 1, .schema = "l,l0" }, + { + .handler = gdb_handle_query_xfer_siginfo, + .cmd = "Xfer:siginfo:read::", + .cmd_startswith = 1, + .schema = "l,l0" + }, #endif { .handler = gdb_handle_query_xfer_exec_file, diff --git a/gdbstub/internals.h b/gdbstub/internals.h index a7cc69dab3..15c01c525a 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -193,6 +193,7 @@ typedef union GdbCmdVariant { void gdb_handle_query_rcmd(GArray *params, void *user_ctx); /* softmmu */ void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */ +void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx); /*user */ void gdb_handle_v_file_open(GArray *params, void *user_ctx); /* user */ void gdb_handle_v_file_close(GArray *params, void *user_ctx); /* user */ void gdb_handle_v_file_pread(GArray *params, void *user_ctx); /* user */ diff --git a/gdbstub/user-target.c b/gdbstub/user-target.c index 215bf33ab3..93739852b0 100644 --- a/gdbstub/user-target.c +++ b/gdbstub/user-target.c @@ -285,6 +285,29 @@ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx) gdb_put_packet_binary(gdbserver_state.str_buf->str, gdbserver_state.str_buf->len, true); } + +void gdb_handle_query_xfer_siginfo(GArray *params, void *user_ctx) +{ + unsigned long offset, len; + uint8_t *siginfo_offset; + + offset = get_param(params, 0)->val_ul; + len = get_param(params, 1)->val_ul; + + if (offset + len > sizeof(target_siginfo_t)) { + /* Invalid offset and/or requested length. */ + gdb_put_packet("E01"); + return; + } + + siginfo_offset = (uint8_t *)gdbserver_state.siginfo + offset; + + /* Reply */ + g_string_assign(gdbserver_state.str_buf, "l"); + gdb_memtox(gdbserver_state.str_buf, (const char *)siginfo_offset, len); + gdb_put_packet_binary(gdbserver_state.str_buf->str, + gdbserver_state.str_buf->len, true); +} #endif static const char *get_filename_param(GArray *params, int i)
Add stub to handle Xfer:siginfo:read packet query that requests the machine's siginfo data. This is used when GDB user executes 'print $_siginfo' and when the machine stops due to a signal, for instance, on SIGSEGV. The information in siginfo allows GDB to determiner further details on the signal, like the fault address/insn when the SIGSEGV is caught. Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org> --- gdbstub/gdbstub.c | 8 ++++++++ gdbstub/internals.h | 1 + gdbstub/user-target.c | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+)