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