X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fopenocd.c;h=7347cad8e5b0d5ba3cb8122d078a78d5517f6bc6;hb=d4de14dafe43f264b9490b543b9cd50a1345fe9e;hp=04a63074152af9976439cc4cb2c57ebca0c7a66c;hpb=1e0f89841575de2b8b6313825ec8edd8bc7910a0;p=openocd.git diff --git a/src/openocd.c b/src/openocd.c index 04a6307415..7347cad8e5 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -2,7 +2,7 @@ * Copyright (C) 2005 by Dominic Rath * * Dominic.Rath@gmx.de * * * - * Copyright (C) 2007,2008 Øyvind Harboe * + * Copyright (C) 2007-2010 Øyvind Harboe * * oyvind.harboe@zylin.com * * * * Copyright (C) 2008 Richard Missenden * @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -51,15 +52,29 @@ #define OPENOCD_VERSION \ "Open On-Chip Debugger " VERSION RELSTR " (" PKGBLDDATE ")" -/* Give TELNET a way to find out what version this is */ -COMMAND_HANDLER(handle_version_command) +/* Give scripts and TELNET a way to find out what version this is */ +static int jim_version_command(Jim_Interp *interp, int argc, + Jim_Obj * const *argv) { - if (CMD_ARGC != 0) - return ERROR_COMMAND_SYNTAX_ERROR; - - command_print(CMD_CTX, OPENOCD_VERSION); + if (argc > 2) + { + return JIM_ERR; + } + const char *str = ""; + char * version_str; + version_str = OPENOCD_VERSION; + + if (argc == 2) + str = Jim_GetString(argv[1], NULL); + + if (strcmp("git", str) == 0) + { + version_str = GITVERSION; + } + + Jim_SetResult(interp, Jim_NewStringObj(interp, version_str, -1)); - return ERROR_OK; + return JIM_OK; } static int log_target_callback_event_handler(struct target *target, enum target_event event, void *priv) @@ -170,10 +185,33 @@ COMMAND_HANDLER(handle_add_script_search_dir_command) return ERROR_OK; } + +static int jim_stacktrace_command(Jim_Interp *interp, int argc, + Jim_Obj * const *argv) +{ + if (argc != 1) + { + return JIM_ERR; + } + Jim_Obj * stacktrace = Jim_DuplicateObj(interp, interp->stackTrace); + + /* 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", - .handler = &handle_version_command, + .jim_handler = jim_version_command, .mode = COMMAND_ANY, .help = "show program version", }, @@ -200,6 +238,14 @@ static const struct command_registration openocd_command_handlers[] = { .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 }; @@ -268,6 +314,9 @@ int openocd_main(int argc, char *argv[]) cmd_ctx = setup_command_handler(NULL); + if (util_init(cmd_ctx) != ERROR_OK) + return EXIT_FAILURE; + if (ioutil_init(cmd_ctx) != ERROR_OK) return EXIT_FAILURE;