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