This is an automated email from Gerrit. Austin Morton ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/2336
-- gerrit commit 29e5e8492c581dca66371459377c057f809803da Author: Austin Morton <[email protected]> Date: Wed Oct 8 08:55:45 2014 -0400 server: tcl_events command Implement tcl_events command which streams event and target state changes to a connected TCL server Change-Id: I4d83e9fa209e95426c440030597f99e9f0c3b260 Signed-off-by: Austin Morton <[email protected]> diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index b62f1a3..c9ede38 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -23,6 +23,7 @@ #endif #include "tcl_server.h" +#include <target/target.h> #define TCL_SERVER_VERSION "TCL Server 0.1" #define TCL_MAX_LINE (4096) @@ -32,9 +33,11 @@ struct tcl_connection { int tc_lineoffset; char tc_line[TCL_MAX_LINE]; int tc_outerror;/* flag an output error */ + enum target_state tc_laststate; }; static char *tcl_port; +static bool tcl_events; /* handlers */ static int tcl_new_connection(struct connection *connection); @@ -42,6 +45,34 @@ static int tcl_input(struct connection *connection); static int tcl_output(struct connection *connection, const void *buf, ssize_t len); static int tcl_closed(struct connection *connection); +static int tcl_target_callback_event_handler(struct target *target, + enum target_event event, void *priv) +{ + struct connection *connection = priv; + struct tcl_connection *tclc; + char buf[256]; + + tclc = connection->priv; + + if (tcl_events) { + sprintf(buf, "#EVENT %s\r\n\x1a", target_event_name(event)); + buf[sizeof(buf)-1] = 0; + tcl_output(connection, buf, strlen(buf)); + + struct target *target = get_current_target(connection->cmd_ctx); + if (target != NULL) { + if (tclc->tc_laststate != target->state) { + tclc->tc_laststate = target->state; + sprintf(buf, "#STATE %s\r\n\x1a", target_state_name(target)); + buf[sizeof(buf)-1] = 0; + tcl_output(connection, buf, strlen(buf)); + } + } + } + + return ERROR_OK; +} + /* write data out to a socket. * * this is a blocking write, so the return value must equal the length, if @@ -77,6 +108,13 @@ static int tcl_new_connection(struct connection *connection) memset(tclc, 0, sizeof(struct tcl_connection)); connection->priv = tclc; + + struct target *target = get_current_target(connection->cmd_ctx); + if (target != NULL) + tclc->tc_laststate = target->state; + + target_register_event_callback(tcl_target_callback_event_handler, connection); + return ERROR_OK; } @@ -152,6 +190,9 @@ static int tcl_closed(struct connection *connection) free(connection->priv); connection->priv = NULL; } + + target_unregister_event_callback(tcl_target_callback_event_handler, connection); + return ERROR_OK; } @@ -172,6 +213,11 @@ COMMAND_HANDLER(handle_tcl_port_command) return CALL_COMMAND_HANDLER(server_pipe_command, &tcl_port); } +COMMAND_HANDLER(handle_tcl_events_command) +{ + return CALL_COMMAND_HANDLER(handle_command_parse_bool, &tcl_events, "TCL Server Event subscription"); +} + static const struct command_registration tcl_command_handlers[] = { { .name = "tcl_port", @@ -182,11 +228,19 @@ static const struct command_registration tcl_command_handlers[] = { "Read help on 'gdb_port'.", .usage = "[port_num]", }, + { + .name = "tcl_events", + .handler = handle_tcl_events_command, + .mode = COMMAND_ANY, + .help = "Enable or disable tcl server event output", + .usage = "[on/off]", + }, COMMAND_REGISTRATION_DONE }; int tcl_register_commands(struct command_context *cmd_ctx) { tcl_port = strdup("6666"); + tcl_events = 0; return register_commands(cmd_ctx, NULL, tcl_command_handlers); } diff --git a/src/target/target.c b/src/target/target.c index d7a2c48..abed5a2 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -280,6 +280,17 @@ const char *target_state_name(struct target *t) return cp; } +const char *target_event_name(enum target_event event) +{ + const char *cp; + cp = Jim_Nvp_value2name_simple(nvp_target_event, event)->name; + if (!cp) { + LOG_ERROR("Invalid target event: %d", (int)(event)); + cp = "(*BUG*unknown*BUG*)"; + } + return cp; +} + /* determine the number of the new target */ static int new_target_number(void) { diff --git a/src/target/target.h b/src/target/target.h index 0552b8f..40a4887 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -565,6 +565,9 @@ int target_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, /** Return the *name* of this targets current state */ const char *target_state_name(struct target *target); +/** Return the *name* of a target event enumeration value */ +const char *target_event_name(enum target_event event); + /* DANGER!!!!! * * if "area" passed in to target_alloc_working_area() points to a memory -- ------------------------------------------------------------------------------ Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
