+ /* insert actual error site at beginning of list*/
+ Jim_Obj *procname = Jim_NewStringObj(interp, "", -1); /* Uhhh... don't know this one. */
+ Jim_ListInsertElements(interp, stacktrace, 0, 1, &procname);
+ Jim_Obj *filename = Jim_NewStringObj(interp, interp->errorFileName, -1);
+ Jim_ListInsertElements(interp, stacktrace, 1, 1, &filename);
+ Jim_Obj *line = Jim_NewIntObj(interp, interp->errorLine);
+ Jim_ListInsertElements(interp, stacktrace, 2, 1, &line);
+
+ Jim_SetResult(interp, stacktrace);
+
+ return JIM_OK;
+}
+
+static const struct command_registration openocd_command_handlers[] = {
+ {
+ .name = "version",
+ .jim_handler = jim_version_command,
+ .mode = COMMAND_ANY,
+ .help = "show program version",
+ },
+ {
+ .name = "noinit",
+ .handler = &handle_noinit_command,
+ .mode = COMMAND_CONFIG,
+ .help = "Prevent 'init' from being called at startup.",
+ },
+ {
+ .name = "init",
+ .handler = &handle_init_command,
+ .mode = COMMAND_ANY,
+ .help = "Initializes configured targets and servers. "
+ "Changes command mode from CONFIG to EXEC. "
+ "Unless 'noinit' is called, this command is "
+ "called automatically at the end of startup.",
+
+ },
+ {
+ .name = "add_script_search_dir",
+ .handler = &handle_add_script_search_dir_command,
+ .mode = COMMAND_ANY,
+ .help = "dir to search for config files and scripts",
+
+ },
+ {
+ .name = "stacktrace",
+ .jim_handler = jim_stacktrace_command,
+ .mode = COMMAND_ANY,
+ .help = "returns the stacktrace as a list of triples: proc, file, line."
+ "The stack trace is reset when a new stack trace is being built after "
+ "a new failure has occurred.",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+static int openocd_register_commands(struct command_context *cmd_ctx)
+{
+ return register_commands(cmd_ctx, NULL, openocd_command_handlers);
+}
+
+struct command_context *global_cmd_ctx;
+
+/* NB! this fn can be invoked outside this file for non PC hosted builds
+ * NB! do not change to 'static'!!!!
+ */
+struct command_context *setup_command_handler(Jim_Interp *interp)
+{
+ log_init();
+ LOG_DEBUG("log_init: complete");
+
+ const char *startup = openocd_startup_tcl;
+ struct command_context *cmd_ctx = command_init(startup, interp);
+