diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2022-05-04 16:17:08 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2022-05-07 11:03:03 +0000 |
commit | f88a7dde6a0c5e0a74806f6e81528a8525591e9e (patch) | |
tree | 0257255a04491313231374e943b781d6a6e0d21a /src/server | |
parent | b4f8d99c8d9e453b2beb3f6c9db7ff01c8d00756 (diff) | |
download | riscv-openocd-f88a7dde6a0c5e0a74806f6e81528a8525591e9e.zip riscv-openocd-f88a7dde6a0c5e0a74806f6e81528a8525591e9e.tar.gz riscv-openocd-f88a7dde6a0c5e0a74806f6e81528a8525591e9e.tar.bz2 |
server/gdb: fix gdb remote monitor cmd on multi-target
Commit 5ebb1bdea1df ("server/gdb: fix return of gdb remote monitor
command") replaces the call to command_run_line() with call to
Jim_EvalObj() but does not properly set the "context".
In multi-target environment, his can cause the erroneously
execution of the command on the wrong target.
Copy from the code in command_run_line() the proper setup before
executing Jim_EvalObj().
Change-Id: I56738c80779082ca146a06c01bc30e28bc835fd3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Bohdan Tymkiv <bohdan200@gmail.com>
Fixes: 5ebb1bdea1df ("server/gdb: fix return of gdb remote monitor command")
Reviewed-on: https://review.openocd.org/c/openocd/+/6966
Tested-by: jenkins
Reviewed-by: Bohdan Tymkiv <bohdan200@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Tim Newsome <tim@sifive.com>
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/gdb_server.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 728cb53..4efdc1e 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -2750,6 +2750,7 @@ static int gdb_query_packet(struct connection *connection, if (strncmp(packet, "qRcmd,", 6) == 0) { if (packet_size > 6) { + Jim_Interp *interp = cmd_ctx->interp; char *cmd; cmd = malloc((packet_size - 6) / 2 + 1); size_t len = unhexify((uint8_t *)cmd, packet + 6, (packet_size - 6) / 2); @@ -2761,20 +2762,31 @@ static int gdb_query_packet(struct connection *connection, /* some commands need to know the GDB connection, make note of current * GDB connection. */ current_gdb_connection = gdb_connection; + struct target *saved_target_override = cmd_ctx->current_target_override; - cmd_ctx->current_target_override = target; + cmd_ctx->current_target_override = NULL; - int retval = Jim_EvalObj(cmd_ctx->interp, Jim_NewStringObj(cmd_ctx->interp, cmd, -1)); + struct command_context *old_context = Jim_GetAssocData(interp, "context"); + Jim_DeleteAssocData(interp, "context"); + int retval = Jim_SetAssocData(interp, "context", NULL, cmd_ctx); + if (retval == JIM_OK) { + retval = Jim_EvalObj(interp, Jim_NewStringObj(interp, cmd, -1)); + Jim_DeleteAssocData(interp, "context"); + } + int inner_retval = Jim_SetAssocData(interp, "context", NULL, old_context); + if (retval == JIM_OK) + retval = inner_retval; cmd_ctx->current_target_override = saved_target_override; + current_gdb_connection = NULL; target_call_timer_callbacks_now(); gdb_connection->output_flag = GDB_OUTPUT_NO; free(cmd); if (retval == JIM_RETURN) - retval = cmd_ctx->interp->returnCode; + retval = interp->returnCode; int lenmsg; - const char *cretmsg = Jim_GetString(Jim_GetResult(cmd_ctx->interp), &lenmsg); + const char *cretmsg = Jim_GetString(Jim_GetResult(interp), &lenmsg); char *retmsg; if (lenmsg && cretmsg[lenmsg - 1] != '\n') { retmsg = alloc_printf("%s\n", cretmsg); |