X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fopenocd.c;h=5ce01e82bd2892ad46759908995e2ef507ce9302;hp=96de50c80cf701923f0572ee5b55b58e4f1fa814;hb=fdae51287cf55a039f3401ed92151dbf518e4e7f;hpb=fb96b8607a0c2a9038df3352b0ef828d78c5e418 diff --git a/src/openocd.c b/src/openocd.c index 96de50c80c..5ce01e82bd 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 * @@ -31,10 +31,10 @@ #include "openocd.h" #include #include +#include #include +#include #include -#include -#include #include #include #include @@ -42,7 +42,6 @@ #include #include -#include #ifdef HAVE_STRINGS_H #include @@ -52,15 +51,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) @@ -120,22 +133,24 @@ COMMAND_HANDLER(handle_init_command) /* we must be able to set up the debug adapter */ return retval; } + LOG_DEBUG("Debug Adapter init complete"); - /* Try to initialize & examine the JTAG chain at this point, - * but continue startup regardless. Note that platforms - * need to be able to provide JTAG event handlers that use - * a variety of JTAG operations in order to do that... + /* "transport init" verifies the expected devices are present; + * for JTAG, it checks the list of configured TAPs against + * what's discoverable, possibly with help from the platform's + * JTAG event handlers. (which require COMMAND_EXEC) */ command_context_mode(CMD_CTX, COMMAND_EXEC); - if (command_run_line(CMD_CTX, "jtag init") == ERROR_OK) - { - LOG_DEBUG("Examining targets..."); - if (target_examine() != ERROR_OK) - LOG_DEBUG("target examination failed"); - } - else - LOG_WARNING("jtag initialization failed; try 'jtag init' again."); + + retval = command_run_line(CMD_CTX, "transport init"); + if (ERROR_OK != retval) + return ERROR_FAIL; + + LOG_DEBUG("Examining targets..."); + if (target_examine() != ERROR_OK) + LOG_DEBUG("target examination failed"); + command_context_mode(CMD_CTX, COMMAND_CONFIG); if (command_run_line(CMD_CTX, "flash init") != ERROR_OK) @@ -169,10 +184,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", }, @@ -199,6 +237,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 }; @@ -227,10 +273,8 @@ struct command_context *setup_command_handler(Jim_Interp *interp) &server_register_commands, &gdb_register_commands, &log_register_commands, + &transport_register_commands, &interface_register_commands, - &jtag_register_commands, - &xsvf_register_commands, - &svf_register_commands, &target_register_commands, &flash_register_commands, &nand_register_commands, @@ -269,6 +313,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; @@ -289,9 +336,6 @@ int openocd_main(int argc, char *argv[]) if (ret != ERROR_OK) return EXIT_FAILURE; - if (httpd_start(cmd_ctx) != ERROR_OK) - return EXIT_FAILURE; - ret = server_init(cmd_ctx); if (ERROR_OK != ret) return EXIT_FAILURE; @@ -309,8 +353,6 @@ int openocd_main(int argc, char *argv[]) server_quit(); - httpd_stop(); - unregister_all_commands(cmd_ctx, NULL); /* free commandline interface */