16 #define TCL_SERVER_VERSION "TCL Server 0.1"
17 #define TCL_LINE_INITIAL (4*1024)
18 #define TCL_LINE_MAX (4*1024*1024)
49 snprintf(buf,
sizeof(buf),
"type target_event event %s\r\n\x1a",
target_event_name(event));
82 size_t len, uint8_t *data,
void *
priv)
86 char *header =
"type target_trace data ";
87 char *trailer =
"\r\n\x1a";
88 size_t hex_len = len * 2 + 1;
89 size_t max_len = hex_len + strlen(header) + strlen(trailer);
95 hex = malloc(hex_len);
96 buf = malloc(max_len);
97 hexify(hex, data, len, hex_len);
98 snprintf(buf, max_len,
"%s%s%s", header, hex, trailer);
126 LOG_ERROR(
"error during write: %d != %d", (
int)wlen, (
int)len);
172 unsigned char in[256];
174 int tc_line_size_new;
179 LOG_ERROR(
"error during read: %s", strerror(errno));
188 for (i = 0; i <
rlen; i++) {
190 tclc->tc_line[tclc->tc_lineoffset] = in[i];
191 if (tclc->tc_lineoffset + 1 < tclc->tc_line_size) {
192 tclc->tc_lineoffset++;
195 tclc->tc_linedrop = 1;
198 if (tclc->tc_line_size <= 1*1024*1024)
199 tc_line_size_new = tclc->tc_line_size * 2;
201 tc_line_size_new = tclc->tc_line_size + 1*1024*1024;
206 tc_line_new = realloc(tclc->tc_line, tc_line_size_new);
208 tclc->tc_linedrop = 1;
210 tclc->tc_line = tc_line_new;
211 tclc->tc_line_size = tc_line_size_new;
212 tclc->tc_lineoffset++;
225 if (tclc->tc_linedrop) {
226 #define ESTR "line too long\n"
232 tclc->tc_line[tclc->tc_lineoffset-1] =
'\0';
234 result = Jim_GetString(Jim_GetResult(interp), &reslen);
242 tclc->tc_lineoffset = 0;
243 tclc->tc_linedrop = 0;
270 .new_connection_during_keep_alive_handler =
NULL,
274 .keep_client_alive_handler =
NULL,
279 if (strcmp(
tcl_port,
"disabled") == 0) {
297 if (
CMD_CTX->output_handler_priv)
314 if (
CMD_CTX->output_handler_priv)
329 .handler = handle_tcl_port_command,
331 .help =
"Specify port on which to listen "
332 "for incoming Tcl syntax. "
333 "Read help on 'gdb port'.",
334 .usage =
"[port_num]",
337 .name =
"notifications",
338 .handler = handle_tcl_notifications_command,
340 .help =
"Target Notification output",
345 .handler = handle_tcl_trace_command,
347 .help =
"Target trace output",
357 .help =
"tcl command group",
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
Convert binary data into a string of hexadecimal pairs.
Support functions to access arbitrary bits in a byte array.
int command_run_line(struct command_context *context, char *line)
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
static struct esp_usb_jtag * priv
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
int connection_write(struct connection *connection, const void *data, int len)
int connection_read(struct connection *connection, void *data, int len)
int add_service(const struct service_driver *driver, const char *port, int max_connections, void *priv)
#define CONNECTION_LIMIT_UNLIMITED
#define ERROR_SERVER_REMOTE_CLOSED
#define ERROR_CONNECTION_REJECTED
void * output_handler_priv
struct command_context * cmd_ctx
const char * name
the name of the server
enum target_state tc_laststate
int target_unregister_reset_callback(int(*callback)(struct target *target, enum target_reset_mode reset_mode, void *priv), void *priv)
int target_unregister_event_callback(int(*callback)(struct target *target, enum target_event event, void *priv), void *priv)
int target_register_event_callback(int(*callback)(struct target *target, enum target_event event, void *priv), void *priv)
int target_unregister_trace_callback(int(*callback)(struct target *target, size_t len, uint8_t *data, void *priv), void *priv)
struct target * get_current_target_or_null(struct command_context *cmd_ctx)
const char * target_event_name(enum target_event event)
Return the name of a target event enumeration value.
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
int target_register_reset_callback(int(*callback)(struct target *target, enum target_reset_mode reset_mode, void *priv), void *priv)
int target_register_trace_callback(int(*callback)(struct target *target, size_t len, uint8_t *data, void *priv), void *priv)
const char * target_reset_mode_name(enum target_reset_mode reset_mode)
Return the name of a target reset reason enumeration value.
static const struct command_registration tcl_command_handlers[]
static int tcl_target_callback_reset_handler(struct target *target, enum target_reset_mode reset_mode, void *priv)
static int tcl_new_connection(struct connection *connection)
static const struct command_registration tcl_subcommand_handlers[]
static const struct service_driver tcl_service_driver
int tcl_register_commands(struct command_context *cmd_ctx)
static int tcl_target_callback_event_handler(struct target *target, enum target_event event, void *priv)
static int tcl_output(struct connection *connection, const void *buf, ssize_t len)
COMMAND_HANDLER(handle_tcl_port_command)
static int tcl_closed(struct connection *connection)
static int tcl_input(struct connection *connection)
static int tcl_target_callback_trace_handler(struct target *target, size_t len, uint8_t *data, void *priv)
void tcl_service_free(void)