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