Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Tracing functionality for remote targets in custom GDB protocol |
9f60d481 | 2 | |
61baf725 | 3 | Copyright (C) 1997-2017 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
5af949e3 | 21 | #include "arch-utils.h" |
c906108c SS |
22 | #include "symtab.h" |
23 | #include "frame.h" | |
c906108c SS |
24 | #include "gdbtypes.h" |
25 | #include "expression.h" | |
26 | #include "gdbcmd.h" | |
27 | #include "value.h" | |
28 | #include "target.h" | |
68c765e2 | 29 | #include "target-dcache.h" |
c906108c | 30 | #include "language.h" |
104c1213 | 31 | #include "inferior.h" |
1042e4c0 | 32 | #include "breakpoint.h" |
104c1213 | 33 | #include "tracepoint.h" |
c5f0f3d0 | 34 | #include "linespec.h" |
4e052eda | 35 | #include "regcache.h" |
c94fdfd0 | 36 | #include "completer.h" |
fe898f56 | 37 | #include "block.h" |
de4f826b | 38 | #include "dictionary.h" |
383f836e | 39 | #include "observer.h" |
029a67e4 | 40 | #include "user-regs.h" |
79a45b7d | 41 | #include "valprint.h" |
41575630 | 42 | #include "gdbcore.h" |
768a979c | 43 | #include "objfiles.h" |
35b1e5cc | 44 | #include "filenames.h" |
00bf0b85 | 45 | #include "gdbthread.h" |
2c58c0a9 | 46 | #include "stack.h" |
176a6961 | 47 | #include "remote.h" |
0fb4aa4b | 48 | #include "source.h" |
c906108c SS |
49 | #include "ax.h" |
50 | #include "ax-gdb.h" | |
2a7498d8 | 51 | #include "memrange.h" |
3065dfb6 | 52 | #include "cli/cli-utils.h" |
55aa24fb | 53 | #include "probe.h" |
d0353e76 | 54 | #include "ctf.h" |
614c279d | 55 | #include "filestuff.h" |
9c3d6531 | 56 | #include "rsp-low.h" |
7951c4eb | 57 | #include "tracefile.h" |
f00aae0f | 58 | #include "location.h" |
325fac50 | 59 | #include <algorithm> |
c906108c SS |
60 | |
61 | /* readline include files */ | |
dbda9972 AC |
62 | #include "readline/readline.h" |
63 | #include "readline/history.h" | |
c906108c SS |
64 | |
65 | /* readline defines this. */ | |
66 | #undef savestring | |
67 | ||
c906108c | 68 | #include <unistd.h> |
c906108c | 69 | |
d183932d MS |
70 | /* Maximum length of an agent aexpression. |
71 | This accounts for the fact that packets are limited to 400 bytes | |
c906108c SS |
72 | (which includes everything -- including the checksum), and assumes |
73 | the worst case of maximum length for each of the pieces of a | |
74 | continuation packet. | |
c5aa993b | 75 | |
c906108c SS |
76 | NOTE: expressions get mem2hex'ed otherwise this would be twice as |
77 | large. (400 - 31)/2 == 184 */ | |
78 | #define MAX_AGENT_EXPR_LEN 184 | |
79 | ||
98c5b216 TT |
80 | /* A hook used to notify the UI of tracepoint operations. */ |
81 | ||
82 | void (*deprecated_trace_find_hook) (char *arg, int from_tty); | |
83 | void (*deprecated_trace_start_stop_hook) (int start, int from_tty); | |
c906108c | 84 | |
c906108c SS |
85 | /* |
86 | Tracepoint.c: | |
87 | ||
88 | This module defines the following debugger commands: | |
89 | trace : set a tracepoint on a function, line, or address. | |
90 | info trace : list all debugger-defined tracepoints. | |
91 | delete trace : delete one or more tracepoints. | |
92 | enable trace : enable one or more tracepoints. | |
93 | disable trace : disable one or more tracepoints. | |
94 | actions : specify actions to be taken at a tracepoint. | |
95 | passcount : specify a pass count for a tracepoint. | |
96 | tstart : start a trace experiment. | |
97 | tstop : stop a trace experiment. | |
98 | tstatus : query the status of a trace experiment. | |
99 | tfind : find a trace frame in the trace buffer. | |
100 | tdump : print everything collected at the current tracepoint. | |
101 | save-tracepoints : write tracepoint setup into a file. | |
102 | ||
103 | This module defines the following user-visible debugger variables: | |
104 | $trace_frame : sequence number of trace frame currently being debugged. | |
105 | $trace_line : source line of trace frame currently being debugged. | |
106 | $trace_file : source file of trace frame currently being debugged. | |
107 | $tracepoint : tracepoint number of trace frame currently being debugged. | |
c5aa993b | 108 | */ |
c906108c SS |
109 | |
110 | ||
111 | /* ======= Important global variables: ======= */ | |
112 | ||
f61e138d SS |
113 | /* The list of all trace state variables. We don't retain pointers to |
114 | any of these for any reason - API is by name or number only - so it | |
115 | works to have a vector of objects. */ | |
116 | ||
117 | typedef struct trace_state_variable tsv_s; | |
118 | DEF_VEC_O(tsv_s); | |
119 | ||
120 | static VEC(tsv_s) *tvariables; | |
121 | ||
122 | /* The next integer to assign to a variable. */ | |
123 | ||
124 | static int next_tsv_number = 1; | |
125 | ||
c906108c SS |
126 | /* Number of last traceframe collected. */ |
127 | static int traceframe_number; | |
128 | ||
129 | /* Tracepoint for last traceframe collected. */ | |
130 | static int tracepoint_number; | |
131 | ||
b3b9301e PA |
132 | /* The traceframe info of the current traceframe. NULL if we haven't |
133 | yet attempted to fetch it, or if the target does not support | |
134 | fetching this object, or if we're not inspecting a traceframe | |
135 | presently. */ | |
8d3c73ef | 136 | static struct traceframe_info *current_traceframe_info; |
b3b9301e | 137 | |
c378eb4e | 138 | /* Tracing command lists. */ |
c906108c SS |
139 | static struct cmd_list_element *tfindlist; |
140 | ||
236f1d4d | 141 | /* List of expressions to collect by default at each tracepoint hit. */ |
bde6261a | 142 | char *default_collect; |
236f1d4d | 143 | |
d5551862 SS |
144 | static int disconnected_tracing; |
145 | ||
4daf5ac0 SS |
146 | /* This variable controls whether we ask the target for a linear or |
147 | circular trace buffer. */ | |
148 | ||
149 | static int circular_trace_buffer; | |
150 | ||
f6f899bf HAQ |
151 | /* This variable is the requested trace buffer size, or -1 to indicate |
152 | that we don't care and leave it up to the target to set a size. */ | |
153 | ||
154 | static int trace_buffer_size = -1; | |
155 | ||
f196051f SS |
156 | /* Textual notes applying to the current and/or future trace runs. */ |
157 | ||
158 | char *trace_user = NULL; | |
159 | ||
160 | /* Textual notes applying to the current and/or future trace runs. */ | |
161 | ||
162 | char *trace_notes = NULL; | |
163 | ||
164 | /* Textual notes applying to the stopping of a trace. */ | |
165 | ||
166 | char *trace_stop_notes = NULL; | |
167 | ||
c906108c | 168 | /* support routines */ |
c906108c SS |
169 | |
170 | struct collection_list; | |
47b667de | 171 | static char *mem2hex (gdb_byte *, char *, int); |
392a587b | 172 | |
3ca73e0c YQ |
173 | static struct command_line * |
174 | all_tracepoint_actions_and_cleanup (struct breakpoint *t); | |
00bf0b85 | 175 | |
00bf0b85 SS |
176 | static struct trace_status trace_status; |
177 | ||
7951c4eb | 178 | const char *stop_reason_names[] = { |
00bf0b85 SS |
179 | "tunknown", |
180 | "tnotrun", | |
181 | "tstop", | |
182 | "tfull", | |
183 | "tdisconnected", | |
6c28cbf2 SS |
184 | "tpasscount", |
185 | "terror" | |
00bf0b85 SS |
186 | }; |
187 | ||
188 | struct trace_status * | |
eeae04df | 189 | current_trace_status (void) |
00bf0b85 SS |
190 | { |
191 | return &trace_status; | |
192 | } | |
193 | ||
b3b9301e PA |
194 | /* Destroy INFO. */ |
195 | ||
196 | static void | |
197 | free_traceframe_info (struct traceframe_info *info) | |
198 | { | |
4cdd21a8 | 199 | delete info; |
b3b9301e PA |
200 | } |
201 | ||
7a9dd1b2 | 202 | /* Free and clear the traceframe info cache of the current |
b3b9301e PA |
203 | traceframe. */ |
204 | ||
205 | static void | |
206 | clear_traceframe_info (void) | |
207 | { | |
8d3c73ef SM |
208 | free_traceframe_info (current_traceframe_info); |
209 | current_traceframe_info = NULL; | |
b3b9301e PA |
210 | } |
211 | ||
c906108c SS |
212 | /* Set traceframe number to NUM. */ |
213 | static void | |
fba45db2 | 214 | set_traceframe_num (int num) |
c906108c SS |
215 | { |
216 | traceframe_number = num; | |
4fa62494 | 217 | set_internalvar_integer (lookup_internalvar ("trace_frame"), num); |
c906108c SS |
218 | } |
219 | ||
220 | /* Set tracepoint number to NUM. */ | |
221 | static void | |
fba45db2 | 222 | set_tracepoint_num (int num) |
c906108c SS |
223 | { |
224 | tracepoint_number = num; | |
4fa62494 | 225 | set_internalvar_integer (lookup_internalvar ("tracepoint"), num); |
c906108c SS |
226 | } |
227 | ||
228 | /* Set externally visible debug variables for querying/printing | |
c378eb4e | 229 | the traceframe context (line, function, file). */ |
c906108c SS |
230 | |
231 | static void | |
fb14de7b | 232 | set_traceframe_context (struct frame_info *trace_frame) |
c906108c | 233 | { |
fb14de7b | 234 | CORE_ADDR trace_pc; |
24a00813 | 235 | struct symbol *traceframe_fun; |
51abb421 | 236 | symtab_and_line traceframe_sal; |
fb14de7b | 237 | |
dba09041 PA |
238 | /* Save as globals for internal use. */ |
239 | if (trace_frame != NULL | |
240 | && get_frame_pc_if_available (trace_frame, &trace_pc)) | |
241 | { | |
242 | traceframe_sal = find_pc_line (trace_pc, 0); | |
243 | traceframe_fun = find_pc_function (trace_pc); | |
244 | ||
245 | /* Save linenumber as "$trace_line", a debugger variable visible to | |
246 | users. */ | |
247 | set_internalvar_integer (lookup_internalvar ("trace_line"), | |
248 | traceframe_sal.line); | |
249 | } | |
250 | else | |
c906108c | 251 | { |
dba09041 | 252 | traceframe_fun = NULL; |
4fa62494 | 253 | set_internalvar_integer (lookup_internalvar ("trace_line"), -1); |
c906108c SS |
254 | } |
255 | ||
d183932d MS |
256 | /* Save func name as "$trace_func", a debugger variable visible to |
257 | users. */ | |
4fa62494 UW |
258 | if (traceframe_fun == NULL |
259 | || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL) | |
260 | clear_internalvar (lookup_internalvar ("trace_func")); | |
c906108c | 261 | else |
78267919 UW |
262 | set_internalvar_string (lookup_internalvar ("trace_func"), |
263 | SYMBOL_LINKAGE_NAME (traceframe_fun)); | |
c906108c | 264 | |
d183932d MS |
265 | /* Save file name as "$trace_file", a debugger variable visible to |
266 | users. */ | |
4e04028d | 267 | if (traceframe_sal.symtab == NULL) |
4fa62494 | 268 | clear_internalvar (lookup_internalvar ("trace_file")); |
c906108c | 269 | else |
78267919 | 270 | set_internalvar_string (lookup_internalvar ("trace_file"), |
05cba821 | 271 | symtab_to_filename_for_display (traceframe_sal.symtab)); |
c906108c SS |
272 | } |
273 | ||
f61e138d SS |
274 | /* Create a new trace state variable with the given name. */ |
275 | ||
276 | struct trace_state_variable * | |
277 | create_trace_state_variable (const char *name) | |
278 | { | |
279 | struct trace_state_variable tsv; | |
280 | ||
281 | memset (&tsv, 0, sizeof (tsv)); | |
40e1c229 | 282 | tsv.name = xstrdup (name); |
f61e138d SS |
283 | tsv.number = next_tsv_number++; |
284 | return VEC_safe_push (tsv_s, tvariables, &tsv); | |
285 | } | |
286 | ||
287 | /* Look for a trace state variable of the given name. */ | |
288 | ||
289 | struct trace_state_variable * | |
290 | find_trace_state_variable (const char *name) | |
291 | { | |
292 | struct trace_state_variable *tsv; | |
293 | int ix; | |
294 | ||
295 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
296 | if (strcmp (name, tsv->name) == 0) | |
297 | return tsv; | |
298 | ||
299 | return NULL; | |
300 | } | |
301 | ||
dc673c81 YQ |
302 | /* Look for a trace state variable of the given number. Return NULL if |
303 | not found. */ | |
304 | ||
305 | struct trace_state_variable * | |
306 | find_trace_state_variable_by_number (int number) | |
307 | { | |
308 | struct trace_state_variable *tsv; | |
309 | int ix; | |
310 | ||
311 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
312 | if (tsv->number == number) | |
313 | return tsv; | |
314 | ||
315 | return NULL; | |
316 | } | |
317 | ||
70221824 | 318 | static void |
f61e138d SS |
319 | delete_trace_state_variable (const char *name) |
320 | { | |
321 | struct trace_state_variable *tsv; | |
322 | int ix; | |
323 | ||
324 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
325 | if (strcmp (name, tsv->name) == 0) | |
326 | { | |
134a2066 YQ |
327 | observer_notify_tsv_deleted (tsv); |
328 | ||
40e1c229 | 329 | xfree ((void *)tsv->name); |
f61e138d | 330 | VEC_unordered_remove (tsv_s, tvariables, ix); |
bb25a15c | 331 | |
f61e138d SS |
332 | return; |
333 | } | |
334 | ||
335 | warning (_("No trace variable named \"$%s\", not deleting"), name); | |
336 | } | |
337 | ||
1773c82c HAQ |
338 | /* Throws an error if NAME is not valid syntax for a trace state |
339 | variable's name. */ | |
340 | ||
341 | void | |
342 | validate_trace_state_variable_name (const char *name) | |
343 | { | |
344 | const char *p; | |
345 | ||
346 | if (*name == '\0') | |
347 | error (_("Must supply a non-empty variable name")); | |
348 | ||
349 | /* All digits in the name is reserved for value history | |
350 | references. */ | |
351 | for (p = name; isdigit (*p); p++) | |
352 | ; | |
353 | if (*p == '\0') | |
354 | error (_("$%s is not a valid trace state variable name"), name); | |
355 | ||
356 | for (p = name; isalnum (*p) || *p == '_'; p++) | |
357 | ; | |
358 | if (*p != '\0') | |
359 | error (_("$%s is not a valid trace state variable name"), name); | |
360 | } | |
361 | ||
f61e138d SS |
362 | /* The 'tvariable' command collects a name and optional expression to |
363 | evaluate into an initial value. */ | |
364 | ||
70221824 | 365 | static void |
f61e138d SS |
366 | trace_variable_command (char *args, int from_tty) |
367 | { | |
f61e138d SS |
368 | LONGEST initval = 0; |
369 | struct trace_state_variable *tsv; | |
8abcee91 | 370 | char *name_start, *p; |
f61e138d SS |
371 | |
372 | if (!args || !*args) | |
1773c82c HAQ |
373 | error_no_arg (_("Syntax is $NAME [ = EXPR ]")); |
374 | ||
375 | /* Only allow two syntaxes; "$name" and "$name=value". */ | |
376 | p = skip_spaces (args); | |
f61e138d | 377 | |
1773c82c HAQ |
378 | if (*p++ != '$') |
379 | error (_("Name of trace variable should start with '$'")); | |
f61e138d | 380 | |
8abcee91 | 381 | name_start = p; |
1773c82c HAQ |
382 | while (isalnum (*p) || *p == '_') |
383 | p++; | |
8abcee91 | 384 | std::string name (name_start, p - name_start); |
f61e138d | 385 | |
1773c82c HAQ |
386 | p = skip_spaces (p); |
387 | if (*p != '=' && *p != '\0') | |
f61e138d SS |
388 | error (_("Syntax must be $NAME [ = EXPR ]")); |
389 | ||
8abcee91 | 390 | validate_trace_state_variable_name (name.c_str ()); |
f61e138d | 391 | |
1773c82c HAQ |
392 | if (*p == '=') |
393 | initval = value_as_long (parse_and_eval (++p)); | |
f61e138d SS |
394 | |
395 | /* If the variable already exists, just change its initial value. */ | |
8abcee91 | 396 | tsv = find_trace_state_variable (name.c_str ()); |
f61e138d SS |
397 | if (tsv) |
398 | { | |
134a2066 YQ |
399 | if (tsv->initial_value != initval) |
400 | { | |
401 | tsv->initial_value = initval; | |
402 | observer_notify_tsv_modified (tsv); | |
403 | } | |
3e43a32a MS |
404 | printf_filtered (_("Trace state variable $%s " |
405 | "now has initial value %s.\n"), | |
f61e138d SS |
406 | tsv->name, plongest (tsv->initial_value)); |
407 | return; | |
408 | } | |
409 | ||
410 | /* Create a new variable. */ | |
8abcee91 | 411 | tsv = create_trace_state_variable (name.c_str ()); |
f61e138d SS |
412 | tsv->initial_value = initval; |
413 | ||
134a2066 | 414 | observer_notify_tsv_created (tsv); |
bb25a15c | 415 | |
3e43a32a MS |
416 | printf_filtered (_("Trace state variable $%s " |
417 | "created, with initial value %s.\n"), | |
f61e138d | 418 | tsv->name, plongest (tsv->initial_value)); |
f61e138d SS |
419 | } |
420 | ||
70221824 | 421 | static void |
2983f7cb | 422 | delete_trace_variable_command (const char *args, int from_tty) |
f61e138d | 423 | { |
f61e138d SS |
424 | if (args == NULL) |
425 | { | |
426 | if (query (_("Delete all trace state variables? "))) | |
427 | VEC_free (tsv_s, tvariables); | |
428 | dont_repeat (); | |
bb25a15c | 429 | observer_notify_tsv_deleted (NULL); |
f61e138d SS |
430 | return; |
431 | } | |
432 | ||
773a1edc | 433 | gdb_argv argv (args); |
f61e138d | 434 | |
773a1edc | 435 | for (char *arg : argv) |
f61e138d | 436 | { |
773a1edc TT |
437 | if (*arg == '$') |
438 | delete_trace_state_variable (arg + 1); | |
f61e138d | 439 | else |
773a1edc | 440 | warning (_("Name \"%s\" not prefixed with '$', ignoring"), arg); |
f61e138d SS |
441 | } |
442 | ||
f61e138d SS |
443 | dont_repeat (); |
444 | } | |
445 | ||
40e1c229 VP |
446 | void |
447 | tvariables_info_1 (void) | |
f61e138d SS |
448 | { |
449 | struct trace_state_variable *tsv; | |
450 | int ix; | |
40e1c229 | 451 | int count = 0; |
79a45e25 | 452 | struct ui_out *uiout = current_uiout; |
f61e138d | 453 | |
112e8700 | 454 | if (VEC_length (tsv_s, tvariables) == 0 && !uiout->is_mi_like_p ()) |
f61e138d SS |
455 | { |
456 | printf_filtered (_("No trace state variables.\n")); | |
457 | return; | |
458 | } | |
459 | ||
35b1e5cc | 460 | /* Try to acquire values from the target. */ |
4baf5cf4 | 461 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix, ++count) |
35b1e5cc SS |
462 | tsv->value_known = target_get_trace_state_variable_value (tsv->number, |
463 | &(tsv->value)); | |
464 | ||
4a2b031d | 465 | ui_out_emit_table table_emitter (uiout, 3, count, "trace-variables"); |
112e8700 SM |
466 | uiout->table_header (15, ui_left, "name", "Name"); |
467 | uiout->table_header (11, ui_left, "initial", "Initial"); | |
468 | uiout->table_header (11, ui_left, "current", "Current"); | |
40e1c229 | 469 | |
112e8700 | 470 | uiout->table_body (); |
f61e138d SS |
471 | |
472 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
473 | { | |
a121b7c1 | 474 | const char *c; |
40e1c229 | 475 | |
a14a62dd | 476 | ui_out_emit_tuple tuple_emitter (uiout, "variable"); |
40e1c229 | 477 | |
a14a62dd TT |
478 | std::string name = std::string ("$") + tsv->name; |
479 | uiout->field_string ("name", name.c_str ()); | |
112e8700 | 480 | uiout->field_string ("initial", plongest (tsv->initial_value)); |
40e1c229 | 481 | |
f61e138d | 482 | if (tsv->value_known) |
40e1c229 | 483 | c = plongest (tsv->value); |
112e8700 | 484 | else if (uiout->is_mi_like_p ()) |
40e1c229 VP |
485 | /* For MI, we prefer not to use magic string constants, but rather |
486 | omit the field completely. The difference between unknown and | |
487 | undefined does not seem important enough to represent. */ | |
488 | c = NULL; | |
00bf0b85 | 489 | else if (current_trace_status ()->running || traceframe_number >= 0) |
f61e138d | 490 | /* The value is/was defined, but we don't have it. */ |
40e1c229 | 491 | c = "<unknown>"; |
f61e138d SS |
492 | else |
493 | /* It is not meaningful to ask about the value. */ | |
40e1c229 VP |
494 | c = "<undefined>"; |
495 | if (c) | |
112e8700 SM |
496 | uiout->field_string ("current", c); |
497 | uiout->text ("\n"); | |
f61e138d | 498 | } |
40e1c229 VP |
499 | } |
500 | ||
501 | /* List all the trace state variables. */ | |
502 | ||
503 | static void | |
11db9430 | 504 | info_tvariables_command (char *args, int from_tty) |
40e1c229 VP |
505 | { |
506 | tvariables_info_1 (); | |
f61e138d SS |
507 | } |
508 | ||
8bf6485c SS |
509 | /* Stash definitions of tsvs into the given file. */ |
510 | ||
511 | void | |
512 | save_trace_state_variables (struct ui_file *fp) | |
513 | { | |
514 | struct trace_state_variable *tsv; | |
515 | int ix; | |
516 | ||
517 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
518 | { | |
519 | fprintf_unfiltered (fp, "tvariable $%s", tsv->name); | |
520 | if (tsv->initial_value) | |
521 | fprintf_unfiltered (fp, " = %s", plongest (tsv->initial_value)); | |
522 | fprintf_unfiltered (fp, "\n"); | |
523 | } | |
524 | } | |
525 | ||
c906108c SS |
526 | /* ACTIONS functions: */ |
527 | ||
c906108c | 528 | /* The three functions: |
c5aa993b JM |
529 | collect_pseudocommand, |
530 | while_stepping_pseudocommand, and | |
531 | end_actions_pseudocommand | |
c906108c SS |
532 | are placeholders for "commands" that are actually ONLY to be used |
533 | within a tracepoint action list. If the actual function is ever called, | |
534 | it means that somebody issued the "command" at the top level, | |
535 | which is always an error. */ | |
536 | ||
7b3ae3a6 | 537 | static void |
fba45db2 | 538 | end_actions_pseudocommand (char *args, int from_tty) |
c906108c | 539 | { |
8a3fe4f8 | 540 | error (_("This command cannot be used at the top level.")); |
c906108c SS |
541 | } |
542 | ||
7b3ae3a6 | 543 | static void |
fba45db2 | 544 | while_stepping_pseudocommand (char *args, int from_tty) |
c906108c | 545 | { |
8a3fe4f8 | 546 | error (_("This command can only be used in a tracepoint actions list.")); |
c906108c SS |
547 | } |
548 | ||
549 | static void | |
fba45db2 | 550 | collect_pseudocommand (char *args, int from_tty) |
c906108c | 551 | { |
8a3fe4f8 | 552 | error (_("This command can only be used in a tracepoint actions list.")); |
c906108c SS |
553 | } |
554 | ||
6da95a67 SS |
555 | static void |
556 | teval_pseudocommand (char *args, int from_tty) | |
557 | { | |
558 | error (_("This command can only be used in a tracepoint actions list.")); | |
559 | } | |
560 | ||
3065dfb6 SS |
561 | /* Parse any collection options, such as /s for strings. */ |
562 | ||
6f937416 | 563 | const char * |
92bc6a20 | 564 | decode_agent_options (const char *exp, int *trace_string) |
3065dfb6 SS |
565 | { |
566 | struct value_print_options opts; | |
567 | ||
92bc6a20 TT |
568 | *trace_string = 0; |
569 | ||
3065dfb6 SS |
570 | if (*exp != '/') |
571 | return exp; | |
572 | ||
573 | /* Call this to borrow the print elements default for collection | |
574 | size. */ | |
575 | get_user_print_options (&opts); | |
576 | ||
577 | exp++; | |
578 | if (*exp == 's') | |
579 | { | |
580 | if (target_supports_string_tracing ()) | |
581 | { | |
582 | /* Allow an optional decimal number giving an explicit maximum | |
583 | string length, defaulting it to the "print elements" value; | |
584 | so "collect/s80 mystr" gets at most 80 bytes of string. */ | |
92bc6a20 | 585 | *trace_string = opts.print_max; |
3065dfb6 SS |
586 | exp++; |
587 | if (*exp >= '0' && *exp <= '9') | |
92bc6a20 | 588 | *trace_string = atoi (exp); |
3065dfb6 SS |
589 | while (*exp >= '0' && *exp <= '9') |
590 | exp++; | |
591 | } | |
592 | else | |
593 | error (_("Target does not support \"/s\" option for string tracing.")); | |
594 | } | |
595 | else | |
596 | error (_("Undefined collection format \"%c\"."), *exp); | |
597 | ||
f1735a53 | 598 | exp = skip_spaces (exp); |
3065dfb6 SS |
599 | |
600 | return exp; | |
601 | } | |
602 | ||
c906108c SS |
603 | /* Enter a list of actions for a tracepoint. */ |
604 | static void | |
e5a873b7 | 605 | actions_command (char *args, int from_tty) |
c906108c | 606 | { |
d9b3f62e | 607 | struct tracepoint *t; |
c906108c | 608 | |
5fa1d40e | 609 | t = get_tracepoint_by_number (&args, NULL); |
7a292a7a | 610 | if (t) |
c906108c | 611 | { |
93921405 TT |
612 | std::string tmpbuf = |
613 | string_printf ("Enter actions for tracepoint %d, one per line.", | |
c1fc2657 | 614 | t->number); |
93921405 TT |
615 | |
616 | command_line_up l = read_command_lines (&tmpbuf[0], from_tty, 1, | |
617 | check_tracepoint_command, t); | |
c1fc2657 | 618 | breakpoint_set_commands (t, std::move (l)); |
c906108c | 619 | } |
5c44784c | 620 | /* else just return */ |
c906108c SS |
621 | } |
622 | ||
fff87407 SS |
623 | /* Report the results of checking the agent expression, as errors or |
624 | internal errors. */ | |
625 | ||
626 | static void | |
35c9c7ba | 627 | report_agent_reqs_errors (struct agent_expr *aexpr) |
fff87407 SS |
628 | { |
629 | /* All of the "flaws" are serious bytecode generation issues that | |
630 | should never occur. */ | |
35c9c7ba | 631 | if (aexpr->flaw != agent_flaw_none) |
fff87407 SS |
632 | internal_error (__FILE__, __LINE__, _("expression is malformed")); |
633 | ||
634 | /* If analysis shows a stack underflow, GDB must have done something | |
635 | badly wrong in its bytecode generation. */ | |
35c9c7ba | 636 | if (aexpr->min_height < 0) |
fff87407 SS |
637 | internal_error (__FILE__, __LINE__, |
638 | _("expression has min height < 0")); | |
639 | ||
640 | /* Issue this error if the stack is predicted to get too deep. The | |
641 | limit is rather arbitrary; a better scheme might be for the | |
642 | target to report how much stack it will have available. The | |
643 | depth roughly corresponds to parenthesization, so a limit of 20 | |
644 | amounts to 20 levels of expression nesting, which is actually | |
645 | a pretty big hairy expression. */ | |
35c9c7ba | 646 | if (aexpr->max_height > 20) |
fff87407 SS |
647 | error (_("Expression is too complicated.")); |
648 | } | |
649 | ||
c906108c | 650 | /* worker function */ |
fff87407 | 651 | void |
6f937416 | 652 | validate_actionline (const char *line, struct breakpoint *b) |
c906108c SS |
653 | { |
654 | struct cmd_list_element *c; | |
6f937416 PA |
655 | const char *tmp_p; |
656 | const char *p; | |
9355b391 | 657 | struct bp_location *loc; |
d9b3f62e | 658 | struct tracepoint *t = (struct tracepoint *) b; |
c906108c | 659 | |
c378eb4e | 660 | /* If EOF is typed, *line is NULL. */ |
6f937416 | 661 | if (line == NULL) |
fff87407 | 662 | return; |
15255275 | 663 | |
f1735a53 | 664 | p = skip_spaces (line); |
c906108c | 665 | |
d183932d MS |
666 | /* Symbol lookup etc. */ |
667 | if (*p == '\0') /* empty line: just prompt for another line. */ | |
fff87407 | 668 | return; |
c906108c | 669 | |
c5aa993b | 670 | if (*p == '#') /* comment line */ |
fff87407 | 671 | return; |
c906108c SS |
672 | |
673 | c = lookup_cmd (&p, cmdlist, "", -1, 1); | |
674 | if (c == 0) | |
fff87407 | 675 | error (_("`%s' is not a tracepoint action, or is ambiguous."), p); |
c5aa993b | 676 | |
bbaca940 | 677 | if (cmd_cfunc_eq (c, collect_pseudocommand)) |
c906108c | 678 | { |
92bc6a20 TT |
679 | int trace_string = 0; |
680 | ||
3065dfb6 | 681 | if (*p == '/') |
92bc6a20 | 682 | p = decode_agent_options (p, &trace_string); |
3065dfb6 | 683 | |
c5aa993b | 684 | do |
c378eb4e MS |
685 | { /* Repeat over a comma-separated list. */ |
686 | QUIT; /* Allow user to bail out with ^C. */ | |
f1735a53 | 687 | p = skip_spaces (p); |
c906108c | 688 | |
c378eb4e | 689 | if (*p == '$') /* Look for special pseudo-symbols. */ |
c5aa993b | 690 | { |
0fb4aa4b PA |
691 | if (0 == strncasecmp ("reg", p + 1, 3) |
692 | || 0 == strncasecmp ("arg", p + 1, 3) | |
693 | || 0 == strncasecmp ("loc", p + 1, 3) | |
6710bf39 | 694 | || 0 == strncasecmp ("_ret", p + 1, 4) |
0fb4aa4b | 695 | || 0 == strncasecmp ("_sdata", p + 1, 6)) |
c5aa993b JM |
696 | { |
697 | p = strchr (p, ','); | |
698 | continue; | |
699 | } | |
d183932d | 700 | /* else fall thru, treat p as an expression and parse it! */ |
c5aa993b | 701 | } |
9355b391 | 702 | tmp_p = p; |
c1fc2657 | 703 | for (loc = t->loc; loc; loc = loc->next) |
c5aa993b | 704 | { |
6f937416 | 705 | p = tmp_p; |
4d01a485 PA |
706 | expression_up exp = parse_exp_1 (&p, loc->address, |
707 | block_for_pc (loc->address), 1); | |
9355b391 SS |
708 | |
709 | if (exp->elts[0].opcode == OP_VAR_VALUE) | |
c5aa993b | 710 | { |
9355b391 SS |
711 | if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST) |
712 | { | |
12df843f | 713 | error (_("constant `%s' (value %s) " |
3e43a32a | 714 | "will not be collected."), |
fff87407 | 715 | SYMBOL_PRINT_NAME (exp->elts[2].symbol), |
12df843f | 716 | plongest (SYMBOL_VALUE (exp->elts[2].symbol))); |
9355b391 | 717 | } |
3e43a32a MS |
718 | else if (SYMBOL_CLASS (exp->elts[2].symbol) |
719 | == LOC_OPTIMIZED_OUT) | |
9355b391 | 720 | { |
3e43a32a MS |
721 | error (_("`%s' is optimized away " |
722 | "and cannot be collected."), | |
fff87407 | 723 | SYMBOL_PRINT_NAME (exp->elts[2].symbol)); |
9355b391 | 724 | } |
c5aa993b | 725 | } |
c906108c | 726 | |
9355b391 SS |
727 | /* We have something to collect, make sure that the expr to |
728 | bytecode translator can handle it and that it's not too | |
729 | long. */ | |
833177a4 PA |
730 | agent_expr_up aexpr = gen_trace_for_expr (loc->address, |
731 | exp.get (), | |
732 | trace_string); | |
c906108c | 733 | |
9355b391 | 734 | if (aexpr->len > MAX_AGENT_EXPR_LEN) |
fff87407 | 735 | error (_("Expression is too complicated.")); |
c906108c | 736 | |
833177a4 | 737 | ax_reqs (aexpr.get ()); |
c906108c | 738 | |
833177a4 | 739 | report_agent_reqs_errors (aexpr.get ()); |
9355b391 | 740 | } |
c5aa993b JM |
741 | } |
742 | while (p && *p++ == ','); | |
c906108c | 743 | } |
fff87407 | 744 | |
6da95a67 SS |
745 | else if (cmd_cfunc_eq (c, teval_pseudocommand)) |
746 | { | |
6da95a67 | 747 | do |
c378eb4e MS |
748 | { /* Repeat over a comma-separated list. */ |
749 | QUIT; /* Allow user to bail out with ^C. */ | |
f1735a53 | 750 | p = skip_spaces (p); |
6da95a67 | 751 | |
9355b391 | 752 | tmp_p = p; |
c1fc2657 | 753 | for (loc = t->loc; loc; loc = loc->next) |
9355b391 | 754 | { |
6f937416 | 755 | p = tmp_p; |
bbc13ae3 | 756 | |
9355b391 | 757 | /* Only expressions are allowed for this action. */ |
4d01a485 PA |
758 | expression_up exp = parse_exp_1 (&p, loc->address, |
759 | block_for_pc (loc->address), 1); | |
6da95a67 | 760 | |
9355b391 SS |
761 | /* We have something to evaluate, make sure that the expr to |
762 | bytecode translator can handle it and that it's not too | |
763 | long. */ | |
833177a4 | 764 | agent_expr_up aexpr = gen_eval_for_expr (loc->address, exp.get ()); |
6da95a67 | 765 | |
9355b391 | 766 | if (aexpr->len > MAX_AGENT_EXPR_LEN) |
fff87407 SS |
767 | error (_("Expression is too complicated.")); |
768 | ||
833177a4 PA |
769 | ax_reqs (aexpr.get ()); |
770 | report_agent_reqs_errors (aexpr.get ()); | |
9355b391 | 771 | } |
6da95a67 SS |
772 | } |
773 | while (p && *p++ == ','); | |
6da95a67 | 774 | } |
fff87407 | 775 | |
bbaca940 | 776 | else if (cmd_cfunc_eq (c, while_stepping_pseudocommand)) |
c906108c | 777 | { |
6f937416 | 778 | char *endp; |
c906108c | 779 | |
f1735a53 | 780 | p = skip_spaces (p); |
6f937416 PA |
781 | t->step_count = strtol (p, &endp, 0); |
782 | if (endp == p || t->step_count == 0) | |
783 | error (_("while-stepping step count `%s' is malformed."), line); | |
784 | p = endp; | |
c906108c | 785 | } |
fff87407 | 786 | |
bbaca940 | 787 | else if (cmd_cfunc_eq (c, end_actions_pseudocommand)) |
fff87407 SS |
788 | ; |
789 | ||
c906108c | 790 | else |
6f937416 | 791 | error (_("`%s' is not a supported tracepoint action."), line); |
74b7792f AC |
792 | } |
793 | ||
f50e79a4 JB |
794 | enum { |
795 | memrange_absolute = -1 | |
796 | }; | |
797 | ||
c906108c SS |
798 | /* MEMRANGE functions: */ |
799 | ||
1f45808e | 800 | /* Compare memranges for std::sort. */ |
c906108c | 801 | |
1f45808e PA |
802 | static bool |
803 | memrange_comp (const memrange &a, const memrange &b) | |
c906108c | 804 | { |
1f45808e | 805 | if (a.type == b.type) |
c906108c | 806 | { |
1f45808e PA |
807 | if (a.type == memrange_absolute) |
808 | return (bfd_vma) a.start < (bfd_vma) b.start; | |
809 | else | |
810 | return a.start < b.start; | |
c906108c | 811 | } |
1f45808e PA |
812 | |
813 | return a.type < b.type; | |
c906108c SS |
814 | } |
815 | ||
1f45808e PA |
816 | /* Sort the memrange list using std::sort, and merge adjacent memranges. */ |
817 | ||
c906108c | 818 | static void |
1f45808e | 819 | memrange_sortmerge (std::vector<memrange> &memranges) |
c906108c | 820 | { |
1f45808e | 821 | if (!memranges.empty ()) |
c906108c | 822 | { |
1f45808e PA |
823 | int a, b; |
824 | ||
825 | std::sort (memranges.begin (), memranges.end (), memrange_comp); | |
826 | ||
827 | for (a = 0, b = 1; b < memranges.size (); b++) | |
c906108c | 828 | { |
1b28d0b3 PA |
829 | /* If memrange b overlaps or is adjacent to memrange a, |
830 | merge them. */ | |
1f45808e PA |
831 | if (memranges[a].type == memranges[b].type |
832 | && memranges[b].start <= memranges[a].end) | |
c906108c | 833 | { |
1f45808e PA |
834 | if (memranges[b].end > memranges[a].end) |
835 | memranges[a].end = memranges[b].end; | |
c906108c SS |
836 | continue; /* next b, same a */ |
837 | } | |
838 | a++; /* next a */ | |
839 | if (a != b) | |
1f45808e | 840 | memranges[a] = memranges[b]; |
c906108c | 841 | } |
1f45808e | 842 | memranges.resize (a + 1); |
c906108c SS |
843 | } |
844 | } | |
845 | ||
d183932d | 846 | /* Add a register to a collection list. */ |
1f45808e PA |
847 | |
848 | void | |
849 | collection_list::add_register (unsigned int regno) | |
c906108c SS |
850 | { |
851 | if (info_verbose) | |
852 | printf_filtered ("collect register %d\n", regno); | |
1f45808e | 853 | if (regno >= (8 * sizeof (m_regs_mask))) |
8a3fe4f8 | 854 | error (_("Internal: register number %d too large for tracepoint"), |
c906108c | 855 | regno); |
1f45808e | 856 | m_regs_mask[regno / 8] |= 1 << (regno % 8); |
c906108c SS |
857 | } |
858 | ||
c378eb4e | 859 | /* Add a memrange to a collection list. */ |
1f45808e PA |
860 | |
861 | void | |
19f1935d PA |
862 | collection_list::add_memrange (struct gdbarch *gdbarch, |
863 | int type, bfd_signed_vma base, | |
1f45808e | 864 | unsigned long len) |
c906108c SS |
865 | { |
866 | if (info_verbose) | |
19f1935d | 867 | printf_filtered ("(%d,%s,%ld)\n", type, paddress (gdbarch, base), len); |
104c1213 | 868 | |
f50e79a4 | 869 | /* type: memrange_absolute == memory, other n == basereg */ |
d183932d | 870 | /* base: addr if memory, offset if reg relative. */ |
c906108c | 871 | /* len: we actually save end (base + len) for convenience */ |
7a63494a | 872 | m_memranges.emplace_back (type, base, base + len); |
c906108c | 873 | |
3e43a32a | 874 | if (type != memrange_absolute) /* Better collect the base register! */ |
1f45808e | 875 | add_register (type); |
c906108c SS |
876 | } |
877 | ||
d183932d | 878 | /* Add a symbol to a collection list. */ |
1f45808e PA |
879 | |
880 | void | |
881 | collection_list::collect_symbol (struct symbol *sym, | |
882 | struct gdbarch *gdbarch, | |
883 | long frame_regno, long frame_offset, | |
884 | CORE_ADDR scope, | |
885 | int trace_string) | |
c906108c | 886 | { |
c5aa993b | 887 | unsigned long len; |
104c1213 | 888 | unsigned int reg; |
c906108c | 889 | bfd_signed_vma offset; |
400c6af0 | 890 | int treat_as_expr = 0; |
c906108c | 891 | |
c5aa993b JM |
892 | len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))); |
893 | switch (SYMBOL_CLASS (sym)) | |
894 | { | |
895 | default: | |
896 | printf_filtered ("%s: don't know symbol class %d\n", | |
3567439c | 897 | SYMBOL_PRINT_NAME (sym), |
d183932d | 898 | SYMBOL_CLASS (sym)); |
c5aa993b JM |
899 | break; |
900 | case LOC_CONST: | |
12df843f JK |
901 | printf_filtered ("constant %s (value %s) will not be collected.\n", |
902 | SYMBOL_PRINT_NAME (sym), plongest (SYMBOL_VALUE (sym))); | |
c5aa993b JM |
903 | break; |
904 | case LOC_STATIC: | |
905 | offset = SYMBOL_VALUE_ADDRESS (sym); | |
906 | if (info_verbose) | |
104c1213 | 907 | { |
104c1213 | 908 | printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n", |
3567439c | 909 | SYMBOL_PRINT_NAME (sym), len, |
19f1935d | 910 | paddress (gdbarch, offset)); |
104c1213 | 911 | } |
400c6af0 SS |
912 | /* A struct may be a C++ class with static fields, go to general |
913 | expression handling. */ | |
914 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT) | |
915 | treat_as_expr = 1; | |
916 | else | |
19f1935d | 917 | add_memrange (gdbarch, memrange_absolute, offset, len); |
c5aa993b JM |
918 | break; |
919 | case LOC_REGISTER: | |
a6d9a66e | 920 | reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); |
c5aa993b | 921 | if (info_verbose) |
d183932d | 922 | printf_filtered ("LOC_REG[parm] %s: ", |
3567439c | 923 | SYMBOL_PRINT_NAME (sym)); |
1f45808e | 924 | add_register (reg); |
d183932d MS |
925 | /* Check for doubles stored in two registers. */ |
926 | /* FIXME: how about larger types stored in 3 or more regs? */ | |
c5aa993b | 927 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT && |
a6d9a66e | 928 | len > register_size (gdbarch, reg)) |
1f45808e | 929 | add_register (reg + 1); |
c5aa993b JM |
930 | break; |
931 | case LOC_REF_ARG: | |
932 | printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n"); | |
933 | printf_filtered (" (will not collect %s)\n", | |
3567439c | 934 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b JM |
935 | break; |
936 | case LOC_ARG: | |
937 | reg = frame_regno; | |
938 | offset = frame_offset + SYMBOL_VALUE (sym); | |
939 | if (info_verbose) | |
940 | { | |
19f1935d PA |
941 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s" |
942 | " from frame ptr reg %d\n", | |
943 | SYMBOL_PRINT_NAME (sym), len, | |
944 | paddress (gdbarch, offset), reg); | |
c5aa993b | 945 | } |
19f1935d | 946 | add_memrange (gdbarch, reg, offset, len); |
c5aa993b JM |
947 | break; |
948 | case LOC_REGPARM_ADDR: | |
949 | reg = SYMBOL_VALUE (sym); | |
950 | offset = 0; | |
951 | if (info_verbose) | |
952 | { | |
19f1935d PA |
953 | printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset %s" |
954 | " from reg %d\n", | |
955 | SYMBOL_PRINT_NAME (sym), len, | |
956 | paddress (gdbarch, offset), reg); | |
c5aa993b | 957 | } |
19f1935d | 958 | add_memrange (gdbarch, reg, offset, len); |
c5aa993b JM |
959 | break; |
960 | case LOC_LOCAL: | |
c5aa993b JM |
961 | reg = frame_regno; |
962 | offset = frame_offset + SYMBOL_VALUE (sym); | |
963 | if (info_verbose) | |
964 | { | |
19f1935d PA |
965 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s" |
966 | " from frame ptr reg %d\n", | |
967 | SYMBOL_PRINT_NAME (sym), len, | |
968 | paddress (gdbarch, offset), reg); | |
c5aa993b | 969 | } |
19f1935d | 970 | add_memrange (gdbarch, reg, offset, len); |
c5aa993b | 971 | break; |
a0405854 | 972 | |
c5aa993b | 973 | case LOC_UNRESOLVED: |
a0405854 | 974 | treat_as_expr = 1; |
c5aa993b | 975 | break; |
a0405854 | 976 | |
c5aa993b | 977 | case LOC_OPTIMIZED_OUT: |
8e1a459b | 978 | printf_filtered ("%s has been optimized out of existence.\n", |
3567439c | 979 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b | 980 | break; |
0936ad1d SS |
981 | |
982 | case LOC_COMPUTED: | |
400c6af0 | 983 | treat_as_expr = 1; |
0936ad1d | 984 | break; |
c5aa993b | 985 | } |
400c6af0 SS |
986 | |
987 | /* Expressions are the most general case. */ | |
988 | if (treat_as_expr) | |
989 | { | |
833177a4 PA |
990 | agent_expr_up aexpr = gen_trace_for_var (scope, gdbarch, |
991 | sym, trace_string); | |
400c6af0 SS |
992 | |
993 | /* It can happen that the symbol is recorded as a computed | |
994 | location, but it's been optimized away and doesn't actually | |
995 | have a location expression. */ | |
996 | if (!aexpr) | |
997 | { | |
998 | printf_filtered ("%s has been optimized out of existence.\n", | |
999 | SYMBOL_PRINT_NAME (sym)); | |
1000 | return; | |
1001 | } | |
1002 | ||
833177a4 | 1003 | ax_reqs (aexpr.get ()); |
fff87407 | 1004 | |
833177a4 | 1005 | report_agent_reqs_errors (aexpr.get ()); |
400c6af0 | 1006 | |
c378eb4e | 1007 | /* Take care of the registers. */ |
35c9c7ba | 1008 | if (aexpr->reg_mask_len > 0) |
400c6af0 | 1009 | { |
833177a4 | 1010 | for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) |
400c6af0 | 1011 | { |
c378eb4e | 1012 | QUIT; /* Allow user to bail out with ^C. */ |
35c9c7ba | 1013 | if (aexpr->reg_mask[ndx1] != 0) |
400c6af0 | 1014 | { |
c378eb4e | 1015 | /* Assume chars have 8 bits. */ |
833177a4 | 1016 | for (int ndx2 = 0; ndx2 < 8; ndx2++) |
35c9c7ba | 1017 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) |
c378eb4e | 1018 | /* It's used -- record it. */ |
1f45808e | 1019 | add_register (ndx1 * 8 + ndx2); |
400c6af0 SS |
1020 | } |
1021 | } | |
1022 | } | |
833177a4 | 1023 | |
6c73cd95 | 1024 | add_aexpr (std::move (aexpr)); |
400c6af0 | 1025 | } |
c906108c SS |
1026 | } |
1027 | ||
2c58c0a9 PA |
1028 | /* Data to be passed around in the calls to the locals and args |
1029 | iterators. */ | |
1030 | ||
1031 | struct add_local_symbols_data | |
1032 | { | |
1033 | struct collection_list *collect; | |
1034 | struct gdbarch *gdbarch; | |
1035 | CORE_ADDR pc; | |
1036 | long frame_regno; | |
1037 | long frame_offset; | |
1038 | int count; | |
92bc6a20 | 1039 | int trace_string; |
2c58c0a9 PA |
1040 | }; |
1041 | ||
c378eb4e | 1042 | /* The callback for the locals and args iterators. */ |
2c58c0a9 PA |
1043 | |
1044 | static void | |
1045 | do_collect_symbol (const char *print_name, | |
1046 | struct symbol *sym, | |
1047 | void *cb_data) | |
1048 | { | |
19ba03f4 | 1049 | struct add_local_symbols_data *p = (struct add_local_symbols_data *) cb_data; |
2c58c0a9 | 1050 | |
1f45808e PA |
1051 | p->collect->collect_symbol (sym, p->gdbarch, p->frame_regno, |
1052 | p->frame_offset, p->pc, p->trace_string); | |
2c58c0a9 | 1053 | p->count++; |
dc673c81 | 1054 | |
1f45808e PA |
1055 | p->collect->add_wholly_collected (print_name); |
1056 | } | |
1057 | ||
1058 | void | |
1059 | collection_list::add_wholly_collected (const char *print_name) | |
1060 | { | |
1061 | m_wholly_collected.push_back (print_name); | |
2c58c0a9 PA |
1062 | } |
1063 | ||
c378eb4e | 1064 | /* Add all locals (or args) symbols to collection list. */ |
1f45808e PA |
1065 | |
1066 | void | |
1067 | collection_list::add_local_symbols (struct gdbarch *gdbarch, CORE_ADDR pc, | |
1068 | long frame_regno, long frame_offset, int type, | |
1069 | int trace_string) | |
c906108c | 1070 | { |
3977b71f | 1071 | const struct block *block; |
2c58c0a9 PA |
1072 | struct add_local_symbols_data cb_data; |
1073 | ||
1f45808e | 1074 | cb_data.collect = this; |
2c58c0a9 PA |
1075 | cb_data.gdbarch = gdbarch; |
1076 | cb_data.pc = pc; | |
1077 | cb_data.frame_regno = frame_regno; | |
1078 | cb_data.frame_offset = frame_offset; | |
1079 | cb_data.count = 0; | |
92bc6a20 | 1080 | cb_data.trace_string = trace_string; |
c906108c | 1081 | |
2c58c0a9 | 1082 | if (type == 'L') |
c906108c | 1083 | { |
2c58c0a9 PA |
1084 | block = block_for_pc (pc); |
1085 | if (block == NULL) | |
c906108c | 1086 | { |
2c58c0a9 PA |
1087 | warning (_("Can't collect locals; " |
1088 | "no symbol table info available.\n")); | |
1089 | return; | |
c906108c | 1090 | } |
2c58c0a9 PA |
1091 | |
1092 | iterate_over_block_local_vars (block, do_collect_symbol, &cb_data); | |
1093 | if (cb_data.count == 0) | |
1094 | warning (_("No locals found in scope.")); | |
1095 | } | |
1096 | else | |
1097 | { | |
1098 | pc = get_pc_function_start (pc); | |
1099 | block = block_for_pc (pc); | |
1100 | if (block == NULL) | |
1101 | { | |
b37520b6 | 1102 | warning (_("Can't collect args; no symbol table info available.")); |
2c58c0a9 PA |
1103 | return; |
1104 | } | |
1105 | ||
1106 | iterate_over_block_arg_vars (block, do_collect_symbol, &cb_data); | |
1107 | if (cb_data.count == 0) | |
1108 | warning (_("No args found in scope.")); | |
c906108c | 1109 | } |
c906108c SS |
1110 | } |
1111 | ||
1f45808e PA |
1112 | void |
1113 | collection_list::add_static_trace_data () | |
0fb4aa4b PA |
1114 | { |
1115 | if (info_verbose) | |
1116 | printf_filtered ("collect static trace data\n"); | |
1f45808e | 1117 | m_strace_data = true; |
cbfa3b61 YQ |
1118 | } |
1119 | ||
1f45808e PA |
1120 | collection_list::collection_list () |
1121 | : m_regs_mask (), | |
1122 | m_strace_data (false) | |
cbfa3b61 | 1123 | { |
1f45808e PA |
1124 | m_memranges.reserve (128); |
1125 | m_aexprs.reserve (128); | |
cbfa3b61 YQ |
1126 | } |
1127 | ||
c378eb4e | 1128 | /* Reduce a collection list to string form (for gdb protocol). */ |
1f45808e PA |
1129 | |
1130 | char ** | |
1131 | collection_list::stringify () | |
c906108c SS |
1132 | { |
1133 | char temp_buf[2048]; | |
1134 | int count; | |
1135 | int ndx = 0; | |
1136 | char *(*str_list)[]; | |
1137 | char *end; | |
c5aa993b | 1138 | long i; |
c906108c | 1139 | |
1f45808e | 1140 | count = 1 + 1 + m_memranges.size () + m_aexprs.size () + 1; |
c5aa993b | 1141 | str_list = (char *(*)[]) xmalloc (count * sizeof (char *)); |
c906108c | 1142 | |
1f45808e | 1143 | if (m_strace_data) |
0fb4aa4b PA |
1144 | { |
1145 | if (info_verbose) | |
1146 | printf_filtered ("\nCollecting static trace data\n"); | |
1147 | end = temp_buf; | |
1148 | *end++ = 'L'; | |
1149 | (*str_list)[ndx] = savestring (temp_buf, end - temp_buf); | |
1150 | ndx++; | |
1151 | } | |
1152 | ||
1f45808e PA |
1153 | for (i = sizeof (m_regs_mask) - 1; i > 0; i--) |
1154 | if (m_regs_mask[i] != 0) /* Skip leading zeroes in regs_mask. */ | |
c906108c | 1155 | break; |
1f45808e | 1156 | if (m_regs_mask[i] != 0) /* Prepare to send regs_mask to the stub. */ |
c906108c SS |
1157 | { |
1158 | if (info_verbose) | |
1159 | printf_filtered ("\nCollecting registers (mask): 0x"); | |
1160 | end = temp_buf; | |
c5aa993b | 1161 | *end++ = 'R'; |
c906108c SS |
1162 | for (; i >= 0; i--) |
1163 | { | |
c378eb4e | 1164 | QUIT; /* Allow user to bail out with ^C. */ |
c906108c | 1165 | if (info_verbose) |
1f45808e PA |
1166 | printf_filtered ("%02X", m_regs_mask[i]); |
1167 | sprintf (end, "%02X", m_regs_mask[i]); | |
c906108c SS |
1168 | end += 2; |
1169 | } | |
1b36a34b | 1170 | (*str_list)[ndx] = xstrdup (temp_buf); |
c906108c SS |
1171 | ndx++; |
1172 | } | |
1173 | if (info_verbose) | |
1174 | printf_filtered ("\n"); | |
1f45808e | 1175 | if (!m_memranges.empty () && info_verbose) |
c906108c | 1176 | printf_filtered ("Collecting memranges: \n"); |
1f45808e | 1177 | for (i = 0, count = 0, end = temp_buf; i < m_memranges.size (); i++) |
c906108c | 1178 | { |
c378eb4e | 1179 | QUIT; /* Allow user to bail out with ^C. */ |
c906108c | 1180 | if (info_verbose) |
104c1213 JM |
1181 | { |
1182 | printf_filtered ("(%d, %s, %ld)\n", | |
1f45808e | 1183 | m_memranges[i].type, |
19f1935d PA |
1184 | paddress (target_gdbarch (), |
1185 | m_memranges[i].start), | |
1f45808e PA |
1186 | (long) (m_memranges[i].end |
1187 | - m_memranges[i].start)); | |
104c1213 | 1188 | } |
c906108c SS |
1189 | if (count + 27 > MAX_AGENT_EXPR_LEN) |
1190 | { | |
c5aa993b | 1191 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
1192 | ndx++; |
1193 | count = 0; | |
1194 | end = temp_buf; | |
1195 | } | |
104c1213 | 1196 | |
d1948716 | 1197 | { |
1f45808e PA |
1198 | bfd_signed_vma length |
1199 | = m_memranges[i].end - m_memranges[i].start; | |
d1948716 JB |
1200 | |
1201 | /* The "%X" conversion specifier expects an unsigned argument, | |
f50e79a4 JB |
1202 | so passing -1 (memrange_absolute) to it directly gives you |
1203 | "FFFFFFFF" (or more, depending on sizeof (unsigned)). | |
1204 | Special-case it. */ | |
1f45808e | 1205 | if (m_memranges[i].type == memrange_absolute) |
19f1935d PA |
1206 | sprintf (end, "M-1,%s,%lX", phex_nz (m_memranges[i].start, 0), |
1207 | (long) length); | |
d1948716 | 1208 | else |
19f1935d PA |
1209 | sprintf (end, "M%X,%s,%lX", m_memranges[i].type, |
1210 | phex_nz (m_memranges[i].start, 0), (long) length); | |
d1948716 | 1211 | } |
104c1213 | 1212 | |
c906108c | 1213 | count += strlen (end); |
3ffbc0a5 | 1214 | end = temp_buf + count; |
c906108c SS |
1215 | } |
1216 | ||
1f45808e | 1217 | for (i = 0; i < m_aexprs.size (); i++) |
c906108c | 1218 | { |
c378eb4e | 1219 | QUIT; /* Allow user to bail out with ^C. */ |
1f45808e | 1220 | if ((count + 10 + 2 * m_aexprs[i]->len) > MAX_AGENT_EXPR_LEN) |
c906108c | 1221 | { |
c5aa993b | 1222 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
1223 | ndx++; |
1224 | count = 0; | |
1225 | end = temp_buf; | |
1226 | } | |
1f45808e | 1227 | sprintf (end, "X%08X,", m_aexprs[i]->len); |
c906108c SS |
1228 | end += 10; /* 'X' + 8 hex digits + ',' */ |
1229 | count += 10; | |
1230 | ||
1f45808e PA |
1231 | end = mem2hex (m_aexprs[i]->buf, end, m_aexprs[i]->len); |
1232 | count += 2 * m_aexprs[i]->len; | |
c906108c SS |
1233 | } |
1234 | ||
1235 | if (count != 0) | |
1236 | { | |
c5aa993b | 1237 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
1238 | ndx++; |
1239 | count = 0; | |
1240 | end = temp_buf; | |
1241 | } | |
1242 | (*str_list)[ndx] = NULL; | |
1243 | ||
1244 | if (ndx == 0) | |
27e06d3e | 1245 | { |
6c761d9c | 1246 | xfree (str_list); |
27e06d3e MS |
1247 | return NULL; |
1248 | } | |
c906108c SS |
1249 | else |
1250 | return *str_list; | |
1251 | } | |
1252 | ||
dc673c81 YQ |
1253 | /* Add the printed expression EXP to *LIST. */ |
1254 | ||
1f45808e PA |
1255 | void |
1256 | collection_list::append_exp (struct expression *exp) | |
dc673c81 | 1257 | { |
d7e74731 | 1258 | string_file tmp_stream; |
dc673c81 | 1259 | |
d7e74731 | 1260 | print_expression (exp, &tmp_stream); |
dc673c81 | 1261 | |
d7e74731 | 1262 | m_computed.push_back (std::move (tmp_stream.string ())); |
dc673c81 | 1263 | } |
a7bdde9e | 1264 | |
1f45808e PA |
1265 | void |
1266 | collection_list::finish () | |
1267 | { | |
1268 | memrange_sortmerge (m_memranges); | |
1269 | } | |
1270 | ||
a7bdde9e VP |
1271 | static void |
1272 | encode_actions_1 (struct command_line *action, | |
a7bdde9e VP |
1273 | struct bp_location *tloc, |
1274 | int frame_reg, | |
1275 | LONGEST frame_offset, | |
1276 | struct collection_list *collect, | |
1277 | struct collection_list *stepping_list) | |
c906108c | 1278 | { |
6f937416 | 1279 | const char *action_exp; |
104c1213 | 1280 | int i; |
f976f6d4 | 1281 | struct value *tempval; |
c906108c | 1282 | struct cmd_list_element *cmd; |
236f1d4d SS |
1283 | |
1284 | for (; action; action = action->next) | |
c906108c | 1285 | { |
c378eb4e | 1286 | QUIT; /* Allow user to bail out with ^C. */ |
a7bdde9e | 1287 | action_exp = action->line; |
f1735a53 | 1288 | action_exp = skip_spaces (action_exp); |
c906108c | 1289 | |
c906108c SS |
1290 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); |
1291 | if (cmd == 0) | |
8a3fe4f8 | 1292 | error (_("Bad action list item: %s"), action_exp); |
c906108c | 1293 | |
bbaca940 | 1294 | if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
c906108c | 1295 | { |
92bc6a20 TT |
1296 | int trace_string = 0; |
1297 | ||
3065dfb6 | 1298 | if (*action_exp == '/') |
92bc6a20 | 1299 | action_exp = decode_agent_options (action_exp, &trace_string); |
3065dfb6 | 1300 | |
c5aa993b | 1301 | do |
c378eb4e MS |
1302 | { /* Repeat over a comma-separated list. */ |
1303 | QUIT; /* Allow user to bail out with ^C. */ | |
f1735a53 | 1304 | action_exp = skip_spaces (action_exp); |
c906108c | 1305 | |
c5aa993b JM |
1306 | if (0 == strncasecmp ("$reg", action_exp, 4)) |
1307 | { | |
82e9becd | 1308 | for (i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++) |
1f45808e | 1309 | collect->add_register (i); |
c5aa993b JM |
1310 | action_exp = strchr (action_exp, ','); /* more? */ |
1311 | } | |
1312 | else if (0 == strncasecmp ("$arg", action_exp, 4)) | |
1313 | { | |
1f45808e PA |
1314 | collect->add_local_symbols (target_gdbarch (), |
1315 | tloc->address, | |
1316 | frame_reg, | |
1317 | frame_offset, | |
1318 | 'A', | |
1319 | trace_string); | |
c5aa993b JM |
1320 | action_exp = strchr (action_exp, ','); /* more? */ |
1321 | } | |
1322 | else if (0 == strncasecmp ("$loc", action_exp, 4)) | |
1323 | { | |
1f45808e PA |
1324 | collect->add_local_symbols (target_gdbarch (), |
1325 | tloc->address, | |
1326 | frame_reg, | |
1327 | frame_offset, | |
1328 | 'L', | |
1329 | trace_string); | |
c5aa993b JM |
1330 | action_exp = strchr (action_exp, ','); /* more? */ |
1331 | } | |
6710bf39 SS |
1332 | else if (0 == strncasecmp ("$_ret", action_exp, 5)) |
1333 | { | |
833177a4 PA |
1334 | agent_expr_up aexpr |
1335 | = gen_trace_for_return_address (tloc->address, | |
1336 | target_gdbarch (), | |
1337 | trace_string); | |
6710bf39 | 1338 | |
833177a4 PA |
1339 | ax_reqs (aexpr.get ()); |
1340 | report_agent_reqs_errors (aexpr.get ()); | |
6710bf39 SS |
1341 | |
1342 | /* take care of the registers */ | |
1343 | if (aexpr->reg_mask_len > 0) | |
1344 | { | |
833177a4 | 1345 | for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) |
6710bf39 SS |
1346 | { |
1347 | QUIT; /* allow user to bail out with ^C */ | |
1348 | if (aexpr->reg_mask[ndx1] != 0) | |
1349 | { | |
1350 | /* assume chars have 8 bits */ | |
833177a4 | 1351 | for (int ndx2 = 0; ndx2 < 8; ndx2++) |
6710bf39 | 1352 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) |
1f45808e PA |
1353 | { |
1354 | /* It's used -- record it. */ | |
1355 | collect->add_register (ndx1 * 8 + ndx2); | |
1356 | } | |
6710bf39 SS |
1357 | } |
1358 | } | |
1359 | } | |
1360 | ||
6c73cd95 | 1361 | collect->add_aexpr (std::move (aexpr)); |
6710bf39 SS |
1362 | action_exp = strchr (action_exp, ','); /* more? */ |
1363 | } | |
0fb4aa4b PA |
1364 | else if (0 == strncasecmp ("$_sdata", action_exp, 7)) |
1365 | { | |
1f45808e | 1366 | collect->add_static_trace_data (); |
0fb4aa4b PA |
1367 | action_exp = strchr (action_exp, ','); /* more? */ |
1368 | } | |
c5aa993b JM |
1369 | else |
1370 | { | |
744a8059 | 1371 | unsigned long addr; |
c5aa993b | 1372 | |
4d01a485 PA |
1373 | expression_up exp = parse_exp_1 (&action_exp, tloc->address, |
1374 | block_for_pc (tloc->address), | |
1375 | 1); | |
c906108c | 1376 | |
c5aa993b JM |
1377 | switch (exp->elts[0].opcode) |
1378 | { | |
1379 | case OP_REGISTER: | |
67f3407f DJ |
1380 | { |
1381 | const char *name = &exp->elts[2].string; | |
1382 | ||
82e9becd | 1383 | i = user_reg_map_name_to_regnum (target_gdbarch (), |
029a67e4 | 1384 | name, strlen (name)); |
67f3407f DJ |
1385 | if (i == -1) |
1386 | internal_error (__FILE__, __LINE__, | |
1387 | _("Register $%s not available"), | |
1388 | name); | |
1389 | if (info_verbose) | |
1390 | printf_filtered ("OP_REGISTER: "); | |
1f45808e | 1391 | collect->add_register (i); |
67f3407f DJ |
1392 | break; |
1393 | } | |
c5aa993b JM |
1394 | |
1395 | case UNOP_MEMVAL: | |
c378eb4e | 1396 | /* Safe because we know it's a simple expression. */ |
4d01a485 | 1397 | tempval = evaluate_expression (exp.get ()); |
42ae5230 | 1398 | addr = value_address (tempval); |
744a8059 SP |
1399 | /* Initialize the TYPE_LENGTH if it is a typedef. */ |
1400 | check_typedef (exp->elts[1].type); | |
19f1935d PA |
1401 | collect->add_memrange (target_gdbarch (), |
1402 | memrange_absolute, addr, | |
1f45808e PA |
1403 | TYPE_LENGTH (exp->elts[1].type)); |
1404 | collect->append_exp (exp.get ()); | |
c5aa993b JM |
1405 | break; |
1406 | ||
1407 | case OP_VAR_VALUE: | |
dc673c81 YQ |
1408 | { |
1409 | struct symbol *sym = exp->elts[2].symbol; | |
1410 | char_ptr name = (char_ptr) SYMBOL_NATURAL_NAME (sym); | |
1411 | ||
1f45808e PA |
1412 | collect->collect_symbol (exp->elts[2].symbol, |
1413 | target_gdbarch (), | |
1414 | frame_reg, | |
1415 | frame_offset, | |
1416 | tloc->address, | |
1417 | trace_string); | |
1418 | collect->add_wholly_collected (name); | |
dc673c81 | 1419 | } |
c5aa993b JM |
1420 | break; |
1421 | ||
c378eb4e | 1422 | default: /* Full-fledged expression. */ |
833177a4 PA |
1423 | agent_expr_up aexpr = gen_trace_for_expr (tloc->address, |
1424 | exp.get (), | |
1425 | trace_string); | |
c5aa993b | 1426 | |
833177a4 | 1427 | ax_reqs (aexpr.get ()); |
c5aa993b | 1428 | |
833177a4 | 1429 | report_agent_reqs_errors (aexpr.get ()); |
c5aa993b | 1430 | |
c378eb4e | 1431 | /* Take care of the registers. */ |
35c9c7ba | 1432 | if (aexpr->reg_mask_len > 0) |
c906108c | 1433 | { |
833177a4 | 1434 | for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) |
c906108c | 1435 | { |
c378eb4e | 1436 | QUIT; /* Allow user to bail out with ^C. */ |
35c9c7ba | 1437 | if (aexpr->reg_mask[ndx1] != 0) |
c5aa993b | 1438 | { |
c378eb4e | 1439 | /* Assume chars have 8 bits. */ |
833177a4 | 1440 | for (int ndx2 = 0; ndx2 < 8; ndx2++) |
35c9c7ba | 1441 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) |
1f45808e PA |
1442 | { |
1443 | /* It's used -- record it. */ | |
1444 | collect->add_register (ndx1 * 8 + ndx2); | |
1445 | } | |
c5aa993b | 1446 | } |
c906108c SS |
1447 | } |
1448 | } | |
dc673c81 | 1449 | |
6c73cd95 | 1450 | collect->add_aexpr (std::move (aexpr)); |
1f45808e | 1451 | collect->append_exp (exp.get ()); |
c5aa993b JM |
1452 | break; |
1453 | } /* switch */ | |
c5aa993b JM |
1454 | } /* do */ |
1455 | } | |
1456 | while (action_exp && *action_exp++ == ','); | |
1457 | } /* if */ | |
6da95a67 SS |
1458 | else if (cmd_cfunc_eq (cmd, teval_pseudocommand)) |
1459 | { | |
1460 | do | |
c378eb4e MS |
1461 | { /* Repeat over a comma-separated list. */ |
1462 | QUIT; /* Allow user to bail out with ^C. */ | |
f1735a53 | 1463 | action_exp = skip_spaces (action_exp); |
6da95a67 SS |
1464 | |
1465 | { | |
4d01a485 PA |
1466 | expression_up exp = parse_exp_1 (&action_exp, tloc->address, |
1467 | block_for_pc (tloc->address), | |
1468 | 1); | |
6da95a67 | 1469 | |
833177a4 PA |
1470 | agent_expr_up aexpr = gen_eval_for_expr (tloc->address, |
1471 | exp.get ()); | |
6da95a67 | 1472 | |
833177a4 PA |
1473 | ax_reqs (aexpr.get ()); |
1474 | report_agent_reqs_errors (aexpr.get ()); | |
6da95a67 | 1475 | |
6da95a67 SS |
1476 | /* Even though we're not officially collecting, add |
1477 | to the collect list anyway. */ | |
6c73cd95 | 1478 | collect->add_aexpr (std::move (aexpr)); |
6da95a67 SS |
1479 | } /* do */ |
1480 | } | |
1481 | while (action_exp && *action_exp++ == ','); | |
1482 | } /* if */ | |
bbaca940 | 1483 | else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
c906108c | 1484 | { |
a7bdde9e VP |
1485 | /* We check against nested while-stepping when setting |
1486 | breakpoint action, so no way to run into nested | |
1487 | here. */ | |
1488 | gdb_assert (stepping_list); | |
1489 | ||
23da373a | 1490 | encode_actions_1 (action->body_list[0], tloc, frame_reg, |
2a2287c7 | 1491 | frame_offset, stepping_list, NULL); |
c906108c | 1492 | } |
a7bdde9e VP |
1493 | else |
1494 | error (_("Invalid tracepoint command '%s'"), action->line); | |
1495 | } /* for */ | |
1496 | } | |
1497 | ||
dc673c81 | 1498 | /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST |
1f45808e | 1499 | and STEPPING_LIST. */ |
5fbce5df | 1500 | |
1f45808e PA |
1501 | void |
1502 | encode_actions (struct bp_location *tloc, | |
1503 | struct collection_list *tracepoint_list, | |
1504 | struct collection_list *stepping_list) | |
a7bdde9e | 1505 | { |
a7bdde9e | 1506 | struct command_line *actions; |
a7bdde9e VP |
1507 | int frame_reg; |
1508 | LONGEST frame_offset; | |
cbfa3b61 | 1509 | |
3e05895e TT |
1510 | gdbarch_virtual_frame_pointer (tloc->gdbarch, |
1511 | tloc->address, &frame_reg, &frame_offset); | |
a7bdde9e | 1512 | |
3ca73e0c | 1513 | actions = all_tracepoint_actions_and_cleanup (tloc->owner); |
a7bdde9e | 1514 | |
23da373a | 1515 | encode_actions_1 (actions, tloc, frame_reg, frame_offset, |
dc673c81 YQ |
1516 | tracepoint_list, stepping_list); |
1517 | ||
1f45808e PA |
1518 | tracepoint_list->finish (); |
1519 | stepping_list->finish (); | |
dc673c81 YQ |
1520 | } |
1521 | ||
1522 | /* Render all actions into gdb protocol. */ | |
1523 | ||
1524 | void | |
1525 | encode_actions_rsp (struct bp_location *tloc, char ***tdp_actions, | |
1526 | char ***stepping_actions) | |
1527 | { | |
1528 | struct collection_list tracepoint_list, stepping_list; | |
a7bdde9e | 1529 | |
dc673c81 YQ |
1530 | *tdp_actions = NULL; |
1531 | *stepping_actions = NULL; | |
1532 | ||
1f45808e | 1533 | encode_actions (tloc, &tracepoint_list, &stepping_list); |
236f1d4d | 1534 | |
1f45808e PA |
1535 | *tdp_actions = tracepoint_list.stringify (); |
1536 | *stepping_actions = stepping_list.stringify (); | |
c906108c SS |
1537 | } |
1538 | ||
1f45808e | 1539 | void |
833177a4 | 1540 | collection_list::add_aexpr (agent_expr_up aexpr) |
c906108c | 1541 | { |
6c73cd95 | 1542 | m_aexprs.push_back (std::move (aexpr)); |
c906108c SS |
1543 | } |
1544 | ||
bfccc43c YQ |
1545 | static void |
1546 | process_tracepoint_on_disconnect (void) | |
1547 | { | |
1548 | VEC(breakpoint_p) *tp_vec = NULL; | |
1549 | int ix; | |
1550 | struct breakpoint *b; | |
1551 | int has_pending_p = 0; | |
1552 | ||
1553 | /* Check whether we still have pending tracepoint. If we have, warn the | |
1554 | user that pending tracepoint will no longer work. */ | |
1555 | tp_vec = all_tracepoints (); | |
1556 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) | |
1557 | { | |
1558 | if (b->loc == NULL) | |
1559 | { | |
1560 | has_pending_p = 1; | |
1561 | break; | |
1562 | } | |
1563 | else | |
1564 | { | |
1565 | struct bp_location *loc1; | |
1566 | ||
1567 | for (loc1 = b->loc; loc1; loc1 = loc1->next) | |
1568 | { | |
1569 | if (loc1->shlib_disabled) | |
1570 | { | |
1571 | has_pending_p = 1; | |
1572 | break; | |
1573 | } | |
1574 | } | |
1575 | ||
1576 | if (has_pending_p) | |
1577 | break; | |
1578 | } | |
1579 | } | |
1580 | VEC_free (breakpoint_p, tp_vec); | |
1581 | ||
1582 | if (has_pending_p) | |
1583 | warning (_("Pending tracepoints will not be resolved while" | |
1584 | " GDB is disconnected\n")); | |
1585 | } | |
1586 | ||
aef525cb YQ |
1587 | /* Reset local state of tracing. */ |
1588 | ||
1589 | void | |
1590 | trace_reset_local_state (void) | |
1591 | { | |
1592 | set_traceframe_num (-1); | |
1593 | set_tracepoint_num (-1); | |
1594 | set_traceframe_context (NULL); | |
1595 | clear_traceframe_info (); | |
1596 | } | |
c5aa993b | 1597 | |
f224b49d | 1598 | void |
f196051f | 1599 | start_tracing (char *notes) |
d183932d | 1600 | { |
1042e4c0 SS |
1601 | VEC(breakpoint_p) *tp_vec = NULL; |
1602 | int ix; | |
d9b3f62e | 1603 | struct breakpoint *b; |
f61e138d | 1604 | struct trace_state_variable *tsv; |
d914c394 | 1605 | int any_enabled = 0, num_to_download = 0; |
f196051f SS |
1606 | int ret; |
1607 | ||
35b1e5cc | 1608 | tp_vec = all_tracepoints (); |
76a2b958 | 1609 | |
c378eb4e | 1610 | /* No point in tracing without any tracepoints... */ |
76a2b958 SS |
1611 | if (VEC_length (breakpoint_p, tp_vec) == 0) |
1612 | { | |
1613 | VEC_free (breakpoint_p, tp_vec); | |
1614 | error (_("No tracepoints defined, not starting trace")); | |
1615 | } | |
1616 | ||
d9b3f62e | 1617 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
76a2b958 | 1618 | { |
d9b3f62e | 1619 | if (b->enable_state == bp_enabled) |
d914c394 SS |
1620 | any_enabled = 1; |
1621 | ||
d9b3f62e | 1622 | if ((b->type == bp_fast_tracepoint |
d914c394 SS |
1623 | ? may_insert_fast_tracepoints |
1624 | : may_insert_tracepoints)) | |
1625 | ++num_to_download; | |
1626 | else | |
1627 | warning (_("May not insert %stracepoints, skipping tracepoint %d"), | |
d9b3f62e | 1628 | (b->type == bp_fast_tracepoint ? "fast " : ""), b->number); |
76a2b958 SS |
1629 | } |
1630 | ||
76a2b958 SS |
1631 | if (!any_enabled) |
1632 | { | |
d248b706 KY |
1633 | if (target_supports_enable_disable_tracepoint ()) |
1634 | warning (_("No tracepoints enabled")); | |
1635 | else | |
1636 | { | |
1637 | /* No point in tracing with only disabled tracepoints that | |
1638 | cannot be re-enabled. */ | |
1639 | VEC_free (breakpoint_p, tp_vec); | |
1640 | error (_("No tracepoints enabled, not starting trace")); | |
1641 | } | |
76a2b958 SS |
1642 | } |
1643 | ||
d914c394 SS |
1644 | if (num_to_download <= 0) |
1645 | { | |
1646 | VEC_free (breakpoint_p, tp_vec); | |
1647 | error (_("No tracepoints that may be downloaded, not starting trace")); | |
1648 | } | |
1649 | ||
76a2b958 SS |
1650 | target_trace_init (); |
1651 | ||
d9b3f62e | 1652 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
7a697b8d | 1653 | { |
d9b3f62e | 1654 | struct tracepoint *t = (struct tracepoint *) b; |
e8ba3115 | 1655 | struct bp_location *loc; |
f2a8bc8a | 1656 | int bp_location_downloaded = 0; |
d9b3f62e | 1657 | |
4511b1ba YQ |
1658 | /* Clear `inserted' flag. */ |
1659 | for (loc = b->loc; loc; loc = loc->next) | |
1660 | loc->inserted = 0; | |
1661 | ||
d9b3f62e | 1662 | if ((b->type == bp_fast_tracepoint |
d914c394 SS |
1663 | ? !may_insert_fast_tracepoints |
1664 | : !may_insert_tracepoints)) | |
1665 | continue; | |
1666 | ||
35b1e5cc | 1667 | t->number_on_target = 0; |
e8ba3115 YQ |
1668 | |
1669 | for (loc = b->loc; loc; loc = loc->next) | |
1e4d1764 YQ |
1670 | { |
1671 | /* Since tracepoint locations are never duplicated, `inserted' | |
1672 | flag should be zero. */ | |
1673 | gdb_assert (!loc->inserted); | |
1674 | ||
1675 | target_download_tracepoint (loc); | |
1676 | ||
1677 | loc->inserted = 1; | |
f2a8bc8a | 1678 | bp_location_downloaded = 1; |
1e4d1764 | 1679 | } |
e8ba3115 | 1680 | |
d9b3f62e | 1681 | t->number_on_target = b->number; |
55aa24fb SDJ |
1682 | |
1683 | for (loc = b->loc; loc; loc = loc->next) | |
0ea5cda8 SDJ |
1684 | if (loc->probe.probe != NULL |
1685 | && loc->probe.probe->pops->set_semaphore != NULL) | |
729662a5 TT |
1686 | loc->probe.probe->pops->set_semaphore (loc->probe.probe, |
1687 | loc->probe.objfile, | |
1688 | loc->gdbarch); | |
f2a8bc8a YQ |
1689 | |
1690 | if (bp_location_downloaded) | |
1691 | observer_notify_breakpoint_modified (b); | |
7a697b8d | 1692 | } |
35b1e5cc | 1693 | VEC_free (breakpoint_p, tp_vec); |
76a2b958 | 1694 | |
00bf0b85 | 1695 | /* Send down all the trace state variables too. */ |
35b1e5cc | 1696 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) |
782b2b07 | 1697 | { |
00bf0b85 | 1698 | target_download_trace_state_variable (tsv); |
782b2b07 | 1699 | } |
35b1e5cc SS |
1700 | |
1701 | /* Tell target to treat text-like sections as transparent. */ | |
1702 | target_trace_set_readonly_regions (); | |
4daf5ac0 SS |
1703 | /* Set some mode flags. */ |
1704 | target_set_disconnected_tracing (disconnected_tracing); | |
1705 | target_set_circular_trace_buffer (circular_trace_buffer); | |
f6f899bf | 1706 | target_set_trace_buffer_size (trace_buffer_size); |
1042e4c0 | 1707 | |
f196051f SS |
1708 | if (!notes) |
1709 | notes = trace_notes; | |
1710 | ret = target_set_trace_notes (trace_user, notes, NULL); | |
1711 | ||
1712 | if (!ret && (trace_user || notes)) | |
43011e52 | 1713 | warning (_("Target does not support trace user/notes, info ignored")); |
f196051f | 1714 | |
35b1e5cc SS |
1715 | /* Now insert traps and begin collecting data. */ |
1716 | target_trace_start (); | |
1042e4c0 | 1717 | |
35b1e5cc | 1718 | /* Reset our local state. */ |
aef525cb | 1719 | trace_reset_local_state (); |
00bf0b85 | 1720 | current_trace_status()->running = 1; |
1042e4c0 SS |
1721 | } |
1722 | ||
f196051f SS |
1723 | /* The tstart command requests the target to start a new trace run. |
1724 | The command passes any arguments it has to the target verbatim, as | |
1725 | an optional "trace note". This is useful as for instance a warning | |
1726 | to other users if the trace runs disconnected, and you don't want | |
1727 | anybody else messing with the target. */ | |
f224b49d VP |
1728 | |
1729 | static void | |
e5a873b7 | 1730 | tstart_command (char *args, int from_tty) |
f224b49d VP |
1731 | { |
1732 | dont_repeat (); /* Like "run", dangerous to repeat accidentally. */ | |
1733 | ||
615bcdef SS |
1734 | if (current_trace_status ()->running) |
1735 | { | |
1736 | if (from_tty | |
1737 | && !query (_("A trace is running already. Start a new run? "))) | |
1738 | error (_("New trace run not started.")); | |
1739 | } | |
1740 | ||
f196051f | 1741 | start_tracing (args); |
f224b49d VP |
1742 | } |
1743 | ||
f196051f SS |
1744 | /* The tstop command stops the tracing run. The command passes any |
1745 | supplied arguments to the target verbatim as a "stop note"; if the | |
1746 | target supports trace notes, then it will be reported back as part | |
1747 | of the trace run's status. */ | |
1748 | ||
c906108c | 1749 | static void |
e5a873b7 | 1750 | tstop_command (char *args, int from_tty) |
d183932d | 1751 | { |
615bcdef SS |
1752 | if (!current_trace_status ()->running) |
1753 | error (_("Trace is not running.")); | |
1754 | ||
f196051f | 1755 | stop_tracing (args); |
c906108c SS |
1756 | } |
1757 | ||
d5551862 | 1758 | void |
f196051f | 1759 | stop_tracing (char *note) |
d5551862 | 1760 | { |
f196051f | 1761 | int ret; |
55aa24fb SDJ |
1762 | VEC(breakpoint_p) *tp_vec = NULL; |
1763 | int ix; | |
1764 | struct breakpoint *t; | |
f196051f | 1765 | |
35b1e5cc | 1766 | target_trace_stop (); |
f196051f | 1767 | |
55aa24fb SDJ |
1768 | tp_vec = all_tracepoints (); |
1769 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) | |
1770 | { | |
1771 | struct bp_location *loc; | |
1772 | ||
1773 | if ((t->type == bp_fast_tracepoint | |
1774 | ? !may_insert_fast_tracepoints | |
1775 | : !may_insert_tracepoints)) | |
1776 | continue; | |
1777 | ||
1778 | for (loc = t->loc; loc; loc = loc->next) | |
1779 | { | |
1780 | /* GDB can be totally absent in some disconnected trace scenarios, | |
1781 | but we don't really care if this semaphore goes out of sync. | |
1782 | That's why we are decrementing it here, but not taking care | |
1783 | in other places. */ | |
0ea5cda8 SDJ |
1784 | if (loc->probe.probe != NULL |
1785 | && loc->probe.probe->pops->clear_semaphore != NULL) | |
729662a5 TT |
1786 | loc->probe.probe->pops->clear_semaphore (loc->probe.probe, |
1787 | loc->probe.objfile, | |
1788 | loc->gdbarch); | |
55aa24fb SDJ |
1789 | } |
1790 | } | |
1791 | ||
1792 | VEC_free (breakpoint_p, tp_vec); | |
1793 | ||
f196051f SS |
1794 | if (!note) |
1795 | note = trace_stop_notes; | |
1796 | ret = target_set_trace_notes (NULL, NULL, note); | |
1797 | ||
1798 | if (!ret && note) | |
43011e52 | 1799 | warning (_("Target does not support trace notes, note ignored")); |
f196051f | 1800 | |
c378eb4e | 1801 | /* Should change in response to reply? */ |
00bf0b85 | 1802 | current_trace_status ()->running = 0; |
d5551862 SS |
1803 | } |
1804 | ||
c906108c SS |
1805 | /* tstatus command */ |
1806 | static void | |
e5a873b7 | 1807 | tstatus_command (char *args, int from_tty) |
d183932d | 1808 | { |
00bf0b85 | 1809 | struct trace_status *ts = current_trace_status (); |
f196051f SS |
1810 | int status, ix; |
1811 | VEC(breakpoint_p) *tp_vec = NULL; | |
1812 | struct breakpoint *t; | |
35b1e5cc | 1813 | |
00bf0b85 SS |
1814 | status = target_get_trace_status (ts); |
1815 | ||
1816 | if (status == -1) | |
1817 | { | |
f5911ea1 | 1818 | if (ts->filename != NULL) |
00bf0b85 SS |
1819 | printf_filtered (_("Using a trace file.\n")); |
1820 | else | |
1821 | { | |
1822 | printf_filtered (_("Trace can not be run on this target.\n")); | |
1823 | return; | |
1824 | } | |
1825 | } | |
1826 | ||
1827 | if (!ts->running_known) | |
1828 | { | |
1829 | printf_filtered (_("Run/stop status is unknown.\n")); | |
1830 | } | |
1831 | else if (ts->running) | |
c906108c | 1832 | { |
35b1e5cc | 1833 | printf_filtered (_("Trace is running on the target.\n")); |
c906108c SS |
1834 | } |
1835 | else | |
00bf0b85 SS |
1836 | { |
1837 | switch (ts->stop_reason) | |
1838 | { | |
1839 | case trace_never_run: | |
1840 | printf_filtered (_("No trace has been run on the target.\n")); | |
1841 | break; | |
e5a873b7 | 1842 | case trace_stop_command: |
f196051f SS |
1843 | if (ts->stop_desc) |
1844 | printf_filtered (_("Trace stopped by a tstop command (%s).\n"), | |
1845 | ts->stop_desc); | |
1846 | else | |
1847 | printf_filtered (_("Trace stopped by a tstop command.\n")); | |
00bf0b85 SS |
1848 | break; |
1849 | case trace_buffer_full: | |
1850 | printf_filtered (_("Trace stopped because the buffer was full.\n")); | |
1851 | break; | |
1852 | case trace_disconnected: | |
1853 | printf_filtered (_("Trace stopped because of disconnection.\n")); | |
1854 | break; | |
1855 | case tracepoint_passcount: | |
00bf0b85 SS |
1856 | printf_filtered (_("Trace stopped by tracepoint %d.\n"), |
1857 | ts->stopping_tracepoint); | |
1858 | break; | |
6c28cbf2 SS |
1859 | case tracepoint_error: |
1860 | if (ts->stopping_tracepoint) | |
3e43a32a MS |
1861 | printf_filtered (_("Trace stopped by an " |
1862 | "error (%s, tracepoint %d).\n"), | |
f196051f | 1863 | ts->stop_desc, ts->stopping_tracepoint); |
6c28cbf2 SS |
1864 | else |
1865 | printf_filtered (_("Trace stopped by an error (%s).\n"), | |
f196051f | 1866 | ts->stop_desc); |
6c28cbf2 | 1867 | break; |
00bf0b85 SS |
1868 | case trace_stop_reason_unknown: |
1869 | printf_filtered (_("Trace stopped for an unknown reason.\n")); | |
1870 | break; | |
1871 | default: | |
1872 | printf_filtered (_("Trace stopped for some other reason (%d).\n"), | |
1873 | ts->stop_reason); | |
1874 | break; | |
1875 | } | |
1876 | } | |
1877 | ||
4daf5ac0 SS |
1878 | if (ts->traceframes_created >= 0 |
1879 | && ts->traceframe_count != ts->traceframes_created) | |
1880 | { | |
3e43a32a MS |
1881 | printf_filtered (_("Buffer contains %d trace " |
1882 | "frames (of %d created total).\n"), | |
4daf5ac0 SS |
1883 | ts->traceframe_count, ts->traceframes_created); |
1884 | } | |
1885 | else if (ts->traceframe_count >= 0) | |
00bf0b85 SS |
1886 | { |
1887 | printf_filtered (_("Collected %d trace frames.\n"), | |
1888 | ts->traceframe_count); | |
1889 | } | |
1890 | ||
4daf5ac0 | 1891 | if (ts->buffer_free >= 0) |
00bf0b85 | 1892 | { |
4daf5ac0 SS |
1893 | if (ts->buffer_size >= 0) |
1894 | { | |
1895 | printf_filtered (_("Trace buffer has %d bytes of %d bytes free"), | |
1896 | ts->buffer_free, ts->buffer_size); | |
1897 | if (ts->buffer_size > 0) | |
1898 | printf_filtered (_(" (%d%% full)"), | |
1899 | ((int) ((((long long) (ts->buffer_size | |
1900 | - ts->buffer_free)) * 100) | |
1901 | / ts->buffer_size))); | |
1902 | printf_filtered (_(".\n")); | |
1903 | } | |
1904 | else | |
1905 | printf_filtered (_("Trace buffer has %d bytes free.\n"), | |
1906 | ts->buffer_free); | |
00bf0b85 | 1907 | } |
35b1e5cc | 1908 | |
33da3f1c SS |
1909 | if (ts->disconnected_tracing) |
1910 | printf_filtered (_("Trace will continue if GDB disconnects.\n")); | |
1911 | else | |
1912 | printf_filtered (_("Trace will stop if GDB disconnects.\n")); | |
1913 | ||
1914 | if (ts->circular_buffer) | |
1915 | printf_filtered (_("Trace buffer is circular.\n")); | |
1916 | ||
f196051f SS |
1917 | if (ts->user_name && strlen (ts->user_name) > 0) |
1918 | printf_filtered (_("Trace user is %s.\n"), ts->user_name); | |
1919 | ||
1920 | if (ts->notes && strlen (ts->notes) > 0) | |
1921 | printf_filtered (_("Trace notes: %s.\n"), ts->notes); | |
1922 | ||
00bf0b85 | 1923 | /* Now report on what we're doing with tfind. */ |
35b1e5cc SS |
1924 | if (traceframe_number >= 0) |
1925 | printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"), | |
1926 | traceframe_number, tracepoint_number); | |
1927 | else | |
1928 | printf_filtered (_("Not looking at any trace frame.\n")); | |
f196051f SS |
1929 | |
1930 | /* Report start/stop times if supplied. */ | |
1931 | if (ts->start_time) | |
1932 | { | |
1933 | if (ts->stop_time) | |
1934 | { | |
1935 | LONGEST run_time = ts->stop_time - ts->start_time; | |
1936 | ||
1937 | /* Reporting a run time is more readable than two long numbers. */ | |
1938 | printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"), | |
f30aa5af DK |
1939 | (long int) (ts->start_time / 1000000), |
1940 | (long int) (ts->start_time % 1000000), | |
1941 | (long int) (run_time / 1000000), | |
1942 | (long int) (run_time % 1000000)); | |
f196051f SS |
1943 | } |
1944 | else | |
1945 | printf_filtered (_("Trace started at %ld.%06ld secs.\n"), | |
f30aa5af DK |
1946 | (long int) (ts->start_time / 1000000), |
1947 | (long int) (ts->start_time % 1000000)); | |
f196051f SS |
1948 | } |
1949 | else if (ts->stop_time) | |
1950 | printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"), | |
f30aa5af DK |
1951 | (long int) (ts->stop_time / 1000000), |
1952 | (long int) (ts->stop_time % 1000000)); | |
f196051f SS |
1953 | |
1954 | /* Now report any per-tracepoint status available. */ | |
1955 | tp_vec = all_tracepoints (); | |
1956 | ||
1957 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) | |
1958 | target_get_tracepoint_status (t, NULL); | |
1959 | ||
1960 | VEC_free (breakpoint_p, tp_vec); | |
c906108c SS |
1961 | } |
1962 | ||
f224b49d VP |
1963 | /* Report the trace status to uiout, in a way suitable for MI, and not |
1964 | suitable for CLI. If ON_STOP is true, suppress a few fields that | |
1965 | are not meaningful in the -trace-stop response. | |
1966 | ||
1967 | The implementation is essentially parallel to trace_status_command, but | |
1968 | merging them will result in unreadable code. */ | |
1969 | void | |
1970 | trace_status_mi (int on_stop) | |
1971 | { | |
79a45e25 | 1972 | struct ui_out *uiout = current_uiout; |
f224b49d VP |
1973 | struct trace_status *ts = current_trace_status (); |
1974 | int status; | |
f224b49d VP |
1975 | |
1976 | status = target_get_trace_status (ts); | |
1977 | ||
f5911ea1 | 1978 | if (status == -1 && ts->filename == NULL) |
f224b49d | 1979 | { |
112e8700 | 1980 | uiout->field_string ("supported", "0"); |
f224b49d VP |
1981 | return; |
1982 | } | |
1983 | ||
f5911ea1 | 1984 | if (ts->filename != NULL) |
112e8700 | 1985 | uiout->field_string ("supported", "file"); |
f224b49d | 1986 | else if (!on_stop) |
112e8700 | 1987 | uiout->field_string ("supported", "1"); |
f224b49d | 1988 | |
f5911ea1 | 1989 | if (ts->filename != NULL) |
112e8700 | 1990 | uiout->field_string ("trace-file", ts->filename); |
f5911ea1 | 1991 | |
f224b49d VP |
1992 | gdb_assert (ts->running_known); |
1993 | ||
1994 | if (ts->running) | |
1995 | { | |
112e8700 | 1996 | uiout->field_string ("running", "1"); |
f224b49d VP |
1997 | |
1998 | /* Unlike CLI, do not show the state of 'disconnected-tracing' variable. | |
1999 | Given that the frontend gets the status either on -trace-stop, or from | |
2000 | -trace-status after re-connection, it does not seem like this | |
2001 | information is necessary for anything. It is not necessary for either | |
2002 | figuring the vital state of the target nor for navigation of trace | |
2003 | frames. If the frontend wants to show the current state is some | |
2004 | configure dialog, it can request the value when such dialog is | |
2005 | invoked by the user. */ | |
2006 | } | |
2007 | else | |
2008 | { | |
a121b7c1 | 2009 | const char *stop_reason = NULL; |
f224b49d VP |
2010 | int stopping_tracepoint = -1; |
2011 | ||
2012 | if (!on_stop) | |
112e8700 | 2013 | uiout->field_string ("running", "0"); |
f224b49d VP |
2014 | |
2015 | if (ts->stop_reason != trace_stop_reason_unknown) | |
2016 | { | |
2017 | switch (ts->stop_reason) | |
2018 | { | |
e5a873b7 | 2019 | case trace_stop_command: |
f224b49d VP |
2020 | stop_reason = "request"; |
2021 | break; | |
2022 | case trace_buffer_full: | |
2023 | stop_reason = "overflow"; | |
2024 | break; | |
2025 | case trace_disconnected: | |
2026 | stop_reason = "disconnection"; | |
2027 | break; | |
2028 | case tracepoint_passcount: | |
2029 | stop_reason = "passcount"; | |
2030 | stopping_tracepoint = ts->stopping_tracepoint; | |
2031 | break; | |
6c28cbf2 SS |
2032 | case tracepoint_error: |
2033 | stop_reason = "error"; | |
2034 | stopping_tracepoint = ts->stopping_tracepoint; | |
2035 | break; | |
f224b49d VP |
2036 | } |
2037 | ||
2038 | if (stop_reason) | |
2039 | { | |
112e8700 | 2040 | uiout->field_string ("stop-reason", stop_reason); |
f224b49d | 2041 | if (stopping_tracepoint != -1) |
112e8700 | 2042 | uiout->field_int ("stopping-tracepoint", |
f224b49d | 2043 | stopping_tracepoint); |
6c28cbf2 | 2044 | if (ts->stop_reason == tracepoint_error) |
112e8700 | 2045 | uiout->field_string ("error-description", |
f196051f | 2046 | ts->stop_desc); |
f224b49d VP |
2047 | } |
2048 | } | |
2049 | } | |
2050 | ||
a97153c7 | 2051 | if (ts->traceframe_count != -1) |
112e8700 | 2052 | uiout->field_int ("frames", ts->traceframe_count); |
87290684 | 2053 | if (ts->traceframes_created != -1) |
112e8700 | 2054 | uiout->field_int ("frames-created", ts->traceframes_created); |
a97153c7 | 2055 | if (ts->buffer_size != -1) |
112e8700 | 2056 | uiout->field_int ("buffer-size", ts->buffer_size); |
a97153c7 | 2057 | if (ts->buffer_free != -1) |
112e8700 | 2058 | uiout->field_int ("buffer-free", ts->buffer_free); |
a97153c7 | 2059 | |
112e8700 SM |
2060 | uiout->field_int ("disconnected", ts->disconnected_tracing); |
2061 | uiout->field_int ("circular", ts->circular_buffer); | |
f196051f | 2062 | |
112e8700 SM |
2063 | uiout->field_string ("user-name", ts->user_name); |
2064 | uiout->field_string ("notes", ts->notes); | |
f196051f SS |
2065 | |
2066 | { | |
2067 | char buf[100]; | |
2068 | ||
2069 | xsnprintf (buf, sizeof buf, "%ld.%06ld", | |
f30aa5af DK |
2070 | (long int) (ts->start_time / 1000000), |
2071 | (long int) (ts->start_time % 1000000)); | |
112e8700 | 2072 | uiout->field_string ("start-time", buf); |
f196051f | 2073 | xsnprintf (buf, sizeof buf, "%ld.%06ld", |
f30aa5af DK |
2074 | (long int) (ts->stop_time / 1000000), |
2075 | (long int) (ts->stop_time % 1000000)); | |
112e8700 | 2076 | uiout->field_string ("stop-time", buf); |
f196051f | 2077 | } |
f224b49d VP |
2078 | } |
2079 | ||
2f9d54cf PA |
2080 | /* Check if a trace run is ongoing. If so, and FROM_TTY, query the |
2081 | user if she really wants to detach. */ | |
2082 | ||
d5551862 | 2083 | void |
2f9d54cf | 2084 | query_if_trace_running (int from_tty) |
d5551862 | 2085 | { |
2f9d54cf PA |
2086 | if (!from_tty) |
2087 | return; | |
2088 | ||
00bf0b85 SS |
2089 | /* It can happen that the target that was tracing went away on its |
2090 | own, and we didn't notice. Get a status update, and if the | |
2091 | current target doesn't even do tracing, then assume it's not | |
2092 | running anymore. */ | |
26afc0d7 | 2093 | if (target_get_trace_status (current_trace_status ()) < 0) |
00bf0b85 SS |
2094 | current_trace_status ()->running = 0; |
2095 | ||
33da3f1c SS |
2096 | /* If running interactively, give the user the option to cancel and |
2097 | then decide what to do differently with the run. Scripts are | |
2098 | just going to disconnect and let the target deal with it, | |
2099 | according to how it's been instructed previously via | |
2100 | disconnected-tracing. */ | |
2f9d54cf | 2101 | if (current_trace_status ()->running) |
d5551862 | 2102 | { |
bfccc43c YQ |
2103 | process_tracepoint_on_disconnect (); |
2104 | ||
33da3f1c SS |
2105 | if (current_trace_status ()->disconnected_tracing) |
2106 | { | |
3e43a32a MS |
2107 | if (!query (_("Trace is running and will " |
2108 | "continue after detach; detach anyway? "))) | |
33da3f1c SS |
2109 | error (_("Not confirmed.")); |
2110 | } | |
2111 | else | |
2112 | { | |
3e43a32a MS |
2113 | if (!query (_("Trace is running but will " |
2114 | "stop on detach; detach anyway? "))) | |
33da3f1c SS |
2115 | error (_("Not confirmed.")); |
2116 | } | |
d5551862 | 2117 | } |
2f9d54cf | 2118 | } |
8b9b7ef8 | 2119 | |
2f9d54cf PA |
2120 | /* This function handles the details of what to do about an ongoing |
2121 | tracing run if the user has asked to detach or otherwise disconnect | |
2122 | from the target. */ | |
2123 | ||
2124 | void | |
2125 | disconnect_tracing (void) | |
2126 | { | |
8b9b7ef8 SS |
2127 | /* Also we want to be out of tfind mode, otherwise things can get |
2128 | confusing upon reconnection. Just use these calls instead of | |
2129 | full tfind_1 behavior because we're in the middle of detaching, | |
2130 | and there's no point to updating current stack frame etc. */ | |
aef525cb | 2131 | trace_reset_local_state (); |
d5551862 SS |
2132 | } |
2133 | ||
d183932d | 2134 | /* Worker function for the various flavors of the tfind command. */ |
f197e0f1 VP |
2135 | void |
2136 | tfind_1 (enum trace_find_type type, int num, | |
cc5925ad | 2137 | CORE_ADDR addr1, CORE_ADDR addr2, |
f197e0f1 | 2138 | int from_tty) |
c906108c SS |
2139 | { |
2140 | int target_frameno = -1, target_tracept = -1; | |
2ce6d6bf | 2141 | struct frame_id old_frame_id = null_frame_id; |
d9b3f62e | 2142 | struct tracepoint *tp; |
79a45e25 | 2143 | struct ui_out *uiout = current_uiout; |
c906108c | 2144 | |
2ce6d6bf SS |
2145 | /* Only try to get the current stack frame if we have a chance of |
2146 | succeeding. In particular, if we're trying to get a first trace | |
2147 | frame while all threads are running, it's not going to succeed, | |
2148 | so leave it with a default value and let the frame comparison | |
2149 | below (correctly) decide to print out the source location of the | |
2150 | trace frame. */ | |
2151 | if (!(type == tfind_number && num == -1) | |
2152 | && (has_stack_frames () || traceframe_number >= 0)) | |
2153 | old_frame_id = get_frame_id (get_current_frame ()); | |
c906108c | 2154 | |
35b1e5cc SS |
2155 | target_frameno = target_trace_find (type, num, addr1, addr2, |
2156 | &target_tracept); | |
2157 | ||
2158 | if (type == tfind_number | |
2159 | && num == -1 | |
2160 | && target_frameno == -1) | |
2161 | { | |
2162 | /* We told the target to get out of tfind mode, and it did. */ | |
2163 | } | |
2164 | else if (target_frameno == -1) | |
2165 | { | |
2ce6d6bf | 2166 | /* A request for a non-existent trace frame has failed. |
35b1e5cc SS |
2167 | Our response will be different, depending on FROM_TTY: |
2168 | ||
2169 | If FROM_TTY is true, meaning that this command was | |
2170 | typed interactively by the user, then give an error | |
2171 | and DO NOT change the state of traceframe_number etc. | |
2172 | ||
2173 | However if FROM_TTY is false, meaning that we're either | |
2174 | in a script, a loop, or a user-defined command, then | |
2175 | DON'T give an error, but DO change the state of | |
2176 | traceframe_number etc. to invalid. | |
2177 | ||
2178 | The rationalle is that if you typed the command, you | |
2179 | might just have committed a typo or something, and you'd | |
2180 | like to NOT lose your current debugging state. However | |
2181 | if you're in a user-defined command or especially in a | |
2182 | loop, then you need a way to detect that the command | |
2183 | failed WITHOUT aborting. This allows you to write | |
2184 | scripts that search thru the trace buffer until the end, | |
2185 | and then continue on to do something else. */ | |
2186 | ||
2187 | if (from_tty) | |
2188 | error (_("Target failed to find requested trace frame.")); | |
2189 | else | |
2190 | { | |
2191 | if (info_verbose) | |
2192 | printf_filtered ("End of trace buffer.\n"); | |
c378eb4e | 2193 | #if 0 /* dubious now? */ |
35b1e5cc SS |
2194 | /* The following will not recurse, since it's |
2195 | special-cased. */ | |
e5a873b7 | 2196 | tfind_command ("-1", from_tty); |
35b1e5cc SS |
2197 | #endif |
2198 | } | |
2199 | } | |
2200 | ||
d5551862 SS |
2201 | tp = get_tracepoint_by_number_on_target (target_tracept); |
2202 | ||
35f196d9 | 2203 | reinit_frame_cache (); |
2f4d8875 | 2204 | target_dcache_invalidate (); |
8d735b87 | 2205 | |
c1fc2657 | 2206 | set_tracepoint_num (tp ? tp->number : target_tracept); |
201b4506 YQ |
2207 | |
2208 | if (target_frameno != get_traceframe_number ()) | |
2209 | observer_notify_traceframe_changed (target_frameno, tracepoint_number); | |
2210 | ||
8d735b87 YQ |
2211 | set_current_traceframe (target_frameno); |
2212 | ||
c906108c | 2213 | if (target_frameno == -1) |
fb14de7b | 2214 | set_traceframe_context (NULL); |
c906108c | 2215 | else |
fb14de7b | 2216 | set_traceframe_context (get_current_frame ()); |
c906108c | 2217 | |
f197e0f1 VP |
2218 | if (traceframe_number >= 0) |
2219 | { | |
2220 | /* Use different branches for MI and CLI to make CLI messages | |
2221 | i18n-eable. */ | |
112e8700 | 2222 | if (uiout->is_mi_like_p ()) |
f197e0f1 | 2223 | { |
112e8700 SM |
2224 | uiout->field_string ("found", "1"); |
2225 | uiout->field_int ("tracepoint", tracepoint_number); | |
2226 | uiout->field_int ("traceframe", traceframe_number); | |
f197e0f1 VP |
2227 | } |
2228 | else | |
2229 | { | |
2230 | printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"), | |
2231 | traceframe_number, tracepoint_number); | |
2232 | } | |
2233 | } | |
2234 | else | |
2235 | { | |
112e8700 SM |
2236 | if (uiout->is_mi_like_p ()) |
2237 | uiout->field_string ("found", "0"); | |
4136fdd2 SS |
2238 | else if (type == tfind_number && num == -1) |
2239 | printf_unfiltered (_("No longer looking at any trace frame\n")); | |
c378eb4e | 2240 | else /* This case may never occur, check. */ |
4136fdd2 | 2241 | printf_unfiltered (_("No trace frame found\n")); |
f197e0f1 VP |
2242 | } |
2243 | ||
00bf0b85 SS |
2244 | /* If we're in nonstop mode and getting out of looking at trace |
2245 | frames, there won't be any current frame to go back to and | |
2246 | display. */ | |
2247 | if (from_tty | |
2248 | && (has_stack_frames () || traceframe_number >= 0)) | |
c906108c | 2249 | { |
0faf0076 | 2250 | enum print_what print_what; |
c906108c | 2251 | |
2ce6d6bf | 2252 | /* NOTE: in imitation of the step command, try to determine |
d183932d MS |
2253 | whether we have made a transition from one function to |
2254 | another. If so, we'll print the "stack frame" (ie. the new | |
2255 | function and it's arguments) -- otherwise we'll just show the | |
fb14de7b UW |
2256 | new source line. */ |
2257 | ||
2258 | if (frame_id_eq (old_frame_id, | |
2259 | get_frame_id (get_current_frame ()))) | |
0faf0076 | 2260 | print_what = SRC_LINE; |
c906108c | 2261 | else |
0faf0076 | 2262 | print_what = SRC_AND_LOC; |
c906108c | 2263 | |
08d72866 | 2264 | print_stack_frame (get_selected_frame (NULL), 1, print_what, 1); |
c906108c SS |
2265 | do_displays (); |
2266 | } | |
2267 | } | |
2268 | ||
cc3da688 YQ |
2269 | /* Error on looking at traceframes while trace is running. */ |
2270 | ||
2271 | void | |
2272 | check_trace_running (struct trace_status *status) | |
2273 | { | |
2274 | if (status->running && status->filename == NULL) | |
2275 | error (_("May not look at trace frames while trace is running.")); | |
2276 | } | |
2277 | ||
c906108c SS |
2278 | /* trace_find_command takes a trace frame number n, |
2279 | sends "QTFrame:<n>" to the target, | |
2280 | and accepts a reply that may contain several optional pieces | |
2281 | of information: a frame number, a tracepoint number, and an | |
2282 | indication of whether this is a trap frame or a stepping frame. | |
2283 | ||
2284 | The minimal response is just "OK" (which indicates that the | |
2285 | target does not give us a frame number or a tracepoint number). | |
2286 | Instead of that, the target may send us a string containing | |
2287 | any combination of: | |
c5aa993b JM |
2288 | F<hexnum> (gives the selected frame number) |
2289 | T<hexnum> (gives the selected tracepoint number) | |
2290 | */ | |
c906108c SS |
2291 | |
2292 | /* tfind command */ | |
2293 | static void | |
a121b7c1 | 2294 | tfind_command_1 (const char *args, int from_tty) |
c378eb4e | 2295 | { /* This should only be called with a numeric argument. */ |
c906108c | 2296 | int frameno = -1; |
c906108c | 2297 | |
cc3da688 | 2298 | check_trace_running (current_trace_status ()); |
35b1e5cc SS |
2299 | |
2300 | if (args == 0 || *args == 0) | |
2301 | { /* TFIND with no args means find NEXT trace frame. */ | |
2302 | if (traceframe_number == -1) | |
c378eb4e | 2303 | frameno = 0; /* "next" is first one. */ |
35b1e5cc SS |
2304 | else |
2305 | frameno = traceframe_number + 1; | |
2306 | } | |
2307 | else if (0 == strcmp (args, "-")) | |
c906108c | 2308 | { |
35b1e5cc SS |
2309 | if (traceframe_number == -1) |
2310 | error (_("not debugging trace buffer")); | |
2311 | else if (from_tty && traceframe_number == 0) | |
2312 | error (_("already at start of trace buffer")); | |
2313 | ||
2314 | frameno = traceframe_number - 1; | |
2315 | } | |
2316 | /* A hack to work around eval's need for fp to have been collected. */ | |
2317 | else if (0 == strcmp (args, "-1")) | |
2318 | frameno = -1; | |
2319 | else | |
2320 | frameno = parse_and_eval_long (args); | |
c906108c | 2321 | |
35b1e5cc SS |
2322 | if (frameno < -1) |
2323 | error (_("invalid input (%d is less than zero)"), frameno); | |
c906108c | 2324 | |
f197e0f1 | 2325 | tfind_1 (tfind_number, frameno, 0, 0, from_tty); |
c906108c SS |
2326 | } |
2327 | ||
a121b7c1 | 2328 | static void |
981a3fb3 | 2329 | tfind_command (const char *args, int from_tty) |
a121b7c1 PA |
2330 | { |
2331 | tfind_command_1 (const_cast<char *> (args), from_tty); | |
2332 | } | |
2333 | ||
c906108c SS |
2334 | /* tfind end */ |
2335 | static void | |
2983f7cb | 2336 | tfind_end_command (const char *args, int from_tty) |
c906108c | 2337 | { |
a121b7c1 | 2338 | tfind_command_1 ("-1", from_tty); |
c906108c SS |
2339 | } |
2340 | ||
c906108c SS |
2341 | /* tfind start */ |
2342 | static void | |
2983f7cb | 2343 | tfind_start_command (const char *args, int from_tty) |
c906108c | 2344 | { |
a121b7c1 | 2345 | tfind_command_1 ("0", from_tty); |
c906108c SS |
2346 | } |
2347 | ||
2348 | /* tfind pc command */ | |
2349 | static void | |
2983f7cb | 2350 | tfind_pc_command (const char *args, int from_tty) |
d183932d | 2351 | { |
c906108c | 2352 | CORE_ADDR pc; |
c906108c | 2353 | |
cc3da688 | 2354 | check_trace_running (current_trace_status ()); |
c906108c | 2355 | |
35b1e5cc SS |
2356 | if (args == 0 || *args == 0) |
2357 | pc = regcache_read_pc (get_current_regcache ()); | |
c906108c | 2358 | else |
35b1e5cc SS |
2359 | pc = parse_and_eval_address (args); |
2360 | ||
f197e0f1 | 2361 | tfind_1 (tfind_pc, 0, pc, 0, from_tty); |
c906108c SS |
2362 | } |
2363 | ||
2364 | /* tfind tracepoint command */ | |
2365 | static void | |
2983f7cb | 2366 | tfind_tracepoint_command (const char *args, int from_tty) |
d183932d | 2367 | { |
c906108c | 2368 | int tdp; |
d9b3f62e | 2369 | struct tracepoint *tp; |
c906108c | 2370 | |
cc3da688 | 2371 | check_trace_running (current_trace_status ()); |
383e5f85 | 2372 | |
35b1e5cc SS |
2373 | if (args == 0 || *args == 0) |
2374 | { | |
2375 | if (tracepoint_number == -1) | |
2376 | error (_("No current tracepoint -- please supply an argument.")); | |
c906108c | 2377 | else |
c378eb4e | 2378 | tdp = tracepoint_number; /* Default is current TDP. */ |
c906108c SS |
2379 | } |
2380 | else | |
35b1e5cc SS |
2381 | tdp = parse_and_eval_long (args); |
2382 | ||
2383 | /* If we have the tracepoint on hand, use the number that the | |
2384 | target knows about (which may be different if we disconnected | |
2385 | and reconnected). */ | |
2386 | tp = get_tracepoint (tdp); | |
2387 | if (tp) | |
2388 | tdp = tp->number_on_target; | |
2389 | ||
f197e0f1 | 2390 | tfind_1 (tfind_tp, tdp, 0, 0, from_tty); |
c906108c SS |
2391 | } |
2392 | ||
2393 | /* TFIND LINE command: | |
c5aa993b | 2394 | |
c906108c | 2395 | This command will take a sourceline for argument, just like BREAK |
d183932d | 2396 | or TRACE (ie. anything that "decode_line_1" can handle). |
c5aa993b | 2397 | |
c906108c SS |
2398 | With no argument, this command will find the next trace frame |
2399 | corresponding to a source line OTHER THAN THE CURRENT ONE. */ | |
2400 | ||
2401 | static void | |
2983f7cb | 2402 | tfind_line_command (const char *args, int from_tty) |
d183932d | 2403 | { |
cc3da688 | 2404 | check_trace_running (current_trace_status ()); |
5af949e3 | 2405 | |
6c5b2ebe | 2406 | symtab_and_line sal; |
35b1e5cc SS |
2407 | if (args == 0 || *args == 0) |
2408 | { | |
2409 | sal = find_pc_line (get_frame_pc (get_current_frame ()), 0); | |
35b1e5cc SS |
2410 | } |
2411 | else | |
42e08e69 | 2412 | { |
6c5b2ebe PA |
2413 | std::vector<symtab_and_line> sals |
2414 | = decode_line_with_current_source (args, DECODE_LINE_FUNFIRSTLINE); | |
2415 | sal = sals[0]; | |
35b1e5cc | 2416 | } |
6c5b2ebe | 2417 | |
35b1e5cc | 2418 | if (sal.symtab == 0) |
42e08e69 SS |
2419 | error (_("No line number information available.")); |
2420 | ||
6c5b2ebe | 2421 | CORE_ADDR start_pc, end_pc; |
42e08e69 | 2422 | if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc)) |
35b1e5cc SS |
2423 | { |
2424 | if (start_pc == end_pc) | |
2425 | { | |
2426 | printf_filtered ("Line %d of \"%s\"", | |
05cba821 JK |
2427 | sal.line, |
2428 | symtab_to_filename_for_display (sal.symtab)); | |
35b1e5cc SS |
2429 | wrap_here (" "); |
2430 | printf_filtered (" is at address "); | |
2431 | print_address (get_current_arch (), start_pc, gdb_stdout); | |
2432 | wrap_here (" "); | |
2433 | printf_filtered (" but contains no code.\n"); | |
2434 | sal = find_pc_line (start_pc, 0); | |
2435 | if (sal.line > 0 | |
2436 | && find_line_pc_range (sal, &start_pc, &end_pc) | |
2437 | && start_pc != end_pc) | |
2438 | printf_filtered ("Attempting to find line %d instead.\n", | |
2439 | sal.line); | |
2440 | else | |
2441 | error (_("Cannot find a good line.")); | |
2442 | } | |
2443 | } | |
2444 | else | |
2445 | /* Is there any case in which we get here, and have an address | |
2446 | which the user would want to see? If we have debugging | |
2447 | symbols and no line numbers? */ | |
2448 | error (_("Line number %d is out of range for \"%s\"."), | |
05cba821 | 2449 | sal.line, symtab_to_filename_for_display (sal.symtab)); |
35b1e5cc SS |
2450 | |
2451 | /* Find within range of stated line. */ | |
2452 | if (args && *args) | |
f197e0f1 | 2453 | tfind_1 (tfind_range, 0, start_pc, end_pc - 1, from_tty); |
c906108c | 2454 | else |
f197e0f1 | 2455 | tfind_1 (tfind_outside, 0, start_pc, end_pc - 1, from_tty); |
c906108c SS |
2456 | } |
2457 | ||
2458 | /* tfind range command */ | |
2459 | static void | |
2983f7cb | 2460 | tfind_range_command (const char *args, int from_tty) |
104c1213 | 2461 | { |
c906108c | 2462 | static CORE_ADDR start, stop; |
2983f7cb | 2463 | const char *tmp; |
c906108c | 2464 | |
cc3da688 | 2465 | check_trace_running (current_trace_status ()); |
c906108c | 2466 | |
35b1e5cc SS |
2467 | if (args == 0 || *args == 0) |
2468 | { /* XXX FIXME: what should default behavior be? */ | |
2469 | printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n"); | |
2470 | return; | |
2471 | } | |
c906108c | 2472 | |
35b1e5cc SS |
2473 | if (0 != (tmp = strchr (args, ','))) |
2474 | { | |
2983f7cb TT |
2475 | std::string start_addr (args, tmp); |
2476 | ++tmp; | |
529480d0 | 2477 | tmp = skip_spaces (tmp); |
2983f7cb | 2478 | start = parse_and_eval_address (start_addr.c_str ()); |
35b1e5cc | 2479 | stop = parse_and_eval_address (tmp); |
c906108c SS |
2480 | } |
2481 | else | |
c378eb4e | 2482 | { /* No explicit end address? */ |
35b1e5cc SS |
2483 | start = parse_and_eval_address (args); |
2484 | stop = start + 1; /* ??? */ | |
2485 | } | |
2486 | ||
f197e0f1 | 2487 | tfind_1 (tfind_range, 0, start, stop, from_tty); |
c906108c SS |
2488 | } |
2489 | ||
2490 | /* tfind outside command */ | |
2491 | static void | |
2983f7cb | 2492 | tfind_outside_command (const char *args, int from_tty) |
104c1213 | 2493 | { |
c906108c | 2494 | CORE_ADDR start, stop; |
2983f7cb | 2495 | const char *tmp; |
c906108c | 2496 | |
f5911ea1 HAQ |
2497 | if (current_trace_status ()->running |
2498 | && current_trace_status ()->filename == NULL) | |
a73c6dcd | 2499 | error (_("May not look at trace frames while trace is running.")); |
c906108c | 2500 | |
35b1e5cc | 2501 | if (args == 0 || *args == 0) |
c378eb4e | 2502 | { /* XXX FIXME: what should default behavior be? */ |
35b1e5cc SS |
2503 | printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n"); |
2504 | return; | |
2505 | } | |
c906108c | 2506 | |
35b1e5cc SS |
2507 | if (0 != (tmp = strchr (args, ','))) |
2508 | { | |
2983f7cb TT |
2509 | std::string start_addr (args, tmp); |
2510 | ++tmp; | |
529480d0 | 2511 | tmp = skip_spaces (tmp); |
2983f7cb | 2512 | start = parse_and_eval_address (start_addr.c_str ()); |
35b1e5cc | 2513 | stop = parse_and_eval_address (tmp); |
c906108c SS |
2514 | } |
2515 | else | |
c378eb4e | 2516 | { /* No explicit end address? */ |
35b1e5cc SS |
2517 | start = parse_and_eval_address (args); |
2518 | stop = start + 1; /* ??? */ | |
2519 | } | |
2520 | ||
f197e0f1 | 2521 | tfind_1 (tfind_outside, 0, start, stop, from_tty); |
c906108c SS |
2522 | } |
2523 | ||
c906108c SS |
2524 | /* info scope command: list the locals for a scope. */ |
2525 | static void | |
f2fc3015 | 2526 | info_scope_command (char *args_in, int from_tty) |
c906108c | 2527 | { |
c906108c | 2528 | struct symbol *sym; |
3b7344d5 | 2529 | struct bound_minimal_symbol msym; |
3977b71f | 2530 | const struct block *block; |
0d5cff50 | 2531 | const char *symname; |
f2fc3015 | 2532 | const char *save_args = args_in; |
8157b174 | 2533 | struct block_iterator iter; |
de4f826b | 2534 | int j, count = 0; |
768a979c UW |
2535 | struct gdbarch *gdbarch; |
2536 | int regno; | |
f2fc3015 | 2537 | const char *args = args_in; |
c906108c SS |
2538 | |
2539 | if (args == 0 || *args == 0) | |
3e43a32a MS |
2540 | error (_("requires an argument (function, " |
2541 | "line or *addr) to define a scope")); | |
c906108c | 2542 | |
ffc2605c TT |
2543 | event_location_up location = string_to_event_location (&args, |
2544 | current_language); | |
6c5b2ebe PA |
2545 | std::vector<symtab_and_line> sals |
2546 | = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
2547 | NULL, NULL, 0); | |
2548 | if (sals.empty ()) | |
f00aae0f KS |
2549 | { |
2550 | /* Presumably decode_line_1 has already warned. */ | |
f00aae0f KS |
2551 | return; |
2552 | } | |
c906108c | 2553 | |
c378eb4e | 2554 | /* Resolve line numbers to PC. */ |
6c5b2ebe PA |
2555 | resolve_sal_pc (&sals[0]); |
2556 | block = block_for_pc (sals[0].pc); | |
c906108c SS |
2557 | |
2558 | while (block != 0) | |
2559 | { | |
c378eb4e | 2560 | QUIT; /* Allow user to bail out with ^C. */ |
de4f826b | 2561 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
c906108c | 2562 | { |
c378eb4e | 2563 | QUIT; /* Allow user to bail out with ^C. */ |
c906108c SS |
2564 | if (count == 0) |
2565 | printf_filtered ("Scope for %s:\n", save_args); | |
2566 | count++; | |
e88c90f2 | 2567 | |
3567439c | 2568 | symname = SYMBOL_PRINT_NAME (sym); |
c906108c | 2569 | if (symname == NULL || *symname == '\0') |
c378eb4e | 2570 | continue; /* Probably botched, certainly useless. */ |
c906108c | 2571 | |
08be3fe3 | 2572 | gdbarch = symbol_arch (sym); |
768a979c | 2573 | |
c906108c | 2574 | printf_filtered ("Symbol %s is ", symname); |
24d6c2a0 TT |
2575 | |
2576 | if (SYMBOL_COMPUTED_OPS (sym) != NULL) | |
2577 | SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, | |
2578 | BLOCK_START (block), | |
2579 | gdb_stdout); | |
2580 | else | |
c5aa993b | 2581 | { |
24d6c2a0 | 2582 | switch (SYMBOL_CLASS (sym)) |
c5aa993b | 2583 | { |
24d6c2a0 TT |
2584 | default: |
2585 | case LOC_UNDEF: /* Messed up symbol? */ | |
2586 | printf_filtered ("a bogus symbol, class %d.\n", | |
2587 | SYMBOL_CLASS (sym)); | |
2588 | count--; /* Don't count this one. */ | |
2589 | continue; | |
2590 | case LOC_CONST: | |
2591 | printf_filtered ("a constant with value %s (%s)", | |
2592 | plongest (SYMBOL_VALUE (sym)), | |
2593 | hex_string (SYMBOL_VALUE (sym))); | |
2594 | break; | |
2595 | case LOC_CONST_BYTES: | |
2596 | printf_filtered ("constant bytes: "); | |
2597 | if (SYMBOL_TYPE (sym)) | |
2598 | for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++) | |
2599 | fprintf_filtered (gdb_stdout, " %02x", | |
2600 | (unsigned) SYMBOL_VALUE_BYTES (sym)[j]); | |
2601 | break; | |
2602 | case LOC_STATIC: | |
2603 | printf_filtered ("in static storage at address "); | |
2604 | printf_filtered ("%s", paddress (gdbarch, | |
2605 | SYMBOL_VALUE_ADDRESS (sym))); | |
2606 | break; | |
2607 | case LOC_REGISTER: | |
2608 | /* GDBARCH is the architecture associated with the objfile | |
2609 | the symbol is defined in; the target architecture may be | |
2610 | different, and may provide additional registers. However, | |
2611 | we do not know the target architecture at this point. | |
2612 | We assume the objfile architecture will contain all the | |
2613 | standard registers that occur in debug info in that | |
2614 | objfile. */ | |
2615 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, | |
2616 | gdbarch); | |
2617 | ||
2618 | if (SYMBOL_IS_ARGUMENT (sym)) | |
2619 | printf_filtered ("an argument in register $%s", | |
2620 | gdbarch_register_name (gdbarch, regno)); | |
2621 | else | |
2622 | printf_filtered ("a local variable in register $%s", | |
2623 | gdbarch_register_name (gdbarch, regno)); | |
2624 | break; | |
2625 | case LOC_ARG: | |
2626 | printf_filtered ("an argument at stack/frame offset %s", | |
2627 | plongest (SYMBOL_VALUE (sym))); | |
2628 | break; | |
2629 | case LOC_LOCAL: | |
2630 | printf_filtered ("a local variable at frame offset %s", | |
2631 | plongest (SYMBOL_VALUE (sym))); | |
2632 | break; | |
2633 | case LOC_REF_ARG: | |
2634 | printf_filtered ("a reference argument at offset %s", | |
2635 | plongest (SYMBOL_VALUE (sym))); | |
2636 | break; | |
2637 | case LOC_REGPARM_ADDR: | |
2638 | /* Note comment at LOC_REGISTER. */ | |
2639 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, | |
2640 | gdbarch); | |
2641 | printf_filtered ("the address of an argument, in register $%s", | |
2642 | gdbarch_register_name (gdbarch, regno)); | |
2643 | break; | |
2644 | case LOC_TYPEDEF: | |
2645 | printf_filtered ("a typedef.\n"); | |
2646 | continue; | |
2647 | case LOC_LABEL: | |
2648 | printf_filtered ("a label at address "); | |
2649 | printf_filtered ("%s", paddress (gdbarch, | |
2650 | SYMBOL_VALUE_ADDRESS (sym))); | |
2651 | break; | |
2652 | case LOC_BLOCK: | |
2653 | printf_filtered ("a function at address "); | |
5af949e3 | 2654 | printf_filtered ("%s", |
24d6c2a0 TT |
2655 | paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym)))); |
2656 | break; | |
2657 | case LOC_UNRESOLVED: | |
2658 | msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), | |
2659 | NULL, NULL); | |
3b7344d5 | 2660 | if (msym.minsym == NULL) |
24d6c2a0 TT |
2661 | printf_filtered ("Unresolved Static"); |
2662 | else | |
2663 | { | |
2664 | printf_filtered ("static storage at address "); | |
2665 | printf_filtered ("%s", | |
2666 | paddress (gdbarch, | |
77e371c0 | 2667 | BMSYMBOL_VALUE_ADDRESS (msym))); |
24d6c2a0 TT |
2668 | } |
2669 | break; | |
2670 | case LOC_OPTIMIZED_OUT: | |
2671 | printf_filtered ("optimized out.\n"); | |
2672 | continue; | |
2673 | case LOC_COMPUTED: | |
2674 | gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method")); | |
c5aa993b | 2675 | } |
c5aa993b | 2676 | } |
c906108c | 2677 | if (SYMBOL_TYPE (sym)) |
c5aa993b | 2678 | printf_filtered (", length %d.\n", |
450bd37b | 2679 | TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)))); |
c906108c SS |
2680 | } |
2681 | if (BLOCK_FUNCTION (block)) | |
2682 | break; | |
2683 | else | |
2684 | block = BLOCK_SUPERBLOCK (block); | |
2685 | } | |
2686 | if (count <= 0) | |
2687 | printf_filtered ("Scope for %s contains no locals or arguments.\n", | |
2688 | save_args); | |
2689 | } | |
2690 | ||
afd02f27 PA |
2691 | /* Helper for trace_dump_command. Dump the action list starting at |
2692 | ACTION. STEPPING_ACTIONS is true if we're iterating over the | |
2693 | actions of the body of a while-stepping action. STEPPING_FRAME is | |
2694 | set if the current traceframe was determined to be a while-stepping | |
2695 | traceframe. */ | |
2696 | ||
c906108c | 2697 | static void |
afd02f27 PA |
2698 | trace_dump_actions (struct command_line *action, |
2699 | int stepping_actions, int stepping_frame, | |
2700 | int from_tty) | |
c906108c | 2701 | { |
6f937416 | 2702 | const char *action_exp, *next_comma; |
c906108c | 2703 | |
afd02f27 | 2704 | for (; action != NULL; action = action->next) |
c906108c SS |
2705 | { |
2706 | struct cmd_list_element *cmd; | |
2707 | ||
c378eb4e | 2708 | QUIT; /* Allow user to bail out with ^C. */ |
a7bdde9e | 2709 | action_exp = action->line; |
f1735a53 | 2710 | action_exp = skip_spaces (action_exp); |
c906108c SS |
2711 | |
2712 | /* The collection actions to be done while stepping are | |
c5aa993b | 2713 | bracketed by the commands "while-stepping" and "end". */ |
c906108c SS |
2714 | |
2715 | if (*action_exp == '#') /* comment line */ | |
2716 | continue; | |
2717 | ||
2718 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); | |
2719 | if (cmd == 0) | |
8a3fe4f8 | 2720 | error (_("Bad action list item: %s"), action_exp); |
c906108c | 2721 | |
bbaca940 | 2722 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
afd02f27 PA |
2723 | { |
2724 | int i; | |
2725 | ||
2726 | for (i = 0; i < action->body_count; ++i) | |
2727 | trace_dump_actions (action->body_list[i], | |
2728 | 1, stepping_frame, from_tty); | |
2729 | } | |
bbaca940 | 2730 | else if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
c906108c SS |
2731 | { |
2732 | /* Display the collected data. | |
d183932d MS |
2733 | For the trap frame, display only what was collected at |
2734 | the trap. Likewise for stepping frames, display only | |
2735 | what was collected while stepping. This means that the | |
2736 | two boolean variables, STEPPING_FRAME and | |
2737 | STEPPING_ACTIONS should be equal. */ | |
c906108c SS |
2738 | if (stepping_frame == stepping_actions) |
2739 | { | |
6f937416 PA |
2740 | char *cmd = NULL; |
2741 | struct cleanup *old_chain | |
2742 | = make_cleanup (free_current_contents, &cmd); | |
92bc6a20 | 2743 | int trace_string = 0; |
6f937416 | 2744 | |
3065dfb6 | 2745 | if (*action_exp == '/') |
92bc6a20 | 2746 | action_exp = decode_agent_options (action_exp, &trace_string); |
3065dfb6 | 2747 | |
c5aa993b | 2748 | do |
c378eb4e MS |
2749 | { /* Repeat over a comma-separated list. */ |
2750 | QUIT; /* Allow user to bail out with ^C. */ | |
c5aa993b JM |
2751 | if (*action_exp == ',') |
2752 | action_exp++; | |
f1735a53 | 2753 | action_exp = skip_spaces (action_exp); |
c5aa993b JM |
2754 | |
2755 | next_comma = strchr (action_exp, ','); | |
2756 | ||
2757 | if (0 == strncasecmp (action_exp, "$reg", 4)) | |
2758 | registers_info (NULL, from_tty); | |
6710bf39 SS |
2759 | else if (0 == strncasecmp (action_exp, "$_ret", 5)) |
2760 | ; | |
c5aa993b | 2761 | else if (0 == strncasecmp (action_exp, "$loc", 4)) |
11db9430 | 2762 | info_locals_command (NULL, from_tty); |
c5aa993b | 2763 | else if (0 == strncasecmp (action_exp, "$arg", 4)) |
11db9430 | 2764 | info_args_command (NULL, from_tty); |
c5aa993b JM |
2765 | else |
2766 | { /* variable */ | |
6f937416 | 2767 | if (next_comma != NULL) |
c5aa993b | 2768 | { |
6f937416 PA |
2769 | size_t len = next_comma - action_exp; |
2770 | ||
224c3ddb | 2771 | cmd = (char *) xrealloc (cmd, len + 1); |
6f937416 PA |
2772 | memcpy (cmd, action_exp, len); |
2773 | cmd[len] = 0; | |
2774 | } | |
2775 | else | |
2776 | { | |
2777 | size_t len = strlen (action_exp); | |
2778 | ||
224c3ddb | 2779 | cmd = (char *) xrealloc (cmd, len + 1); |
6f937416 | 2780 | memcpy (cmd, action_exp, len + 1); |
c5aa993b | 2781 | } |
6f937416 PA |
2782 | |
2783 | printf_filtered ("%s = ", cmd); | |
2784 | output_command_const (cmd, from_tty); | |
c5aa993b JM |
2785 | printf_filtered ("\n"); |
2786 | } | |
c5aa993b JM |
2787 | action_exp = next_comma; |
2788 | } | |
2789 | while (action_exp && *action_exp == ','); | |
6f937416 PA |
2790 | |
2791 | do_cleanups (old_chain); | |
c906108c SS |
2792 | } |
2793 | } | |
2794 | } | |
afd02f27 PA |
2795 | } |
2796 | ||
ddacd3c8 YQ |
2797 | /* Return bp_location of the tracepoint associated with the current |
2798 | traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe | |
2799 | is a stepping traceframe. */ | |
2800 | ||
dc673c81 | 2801 | struct bp_location * |
ddacd3c8 YQ |
2802 | get_traceframe_location (int *stepping_frame_p) |
2803 | { | |
2804 | struct tracepoint *t; | |
2805 | struct bp_location *tloc; | |
2806 | struct regcache *regcache; | |
2807 | ||
2808 | if (tracepoint_number == -1) | |
2809 | error (_("No current trace frame.")); | |
2810 | ||
2811 | t = get_tracepoint (tracepoint_number); | |
2812 | ||
2813 | if (t == NULL) | |
2814 | error (_("No known tracepoint matches 'current' tracepoint #%d."), | |
2815 | tracepoint_number); | |
2816 | ||
2817 | /* The current frame is a trap frame if the frame PC is equal to the | |
2818 | tracepoint PC. If not, then the current frame was collected | |
2819 | during single-stepping. */ | |
2820 | regcache = get_current_regcache (); | |
2821 | ||
2822 | /* If the traceframe's address matches any of the tracepoint's | |
2823 | locations, assume it is a direct hit rather than a while-stepping | |
2824 | frame. (FIXME this is not reliable, should record each frame's | |
2825 | type.) */ | |
c1fc2657 | 2826 | for (tloc = t->loc; tloc; tloc = tloc->next) |
ddacd3c8 YQ |
2827 | if (tloc->address == regcache_read_pc (regcache)) |
2828 | { | |
2829 | *stepping_frame_p = 0; | |
2830 | return tloc; | |
2831 | } | |
2832 | ||
2833 | /* If this is a stepping frame, we don't know which location | |
2834 | triggered. The first is as good (or bad) a guess as any... */ | |
2835 | *stepping_frame_p = 1; | |
c1fc2657 | 2836 | return t->loc; |
ddacd3c8 YQ |
2837 | } |
2838 | ||
3ca73e0c YQ |
2839 | /* Return all the actions, including default collect, of a tracepoint |
2840 | T. It constructs cleanups into the chain, and leaves the caller to | |
2841 | handle them (call do_cleanups). */ | |
2842 | ||
2843 | static struct command_line * | |
2844 | all_tracepoint_actions_and_cleanup (struct breakpoint *t) | |
2845 | { | |
2846 | struct command_line *actions; | |
2847 | ||
2848 | actions = breakpoint_commands (t); | |
2849 | ||
2850 | /* If there are default expressions to collect, make up a collect | |
2851 | action and prepend to the action list to encode. Note that since | |
2852 | validation is per-tracepoint (local var "xyz" might be valid for | |
2853 | one tracepoint and not another, etc), we make up the action on | |
2854 | the fly, and don't cache it. */ | |
2855 | if (*default_collect) | |
2856 | { | |
2857 | struct command_line *default_collect_action; | |
2858 | char *default_collect_line; | |
2859 | ||
2860 | default_collect_line = xstrprintf ("collect %s", default_collect); | |
2861 | make_cleanup (xfree, default_collect_line); | |
2862 | ||
2863 | validate_actionline (default_collect_line, t); | |
8d749320 | 2864 | default_collect_action = XNEW (struct command_line); |
3ca73e0c YQ |
2865 | make_cleanup (xfree, default_collect_action); |
2866 | default_collect_action->next = actions; | |
2867 | default_collect_action->line = default_collect_line; | |
2868 | actions = default_collect_action; | |
2869 | } | |
2870 | ||
2871 | return actions; | |
2872 | } | |
2873 | ||
afd02f27 PA |
2874 | /* The tdump command. */ |
2875 | ||
2876 | static void | |
e5a873b7 | 2877 | tdump_command (char *args, int from_tty) |
afd02f27 | 2878 | { |
afd02f27 PA |
2879 | int stepping_frame = 0; |
2880 | struct bp_location *loc; | |
ddacd3c8 | 2881 | struct command_line *actions; |
afd02f27 | 2882 | |
ddacd3c8 YQ |
2883 | /* This throws an error is not inspecting a trace frame. */ |
2884 | loc = get_traceframe_location (&stepping_frame); | |
afd02f27 PA |
2885 | |
2886 | printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n", | |
2887 | tracepoint_number, traceframe_number); | |
2888 | ||
de74e63a YQ |
2889 | /* This command only makes sense for the current frame, not the |
2890 | selected frame. */ | |
5ed8105e PA |
2891 | scoped_restore_current_thread restore_thread; |
2892 | ||
de74e63a YQ |
2893 | select_frame (get_current_frame ()); |
2894 | ||
ddacd3c8 | 2895 | actions = all_tracepoint_actions_and_cleanup (loc->owner); |
2114d44c SS |
2896 | |
2897 | trace_dump_actions (actions, 0, stepping_frame, from_tty); | |
c906108c SS |
2898 | } |
2899 | ||
409873ef SS |
2900 | /* Encode a piece of a tracepoint's source-level definition in a form |
2901 | that is suitable for both protocol and saving in files. */ | |
2902 | /* This version does not do multiple encodes for long strings; it should | |
2903 | return an offset to the next piece to encode. FIXME */ | |
2904 | ||
a121b7c1 | 2905 | int |
409873ef | 2906 | encode_source_string (int tpnum, ULONGEST addr, |
a121b7c1 PA |
2907 | const char *srctype, const char *src, |
2908 | char *buf, int buf_size) | |
409873ef SS |
2909 | { |
2910 | if (80 + strlen (srctype) > buf_size) | |
2911 | error (_("Buffer too small for source encoding")); | |
2912 | sprintf (buf, "%x:%s:%s:%x:%x:", | |
3e43a32a MS |
2913 | tpnum, phex_nz (addr, sizeof (addr)), |
2914 | srctype, 0, (int) strlen (src)); | |
409873ef SS |
2915 | if (strlen (buf) + strlen (src) * 2 >= buf_size) |
2916 | error (_("Source string too long for buffer")); | |
9f1b45b0 | 2917 | bin2hex ((gdb_byte *) src, buf + strlen (buf), strlen (src)); |
409873ef SS |
2918 | return -1; |
2919 | } | |
2920 | ||
d5551862 SS |
2921 | /* Tell the target what to do with an ongoing tracing run if GDB |
2922 | disconnects for some reason. */ | |
2923 | ||
d5551862 SS |
2924 | static void |
2925 | set_disconnected_tracing (char *args, int from_tty, | |
2926 | struct cmd_list_element *c) | |
2927 | { | |
f196051f | 2928 | target_set_disconnected_tracing (disconnected_tracing); |
d5551862 SS |
2929 | } |
2930 | ||
4daf5ac0 SS |
2931 | static void |
2932 | set_circular_trace_buffer (char *args, int from_tty, | |
2933 | struct cmd_list_element *c) | |
2934 | { | |
2935 | target_set_circular_trace_buffer (circular_trace_buffer); | |
2936 | } | |
2937 | ||
f6f899bf HAQ |
2938 | static void |
2939 | set_trace_buffer_size (char *args, int from_tty, | |
2940 | struct cmd_list_element *c) | |
2941 | { | |
2942 | target_set_trace_buffer_size (trace_buffer_size); | |
2943 | } | |
2944 | ||
f196051f SS |
2945 | static void |
2946 | set_trace_user (char *args, int from_tty, | |
2947 | struct cmd_list_element *c) | |
2948 | { | |
2949 | int ret; | |
2950 | ||
2951 | ret = target_set_trace_notes (trace_user, NULL, NULL); | |
2952 | ||
2953 | if (!ret) | |
43011e52 | 2954 | warning (_("Target does not support trace notes, user ignored")); |
f196051f SS |
2955 | } |
2956 | ||
2957 | static void | |
2958 | set_trace_notes (char *args, int from_tty, | |
2959 | struct cmd_list_element *c) | |
2960 | { | |
2961 | int ret; | |
2962 | ||
2963 | ret = target_set_trace_notes (NULL, trace_notes, NULL); | |
2964 | ||
2965 | if (!ret) | |
43011e52 | 2966 | warning (_("Target does not support trace notes, note ignored")); |
f196051f SS |
2967 | } |
2968 | ||
2969 | static void | |
2970 | set_trace_stop_notes (char *args, int from_tty, | |
2971 | struct cmd_list_element *c) | |
2972 | { | |
2973 | int ret; | |
2974 | ||
2975 | ret = target_set_trace_notes (NULL, NULL, trace_stop_notes); | |
2976 | ||
2977 | if (!ret) | |
43011e52 | 2978 | warning (_("Target does not support trace notes, stop note ignored")); |
f196051f SS |
2979 | } |
2980 | ||
c906108c SS |
2981 | /* Convert the memory pointed to by mem into hex, placing result in buf. |
2982 | * Return a pointer to the last char put in buf (null) | |
2983 | * "stolen" from sparc-stub.c | |
2984 | */ | |
2985 | ||
c5aa993b | 2986 | static const char hexchars[] = "0123456789abcdef"; |
c906108c | 2987 | |
47b667de AC |
2988 | static char * |
2989 | mem2hex (gdb_byte *mem, char *buf, int count) | |
c906108c | 2990 | { |
47b667de | 2991 | gdb_byte ch; |
c906108c SS |
2992 | |
2993 | while (count-- > 0) | |
2994 | { | |
2995 | ch = *mem++; | |
2996 | ||
2997 | *buf++ = hexchars[ch >> 4]; | |
2998 | *buf++ = hexchars[ch & 0xf]; | |
2999 | } | |
3000 | ||
3001 | *buf = 0; | |
3002 | ||
3003 | return buf; | |
3004 | } | |
3005 | ||
c5aa993b | 3006 | int |
fba45db2 | 3007 | get_traceframe_number (void) |
c906108c | 3008 | { |
c5aa993b | 3009 | return traceframe_number; |
c906108c SS |
3010 | } |
3011 | ||
393fd4c3 YQ |
3012 | int |
3013 | get_tracepoint_number (void) | |
3014 | { | |
3015 | return tracepoint_number; | |
3016 | } | |
3017 | ||
06cd862c PA |
3018 | /* Make the traceframe NUM be the current trace frame. Does nothing |
3019 | if NUM is already current. */ | |
3020 | ||
3021 | void | |
e6e4e701 | 3022 | set_current_traceframe (int num) |
06cd862c PA |
3023 | { |
3024 | int newnum; | |
3025 | ||
3026 | if (traceframe_number == num) | |
3027 | { | |
3028 | /* Nothing to do. */ | |
3029 | return; | |
3030 | } | |
3031 | ||
3032 | newnum = target_trace_find (tfind_number, num, 0, 0, NULL); | |
3033 | ||
3034 | if (newnum != num) | |
3035 | warning (_("could not change traceframe")); | |
3036 | ||
8d735b87 | 3037 | set_traceframe_num (newnum); |
06cd862c PA |
3038 | |
3039 | /* Changing the traceframe changes our view of registers and of the | |
3040 | frame chain. */ | |
3041 | registers_changed (); | |
b3b9301e PA |
3042 | |
3043 | clear_traceframe_info (); | |
06cd862c PA |
3044 | } |
3045 | ||
3046 | /* A cleanup used when switching away and back from tfind mode. */ | |
3047 | ||
3048 | struct current_traceframe_cleanup | |
3049 | { | |
3050 | /* The traceframe we were inspecting. */ | |
3051 | int traceframe_number; | |
3052 | }; | |
3053 | ||
3054 | static void | |
3055 | do_restore_current_traceframe_cleanup (void *arg) | |
3056 | { | |
19ba03f4 SM |
3057 | struct current_traceframe_cleanup *old |
3058 | = (struct current_traceframe_cleanup *) arg; | |
06cd862c | 3059 | |
e6e4e701 | 3060 | set_current_traceframe (old->traceframe_number); |
06cd862c PA |
3061 | } |
3062 | ||
3063 | static void | |
3064 | restore_current_traceframe_cleanup_dtor (void *arg) | |
3065 | { | |
19ba03f4 SM |
3066 | struct current_traceframe_cleanup *old |
3067 | = (struct current_traceframe_cleanup *) arg; | |
06cd862c PA |
3068 | |
3069 | xfree (old); | |
3070 | } | |
3071 | ||
3072 | struct cleanup * | |
3073 | make_cleanup_restore_current_traceframe (void) | |
3074 | { | |
8d749320 SM |
3075 | struct current_traceframe_cleanup *old = |
3076 | XNEW (struct current_traceframe_cleanup); | |
06cd862c | 3077 | |
06cd862c PA |
3078 | old->traceframe_number = traceframe_number; |
3079 | ||
3080 | return make_cleanup_dtor (do_restore_current_traceframe_cleanup, old, | |
3081 | restore_current_traceframe_cleanup_dtor); | |
3082 | } | |
00bf0b85 SS |
3083 | |
3084 | /* Given a number and address, return an uploaded tracepoint with that | |
3085 | number, creating if necessary. */ | |
3086 | ||
3087 | struct uploaded_tp * | |
3088 | get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp) | |
3089 | { | |
3090 | struct uploaded_tp *utp; | |
3091 | ||
3092 | for (utp = *utpp; utp; utp = utp->next) | |
3093 | if (utp->number == num && utp->addr == addr) | |
3094 | return utp; | |
8d749320 SM |
3095 | |
3096 | utp = XCNEW (struct uploaded_tp); | |
00bf0b85 SS |
3097 | utp->number = num; |
3098 | utp->addr = addr; | |
3149d8c1 SS |
3099 | utp->actions = NULL; |
3100 | utp->step_actions = NULL; | |
3101 | utp->cmd_strings = NULL; | |
00bf0b85 SS |
3102 | utp->next = *utpp; |
3103 | *utpp = utp; | |
8d749320 | 3104 | |
00bf0b85 SS |
3105 | return utp; |
3106 | } | |
3107 | ||
7951c4eb | 3108 | void |
00bf0b85 SS |
3109 | free_uploaded_tps (struct uploaded_tp **utpp) |
3110 | { | |
3111 | struct uploaded_tp *next_one; | |
3112 | ||
3113 | while (*utpp) | |
3114 | { | |
3115 | next_one = (*utpp)->next; | |
3116 | xfree (*utpp); | |
3117 | *utpp = next_one; | |
3118 | } | |
3119 | } | |
3120 | ||
3121 | /* Given a number and address, return an uploaded tracepoint with that | |
3122 | number, creating if necessary. */ | |
3123 | ||
393fd4c3 | 3124 | struct uploaded_tsv * |
00bf0b85 SS |
3125 | get_uploaded_tsv (int num, struct uploaded_tsv **utsvp) |
3126 | { | |
3127 | struct uploaded_tsv *utsv; | |
3128 | ||
3129 | for (utsv = *utsvp; utsv; utsv = utsv->next) | |
3130 | if (utsv->number == num) | |
3131 | return utsv; | |
8d749320 SM |
3132 | |
3133 | utsv = XCNEW (struct uploaded_tsv); | |
00bf0b85 SS |
3134 | utsv->number = num; |
3135 | utsv->next = *utsvp; | |
3136 | *utsvp = utsv; | |
8d749320 | 3137 | |
00bf0b85 SS |
3138 | return utsv; |
3139 | } | |
3140 | ||
7951c4eb | 3141 | void |
00bf0b85 SS |
3142 | free_uploaded_tsvs (struct uploaded_tsv **utsvp) |
3143 | { | |
3144 | struct uploaded_tsv *next_one; | |
3145 | ||
3146 | while (*utsvp) | |
3147 | { | |
3148 | next_one = (*utsvp)->next; | |
3149 | xfree (*utsvp); | |
3150 | *utsvp = next_one; | |
3151 | } | |
3152 | } | |
3153 | ||
4e5c165d HZ |
3154 | /* FIXME this function is heuristic and will miss the cases where the |
3155 | conditional is semantically identical but differs in whitespace, | |
3156 | such as "x == 0" vs "x==0". */ | |
3157 | ||
3158 | static int | |
3159 | cond_string_is_same (char *str1, char *str2) | |
3160 | { | |
3161 | if (str1 == NULL || str2 == NULL) | |
3162 | return (str1 == str2); | |
3163 | ||
3164 | return (strcmp (str1, str2) == 0); | |
3165 | } | |
3166 | ||
00bf0b85 SS |
3167 | /* Look for an existing tracepoint that seems similar enough to the |
3168 | uploaded one. Enablement isn't compared, because the user can | |
3169 | toggle that freely, and may have done so in anticipation of the | |
1e4d1764 | 3170 | next trace run. Return the location of matched tracepoint. */ |
00bf0b85 | 3171 | |
70221824 | 3172 | static struct bp_location * |
1e4d1764 | 3173 | find_matching_tracepoint_location (struct uploaded_tp *utp) |
00bf0b85 SS |
3174 | { |
3175 | VEC(breakpoint_p) *tp_vec = all_tracepoints (); | |
3176 | int ix; | |
d9b3f62e | 3177 | struct breakpoint *b; |
00bf0b85 SS |
3178 | struct bp_location *loc; |
3179 | ||
d9b3f62e | 3180 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
00bf0b85 | 3181 | { |
d9b3f62e PA |
3182 | struct tracepoint *t = (struct tracepoint *) b; |
3183 | ||
3184 | if (b->type == utp->type | |
00bf0b85 SS |
3185 | && t->step_count == utp->step |
3186 | && t->pass_count == utp->pass | |
c1fc2657 | 3187 | && cond_string_is_same (t->cond_string, utp->cond_string) |
4e5c165d | 3188 | /* FIXME also test actions. */ |
00bf0b85 SS |
3189 | ) |
3190 | { | |
3191 | /* Scan the locations for an address match. */ | |
d9b3f62e | 3192 | for (loc = b->loc; loc; loc = loc->next) |
00bf0b85 SS |
3193 | { |
3194 | if (loc->address == utp->addr) | |
1e4d1764 | 3195 | return loc; |
00bf0b85 SS |
3196 | } |
3197 | } | |
3198 | } | |
3199 | return NULL; | |
3200 | } | |
3201 | ||
3202 | /* Given a list of tracepoints uploaded from a target, attempt to | |
3203 | match them up with existing tracepoints, and create new ones if not | |
3204 | found. */ | |
3205 | ||
3206 | void | |
3207 | merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps) | |
3208 | { | |
3209 | struct uploaded_tp *utp; | |
f2a8bc8a YQ |
3210 | /* A set of tracepoints which are modified. */ |
3211 | VEC(breakpoint_p) *modified_tp = NULL; | |
3212 | int ix; | |
3213 | struct breakpoint *b; | |
00bf0b85 SS |
3214 | |
3215 | /* Look for GDB tracepoints that match up with our uploaded versions. */ | |
3216 | for (utp = *uploaded_tps; utp; utp = utp->next) | |
3217 | { | |
1e4d1764 YQ |
3218 | struct bp_location *loc; |
3219 | struct tracepoint *t; | |
3220 | ||
3221 | loc = find_matching_tracepoint_location (utp); | |
3222 | if (loc) | |
3223 | { | |
f2a8bc8a YQ |
3224 | int found = 0; |
3225 | ||
1e4d1764 YQ |
3226 | /* Mark this location as already inserted. */ |
3227 | loc->inserted = 1; | |
3228 | t = (struct tracepoint *) loc->owner; | |
3229 | printf_filtered (_("Assuming tracepoint %d is same " | |
3230 | "as target's tracepoint %d at %s.\n"), | |
3231 | loc->owner->number, utp->number, | |
3232 | paddress (loc->gdbarch, utp->addr)); | |
f2a8bc8a YQ |
3233 | |
3234 | /* The tracepoint LOC->owner was modified (the location LOC | |
3235 | was marked as inserted in the target). Save it in | |
3236 | MODIFIED_TP if not there yet. The 'breakpoint-modified' | |
3237 | observers will be notified later once for each tracepoint | |
3238 | saved in MODIFIED_TP. */ | |
3239 | for (ix = 0; | |
3240 | VEC_iterate (breakpoint_p, modified_tp, ix, b); | |
3241 | ix++) | |
3242 | if (b == loc->owner) | |
3243 | { | |
3244 | found = 1; | |
3245 | break; | |
3246 | } | |
3247 | if (!found) | |
3248 | VEC_safe_push (breakpoint_p, modified_tp, loc->owner); | |
1e4d1764 | 3249 | } |
00bf0b85 SS |
3250 | else |
3251 | { | |
3252 | t = create_tracepoint_from_upload (utp); | |
3253 | if (t) | |
3e43a32a MS |
3254 | printf_filtered (_("Created tracepoint %d for " |
3255 | "target's tracepoint %d at %s.\n"), | |
c1fc2657 | 3256 | t->number, utp->number, |
3e43a32a | 3257 | paddress (get_current_arch (), utp->addr)); |
00bf0b85 | 3258 | else |
3e43a32a MS |
3259 | printf_filtered (_("Failed to create tracepoint for target's " |
3260 | "tracepoint %d at %s, skipping it.\n"), | |
3261 | utp->number, | |
3262 | paddress (get_current_arch (), utp->addr)); | |
00bf0b85 SS |
3263 | } |
3264 | /* Whether found or created, record the number used by the | |
3265 | target, to help with mapping target tracepoints back to their | |
3266 | counterparts here. */ | |
3267 | if (t) | |
3268 | t->number_on_target = utp->number; | |
3269 | } | |
3270 | ||
f2a8bc8a YQ |
3271 | /* Notify 'breakpoint-modified' observer that at least one of B's |
3272 | locations was changed. */ | |
3273 | for (ix = 0; VEC_iterate (breakpoint_p, modified_tp, ix, b); ix++) | |
3274 | observer_notify_breakpoint_modified (b); | |
3275 | ||
3276 | VEC_free (breakpoint_p, modified_tp); | |
00bf0b85 SS |
3277 | free_uploaded_tps (uploaded_tps); |
3278 | } | |
3279 | ||
3280 | /* Trace state variables don't have much to identify them beyond their | |
3281 | name, so just use that to detect matches. */ | |
3282 | ||
70221824 | 3283 | static struct trace_state_variable * |
00bf0b85 SS |
3284 | find_matching_tsv (struct uploaded_tsv *utsv) |
3285 | { | |
3286 | if (!utsv->name) | |
3287 | return NULL; | |
3288 | ||
3289 | return find_trace_state_variable (utsv->name); | |
3290 | } | |
3291 | ||
70221824 | 3292 | static struct trace_state_variable * |
00bf0b85 SS |
3293 | create_tsv_from_upload (struct uploaded_tsv *utsv) |
3294 | { | |
3295 | const char *namebase; | |
8abcee91 | 3296 | std::string buf; |
00bf0b85 SS |
3297 | int try_num = 0; |
3298 | struct trace_state_variable *tsv; | |
df5a4bd3 | 3299 | struct cleanup *old_chain; |
00bf0b85 SS |
3300 | |
3301 | if (utsv->name) | |
3302 | { | |
3303 | namebase = utsv->name; | |
8abcee91 | 3304 | buf = namebase; |
00bf0b85 SS |
3305 | } |
3306 | else | |
3307 | { | |
3308 | namebase = "__tsv"; | |
8abcee91 | 3309 | buf = string_printf ("%s_%d", namebase, try_num++); |
00bf0b85 SS |
3310 | } |
3311 | ||
3312 | /* Fish for a name that is not in use. */ | |
c378eb4e | 3313 | /* (should check against all internal vars?) */ |
8abcee91 TT |
3314 | while (find_trace_state_variable (buf.c_str ())) |
3315 | buf = string_printf ("%s_%d", namebase, try_num++); | |
00bf0b85 SS |
3316 | |
3317 | /* We have an available name, create the variable. */ | |
8abcee91 | 3318 | tsv = create_trace_state_variable (buf.c_str ()); |
00bf0b85 SS |
3319 | tsv->initial_value = utsv->initial_value; |
3320 | tsv->builtin = utsv->builtin; | |
3321 | ||
134a2066 | 3322 | observer_notify_tsv_created (tsv); |
bb25a15c | 3323 | |
00bf0b85 SS |
3324 | return tsv; |
3325 | } | |
3326 | ||
3327 | /* Given a list of uploaded trace state variables, try to match them | |
3328 | up with existing variables, or create additional ones. */ | |
3329 | ||
3330 | void | |
3331 | merge_uploaded_trace_state_variables (struct uploaded_tsv **uploaded_tsvs) | |
3332 | { | |
3333 | int ix; | |
3334 | struct uploaded_tsv *utsv; | |
3335 | struct trace_state_variable *tsv; | |
3336 | int highest; | |
3337 | ||
3338 | /* Most likely some numbers will have to be reassigned as part of | |
3339 | the merge, so clear them all in anticipation. */ | |
3340 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
3341 | tsv->number = 0; | |
3342 | ||
3343 | for (utsv = *uploaded_tsvs; utsv; utsv = utsv->next) | |
3344 | { | |
3345 | tsv = find_matching_tsv (utsv); | |
3346 | if (tsv) | |
417b5110 DJ |
3347 | { |
3348 | if (info_verbose) | |
3e43a32a MS |
3349 | printf_filtered (_("Assuming trace state variable $%s " |
3350 | "is same as target's variable %d.\n"), | |
417b5110 DJ |
3351 | tsv->name, utsv->number); |
3352 | } | |
00bf0b85 SS |
3353 | else |
3354 | { | |
3355 | tsv = create_tsv_from_upload (utsv); | |
417b5110 | 3356 | if (info_verbose) |
3e43a32a MS |
3357 | printf_filtered (_("Created trace state variable " |
3358 | "$%s for target's variable %d.\n"), | |
417b5110 | 3359 | tsv->name, utsv->number); |
00bf0b85 SS |
3360 | } |
3361 | /* Give precedence to numberings that come from the target. */ | |
3362 | if (tsv) | |
3363 | tsv->number = utsv->number; | |
3364 | } | |
3365 | ||
3366 | /* Renumber everything that didn't get a target-assigned number. */ | |
3367 | highest = 0; | |
3368 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
3369 | if (tsv->number > highest) | |
3370 | highest = tsv->number; | |
3371 | ||
3372 | ++highest; | |
3373 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
3374 | if (tsv->number == 0) | |
3375 | tsv->number = highest++; | |
3376 | ||
3377 | free_uploaded_tsvs (uploaded_tsvs); | |
3378 | } | |
3379 | ||
00bf0b85 SS |
3380 | /* Parse the part of trace status syntax that is shared between |
3381 | the remote protocol and the trace file reader. */ | |
3382 | ||
00bf0b85 | 3383 | void |
256642e8 | 3384 | parse_trace_status (const char *line, struct trace_status *ts) |
00bf0b85 | 3385 | { |
256642e8 | 3386 | const char *p = line, *p1, *p2, *p3, *p_temp; |
f196051f | 3387 | int end; |
00bf0b85 SS |
3388 | ULONGEST val; |
3389 | ||
3390 | ts->running_known = 1; | |
3391 | ts->running = (*p++ == '1'); | |
3392 | ts->stop_reason = trace_stop_reason_unknown; | |
f196051f SS |
3393 | xfree (ts->stop_desc); |
3394 | ts->stop_desc = NULL; | |
4daf5ac0 SS |
3395 | ts->traceframe_count = -1; |
3396 | ts->traceframes_created = -1; | |
3397 | ts->buffer_free = -1; | |
3398 | ts->buffer_size = -1; | |
33da3f1c SS |
3399 | ts->disconnected_tracing = 0; |
3400 | ts->circular_buffer = 0; | |
f196051f SS |
3401 | xfree (ts->user_name); |
3402 | ts->user_name = NULL; | |
3403 | xfree (ts->notes); | |
3404 | ts->notes = NULL; | |
3405 | ts->start_time = ts->stop_time = 0; | |
4daf5ac0 | 3406 | |
00bf0b85 SS |
3407 | while (*p++) |
3408 | { | |
3409 | p1 = strchr (p, ':'); | |
3410 | if (p1 == NULL) | |
3411 | error (_("Malformed trace status, at %s\n\ | |
3412 | Status line: '%s'\n"), p, line); | |
f196051f SS |
3413 | p3 = strchr (p, ';'); |
3414 | if (p3 == NULL) | |
3415 | p3 = p + strlen (p); | |
00bf0b85 SS |
3416 | if (strncmp (p, stop_reason_names[trace_buffer_full], p1 - p) == 0) |
3417 | { | |
3418 | p = unpack_varlen_hex (++p1, &val); | |
3419 | ts->stop_reason = trace_buffer_full; | |
3420 | } | |
3421 | else if (strncmp (p, stop_reason_names[trace_never_run], p1 - p) == 0) | |
3422 | { | |
3423 | p = unpack_varlen_hex (++p1, &val); | |
3424 | ts->stop_reason = trace_never_run; | |
3425 | } | |
3e43a32a MS |
3426 | else if (strncmp (p, stop_reason_names[tracepoint_passcount], |
3427 | p1 - p) == 0) | |
00bf0b85 SS |
3428 | { |
3429 | p = unpack_varlen_hex (++p1, &val); | |
3430 | ts->stop_reason = tracepoint_passcount; | |
3431 | ts->stopping_tracepoint = val; | |
3432 | } | |
e5a873b7 | 3433 | else if (strncmp (p, stop_reason_names[trace_stop_command], p1 - p) == 0) |
00bf0b85 | 3434 | { |
f196051f SS |
3435 | p2 = strchr (++p1, ':'); |
3436 | if (!p2 || p2 > p3) | |
3437 | { | |
3438 | /*older style*/ | |
3439 | p2 = p1; | |
3440 | } | |
3441 | else if (p2 != p1) | |
3442 | { | |
224c3ddb | 3443 | ts->stop_desc = (char *) xmalloc (strlen (line)); |
bc20a4af | 3444 | end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2); |
f196051f SS |
3445 | ts->stop_desc[end] = '\0'; |
3446 | } | |
3447 | else | |
3448 | ts->stop_desc = xstrdup (""); | |
3449 | ||
3450 | p = unpack_varlen_hex (++p2, &val); | |
e5a873b7 | 3451 | ts->stop_reason = trace_stop_command; |
00bf0b85 | 3452 | } |
33da3f1c SS |
3453 | else if (strncmp (p, stop_reason_names[trace_disconnected], p1 - p) == 0) |
3454 | { | |
3455 | p = unpack_varlen_hex (++p1, &val); | |
3456 | ts->stop_reason = trace_disconnected; | |
3457 | } | |
6c28cbf2 SS |
3458 | else if (strncmp (p, stop_reason_names[tracepoint_error], p1 - p) == 0) |
3459 | { | |
3460 | p2 = strchr (++p1, ':'); | |
3461 | if (p2 != p1) | |
3462 | { | |
224c3ddb | 3463 | ts->stop_desc = (char *) xmalloc ((p2 - p1) / 2 + 1); |
bc20a4af | 3464 | end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2); |
f196051f | 3465 | ts->stop_desc[end] = '\0'; |
6c28cbf2 | 3466 | } |
a609a0c8 | 3467 | else |
f196051f | 3468 | ts->stop_desc = xstrdup (""); |
a609a0c8 | 3469 | |
6c28cbf2 SS |
3470 | p = unpack_varlen_hex (++p2, &val); |
3471 | ts->stopping_tracepoint = val; | |
3472 | ts->stop_reason = tracepoint_error; | |
3473 | } | |
4daf5ac0 | 3474 | else if (strncmp (p, "tframes", p1 - p) == 0) |
00bf0b85 SS |
3475 | { |
3476 | p = unpack_varlen_hex (++p1, &val); | |
3477 | ts->traceframe_count = val; | |
3478 | } | |
4daf5ac0 SS |
3479 | else if (strncmp (p, "tcreated", p1 - p) == 0) |
3480 | { | |
3481 | p = unpack_varlen_hex (++p1, &val); | |
3482 | ts->traceframes_created = val; | |
3483 | } | |
3484 | else if (strncmp (p, "tfree", p1 - p) == 0) | |
00bf0b85 SS |
3485 | { |
3486 | p = unpack_varlen_hex (++p1, &val); | |
3487 | ts->buffer_free = val; | |
3488 | } | |
4daf5ac0 SS |
3489 | else if (strncmp (p, "tsize", p1 - p) == 0) |
3490 | { | |
3491 | p = unpack_varlen_hex (++p1, &val); | |
3492 | ts->buffer_size = val; | |
3493 | } | |
33da3f1c SS |
3494 | else if (strncmp (p, "disconn", p1 - p) == 0) |
3495 | { | |
3496 | p = unpack_varlen_hex (++p1, &val); | |
3497 | ts->disconnected_tracing = val; | |
3498 | } | |
3499 | else if (strncmp (p, "circular", p1 - p) == 0) | |
3500 | { | |
3501 | p = unpack_varlen_hex (++p1, &val); | |
3502 | ts->circular_buffer = val; | |
3503 | } | |
f196051f SS |
3504 | else if (strncmp (p, "starttime", p1 - p) == 0) |
3505 | { | |
3506 | p = unpack_varlen_hex (++p1, &val); | |
3507 | ts->start_time = val; | |
3508 | } | |
3509 | else if (strncmp (p, "stoptime", p1 - p) == 0) | |
3510 | { | |
3511 | p = unpack_varlen_hex (++p1, &val); | |
3512 | ts->stop_time = val; | |
3513 | } | |
3514 | else if (strncmp (p, "username", p1 - p) == 0) | |
3515 | { | |
3516 | ++p1; | |
224c3ddb | 3517 | ts->user_name = (char *) xmalloc (strlen (p) / 2); |
bc20a4af | 3518 | end = hex2bin (p1, (gdb_byte *) ts->user_name, (p3 - p1) / 2); |
f196051f SS |
3519 | ts->user_name[end] = '\0'; |
3520 | p = p3; | |
3521 | } | |
3522 | else if (strncmp (p, "notes", p1 - p) == 0) | |
3523 | { | |
3524 | ++p1; | |
224c3ddb | 3525 | ts->notes = (char *) xmalloc (strlen (p) / 2); |
bc20a4af | 3526 | end = hex2bin (p1, (gdb_byte *) ts->notes, (p3 - p1) / 2); |
f196051f SS |
3527 | ts->notes[end] = '\0'; |
3528 | p = p3; | |
3529 | } | |
00bf0b85 SS |
3530 | else |
3531 | { | |
3532 | /* Silently skip unknown optional info. */ | |
3533 | p_temp = strchr (p1 + 1, ';'); | |
3534 | if (p_temp) | |
3535 | p = p_temp; | |
3536 | else | |
3537 | /* Must be at the end. */ | |
3538 | break; | |
3539 | } | |
3540 | } | |
3541 | } | |
3542 | ||
f196051f | 3543 | void |
256642e8 | 3544 | parse_tracepoint_status (const char *p, struct breakpoint *bp, |
f196051f SS |
3545 | struct uploaded_tp *utp) |
3546 | { | |
3547 | ULONGEST uval; | |
3548 | struct tracepoint *tp = (struct tracepoint *) bp; | |
3549 | ||
3550 | p = unpack_varlen_hex (p, &uval); | |
3551 | if (tp) | |
c1fc2657 | 3552 | tp->hit_count += uval; |
f196051f SS |
3553 | else |
3554 | utp->hit_count += uval; | |
3555 | p = unpack_varlen_hex (p + 1, &uval); | |
3556 | if (tp) | |
3557 | tp->traceframe_usage += uval; | |
3558 | else | |
3559 | utp->traceframe_usage += uval; | |
3560 | /* Ignore any extra, allowing for future extensions. */ | |
3561 | } | |
3562 | ||
409873ef SS |
3563 | /* Given a line of text defining a part of a tracepoint, parse it into |
3564 | an "uploaded tracepoint". */ | |
00bf0b85 SS |
3565 | |
3566 | void | |
256642e8 | 3567 | parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp) |
00bf0b85 | 3568 | { |
256642e8 | 3569 | const char *p; |
00bf0b85 | 3570 | char piece; |
409873ef | 3571 | ULONGEST num, addr, step, pass, orig_size, xlen, start; |
2a2287c7 | 3572 | int enabled, end; |
00bf0b85 | 3573 | enum bptype type; |
256642e8 PA |
3574 | const char *srctype; |
3575 | char *cond, *buf; | |
00bf0b85 SS |
3576 | struct uploaded_tp *utp = NULL; |
3577 | ||
3578 | p = line; | |
3579 | /* Both tracepoint and action definitions start with the same number | |
3580 | and address sequence. */ | |
3581 | piece = *p++; | |
3582 | p = unpack_varlen_hex (p, &num); | |
3583 | p++; /* skip a colon */ | |
3584 | p = unpack_varlen_hex (p, &addr); | |
3585 | p++; /* skip a colon */ | |
3586 | if (piece == 'T') | |
3587 | { | |
3588 | enabled = (*p++ == 'E'); | |
3589 | p++; /* skip a colon */ | |
3590 | p = unpack_varlen_hex (p, &step); | |
3591 | p++; /* skip a colon */ | |
3592 | p = unpack_varlen_hex (p, &pass); | |
3593 | type = bp_tracepoint; | |
3594 | cond = NULL; | |
3595 | /* Thumb through optional fields. */ | |
3596 | while (*p == ':') | |
3597 | { | |
3598 | p++; /* skip a colon */ | |
3599 | if (*p == 'F') | |
3600 | { | |
3601 | type = bp_fast_tracepoint; | |
3602 | p++; | |
3603 | p = unpack_varlen_hex (p, &orig_size); | |
3604 | } | |
0fb4aa4b PA |
3605 | else if (*p == 'S') |
3606 | { | |
3607 | type = bp_static_tracepoint; | |
3608 | p++; | |
3609 | } | |
00bf0b85 SS |
3610 | else if (*p == 'X') |
3611 | { | |
3612 | p++; | |
3613 | p = unpack_varlen_hex (p, &xlen); | |
3614 | p++; /* skip a comma */ | |
3615 | cond = (char *) xmalloc (2 * xlen + 1); | |
3616 | strncpy (cond, p, 2 * xlen); | |
3617 | cond[2 * xlen] = '\0'; | |
3618 | p += 2 * xlen; | |
3619 | } | |
3620 | else | |
3e43a32a MS |
3621 | warning (_("Unrecognized char '%c' in tracepoint " |
3622 | "definition, skipping rest"), *p); | |
00bf0b85 SS |
3623 | } |
3624 | utp = get_uploaded_tp (num, addr, utpp); | |
3625 | utp->type = type; | |
3626 | utp->enabled = enabled; | |
3627 | utp->step = step; | |
3628 | utp->pass = pass; | |
3629 | utp->cond = cond; | |
3630 | } | |
3631 | else if (piece == 'A') | |
3632 | { | |
3633 | utp = get_uploaded_tp (num, addr, utpp); | |
3149d8c1 | 3634 | VEC_safe_push (char_ptr, utp->actions, xstrdup (p)); |
00bf0b85 SS |
3635 | } |
3636 | else if (piece == 'S') | |
3637 | { | |
3638 | utp = get_uploaded_tp (num, addr, utpp); | |
3149d8c1 | 3639 | VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p)); |
00bf0b85 | 3640 | } |
409873ef SS |
3641 | else if (piece == 'Z') |
3642 | { | |
3643 | /* Parse a chunk of source form definition. */ | |
3644 | utp = get_uploaded_tp (num, addr, utpp); | |
3645 | srctype = p; | |
3646 | p = strchr (p, ':'); | |
3647 | p++; /* skip a colon */ | |
3648 | p = unpack_varlen_hex (p, &start); | |
3649 | p++; /* skip a colon */ | |
3650 | p = unpack_varlen_hex (p, &xlen); | |
3651 | p++; /* skip a colon */ | |
3652 | ||
224c3ddb | 3653 | buf = (char *) alloca (strlen (line)); |
409873ef SS |
3654 | |
3655 | end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2); | |
3656 | buf[end] = '\0'; | |
3657 | ||
61012eef | 3658 | if (startswith (srctype, "at:")) |
409873ef | 3659 | utp->at_string = xstrdup (buf); |
61012eef | 3660 | else if (startswith (srctype, "cond:")) |
409873ef | 3661 | utp->cond_string = xstrdup (buf); |
61012eef | 3662 | else if (startswith (srctype, "cmd:")) |
3149d8c1 | 3663 | VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf)); |
409873ef | 3664 | } |
f196051f SS |
3665 | else if (piece == 'V') |
3666 | { | |
3667 | utp = get_uploaded_tp (num, addr, utpp); | |
3668 | ||
3669 | parse_tracepoint_status (p, NULL, utp); | |
3670 | } | |
00bf0b85 SS |
3671 | else |
3672 | { | |
409873ef SS |
3673 | /* Don't error out, the target might be sending us optional |
3674 | info that we don't care about. */ | |
3675 | warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece); | |
00bf0b85 SS |
3676 | } |
3677 | } | |
3678 | ||
3679 | /* Convert a textual description of a trace state variable into an | |
3680 | uploaded object. */ | |
3681 | ||
3682 | void | |
256642e8 | 3683 | parse_tsv_definition (const char *line, struct uploaded_tsv **utsvp) |
00bf0b85 | 3684 | { |
256642e8 PA |
3685 | const char *p; |
3686 | char *buf; | |
00bf0b85 SS |
3687 | ULONGEST num, initval, builtin; |
3688 | int end; | |
3689 | struct uploaded_tsv *utsv = NULL; | |
3690 | ||
224c3ddb | 3691 | buf = (char *) alloca (strlen (line)); |
00bf0b85 SS |
3692 | |
3693 | p = line; | |
3694 | p = unpack_varlen_hex (p, &num); | |
3695 | p++; /* skip a colon */ | |
3696 | p = unpack_varlen_hex (p, &initval); | |
3697 | p++; /* skip a colon */ | |
3698 | p = unpack_varlen_hex (p, &builtin); | |
3699 | p++; /* skip a colon */ | |
3700 | end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2); | |
3701 | buf[end] = '\0'; | |
3702 | ||
3703 | utsv = get_uploaded_tsv (num, utsvp); | |
3704 | utsv->initial_value = initval; | |
3705 | utsv->builtin = builtin; | |
3706 | utsv->name = xstrdup (buf); | |
3707 | } | |
3708 | ||
5808517f YQ |
3709 | void |
3710 | free_current_marker (void *arg) | |
3711 | { | |
19ba03f4 SM |
3712 | struct static_tracepoint_marker **marker_p |
3713 | = (struct static_tracepoint_marker **) arg; | |
5808517f YQ |
3714 | |
3715 | if (*marker_p != NULL) | |
3716 | { | |
3717 | release_static_tracepoint_marker (*marker_p); | |
3718 | xfree (*marker_p); | |
3719 | } | |
3720 | else | |
3721 | *marker_p = NULL; | |
3722 | } | |
3723 | ||
0fb4aa4b PA |
3724 | /* Given a line of text defining a static tracepoint marker, parse it |
3725 | into a "static tracepoint marker" object. Throws an error is | |
3726 | parsing fails. If PP is non-null, it points to one past the end of | |
3727 | the parsed marker definition. */ | |
3728 | ||
3729 | void | |
256642e8 | 3730 | parse_static_tracepoint_marker_definition (const char *line, const char **pp, |
0fb4aa4b PA |
3731 | struct static_tracepoint_marker *marker) |
3732 | { | |
256642e8 | 3733 | const char *p, *endp; |
0fb4aa4b PA |
3734 | ULONGEST addr; |
3735 | int end; | |
3736 | ||
3737 | p = line; | |
3738 | p = unpack_varlen_hex (p, &addr); | |
3739 | p++; /* skip a colon */ | |
3740 | ||
f5656ead | 3741 | marker->gdbarch = target_gdbarch (); |
0fb4aa4b PA |
3742 | marker->address = (CORE_ADDR) addr; |
3743 | ||
3744 | endp = strchr (p, ':'); | |
3745 | if (endp == NULL) | |
74232302 | 3746 | error (_("bad marker definition: %s"), line); |
0fb4aa4b | 3747 | |
224c3ddb | 3748 | marker->str_id = (char *) xmalloc (endp - p + 1); |
0fb4aa4b PA |
3749 | end = hex2bin (p, (gdb_byte *) marker->str_id, (endp - p + 1) / 2); |
3750 | marker->str_id[end] = '\0'; | |
3751 | ||
3752 | p += 2 * end; | |
3753 | p++; /* skip a colon */ | |
3754 | ||
224c3ddb | 3755 | marker->extra = (char *) xmalloc (strlen (p) + 1); |
0fb4aa4b PA |
3756 | end = hex2bin (p, (gdb_byte *) marker->extra, strlen (p) / 2); |
3757 | marker->extra[end] = '\0'; | |
3758 | ||
3759 | if (pp) | |
3760 | *pp = p; | |
3761 | } | |
3762 | ||
3763 | /* Release a static tracepoint marker's contents. Note that the | |
3764 | object itself isn't released here. There objects are usually on | |
3765 | the stack. */ | |
3766 | ||
3767 | void | |
3768 | release_static_tracepoint_marker (struct static_tracepoint_marker *marker) | |
3769 | { | |
3770 | xfree (marker->str_id); | |
3771 | marker->str_id = NULL; | |
3772 | } | |
3773 | ||
3774 | /* Print MARKER to gdb_stdout. */ | |
3775 | ||
3776 | static void | |
3777 | print_one_static_tracepoint_marker (int count, | |
3778 | struct static_tracepoint_marker *marker) | |
3779 | { | |
0fb4aa4b PA |
3780 | struct symbol *sym; |
3781 | ||
3782 | char wrap_indent[80]; | |
3783 | char extra_field_indent[80]; | |
79a45e25 | 3784 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
3785 | VEC(breakpoint_p) *tracepoints; |
3786 | ||
51abb421 | 3787 | symtab_and_line sal; |
0fb4aa4b PA |
3788 | sal.pc = marker->address; |
3789 | ||
3790 | tracepoints = static_tracepoints_here (marker->address); | |
3791 | ||
a14a62dd | 3792 | ui_out_emit_tuple tuple_emitter (uiout, "marker"); |
0fb4aa4b PA |
3793 | |
3794 | /* A counter field to help readability. This is not a stable | |
3795 | identifier! */ | |
112e8700 | 3796 | uiout->field_int ("count", count); |
0fb4aa4b | 3797 | |
112e8700 | 3798 | uiout->field_string ("marker-id", marker->str_id); |
0fb4aa4b | 3799 | |
112e8700 | 3800 | uiout->field_fmt ("enabled", "%c", |
0fb4aa4b | 3801 | !VEC_empty (breakpoint_p, tracepoints) ? 'y' : 'n'); |
112e8700 | 3802 | uiout->spaces (2); |
0fb4aa4b PA |
3803 | |
3804 | strcpy (wrap_indent, " "); | |
3805 | ||
3806 | if (gdbarch_addr_bit (marker->gdbarch) <= 32) | |
3807 | strcat (wrap_indent, " "); | |
3808 | else | |
3809 | strcat (wrap_indent, " "); | |
3810 | ||
3811 | strcpy (extra_field_indent, " "); | |
3812 | ||
112e8700 | 3813 | uiout->field_core_addr ("addr", marker->gdbarch, marker->address); |
0fb4aa4b PA |
3814 | |
3815 | sal = find_pc_line (marker->address, 0); | |
3816 | sym = find_pc_sect_function (marker->address, NULL); | |
3817 | if (sym) | |
3818 | { | |
112e8700 SM |
3819 | uiout->text ("in "); |
3820 | uiout->field_string ("func", | |
0fb4aa4b | 3821 | SYMBOL_PRINT_NAME (sym)); |
112e8700 SM |
3822 | uiout->wrap_hint (wrap_indent); |
3823 | uiout->text (" at "); | |
0fb4aa4b PA |
3824 | } |
3825 | else | |
112e8700 | 3826 | uiout->field_skip ("func"); |
0fb4aa4b PA |
3827 | |
3828 | if (sal.symtab != NULL) | |
3829 | { | |
112e8700 | 3830 | uiout->field_string ("file", |
05cba821 | 3831 | symtab_to_filename_for_display (sal.symtab)); |
112e8700 | 3832 | uiout->text (":"); |
0fb4aa4b | 3833 | |
112e8700 | 3834 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 3835 | { |
0b0865da | 3836 | const char *fullname = symtab_to_fullname (sal.symtab); |
0fb4aa4b | 3837 | |
112e8700 | 3838 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
3839 | } |
3840 | else | |
112e8700 | 3841 | uiout->field_skip ("fullname"); |
0fb4aa4b | 3842 | |
112e8700 | 3843 | uiout->field_int ("line", sal.line); |
0fb4aa4b PA |
3844 | } |
3845 | else | |
3846 | { | |
112e8700 SM |
3847 | uiout->field_skip ("fullname"); |
3848 | uiout->field_skip ("line"); | |
0fb4aa4b PA |
3849 | } |
3850 | ||
112e8700 SM |
3851 | uiout->text ("\n"); |
3852 | uiout->text (extra_field_indent); | |
3853 | uiout->text (_("Data: \"")); | |
3854 | uiout->field_string ("extra-data", marker->extra); | |
3855 | uiout->text ("\"\n"); | |
0fb4aa4b PA |
3856 | |
3857 | if (!VEC_empty (breakpoint_p, tracepoints)) | |
3858 | { | |
0fb4aa4b PA |
3859 | int ix; |
3860 | struct breakpoint *b; | |
3861 | ||
a14a62dd TT |
3862 | { |
3863 | ui_out_emit_tuple tuple_emitter (uiout, "tracepoints-at"); | |
3864 | ||
3865 | uiout->text (extra_field_indent); | |
3866 | uiout->text (_("Probed by static tracepoints: ")); | |
3867 | for (ix = 0; VEC_iterate(breakpoint_p, tracepoints, ix, b); ix++) | |
3868 | { | |
3869 | if (ix > 0) | |
3870 | uiout->text (", "); | |
3871 | uiout->text ("#"); | |
3872 | uiout->field_int ("tracepoint-id", b->number); | |
3873 | } | |
3874 | } | |
0fb4aa4b | 3875 | |
112e8700 SM |
3876 | if (uiout->is_mi_like_p ()) |
3877 | uiout->field_int ("number-of-tracepoints", | |
0fb4aa4b PA |
3878 | VEC_length(breakpoint_p, tracepoints)); |
3879 | else | |
112e8700 | 3880 | uiout->text ("\n"); |
0fb4aa4b PA |
3881 | } |
3882 | VEC_free (breakpoint_p, tracepoints); | |
0fb4aa4b PA |
3883 | } |
3884 | ||
3885 | static void | |
3886 | info_static_tracepoint_markers_command (char *arg, int from_tty) | |
3887 | { | |
3888 | VEC(static_tracepoint_marker_p) *markers; | |
3889 | struct cleanup *old_chain; | |
3890 | struct static_tracepoint_marker *marker; | |
79a45e25 | 3891 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
3892 | int i; |
3893 | ||
d1feda86 YQ |
3894 | /* We don't have to check target_can_use_agent and agent's capability on |
3895 | static tracepoint here, in order to be compatible with older GDBserver. | |
3896 | We don't check USE_AGENT is true or not, because static tracepoints | |
3897 | don't work without in-process agent, so we don't bother users to type | |
3898 | `set agent on' when to use static tracepoint. */ | |
3899 | ||
4a2b031d TT |
3900 | ui_out_emit_table table_emitter (uiout, 5, -1, |
3901 | "StaticTracepointMarkersTable"); | |
0fb4aa4b | 3902 | |
112e8700 | 3903 | uiout->table_header (7, ui_left, "counter", "Cnt"); |
0fb4aa4b | 3904 | |
112e8700 | 3905 | uiout->table_header (40, ui_left, "marker-id", "ID"); |
0fb4aa4b | 3906 | |
112e8700 | 3907 | uiout->table_header (3, ui_left, "enabled", "Enb"); |
f5656ead | 3908 | if (gdbarch_addr_bit (target_gdbarch ()) <= 32) |
112e8700 | 3909 | uiout->table_header (10, ui_left, "addr", "Address"); |
0fb4aa4b | 3910 | else |
112e8700 SM |
3911 | uiout->table_header (18, ui_left, "addr", "Address"); |
3912 | uiout->table_header (40, ui_noalign, "what", "What"); | |
0fb4aa4b | 3913 | |
112e8700 | 3914 | uiout->table_body (); |
0fb4aa4b PA |
3915 | |
3916 | markers = target_static_tracepoint_markers_by_strid (NULL); | |
4a2b031d | 3917 | old_chain = make_cleanup (VEC_cleanup (static_tracepoint_marker_p), &markers); |
0fb4aa4b PA |
3918 | |
3919 | for (i = 0; | |
3920 | VEC_iterate (static_tracepoint_marker_p, | |
3921 | markers, i, marker); | |
3922 | i++) | |
3923 | { | |
3924 | print_one_static_tracepoint_marker (i + 1, marker); | |
3925 | release_static_tracepoint_marker (marker); | |
3926 | } | |
3927 | ||
3928 | do_cleanups (old_chain); | |
3929 | } | |
3930 | ||
3931 | /* The $_sdata convenience variable is a bit special. We don't know | |
3932 | for sure type of the value until we actually have a chance to fetch | |
3933 | the data --- the size of the object depends on what has been | |
3934 | collected. We solve this by making $_sdata be an internalvar that | |
3935 | creates a new value on access. */ | |
3936 | ||
3937 | /* Return a new value with the correct type for the sdata object of | |
3938 | the current trace frame. Return a void value if there's no object | |
3939 | available. */ | |
3940 | ||
3941 | static struct value * | |
22d2b532 SDJ |
3942 | sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var, |
3943 | void *ignore) | |
0fb4aa4b PA |
3944 | { |
3945 | LONGEST size; | |
3946 | gdb_byte *buf; | |
3947 | ||
3948 | /* We need to read the whole object before we know its size. */ | |
3949 | size = target_read_alloc (¤t_target, | |
3950 | TARGET_OBJECT_STATIC_TRACE_DATA, | |
3951 | NULL, &buf); | |
3952 | if (size >= 0) | |
3953 | { | |
3954 | struct value *v; | |
3955 | struct type *type; | |
3956 | ||
3957 | type = init_vector_type (builtin_type (gdbarch)->builtin_true_char, | |
3958 | size); | |
3959 | v = allocate_value (type); | |
3960 | memcpy (value_contents_raw (v), buf, size); | |
3961 | xfree (buf); | |
3962 | return v; | |
3963 | } | |
3964 | else | |
3965 | return allocate_value (builtin_type (gdbarch)->builtin_void); | |
3966 | } | |
3967 | ||
b3b9301e PA |
3968 | #if !defined(HAVE_LIBEXPAT) |
3969 | ||
3970 | struct traceframe_info * | |
3971 | parse_traceframe_info (const char *tframe_info) | |
3972 | { | |
3973 | static int have_warned; | |
3974 | ||
3975 | if (!have_warned) | |
3976 | { | |
3977 | have_warned = 1; | |
3978 | warning (_("Can not parse XML trace frame info; XML support " | |
3979 | "was disabled at compile time")); | |
3980 | } | |
3981 | ||
3982 | return NULL; | |
3983 | } | |
3984 | ||
3985 | #else /* HAVE_LIBEXPAT */ | |
3986 | ||
3987 | #include "xml-support.h" | |
3988 | ||
3989 | /* Handle the start of a <memory> element. */ | |
3990 | ||
3991 | static void | |
3992 | traceframe_info_start_memory (struct gdb_xml_parser *parser, | |
3993 | const struct gdb_xml_element *element, | |
3994 | void *user_data, VEC(gdb_xml_value_s) *attributes) | |
3995 | { | |
19ba03f4 | 3996 | struct traceframe_info *info = (struct traceframe_info *) user_data; |
b3b9301e PA |
3997 | ULONGEST *start_p, *length_p; |
3998 | ||
19ba03f4 | 3999 | start_p |
bc84451b | 4000 | = (ULONGEST *) xml_find_attribute (attributes, "start")->value; |
19ba03f4 | 4001 | length_p |
bc84451b | 4002 | = (ULONGEST *) xml_find_attribute (attributes, "length")->value; |
b3b9301e | 4003 | |
4cdd21a8 | 4004 | info->memory.emplace_back (*start_p, *length_p); |
b3b9301e PA |
4005 | } |
4006 | ||
28a93511 YQ |
4007 | /* Handle the start of a <tvar> element. */ |
4008 | ||
4009 | static void | |
4010 | traceframe_info_start_tvar (struct gdb_xml_parser *parser, | |
4011 | const struct gdb_xml_element *element, | |
4012 | void *user_data, | |
4013 | VEC(gdb_xml_value_s) *attributes) | |
4014 | { | |
19ba03f4 SM |
4015 | struct traceframe_info *info = (struct traceframe_info *) user_data; |
4016 | const char *id_attrib | |
4017 | = (const char *) xml_find_attribute (attributes, "id")->value; | |
28a93511 YQ |
4018 | int id = gdb_xml_parse_ulongest (parser, id_attrib); |
4019 | ||
d0d292a2 | 4020 | info->tvars.push_back (id); |
28a93511 YQ |
4021 | } |
4022 | ||
b3b9301e PA |
4023 | /* Discard the constructed trace frame info (if an error occurs). */ |
4024 | ||
4025 | static void | |
4026 | free_result (void *p) | |
4027 | { | |
19ba03f4 | 4028 | struct traceframe_info *result = (struct traceframe_info *) p; |
b3b9301e PA |
4029 | |
4030 | free_traceframe_info (result); | |
4031 | } | |
4032 | ||
4033 | /* The allowed elements and attributes for an XML memory map. */ | |
4034 | ||
4035 | static const struct gdb_xml_attribute memory_attributes[] = { | |
4036 | { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, | |
4037 | { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, | |
4038 | { NULL, GDB_XML_AF_NONE, NULL, NULL } | |
4039 | }; | |
4040 | ||
28a93511 YQ |
4041 | static const struct gdb_xml_attribute tvar_attributes[] = { |
4042 | { "id", GDB_XML_AF_NONE, NULL, NULL }, | |
4043 | { NULL, GDB_XML_AF_NONE, NULL, NULL } | |
4044 | }; | |
4045 | ||
b3b9301e PA |
4046 | static const struct gdb_xml_element traceframe_info_children[] = { |
4047 | { "memory", memory_attributes, NULL, | |
4048 | GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, | |
4049 | traceframe_info_start_memory, NULL }, | |
28a93511 YQ |
4050 | { "tvar", tvar_attributes, NULL, |
4051 | GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, | |
4052 | traceframe_info_start_tvar, NULL }, | |
b3b9301e PA |
4053 | { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } |
4054 | }; | |
4055 | ||
4056 | static const struct gdb_xml_element traceframe_info_elements[] = { | |
4057 | { "traceframe-info", NULL, traceframe_info_children, GDB_XML_EF_NONE, | |
4058 | NULL, NULL }, | |
4059 | { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } | |
4060 | }; | |
4061 | ||
4062 | /* Parse a traceframe-info XML document. */ | |
4063 | ||
4064 | struct traceframe_info * | |
4065 | parse_traceframe_info (const char *tframe_info) | |
4066 | { | |
d0d292a2 | 4067 | traceframe_info *result = new traceframe_info; |
b3b9301e PA |
4068 | struct cleanup *back_to; |
4069 | ||
b3b9301e PA |
4070 | back_to = make_cleanup (free_result, result); |
4071 | ||
4072 | if (gdb_xml_parse_quick (_("trace frame info"), | |
4073 | "traceframe-info.dtd", traceframe_info_elements, | |
4074 | tframe_info, result) == 0) | |
4075 | { | |
4076 | /* Parsed successfully, keep the result. */ | |
4077 | discard_cleanups (back_to); | |
4078 | ||
4079 | return result; | |
4080 | } | |
4081 | ||
4082 | do_cleanups (back_to); | |
4083 | return NULL; | |
4084 | } | |
4085 | ||
4086 | #endif /* HAVE_LIBEXPAT */ | |
4087 | ||
4088 | /* Returns the traceframe_info object for the current traceframe. | |
4089 | This is where we avoid re-fetching the object from the target if we | |
4090 | already have it cached. */ | |
4091 | ||
dc673c81 | 4092 | struct traceframe_info * |
b3b9301e PA |
4093 | get_traceframe_info (void) |
4094 | { | |
8d3c73ef SM |
4095 | if (current_traceframe_info == NULL) |
4096 | current_traceframe_info = target_traceframe_info (); | |
b3b9301e | 4097 | |
8d3c73ef | 4098 | return current_traceframe_info; |
b3b9301e PA |
4099 | } |
4100 | ||
c0f61f9c PA |
4101 | /* If the target supports the query, return in RESULT the set of |
4102 | collected memory in the current traceframe, found within the LEN | |
4103 | bytes range starting at MEMADDR. Returns true if the target | |
4104 | supports the query, otherwise returns false, and RESULT is left | |
4105 | undefined. */ | |
2a7498d8 PA |
4106 | |
4107 | int | |
4108 | traceframe_available_memory (VEC(mem_range_s) **result, | |
4109 | CORE_ADDR memaddr, ULONGEST len) | |
4110 | { | |
4111 | struct traceframe_info *info = get_traceframe_info (); | |
4112 | ||
4113 | if (info != NULL) | |
4114 | { | |
2a7498d8 PA |
4115 | *result = NULL; |
4116 | ||
4cdd21a8 SM |
4117 | for (mem_range &r : info->memory) |
4118 | if (mem_ranges_overlap (r.start, r.length, memaddr, len)) | |
2a7498d8 PA |
4119 | { |
4120 | ULONGEST lo1, hi1, lo2, hi2; | |
4121 | struct mem_range *nr; | |
4122 | ||
4123 | lo1 = memaddr; | |
4124 | hi1 = memaddr + len; | |
4125 | ||
4cdd21a8 SM |
4126 | lo2 = r.start; |
4127 | hi2 = r.start + r.length; | |
2a7498d8 PA |
4128 | |
4129 | nr = VEC_safe_push (mem_range_s, *result, NULL); | |
4130 | ||
325fac50 PA |
4131 | nr->start = std::max (lo1, lo2); |
4132 | nr->length = std::min (hi1, hi2) - nr->start; | |
2a7498d8 PA |
4133 | } |
4134 | ||
4135 | normalize_mem_ranges (*result); | |
4136 | return 1; | |
4137 | } | |
4138 | ||
4139 | return 0; | |
4140 | } | |
4141 | ||
22d2b532 SDJ |
4142 | /* Implementation of `sdata' variable. */ |
4143 | ||
4144 | static const struct internalvar_funcs sdata_funcs = | |
4145 | { | |
4146 | sdata_make_value, | |
4147 | NULL, | |
4148 | NULL | |
4149 | }; | |
4150 | ||
c906108c SS |
4151 | /* module initialization */ |
4152 | void | |
fba45db2 | 4153 | _initialize_tracepoint (void) |
c906108c | 4154 | { |
fa58ee11 EZ |
4155 | struct cmd_list_element *c; |
4156 | ||
0fb4aa4b PA |
4157 | /* Explicitly create without lookup, since that tries to create a |
4158 | value with a void typed value, and when we get here, gdbarch | |
4159 | isn't initialized yet. At this point, we're quite sure there | |
4160 | isn't another convenience variable of the same name. */ | |
22d2b532 | 4161 | create_internalvar_type_lazy ("_sdata", &sdata_funcs, NULL); |
0fb4aa4b | 4162 | |
c906108c SS |
4163 | traceframe_number = -1; |
4164 | tracepoint_number = -1; | |
4165 | ||
11db9430 | 4166 | add_info ("scope", info_scope_command, |
1bedd215 | 4167 | _("List the variables local to a scope")); |
c906108c | 4168 | |
0450cc4c | 4169 | add_cmd ("tracepoints", class_trace, |
1a966eab | 4170 | _("Tracing of program execution without stopping the program."), |
c906108c SS |
4171 | &cmdlist); |
4172 | ||
e5a873b7 | 4173 | add_com ("tdump", class_trace, tdump_command, |
1bedd215 | 4174 | _("Print everything collected at the current tracepoint.")); |
c906108c | 4175 | |
f61e138d SS |
4176 | c = add_com ("tvariable", class_trace, trace_variable_command,_("\ |
4177 | Define a trace state variable.\n\ | |
4178 | Argument is a $-prefixed name, optionally followed\n\ | |
4179 | by '=' and an expression that sets the initial value\n\ | |
4180 | at the start of tracing.")); | |
4181 | set_cmd_completer (c, expression_completer); | |
4182 | ||
4183 | add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\ | |
4184 | Delete one or more trace state variables.\n\ | |
4185 | Arguments are the names of the variables to delete.\n\ | |
4186 | If no arguments are supplied, delete all variables."), &deletelist); | |
c378eb4e | 4187 | /* FIXME add a trace variable completer. */ |
f61e138d | 4188 | |
11db9430 | 4189 | add_info ("tvariables", info_tvariables_command, _("\ |
f61e138d | 4190 | Status of trace state variables and their values.\n\ |
0fb4aa4b PA |
4191 | ")); |
4192 | ||
4193 | add_info ("static-tracepoint-markers", | |
4194 | info_static_tracepoint_markers_command, _("\ | |
4195 | List target static tracepoints markers.\n\ | |
f61e138d SS |
4196 | ")); |
4197 | ||
e5a873b7 | 4198 | add_prefix_cmd ("tfind", class_trace, tfind_command, _("\ |
1bedd215 AC |
4199 | Select a trace frame;\n\ |
4200 | No argument means forward by one frame; '-' means backward by one frame."), | |
c906108c SS |
4201 | &tfindlist, "tfind ", 1, &cmdlist); |
4202 | ||
e5a873b7 | 4203 | add_cmd ("outside", class_trace, tfind_outside_command, _("\ |
081dfbf7 | 4204 | Select a trace frame whose PC is outside the given range (exclusive).\n\ |
1a966eab | 4205 | Usage: tfind outside addr1, addr2"), |
c906108c SS |
4206 | &tfindlist); |
4207 | ||
e5a873b7 | 4208 | add_cmd ("range", class_trace, tfind_range_command, _("\ |
081dfbf7 | 4209 | Select a trace frame whose PC is in the given range (inclusive).\n\ |
1a966eab | 4210 | Usage: tfind range addr1,addr2"), |
c906108c SS |
4211 | &tfindlist); |
4212 | ||
e5a873b7 | 4213 | add_cmd ("line", class_trace, tfind_line_command, _("\ |
1a966eab | 4214 | Select a trace frame by source line.\n\ |
cce7e648 | 4215 | Argument can be a line number (with optional source file),\n\ |
c906108c | 4216 | a function name, or '*' followed by an address.\n\ |
1a966eab | 4217 | Default argument is 'the next source line that was traced'."), |
c906108c SS |
4218 | &tfindlist); |
4219 | ||
e5a873b7 | 4220 | add_cmd ("tracepoint", class_trace, tfind_tracepoint_command, _("\ |
1a966eab AC |
4221 | Select a trace frame by tracepoint number.\n\ |
4222 | Default is the tracepoint for the current trace frame."), | |
c906108c SS |
4223 | &tfindlist); |
4224 | ||
e5a873b7 | 4225 | add_cmd ("pc", class_trace, tfind_pc_command, _("\ |
1a966eab AC |
4226 | Select a trace frame by PC.\n\ |
4227 | Default is the current PC, or the PC of the current trace frame."), | |
c906108c SS |
4228 | &tfindlist); |
4229 | ||
e5a873b7 | 4230 | add_cmd ("end", class_trace, tfind_end_command, _("\ |
1a966eab | 4231 | De-select any trace frame and resume 'live' debugging."), |
c906108c SS |
4232 | &tfindlist); |
4233 | ||
8acc4065 | 4234 | add_alias_cmd ("none", "end", class_trace, 0, &tfindlist); |
c906108c | 4235 | |
e5a873b7 | 4236 | add_cmd ("start", class_trace, tfind_start_command, |
1a966eab | 4237 | _("Select the first trace frame in the trace buffer."), |
c906108c SS |
4238 | &tfindlist); |
4239 | ||
e5a873b7 | 4240 | add_com ("tstatus", class_trace, tstatus_command, |
1bedd215 | 4241 | _("Display the status of the current trace data collection.")); |
c906108c | 4242 | |
e5a873b7 | 4243 | add_com ("tstop", class_trace, tstop_command, _("\ |
f196051f SS |
4244 | Stop trace data collection.\n\ |
4245 | Usage: tstop [ <notes> ... ]\n\ | |
4246 | Any arguments supplied are recorded with the trace as a stop reason and\n\ | |
4247 | reported by tstatus (if the target supports trace notes).")); | |
c906108c | 4248 | |
e5a873b7 | 4249 | add_com ("tstart", class_trace, tstart_command, _("\ |
f196051f SS |
4250 | Start trace data collection.\n\ |
4251 | Usage: tstart [ <notes> ... ]\n\ | |
4252 | Any arguments supplied are recorded with the trace as a note and\n\ | |
4253 | reported by tstatus (if the target supports trace notes).")); | |
c906108c | 4254 | |
1bedd215 AC |
4255 | add_com ("end", class_trace, end_actions_pseudocommand, _("\ |
4256 | Ends a list of commands or actions.\n\ | |
c906108c SS |
4257 | Several GDB commands allow you to enter a list of commands or actions.\n\ |
4258 | Entering \"end\" on a line by itself is the normal way to terminate\n\ | |
4259 | such a list.\n\n\ | |
1bedd215 | 4260 | Note: the \"end\" command cannot be used at the gdb prompt.")); |
c906108c | 4261 | |
1bedd215 AC |
4262 | add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\ |
4263 | Specify single-stepping behavior at a tracepoint.\n\ | |
c906108c SS |
4264 | Argument is number of instructions to trace in single-step mode\n\ |
4265 | following the tracepoint. This command is normally followed by\n\ | |
4266 | one or more \"collect\" commands, to specify what to collect\n\ | |
4267 | while single-stepping.\n\n\ | |
1bedd215 | 4268 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
c906108c | 4269 | |
c5aa993b JM |
4270 | add_com_alias ("ws", "while-stepping", class_alias, 0); |
4271 | add_com_alias ("stepping", "while-stepping", class_alias, 0); | |
c906108c | 4272 | |
1bedd215 AC |
4273 | add_com ("collect", class_trace, collect_pseudocommand, _("\ |
4274 | Specify one or more data items to be collected at a tracepoint.\n\ | |
c906108c SS |
4275 | Accepts a comma-separated list of (one or more) expressions. GDB will\n\ |
4276 | collect all data (variables, registers) referenced by that expression.\n\ | |
4277 | Also accepts the following special arguments:\n\ | |
4278 | $regs -- all registers.\n\ | |
4279 | $args -- all function arguments.\n\ | |
4280 | $locals -- all variables local to the block/function scope.\n\ | |
0fb4aa4b | 4281 | $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\ |
1bedd215 | 4282 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
c906108c | 4283 | |
6da95a67 SS |
4284 | add_com ("teval", class_trace, teval_pseudocommand, _("\ |
4285 | Specify one or more expressions to be evaluated at a tracepoint.\n\ | |
4286 | Accepts a comma-separated list of (one or more) expressions.\n\ | |
4287 | The result of each evaluation will be discarded.\n\ | |
4288 | Note: this command can only be used in a tracepoint \"actions\" list.")); | |
4289 | ||
e5a873b7 | 4290 | add_com ("actions", class_trace, actions_command, _("\ |
1bedd215 | 4291 | Specify the actions to be taken at a tracepoint.\n\ |
cce7e648 PA |
4292 | Tracepoint actions may include collecting of specified data,\n\ |
4293 | single-stepping, or enabling/disabling other tracepoints,\n\ | |
1bedd215 | 4294 | depending on target's capabilities.")); |
c906108c | 4295 | |
236f1d4d SS |
4296 | default_collect = xstrdup (""); |
4297 | add_setshow_string_cmd ("default-collect", class_trace, | |
4298 | &default_collect, _("\ | |
4299 | Set the list of expressions to collect by default"), _("\ | |
4300 | Show the list of expressions to collect by default"), NULL, | |
4301 | NULL, NULL, | |
4302 | &setlist, &showlist); | |
4303 | ||
d5551862 SS |
4304 | add_setshow_boolean_cmd ("disconnected-tracing", no_class, |
4305 | &disconnected_tracing, _("\ | |
4306 | Set whether tracing continues after GDB disconnects."), _("\ | |
4307 | Show whether tracing continues after GDB disconnects."), _("\ | |
4308 | Use this to continue a tracing run even if GDB disconnects\n\ | |
4309 | or detaches from the target. You can reconnect later and look at\n\ | |
4310 | trace data collected in the meantime."), | |
4311 | set_disconnected_tracing, | |
4312 | NULL, | |
4313 | &setlist, | |
4314 | &showlist); | |
00bf0b85 | 4315 | |
4daf5ac0 SS |
4316 | add_setshow_boolean_cmd ("circular-trace-buffer", no_class, |
4317 | &circular_trace_buffer, _("\ | |
4318 | Set target's use of circular trace buffer."), _("\ | |
4319 | Show target's use of circular trace buffer."), _("\ | |
4320 | Use this to make the trace buffer into a circular buffer,\n\ | |
4321 | which will discard traceframes (oldest first) instead of filling\n\ | |
4322 | up and stopping the trace run."), | |
4323 | set_circular_trace_buffer, | |
4324 | NULL, | |
4325 | &setlist, | |
4326 | &showlist); | |
4327 | ||
f6f899bf | 4328 | add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class, |
9b67fcec | 4329 | &trace_buffer_size, _("\ |
f6f899bf HAQ |
4330 | Set requested size of trace buffer."), _("\ |
4331 | Show requested size of trace buffer."), _("\ | |
4332 | Use this to choose a size for the trace buffer. Some targets\n\ | |
f81d1120 PA |
4333 | may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\ |
4334 | disables any attempt to set the buffer size and lets the target choose."), | |
9b67fcec YQ |
4335 | set_trace_buffer_size, NULL, |
4336 | &setlist, &showlist); | |
f6f899bf | 4337 | |
f196051f SS |
4338 | add_setshow_string_cmd ("trace-user", class_trace, |
4339 | &trace_user, _("\ | |
4340 | Set the user name to use for current and future trace runs"), _("\ | |
4341 | Show the user name to use for current and future trace runs"), NULL, | |
4342 | set_trace_user, NULL, | |
4343 | &setlist, &showlist); | |
4344 | ||
4345 | add_setshow_string_cmd ("trace-notes", class_trace, | |
4346 | &trace_notes, _("\ | |
4347 | Set notes string to use for current and future trace runs"), _("\ | |
4348 | Show the notes string to use for current and future trace runs"), NULL, | |
4349 | set_trace_notes, NULL, | |
4350 | &setlist, &showlist); | |
4351 | ||
4352 | add_setshow_string_cmd ("trace-stop-notes", class_trace, | |
4353 | &trace_stop_notes, _("\ | |
4354 | Set notes string to use for future tstop commands"), _("\ | |
4355 | Show the notes string to use for future tstop commands"), NULL, | |
4356 | set_trace_stop_notes, NULL, | |
4357 | &setlist, &showlist); | |
c906108c | 4358 | } |