diff options
author | Marek Vrbka <marek.vrbka@codasip.com> | 2023-09-18 14:32:44 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2023-10-14 12:00:16 +0000 |
commit | 2c8c2cb6b1426afc73519a7445a71a0aed36cf0f (patch) | |
tree | ed6d66c04809d9ca4ad9c4e506edb8827dd3830f /src | |
parent | bcaac692d0fce45189279a4c80cbd6852e4bbf4e (diff) | |
download | riscv-openocd-2c8c2cb6b1426afc73519a7445a71a0aed36cf0f.zip riscv-openocd-2c8c2cb6b1426afc73519a7445a71a0aed36cf0f.tar.gz riscv-openocd-2c8c2cb6b1426afc73519a7445a71a0aed36cf0f.tar.bz2 |
command: Prepend logs during command capture
Previously, if you ran a tcl command in capture like so:
"capture { reg 0x1000 hw }"
Such command did overwrite the tcl result if LOG_LVL_INFO or
lower was logged during it.
This patch changes it by prepending the log to the tcl result instead.
As the tcl results should not be lost during capture.
Change-Id: I37381b45e15c931ba2844d65c9d38f6ed2f6e4fd
Signed-off-by: Marek Vrbka <marek.vrbka@codasip.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7902
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
Reviewed-by: Jan Matyas <jan.matyas@codasip.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/helper/command.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index 945b890..ef50ab5 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -99,8 +99,7 @@ static struct log_capture_state *command_log_capture_start(Jim_Interp *interp) * The tcl return value is empty for openocd commands that provide * progress output. * - * Therefore we set the tcl return value only if we actually - * captured output. + * For other commands, we prepend the logs to the tcl return value. */ static void command_log_capture_finish(struct log_capture_state *state) { @@ -109,15 +108,18 @@ static void command_log_capture_finish(struct log_capture_state *state) log_remove_callback(tcl_output, state); - int length; - Jim_GetString(state->output, &length); + int loglen; + const char *log_result = Jim_GetString(state->output, &loglen); + int reslen; + const char *cmd_result = Jim_GetString(Jim_GetResult(state->interp), &reslen); - if (length > 0) - Jim_SetResult(state->interp, state->output); - else { - /* No output captured, use tcl return value (which could - * be empty too). */ - } + // Just in case the log doesn't end with a newline, we add it + if (loglen != 0 && reslen != 0 && log_result[loglen - 1] != '\n') + Jim_AppendString(state->interp, state->output, "\n", 1); + + Jim_AppendString(state->interp, state->output, cmd_result, reslen); + + Jim_SetResult(state->interp, state->output); Jim_DecrRefCount(state->interp, state->output); free(state); @@ -691,8 +693,8 @@ COMMAND_HANDLER(handle_echo) return ERROR_OK; } -/* Capture progress output and return as tcl return value. If the - * progress output was empty, return tcl return value. +/* Return both the progress output (LOG_INFO and higher) + * and the tcl return value of a command. */ static int jim_capture(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { |