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