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