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