2022-08-30 10:01:12 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2022-06-26 18:24:07 -05:00
|
|
|
|
2007-08-10 14:44:06 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005, 2007 by Dominic Rath *
|
|
|
|
* Dominic.Rath@gmx.de *
|
|
|
|
***************************************************************************/
|
2012-02-05 06:03:04 -06:00
|
|
|
|
2007-08-10 14:44:06 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-12-03 06:14:28 -06:00
|
|
|
#include <helper/log.h>
|
2007-08-10 14:44:06 -05:00
|
|
|
#include "trace.h"
|
|
|
|
#include "target.h"
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
int trace_point(struct target *target, uint32_t number)
|
2007-08-14 04:48:54 -05:00
|
|
|
{
|
2009-11-13 11:26:19 -06:00
|
|
|
struct trace *trace = target->trace_info;
|
2007-08-14 04:48:54 -05:00
|
|
|
|
2009-06-20 22:17:46 -05:00
|
|
|
LOG_DEBUG("tracepoint: %i", (int)number);
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2007-08-14 04:48:54 -05:00
|
|
|
if (number < trace->num_trace_points)
|
|
|
|
trace->trace_points[number].hit_counter++;
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
if (trace->trace_history_size) {
|
2007-08-14 04:48:54 -05:00
|
|
|
trace->trace_history[trace->trace_history_pos++] = number;
|
2012-02-05 06:03:04 -06:00
|
|
|
if (trace->trace_history_pos == trace->trace_history_size) {
|
2007-08-14 04:48:54 -05:00
|
|
|
trace->trace_history_pos = 0;
|
|
|
|
trace->trace_history_overflowed = 1;
|
|
|
|
}
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2007-08-14 04:48:54 -05:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-10 01:56:52 -06:00
|
|
|
COMMAND_HANDLER(handle_trace_point_command)
|
2007-08-14 04:48:54 -05:00
|
|
|
{
|
2009-11-15 07:57:37 -06:00
|
|
|
struct target *target = get_current_target(CMD_CTX);
|
2009-11-13 11:26:19 -06:00
|
|
|
struct trace *trace = target->trace_info;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
if (CMD_ARGC == 0) {
|
2009-06-18 02:09:35 -05:00
|
|
|
uint32_t i;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
for (i = 0; i < trace->num_trace_points; i++) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "trace point 0x%8.8" PRIx32 " (%lld times hit)",
|
2007-08-14 04:48:54 -05:00
|
|
|
trace->trace_points[i].address,
|
2009-06-18 05:40:33 -05:00
|
|
|
(long long)trace->trace_points[i].hit_counter);
|
2007-08-14 04:48:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
if (!strcmp(CMD_ARGV[0], "clear")) {
|
2020-08-17 02:58:58 -05:00
|
|
|
free(trace->trace_points);
|
|
|
|
trace->trace_points = NULL;
|
|
|
|
|
2008-01-20 07:52:06 -06:00
|
|
|
trace->num_trace_points = 0;
|
2007-08-14 04:48:54 -05:00
|
|
|
trace->trace_points_size = 0;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2007-08-14 04:48:54 -05:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2007-08-14 04:48:54 -05:00
|
|
|
/* resize array if necessary */
|
2012-02-05 06:03:04 -06:00
|
|
|
if (!trace->trace_points || (trace->trace_points_size == trace->num_trace_points)) {
|
|
|
|
trace->trace_points = realloc(trace->trace_points,
|
|
|
|
sizeof(struct trace_point) * (trace->trace_points_size + 32));
|
2007-08-14 04:48:54 -05:00
|
|
|
trace->trace_points_size += 32;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-10-24 08:36:06 -05:00
|
|
|
uint32_t address;
|
2009-11-15 10:15:59 -06:00
|
|
|
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
|
2009-10-24 08:36:06 -05:00
|
|
|
trace->trace_points[trace->num_trace_points].address = address;
|
2007-08-14 04:48:54 -05:00
|
|
|
trace->trace_points[trace->num_trace_points].hit_counter = 0;
|
|
|
|
trace->num_trace_points++;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2007-08-14 04:48:54 -05:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2007-08-10 14:44:06 -05:00
|
|
|
|
2009-11-10 01:56:52 -06:00
|
|
|
COMMAND_HANDLER(handle_trace_history_command)
|
2007-08-10 14:44:06 -05:00
|
|
|
{
|
2009-11-15 07:57:37 -06:00
|
|
|
struct target *target = get_current_target(CMD_CTX);
|
2009-11-13 11:26:19 -06:00
|
|
|
struct trace *trace = target->trace_info;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
if (CMD_ARGC > 0) {
|
2007-08-14 04:48:54 -05:00
|
|
|
trace->trace_history_pos = 0;
|
|
|
|
trace->trace_history_overflowed = 0;
|
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
if (!strcmp(CMD_ARGV[0], "clear")) {
|
2007-08-14 04:48:54 -05:00
|
|
|
/* clearing is implicit, we've just reset position anyway */
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2020-08-17 02:58:58 -05:00
|
|
|
free(trace->trace_history);
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-11-15 10:15:59 -06:00
|
|
|
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], trace->trace_history_size);
|
2009-06-18 02:09:35 -05:00
|
|
|
trace->trace_history = malloc(sizeof(uint32_t) * trace->trace_history_size);
|
2009-06-23 17:49:23 -05:00
|
|
|
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "new trace history size: %i", (int)(trace->trace_history_size));
|
2012-02-05 06:03:04 -06:00
|
|
|
} else {
|
2009-06-18 02:09:35 -05:00
|
|
|
uint32_t i;
|
|
|
|
uint32_t first = 0;
|
|
|
|
uint32_t last = trace->trace_history_pos;
|
2009-03-18 06:43:09 -05:00
|
|
|
|
2009-06-23 17:47:42 -05:00
|
|
|
if (!trace->trace_history_size) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "trace history buffer is not allocated");
|
2009-03-18 06:43:09 -05:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2012-02-05 06:03:04 -06:00
|
|
|
|
|
|
|
if (trace->trace_history_overflowed) {
|
2007-08-14 04:48:54 -05:00
|
|
|
first = trace->trace_history_pos;
|
|
|
|
last = trace->trace_history_pos - 1;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2012-02-05 06:03:04 -06:00
|
|
|
for (i = first; (i % trace->trace_history_size) != last; i++) {
|
|
|
|
if (trace->trace_history[i % trace->trace_history_size] < trace->num_trace_points) {
|
2009-06-18 02:09:35 -05:00
|
|
|
uint32_t address;
|
2007-08-14 04:48:54 -05:00
|
|
|
address = trace->trace_points[trace->trace_history[i % trace->trace_history_size]].address;
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "trace point %i: 0x%8.8" PRIx32 "",
|
2012-02-05 06:03:04 -06:00
|
|
|
(int)(trace->trace_history[i % trace->trace_history_size]),
|
|
|
|
address);
|
|
|
|
} else
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "trace point %i: -not defined-",
|
2012-02-05 06:03:04 -06:00
|
|
|
(int)(trace->trace_history[i % trace->trace_history_size]));
|
2007-08-10 14:44:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2007-08-14 04:48:54 -05:00
|
|
|
|
2009-11-23 09:43:06 -06:00
|
|
|
static const struct command_registration trace_exec_command_handlers[] = {
|
|
|
|
{
|
|
|
|
.name = "history",
|
2010-01-07 17:05:26 -06:00
|
|
|
.handler = handle_trace_history_command,
|
2009-11-23 09:43:06 -06:00
|
|
|
.mode = COMMAND_EXEC,
|
2010-01-07 17:05:26 -06:00
|
|
|
.help = "display trace history, clear history or set size",
|
|
|
|
.usage = "['clear'|size]",
|
2009-11-23 09:43:06 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "point",
|
2010-01-07 17:05:26 -06:00
|
|
|
.handler = handle_trace_point_command,
|
2009-11-23 09:43:06 -06:00
|
|
|
.mode = COMMAND_EXEC,
|
|
|
|
.help = "display trace points, clear list of trace points, "
|
2010-01-07 17:05:26 -06:00
|
|
|
"or add new tracepoint at address",
|
|
|
|
.usage = "['clear'|address]",
|
2009-11-23 09:43:06 -06:00
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
static const struct command_registration trace_command_handlers[] = {
|
|
|
|
{
|
|
|
|
.name = "trace",
|
2010-01-02 17:52:35 -06:00
|
|
|
.mode = COMMAND_EXEC,
|
2009-11-23 09:43:06 -06:00
|
|
|
.help = "trace command group",
|
2011-12-24 08:26:12 -06:00
|
|
|
.usage = "",
|
2009-11-23 09:43:06 -06:00
|
|
|
.chain = trace_exec_command_handlers,
|
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
|
2009-11-13 15:25:47 -06:00
|
|
|
int trace_register_commands(struct command_context *cmd_ctx)
|
2007-08-14 04:48:54 -05:00
|
|
|
{
|
2009-11-23 09:43:06 -06:00
|
|
|
return register_commands(cmd_ctx, NULL, trace_command_handlers);
|
2007-08-14 04:48:54 -05:00
|
|
|
}
|