openocd/src/target/trace.c

178 lines
5.6 KiB
C
Raw Normal View History

/***************************************************************************
* Copyright (C) 2005, 2007 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <helper/log.h>
#include "trace.h"
#include "target.h"
int trace_point(struct target *target, uint32_t number)
{
struct trace *trace = target->trace_info;
LOG_DEBUG("tracepoint: %i", (int)number);
if (number < trace->num_trace_points)
trace->trace_points[number].hit_counter++;
if (trace->trace_history_size) {
trace->trace_history[trace->trace_history_pos++] = number;
if (trace->trace_history_pos == trace->trace_history_size) {
trace->trace_history_pos = 0;
trace->trace_history_overflowed = 1;
}
}
return ERROR_OK;
}
COMMAND_HANDLER(handle_trace_point_command)
{
struct target *target = get_current_target(CMD_CTX);
struct trace *trace = target->trace_info;
if (CMD_ARGC == 0) {
uint32_t i;
for (i = 0; i < trace->num_trace_points; i++) {
command_print(CMD_CTX, "trace point 0x%8.8" PRIx32 " (%lld times hit)",
trace->trace_points[i].address,
(long long)trace->trace_points[i].hit_counter);
}
return ERROR_OK;
}
if (!strcmp(CMD_ARGV[0], "clear")) {
if (trace->trace_points) {
free(trace->trace_points);
trace->trace_points = NULL;
}
trace->num_trace_points = 0;
trace->trace_points_size = 0;
return ERROR_OK;
}
/* resize array if necessary */
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));
trace->trace_points_size += 32;
}
uint32_t address;
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
trace->trace_points[trace->num_trace_points].address = address;
trace->trace_points[trace->num_trace_points].hit_counter = 0;
trace->num_trace_points++;
return ERROR_OK;
}
COMMAND_HANDLER(handle_trace_history_command)
{
struct target *target = get_current_target(CMD_CTX);
struct trace *trace = target->trace_info;
if (CMD_ARGC > 0) {
trace->trace_history_pos = 0;
trace->trace_history_overflowed = 0;
if (!strcmp(CMD_ARGV[0], "clear")) {
/* clearing is implicit, we've just reset position anyway */
return ERROR_OK;
}
if (trace->trace_history)
free(trace->trace_history);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], trace->trace_history_size);
trace->trace_history = malloc(sizeof(uint32_t) * trace->trace_history_size);
command_print(CMD_CTX, "new trace history size: %i", (int)(trace->trace_history_size));
} else {
uint32_t i;
uint32_t first = 0;
uint32_t last = trace->trace_history_pos;
if (!trace->trace_history_size) {
command_print(CMD_CTX, "trace history buffer is not allocated");
return ERROR_OK;
}
if (trace->trace_history_overflowed) {
first = trace->trace_history_pos;
last = trace->trace_history_pos - 1;
}
for (i = first; (i % trace->trace_history_size) != last; i++) {
if (trace->trace_history[i % trace->trace_history_size] < trace->num_trace_points) {
uint32_t address;
address = trace->trace_points[trace->trace_history[i % trace->trace_history_size]].address;
command_print(CMD_CTX, "trace point %i: 0x%8.8" PRIx32 "",
(int)(trace->trace_history[i % trace->trace_history_size]),
address);
} else
command_print(CMD_CTX, "trace point %i: -not defined-",
(int)(trace->trace_history[i % trace->trace_history_size]));
}
}
return ERROR_OK;
}
2009-11-23 15:43:06 +00:00
static const struct command_registration trace_exec_command_handlers[] = {
{
.name = "history",
.handler = handle_trace_history_command,
2009-11-23 15:43:06 +00:00
.mode = COMMAND_EXEC,
.help = "display trace history, clear history or set size",
.usage = "['clear'|size]",
2009-11-23 15:43:06 +00:00
},
{
.name = "point",
.handler = handle_trace_point_command,
2009-11-23 15:43:06 +00:00
.mode = COMMAND_EXEC,
.help = "display trace points, clear list of trace points, "
"or add new tracepoint at address",
.usage = "['clear'|address]",
2009-11-23 15:43:06 +00:00
},
COMMAND_REGISTRATION_DONE
};
static const struct command_registration trace_command_handlers[] = {
{
.name = "trace",
.mode = COMMAND_EXEC,
2009-11-23 15:43:06 +00:00
.help = "trace command group",
command: print BUG warning when usage is missing These error messages will prompt patches to be submitted for missing .usage or empty fields. All of the below must be resolved before next release. The Jim defined commands are excluded from this checklist because the help text can be set later than during command registration. strlen(.usage) == 0 means that the command expects no arguments. Updates to this patch in Gerrit to fix problems below are most welcome. Anyone can push updated versions of a patch to Gerrit. If there are no further updates to this patch within a week, it will be pushed to the master branch to prompt more fixes. These were caught by launching OpenOCD. Error: BUG: command 'command' does not have the '.usage' field filled out Error: BUG: command 'script' does not have the '.usage' field filled out Error: BUG: command 'power_restore' does not have the '.usage' field filled out Error: BUG: command 'srst_deasserted' does not have the '.usage' field filled out Error: BUG: command 'measure_clk' does not have the '.usage' field filled out Error: BUG: command 'exit' does not have the '.usage' field filled out Error: BUG: command 'shutdown' does not have the '.usage' field filled out Error: BUG: command 'gdb_sync' does not have the '.usage' field filled out Error: BUG: command 'interface_list' does not have the '.usage' field filled out Error: BUG: command 'target' does not have the '.usage' field filled out Error: BUG: command 'target init' does not have the '.usage' field filled out Error: BUG: command 'flash' does not have the '.usage' field filled out Error: BUG: command 'flash init' does not have the '.usage' field filled out Error: BUG: command 'flash banks' does not have the '.usage' field filled out Error: BUG: command 'nand' does not have the '.usage' field filled out Error: BUG: command 'nand drivers' does not have the '.usage' field filled out Error: BUG: command 'nand init' does not have the '.usage' field filled out Error: BUG: command 'pld' does not have the '.usage' field filled out Error: BUG: command 'pld init' does not have the '.usage' field filled out Error: BUG: command 'mflash' does not have the '.usage' field filled out Error: BUG: command 'mflash init' does not have the '.usage' field filled out Error: BUG: command 'dummy' does not have the '.usage' field filled out Error: BUG: command 'dummy foo' does not have the '.usage' field filled out Error: BUG: command 'scan_chain' does not have the '.usage' field filled out Error: BUG: command 'jtag' does not have the '.usage' field filled out Error: BUG: command 'jtag init' does not have the '.usage' field filled out Error: BUG: command 'arm' does not have the '.usage' field filled out Error: BUG: command 'arm reg' does not have the '.usage' field filled out Error: BUG: command 'etm' does not have the '.usage' field filled out Error: BUG: command 'arm7_9' does not have the '.usage' field filled out Error: BUG: command 'at91eb40a.cpu' does not have the '.usage' field filled out Error: BUG: command 'at91eb40a.cpu arm' does not have the '.usage' field filled out Error: BUG: command 'arm reg' does not have the '.usage' field filled out Error: BUG: command 'at91eb40a.cpu etm' does not have the '.usage' field filled out Error: BUG: command 'at91eb40a.cpu arm7_9' does not have the '.usage' field filled out Error: BUG: command 'target_request' does not have the '.usage' field filled out ^C oyvind@fierce:~/openocd$ openocd -c "interface dummy" -f board/at91eb40a.cfg 2>&1 | grep -w BUG Error: BUG: command 'command' does not have the '.usage' field filled out Error: BUG: command 'script' does not have the '.usage' field filled out Error: BUG: command 'power_restore' does not have the '.usage' field filled out Error: BUG: command 'srst_deasserted' does not have the '.usage' field filled out Error: BUG: command 'measure_clk' does not have the '.usage' field filled out Error: BUG: command 'exit' does not have the '.usage' field filled out Error: BUG: command 'shutdown' does not have the '.usage' field filled out Error: BUG: command 'gdb_sync' does not have the '.usage' field filled out Error: BUG: command 'interface_list' does not have the '.usage' field filled out Error: BUG: command 'target' does not have the '.usage' field filled out Error: BUG: command 'target init' does not have the '.usage' field filled out Error: BUG: command 'flash' does not have the '.usage' field filled out Error: BUG: command 'flash init' does not have the '.usage' field filled out Error: BUG: command 'flash banks' does not have the '.usage' field filled out Error: BUG: command 'nand' does not have the '.usage' field filled out Error: BUG: command 'nand drivers' does not have the '.usage' field filled out Error: BUG: command 'nand init' does not have the '.usage' field filled out Error: BUG: command 'pld' does not have the '.usage' field filled out Error: BUG: command 'pld init' does not have the '.usage' field filled out Error: BUG: command 'mflash' does not have the '.usage' field filled out Error: BUG: command 'mflash init' does not have the '.usage' field filled out Error: BUG: command 'dummy' does not have the '.usage' field filled out Error: BUG: command 'dummy foo' does not have the '.usage' field filled out Error: BUG: command 'scan_chain' does not have the '.usage' field filled out Error: BUG: command 'jtag' does not have the '.usage' field filled out Error: BUG: command 'jtag init' does not have the '.usage' field filled out Error: BUG: command 'arm' does not have the '.usage' field filled out Error: BUG: command 'arm reg' does not have the '.usage' field filled out Error: BUG: command 'etm' does not have the '.usage' field filled out Error: BUG: command 'arm7_9' does not have the '.usage' field filled out Error: BUG: command 'at91eb40a.cpu' does not have the '.usage' field filled out Error: BUG: command 'at91eb40a.cpu arm' does not have the '.usage' field filled out Error: BUG: command 'arm reg' does not have the '.usage' field filled out Error: BUG: command 'at91eb40a.cpu etm' does not have the '.usage' field filled out Error: BUG: command 'at91eb40a.cpu arm7_9' does not have the '.usage' field filled out Error: BUG: command 'target_request' does not have the '.usage' field filled out Change-Id: I2c3e529530a15d2295a1950ffc59e8f2fc661012 Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com> Signed-off-by: Mathias K <kesmtp@freenet.de> Reviewed-on: http://openocd.zylin.com/299 Tested-by: jenkins Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com> Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2011-12-24 14:26:12 +00:00
.usage = "",
2009-11-23 15:43:06 +00:00
.chain = trace_exec_command_handlers,
},
COMMAND_REGISTRATION_DONE
};
int trace_register_commands(struct command_context *cmd_ctx)
{
2009-11-23 15:43:06 +00:00
return register_commands(cmd_ctx, NULL, trace_command_handlers);
}