server: tcl_trace command
Implements async target trace output to the tcl server Change-Id: I0178f6404447337d523782a1d2c317457030da40 Signed-off-by: Austin Morton <austinpmorton@gmail.com> Reviewed-on: http://openocd.zylin.com/2588 Tested-by: jenkins Reviewed-by: Paul Fertser <fercerpav@gmail.com>
This commit is contained in:
committed by
Paul Fertser
parent
85903156d7
commit
d28ab08cfa
@@ -35,11 +35,15 @@ static int armv7m_poll_trace(void *target)
|
||||
if (retval != ERROR_OK || !size)
|
||||
return retval;
|
||||
|
||||
if (fwrite(buf, 1, size, armv7m->trace_config.trace_file) == size)
|
||||
fflush(armv7m->trace_config.trace_file);
|
||||
else {
|
||||
LOG_ERROR("Error writing to the trace destination file");
|
||||
return ERROR_FAIL;
|
||||
target_call_trace_callbacks(target, size, buf);
|
||||
|
||||
if (armv7m->trace_config.trace_file != NULL) {
|
||||
if (fwrite(buf, 1, size, armv7m->trace_config.trace_file) == size)
|
||||
fflush(armv7m->trace_config.trace_file);
|
||||
else {
|
||||
LOG_ERROR("Error writing to the trace destination file");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
@@ -183,10 +187,13 @@ COMMAND_HANDLER(handle_tpiu_config_command)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
armv7m->trace_config.config_type = INTERNAL;
|
||||
armv7m->trace_config.trace_file = fopen(CMD_ARGV[cmd_idx], "ab");
|
||||
if (!armv7m->trace_config.trace_file) {
|
||||
LOG_ERROR("Can't open trace destination file");
|
||||
return ERROR_FAIL;
|
||||
|
||||
if (strcmp(CMD_ARGV[cmd_idx], "-") != 0) {
|
||||
armv7m->trace_config.trace_file = fopen(CMD_ARGV[cmd_idx], "ab");
|
||||
if (!armv7m->trace_config.trace_file) {
|
||||
LOG_ERROR("Can't open trace destination file");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd_idx++;
|
||||
|
||||
@@ -140,6 +140,7 @@ struct target *all_targets;
|
||||
static struct target_event_callback *target_event_callbacks;
|
||||
static struct target_timer_callback *target_timer_callbacks;
|
||||
LIST_HEAD(target_reset_callback_list);
|
||||
LIST_HEAD(target_trace_callback_list);
|
||||
static const int polling_interval = 100;
|
||||
|
||||
static const Jim_Nvp nvp_assert[] = {
|
||||
@@ -1350,6 +1351,28 @@ int target_register_reset_callback(int (*callback)(struct target *target,
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
int target_register_trace_callback(int (*callback)(struct target *target,
|
||||
size_t len, uint8_t *data, void *priv), void *priv)
|
||||
{
|
||||
struct target_trace_callback *entry;
|
||||
|
||||
if (callback == NULL)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
entry = malloc(sizeof(struct target_trace_callback));
|
||||
if (entry == NULL) {
|
||||
LOG_ERROR("error allocating buffer for trace callback entry");
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
entry->callback = callback;
|
||||
entry->priv = priv;
|
||||
list_add(&entry->list, &target_trace_callback_list);
|
||||
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
int target_register_timer_callback(int (*callback)(void *priv), int time_ms, int periodic, void *priv)
|
||||
{
|
||||
struct target_timer_callback **callbacks_p = &target_timer_callbacks;
|
||||
@@ -1427,6 +1450,25 @@ int target_unregister_reset_callback(int (*callback)(struct target *target,
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
int target_unregister_trace_callback(int (*callback)(struct target *target,
|
||||
size_t len, uint8_t *data, void *priv), void *priv)
|
||||
{
|
||||
struct target_trace_callback *entry;
|
||||
|
||||
if (callback == NULL)
|
||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||
|
||||
list_for_each_entry(entry, &target_trace_callback_list, list) {
|
||||
if (entry->callback == callback && entry->priv == priv) {
|
||||
list_del(&entry->list);
|
||||
free(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
int target_unregister_timer_callback(int (*callback)(void *priv), void *priv)
|
||||
{
|
||||
if (callback == NULL)
|
||||
@@ -1480,6 +1522,16 @@ int target_call_reset_callbacks(struct target *target, enum target_reset_mode re
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
int target_call_trace_callbacks(struct target *target, size_t len, uint8_t *data)
|
||||
{
|
||||
struct target_trace_callback *callback;
|
||||
|
||||
list_for_each_entry(callback, &target_trace_callback_list, list)
|
||||
callback->callback(target, len, data, callback->priv);
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
static int target_timer_callback_periodic_restart(
|
||||
struct target_timer_callback *cb, struct timeval *now)
|
||||
{
|
||||
|
||||
@@ -292,6 +292,12 @@ struct target_reset_callback {
|
||||
int (*callback)(struct target *target, enum target_reset_mode reset_mode, void *priv);
|
||||
};
|
||||
|
||||
struct target_trace_callback {
|
||||
struct list_head list;
|
||||
void *priv;
|
||||
int (*callback)(struct target *target, size_t len, uint8_t *data, void *priv);
|
||||
};
|
||||
|
||||
struct target_timer_callback {
|
||||
int (*callback)(void *priv);
|
||||
int time_ms;
|
||||
@@ -323,6 +329,15 @@ int target_unregister_reset_callback(
|
||||
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);
|
||||
int target_unregister_trace_callback(
|
||||
int (*callback)(struct target *target,
|
||||
size_t len, uint8_t *data, void *priv),
|
||||
void *priv);
|
||||
|
||||
/* Poll the status of the target, detect any error conditions and report them.
|
||||
*
|
||||
* Also note that this fn will clear such error conditions, so a subsequent
|
||||
@@ -341,6 +356,7 @@ int target_resume(struct target *target, int current, uint32_t address,
|
||||
int target_halt(struct target *target);
|
||||
int target_call_event_callbacks(struct target *target, enum target_event event);
|
||||
int target_call_reset_callbacks(struct target *target, enum target_reset_mode reset_mode);
|
||||
int target_call_trace_callbacks(struct target *target, size_t len, uint8_t *data);
|
||||
|
||||
/**
|
||||
* The period is very approximate, the callback can happen much more often
|
||||
|
||||
Reference in New Issue
Block a user