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