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