file not found SEGFAULT fix
[openocd.git] / src / target / trace.c
1 /***************************************************************************
2 * Copyright (C) 2005, 2007 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "replacements.h"
25 #include "log.h"
26 #include "trace.h"
27 #include "target.h"
28 #include "command.h"
29
30 #include <stdlib.h>
31 #include <string.h>
32 #include <inttypes.h>
33
34 int trace_point(target_t *target, int number)
35 {
36 trace_t *trace = target->trace_info;
37
38 LOG_DEBUG("tracepoint: %i", number);
39
40 if (number < trace->num_trace_points)
41 trace->trace_points[number].hit_counter++;
42
43 if (trace->trace_history_size)
44 {
45 trace->trace_history[trace->trace_history_pos++] = number;
46 if (trace->trace_history_pos == trace->trace_history_size)
47 {
48 trace->trace_history_pos = 0;
49 trace->trace_history_overflowed = 1;
50 }
51 }
52
53 return ERROR_OK;
54 }
55
56 int handle_trace_point_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
57 {
58 target_t *target = get_current_target(cmd_ctx);
59 trace_t *trace = target->trace_info;
60
61 if (argc == 0)
62 {
63 int i;
64
65 for (i = 0; i < trace->num_trace_points; i++)
66 {
67 command_print(cmd_ctx, "trace point 0x%8.8x (%"PRIi64" times hit)",
68 trace->trace_points[i].address,
69 trace->trace_points[i].hit_counter);
70 }
71
72 return ERROR_OK;
73 }
74
75 if (!strcmp(args[0], "clear"))
76 {
77 if (trace->trace_points)
78 {
79 free(trace->trace_points);
80 trace->trace_points = NULL;
81 }
82 trace->num_trace_points = 0;
83 trace->trace_points_size = 0;
84
85 return ERROR_OK;
86 }
87
88 /* resize array if necessary */
89 if (!trace->trace_points || (trace->trace_points_size == trace->num_trace_points))
90 {
91 trace->trace_points = realloc(trace->trace_points, sizeof(trace_point_t) * (trace->trace_points_size + 32));
92 trace->trace_points_size += 32;
93 }
94
95 trace->trace_points[trace->num_trace_points].address = strtoul(args[0], NULL, 0);
96 trace->trace_points[trace->num_trace_points].hit_counter = 0;
97 trace->num_trace_points++;
98
99 return ERROR_OK;
100 }
101
102 int handle_trace_history_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
103 {
104 target_t *target = get_current_target(cmd_ctx);
105 trace_t *trace = target->trace_info;
106
107 if (argc > 0)
108 {
109 trace->trace_history_pos = 0;
110 trace->trace_history_overflowed = 0;
111
112 if (!strcmp(args[0], "clear"))
113 {
114 /* clearing is implicit, we've just reset position anyway */
115 return ERROR_OK;
116 }
117
118 if (trace->trace_history)
119 free(trace->trace_history);
120
121 trace->trace_history_size = strtoul(args[0], NULL, 0);
122 trace->trace_history = malloc(sizeof(u32) * trace->trace_history_size);
123
124 command_print(cmd_ctx, "new trace history size: %i", trace->trace_history_size);
125 }
126 else
127 {
128 int i;
129 int first = 0;
130 int last = trace->trace_history_pos;
131
132 if (trace->trace_history_overflowed)
133 {
134 first = trace->trace_history_pos;
135 last = trace->trace_history_pos - 1;
136 }
137
138 for (i = first; (i % trace->trace_history_size) != last; i++)
139 {
140 if (trace->trace_history[i % trace->trace_history_size] < trace->num_trace_points)
141 {
142 u32 address;
143 address = trace->trace_points[trace->trace_history[i % trace->trace_history_size]].address;
144 command_print(cmd_ctx, "trace point %i: 0x%8.8x",
145 trace->trace_history[i % trace->trace_history_size],
146 address);
147 }
148
149 else
150 {
151 command_print(cmd_ctx, "trace point %i: -not defined-", trace->trace_history[i % trace->trace_history_size]);
152 }
153 }
154 }
155
156 return ERROR_OK;
157 }
158
159 int trace_register_commands(struct command_context_s *cmd_ctx)
160 {
161 command_t *trace_cmd =
162 register_command(cmd_ctx, NULL, "trace", NULL, COMMAND_ANY, "trace commands");
163
164 register_command(cmd_ctx, trace_cmd, "history", handle_trace_history_command,
165 COMMAND_EXEC, "display trace history, ['clear'] history or set [size]");
166
167 register_command(cmd_ctx, trace_cmd, "point", handle_trace_point_command,
168 COMMAND_EXEC, "display trace points, ['clear'] list of trace points, or add new tracepoint at [address]");
169
170 return ERROR_OK;
171 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)