This is an automated email from Gerrit.

"Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8587

-- gerrit

commit 93a428f016aba619ddd652b26610b5c0d38d7bda
Author: Antonio Borneo <borneo.anto...@gmail.com>
Date:   Sat Dec 2 17:34:57 2023 +0100

    command: rewrite command 'capture' as COMMAND_HANDLER
    
    While there, use Jim_EvalObj() to execute the subcommand, so any
    error will correctly report the TCL file and the line number that
    have originated the error, instead of the silly:
            > capture {bogus command}
            command.c:703: Error: invalid command name "bogus"
            at file "command.c", line 703
    
    Change-Id: Ic75a6146d6cedf49e808d98501fa1a7d4235b58a
    Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com>

diff --git a/src/helper/command.c b/src/helper/command.c
index dae5ef0aa7..ed6ac2fe85 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -683,12 +683,12 @@ COMMAND_HANDLER(handle_echo)
 /* 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)
+COMMAND_HANDLER(handle_command_capture)
 {
-       if (argc != 2)
-               return JIM_ERR;
+       if (CMD_ARGC != 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
 
-       struct log_capture_state *state = command_log_capture_start(interp);
+       struct log_capture_state *state = 
command_log_capture_start(CMD_CTX->interp);
 
        /* disable polling during capture. This avoids capturing output
         * from polling.
@@ -698,14 +698,18 @@ static int jim_capture(Jim_Interp *interp, int argc, 
Jim_Obj *const *argv)
         */
        bool save_poll_mask = jtag_poll_mask();
 
-       const char *str = Jim_GetString(argv[1], NULL);
-       int retcode = Jim_Eval_Named(interp, str, __THIS__FILE__, __LINE__);
+       int jimretval = Jim_EvalObj(CMD_CTX->interp, CMD_JIMTCL_ARGV[0]);
 
        jtag_poll_unmask(save_poll_mask);
 
        command_log_capture_finish(state);
 
-       return retcode;
+       int reslen;
+       const char *result = Jim_GetString(Jim_GetResult(CMD_CTX->interp), 
&reslen);
+       if (reslen > 0)
+               command_print(CMD, "%s", result);
+
+       return (jimretval == JIM_OK) ? ERROR_OK : ERROR_FAIL;
 }
 
 struct help_entry {
@@ -1134,7 +1138,7 @@ static const struct command_registration 
command_builtin_handlers[] = {
        {
                .name = "capture",
                .mode = COMMAND_ANY,
-               .jim_handler = jim_capture,
+               .handler = handle_command_capture,
                .help = "Capture progress output and return as tcl return 
value. If the "
                                "progress output was empty, return tcl return 
value.",
                .usage = "command",

-- 

Reply via email to