X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fopenocd.c;h=5ce01e82bd2892ad46759908995e2ef507ce9302;hp=0ae0d19f3537bdb87217790db09ab69944a9c406;hb=f5ae179519d578169b4123af89eebf667efa1e2c;hpb=c5eb8e29bdc296c2d0b25cc771639567b5f7707f diff --git a/src/openocd.c b/src/openocd.c index 0ae0d19f35..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 * @@ -29,18 +29,19 @@ #endif #include "openocd.h" +#include #include +#include #include +#include #include -#include -#include -#include +#include +#include #include #include #include #include -#include #ifdef HAVE_STRINGS_H #include @@ -50,18 +51,31 @@ #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) { switch (event) @@ -114,27 +128,29 @@ COMMAND_HANDLER(handle_init_command) if (ERROR_OK != retval) return ERROR_FAIL; - if ((retval = jtag_interface_init(CMD_CTX)) != ERROR_OK) + if ((retval = adapter_init(CMD_CTX)) != ERROR_OK) { - /* we must be able to set up the jtag interface */ + /* we must be able to set up the debug adapter */ return retval; } - LOG_DEBUG("jtag interface 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... + LOG_DEBUG("Debug Adapter init complete"); + + /* "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) @@ -158,10 +174,43 @@ COMMAND_HANDLER(handle_init_command) return ERROR_OK; } +COMMAND_HANDLER(handle_add_script_search_dir_command) +{ + if (CMD_ARGC != 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + add_script_search_dir(CMD_ARGV[0]); + + 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", }, @@ -181,17 +230,34 @@ static const struct command_registration openocd_command_handlers[] = { "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 }; -int openocd_register_commands(struct command_context *cmd_ctx) +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! 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(); @@ -202,14 +268,13 @@ struct command_context *setup_command_handler(Jim_Interp *interp) /* register subsystem commands */ typedef int (*command_registrant_t)(struct command_context *cmd_ctx); - command_registrant_t command_registrants[] = { + static const command_registrant_t command_registrants[] = { &openocd_register_commands, &server_register_commands, &gdb_register_commands, &log_register_commands, - &jtag_register_commands, - &xsvf_register_commands, - &svf_register_commands, + &transport_register_commands, + &interface_register_commands, &target_register_commands, &flash_register_commands, &nand_register_commands, @@ -228,7 +293,8 @@ struct command_context *setup_command_handler(Jim_Interp *interp) } LOG_DEBUG("command registration: complete"); - LOG_OUTPUT(OPENOCD_VERSION "\n"); + LOG_OUTPUT(OPENOCD_VERSION "\n" + "Licensed under GNU GPL v2\n"); global_cmd_ctx = cmd_ctx; @@ -247,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; @@ -254,18 +323,17 @@ int openocd_main(int argc, char *argv[]) "http://openocd.berlios.de/doc/doxygen/bugs.html" "\n"); - command_context_mode(cmd_ctx, COMMAND_CONFIG); command_set_output_handler(cmd_ctx, configuration_output_handler, NULL); if (parse_cmdline_args(cmd_ctx, argc, argv) != ERROR_OK) return EXIT_FAILURE; - ret = parse_config_file(cmd_ctx); - if (ret != ERROR_OK) + if (server_preinit() != ERROR_OK) return EXIT_FAILURE; - if (httpd_start(cmd_ctx) != ERROR_OK) + ret = parse_config_file(cmd_ctx); + if (ret != ERROR_OK) return EXIT_FAILURE; ret = server_init(cmd_ctx); @@ -285,14 +353,12 @@ int openocd_main(int argc, char *argv[]) server_quit(); - httpd_stop(); - unregister_all_commands(cmd_ctx, NULL); /* free commandline interface */ command_done(cmd_ctx); - jtag_interface_quit(); + adapter_quit(); return ret; }