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