command context: fix errors when running certain commands on startup
authorØyvind Harboe <oyvind.harboe@zylin.com>
Mon, 3 May 2010 15:01:53 +0000 (17:01 +0200)
committerØyvind Harboe <oyvind.harboe@zylin.com>
Wed, 5 May 2010 13:24:24 +0000 (15:24 +0200)
Various commands, e.g. "arm mcr xxxx" would fail if invoked upon startup
since it there was no command context defined for the jim interpreter
in that case.

A Jim interpreter is now associated with a command context(telnet,
gdb server's) or the default global command context.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
src/helper/command.c
src/helper/command.h
src/jtag/tcl.c
src/target/armv4_5.c
src/target/target.c

index 3625508f26b584afc09177dd19e391623ccdff34..be262f2e463d684ca8db4db51b7dd74d5771dee2 100644 (file)
@@ -167,14 +167,18 @@ static const char **script_command_args_alloc(
        return words;
 }
 
-static struct command_context *current_command_context(Jim_Interp *interp)
+struct command_context *current_command_context(Jim_Interp *interp)
 {
        /* grab the command context from the associated data */
        struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
        if (NULL == cmd_ctx)
        {
                /* Tcl can invoke commands directly instead of via command_run_line(). This would
-                * happen when the Jim Tcl interpreter is provided by eCos.
+                * happen when the Jim Tcl interpreter is provided by eCos or if we are running
+                * commands in a startup script.
+                *
+                * A telnet or gdb server would provide a non-default command context to
+                * handle piping of error output, have a separate current target, etc.
                 */
                cmd_ctx = global_cmd_ctx;
        }
index 8a418d367d04f604ad6084adb47f381a420c58de..2c192416ef1d7324b7762a26c5c23e4cb510e3cc 100644 (file)
@@ -311,6 +311,10 @@ void command_set_output_handler(struct command_context* context,
 
 int command_context_mode(struct command_context *context, enum command_mode mode);
 
+/* Return the current command context associated with the Jim interpreter or
+ * alternatively the global default command interpreter
+ */
+struct command_context *current_command_context(Jim_Interp *interp);
 /**
  * Creates a new command context using the startup TCL provided and
  * the existing Jim interpreter, if any. If interp == NULL, then command_init
index 579ca9e598f55d99086cdfda0e9ac2ad4a70d9ae..ea6d07e341a34bf8a1eb6de45b8fc5416bed320b 100644 (file)
@@ -684,7 +684,7 @@ static int jim_jtag_arp_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
                return JIM_ERR;
        }
-       struct command_context *context = Jim_GetAssocData(interp, "context");
+       struct command_context *context = current_command_context(interp);
        int e = jtag_init_inner(context);
        if (e != ERROR_OK) {
                Jim_SetResult_sprintf(goi.interp, "error: %d", e);
@@ -701,7 +701,7 @@ static int jim_jtag_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj *const
                Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
                return JIM_ERR;
        }
-       struct command_context *context = Jim_GetAssocData(interp, "context");
+       struct command_context *context = current_command_context(interp);
        int e = jtag_init_reset(context);
        if (e != ERROR_OK) {
                Jim_SetResult_sprintf(goi.interp, "error: %d", e);
index eeb6694c93c28fd1590425ba409de19be51b4a63..1a84a5f4e77b34680e06f4ff7c0ff3a07c054545 100644 (file)
@@ -820,11 +820,9 @@ static int jim_mcrmrc(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        struct arm *arm;
        int retval;
 
-       context = Jim_GetAssocData(interp, "context");
-       if (context == NULL) {
-               LOG_ERROR("%s: no command context", __func__);
-               return JIM_ERR;
-       }
+       context = current_command_context(interp);
+       assert( context != NULL);
+
        target = get_current_target(context);
        if (target == NULL) {
                LOG_ERROR("%s: no current target", __func__);
index a3a1b0adb763a32c27ad3a4039a73d828fd5cd9a..d17bb7445fa119b579a28ee15e9bedfbb2f35a38 100644 (file)
@@ -3236,12 +3236,9 @@ static int jim_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        struct command_context *context;
        struct target *target;
 
-       context = Jim_GetAssocData(interp, "context");
-       if (context == NULL)
-       {
-               LOG_ERROR("mem2array: no command context");
-               return JIM_ERR;
-       }
+       context = current_command_context(interp);
+       assert (context != NULL);
+
        target = get_current_target(context);
        if (target == NULL)
        {
@@ -3432,11 +3429,9 @@ static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        struct command_context *context;
        struct target *target;
 
-       context = Jim_GetAssocData(interp, "context");
-       if (context == NULL) {
-               LOG_ERROR("array2mem: no command context");
-               return JIM_ERR;
-       }
+       context = current_command_context(interp);
+       assert (context != NULL);
+
        target = get_current_target(context);
        if (target == NULL) {
                LOG_ERROR("array2mem: no current target");
@@ -4318,7 +4313,9 @@ static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *a
  */
 static int jim_target_event_list(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
-       struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert (cmd_ctx != NULL);
+
        struct target *target = Jim_CmdPrivData(interp);
        struct target_event_action *teap = target->event_action;
        command_print(cmd_ctx, "Event actions for target (%d) %s\n",
@@ -4512,7 +4509,9 @@ static int target_create(Jim_GetOptInfo *goi)
        struct target *target;
        struct command_context *cmd_ctx;
 
-       cmd_ctx = Jim_GetAssocData(goi->interp, "context");
+       cmd_ctx = current_command_context(goi->interp);
+       assert (cmd_ctx != NULL);
+
        if (goi->argc < 3) {
                Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ?type? ..options...");
                return JIM_ERR;
@@ -4686,7 +4685,9 @@ static int jim_target_current(Jim_Interp *interp, int argc, Jim_Obj *const *argv
                Jim_WrongNumArgs(interp, 1, argv, "Too many parameters");
                return JIM_ERR;
        }
-       struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
+       struct command_context *cmd_ctx = current_command_context(interp);
+       assert (cmd_ctx != NULL);
+
        Jim_SetResultString(interp, get_current_target(cmd_ctx)->cmd_name, -1);
        return JIM_OK;
 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)