Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Tracing functionality for remote targets in custom GDB protocol |
9f60d481 | 2 | |
32d0add0 | 3 | Copyright (C) 1997-2015 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
5af949e3 | 21 | #include "arch-utils.h" |
c906108c SS |
22 | #include "symtab.h" |
23 | #include "frame.h" | |
c906108c SS |
24 | #include "gdbtypes.h" |
25 | #include "expression.h" | |
26 | #include "gdbcmd.h" | |
27 | #include "value.h" | |
28 | #include "target.h" | |
68c765e2 | 29 | #include "target-dcache.h" |
c906108c | 30 | #include "language.h" |
104c1213 | 31 | #include "inferior.h" |
1042e4c0 | 32 | #include "breakpoint.h" |
104c1213 | 33 | #include "tracepoint.h" |
c5f0f3d0 | 34 | #include "linespec.h" |
4e052eda | 35 | #include "regcache.h" |
c94fdfd0 | 36 | #include "completer.h" |
fe898f56 | 37 | #include "block.h" |
de4f826b | 38 | #include "dictionary.h" |
383f836e | 39 | #include "observer.h" |
029a67e4 | 40 | #include "user-regs.h" |
79a45b7d | 41 | #include "valprint.h" |
41575630 | 42 | #include "gdbcore.h" |
768a979c | 43 | #include "objfiles.h" |
35b1e5cc | 44 | #include "filenames.h" |
00bf0b85 | 45 | #include "gdbthread.h" |
2c58c0a9 | 46 | #include "stack.h" |
176a6961 | 47 | #include "remote.h" |
0fb4aa4b | 48 | #include "source.h" |
c906108c SS |
49 | #include "ax.h" |
50 | #include "ax-gdb.h" | |
2a7498d8 | 51 | #include "memrange.h" |
3065dfb6 | 52 | #include "cli/cli-utils.h" |
55aa24fb | 53 | #include "probe.h" |
d0353e76 | 54 | #include "ctf.h" |
614c279d | 55 | #include "filestuff.h" |
9c3d6531 | 56 | #include "rsp-low.h" |
7951c4eb | 57 | #include "tracefile.h" |
f00aae0f | 58 | #include "location.h" |
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 | 862 | { |
19ba03f4 SM |
863 | const struct memrange *a = (const struct memrange *) va; |
864 | const struct memrange *b = (const struct memrange *) vb; | |
c906108c SS |
865 | |
866 | if (a->type < b->type) | |
867 | return -1; | |
868 | if (a->type > b->type) | |
c5aa993b | 869 | return 1; |
f50e79a4 | 870 | if (a->type == memrange_absolute) |
c906108c | 871 | { |
c5aa993b JM |
872 | if ((bfd_vma) a->start < (bfd_vma) b->start) |
873 | return -1; | |
874 | if ((bfd_vma) a->start > (bfd_vma) b->start) | |
875 | return 1; | |
c906108c SS |
876 | } |
877 | else | |
878 | { | |
c5aa993b | 879 | if (a->start < b->start) |
c906108c | 880 | return -1; |
c5aa993b JM |
881 | if (a->start > b->start) |
882 | return 1; | |
c906108c SS |
883 | } |
884 | return 0; | |
885 | } | |
886 | ||
d183932d | 887 | /* Sort the memrange list using qsort, and merge adjacent memranges. */ |
c906108c | 888 | static void |
fba45db2 | 889 | memrange_sortmerge (struct collection_list *memranges) |
c906108c SS |
890 | { |
891 | int a, b; | |
892 | ||
c5aa993b | 893 | qsort (memranges->list, memranges->next_memrange, |
c906108c SS |
894 | sizeof (struct memrange), memrange_cmp); |
895 | if (memranges->next_memrange > 0) | |
896 | { | |
897 | for (a = 0, b = 1; b < memranges->next_memrange; b++) | |
898 | { | |
1b28d0b3 PA |
899 | /* If memrange b overlaps or is adjacent to memrange a, |
900 | merge them. */ | |
901 | if (memranges->list[a].type == memranges->list[b].type | |
902 | && memranges->list[b].start <= memranges->list[a].end) | |
c906108c | 903 | { |
08807d5a PA |
904 | if (memranges->list[b].end > memranges->list[a].end) |
905 | memranges->list[a].end = memranges->list[b].end; | |
c906108c SS |
906 | continue; /* next b, same a */ |
907 | } | |
908 | a++; /* next a */ | |
909 | if (a != b) | |
c5aa993b | 910 | memcpy (&memranges->list[a], &memranges->list[b], |
c906108c SS |
911 | sizeof (struct memrange)); |
912 | } | |
913 | memranges->next_memrange = a + 1; | |
914 | } | |
915 | } | |
916 | ||
d183932d | 917 | /* Add a register to a collection list. */ |
392a587b | 918 | static void |
fba45db2 | 919 | add_register (struct collection_list *collection, unsigned int regno) |
c906108c SS |
920 | { |
921 | if (info_verbose) | |
922 | printf_filtered ("collect register %d\n", regno); | |
27e06d3e | 923 | if (regno >= (8 * sizeof (collection->regs_mask))) |
8a3fe4f8 | 924 | error (_("Internal: register number %d too large for tracepoint"), |
c906108c | 925 | regno); |
c5aa993b | 926 | collection->regs_mask[regno / 8] |= 1 << (regno % 8); |
c906108c SS |
927 | } |
928 | ||
c378eb4e | 929 | /* Add a memrange to a collection list. */ |
c906108c | 930 | static void |
d183932d MS |
931 | add_memrange (struct collection_list *memranges, |
932 | int type, bfd_signed_vma base, | |
fba45db2 | 933 | unsigned long len) |
c906108c SS |
934 | { |
935 | if (info_verbose) | |
104c1213 JM |
936 | { |
937 | printf_filtered ("(%d,", type); | |
938 | printf_vma (base); | |
939 | printf_filtered (",%ld)\n", len); | |
940 | } | |
941 | ||
f50e79a4 | 942 | /* type: memrange_absolute == memory, other n == basereg */ |
c5aa993b | 943 | memranges->list[memranges->next_memrange].type = type; |
d183932d | 944 | /* base: addr if memory, offset if reg relative. */ |
c906108c SS |
945 | memranges->list[memranges->next_memrange].start = base; |
946 | /* len: we actually save end (base + len) for convenience */ | |
c5aa993b | 947 | memranges->list[memranges->next_memrange].end = base + len; |
c906108c SS |
948 | memranges->next_memrange++; |
949 | if (memranges->next_memrange >= memranges->listsize) | |
950 | { | |
951 | memranges->listsize *= 2; | |
224c3ddb SM |
952 | memranges->list = (struct memrange *) xrealloc (memranges->list, |
953 | memranges->listsize); | |
c906108c SS |
954 | } |
955 | ||
3e43a32a | 956 | if (type != memrange_absolute) /* Better collect the base register! */ |
c906108c SS |
957 | add_register (memranges, type); |
958 | } | |
959 | ||
d183932d | 960 | /* Add a symbol to a collection list. */ |
c906108c | 961 | static void |
d183932d MS |
962 | collect_symbol (struct collection_list *collect, |
963 | struct symbol *sym, | |
a6d9a66e | 964 | struct gdbarch *gdbarch, |
0936ad1d | 965 | long frame_regno, long frame_offset, |
92bc6a20 TT |
966 | CORE_ADDR scope, |
967 | int trace_string) | |
c906108c | 968 | { |
c5aa993b | 969 | unsigned long len; |
104c1213 | 970 | unsigned int reg; |
c906108c | 971 | bfd_signed_vma offset; |
400c6af0 | 972 | int treat_as_expr = 0; |
c906108c | 973 | |
c5aa993b JM |
974 | len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))); |
975 | switch (SYMBOL_CLASS (sym)) | |
976 | { | |
977 | default: | |
978 | printf_filtered ("%s: don't know symbol class %d\n", | |
3567439c | 979 | SYMBOL_PRINT_NAME (sym), |
d183932d | 980 | SYMBOL_CLASS (sym)); |
c5aa993b JM |
981 | break; |
982 | case LOC_CONST: | |
12df843f JK |
983 | printf_filtered ("constant %s (value %s) will not be collected.\n", |
984 | SYMBOL_PRINT_NAME (sym), plongest (SYMBOL_VALUE (sym))); | |
c5aa993b JM |
985 | break; |
986 | case LOC_STATIC: | |
987 | offset = SYMBOL_VALUE_ADDRESS (sym); | |
988 | if (info_verbose) | |
104c1213 JM |
989 | { |
990 | char tmp[40]; | |
991 | ||
992 | sprintf_vma (tmp, offset); | |
993 | printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n", | |
3567439c | 994 | SYMBOL_PRINT_NAME (sym), len, |
d183932d | 995 | tmp /* address */); |
104c1213 | 996 | } |
400c6af0 SS |
997 | /* A struct may be a C++ class with static fields, go to general |
998 | expression handling. */ | |
999 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT) | |
1000 | treat_as_expr = 1; | |
1001 | else | |
1002 | add_memrange (collect, memrange_absolute, offset, len); | |
c5aa993b JM |
1003 | break; |
1004 | case LOC_REGISTER: | |
a6d9a66e | 1005 | reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch); |
c5aa993b | 1006 | if (info_verbose) |
d183932d | 1007 | printf_filtered ("LOC_REG[parm] %s: ", |
3567439c | 1008 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b | 1009 | add_register (collect, reg); |
d183932d MS |
1010 | /* Check for doubles stored in two registers. */ |
1011 | /* FIXME: how about larger types stored in 3 or more regs? */ | |
c5aa993b | 1012 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT && |
a6d9a66e | 1013 | len > register_size (gdbarch, reg)) |
c5aa993b JM |
1014 | add_register (collect, reg + 1); |
1015 | break; | |
1016 | case LOC_REF_ARG: | |
1017 | printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n"); | |
1018 | printf_filtered (" (will not collect %s)\n", | |
3567439c | 1019 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b JM |
1020 | break; |
1021 | case LOC_ARG: | |
1022 | reg = frame_regno; | |
1023 | offset = frame_offset + SYMBOL_VALUE (sym); | |
1024 | if (info_verbose) | |
1025 | { | |
104c1213 | 1026 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ", |
3567439c | 1027 | SYMBOL_PRINT_NAME (sym), len); |
104c1213 JM |
1028 | printf_vma (offset); |
1029 | printf_filtered (" from frame ptr reg %d\n", reg); | |
c5aa993b JM |
1030 | } |
1031 | add_memrange (collect, reg, offset, len); | |
1032 | break; | |
1033 | case LOC_REGPARM_ADDR: | |
1034 | reg = SYMBOL_VALUE (sym); | |
1035 | offset = 0; | |
1036 | if (info_verbose) | |
1037 | { | |
104c1213 | 1038 | printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ", |
3567439c | 1039 | SYMBOL_PRINT_NAME (sym), len); |
104c1213 JM |
1040 | printf_vma (offset); |
1041 | printf_filtered (" from reg %d\n", reg); | |
c5aa993b JM |
1042 | } |
1043 | add_memrange (collect, reg, offset, len); | |
1044 | break; | |
1045 | case LOC_LOCAL: | |
c5aa993b JM |
1046 | reg = frame_regno; |
1047 | offset = frame_offset + SYMBOL_VALUE (sym); | |
1048 | if (info_verbose) | |
1049 | { | |
104c1213 | 1050 | printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ", |
3567439c | 1051 | SYMBOL_PRINT_NAME (sym), len); |
104c1213 JM |
1052 | printf_vma (offset); |
1053 | printf_filtered (" from frame ptr reg %d\n", reg); | |
c5aa993b JM |
1054 | } |
1055 | add_memrange (collect, reg, offset, len); | |
1056 | break; | |
a0405854 | 1057 | |
c5aa993b | 1058 | case LOC_UNRESOLVED: |
a0405854 | 1059 | treat_as_expr = 1; |
c5aa993b | 1060 | break; |
a0405854 | 1061 | |
c5aa993b | 1062 | case LOC_OPTIMIZED_OUT: |
8e1a459b | 1063 | printf_filtered ("%s has been optimized out of existence.\n", |
3567439c | 1064 | SYMBOL_PRINT_NAME (sym)); |
c5aa993b | 1065 | break; |
0936ad1d SS |
1066 | |
1067 | case LOC_COMPUTED: | |
400c6af0 | 1068 | treat_as_expr = 1; |
0936ad1d | 1069 | break; |
c5aa993b | 1070 | } |
400c6af0 SS |
1071 | |
1072 | /* Expressions are the most general case. */ | |
1073 | if (treat_as_expr) | |
1074 | { | |
1075 | struct agent_expr *aexpr; | |
1076 | struct cleanup *old_chain1 = NULL; | |
400c6af0 | 1077 | |
92bc6a20 | 1078 | aexpr = gen_trace_for_var (scope, gdbarch, sym, trace_string); |
400c6af0 SS |
1079 | |
1080 | /* It can happen that the symbol is recorded as a computed | |
1081 | location, but it's been optimized away and doesn't actually | |
1082 | have a location expression. */ | |
1083 | if (!aexpr) | |
1084 | { | |
1085 | printf_filtered ("%s has been optimized out of existence.\n", | |
1086 | SYMBOL_PRINT_NAME (sym)); | |
1087 | return; | |
1088 | } | |
1089 | ||
1090 | old_chain1 = make_cleanup_free_agent_expr (aexpr); | |
1091 | ||
35c9c7ba | 1092 | ax_reqs (aexpr); |
fff87407 | 1093 | |
35c9c7ba | 1094 | report_agent_reqs_errors (aexpr); |
400c6af0 SS |
1095 | |
1096 | discard_cleanups (old_chain1); | |
1097 | add_aexpr (collect, aexpr); | |
1098 | ||
c378eb4e | 1099 | /* Take care of the registers. */ |
35c9c7ba | 1100 | if (aexpr->reg_mask_len > 0) |
400c6af0 SS |
1101 | { |
1102 | int ndx1, ndx2; | |
1103 | ||
35c9c7ba | 1104 | for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) |
400c6af0 | 1105 | { |
c378eb4e | 1106 | QUIT; /* Allow user to bail out with ^C. */ |
35c9c7ba | 1107 | if (aexpr->reg_mask[ndx1] != 0) |
400c6af0 | 1108 | { |
c378eb4e | 1109 | /* Assume chars have 8 bits. */ |
400c6af0 | 1110 | for (ndx2 = 0; ndx2 < 8; ndx2++) |
35c9c7ba | 1111 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) |
c378eb4e | 1112 | /* It's used -- record it. */ |
400c6af0 SS |
1113 | add_register (collect, ndx1 * 8 + ndx2); |
1114 | } | |
1115 | } | |
1116 | } | |
1117 | } | |
c906108c SS |
1118 | } |
1119 | ||
2c58c0a9 PA |
1120 | /* Data to be passed around in the calls to the locals and args |
1121 | iterators. */ | |
1122 | ||
1123 | struct add_local_symbols_data | |
1124 | { | |
1125 | struct collection_list *collect; | |
1126 | struct gdbarch *gdbarch; | |
1127 | CORE_ADDR pc; | |
1128 | long frame_regno; | |
1129 | long frame_offset; | |
1130 | int count; | |
92bc6a20 | 1131 | int trace_string; |
2c58c0a9 PA |
1132 | }; |
1133 | ||
c378eb4e | 1134 | /* The callback for the locals and args iterators. */ |
2c58c0a9 PA |
1135 | |
1136 | static void | |
1137 | do_collect_symbol (const char *print_name, | |
1138 | struct symbol *sym, | |
1139 | void *cb_data) | |
1140 | { | |
19ba03f4 | 1141 | struct add_local_symbols_data *p = (struct add_local_symbols_data *) cb_data; |
2c58c0a9 PA |
1142 | |
1143 | collect_symbol (p->collect, sym, p->gdbarch, p->frame_regno, | |
92bc6a20 | 1144 | p->frame_offset, p->pc, p->trace_string); |
2c58c0a9 | 1145 | p->count++; |
dc673c81 YQ |
1146 | |
1147 | VEC_safe_push (char_ptr, p->collect->wholly_collected, | |
1148 | xstrdup (print_name)); | |
2c58c0a9 PA |
1149 | } |
1150 | ||
c378eb4e | 1151 | /* Add all locals (or args) symbols to collection list. */ |
c906108c | 1152 | static void |
a6d9a66e UW |
1153 | add_local_symbols (struct collection_list *collect, |
1154 | struct gdbarch *gdbarch, CORE_ADDR pc, | |
92bc6a20 TT |
1155 | long frame_regno, long frame_offset, int type, |
1156 | int trace_string) | |
c906108c | 1157 | { |
3977b71f | 1158 | const struct block *block; |
2c58c0a9 PA |
1159 | struct add_local_symbols_data cb_data; |
1160 | ||
1161 | cb_data.collect = collect; | |
1162 | cb_data.gdbarch = gdbarch; | |
1163 | cb_data.pc = pc; | |
1164 | cb_data.frame_regno = frame_regno; | |
1165 | cb_data.frame_offset = frame_offset; | |
1166 | cb_data.count = 0; | |
92bc6a20 | 1167 | cb_data.trace_string = trace_string; |
c906108c | 1168 | |
2c58c0a9 | 1169 | if (type == 'L') |
c906108c | 1170 | { |
2c58c0a9 PA |
1171 | block = block_for_pc (pc); |
1172 | if (block == NULL) | |
c906108c | 1173 | { |
2c58c0a9 PA |
1174 | warning (_("Can't collect locals; " |
1175 | "no symbol table info available.\n")); | |
1176 | return; | |
c906108c | 1177 | } |
2c58c0a9 PA |
1178 | |
1179 | iterate_over_block_local_vars (block, do_collect_symbol, &cb_data); | |
1180 | if (cb_data.count == 0) | |
1181 | warning (_("No locals found in scope.")); | |
1182 | } | |
1183 | else | |
1184 | { | |
1185 | pc = get_pc_function_start (pc); | |
1186 | block = block_for_pc (pc); | |
1187 | if (block == NULL) | |
1188 | { | |
b37520b6 | 1189 | warning (_("Can't collect args; no symbol table info available.")); |
2c58c0a9 PA |
1190 | return; |
1191 | } | |
1192 | ||
1193 | iterate_over_block_arg_vars (block, do_collect_symbol, &cb_data); | |
1194 | if (cb_data.count == 0) | |
1195 | warning (_("No args found in scope.")); | |
c906108c | 1196 | } |
c906108c SS |
1197 | } |
1198 | ||
0fb4aa4b PA |
1199 | static void |
1200 | add_static_trace_data (struct collection_list *collection) | |
1201 | { | |
1202 | if (info_verbose) | |
1203 | printf_filtered ("collect static trace data\n"); | |
1204 | collection->strace_data = 1; | |
1205 | } | |
1206 | ||
c906108c SS |
1207 | /* worker function */ |
1208 | static void | |
fba45db2 | 1209 | clear_collection_list (struct collection_list *list) |
c906108c SS |
1210 | { |
1211 | int ndx; | |
1212 | ||
1213 | list->next_memrange = 0; | |
1214 | for (ndx = 0; ndx < list->next_aexpr_elt; ndx++) | |
1215 | { | |
c5aa993b | 1216 | free_agent_expr (list->aexpr_list[ndx]); |
c906108c SS |
1217 | list->aexpr_list[ndx] = NULL; |
1218 | } | |
1219 | list->next_aexpr_elt = 0; | |
1220 | memset (list->regs_mask, 0, sizeof (list->regs_mask)); | |
0fb4aa4b | 1221 | list->strace_data = 0; |
cbfa3b61 YQ |
1222 | |
1223 | xfree (list->aexpr_list); | |
1224 | xfree (list->list); | |
dc673c81 YQ |
1225 | |
1226 | VEC_free (char_ptr, list->wholly_collected); | |
1227 | VEC_free (char_ptr, list->computed); | |
cbfa3b61 YQ |
1228 | } |
1229 | ||
1230 | /* A cleanup wrapper for function clear_collection_list. */ | |
1231 | ||
1232 | static void | |
1233 | do_clear_collection_list (void *list) | |
1234 | { | |
19ba03f4 | 1235 | struct collection_list *l = (struct collection_list *) list; |
cbfa3b61 YQ |
1236 | |
1237 | clear_collection_list (l); | |
1238 | } | |
1239 | ||
1240 | /* Initialize collection_list CLIST. */ | |
1241 | ||
1242 | static void | |
1243 | init_collection_list (struct collection_list *clist) | |
1244 | { | |
1245 | memset (clist, 0, sizeof *clist); | |
1246 | ||
1247 | clist->listsize = 128; | |
224c3ddb | 1248 | clist->list = XCNEWVEC (struct memrange, clist->listsize); |
cbfa3b61 YQ |
1249 | |
1250 | clist->aexpr_listsize = 128; | |
224c3ddb | 1251 | clist->aexpr_list = XCNEWVEC (struct agent_expr *, clist->aexpr_listsize); |
c906108c SS |
1252 | } |
1253 | ||
c378eb4e | 1254 | /* Reduce a collection list to string form (for gdb protocol). */ |
c906108c | 1255 | static char ** |
a73e3634 | 1256 | stringify_collection_list (struct collection_list *list) |
c906108c SS |
1257 | { |
1258 | char temp_buf[2048]; | |
104c1213 | 1259 | char tmp2[40]; |
c906108c SS |
1260 | int count; |
1261 | int ndx = 0; | |
1262 | char *(*str_list)[]; | |
1263 | char *end; | |
c5aa993b | 1264 | long i; |
c906108c | 1265 | |
0fb4aa4b | 1266 | count = 1 + 1 + list->next_memrange + list->next_aexpr_elt + 1; |
c5aa993b | 1267 | str_list = (char *(*)[]) xmalloc (count * sizeof (char *)); |
c906108c | 1268 | |
0fb4aa4b PA |
1269 | if (list->strace_data) |
1270 | { | |
1271 | if (info_verbose) | |
1272 | printf_filtered ("\nCollecting static trace data\n"); | |
1273 | end = temp_buf; | |
1274 | *end++ = 'L'; | |
1275 | (*str_list)[ndx] = savestring (temp_buf, end - temp_buf); | |
1276 | ndx++; | |
1277 | } | |
1278 | ||
c906108c | 1279 | for (i = sizeof (list->regs_mask) - 1; i > 0; i--) |
c378eb4e | 1280 | if (list->regs_mask[i] != 0) /* Skip leading zeroes in regs_mask. */ |
c906108c | 1281 | break; |
c378eb4e | 1282 | if (list->regs_mask[i] != 0) /* Prepare to send regs_mask to the stub. */ |
c906108c SS |
1283 | { |
1284 | if (info_verbose) | |
1285 | printf_filtered ("\nCollecting registers (mask): 0x"); | |
1286 | end = temp_buf; | |
c5aa993b | 1287 | *end++ = 'R'; |
c906108c SS |
1288 | for (; i >= 0; i--) |
1289 | { | |
c378eb4e | 1290 | QUIT; /* Allow user to bail out with ^C. */ |
c906108c SS |
1291 | if (info_verbose) |
1292 | printf_filtered ("%02X", list->regs_mask[i]); | |
c5aa993b | 1293 | sprintf (end, "%02X", list->regs_mask[i]); |
c906108c SS |
1294 | end += 2; |
1295 | } | |
1b36a34b | 1296 | (*str_list)[ndx] = xstrdup (temp_buf); |
c906108c SS |
1297 | ndx++; |
1298 | } | |
1299 | if (info_verbose) | |
1300 | printf_filtered ("\n"); | |
1301 | if (list->next_memrange > 0 && info_verbose) | |
1302 | printf_filtered ("Collecting memranges: \n"); | |
1303 | for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++) | |
1304 | { | |
c378eb4e | 1305 | QUIT; /* Allow user to bail out with ^C. */ |
104c1213 | 1306 | sprintf_vma (tmp2, list->list[i].start); |
c906108c | 1307 | if (info_verbose) |
104c1213 JM |
1308 | { |
1309 | printf_filtered ("(%d, %s, %ld)\n", | |
1310 | list->list[i].type, | |
1311 | tmp2, | |
1312 | (long) (list->list[i].end - list->list[i].start)); | |
1313 | } | |
c906108c SS |
1314 | if (count + 27 > MAX_AGENT_EXPR_LEN) |
1315 | { | |
c5aa993b | 1316 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
1317 | ndx++; |
1318 | count = 0; | |
1319 | end = temp_buf; | |
1320 | } | |
104c1213 | 1321 | |
d1948716 JB |
1322 | { |
1323 | bfd_signed_vma length = list->list[i].end - list->list[i].start; | |
1324 | ||
1325 | /* The "%X" conversion specifier expects an unsigned argument, | |
f50e79a4 JB |
1326 | so passing -1 (memrange_absolute) to it directly gives you |
1327 | "FFFFFFFF" (or more, depending on sizeof (unsigned)). | |
1328 | Special-case it. */ | |
1329 | if (list->list[i].type == memrange_absolute) | |
d1948716 JB |
1330 | sprintf (end, "M-1,%s,%lX", tmp2, (long) length); |
1331 | else | |
1332 | sprintf (end, "M%X,%s,%lX", list->list[i].type, tmp2, (long) length); | |
1333 | } | |
104c1213 | 1334 | |
c906108c | 1335 | count += strlen (end); |
3ffbc0a5 | 1336 | end = temp_buf + count; |
c906108c SS |
1337 | } |
1338 | ||
1339 | for (i = 0; i < list->next_aexpr_elt; i++) | |
1340 | { | |
c378eb4e | 1341 | QUIT; /* Allow user to bail out with ^C. */ |
c906108c SS |
1342 | if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN) |
1343 | { | |
c5aa993b | 1344 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
1345 | ndx++; |
1346 | count = 0; | |
1347 | end = temp_buf; | |
1348 | } | |
1349 | sprintf (end, "X%08X,", list->aexpr_list[i]->len); | |
1350 | end += 10; /* 'X' + 8 hex digits + ',' */ | |
1351 | count += 10; | |
1352 | ||
d183932d MS |
1353 | end = mem2hex (list->aexpr_list[i]->buf, |
1354 | end, list->aexpr_list[i]->len); | |
c906108c SS |
1355 | count += 2 * list->aexpr_list[i]->len; |
1356 | } | |
1357 | ||
1358 | if (count != 0) | |
1359 | { | |
c5aa993b | 1360 | (*str_list)[ndx] = savestring (temp_buf, count); |
c906108c SS |
1361 | ndx++; |
1362 | count = 0; | |
1363 | end = temp_buf; | |
1364 | } | |
1365 | (*str_list)[ndx] = NULL; | |
1366 | ||
1367 | if (ndx == 0) | |
27e06d3e | 1368 | { |
6c761d9c | 1369 | xfree (str_list); |
27e06d3e MS |
1370 | return NULL; |
1371 | } | |
c906108c SS |
1372 | else |
1373 | return *str_list; | |
1374 | } | |
1375 | ||
dc673c81 YQ |
1376 | /* Add the printed expression EXP to *LIST. */ |
1377 | ||
1378 | static void | |
1379 | append_exp (struct expression *exp, VEC(char_ptr) **list) | |
1380 | { | |
1381 | struct ui_file *tmp_stream = mem_fileopen (); | |
1382 | char *text; | |
1383 | ||
1384 | print_expression (exp, tmp_stream); | |
1385 | ||
1386 | text = ui_file_xstrdup (tmp_stream, NULL); | |
1387 | ||
1388 | VEC_safe_push (char_ptr, *list, text); | |
1389 | ui_file_delete (tmp_stream); | |
1390 | } | |
a7bdde9e VP |
1391 | |
1392 | static void | |
1393 | encode_actions_1 (struct command_line *action, | |
a7bdde9e VP |
1394 | struct bp_location *tloc, |
1395 | int frame_reg, | |
1396 | LONGEST frame_offset, | |
1397 | struct collection_list *collect, | |
1398 | struct collection_list *stepping_list) | |
c906108c | 1399 | { |
6f937416 | 1400 | const char *action_exp; |
c5aa993b | 1401 | struct expression *exp = NULL; |
104c1213 | 1402 | int i; |
f976f6d4 | 1403 | struct value *tempval; |
c906108c SS |
1404 | struct cmd_list_element *cmd; |
1405 | struct agent_expr *aexpr; | |
236f1d4d SS |
1406 | |
1407 | for (; action; action = action->next) | |
c906108c | 1408 | { |
c378eb4e | 1409 | QUIT; /* Allow user to bail out with ^C. */ |
a7bdde9e | 1410 | action_exp = action->line; |
6f937416 | 1411 | action_exp = skip_spaces_const (action_exp); |
c906108c | 1412 | |
c906108c SS |
1413 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); |
1414 | if (cmd == 0) | |
8a3fe4f8 | 1415 | error (_("Bad action list item: %s"), action_exp); |
c906108c | 1416 | |
bbaca940 | 1417 | if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
c906108c | 1418 | { |
92bc6a20 TT |
1419 | int trace_string = 0; |
1420 | ||
3065dfb6 | 1421 | if (*action_exp == '/') |
92bc6a20 | 1422 | action_exp = decode_agent_options (action_exp, &trace_string); |
3065dfb6 | 1423 | |
c5aa993b | 1424 | do |
c378eb4e MS |
1425 | { /* Repeat over a comma-separated list. */ |
1426 | QUIT; /* Allow user to bail out with ^C. */ | |
6f937416 | 1427 | action_exp = skip_spaces_const (action_exp); |
c906108c | 1428 | |
c5aa993b JM |
1429 | if (0 == strncasecmp ("$reg", action_exp, 4)) |
1430 | { | |
3e05895e | 1431 | for (i = 0; i < gdbarch_num_regs (tloc->gdbarch); i++) |
c5aa993b JM |
1432 | add_register (collect, i); |
1433 | action_exp = strchr (action_exp, ','); /* more? */ | |
1434 | } | |
1435 | else if (0 == strncasecmp ("$arg", action_exp, 4)) | |
1436 | { | |
1437 | add_local_symbols (collect, | |
3e05895e | 1438 | tloc->gdbarch, |
9355b391 | 1439 | tloc->address, |
c5aa993b JM |
1440 | frame_reg, |
1441 | frame_offset, | |
92bc6a20 TT |
1442 | 'A', |
1443 | trace_string); | |
c5aa993b JM |
1444 | action_exp = strchr (action_exp, ','); /* more? */ |
1445 | } | |
1446 | else if (0 == strncasecmp ("$loc", action_exp, 4)) | |
1447 | { | |
1448 | add_local_symbols (collect, | |
3e05895e | 1449 | tloc->gdbarch, |
9355b391 | 1450 | tloc->address, |
c5aa993b JM |
1451 | frame_reg, |
1452 | frame_offset, | |
92bc6a20 TT |
1453 | 'L', |
1454 | trace_string); | |
c5aa993b JM |
1455 | action_exp = strchr (action_exp, ','); /* more? */ |
1456 | } | |
6710bf39 SS |
1457 | else if (0 == strncasecmp ("$_ret", action_exp, 5)) |
1458 | { | |
1459 | struct cleanup *old_chain1 = NULL; | |
1460 | ||
1461 | aexpr = gen_trace_for_return_address (tloc->address, | |
92bc6a20 TT |
1462 | tloc->gdbarch, |
1463 | trace_string); | |
6710bf39 SS |
1464 | |
1465 | old_chain1 = make_cleanup_free_agent_expr (aexpr); | |
1466 | ||
1467 | ax_reqs (aexpr); | |
1468 | report_agent_reqs_errors (aexpr); | |
1469 | ||
1470 | discard_cleanups (old_chain1); | |
1471 | add_aexpr (collect, aexpr); | |
1472 | ||
1473 | /* take care of the registers */ | |
1474 | if (aexpr->reg_mask_len > 0) | |
1475 | { | |
1476 | int ndx1, ndx2; | |
1477 | ||
1478 | for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) | |
1479 | { | |
1480 | QUIT; /* allow user to bail out with ^C */ | |
1481 | if (aexpr->reg_mask[ndx1] != 0) | |
1482 | { | |
1483 | /* assume chars have 8 bits */ | |
1484 | for (ndx2 = 0; ndx2 < 8; ndx2++) | |
1485 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) | |
1486 | /* it's used -- record it */ | |
1487 | add_register (collect, | |
1488 | ndx1 * 8 + ndx2); | |
1489 | } | |
1490 | } | |
1491 | } | |
1492 | ||
1493 | action_exp = strchr (action_exp, ','); /* more? */ | |
1494 | } | |
0fb4aa4b PA |
1495 | else if (0 == strncasecmp ("$_sdata", action_exp, 7)) |
1496 | { | |
1497 | add_static_trace_data (collect); | |
1498 | action_exp = strchr (action_exp, ','); /* more? */ | |
1499 | } | |
c5aa993b JM |
1500 | else |
1501 | { | |
744a8059 | 1502 | unsigned long addr; |
c5aa993b JM |
1503 | struct cleanup *old_chain = NULL; |
1504 | struct cleanup *old_chain1 = NULL; | |
c5aa993b | 1505 | |
6f937416 | 1506 | exp = parse_exp_1 (&action_exp, tloc->address, |
9355b391 | 1507 | block_for_pc (tloc->address), 1); |
74b7792f | 1508 | old_chain = make_cleanup (free_current_contents, &exp); |
c906108c | 1509 | |
c5aa993b JM |
1510 | switch (exp->elts[0].opcode) |
1511 | { | |
1512 | case OP_REGISTER: | |
67f3407f DJ |
1513 | { |
1514 | const char *name = &exp->elts[2].string; | |
1515 | ||
3e05895e | 1516 | i = user_reg_map_name_to_regnum (tloc->gdbarch, |
029a67e4 | 1517 | name, strlen (name)); |
67f3407f DJ |
1518 | if (i == -1) |
1519 | internal_error (__FILE__, __LINE__, | |
1520 | _("Register $%s not available"), | |
1521 | name); | |
1522 | if (info_verbose) | |
1523 | printf_filtered ("OP_REGISTER: "); | |
1524 | add_register (collect, i); | |
1525 | break; | |
1526 | } | |
c5aa993b JM |
1527 | |
1528 | case UNOP_MEMVAL: | |
c378eb4e | 1529 | /* Safe because we know it's a simple expression. */ |
c5aa993b | 1530 | tempval = evaluate_expression (exp); |
42ae5230 | 1531 | addr = value_address (tempval); |
744a8059 SP |
1532 | /* Initialize the TYPE_LENGTH if it is a typedef. */ |
1533 | check_typedef (exp->elts[1].type); | |
1534 | add_memrange (collect, memrange_absolute, addr, | |
1535 | TYPE_LENGTH (exp->elts[1].type)); | |
dc673c81 | 1536 | append_exp (exp, &collect->computed); |
c5aa993b JM |
1537 | break; |
1538 | ||
1539 | case OP_VAR_VALUE: | |
dc673c81 YQ |
1540 | { |
1541 | struct symbol *sym = exp->elts[2].symbol; | |
1542 | char_ptr name = (char_ptr) SYMBOL_NATURAL_NAME (sym); | |
1543 | ||
1544 | collect_symbol (collect, | |
1545 | exp->elts[2].symbol, | |
1546 | tloc->gdbarch, | |
1547 | frame_reg, | |
1548 | frame_offset, | |
1549 | tloc->address, | |
1550 | trace_string); | |
1551 | VEC_safe_push (char_ptr, | |
1552 | collect->wholly_collected, | |
1553 | name); | |
1554 | } | |
c5aa993b JM |
1555 | break; |
1556 | ||
c378eb4e | 1557 | default: /* Full-fledged expression. */ |
92bc6a20 TT |
1558 | aexpr = gen_trace_for_expr (tloc->address, exp, |
1559 | trace_string); | |
c5aa993b | 1560 | |
f23d52e0 | 1561 | old_chain1 = make_cleanup_free_agent_expr (aexpr); |
c5aa993b | 1562 | |
35c9c7ba | 1563 | ax_reqs (aexpr); |
c5aa993b | 1564 | |
35c9c7ba | 1565 | report_agent_reqs_errors (aexpr); |
c5aa993b JM |
1566 | |
1567 | discard_cleanups (old_chain1); | |
1568 | add_aexpr (collect, aexpr); | |
1569 | ||
c378eb4e | 1570 | /* Take care of the registers. */ |
35c9c7ba | 1571 | if (aexpr->reg_mask_len > 0) |
c906108c | 1572 | { |
c5aa993b JM |
1573 | int ndx1; |
1574 | int ndx2; | |
1575 | ||
35c9c7ba | 1576 | for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++) |
c906108c | 1577 | { |
c378eb4e | 1578 | QUIT; /* Allow user to bail out with ^C. */ |
35c9c7ba | 1579 | if (aexpr->reg_mask[ndx1] != 0) |
c5aa993b | 1580 | { |
c378eb4e | 1581 | /* Assume chars have 8 bits. */ |
c5aa993b | 1582 | for (ndx2 = 0; ndx2 < 8; ndx2++) |
35c9c7ba | 1583 | if (aexpr->reg_mask[ndx1] & (1 << ndx2)) |
c378eb4e | 1584 | /* It's used -- record it. */ |
d183932d MS |
1585 | add_register (collect, |
1586 | ndx1 * 8 + ndx2); | |
c5aa993b | 1587 | } |
c906108c SS |
1588 | } |
1589 | } | |
dc673c81 YQ |
1590 | |
1591 | append_exp (exp, &collect->computed); | |
c5aa993b JM |
1592 | break; |
1593 | } /* switch */ | |
1594 | do_cleanups (old_chain); | |
1595 | } /* do */ | |
1596 | } | |
1597 | while (action_exp && *action_exp++ == ','); | |
1598 | } /* if */ | |
6da95a67 SS |
1599 | else if (cmd_cfunc_eq (cmd, teval_pseudocommand)) |
1600 | { | |
1601 | do | |
c378eb4e MS |
1602 | { /* Repeat over a comma-separated list. */ |
1603 | QUIT; /* Allow user to bail out with ^C. */ | |
6f937416 | 1604 | action_exp = skip_spaces_const (action_exp); |
6da95a67 SS |
1605 | |
1606 | { | |
6da95a67 SS |
1607 | struct cleanup *old_chain = NULL; |
1608 | struct cleanup *old_chain1 = NULL; | |
6da95a67 | 1609 | |
6f937416 | 1610 | exp = parse_exp_1 (&action_exp, tloc->address, |
9355b391 | 1611 | block_for_pc (tloc->address), 1); |
6da95a67 SS |
1612 | old_chain = make_cleanup (free_current_contents, &exp); |
1613 | ||
9355b391 | 1614 | aexpr = gen_eval_for_expr (tloc->address, exp); |
6da95a67 SS |
1615 | old_chain1 = make_cleanup_free_agent_expr (aexpr); |
1616 | ||
35c9c7ba SS |
1617 | ax_reqs (aexpr); |
1618 | report_agent_reqs_errors (aexpr); | |
6da95a67 SS |
1619 | |
1620 | discard_cleanups (old_chain1); | |
1621 | /* Even though we're not officially collecting, add | |
1622 | to the collect list anyway. */ | |
1623 | add_aexpr (collect, aexpr); | |
1624 | ||
1625 | do_cleanups (old_chain); | |
1626 | } /* do */ | |
1627 | } | |
1628 | while (action_exp && *action_exp++ == ','); | |
1629 | } /* if */ | |
bbaca940 | 1630 | else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
c906108c | 1631 | { |
a7bdde9e VP |
1632 | /* We check against nested while-stepping when setting |
1633 | breakpoint action, so no way to run into nested | |
1634 | here. */ | |
1635 | gdb_assert (stepping_list); | |
1636 | ||
23da373a | 1637 | encode_actions_1 (action->body_list[0], tloc, frame_reg, |
2a2287c7 | 1638 | frame_offset, stepping_list, NULL); |
c906108c | 1639 | } |
a7bdde9e VP |
1640 | else |
1641 | error (_("Invalid tracepoint command '%s'"), action->line); | |
1642 | } /* for */ | |
1643 | } | |
1644 | ||
dc673c81 YQ |
1645 | /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST |
1646 | and STEPPING_LIST. Return a cleanup pointer to clean up both | |
1647 | TRACEPOINT_LIST and STEPPING_LIST. */ | |
5fbce5df | 1648 | |
dc673c81 YQ |
1649 | struct cleanup * |
1650 | encode_actions_and_make_cleanup (struct bp_location *tloc, | |
1651 | struct collection_list *tracepoint_list, | |
1652 | struct collection_list *stepping_list) | |
a7bdde9e | 1653 | { |
a7bdde9e VP |
1654 | char *default_collect_line = NULL; |
1655 | struct command_line *actions; | |
1656 | struct command_line *default_collect_action = NULL; | |
1657 | int frame_reg; | |
1658 | LONGEST frame_offset; | |
dc673c81 | 1659 | struct cleanup *back_to, *return_chain; |
a7bdde9e | 1660 | |
dc673c81 YQ |
1661 | return_chain = make_cleanup (null_cleanup, NULL); |
1662 | init_collection_list (tracepoint_list); | |
1663 | init_collection_list (stepping_list); | |
cbfa3b61 | 1664 | |
dc673c81 YQ |
1665 | make_cleanup (do_clear_collection_list, tracepoint_list); |
1666 | make_cleanup (do_clear_collection_list, stepping_list); | |
a7bdde9e | 1667 | |
dc673c81 | 1668 | back_to = make_cleanup (null_cleanup, NULL); |
3e05895e TT |
1669 | gdbarch_virtual_frame_pointer (tloc->gdbarch, |
1670 | tloc->address, &frame_reg, &frame_offset); | |
a7bdde9e | 1671 | |
3ca73e0c | 1672 | actions = all_tracepoint_actions_and_cleanup (tloc->owner); |
a7bdde9e | 1673 | |
23da373a | 1674 | encode_actions_1 (actions, tloc, frame_reg, frame_offset, |
dc673c81 YQ |
1675 | tracepoint_list, stepping_list); |
1676 | ||
1677 | memrange_sortmerge (tracepoint_list); | |
1678 | memrange_sortmerge (stepping_list); | |
1679 | ||
1680 | do_cleanups (back_to); | |
1681 | return return_chain; | |
1682 | } | |
1683 | ||
1684 | /* Render all actions into gdb protocol. */ | |
1685 | ||
1686 | void | |
1687 | encode_actions_rsp (struct bp_location *tloc, char ***tdp_actions, | |
1688 | char ***stepping_actions) | |
1689 | { | |
1690 | struct collection_list tracepoint_list, stepping_list; | |
1691 | struct cleanup *cleanup; | |
a7bdde9e | 1692 | |
dc673c81 YQ |
1693 | *tdp_actions = NULL; |
1694 | *stepping_actions = NULL; | |
1695 | ||
1696 | cleanup = encode_actions_and_make_cleanup (tloc, &tracepoint_list, | |
1697 | &stepping_list); | |
c906108c | 1698 | |
a73e3634 YQ |
1699 | *tdp_actions = stringify_collection_list (&tracepoint_list); |
1700 | *stepping_actions = stringify_collection_list (&stepping_list); | |
236f1d4d | 1701 | |
dc673c81 | 1702 | do_cleanups (cleanup); |
c906108c SS |
1703 | } |
1704 | ||
1705 | static void | |
fba45db2 | 1706 | add_aexpr (struct collection_list *collect, struct agent_expr *aexpr) |
c906108c SS |
1707 | { |
1708 | if (collect->next_aexpr_elt >= collect->aexpr_listsize) | |
1709 | { | |
224c3ddb SM |
1710 | collect->aexpr_list = XRESIZEVEC (struct agent_expr *, |
1711 | collect->aexpr_list, | |
1712 | 2 * collect->aexpr_listsize); | |
c906108c SS |
1713 | collect->aexpr_listsize *= 2; |
1714 | } | |
1715 | collect->aexpr_list[collect->next_aexpr_elt] = aexpr; | |
1716 | collect->next_aexpr_elt++; | |
1717 | } | |
1718 | ||
bfccc43c YQ |
1719 | static void |
1720 | process_tracepoint_on_disconnect (void) | |
1721 | { | |
1722 | VEC(breakpoint_p) *tp_vec = NULL; | |
1723 | int ix; | |
1724 | struct breakpoint *b; | |
1725 | int has_pending_p = 0; | |
1726 | ||
1727 | /* Check whether we still have pending tracepoint. If we have, warn the | |
1728 | user that pending tracepoint will no longer work. */ | |
1729 | tp_vec = all_tracepoints (); | |
1730 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) | |
1731 | { | |
1732 | if (b->loc == NULL) | |
1733 | { | |
1734 | has_pending_p = 1; | |
1735 | break; | |
1736 | } | |
1737 | else | |
1738 | { | |
1739 | struct bp_location *loc1; | |
1740 | ||
1741 | for (loc1 = b->loc; loc1; loc1 = loc1->next) | |
1742 | { | |
1743 | if (loc1->shlib_disabled) | |
1744 | { | |
1745 | has_pending_p = 1; | |
1746 | break; | |
1747 | } | |
1748 | } | |
1749 | ||
1750 | if (has_pending_p) | |
1751 | break; | |
1752 | } | |
1753 | } | |
1754 | VEC_free (breakpoint_p, tp_vec); | |
1755 | ||
1756 | if (has_pending_p) | |
1757 | warning (_("Pending tracepoints will not be resolved while" | |
1758 | " GDB is disconnected\n")); | |
1759 | } | |
1760 | ||
aef525cb YQ |
1761 | /* Reset local state of tracing. */ |
1762 | ||
1763 | void | |
1764 | trace_reset_local_state (void) | |
1765 | { | |
1766 | set_traceframe_num (-1); | |
1767 | set_tracepoint_num (-1); | |
1768 | set_traceframe_context (NULL); | |
1769 | clear_traceframe_info (); | |
1770 | } | |
c5aa993b | 1771 | |
f224b49d | 1772 | void |
f196051f | 1773 | start_tracing (char *notes) |
d183932d | 1774 | { |
1042e4c0 SS |
1775 | VEC(breakpoint_p) *tp_vec = NULL; |
1776 | int ix; | |
d9b3f62e | 1777 | struct breakpoint *b; |
f61e138d | 1778 | struct trace_state_variable *tsv; |
d914c394 | 1779 | int any_enabled = 0, num_to_download = 0; |
f196051f SS |
1780 | int ret; |
1781 | ||
35b1e5cc | 1782 | tp_vec = all_tracepoints (); |
76a2b958 | 1783 | |
c378eb4e | 1784 | /* No point in tracing without any tracepoints... */ |
76a2b958 SS |
1785 | if (VEC_length (breakpoint_p, tp_vec) == 0) |
1786 | { | |
1787 | VEC_free (breakpoint_p, tp_vec); | |
1788 | error (_("No tracepoints defined, not starting trace")); | |
1789 | } | |
1790 | ||
d9b3f62e | 1791 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
76a2b958 | 1792 | { |
d9b3f62e | 1793 | struct tracepoint *t = (struct tracepoint *) b; |
55aa24fb | 1794 | struct bp_location *loc; |
d9b3f62e PA |
1795 | |
1796 | if (b->enable_state == bp_enabled) | |
d914c394 SS |
1797 | any_enabled = 1; |
1798 | ||
d9b3f62e | 1799 | if ((b->type == bp_fast_tracepoint |
d914c394 SS |
1800 | ? may_insert_fast_tracepoints |
1801 | : may_insert_tracepoints)) | |
1802 | ++num_to_download; | |
1803 | else | |
1804 | warning (_("May not insert %stracepoints, skipping tracepoint %d"), | |
d9b3f62e | 1805 | (b->type == bp_fast_tracepoint ? "fast " : ""), b->number); |
76a2b958 SS |
1806 | } |
1807 | ||
76a2b958 SS |
1808 | if (!any_enabled) |
1809 | { | |
d248b706 KY |
1810 | if (target_supports_enable_disable_tracepoint ()) |
1811 | warning (_("No tracepoints enabled")); | |
1812 | else | |
1813 | { | |
1814 | /* No point in tracing with only disabled tracepoints that | |
1815 | cannot be re-enabled. */ | |
1816 | VEC_free (breakpoint_p, tp_vec); | |
1817 | error (_("No tracepoints enabled, not starting trace")); | |
1818 | } | |
76a2b958 SS |
1819 | } |
1820 | ||
d914c394 SS |
1821 | if (num_to_download <= 0) |
1822 | { | |
1823 | VEC_free (breakpoint_p, tp_vec); | |
1824 | error (_("No tracepoints that may be downloaded, not starting trace")); | |
1825 | } | |
1826 | ||
76a2b958 SS |
1827 | target_trace_init (); |
1828 | ||
d9b3f62e | 1829 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
7a697b8d | 1830 | { |
d9b3f62e | 1831 | struct tracepoint *t = (struct tracepoint *) b; |
e8ba3115 | 1832 | struct bp_location *loc; |
f2a8bc8a | 1833 | int bp_location_downloaded = 0; |
d9b3f62e | 1834 | |
4511b1ba YQ |
1835 | /* Clear `inserted' flag. */ |
1836 | for (loc = b->loc; loc; loc = loc->next) | |
1837 | loc->inserted = 0; | |
1838 | ||
d9b3f62e | 1839 | if ((b->type == bp_fast_tracepoint |
d914c394 SS |
1840 | ? !may_insert_fast_tracepoints |
1841 | : !may_insert_tracepoints)) | |
1842 | continue; | |
1843 | ||
35b1e5cc | 1844 | t->number_on_target = 0; |
e8ba3115 YQ |
1845 | |
1846 | for (loc = b->loc; loc; loc = loc->next) | |
1e4d1764 YQ |
1847 | { |
1848 | /* Since tracepoint locations are never duplicated, `inserted' | |
1849 | flag should be zero. */ | |
1850 | gdb_assert (!loc->inserted); | |
1851 | ||
1852 | target_download_tracepoint (loc); | |
1853 | ||
1854 | loc->inserted = 1; | |
f2a8bc8a | 1855 | bp_location_downloaded = 1; |
1e4d1764 | 1856 | } |
e8ba3115 | 1857 | |
d9b3f62e | 1858 | t->number_on_target = b->number; |
55aa24fb SDJ |
1859 | |
1860 | for (loc = b->loc; loc; loc = loc->next) | |
0ea5cda8 SDJ |
1861 | if (loc->probe.probe != NULL |
1862 | && loc->probe.probe->pops->set_semaphore != NULL) | |
729662a5 TT |
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. */ | |
0ea5cda8 SDJ |
1961 | if (loc->probe.probe != NULL |
1962 | && loc->probe.probe->pops->clear_semaphore != NULL) | |
729662a5 TT |
1963 | loc->probe.probe->pops->clear_semaphore (loc->probe.probe, |
1964 | loc->probe.objfile, | |
1965 | loc->gdbarch); | |
55aa24fb SDJ |
1966 | } |
1967 | } | |
1968 | ||
1969 | VEC_free (breakpoint_p, tp_vec); | |
1970 | ||
f196051f SS |
1971 | if (!note) |
1972 | note = trace_stop_notes; | |
1973 | ret = target_set_trace_notes (NULL, NULL, note); | |
1974 | ||
1975 | if (!ret && note) | |
43011e52 | 1976 | warning (_("Target does not support trace notes, note ignored")); |
f196051f | 1977 | |
c378eb4e | 1978 | /* Should change in response to reply? */ |
00bf0b85 | 1979 | current_trace_status ()->running = 0; |
d5551862 SS |
1980 | } |
1981 | ||
c906108c SS |
1982 | /* tstatus command */ |
1983 | static void | |
fba45db2 | 1984 | trace_status_command (char *args, int from_tty) |
d183932d | 1985 | { |
00bf0b85 | 1986 | struct trace_status *ts = current_trace_status (); |
f196051f SS |
1987 | int status, ix; |
1988 | VEC(breakpoint_p) *tp_vec = NULL; | |
1989 | struct breakpoint *t; | |
35b1e5cc | 1990 | |
00bf0b85 SS |
1991 | status = target_get_trace_status (ts); |
1992 | ||
1993 | if (status == -1) | |
1994 | { | |
f5911ea1 | 1995 | if (ts->filename != NULL) |
00bf0b85 SS |
1996 | printf_filtered (_("Using a trace file.\n")); |
1997 | else | |
1998 | { | |
1999 | printf_filtered (_("Trace can not be run on this target.\n")); | |
2000 | return; | |
2001 | } | |
2002 | } | |
2003 | ||
2004 | if (!ts->running_known) | |
2005 | { | |
2006 | printf_filtered (_("Run/stop status is unknown.\n")); | |
2007 | } | |
2008 | else if (ts->running) | |
c906108c | 2009 | { |
35b1e5cc | 2010 | printf_filtered (_("Trace is running on the target.\n")); |
c906108c SS |
2011 | } |
2012 | else | |
00bf0b85 SS |
2013 | { |
2014 | switch (ts->stop_reason) | |
2015 | { | |
2016 | case trace_never_run: | |
2017 | printf_filtered (_("No trace has been run on the target.\n")); | |
2018 | break; | |
2019 | case tstop_command: | |
f196051f SS |
2020 | if (ts->stop_desc) |
2021 | printf_filtered (_("Trace stopped by a tstop command (%s).\n"), | |
2022 | ts->stop_desc); | |
2023 | else | |
2024 | printf_filtered (_("Trace stopped by a tstop command.\n")); | |
00bf0b85 SS |
2025 | break; |
2026 | case trace_buffer_full: | |
2027 | printf_filtered (_("Trace stopped because the buffer was full.\n")); | |
2028 | break; | |
2029 | case trace_disconnected: | |
2030 | printf_filtered (_("Trace stopped because of disconnection.\n")); | |
2031 | break; | |
2032 | case tracepoint_passcount: | |
00bf0b85 SS |
2033 | printf_filtered (_("Trace stopped by tracepoint %d.\n"), |
2034 | ts->stopping_tracepoint); | |
2035 | break; | |
6c28cbf2 SS |
2036 | case tracepoint_error: |
2037 | if (ts->stopping_tracepoint) | |
3e43a32a MS |
2038 | printf_filtered (_("Trace stopped by an " |
2039 | "error (%s, tracepoint %d).\n"), | |
f196051f | 2040 | ts->stop_desc, ts->stopping_tracepoint); |
6c28cbf2 SS |
2041 | else |
2042 | printf_filtered (_("Trace stopped by an error (%s).\n"), | |
f196051f | 2043 | ts->stop_desc); |
6c28cbf2 | 2044 | break; |
00bf0b85 SS |
2045 | case trace_stop_reason_unknown: |
2046 | printf_filtered (_("Trace stopped for an unknown reason.\n")); | |
2047 | break; | |
2048 | default: | |
2049 | printf_filtered (_("Trace stopped for some other reason (%d).\n"), | |
2050 | ts->stop_reason); | |
2051 | break; | |
2052 | } | |
2053 | } | |
2054 | ||
4daf5ac0 SS |
2055 | if (ts->traceframes_created >= 0 |
2056 | && ts->traceframe_count != ts->traceframes_created) | |
2057 | { | |
3e43a32a MS |
2058 | printf_filtered (_("Buffer contains %d trace " |
2059 | "frames (of %d created total).\n"), | |
4daf5ac0 SS |
2060 | ts->traceframe_count, ts->traceframes_created); |
2061 | } | |
2062 | else if (ts->traceframe_count >= 0) | |
00bf0b85 SS |
2063 | { |
2064 | printf_filtered (_("Collected %d trace frames.\n"), | |
2065 | ts->traceframe_count); | |
2066 | } | |
2067 | ||
4daf5ac0 | 2068 | if (ts->buffer_free >= 0) |
00bf0b85 | 2069 | { |
4daf5ac0 SS |
2070 | if (ts->buffer_size >= 0) |
2071 | { | |
2072 | printf_filtered (_("Trace buffer has %d bytes of %d bytes free"), | |
2073 | ts->buffer_free, ts->buffer_size); | |
2074 | if (ts->buffer_size > 0) | |
2075 | printf_filtered (_(" (%d%% full)"), | |
2076 | ((int) ((((long long) (ts->buffer_size | |
2077 | - ts->buffer_free)) * 100) | |
2078 | / ts->buffer_size))); | |
2079 | printf_filtered (_(".\n")); | |
2080 | } | |
2081 | else | |
2082 | printf_filtered (_("Trace buffer has %d bytes free.\n"), | |
2083 | ts->buffer_free); | |
00bf0b85 | 2084 | } |
35b1e5cc | 2085 | |
33da3f1c SS |
2086 | if (ts->disconnected_tracing) |
2087 | printf_filtered (_("Trace will continue if GDB disconnects.\n")); | |
2088 | else | |
2089 | printf_filtered (_("Trace will stop if GDB disconnects.\n")); | |
2090 | ||
2091 | if (ts->circular_buffer) | |
2092 | printf_filtered (_("Trace buffer is circular.\n")); | |
2093 | ||
f196051f SS |
2094 | if (ts->user_name && strlen (ts->user_name) > 0) |
2095 | printf_filtered (_("Trace user is %s.\n"), ts->user_name); | |
2096 | ||
2097 | if (ts->notes && strlen (ts->notes) > 0) | |
2098 | printf_filtered (_("Trace notes: %s.\n"), ts->notes); | |
2099 | ||
00bf0b85 | 2100 | /* Now report on what we're doing with tfind. */ |
35b1e5cc SS |
2101 | if (traceframe_number >= 0) |
2102 | printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"), | |
2103 | traceframe_number, tracepoint_number); | |
2104 | else | |
2105 | printf_filtered (_("Not looking at any trace frame.\n")); | |
f196051f SS |
2106 | |
2107 | /* Report start/stop times if supplied. */ | |
2108 | if (ts->start_time) | |
2109 | { | |
2110 | if (ts->stop_time) | |
2111 | { | |
2112 | LONGEST run_time = ts->stop_time - ts->start_time; | |
2113 | ||
2114 | /* Reporting a run time is more readable than two long numbers. */ | |
2115 | printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"), | |
f30aa5af DK |
2116 | (long int) (ts->start_time / 1000000), |
2117 | (long int) (ts->start_time % 1000000), | |
2118 | (long int) (run_time / 1000000), | |
2119 | (long int) (run_time % 1000000)); | |
f196051f SS |
2120 | } |
2121 | else | |
2122 | printf_filtered (_("Trace started at %ld.%06ld secs.\n"), | |
f30aa5af DK |
2123 | (long int) (ts->start_time / 1000000), |
2124 | (long int) (ts->start_time % 1000000)); | |
f196051f SS |
2125 | } |
2126 | else if (ts->stop_time) | |
2127 | printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"), | |
f30aa5af DK |
2128 | (long int) (ts->stop_time / 1000000), |
2129 | (long int) (ts->stop_time % 1000000)); | |
f196051f SS |
2130 | |
2131 | /* Now report any per-tracepoint status available. */ | |
2132 | tp_vec = all_tracepoints (); | |
2133 | ||
2134 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++) | |
2135 | target_get_tracepoint_status (t, NULL); | |
2136 | ||
2137 | VEC_free (breakpoint_p, tp_vec); | |
c906108c SS |
2138 | } |
2139 | ||
f224b49d VP |
2140 | /* Report the trace status to uiout, in a way suitable for MI, and not |
2141 | suitable for CLI. If ON_STOP is true, suppress a few fields that | |
2142 | are not meaningful in the -trace-stop response. | |
2143 | ||
2144 | The implementation is essentially parallel to trace_status_command, but | |
2145 | merging them will result in unreadable code. */ | |
2146 | void | |
2147 | trace_status_mi (int on_stop) | |
2148 | { | |
79a45e25 | 2149 | struct ui_out *uiout = current_uiout; |
f224b49d VP |
2150 | struct trace_status *ts = current_trace_status (); |
2151 | int status; | |
f224b49d VP |
2152 | |
2153 | status = target_get_trace_status (ts); | |
2154 | ||
f5911ea1 | 2155 | if (status == -1 && ts->filename == NULL) |
f224b49d VP |
2156 | { |
2157 | ui_out_field_string (uiout, "supported", "0"); | |
2158 | return; | |
2159 | } | |
2160 | ||
f5911ea1 | 2161 | if (ts->filename != NULL) |
f224b49d VP |
2162 | ui_out_field_string (uiout, "supported", "file"); |
2163 | else if (!on_stop) | |
2164 | ui_out_field_string (uiout, "supported", "1"); | |
2165 | ||
f5911ea1 HAQ |
2166 | if (ts->filename != NULL) |
2167 | ui_out_field_string (uiout, "trace-file", ts->filename); | |
2168 | ||
f224b49d VP |
2169 | gdb_assert (ts->running_known); |
2170 | ||
2171 | if (ts->running) | |
2172 | { | |
2173 | ui_out_field_string (uiout, "running", "1"); | |
2174 | ||
2175 | /* Unlike CLI, do not show the state of 'disconnected-tracing' variable. | |
2176 | Given that the frontend gets the status either on -trace-stop, or from | |
2177 | -trace-status after re-connection, it does not seem like this | |
2178 | information is necessary for anything. It is not necessary for either | |
2179 | figuring the vital state of the target nor for navigation of trace | |
2180 | frames. If the frontend wants to show the current state is some | |
2181 | configure dialog, it can request the value when such dialog is | |
2182 | invoked by the user. */ | |
2183 | } | |
2184 | else | |
2185 | { | |
2186 | char *stop_reason = NULL; | |
2187 | int stopping_tracepoint = -1; | |
2188 | ||
2189 | if (!on_stop) | |
2190 | ui_out_field_string (uiout, "running", "0"); | |
2191 | ||
2192 | if (ts->stop_reason != trace_stop_reason_unknown) | |
2193 | { | |
2194 | switch (ts->stop_reason) | |
2195 | { | |
2196 | case tstop_command: | |
2197 | stop_reason = "request"; | |
2198 | break; | |
2199 | case trace_buffer_full: | |
2200 | stop_reason = "overflow"; | |
2201 | break; | |
2202 | case trace_disconnected: | |
2203 | stop_reason = "disconnection"; | |
2204 | break; | |
2205 | case tracepoint_passcount: | |
2206 | stop_reason = "passcount"; | |
2207 | stopping_tracepoint = ts->stopping_tracepoint; | |
2208 | break; | |
6c28cbf2 SS |
2209 | case tracepoint_error: |
2210 | stop_reason = "error"; | |
2211 | stopping_tracepoint = ts->stopping_tracepoint; | |
2212 | break; | |
f224b49d VP |
2213 | } |
2214 | ||
2215 | if (stop_reason) | |
2216 | { | |
2217 | ui_out_field_string (uiout, "stop-reason", stop_reason); | |
2218 | if (stopping_tracepoint != -1) | |
2219 | ui_out_field_int (uiout, "stopping-tracepoint", | |
2220 | stopping_tracepoint); | |
6c28cbf2 SS |
2221 | if (ts->stop_reason == tracepoint_error) |
2222 | ui_out_field_string (uiout, "error-description", | |
f196051f | 2223 | ts->stop_desc); |
f224b49d VP |
2224 | } |
2225 | } | |
2226 | } | |
2227 | ||
a97153c7 | 2228 | if (ts->traceframe_count != -1) |
f224b49d | 2229 | ui_out_field_int (uiout, "frames", ts->traceframe_count); |
87290684 SS |
2230 | if (ts->traceframes_created != -1) |
2231 | ui_out_field_int (uiout, "frames-created", ts->traceframes_created); | |
a97153c7 PA |
2232 | if (ts->buffer_size != -1) |
2233 | ui_out_field_int (uiout, "buffer-size", ts->buffer_size); | |
2234 | if (ts->buffer_free != -1) | |
2235 | ui_out_field_int (uiout, "buffer-free", ts->buffer_free); | |
2236 | ||
2237 | ui_out_field_int (uiout, "disconnected", ts->disconnected_tracing); | |
2238 | ui_out_field_int (uiout, "circular", ts->circular_buffer); | |
f196051f SS |
2239 | |
2240 | ui_out_field_string (uiout, "user-name", ts->user_name); | |
2241 | ui_out_field_string (uiout, "notes", ts->notes); | |
2242 | ||
2243 | { | |
2244 | char buf[100]; | |
2245 | ||
2246 | xsnprintf (buf, sizeof buf, "%ld.%06ld", | |
f30aa5af DK |
2247 | (long int) (ts->start_time / 1000000), |
2248 | (long int) (ts->start_time % 1000000)); | |
f196051f SS |
2249 | ui_out_field_string (uiout, "start-time", buf); |
2250 | xsnprintf (buf, sizeof buf, "%ld.%06ld", | |
f30aa5af DK |
2251 | (long int) (ts->stop_time / 1000000), |
2252 | (long int) (ts->stop_time % 1000000)); | |
f196051f SS |
2253 | ui_out_field_string (uiout, "stop-time", buf); |
2254 | } | |
f224b49d VP |
2255 | } |
2256 | ||
2f9d54cf PA |
2257 | /* Check if a trace run is ongoing. If so, and FROM_TTY, query the |
2258 | user if she really wants to detach. */ | |
2259 | ||
d5551862 | 2260 | void |
2f9d54cf | 2261 | query_if_trace_running (int from_tty) |
d5551862 | 2262 | { |
2f9d54cf PA |
2263 | if (!from_tty) |
2264 | return; | |
2265 | ||
00bf0b85 SS |
2266 | /* It can happen that the target that was tracing went away on its |
2267 | own, and we didn't notice. Get a status update, and if the | |
2268 | current target doesn't even do tracing, then assume it's not | |
2269 | running anymore. */ | |
26afc0d7 | 2270 | if (target_get_trace_status (current_trace_status ()) < 0) |
00bf0b85 SS |
2271 | current_trace_status ()->running = 0; |
2272 | ||
33da3f1c SS |
2273 | /* If running interactively, give the user the option to cancel and |
2274 | then decide what to do differently with the run. Scripts are | |
2275 | just going to disconnect and let the target deal with it, | |
2276 | according to how it's been instructed previously via | |
2277 | disconnected-tracing. */ | |
2f9d54cf | 2278 | if (current_trace_status ()->running) |
d5551862 | 2279 | { |
bfccc43c YQ |
2280 | process_tracepoint_on_disconnect (); |
2281 | ||
33da3f1c SS |
2282 | if (current_trace_status ()->disconnected_tracing) |
2283 | { | |
3e43a32a MS |
2284 | if (!query (_("Trace is running and will " |
2285 | "continue after detach; detach anyway? "))) | |
33da3f1c SS |
2286 | error (_("Not confirmed.")); |
2287 | } | |
2288 | else | |
2289 | { | |
3e43a32a MS |
2290 | if (!query (_("Trace is running but will " |
2291 | "stop on detach; detach anyway? "))) | |
33da3f1c SS |
2292 | error (_("Not confirmed.")); |
2293 | } | |
d5551862 | 2294 | } |
2f9d54cf | 2295 | } |
8b9b7ef8 | 2296 | |
2f9d54cf PA |
2297 | /* This function handles the details of what to do about an ongoing |
2298 | tracing run if the user has asked to detach or otherwise disconnect | |
2299 | from the target. */ | |
2300 | ||
2301 | void | |
2302 | disconnect_tracing (void) | |
2303 | { | |
8b9b7ef8 SS |
2304 | /* Also we want to be out of tfind mode, otherwise things can get |
2305 | confusing upon reconnection. Just use these calls instead of | |
2306 | full tfind_1 behavior because we're in the middle of detaching, | |
2307 | and there's no point to updating current stack frame etc. */ | |
aef525cb | 2308 | trace_reset_local_state (); |
d5551862 SS |
2309 | } |
2310 | ||
d183932d | 2311 | /* Worker function for the various flavors of the tfind command. */ |
f197e0f1 VP |
2312 | void |
2313 | tfind_1 (enum trace_find_type type, int num, | |
cc5925ad | 2314 | CORE_ADDR addr1, CORE_ADDR addr2, |
f197e0f1 | 2315 | int from_tty) |
c906108c SS |
2316 | { |
2317 | int target_frameno = -1, target_tracept = -1; | |
2ce6d6bf | 2318 | struct frame_id old_frame_id = null_frame_id; |
d9b3f62e | 2319 | struct tracepoint *tp; |
79a45e25 | 2320 | struct ui_out *uiout = current_uiout; |
c906108c | 2321 | |
2ce6d6bf SS |
2322 | /* Only try to get the current stack frame if we have a chance of |
2323 | succeeding. In particular, if we're trying to get a first trace | |
2324 | frame while all threads are running, it's not going to succeed, | |
2325 | so leave it with a default value and let the frame comparison | |
2326 | below (correctly) decide to print out the source location of the | |
2327 | trace frame. */ | |
2328 | if (!(type == tfind_number && num == -1) | |
2329 | && (has_stack_frames () || traceframe_number >= 0)) | |
2330 | old_frame_id = get_frame_id (get_current_frame ()); | |
c906108c | 2331 | |
35b1e5cc SS |
2332 | target_frameno = target_trace_find (type, num, addr1, addr2, |
2333 | &target_tracept); | |
2334 | ||
2335 | if (type == tfind_number | |
2336 | && num == -1 | |
2337 | && target_frameno == -1) | |
2338 | { | |
2339 | /* We told the target to get out of tfind mode, and it did. */ | |
2340 | } | |
2341 | else if (target_frameno == -1) | |
2342 | { | |
2ce6d6bf | 2343 | /* A request for a non-existent trace frame has failed. |
35b1e5cc SS |
2344 | Our response will be different, depending on FROM_TTY: |
2345 | ||
2346 | If FROM_TTY is true, meaning that this command was | |
2347 | typed interactively by the user, then give an error | |
2348 | and DO NOT change the state of traceframe_number etc. | |
2349 | ||
2350 | However if FROM_TTY is false, meaning that we're either | |
2351 | in a script, a loop, or a user-defined command, then | |
2352 | DON'T give an error, but DO change the state of | |
2353 | traceframe_number etc. to invalid. | |
2354 | ||
2355 | The rationalle is that if you typed the command, you | |
2356 | might just have committed a typo or something, and you'd | |
2357 | like to NOT lose your current debugging state. However | |
2358 | if you're in a user-defined command or especially in a | |
2359 | loop, then you need a way to detect that the command | |
2360 | failed WITHOUT aborting. This allows you to write | |
2361 | scripts that search thru the trace buffer until the end, | |
2362 | and then continue on to do something else. */ | |
2363 | ||
2364 | if (from_tty) | |
2365 | error (_("Target failed to find requested trace frame.")); | |
2366 | else | |
2367 | { | |
2368 | if (info_verbose) | |
2369 | printf_filtered ("End of trace buffer.\n"); | |
c378eb4e | 2370 | #if 0 /* dubious now? */ |
35b1e5cc SS |
2371 | /* The following will not recurse, since it's |
2372 | special-cased. */ | |
2373 | trace_find_command ("-1", from_tty); | |
2374 | #endif | |
2375 | } | |
2376 | } | |
2377 | ||
d5551862 SS |
2378 | tp = get_tracepoint_by_number_on_target (target_tracept); |
2379 | ||
35f196d9 | 2380 | reinit_frame_cache (); |
2f4d8875 | 2381 | target_dcache_invalidate (); |
8d735b87 | 2382 | |
201b4506 YQ |
2383 | set_tracepoint_num (tp ? tp->base.number : target_tracept); |
2384 | ||
2385 | if (target_frameno != get_traceframe_number ()) | |
2386 | observer_notify_traceframe_changed (target_frameno, tracepoint_number); | |
2387 | ||
8d735b87 YQ |
2388 | set_current_traceframe (target_frameno); |
2389 | ||
c906108c | 2390 | if (target_frameno == -1) |
fb14de7b | 2391 | set_traceframe_context (NULL); |
c906108c | 2392 | else |
fb14de7b | 2393 | set_traceframe_context (get_current_frame ()); |
c906108c | 2394 | |
f197e0f1 VP |
2395 | if (traceframe_number >= 0) |
2396 | { | |
2397 | /* Use different branches for MI and CLI to make CLI messages | |
2398 | i18n-eable. */ | |
2399 | if (ui_out_is_mi_like_p (uiout)) | |
2400 | { | |
2401 | ui_out_field_string (uiout, "found", "1"); | |
2402 | ui_out_field_int (uiout, "tracepoint", tracepoint_number); | |
2403 | ui_out_field_int (uiout, "traceframe", traceframe_number); | |
2404 | } | |
2405 | else | |
2406 | { | |
2407 | printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"), | |
2408 | traceframe_number, tracepoint_number); | |
2409 | } | |
2410 | } | |
2411 | else | |
2412 | { | |
2413 | if (ui_out_is_mi_like_p (uiout)) | |
2414 | ui_out_field_string (uiout, "found", "0"); | |
4136fdd2 SS |
2415 | else if (type == tfind_number && num == -1) |
2416 | printf_unfiltered (_("No longer looking at any trace frame\n")); | |
c378eb4e | 2417 | else /* This case may never occur, check. */ |
4136fdd2 | 2418 | printf_unfiltered (_("No trace frame found\n")); |
f197e0f1 VP |
2419 | } |
2420 | ||
00bf0b85 SS |
2421 | /* If we're in nonstop mode and getting out of looking at trace |
2422 | frames, there won't be any current frame to go back to and | |
2423 | display. */ | |
2424 | if (from_tty | |
2425 | && (has_stack_frames () || traceframe_number >= 0)) | |
c906108c | 2426 | { |
0faf0076 | 2427 | enum print_what print_what; |
c906108c | 2428 | |
2ce6d6bf | 2429 | /* NOTE: in imitation of the step command, try to determine |
d183932d MS |
2430 | whether we have made a transition from one function to |
2431 | another. If so, we'll print the "stack frame" (ie. the new | |
2432 | function and it's arguments) -- otherwise we'll just show the | |
fb14de7b UW |
2433 | new source line. */ |
2434 | ||
2435 | if (frame_id_eq (old_frame_id, | |
2436 | get_frame_id (get_current_frame ()))) | |
0faf0076 | 2437 | print_what = SRC_LINE; |
c906108c | 2438 | else |
0faf0076 | 2439 | print_what = SRC_AND_LOC; |
c906108c | 2440 | |
08d72866 | 2441 | print_stack_frame (get_selected_frame (NULL), 1, print_what, 1); |
c906108c SS |
2442 | do_displays (); |
2443 | } | |
2444 | } | |
2445 | ||
cc3da688 YQ |
2446 | /* Error on looking at traceframes while trace is running. */ |
2447 | ||
2448 | void | |
2449 | check_trace_running (struct trace_status *status) | |
2450 | { | |
2451 | if (status->running && status->filename == NULL) | |
2452 | error (_("May not look at trace frames while trace is running.")); | |
2453 | } | |
2454 | ||
c906108c SS |
2455 | /* trace_find_command takes a trace frame number n, |
2456 | sends "QTFrame:<n>" to the target, | |
2457 | and accepts a reply that may contain several optional pieces | |
2458 | of information: a frame number, a tracepoint number, and an | |
2459 | indication of whether this is a trap frame or a stepping frame. | |
2460 | ||
2461 | The minimal response is just "OK" (which indicates that the | |
2462 | target does not give us a frame number or a tracepoint number). | |
2463 | Instead of that, the target may send us a string containing | |
2464 | any combination of: | |
c5aa993b JM |
2465 | F<hexnum> (gives the selected frame number) |
2466 | T<hexnum> (gives the selected tracepoint number) | |
2467 | */ | |
c906108c SS |
2468 | |
2469 | /* tfind command */ | |
2470 | static void | |
fba45db2 | 2471 | trace_find_command (char *args, int from_tty) |
c378eb4e | 2472 | { /* This should only be called with a numeric argument. */ |
c906108c | 2473 | int frameno = -1; |
c906108c | 2474 | |
cc3da688 | 2475 | check_trace_running (current_trace_status ()); |
35b1e5cc SS |
2476 | |
2477 | if (args == 0 || *args == 0) | |
2478 | { /* TFIND with no args means find NEXT trace frame. */ | |
2479 | if (traceframe_number == -1) | |
c378eb4e | 2480 | frameno = 0; /* "next" is first one. */ |
35b1e5cc SS |
2481 | else |
2482 | frameno = traceframe_number + 1; | |
2483 | } | |
2484 | else if (0 == strcmp (args, "-")) | |
c906108c | 2485 | { |
35b1e5cc SS |
2486 | if (traceframe_number == -1) |
2487 | error (_("not debugging trace buffer")); | |
2488 | else if (from_tty && traceframe_number == 0) | |
2489 | error (_("already at start of trace buffer")); | |
2490 | ||
2491 | frameno = traceframe_number - 1; | |
2492 | } | |
2493 | /* A hack to work around eval's need for fp to have been collected. */ | |
2494 | else if (0 == strcmp (args, "-1")) | |
2495 | frameno = -1; | |
2496 | else | |
2497 | frameno = parse_and_eval_long (args); | |
c906108c | 2498 | |
35b1e5cc SS |
2499 | if (frameno < -1) |
2500 | error (_("invalid input (%d is less than zero)"), frameno); | |
c906108c | 2501 | |
f197e0f1 | 2502 | tfind_1 (tfind_number, frameno, 0, 0, from_tty); |
c906108c SS |
2503 | } |
2504 | ||
2505 | /* tfind end */ | |
2506 | static void | |
fba45db2 | 2507 | trace_find_end_command (char *args, int from_tty) |
c906108c SS |
2508 | { |
2509 | trace_find_command ("-1", from_tty); | |
2510 | } | |
2511 | ||
c906108c SS |
2512 | /* tfind start */ |
2513 | static void | |
fba45db2 | 2514 | trace_find_start_command (char *args, int from_tty) |
c906108c SS |
2515 | { |
2516 | trace_find_command ("0", from_tty); | |
2517 | } | |
2518 | ||
2519 | /* tfind pc command */ | |
2520 | static void | |
fba45db2 | 2521 | trace_find_pc_command (char *args, int from_tty) |
d183932d | 2522 | { |
c906108c | 2523 | CORE_ADDR pc; |
c906108c | 2524 | |
cc3da688 | 2525 | check_trace_running (current_trace_status ()); |
c906108c | 2526 | |
35b1e5cc SS |
2527 | if (args == 0 || *args == 0) |
2528 | pc = regcache_read_pc (get_current_regcache ()); | |
c906108c | 2529 | else |
35b1e5cc SS |
2530 | pc = parse_and_eval_address (args); |
2531 | ||
f197e0f1 | 2532 | tfind_1 (tfind_pc, 0, pc, 0, from_tty); |
c906108c SS |
2533 | } |
2534 | ||
2535 | /* tfind tracepoint command */ | |
2536 | static void | |
fba45db2 | 2537 | trace_find_tracepoint_command (char *args, int from_tty) |
d183932d | 2538 | { |
c906108c | 2539 | int tdp; |
d9b3f62e | 2540 | struct tracepoint *tp; |
c906108c | 2541 | |
cc3da688 | 2542 | check_trace_running (current_trace_status ()); |
383e5f85 | 2543 | |
35b1e5cc SS |
2544 | if (args == 0 || *args == 0) |
2545 | { | |
2546 | if (tracepoint_number == -1) | |
2547 | error (_("No current tracepoint -- please supply an argument.")); | |
c906108c | 2548 | else |
c378eb4e | 2549 | tdp = tracepoint_number; /* Default is current TDP. */ |
c906108c SS |
2550 | } |
2551 | else | |
35b1e5cc SS |
2552 | tdp = parse_and_eval_long (args); |
2553 | ||
2554 | /* If we have the tracepoint on hand, use the number that the | |
2555 | target knows about (which may be different if we disconnected | |
2556 | and reconnected). */ | |
2557 | tp = get_tracepoint (tdp); | |
2558 | if (tp) | |
2559 | tdp = tp->number_on_target; | |
2560 | ||
f197e0f1 | 2561 | tfind_1 (tfind_tp, tdp, 0, 0, from_tty); |
c906108c SS |
2562 | } |
2563 | ||
2564 | /* TFIND LINE command: | |
c5aa993b | 2565 | |
c906108c | 2566 | This command will take a sourceline for argument, just like BREAK |
d183932d | 2567 | or TRACE (ie. anything that "decode_line_1" can handle). |
c5aa993b | 2568 | |
c906108c SS |
2569 | With no argument, this command will find the next trace frame |
2570 | corresponding to a source line OTHER THAN THE CURRENT ONE. */ | |
2571 | ||
2572 | static void | |
fba45db2 | 2573 | trace_find_line_command (char *args, int from_tty) |
d183932d | 2574 | { |
c906108c SS |
2575 | static CORE_ADDR start_pc, end_pc; |
2576 | struct symtabs_and_lines sals; | |
2577 | struct symtab_and_line sal; | |
c906108c SS |
2578 | struct cleanup *old_chain; |
2579 | ||
cc3da688 | 2580 | check_trace_running (current_trace_status ()); |
5af949e3 | 2581 | |
35b1e5cc SS |
2582 | if (args == 0 || *args == 0) |
2583 | { | |
2584 | sal = find_pc_line (get_frame_pc (get_current_frame ()), 0); | |
2585 | sals.nelts = 1; | |
8d749320 | 2586 | sals.sals = XNEW (struct symtab_and_line); |
35b1e5cc SS |
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; | |
f00aae0f KS |
2714 | struct event_location *location; |
2715 | struct cleanup *back_to; | |
c906108c SS |
2716 | |
2717 | if (args == 0 || *args == 0) | |
3e43a32a MS |
2718 | error (_("requires an argument (function, " |
2719 | "line or *addr) to define a scope")); | |
c906108c | 2720 | |
f00aae0f KS |
2721 | location = string_to_event_location (&args, current_language); |
2722 | back_to = make_cleanup_delete_event_location (location); | |
2723 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, 0); | |
c906108c | 2724 | if (sals.nelts == 0) |
f00aae0f KS |
2725 | { |
2726 | /* Presumably decode_line_1 has already warned. */ | |
2727 | do_cleanups (back_to); | |
2728 | return; | |
2729 | } | |
c906108c | 2730 | |
c378eb4e | 2731 | /* Resolve line numbers to PC. */ |
c906108c SS |
2732 | resolve_sal_pc (&sals.sals[0]); |
2733 | block = block_for_pc (sals.sals[0].pc); | |
2734 | ||
2735 | while (block != 0) | |
2736 | { | |
c378eb4e | 2737 | QUIT; /* Allow user to bail out with ^C. */ |
de4f826b | 2738 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
c906108c | 2739 | { |
c378eb4e | 2740 | QUIT; /* Allow user to bail out with ^C. */ |
c906108c SS |
2741 | if (count == 0) |
2742 | printf_filtered ("Scope for %s:\n", save_args); | |
2743 | count++; | |
e88c90f2 | 2744 | |
3567439c | 2745 | symname = SYMBOL_PRINT_NAME (sym); |
c906108c | 2746 | if (symname == NULL || *symname == '\0') |
c378eb4e | 2747 | continue; /* Probably botched, certainly useless. */ |
c906108c | 2748 | |
08be3fe3 | 2749 | gdbarch = symbol_arch (sym); |
768a979c | 2750 | |
c906108c | 2751 | printf_filtered ("Symbol %s is ", symname); |
24d6c2a0 TT |
2752 | |
2753 | if (SYMBOL_COMPUTED_OPS (sym) != NULL) | |
2754 | SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, | |
2755 | BLOCK_START (block), | |
2756 | gdb_stdout); | |
2757 | else | |
c5aa993b | 2758 | { |
24d6c2a0 | 2759 | switch (SYMBOL_CLASS (sym)) |
c5aa993b | 2760 | { |
24d6c2a0 TT |
2761 | default: |
2762 | case LOC_UNDEF: /* Messed up symbol? */ | |
2763 | printf_filtered ("a bogus symbol, class %d.\n", | |
2764 | SYMBOL_CLASS (sym)); | |
2765 | count--; /* Don't count this one. */ | |
2766 | continue; | |
2767 | case LOC_CONST: | |
2768 | printf_filtered ("a constant with value %s (%s)", | |
2769 | plongest (SYMBOL_VALUE (sym)), | |
2770 | hex_string (SYMBOL_VALUE (sym))); | |
2771 | break; | |
2772 | case LOC_CONST_BYTES: | |
2773 | printf_filtered ("constant bytes: "); | |
2774 | if (SYMBOL_TYPE (sym)) | |
2775 | for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++) | |
2776 | fprintf_filtered (gdb_stdout, " %02x", | |
2777 | (unsigned) SYMBOL_VALUE_BYTES (sym)[j]); | |
2778 | break; | |
2779 | case LOC_STATIC: | |
2780 | printf_filtered ("in static storage at address "); | |
2781 | printf_filtered ("%s", paddress (gdbarch, | |
2782 | SYMBOL_VALUE_ADDRESS (sym))); | |
2783 | break; | |
2784 | case LOC_REGISTER: | |
2785 | /* GDBARCH is the architecture associated with the objfile | |
2786 | the symbol is defined in; the target architecture may be | |
2787 | different, and may provide additional registers. However, | |
2788 | we do not know the target architecture at this point. | |
2789 | We assume the objfile architecture will contain all the | |
2790 | standard registers that occur in debug info in that | |
2791 | objfile. */ | |
2792 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, | |
2793 | gdbarch); | |
2794 | ||
2795 | if (SYMBOL_IS_ARGUMENT (sym)) | |
2796 | printf_filtered ("an argument in register $%s", | |
2797 | gdbarch_register_name (gdbarch, regno)); | |
2798 | else | |
2799 | printf_filtered ("a local variable in register $%s", | |
2800 | gdbarch_register_name (gdbarch, regno)); | |
2801 | break; | |
2802 | case LOC_ARG: | |
2803 | printf_filtered ("an argument at stack/frame offset %s", | |
2804 | plongest (SYMBOL_VALUE (sym))); | |
2805 | break; | |
2806 | case LOC_LOCAL: | |
2807 | printf_filtered ("a local variable at frame offset %s", | |
2808 | plongest (SYMBOL_VALUE (sym))); | |
2809 | break; | |
2810 | case LOC_REF_ARG: | |
2811 | printf_filtered ("a reference argument at offset %s", | |
2812 | plongest (SYMBOL_VALUE (sym))); | |
2813 | break; | |
2814 | case LOC_REGPARM_ADDR: | |
2815 | /* Note comment at LOC_REGISTER. */ | |
2816 | regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, | |
2817 | gdbarch); | |
2818 | printf_filtered ("the address of an argument, in register $%s", | |
2819 | gdbarch_register_name (gdbarch, regno)); | |
2820 | break; | |
2821 | case LOC_TYPEDEF: | |
2822 | printf_filtered ("a typedef.\n"); | |
2823 | continue; | |
2824 | case LOC_LABEL: | |
2825 | printf_filtered ("a label at address "); | |
2826 | printf_filtered ("%s", paddress (gdbarch, | |
2827 | SYMBOL_VALUE_ADDRESS (sym))); | |
2828 | break; | |
2829 | case LOC_BLOCK: | |
2830 | printf_filtered ("a function at address "); | |
5af949e3 | 2831 | printf_filtered ("%s", |
24d6c2a0 TT |
2832 | paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym)))); |
2833 | break; | |
2834 | case LOC_UNRESOLVED: | |
2835 | msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym), | |
2836 | NULL, NULL); | |
3b7344d5 | 2837 | if (msym.minsym == NULL) |
24d6c2a0 TT |
2838 | printf_filtered ("Unresolved Static"); |
2839 | else | |
2840 | { | |
2841 | printf_filtered ("static storage at address "); | |
2842 | printf_filtered ("%s", | |
2843 | paddress (gdbarch, | |
77e371c0 | 2844 | BMSYMBOL_VALUE_ADDRESS (msym))); |
24d6c2a0 TT |
2845 | } |
2846 | break; | |
2847 | case LOC_OPTIMIZED_OUT: | |
2848 | printf_filtered ("optimized out.\n"); | |
2849 | continue; | |
2850 | case LOC_COMPUTED: | |
2851 | gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method")); | |
c5aa993b | 2852 | } |
c5aa993b | 2853 | } |
c906108c | 2854 | if (SYMBOL_TYPE (sym)) |
c5aa993b | 2855 | printf_filtered (", length %d.\n", |
450bd37b | 2856 | TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)))); |
c906108c SS |
2857 | } |
2858 | if (BLOCK_FUNCTION (block)) | |
2859 | break; | |
2860 | else | |
2861 | block = BLOCK_SUPERBLOCK (block); | |
2862 | } | |
2863 | if (count <= 0) | |
2864 | printf_filtered ("Scope for %s contains no locals or arguments.\n", | |
2865 | save_args); | |
f00aae0f | 2866 | do_cleanups (back_to); |
c906108c SS |
2867 | } |
2868 | ||
afd02f27 PA |
2869 | /* Helper for trace_dump_command. Dump the action list starting at |
2870 | ACTION. STEPPING_ACTIONS is true if we're iterating over the | |
2871 | actions of the body of a while-stepping action. STEPPING_FRAME is | |
2872 | set if the current traceframe was determined to be a while-stepping | |
2873 | traceframe. */ | |
2874 | ||
c906108c | 2875 | static void |
afd02f27 PA |
2876 | trace_dump_actions (struct command_line *action, |
2877 | int stepping_actions, int stepping_frame, | |
2878 | int from_tty) | |
c906108c | 2879 | { |
6f937416 | 2880 | const char *action_exp, *next_comma; |
c906108c | 2881 | |
afd02f27 | 2882 | for (; action != NULL; action = action->next) |
c906108c SS |
2883 | { |
2884 | struct cmd_list_element *cmd; | |
2885 | ||
c378eb4e | 2886 | QUIT; /* Allow user to bail out with ^C. */ |
a7bdde9e | 2887 | action_exp = action->line; |
6f937416 | 2888 | action_exp = skip_spaces_const (action_exp); |
c906108c SS |
2889 | |
2890 | /* The collection actions to be done while stepping are | |
c5aa993b | 2891 | bracketed by the commands "while-stepping" and "end". */ |
c906108c SS |
2892 | |
2893 | if (*action_exp == '#') /* comment line */ | |
2894 | continue; | |
2895 | ||
2896 | cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1); | |
2897 | if (cmd == 0) | |
8a3fe4f8 | 2898 | error (_("Bad action list item: %s"), action_exp); |
c906108c | 2899 | |
bbaca940 | 2900 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
afd02f27 PA |
2901 | { |
2902 | int i; | |
2903 | ||
2904 | for (i = 0; i < action->body_count; ++i) | |
2905 | trace_dump_actions (action->body_list[i], | |
2906 | 1, stepping_frame, from_tty); | |
2907 | } | |
bbaca940 | 2908 | else if (cmd_cfunc_eq (cmd, collect_pseudocommand)) |
c906108c SS |
2909 | { |
2910 | /* Display the collected data. | |
d183932d MS |
2911 | For the trap frame, display only what was collected at |
2912 | the trap. Likewise for stepping frames, display only | |
2913 | what was collected while stepping. This means that the | |
2914 | two boolean variables, STEPPING_FRAME and | |
2915 | STEPPING_ACTIONS should be equal. */ | |
c906108c SS |
2916 | if (stepping_frame == stepping_actions) |
2917 | { | |
6f937416 PA |
2918 | char *cmd = NULL; |
2919 | struct cleanup *old_chain | |
2920 | = make_cleanup (free_current_contents, &cmd); | |
92bc6a20 | 2921 | int trace_string = 0; |
6f937416 | 2922 | |
3065dfb6 | 2923 | if (*action_exp == '/') |
92bc6a20 | 2924 | action_exp = decode_agent_options (action_exp, &trace_string); |
3065dfb6 | 2925 | |
c5aa993b | 2926 | do |
c378eb4e MS |
2927 | { /* Repeat over a comma-separated list. */ |
2928 | QUIT; /* Allow user to bail out with ^C. */ | |
c5aa993b JM |
2929 | if (*action_exp == ',') |
2930 | action_exp++; | |
6f937416 | 2931 | action_exp = skip_spaces_const (action_exp); |
c5aa993b JM |
2932 | |
2933 | next_comma = strchr (action_exp, ','); | |
2934 | ||
2935 | if (0 == strncasecmp (action_exp, "$reg", 4)) | |
2936 | registers_info (NULL, from_tty); | |
6710bf39 SS |
2937 | else if (0 == strncasecmp (action_exp, "$_ret", 5)) |
2938 | ; | |
c5aa993b JM |
2939 | else if (0 == strncasecmp (action_exp, "$loc", 4)) |
2940 | locals_info (NULL, from_tty); | |
2941 | else if (0 == strncasecmp (action_exp, "$arg", 4)) | |
2942 | args_info (NULL, from_tty); | |
2943 | else | |
2944 | { /* variable */ | |
6f937416 | 2945 | if (next_comma != NULL) |
c5aa993b | 2946 | { |
6f937416 PA |
2947 | size_t len = next_comma - action_exp; |
2948 | ||
224c3ddb | 2949 | cmd = (char *) xrealloc (cmd, len + 1); |
6f937416 PA |
2950 | memcpy (cmd, action_exp, len); |
2951 | cmd[len] = 0; | |
2952 | } | |
2953 | else | |
2954 | { | |
2955 | size_t len = strlen (action_exp); | |
2956 | ||
224c3ddb | 2957 | cmd = (char *) xrealloc (cmd, len + 1); |
6f937416 | 2958 | memcpy (cmd, action_exp, len + 1); |
c5aa993b | 2959 | } |
6f937416 PA |
2960 | |
2961 | printf_filtered ("%s = ", cmd); | |
2962 | output_command_const (cmd, from_tty); | |
c5aa993b JM |
2963 | printf_filtered ("\n"); |
2964 | } | |
c5aa993b JM |
2965 | action_exp = next_comma; |
2966 | } | |
2967 | while (action_exp && *action_exp == ','); | |
6f937416 PA |
2968 | |
2969 | do_cleanups (old_chain); | |
c906108c SS |
2970 | } |
2971 | } | |
2972 | } | |
afd02f27 PA |
2973 | } |
2974 | ||
ddacd3c8 YQ |
2975 | /* Return bp_location of the tracepoint associated with the current |
2976 | traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe | |
2977 | is a stepping traceframe. */ | |
2978 | ||
dc673c81 | 2979 | struct bp_location * |
ddacd3c8 YQ |
2980 | get_traceframe_location (int *stepping_frame_p) |
2981 | { | |
2982 | struct tracepoint *t; | |
2983 | struct bp_location *tloc; | |
2984 | struct regcache *regcache; | |
2985 | ||
2986 | if (tracepoint_number == -1) | |
2987 | error (_("No current trace frame.")); | |
2988 | ||
2989 | t = get_tracepoint (tracepoint_number); | |
2990 | ||
2991 | if (t == NULL) | |
2992 | error (_("No known tracepoint matches 'current' tracepoint #%d."), | |
2993 | tracepoint_number); | |
2994 | ||
2995 | /* The current frame is a trap frame if the frame PC is equal to the | |
2996 | tracepoint PC. If not, then the current frame was collected | |
2997 | during single-stepping. */ | |
2998 | regcache = get_current_regcache (); | |
2999 | ||
3000 | /* If the traceframe's address matches any of the tracepoint's | |
3001 | locations, assume it is a direct hit rather than a while-stepping | |
3002 | frame. (FIXME this is not reliable, should record each frame's | |
3003 | type.) */ | |
3004 | for (tloc = t->base.loc; tloc; tloc = tloc->next) | |
3005 | if (tloc->address == regcache_read_pc (regcache)) | |
3006 | { | |
3007 | *stepping_frame_p = 0; | |
3008 | return tloc; | |
3009 | } | |
3010 | ||
3011 | /* If this is a stepping frame, we don't know which location | |
3012 | triggered. The first is as good (or bad) a guess as any... */ | |
3013 | *stepping_frame_p = 1; | |
3014 | return t->base.loc; | |
3015 | } | |
3016 | ||
3ca73e0c YQ |
3017 | /* Return all the actions, including default collect, of a tracepoint |
3018 | T. It constructs cleanups into the chain, and leaves the caller to | |
3019 | handle them (call do_cleanups). */ | |
3020 | ||
3021 | static struct command_line * | |
3022 | all_tracepoint_actions_and_cleanup (struct breakpoint *t) | |
3023 | { | |
3024 | struct command_line *actions; | |
3025 | ||
3026 | actions = breakpoint_commands (t); | |
3027 | ||
3028 | /* If there are default expressions to collect, make up a collect | |
3029 | action and prepend to the action list to encode. Note that since | |
3030 | validation is per-tracepoint (local var "xyz" might be valid for | |
3031 | one tracepoint and not another, etc), we make up the action on | |
3032 | the fly, and don't cache it. */ | |
3033 | if (*default_collect) | |
3034 | { | |
3035 | struct command_line *default_collect_action; | |
3036 | char *default_collect_line; | |
3037 | ||
3038 | default_collect_line = xstrprintf ("collect %s", default_collect); | |
3039 | make_cleanup (xfree, default_collect_line); | |
3040 | ||
3041 | validate_actionline (default_collect_line, t); | |
8d749320 | 3042 | default_collect_action = XNEW (struct command_line); |
3ca73e0c YQ |
3043 | make_cleanup (xfree, default_collect_action); |
3044 | default_collect_action->next = actions; | |
3045 | default_collect_action->line = default_collect_line; | |
3046 | actions = default_collect_action; | |
3047 | } | |
3048 | ||
3049 | return actions; | |
3050 | } | |
3051 | ||
afd02f27 PA |
3052 | /* The tdump command. */ |
3053 | ||
3054 | static void | |
3055 | trace_dump_command (char *args, int from_tty) | |
3056 | { | |
afd02f27 PA |
3057 | int stepping_frame = 0; |
3058 | struct bp_location *loc; | |
4fd2d6af | 3059 | struct cleanup *old_chain; |
ddacd3c8 | 3060 | struct command_line *actions; |
afd02f27 | 3061 | |
ddacd3c8 YQ |
3062 | /* This throws an error is not inspecting a trace frame. */ |
3063 | loc = get_traceframe_location (&stepping_frame); | |
afd02f27 PA |
3064 | |
3065 | printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n", | |
3066 | tracepoint_number, traceframe_number); | |
3067 | ||
ddacd3c8 | 3068 | old_chain = make_cleanup (null_cleanup, NULL); |
de74e63a YQ |
3069 | |
3070 | /* This command only makes sense for the current frame, not the | |
3071 | selected frame. */ | |
3072 | make_cleanup_restore_current_thread (); | |
3073 | select_frame (get_current_frame ()); | |
3074 | ||
ddacd3c8 | 3075 | actions = all_tracepoint_actions_and_cleanup (loc->owner); |
2114d44c SS |
3076 | |
3077 | trace_dump_actions (actions, 0, stepping_frame, from_tty); | |
3078 | ||
4fd2d6af | 3079 | do_cleanups (old_chain); |
c906108c SS |
3080 | } |
3081 | ||
409873ef SS |
3082 | /* Encode a piece of a tracepoint's source-level definition in a form |
3083 | that is suitable for both protocol and saving in files. */ | |
3084 | /* This version does not do multiple encodes for long strings; it should | |
3085 | return an offset to the next piece to encode. FIXME */ | |
3086 | ||
3087 | extern int | |
3088 | encode_source_string (int tpnum, ULONGEST addr, | |
f00aae0f | 3089 | char *srctype, const char *src, char *buf, int buf_size) |
409873ef SS |
3090 | { |
3091 | if (80 + strlen (srctype) > buf_size) | |
3092 | error (_("Buffer too small for source encoding")); | |
3093 | sprintf (buf, "%x:%s:%s:%x:%x:", | |
3e43a32a MS |
3094 | tpnum, phex_nz (addr, sizeof (addr)), |
3095 | srctype, 0, (int) strlen (src)); | |
409873ef SS |
3096 | if (strlen (buf) + strlen (src) * 2 >= buf_size) |
3097 | error (_("Source string too long for buffer")); | |
9f1b45b0 | 3098 | bin2hex ((gdb_byte *) src, buf + strlen (buf), strlen (src)); |
409873ef SS |
3099 | return -1; |
3100 | } | |
3101 | ||
d5551862 SS |
3102 | /* Tell the target what to do with an ongoing tracing run if GDB |
3103 | disconnects for some reason. */ | |
3104 | ||
d5551862 SS |
3105 | static void |
3106 | set_disconnected_tracing (char *args, int from_tty, | |
3107 | struct cmd_list_element *c) | |
3108 | { | |
f196051f | 3109 | target_set_disconnected_tracing (disconnected_tracing); |
d5551862 SS |
3110 | } |
3111 | ||
4daf5ac0 SS |
3112 | static void |
3113 | set_circular_trace_buffer (char *args, int from_tty, | |
3114 | struct cmd_list_element *c) | |
3115 | { | |
3116 | target_set_circular_trace_buffer (circular_trace_buffer); | |
3117 | } | |
3118 | ||
f6f899bf HAQ |
3119 | static void |
3120 | set_trace_buffer_size (char *args, int from_tty, | |
3121 | struct cmd_list_element *c) | |
3122 | { | |
3123 | target_set_trace_buffer_size (trace_buffer_size); | |
3124 | } | |
3125 | ||
f196051f SS |
3126 | static void |
3127 | set_trace_user (char *args, int from_tty, | |
3128 | struct cmd_list_element *c) | |
3129 | { | |
3130 | int ret; | |
3131 | ||
3132 | ret = target_set_trace_notes (trace_user, NULL, NULL); | |
3133 | ||
3134 | if (!ret) | |
43011e52 | 3135 | warning (_("Target does not support trace notes, user ignored")); |
f196051f SS |
3136 | } |
3137 | ||
3138 | static void | |
3139 | set_trace_notes (char *args, int from_tty, | |
3140 | struct cmd_list_element *c) | |
3141 | { | |
3142 | int ret; | |
3143 | ||
3144 | ret = target_set_trace_notes (NULL, trace_notes, NULL); | |
3145 | ||
3146 | if (!ret) | |
43011e52 | 3147 | warning (_("Target does not support trace notes, note ignored")); |
f196051f SS |
3148 | } |
3149 | ||
3150 | static void | |
3151 | set_trace_stop_notes (char *args, int from_tty, | |
3152 | struct cmd_list_element *c) | |
3153 | { | |
3154 | int ret; | |
3155 | ||
3156 | ret = target_set_trace_notes (NULL, NULL, trace_stop_notes); | |
3157 | ||
3158 | if (!ret) | |
43011e52 | 3159 | warning (_("Target does not support trace notes, stop note ignored")); |
f196051f SS |
3160 | } |
3161 | ||
c906108c SS |
3162 | /* Convert the memory pointed to by mem into hex, placing result in buf. |
3163 | * Return a pointer to the last char put in buf (null) | |
3164 | * "stolen" from sparc-stub.c | |
3165 | */ | |
3166 | ||
c5aa993b | 3167 | static const char hexchars[] = "0123456789abcdef"; |
c906108c | 3168 | |
47b667de AC |
3169 | static char * |
3170 | mem2hex (gdb_byte *mem, char *buf, int count) | |
c906108c | 3171 | { |
47b667de | 3172 | gdb_byte ch; |
c906108c SS |
3173 | |
3174 | while (count-- > 0) | |
3175 | { | |
3176 | ch = *mem++; | |
3177 | ||
3178 | *buf++ = hexchars[ch >> 4]; | |
3179 | *buf++ = hexchars[ch & 0xf]; | |
3180 | } | |
3181 | ||
3182 | *buf = 0; | |
3183 | ||
3184 | return buf; | |
3185 | } | |
3186 | ||
c5aa993b | 3187 | int |
fba45db2 | 3188 | get_traceframe_number (void) |
c906108c | 3189 | { |
c5aa993b | 3190 | return traceframe_number; |
c906108c SS |
3191 | } |
3192 | ||
393fd4c3 YQ |
3193 | int |
3194 | get_tracepoint_number (void) | |
3195 | { | |
3196 | return tracepoint_number; | |
3197 | } | |
3198 | ||
06cd862c PA |
3199 | /* Make the traceframe NUM be the current trace frame. Does nothing |
3200 | if NUM is already current. */ | |
3201 | ||
3202 | void | |
e6e4e701 | 3203 | set_current_traceframe (int num) |
06cd862c PA |
3204 | { |
3205 | int newnum; | |
3206 | ||
3207 | if (traceframe_number == num) | |
3208 | { | |
3209 | /* Nothing to do. */ | |
3210 | return; | |
3211 | } | |
3212 | ||
3213 | newnum = target_trace_find (tfind_number, num, 0, 0, NULL); | |
3214 | ||
3215 | if (newnum != num) | |
3216 | warning (_("could not change traceframe")); | |
3217 | ||
8d735b87 | 3218 | set_traceframe_num (newnum); |
06cd862c PA |
3219 | |
3220 | /* Changing the traceframe changes our view of registers and of the | |
3221 | frame chain. */ | |
3222 | registers_changed (); | |
b3b9301e PA |
3223 | |
3224 | clear_traceframe_info (); | |
06cd862c PA |
3225 | } |
3226 | ||
3227 | /* A cleanup used when switching away and back from tfind mode. */ | |
3228 | ||
3229 | struct current_traceframe_cleanup | |
3230 | { | |
3231 | /* The traceframe we were inspecting. */ | |
3232 | int traceframe_number; | |
3233 | }; | |
3234 | ||
3235 | static void | |
3236 | do_restore_current_traceframe_cleanup (void *arg) | |
3237 | { | |
19ba03f4 SM |
3238 | struct current_traceframe_cleanup *old |
3239 | = (struct current_traceframe_cleanup *) arg; | |
06cd862c | 3240 | |
e6e4e701 | 3241 | set_current_traceframe (old->traceframe_number); |
06cd862c PA |
3242 | } |
3243 | ||
3244 | static void | |
3245 | restore_current_traceframe_cleanup_dtor (void *arg) | |
3246 | { | |
19ba03f4 SM |
3247 | struct current_traceframe_cleanup *old |
3248 | = (struct current_traceframe_cleanup *) arg; | |
06cd862c PA |
3249 | |
3250 | xfree (old); | |
3251 | } | |
3252 | ||
3253 | struct cleanup * | |
3254 | make_cleanup_restore_current_traceframe (void) | |
3255 | { | |
8d749320 SM |
3256 | struct current_traceframe_cleanup *old = |
3257 | XNEW (struct current_traceframe_cleanup); | |
06cd862c | 3258 | |
06cd862c PA |
3259 | old->traceframe_number = traceframe_number; |
3260 | ||
3261 | return make_cleanup_dtor (do_restore_current_traceframe_cleanup, old, | |
3262 | restore_current_traceframe_cleanup_dtor); | |
3263 | } | |
00bf0b85 SS |
3264 | |
3265 | /* Given a number and address, return an uploaded tracepoint with that | |
3266 | number, creating if necessary. */ | |
3267 | ||
3268 | struct uploaded_tp * | |
3269 | get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp) | |
3270 | { | |
3271 | struct uploaded_tp *utp; | |
3272 | ||
3273 | for (utp = *utpp; utp; utp = utp->next) | |
3274 | if (utp->number == num && utp->addr == addr) | |
3275 | return utp; | |
8d749320 SM |
3276 | |
3277 | utp = XCNEW (struct uploaded_tp); | |
00bf0b85 SS |
3278 | utp->number = num; |
3279 | utp->addr = addr; | |
3149d8c1 SS |
3280 | utp->actions = NULL; |
3281 | utp->step_actions = NULL; | |
3282 | utp->cmd_strings = NULL; | |
00bf0b85 SS |
3283 | utp->next = *utpp; |
3284 | *utpp = utp; | |
8d749320 | 3285 | |
00bf0b85 SS |
3286 | return utp; |
3287 | } | |
3288 | ||
7951c4eb | 3289 | void |
00bf0b85 SS |
3290 | free_uploaded_tps (struct uploaded_tp **utpp) |
3291 | { | |
3292 | struct uploaded_tp *next_one; | |
3293 | ||
3294 | while (*utpp) | |
3295 | { | |
3296 | next_one = (*utpp)->next; | |
3297 | xfree (*utpp); | |
3298 | *utpp = next_one; | |
3299 | } | |
3300 | } | |
3301 | ||
3302 | /* Given a number and address, return an uploaded tracepoint with that | |
3303 | number, creating if necessary. */ | |
3304 | ||
393fd4c3 | 3305 | struct uploaded_tsv * |
00bf0b85 SS |
3306 | get_uploaded_tsv (int num, struct uploaded_tsv **utsvp) |
3307 | { | |
3308 | struct uploaded_tsv *utsv; | |
3309 | ||
3310 | for (utsv = *utsvp; utsv; utsv = utsv->next) | |
3311 | if (utsv->number == num) | |
3312 | return utsv; | |
8d749320 SM |
3313 | |
3314 | utsv = XCNEW (struct uploaded_tsv); | |
00bf0b85 SS |
3315 | utsv->number = num; |
3316 | utsv->next = *utsvp; | |
3317 | *utsvp = utsv; | |
8d749320 | 3318 | |
00bf0b85 SS |
3319 | return utsv; |
3320 | } | |
3321 | ||
7951c4eb | 3322 | void |
00bf0b85 SS |
3323 | free_uploaded_tsvs (struct uploaded_tsv **utsvp) |
3324 | { | |
3325 | struct uploaded_tsv *next_one; | |
3326 | ||
3327 | while (*utsvp) | |
3328 | { | |
3329 | next_one = (*utsvp)->next; | |
3330 | xfree (*utsvp); | |
3331 | *utsvp = next_one; | |
3332 | } | |
3333 | } | |
3334 | ||
4e5c165d HZ |
3335 | /* FIXME this function is heuristic and will miss the cases where the |
3336 | conditional is semantically identical but differs in whitespace, | |
3337 | such as "x == 0" vs "x==0". */ | |
3338 | ||
3339 | static int | |
3340 | cond_string_is_same (char *str1, char *str2) | |
3341 | { | |
3342 | if (str1 == NULL || str2 == NULL) | |
3343 | return (str1 == str2); | |
3344 | ||
3345 | return (strcmp (str1, str2) == 0); | |
3346 | } | |
3347 | ||
00bf0b85 SS |
3348 | /* Look for an existing tracepoint that seems similar enough to the |
3349 | uploaded one. Enablement isn't compared, because the user can | |
3350 | toggle that freely, and may have done so in anticipation of the | |
1e4d1764 | 3351 | next trace run. Return the location of matched tracepoint. */ |
00bf0b85 | 3352 | |
70221824 | 3353 | static struct bp_location * |
1e4d1764 | 3354 | find_matching_tracepoint_location (struct uploaded_tp *utp) |
00bf0b85 SS |
3355 | { |
3356 | VEC(breakpoint_p) *tp_vec = all_tracepoints (); | |
3357 | int ix; | |
d9b3f62e | 3358 | struct breakpoint *b; |
00bf0b85 SS |
3359 | struct bp_location *loc; |
3360 | ||
d9b3f62e | 3361 | for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++) |
00bf0b85 | 3362 | { |
d9b3f62e PA |
3363 | struct tracepoint *t = (struct tracepoint *) b; |
3364 | ||
3365 | if (b->type == utp->type | |
00bf0b85 SS |
3366 | && t->step_count == utp->step |
3367 | && t->pass_count == utp->pass | |
4e5c165d HZ |
3368 | && cond_string_is_same (t->base.cond_string, utp->cond_string) |
3369 | /* FIXME also test actions. */ | |
00bf0b85 SS |
3370 | ) |
3371 | { | |
3372 | /* Scan the locations for an address match. */ | |
d9b3f62e | 3373 | for (loc = b->loc; loc; loc = loc->next) |
00bf0b85 SS |
3374 | { |
3375 | if (loc->address == utp->addr) | |
1e4d1764 | 3376 | return loc; |
00bf0b85 SS |
3377 | } |
3378 | } | |
3379 | } | |
3380 | return NULL; | |
3381 | } | |
3382 | ||
3383 | /* Given a list of tracepoints uploaded from a target, attempt to | |
3384 | match them up with existing tracepoints, and create new ones if not | |
3385 | found. */ | |
3386 | ||
3387 | void | |
3388 | merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps) | |
3389 | { | |
3390 | struct uploaded_tp *utp; | |
f2a8bc8a YQ |
3391 | /* A set of tracepoints which are modified. */ |
3392 | VEC(breakpoint_p) *modified_tp = NULL; | |
3393 | int ix; | |
3394 | struct breakpoint *b; | |
00bf0b85 SS |
3395 | |
3396 | /* Look for GDB tracepoints that match up with our uploaded versions. */ | |
3397 | for (utp = *uploaded_tps; utp; utp = utp->next) | |
3398 | { | |
1e4d1764 YQ |
3399 | struct bp_location *loc; |
3400 | struct tracepoint *t; | |
3401 | ||
3402 | loc = find_matching_tracepoint_location (utp); | |
3403 | if (loc) | |
3404 | { | |
f2a8bc8a YQ |
3405 | int found = 0; |
3406 | ||
1e4d1764 YQ |
3407 | /* Mark this location as already inserted. */ |
3408 | loc->inserted = 1; | |
3409 | t = (struct tracepoint *) loc->owner; | |
3410 | printf_filtered (_("Assuming tracepoint %d is same " | |
3411 | "as target's tracepoint %d at %s.\n"), | |
3412 | loc->owner->number, utp->number, | |
3413 | paddress (loc->gdbarch, utp->addr)); | |
f2a8bc8a YQ |
3414 | |
3415 | /* The tracepoint LOC->owner was modified (the location LOC | |
3416 | was marked as inserted in the target). Save it in | |
3417 | MODIFIED_TP if not there yet. The 'breakpoint-modified' | |
3418 | observers will be notified later once for each tracepoint | |
3419 | saved in MODIFIED_TP. */ | |
3420 | for (ix = 0; | |
3421 | VEC_iterate (breakpoint_p, modified_tp, ix, b); | |
3422 | ix++) | |
3423 | if (b == loc->owner) | |
3424 | { | |
3425 | found = 1; | |
3426 | break; | |
3427 | } | |
3428 | if (!found) | |
3429 | VEC_safe_push (breakpoint_p, modified_tp, loc->owner); | |
1e4d1764 | 3430 | } |
00bf0b85 SS |
3431 | else |
3432 | { | |
3433 | t = create_tracepoint_from_upload (utp); | |
3434 | if (t) | |
3e43a32a MS |
3435 | printf_filtered (_("Created tracepoint %d for " |
3436 | "target's tracepoint %d at %s.\n"), | |
d9b3f62e | 3437 | t->base.number, utp->number, |
3e43a32a | 3438 | paddress (get_current_arch (), utp->addr)); |
00bf0b85 | 3439 | else |
3e43a32a MS |
3440 | printf_filtered (_("Failed to create tracepoint for target's " |
3441 | "tracepoint %d at %s, skipping it.\n"), | |
3442 | utp->number, | |
3443 | paddress (get_current_arch (), utp->addr)); | |
00bf0b85 SS |
3444 | } |
3445 | /* Whether found or created, record the number used by the | |
3446 | target, to help with mapping target tracepoints back to their | |
3447 | counterparts here. */ | |
3448 | if (t) | |
3449 | t->number_on_target = utp->number; | |
3450 | } | |
3451 | ||
f2a8bc8a YQ |
3452 | /* Notify 'breakpoint-modified' observer that at least one of B's |
3453 | locations was changed. */ | |
3454 | for (ix = 0; VEC_iterate (breakpoint_p, modified_tp, ix, b); ix++) | |
3455 | observer_notify_breakpoint_modified (b); | |
3456 | ||
3457 | VEC_free (breakpoint_p, modified_tp); | |
00bf0b85 SS |
3458 | free_uploaded_tps (uploaded_tps); |
3459 | } | |
3460 | ||
3461 | /* Trace state variables don't have much to identify them beyond their | |
3462 | name, so just use that to detect matches. */ | |
3463 | ||
70221824 | 3464 | static struct trace_state_variable * |
00bf0b85 SS |
3465 | find_matching_tsv (struct uploaded_tsv *utsv) |
3466 | { | |
3467 | if (!utsv->name) | |
3468 | return NULL; | |
3469 | ||
3470 | return find_trace_state_variable (utsv->name); | |
3471 | } | |
3472 | ||
70221824 | 3473 | static struct trace_state_variable * |
00bf0b85 SS |
3474 | create_tsv_from_upload (struct uploaded_tsv *utsv) |
3475 | { | |
3476 | const char *namebase; | |
df5a4bd3 | 3477 | char *buf; |
00bf0b85 SS |
3478 | int try_num = 0; |
3479 | struct trace_state_variable *tsv; | |
df5a4bd3 | 3480 | struct cleanup *old_chain; |
00bf0b85 SS |
3481 | |
3482 | if (utsv->name) | |
3483 | { | |
3484 | namebase = utsv->name; | |
df5a4bd3 | 3485 | buf = xstrprintf ("%s", namebase); |
00bf0b85 SS |
3486 | } |
3487 | else | |
3488 | { | |
3489 | namebase = "__tsv"; | |
df5a4bd3 | 3490 | buf = xstrprintf ("%s_%d", namebase, try_num++); |
00bf0b85 SS |
3491 | } |
3492 | ||
3493 | /* Fish for a name that is not in use. */ | |
c378eb4e | 3494 | /* (should check against all internal vars?) */ |
00bf0b85 | 3495 | while (find_trace_state_variable (buf)) |
df5a4bd3 HZ |
3496 | { |
3497 | xfree (buf); | |
3498 | buf = xstrprintf ("%s_%d", namebase, try_num++); | |
3499 | } | |
3500 | ||
3501 | old_chain = make_cleanup (xfree, buf); | |
00bf0b85 SS |
3502 | |
3503 | /* We have an available name, create the variable. */ | |
a0aa2878 | 3504 | tsv = create_trace_state_variable (buf); |
00bf0b85 SS |
3505 | tsv->initial_value = utsv->initial_value; |
3506 | tsv->builtin = utsv->builtin; | |
3507 | ||
134a2066 | 3508 | observer_notify_tsv_created (tsv); |
bb25a15c | 3509 | |
df5a4bd3 HZ |
3510 | do_cleanups (old_chain); |
3511 | ||
00bf0b85 SS |
3512 | return tsv; |
3513 | } | |
3514 | ||
3515 | /* Given a list of uploaded trace state variables, try to match them | |
3516 | up with existing variables, or create additional ones. */ | |
3517 | ||
3518 | void | |
3519 | merge_uploaded_trace_state_variables (struct uploaded_tsv **uploaded_tsvs) | |
3520 | { | |
3521 | int ix; | |
3522 | struct uploaded_tsv *utsv; | |
3523 | struct trace_state_variable *tsv; | |
3524 | int highest; | |
3525 | ||
3526 | /* Most likely some numbers will have to be reassigned as part of | |
3527 | the merge, so clear them all in anticipation. */ | |
3528 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
3529 | tsv->number = 0; | |
3530 | ||
3531 | for (utsv = *uploaded_tsvs; utsv; utsv = utsv->next) | |
3532 | { | |
3533 | tsv = find_matching_tsv (utsv); | |
3534 | if (tsv) | |
417b5110 DJ |
3535 | { |
3536 | if (info_verbose) | |
3e43a32a MS |
3537 | printf_filtered (_("Assuming trace state variable $%s " |
3538 | "is same as target's variable %d.\n"), | |
417b5110 DJ |
3539 | tsv->name, utsv->number); |
3540 | } | |
00bf0b85 SS |
3541 | else |
3542 | { | |
3543 | tsv = create_tsv_from_upload (utsv); | |
417b5110 | 3544 | if (info_verbose) |
3e43a32a MS |
3545 | printf_filtered (_("Created trace state variable " |
3546 | "$%s for target's variable %d.\n"), | |
417b5110 | 3547 | tsv->name, utsv->number); |
00bf0b85 SS |
3548 | } |
3549 | /* Give precedence to numberings that come from the target. */ | |
3550 | if (tsv) | |
3551 | tsv->number = utsv->number; | |
3552 | } | |
3553 | ||
3554 | /* Renumber everything that didn't get a target-assigned number. */ | |
3555 | highest = 0; | |
3556 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
3557 | if (tsv->number > highest) | |
3558 | highest = tsv->number; | |
3559 | ||
3560 | ++highest; | |
3561 | for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix) | |
3562 | if (tsv->number == 0) | |
3563 | tsv->number = highest++; | |
3564 | ||
3565 | free_uploaded_tsvs (uploaded_tsvs); | |
3566 | } | |
3567 | ||
00bf0b85 SS |
3568 | /* Parse the part of trace status syntax that is shared between |
3569 | the remote protocol and the trace file reader. */ | |
3570 | ||
00bf0b85 SS |
3571 | void |
3572 | parse_trace_status (char *line, struct trace_status *ts) | |
3573 | { | |
f196051f SS |
3574 | char *p = line, *p1, *p2, *p3, *p_temp; |
3575 | int end; | |
00bf0b85 SS |
3576 | ULONGEST val; |
3577 | ||
3578 | ts->running_known = 1; | |
3579 | ts->running = (*p++ == '1'); | |
3580 | ts->stop_reason = trace_stop_reason_unknown; | |
f196051f SS |
3581 | xfree (ts->stop_desc); |
3582 | ts->stop_desc = NULL; | |
4daf5ac0 SS |
3583 | ts->traceframe_count = -1; |
3584 | ts->traceframes_created = -1; | |
3585 | ts->buffer_free = -1; | |
3586 | ts->buffer_size = -1; | |
33da3f1c SS |
3587 | ts->disconnected_tracing = 0; |
3588 | ts->circular_buffer = 0; | |
f196051f SS |
3589 | xfree (ts->user_name); |
3590 | ts->user_name = NULL; | |
3591 | xfree (ts->notes); | |
3592 | ts->notes = NULL; | |
3593 | ts->start_time = ts->stop_time = 0; | |
4daf5ac0 | 3594 | |
00bf0b85 SS |
3595 | while (*p++) |
3596 | { | |
3597 | p1 = strchr (p, ':'); | |
3598 | if (p1 == NULL) | |
3599 | error (_("Malformed trace status, at %s\n\ | |
3600 | Status line: '%s'\n"), p, line); | |
f196051f SS |
3601 | p3 = strchr (p, ';'); |
3602 | if (p3 == NULL) | |
3603 | p3 = p + strlen (p); | |
00bf0b85 SS |
3604 | if (strncmp (p, stop_reason_names[trace_buffer_full], p1 - p) == 0) |
3605 | { | |
3606 | p = unpack_varlen_hex (++p1, &val); | |
3607 | ts->stop_reason = trace_buffer_full; | |
3608 | } | |
3609 | else if (strncmp (p, stop_reason_names[trace_never_run], p1 - p) == 0) | |
3610 | { | |
3611 | p = unpack_varlen_hex (++p1, &val); | |
3612 | ts->stop_reason = trace_never_run; | |
3613 | } | |
3e43a32a MS |
3614 | else if (strncmp (p, stop_reason_names[tracepoint_passcount], |
3615 | p1 - p) == 0) | |
00bf0b85 SS |
3616 | { |
3617 | p = unpack_varlen_hex (++p1, &val); | |
3618 | ts->stop_reason = tracepoint_passcount; | |
3619 | ts->stopping_tracepoint = val; | |
3620 | } | |
3621 | else if (strncmp (p, stop_reason_names[tstop_command], p1 - p) == 0) | |
3622 | { | |
f196051f SS |
3623 | p2 = strchr (++p1, ':'); |
3624 | if (!p2 || p2 > p3) | |
3625 | { | |
3626 | /*older style*/ | |
3627 | p2 = p1; | |
3628 | } | |
3629 | else if (p2 != p1) | |
3630 | { | |
224c3ddb | 3631 | ts->stop_desc = (char *) xmalloc (strlen (line)); |
bc20a4af | 3632 | end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2); |
f196051f SS |
3633 | ts->stop_desc[end] = '\0'; |
3634 | } | |
3635 | else | |
3636 | ts->stop_desc = xstrdup (""); | |
3637 | ||
3638 | p = unpack_varlen_hex (++p2, &val); | |
00bf0b85 SS |
3639 | ts->stop_reason = tstop_command; |
3640 | } | |
33da3f1c SS |
3641 | else if (strncmp (p, stop_reason_names[trace_disconnected], p1 - p) == 0) |
3642 | { | |
3643 | p = unpack_varlen_hex (++p1, &val); | |
3644 | ts->stop_reason = trace_disconnected; | |
3645 | } | |
6c28cbf2 SS |
3646 | else if (strncmp (p, stop_reason_names[tracepoint_error], p1 - p) == 0) |
3647 | { | |
3648 | p2 = strchr (++p1, ':'); | |
3649 | if (p2 != p1) | |
3650 | { | |
224c3ddb | 3651 | ts->stop_desc = (char *) xmalloc ((p2 - p1) / 2 + 1); |
bc20a4af | 3652 | end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2); |
f196051f | 3653 | ts->stop_desc[end] = '\0'; |
6c28cbf2 | 3654 | } |
a609a0c8 | 3655 | else |
f196051f | 3656 | ts->stop_desc = xstrdup (""); |
a609a0c8 | 3657 | |
6c28cbf2 SS |
3658 | p = unpack_varlen_hex (++p2, &val); |
3659 | ts->stopping_tracepoint = val; | |
3660 | ts->stop_reason = tracepoint_error; | |
3661 | } | |
4daf5ac0 | 3662 | else if (strncmp (p, "tframes", p1 - p) == 0) |
00bf0b85 SS |
3663 | { |
3664 | p = unpack_varlen_hex (++p1, &val); | |
3665 | ts->traceframe_count = val; | |
3666 | } | |
4daf5ac0 SS |
3667 | else if (strncmp (p, "tcreated", p1 - p) == 0) |
3668 | { | |
3669 | p = unpack_varlen_hex (++p1, &val); | |
3670 | ts->traceframes_created = val; | |
3671 | } | |
3672 | else if (strncmp (p, "tfree", p1 - p) == 0) | |
00bf0b85 SS |
3673 | { |
3674 | p = unpack_varlen_hex (++p1, &val); | |
3675 | ts->buffer_free = val; | |
3676 | } | |
4daf5ac0 SS |
3677 | else if (strncmp (p, "tsize", p1 - p) == 0) |
3678 | { | |
3679 | p = unpack_varlen_hex (++p1, &val); | |
3680 | ts->buffer_size = val; | |
3681 | } | |
33da3f1c SS |
3682 | else if (strncmp (p, "disconn", p1 - p) == 0) |
3683 | { | |
3684 | p = unpack_varlen_hex (++p1, &val); | |
3685 | ts->disconnected_tracing = val; | |
3686 | } | |
3687 | else if (strncmp (p, "circular", p1 - p) == 0) | |
3688 | { | |
3689 | p = unpack_varlen_hex (++p1, &val); | |
3690 | ts->circular_buffer = val; | |
3691 | } | |
f196051f SS |
3692 | else if (strncmp (p, "starttime", p1 - p) == 0) |
3693 | { | |
3694 | p = unpack_varlen_hex (++p1, &val); | |
3695 | ts->start_time = val; | |
3696 | } | |
3697 | else if (strncmp (p, "stoptime", p1 - p) == 0) | |
3698 | { | |
3699 | p = unpack_varlen_hex (++p1, &val); | |
3700 | ts->stop_time = val; | |
3701 | } | |
3702 | else if (strncmp (p, "username", p1 - p) == 0) | |
3703 | { | |
3704 | ++p1; | |
224c3ddb | 3705 | ts->user_name = (char *) xmalloc (strlen (p) / 2); |
bc20a4af | 3706 | end = hex2bin (p1, (gdb_byte *) ts->user_name, (p3 - p1) / 2); |
f196051f SS |
3707 | ts->user_name[end] = '\0'; |
3708 | p = p3; | |
3709 | } | |
3710 | else if (strncmp (p, "notes", p1 - p) == 0) | |
3711 | { | |
3712 | ++p1; | |
224c3ddb | 3713 | ts->notes = (char *) xmalloc (strlen (p) / 2); |
bc20a4af | 3714 | end = hex2bin (p1, (gdb_byte *) ts->notes, (p3 - p1) / 2); |
f196051f SS |
3715 | ts->notes[end] = '\0'; |
3716 | p = p3; | |
3717 | } | |
00bf0b85 SS |
3718 | else |
3719 | { | |
3720 | /* Silently skip unknown optional info. */ | |
3721 | p_temp = strchr (p1 + 1, ';'); | |
3722 | if (p_temp) | |
3723 | p = p_temp; | |
3724 | else | |
3725 | /* Must be at the end. */ | |
3726 | break; | |
3727 | } | |
3728 | } | |
3729 | } | |
3730 | ||
f196051f SS |
3731 | void |
3732 | parse_tracepoint_status (char *p, struct breakpoint *bp, | |
3733 | struct uploaded_tp *utp) | |
3734 | { | |
3735 | ULONGEST uval; | |
3736 | struct tracepoint *tp = (struct tracepoint *) bp; | |
3737 | ||
3738 | p = unpack_varlen_hex (p, &uval); | |
3739 | if (tp) | |
3740 | tp->base.hit_count += uval; | |
3741 | else | |
3742 | utp->hit_count += uval; | |
3743 | p = unpack_varlen_hex (p + 1, &uval); | |
3744 | if (tp) | |
3745 | tp->traceframe_usage += uval; | |
3746 | else | |
3747 | utp->traceframe_usage += uval; | |
3748 | /* Ignore any extra, allowing for future extensions. */ | |
3749 | } | |
3750 | ||
409873ef SS |
3751 | /* Given a line of text defining a part of a tracepoint, parse it into |
3752 | an "uploaded tracepoint". */ | |
00bf0b85 SS |
3753 | |
3754 | void | |
3755 | parse_tracepoint_definition (char *line, struct uploaded_tp **utpp) | |
3756 | { | |
3757 | char *p; | |
3758 | char piece; | |
409873ef | 3759 | ULONGEST num, addr, step, pass, orig_size, xlen, start; |
2a2287c7 | 3760 | int enabled, end; |
00bf0b85 | 3761 | enum bptype type; |
2a2287c7 | 3762 | char *cond, *srctype, *buf; |
00bf0b85 SS |
3763 | struct uploaded_tp *utp = NULL; |
3764 | ||
3765 | p = line; | |
3766 | /* Both tracepoint and action definitions start with the same number | |
3767 | and address sequence. */ | |
3768 | piece = *p++; | |
3769 | p = unpack_varlen_hex (p, &num); | |
3770 | p++; /* skip a colon */ | |
3771 | p = unpack_varlen_hex (p, &addr); | |
3772 | p++; /* skip a colon */ | |
3773 | if (piece == 'T') | |
3774 | { | |
3775 | enabled = (*p++ == 'E'); | |
3776 | p++; /* skip a colon */ | |
3777 | p = unpack_varlen_hex (p, &step); | |
3778 | p++; /* skip a colon */ | |
3779 | p = unpack_varlen_hex (p, &pass); | |
3780 | type = bp_tracepoint; | |
3781 | cond = NULL; | |
3782 | /* Thumb through optional fields. */ | |
3783 | while (*p == ':') | |
3784 | { | |
3785 | p++; /* skip a colon */ | |
3786 | if (*p == 'F') | |
3787 | { | |
3788 | type = bp_fast_tracepoint; | |
3789 | p++; | |
3790 | p = unpack_varlen_hex (p, &orig_size); | |
3791 | } | |
0fb4aa4b PA |
3792 | else if (*p == 'S') |
3793 | { | |
3794 | type = bp_static_tracepoint; | |
3795 | p++; | |
3796 | } | |
00bf0b85 SS |
3797 | else if (*p == 'X') |
3798 | { | |
3799 | p++; | |
3800 | p = unpack_varlen_hex (p, &xlen); | |
3801 | p++; /* skip a comma */ | |
3802 | cond = (char *) xmalloc (2 * xlen + 1); | |
3803 | strncpy (cond, p, 2 * xlen); | |
3804 | cond[2 * xlen] = '\0'; | |
3805 | p += 2 * xlen; | |
3806 | } | |
3807 | else | |
3e43a32a MS |
3808 | warning (_("Unrecognized char '%c' in tracepoint " |
3809 | "definition, skipping rest"), *p); | |
00bf0b85 SS |
3810 | } |
3811 | utp = get_uploaded_tp (num, addr, utpp); | |
3812 | utp->type = type; | |
3813 | utp->enabled = enabled; | |
3814 | utp->step = step; | |
3815 | utp->pass = pass; | |
3816 | utp->cond = cond; | |
3817 | } | |
3818 | else if (piece == 'A') | |
3819 | { | |
3820 | utp = get_uploaded_tp (num, addr, utpp); | |
3149d8c1 | 3821 | VEC_safe_push (char_ptr, utp->actions, xstrdup (p)); |
00bf0b85 SS |
3822 | } |
3823 | else if (piece == 'S') | |
3824 | { | |
3825 | utp = get_uploaded_tp (num, addr, utpp); | |
3149d8c1 | 3826 | VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p)); |
00bf0b85 | 3827 | } |
409873ef SS |
3828 | else if (piece == 'Z') |
3829 | { | |
3830 | /* Parse a chunk of source form definition. */ | |
3831 | utp = get_uploaded_tp (num, addr, utpp); | |
3832 | srctype = p; | |
3833 | p = strchr (p, ':'); | |
3834 | p++; /* skip a colon */ | |
3835 | p = unpack_varlen_hex (p, &start); | |
3836 | p++; /* skip a colon */ | |
3837 | p = unpack_varlen_hex (p, &xlen); | |
3838 | p++; /* skip a colon */ | |
3839 | ||
224c3ddb | 3840 | buf = (char *) alloca (strlen (line)); |
409873ef SS |
3841 | |
3842 | end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2); | |
3843 | buf[end] = '\0'; | |
3844 | ||
61012eef | 3845 | if (startswith (srctype, "at:")) |
409873ef | 3846 | utp->at_string = xstrdup (buf); |
61012eef | 3847 | else if (startswith (srctype, "cond:")) |
409873ef | 3848 | utp->cond_string = xstrdup (buf); |
61012eef | 3849 | else if (startswith (srctype, "cmd:")) |
3149d8c1 | 3850 | VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf)); |
409873ef | 3851 | } |
f196051f SS |
3852 | else if (piece == 'V') |
3853 | { | |
3854 | utp = get_uploaded_tp (num, addr, utpp); | |
3855 | ||
3856 | parse_tracepoint_status (p, NULL, utp); | |
3857 | } | |
00bf0b85 SS |
3858 | else |
3859 | { | |
409873ef SS |
3860 | /* Don't error out, the target might be sending us optional |
3861 | info that we don't care about. */ | |
3862 | warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece); | |
00bf0b85 SS |
3863 | } |
3864 | } | |
3865 | ||
3866 | /* Convert a textual description of a trace state variable into an | |
3867 | uploaded object. */ | |
3868 | ||
3869 | void | |
3870 | parse_tsv_definition (char *line, struct uploaded_tsv **utsvp) | |
3871 | { | |
3872 | char *p, *buf; | |
3873 | ULONGEST num, initval, builtin; | |
3874 | int end; | |
3875 | struct uploaded_tsv *utsv = NULL; | |
3876 | ||
224c3ddb | 3877 | buf = (char *) alloca (strlen (line)); |
00bf0b85 SS |
3878 | |
3879 | p = line; | |
3880 | p = unpack_varlen_hex (p, &num); | |
3881 | p++; /* skip a colon */ | |
3882 | p = unpack_varlen_hex (p, &initval); | |
3883 | p++; /* skip a colon */ | |
3884 | p = unpack_varlen_hex (p, &builtin); | |
3885 | p++; /* skip a colon */ | |
3886 | end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2); | |
3887 | buf[end] = '\0'; | |
3888 | ||
3889 | utsv = get_uploaded_tsv (num, utsvp); | |
3890 | utsv->initial_value = initval; | |
3891 | utsv->builtin = builtin; | |
3892 | utsv->name = xstrdup (buf); | |
3893 | } | |
3894 | ||
5808517f YQ |
3895 | void |
3896 | free_current_marker (void *arg) | |
3897 | { | |
19ba03f4 SM |
3898 | struct static_tracepoint_marker **marker_p |
3899 | = (struct static_tracepoint_marker **) arg; | |
5808517f YQ |
3900 | |
3901 | if (*marker_p != NULL) | |
3902 | { | |
3903 | release_static_tracepoint_marker (*marker_p); | |
3904 | xfree (*marker_p); | |
3905 | } | |
3906 | else | |
3907 | *marker_p = NULL; | |
3908 | } | |
3909 | ||
0fb4aa4b PA |
3910 | /* Given a line of text defining a static tracepoint marker, parse it |
3911 | into a "static tracepoint marker" object. Throws an error is | |
3912 | parsing fails. If PP is non-null, it points to one past the end of | |
3913 | the parsed marker definition. */ | |
3914 | ||
3915 | void | |
3916 | parse_static_tracepoint_marker_definition (char *line, char **pp, | |
3917 | struct static_tracepoint_marker *marker) | |
3918 | { | |
3919 | char *p, *endp; | |
3920 | ULONGEST addr; | |
3921 | int end; | |
3922 | ||
3923 | p = line; | |
3924 | p = unpack_varlen_hex (p, &addr); | |
3925 | p++; /* skip a colon */ | |
3926 | ||
f5656ead | 3927 | marker->gdbarch = target_gdbarch (); |
0fb4aa4b PA |
3928 | marker->address = (CORE_ADDR) addr; |
3929 | ||
3930 | endp = strchr (p, ':'); | |
3931 | if (endp == NULL) | |
74232302 | 3932 | error (_("bad marker definition: %s"), line); |
0fb4aa4b | 3933 | |
224c3ddb | 3934 | marker->str_id = (char *) xmalloc (endp - p + 1); |
0fb4aa4b PA |
3935 | end = hex2bin (p, (gdb_byte *) marker->str_id, (endp - p + 1) / 2); |
3936 | marker->str_id[end] = '\0'; | |
3937 | ||
3938 | p += 2 * end; | |
3939 | p++; /* skip a colon */ | |
3940 | ||
224c3ddb | 3941 | marker->extra = (char *) xmalloc (strlen (p) + 1); |
0fb4aa4b PA |
3942 | end = hex2bin (p, (gdb_byte *) marker->extra, strlen (p) / 2); |
3943 | marker->extra[end] = '\0'; | |
3944 | ||
3945 | if (pp) | |
3946 | *pp = p; | |
3947 | } | |
3948 | ||
3949 | /* Release a static tracepoint marker's contents. Note that the | |
3950 | object itself isn't released here. There objects are usually on | |
3951 | the stack. */ | |
3952 | ||
3953 | void | |
3954 | release_static_tracepoint_marker (struct static_tracepoint_marker *marker) | |
3955 | { | |
3956 | xfree (marker->str_id); | |
3957 | marker->str_id = NULL; | |
3958 | } | |
3959 | ||
3960 | /* Print MARKER to gdb_stdout. */ | |
3961 | ||
3962 | static void | |
3963 | print_one_static_tracepoint_marker (int count, | |
3964 | struct static_tracepoint_marker *marker) | |
3965 | { | |
3966 | struct command_line *l; | |
3967 | struct symbol *sym; | |
3968 | ||
3969 | char wrap_indent[80]; | |
3970 | char extra_field_indent[80]; | |
79a45e25 | 3971 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
3972 | struct cleanup *bkpt_chain; |
3973 | VEC(breakpoint_p) *tracepoints; | |
3974 | ||
3975 | struct symtab_and_line sal; | |
3976 | ||
3977 | init_sal (&sal); | |
3978 | ||
3979 | sal.pc = marker->address; | |
3980 | ||
3981 | tracepoints = static_tracepoints_here (marker->address); | |
3982 | ||
3983 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "marker"); | |
3984 | ||
3985 | /* A counter field to help readability. This is not a stable | |
3986 | identifier! */ | |
3987 | ui_out_field_int (uiout, "count", count); | |
3988 | ||
3989 | ui_out_field_string (uiout, "marker-id", marker->str_id); | |
3990 | ||
3991 | ui_out_field_fmt (uiout, "enabled", "%c", | |
3992 | !VEC_empty (breakpoint_p, tracepoints) ? 'y' : 'n'); | |
3993 | ui_out_spaces (uiout, 2); | |
3994 | ||
3995 | strcpy (wrap_indent, " "); | |
3996 | ||
3997 | if (gdbarch_addr_bit (marker->gdbarch) <= 32) | |
3998 | strcat (wrap_indent, " "); | |
3999 | else | |
4000 | strcat (wrap_indent, " "); | |
4001 | ||
4002 | strcpy (extra_field_indent, " "); | |
4003 | ||
4004 | ui_out_field_core_addr (uiout, "addr", marker->gdbarch, marker->address); | |
4005 | ||
4006 | sal = find_pc_line (marker->address, 0); | |
4007 | sym = find_pc_sect_function (marker->address, NULL); | |
4008 | if (sym) | |
4009 | { | |
4010 | ui_out_text (uiout, "in "); | |
4011 | ui_out_field_string (uiout, "func", | |
4012 | SYMBOL_PRINT_NAME (sym)); | |
4013 | ui_out_wrap_hint (uiout, wrap_indent); | |
4014 | ui_out_text (uiout, " at "); | |
4015 | } | |
4016 | else | |
4017 | ui_out_field_skip (uiout, "func"); | |
4018 | ||
4019 | if (sal.symtab != NULL) | |
4020 | { | |
05cba821 JK |
4021 | ui_out_field_string (uiout, "file", |
4022 | symtab_to_filename_for_display (sal.symtab)); | |
0fb4aa4b PA |
4023 | ui_out_text (uiout, ":"); |
4024 | ||
4025 | if (ui_out_is_mi_like_p (uiout)) | |
4026 | { | |
0b0865da | 4027 | const char *fullname = symtab_to_fullname (sal.symtab); |
0fb4aa4b | 4028 | |
f35a17b5 | 4029 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
4030 | } |
4031 | else | |
4032 | ui_out_field_skip (uiout, "fullname"); | |
4033 | ||
4034 | ui_out_field_int (uiout, "line", sal.line); | |
4035 | } | |
4036 | else | |
4037 | { | |
4038 | ui_out_field_skip (uiout, "fullname"); | |
4039 | ui_out_field_skip (uiout, "line"); | |
4040 | } | |
4041 | ||
4042 | ui_out_text (uiout, "\n"); | |
4043 | ui_out_text (uiout, extra_field_indent); | |
4044 | ui_out_text (uiout, _("Data: \"")); | |
4045 | ui_out_field_string (uiout, "extra-data", marker->extra); | |
4046 | ui_out_text (uiout, "\"\n"); | |
4047 | ||
4048 | if (!VEC_empty (breakpoint_p, tracepoints)) | |
4049 | { | |
4050 | struct cleanup *cleanup_chain; | |
4051 | int ix; | |
4052 | struct breakpoint *b; | |
4053 | ||
4054 | cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout, | |
4055 | "tracepoints-at"); | |
4056 | ||
4057 | ui_out_text (uiout, extra_field_indent); | |
4058 | ui_out_text (uiout, _("Probed by static tracepoints: ")); | |
4059 | for (ix = 0; VEC_iterate(breakpoint_p, tracepoints, ix, b); ix++) | |
4060 | { | |
4061 | if (ix > 0) | |
4062 | ui_out_text (uiout, ", "); | |
4063 | ui_out_text (uiout, "#"); | |
4064 | ui_out_field_int (uiout, "tracepoint-id", b->number); | |
4065 | } | |
4066 | ||
4067 | do_cleanups (cleanup_chain); | |
4068 | ||
4069 | if (ui_out_is_mi_like_p (uiout)) | |
4070 | ui_out_field_int (uiout, "number-of-tracepoints", | |
4071 | VEC_length(breakpoint_p, tracepoints)); | |
4072 | else | |
4073 | ui_out_text (uiout, "\n"); | |
4074 | } | |
4075 | VEC_free (breakpoint_p, tracepoints); | |
4076 | ||
4077 | do_cleanups (bkpt_chain); | |
0fb4aa4b PA |
4078 | } |
4079 | ||
4080 | static void | |
4081 | info_static_tracepoint_markers_command (char *arg, int from_tty) | |
4082 | { | |
4083 | VEC(static_tracepoint_marker_p) *markers; | |
4084 | struct cleanup *old_chain; | |
4085 | struct static_tracepoint_marker *marker; | |
79a45e25 | 4086 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
4087 | int i; |
4088 | ||
d1feda86 YQ |
4089 | /* We don't have to check target_can_use_agent and agent's capability on |
4090 | static tracepoint here, in order to be compatible with older GDBserver. | |
4091 | We don't check USE_AGENT is true or not, because static tracepoints | |
4092 | don't work without in-process agent, so we don't bother users to type | |
4093 | `set agent on' when to use static tracepoint. */ | |
4094 | ||
0fb4aa4b PA |
4095 | old_chain |
4096 | = make_cleanup_ui_out_table_begin_end (uiout, 5, -1, | |
4097 | "StaticTracepointMarkersTable"); | |
4098 | ||
4099 | ui_out_table_header (uiout, 7, ui_left, "counter", "Cnt"); | |
4100 | ||
4101 | ui_out_table_header (uiout, 40, ui_left, "marker-id", "ID"); | |
4102 | ||
4103 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); | |
f5656ead | 4104 | if (gdbarch_addr_bit (target_gdbarch ()) <= 32) |
0fb4aa4b PA |
4105 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address"); |
4106 | else | |
4107 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address"); | |
4108 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); | |
4109 | ||
4110 | ui_out_table_body (uiout); | |
4111 | ||
4112 | markers = target_static_tracepoint_markers_by_strid (NULL); | |
4113 | make_cleanup (VEC_cleanup (static_tracepoint_marker_p), &markers); | |
4114 | ||
4115 | for (i = 0; | |
4116 | VEC_iterate (static_tracepoint_marker_p, | |
4117 | markers, i, marker); | |
4118 | i++) | |
4119 | { | |
4120 | print_one_static_tracepoint_marker (i + 1, marker); | |
4121 | release_static_tracepoint_marker (marker); | |
4122 | } | |
4123 | ||
4124 | do_cleanups (old_chain); | |
4125 | } | |
4126 | ||
4127 | /* The $_sdata convenience variable is a bit special. We don't know | |
4128 | for sure type of the value until we actually have a chance to fetch | |
4129 | the data --- the size of the object depends on what has been | |
4130 | collected. We solve this by making $_sdata be an internalvar that | |
4131 | creates a new value on access. */ | |
4132 | ||
4133 | /* Return a new value with the correct type for the sdata object of | |
4134 | the current trace frame. Return a void value if there's no object | |
4135 | available. */ | |
4136 | ||
4137 | static struct value * | |
22d2b532 SDJ |
4138 | sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var, |
4139 | void *ignore) | |
0fb4aa4b PA |
4140 | { |
4141 | LONGEST size; | |
4142 | gdb_byte *buf; | |
4143 | ||
4144 | /* We need to read the whole object before we know its size. */ | |
4145 | size = target_read_alloc (¤t_target, | |
4146 | TARGET_OBJECT_STATIC_TRACE_DATA, | |
4147 | NULL, &buf); | |
4148 | if (size >= 0) | |
4149 | { | |
4150 | struct value *v; | |
4151 | struct type *type; | |
4152 | ||
4153 | type = init_vector_type (builtin_type (gdbarch)->builtin_true_char, | |
4154 | size); | |
4155 | v = allocate_value (type); | |
4156 | memcpy (value_contents_raw (v), buf, size); | |
4157 | xfree (buf); | |
4158 | return v; | |
4159 | } | |
4160 | else | |
4161 | return allocate_value (builtin_type (gdbarch)->builtin_void); | |
4162 | } | |
4163 | ||
b3b9301e PA |
4164 | #if !defined(HAVE_LIBEXPAT) |
4165 | ||
4166 | struct traceframe_info * | |
4167 | parse_traceframe_info (const char *tframe_info) | |
4168 | { | |
4169 | static int have_warned; | |
4170 | ||
4171 | if (!have_warned) | |
4172 | { | |
4173 | have_warned = 1; | |
4174 | warning (_("Can not parse XML trace frame info; XML support " | |
4175 | "was disabled at compile time")); | |
4176 | } | |
4177 | ||
4178 | return NULL; | |
4179 | } | |
4180 | ||
4181 | #else /* HAVE_LIBEXPAT */ | |
4182 | ||
4183 | #include "xml-support.h" | |
4184 | ||
4185 | /* Handle the start of a <memory> element. */ | |
4186 | ||
4187 | static void | |
4188 | traceframe_info_start_memory (struct gdb_xml_parser *parser, | |
4189 | const struct gdb_xml_element *element, | |
4190 | void *user_data, VEC(gdb_xml_value_s) *attributes) | |
4191 | { | |
19ba03f4 | 4192 | struct traceframe_info *info = (struct traceframe_info *) user_data; |
b3b9301e PA |
4193 | struct mem_range *r = VEC_safe_push (mem_range_s, info->memory, NULL); |
4194 | ULONGEST *start_p, *length_p; | |
4195 | ||
19ba03f4 | 4196 | start_p |
bc84451b | 4197 | = (ULONGEST *) xml_find_attribute (attributes, "start")->value; |
19ba03f4 | 4198 | length_p |
bc84451b | 4199 | = (ULONGEST *) xml_find_attribute (attributes, "length")->value; |
b3b9301e PA |
4200 | |
4201 | r->start = *start_p; | |
4202 | r->length = *length_p; | |
4203 | } | |
4204 | ||
28a93511 YQ |
4205 | /* Handle the start of a <tvar> element. */ |
4206 | ||
4207 | static void | |
4208 | traceframe_info_start_tvar (struct gdb_xml_parser *parser, | |
4209 | const struct gdb_xml_element *element, | |
4210 | void *user_data, | |
4211 | VEC(gdb_xml_value_s) *attributes) | |
4212 | { | |
19ba03f4 SM |
4213 | struct traceframe_info *info = (struct traceframe_info *) user_data; |
4214 | const char *id_attrib | |
4215 | = (const char *) xml_find_attribute (attributes, "id")->value; | |
28a93511 YQ |
4216 | int id = gdb_xml_parse_ulongest (parser, id_attrib); |
4217 | ||
4218 | VEC_safe_push (int, info->tvars, id); | |
4219 | } | |
4220 | ||
b3b9301e PA |
4221 | /* Discard the constructed trace frame info (if an error occurs). */ |
4222 | ||
4223 | static void | |
4224 | free_result (void *p) | |
4225 | { | |
19ba03f4 | 4226 | struct traceframe_info *result = (struct traceframe_info *) p; |
b3b9301e PA |
4227 | |
4228 | free_traceframe_info (result); | |
4229 | } | |
4230 | ||
4231 | /* The allowed elements and attributes for an XML memory map. */ | |
4232 | ||
4233 | static const struct gdb_xml_attribute memory_attributes[] = { | |
4234 | { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, | |
4235 | { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, | |
4236 | { NULL, GDB_XML_AF_NONE, NULL, NULL } | |
4237 | }; | |
4238 | ||
28a93511 YQ |
4239 | static const struct gdb_xml_attribute tvar_attributes[] = { |
4240 | { "id", GDB_XML_AF_NONE, NULL, NULL }, | |
4241 | { NULL, GDB_XML_AF_NONE, NULL, NULL } | |
4242 | }; | |
4243 | ||
b3b9301e PA |
4244 | static const struct gdb_xml_element traceframe_info_children[] = { |
4245 | { "memory", memory_attributes, NULL, | |
4246 | GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, | |
4247 | traceframe_info_start_memory, NULL }, | |
28a93511 YQ |
4248 | { "tvar", tvar_attributes, NULL, |
4249 | GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, | |
4250 | traceframe_info_start_tvar, NULL }, | |
b3b9301e PA |
4251 | { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } |
4252 | }; | |
4253 | ||
4254 | static const struct gdb_xml_element traceframe_info_elements[] = { | |
4255 | { "traceframe-info", NULL, traceframe_info_children, GDB_XML_EF_NONE, | |
4256 | NULL, NULL }, | |
4257 | { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } | |
4258 | }; | |
4259 | ||
4260 | /* Parse a traceframe-info XML document. */ | |
4261 | ||
4262 | struct traceframe_info * | |
4263 | parse_traceframe_info (const char *tframe_info) | |
4264 | { | |
4265 | struct traceframe_info *result; | |
4266 | struct cleanup *back_to; | |
4267 | ||
4268 | result = XCNEW (struct traceframe_info); | |
4269 | back_to = make_cleanup (free_result, result); | |
4270 | ||
4271 | if (gdb_xml_parse_quick (_("trace frame info"), | |
4272 | "traceframe-info.dtd", traceframe_info_elements, | |
4273 | tframe_info, result) == 0) | |
4274 | { | |
4275 | /* Parsed successfully, keep the result. */ | |
4276 | discard_cleanups (back_to); | |
4277 | ||
4278 | return result; | |
4279 | } | |
4280 | ||
4281 | do_cleanups (back_to); | |
4282 | return NULL; | |
4283 | } | |
4284 | ||
4285 | #endif /* HAVE_LIBEXPAT */ | |
4286 | ||
4287 | /* Returns the traceframe_info object for the current traceframe. | |
4288 | This is where we avoid re-fetching the object from the target if we | |
4289 | already have it cached. */ | |
4290 | ||
dc673c81 | 4291 | struct traceframe_info * |
b3b9301e PA |
4292 | get_traceframe_info (void) |
4293 | { | |
4294 | if (traceframe_info == NULL) | |
4295 | traceframe_info = target_traceframe_info (); | |
4296 | ||
4297 | return traceframe_info; | |
4298 | } | |
4299 | ||
c0f61f9c PA |
4300 | /* If the target supports the query, return in RESULT the set of |
4301 | collected memory in the current traceframe, found within the LEN | |
4302 | bytes range starting at MEMADDR. Returns true if the target | |
4303 | supports the query, otherwise returns false, and RESULT is left | |
4304 | undefined. */ | |
2a7498d8 PA |
4305 | |
4306 | int | |
4307 | traceframe_available_memory (VEC(mem_range_s) **result, | |
4308 | CORE_ADDR memaddr, ULONGEST len) | |
4309 | { | |
4310 | struct traceframe_info *info = get_traceframe_info (); | |
4311 | ||
4312 | if (info != NULL) | |
4313 | { | |
4314 | struct mem_range *r; | |
4315 | int i; | |
4316 | ||
4317 | *result = NULL; | |
4318 | ||
4319 | for (i = 0; VEC_iterate (mem_range_s, info->memory, i, r); i++) | |
4320 | if (mem_ranges_overlap (r->start, r->length, memaddr, len)) | |
4321 | { | |
4322 | ULONGEST lo1, hi1, lo2, hi2; | |
4323 | struct mem_range *nr; | |
4324 | ||
4325 | lo1 = memaddr; | |
4326 | hi1 = memaddr + len; | |
4327 | ||
4328 | lo2 = r->start; | |
4329 | hi2 = r->start + r->length; | |
4330 | ||
4331 | nr = VEC_safe_push (mem_range_s, *result, NULL); | |
4332 | ||
4333 | nr->start = max (lo1, lo2); | |
4334 | nr->length = min (hi1, hi2) - nr->start; | |
4335 | } | |
4336 | ||
4337 | normalize_mem_ranges (*result); | |
4338 | return 1; | |
4339 | } | |
4340 | ||
4341 | return 0; | |
4342 | } | |
4343 | ||
22d2b532 SDJ |
4344 | /* Implementation of `sdata' variable. */ |
4345 | ||
4346 | static const struct internalvar_funcs sdata_funcs = | |
4347 | { | |
4348 | sdata_make_value, | |
4349 | NULL, | |
4350 | NULL | |
4351 | }; | |
4352 | ||
c906108c SS |
4353 | /* module initialization */ |
4354 | void | |
fba45db2 | 4355 | _initialize_tracepoint (void) |
c906108c | 4356 | { |
fa58ee11 EZ |
4357 | struct cmd_list_element *c; |
4358 | ||
0fb4aa4b PA |
4359 | /* Explicitly create without lookup, since that tries to create a |
4360 | value with a void typed value, and when we get here, gdbarch | |
4361 | isn't initialized yet. At this point, we're quite sure there | |
4362 | isn't another convenience variable of the same name. */ | |
22d2b532 | 4363 | create_internalvar_type_lazy ("_sdata", &sdata_funcs, NULL); |
0fb4aa4b | 4364 | |
c906108c SS |
4365 | traceframe_number = -1; |
4366 | tracepoint_number = -1; | |
4367 | ||
c5aa993b | 4368 | add_info ("scope", scope_info, |
1bedd215 | 4369 | _("List the variables local to a scope")); |
c906108c | 4370 | |
e00d1dc8 | 4371 | add_cmd ("tracepoints", class_trace, NULL, |
1a966eab | 4372 | _("Tracing of program execution without stopping the program."), |
c906108c SS |
4373 | &cmdlist); |
4374 | ||
c5aa993b | 4375 | add_com ("tdump", class_trace, trace_dump_command, |
1bedd215 | 4376 | _("Print everything collected at the current tracepoint.")); |
c906108c | 4377 | |
f61e138d SS |
4378 | c = add_com ("tvariable", class_trace, trace_variable_command,_("\ |
4379 | Define a trace state variable.\n\ | |
4380 | Argument is a $-prefixed name, optionally followed\n\ | |
4381 | by '=' and an expression that sets the initial value\n\ | |
4382 | at the start of tracing.")); | |
4383 | set_cmd_completer (c, expression_completer); | |
4384 | ||
4385 | add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\ | |
4386 | Delete one or more trace state variables.\n\ | |
4387 | Arguments are the names of the variables to delete.\n\ | |
4388 | If no arguments are supplied, delete all variables."), &deletelist); | |
c378eb4e | 4389 | /* FIXME add a trace variable completer. */ |
f61e138d SS |
4390 | |
4391 | add_info ("tvariables", tvariables_info, _("\ | |
4392 | Status of trace state variables and their values.\n\ | |
0fb4aa4b PA |
4393 | ")); |
4394 | ||
4395 | add_info ("static-tracepoint-markers", | |
4396 | info_static_tracepoint_markers_command, _("\ | |
4397 | List target static tracepoints markers.\n\ | |
f61e138d SS |
4398 | ")); |
4399 | ||
1bedd215 AC |
4400 | add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\ |
4401 | Select a trace frame;\n\ | |
4402 | No argument means forward by one frame; '-' means backward by one frame."), | |
c906108c SS |
4403 | &tfindlist, "tfind ", 1, &cmdlist); |
4404 | ||
1a966eab | 4405 | add_cmd ("outside", class_trace, trace_find_outside_command, _("\ |
081dfbf7 | 4406 | Select a trace frame whose PC is outside the given range (exclusive).\n\ |
1a966eab | 4407 | Usage: tfind outside addr1, addr2"), |
c906108c SS |
4408 | &tfindlist); |
4409 | ||
1a966eab | 4410 | add_cmd ("range", class_trace, trace_find_range_command, _("\ |
081dfbf7 | 4411 | Select a trace frame whose PC is in the given range (inclusive).\n\ |
1a966eab | 4412 | Usage: tfind range addr1,addr2"), |
c906108c SS |
4413 | &tfindlist); |
4414 | ||
1a966eab AC |
4415 | add_cmd ("line", class_trace, trace_find_line_command, _("\ |
4416 | Select a trace frame by source line.\n\ | |
cce7e648 | 4417 | Argument can be a line number (with optional source file),\n\ |
c906108c | 4418 | a function name, or '*' followed by an address.\n\ |
1a966eab | 4419 | Default argument is 'the next source line that was traced'."), |
c906108c SS |
4420 | &tfindlist); |
4421 | ||
1a966eab AC |
4422 | add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, _("\ |
4423 | Select a trace frame by tracepoint number.\n\ | |
4424 | Default is the tracepoint for the current trace frame."), | |
c906108c SS |
4425 | &tfindlist); |
4426 | ||
1a966eab AC |
4427 | add_cmd ("pc", class_trace, trace_find_pc_command, _("\ |
4428 | Select a trace frame by PC.\n\ | |
4429 | Default is the current PC, or the PC of the current trace frame."), | |
c906108c SS |
4430 | &tfindlist); |
4431 | ||
1a966eab | 4432 | add_cmd ("end", class_trace, trace_find_end_command, _("\ |
1a966eab | 4433 | De-select any trace frame and resume 'live' debugging."), |
c906108c SS |
4434 | &tfindlist); |
4435 | ||
8acc4065 | 4436 | add_alias_cmd ("none", "end", class_trace, 0, &tfindlist); |
c906108c SS |
4437 | |
4438 | add_cmd ("start", class_trace, trace_find_start_command, | |
1a966eab | 4439 | _("Select the first trace frame in the trace buffer."), |
c906108c SS |
4440 | &tfindlist); |
4441 | ||
c5aa993b | 4442 | add_com ("tstatus", class_trace, trace_status_command, |
1bedd215 | 4443 | _("Display the status of the current trace data collection.")); |
c906108c | 4444 | |
f196051f SS |
4445 | add_com ("tstop", class_trace, trace_stop_command, _("\ |
4446 | Stop trace data collection.\n\ | |
4447 | Usage: tstop [ <notes> ... ]\n\ | |
4448 | Any arguments supplied are recorded with the trace as a stop reason and\n\ | |
4449 | reported by tstatus (if the target supports trace notes).")); | |
c906108c | 4450 | |
f196051f SS |
4451 | add_com ("tstart", class_trace, trace_start_command, _("\ |
4452 | Start trace data collection.\n\ | |
4453 | Usage: tstart [ <notes> ... ]\n\ | |
4454 | Any arguments supplied are recorded with the trace as a note and\n\ | |
4455 | reported by tstatus (if the target supports trace notes).")); | |
c906108c | 4456 | |
1bedd215 AC |
4457 | add_com ("end", class_trace, end_actions_pseudocommand, _("\ |
4458 | Ends a list of commands or actions.\n\ | |
c906108c SS |
4459 | Several GDB commands allow you to enter a list of commands or actions.\n\ |
4460 | Entering \"end\" on a line by itself is the normal way to terminate\n\ | |
4461 | such a list.\n\n\ | |
1bedd215 | 4462 | Note: the \"end\" command cannot be used at the gdb prompt.")); |
c906108c | 4463 | |
1bedd215 AC |
4464 | add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\ |
4465 | Specify single-stepping behavior at a tracepoint.\n\ | |
c906108c SS |
4466 | Argument is number of instructions to trace in single-step mode\n\ |
4467 | following the tracepoint. This command is normally followed by\n\ | |
4468 | one or more \"collect\" commands, to specify what to collect\n\ | |
4469 | while single-stepping.\n\n\ | |
1bedd215 | 4470 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
c906108c | 4471 | |
c5aa993b JM |
4472 | add_com_alias ("ws", "while-stepping", class_alias, 0); |
4473 | add_com_alias ("stepping", "while-stepping", class_alias, 0); | |
c906108c | 4474 | |
1bedd215 AC |
4475 | add_com ("collect", class_trace, collect_pseudocommand, _("\ |
4476 | Specify one or more data items to be collected at a tracepoint.\n\ | |
c906108c SS |
4477 | Accepts a comma-separated list of (one or more) expressions. GDB will\n\ |
4478 | collect all data (variables, registers) referenced by that expression.\n\ | |
4479 | Also accepts the following special arguments:\n\ | |
4480 | $regs -- all registers.\n\ | |
4481 | $args -- all function arguments.\n\ | |
4482 | $locals -- all variables local to the block/function scope.\n\ | |
0fb4aa4b | 4483 | $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\ |
1bedd215 | 4484 | Note: this command can only be used in a tracepoint \"actions\" list.")); |
c906108c | 4485 | |
6da95a67 SS |
4486 | add_com ("teval", class_trace, teval_pseudocommand, _("\ |
4487 | Specify one or more expressions to be evaluated at a tracepoint.\n\ | |
4488 | Accepts a comma-separated list of (one or more) expressions.\n\ | |
4489 | The result of each evaluation will be discarded.\n\ | |
4490 | Note: this command can only be used in a tracepoint \"actions\" list.")); | |
4491 | ||
1bedd215 AC |
4492 | add_com ("actions", class_trace, trace_actions_command, _("\ |
4493 | Specify the actions to be taken at a tracepoint.\n\ | |
cce7e648 PA |
4494 | Tracepoint actions may include collecting of specified data,\n\ |
4495 | single-stepping, or enabling/disabling other tracepoints,\n\ | |
1bedd215 | 4496 | depending on target's capabilities.")); |
c906108c | 4497 | |
236f1d4d SS |
4498 | default_collect = xstrdup (""); |
4499 | add_setshow_string_cmd ("default-collect", class_trace, | |
4500 | &default_collect, _("\ | |
4501 | Set the list of expressions to collect by default"), _("\ | |
4502 | Show the list of expressions to collect by default"), NULL, | |
4503 | NULL, NULL, | |
4504 | &setlist, &showlist); | |
4505 | ||
d5551862 SS |
4506 | add_setshow_boolean_cmd ("disconnected-tracing", no_class, |
4507 | &disconnected_tracing, _("\ | |
4508 | Set whether tracing continues after GDB disconnects."), _("\ | |
4509 | Show whether tracing continues after GDB disconnects."), _("\ | |
4510 | Use this to continue a tracing run even if GDB disconnects\n\ | |
4511 | or detaches from the target. You can reconnect later and look at\n\ | |
4512 | trace data collected in the meantime."), | |
4513 | set_disconnected_tracing, | |
4514 | NULL, | |
4515 | &setlist, | |
4516 | &showlist); | |
00bf0b85 | 4517 | |
4daf5ac0 SS |
4518 | add_setshow_boolean_cmd ("circular-trace-buffer", no_class, |
4519 | &circular_trace_buffer, _("\ | |
4520 | Set target's use of circular trace buffer."), _("\ | |
4521 | Show target's use of circular trace buffer."), _("\ | |
4522 | Use this to make the trace buffer into a circular buffer,\n\ | |
4523 | which will discard traceframes (oldest first) instead of filling\n\ | |
4524 | up and stopping the trace run."), | |
4525 | set_circular_trace_buffer, | |
4526 | NULL, | |
4527 | &setlist, | |
4528 | &showlist); | |
4529 | ||
f6f899bf | 4530 | add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class, |
9b67fcec | 4531 | &trace_buffer_size, _("\ |
f6f899bf HAQ |
4532 | Set requested size of trace buffer."), _("\ |
4533 | Show requested size of trace buffer."), _("\ | |
4534 | Use this to choose a size for the trace buffer. Some targets\n\ | |
f81d1120 PA |
4535 | may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\ |
4536 | disables any attempt to set the buffer size and lets the target choose."), | |
9b67fcec YQ |
4537 | set_trace_buffer_size, NULL, |
4538 | &setlist, &showlist); | |
f6f899bf | 4539 | |
f196051f SS |
4540 | add_setshow_string_cmd ("trace-user", class_trace, |
4541 | &trace_user, _("\ | |
4542 | Set the user name to use for current and future trace runs"), _("\ | |
4543 | Show the user name to use for current and future trace runs"), NULL, | |
4544 | set_trace_user, NULL, | |
4545 | &setlist, &showlist); | |
4546 | ||
4547 | add_setshow_string_cmd ("trace-notes", class_trace, | |
4548 | &trace_notes, _("\ | |
4549 | Set notes string to use for current and future trace runs"), _("\ | |
4550 | Show the notes string to use for current and future trace runs"), NULL, | |
4551 | set_trace_notes, NULL, | |
4552 | &setlist, &showlist); | |
4553 | ||
4554 | add_setshow_string_cmd ("trace-stop-notes", class_trace, | |
4555 | &trace_stop_notes, _("\ | |
4556 | Set notes string to use for future tstop commands"), _("\ | |
4557 | Show the notes string to use for future tstop commands"), NULL, | |
4558 | set_trace_stop_notes, NULL, | |
4559 | &setlist, &showlist); | |
c906108c | 4560 | } |