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