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