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