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