1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "arch-utils.h"
25 #include "expression.h"
29 #include "target-dcache.h"
32 #include "breakpoint.h"
33 #include "tracepoint.h"
36 #include "completer.h"
38 #include "dictionary.h"
40 #include "user-regs.h"
44 #include "filenames.h"
45 #include "gdbthread.h"
52 #include "cli/cli-utils.h"
55 #include "filestuff.h"
57 #include "tracefile.h"
61 /* readline include files */
62 #include "readline/readline.h"
63 #include "readline/history.h"
65 /* readline defines this. */
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
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
80 /* A hook used to notify the UI of tracepoint operations. */
82 void (*deprecated_trace_find_hook) (char *arg, int from_tty);
83 void (*deprecated_trace_start_stop_hook) (int start, int from_tty);
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.
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.
111 /* ======= Important global variables: ======= */
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. */
117 typedef struct trace_state_variable tsv_s;
120 static VEC(tsv_s) *tvariables;
122 /* The next integer to assign to a variable. */
124 static int next_tsv_number = 1;
126 /* Number of last traceframe collected. */
127 static int traceframe_number;
129 /* Tracepoint for last traceframe collected. */
130 static int tracepoint_number;
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
136 static struct traceframe_info *traceframe_info;
138 /* Tracing command lists. */
139 static struct cmd_list_element *tfindlist;
141 /* List of expressions to collect by default at each tracepoint hit. */
142 char *default_collect = "";
144 static int disconnected_tracing;
146 /* This variable controls whether we ask the target for a linear or
147 circular trace buffer. */
149 static int circular_trace_buffer;
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. */
154 static int trace_buffer_size = -1;
156 /* Textual notes applying to the current and/or future trace runs. */
158 char *trace_user = NULL;
160 /* Textual notes applying to the current and/or future trace runs. */
162 char *trace_notes = NULL;
164 /* Textual notes applying to the stopping of a trace. */
166 char *trace_stop_notes = NULL;
168 /* ======= Important command functions: ======= */
169 static void actions_command (char *, int);
170 static void tstart_command (char *, int);
171 static void tstop_command (char *, int);
172 static void tstatus_command (char *, int);
173 static void tfind_command (char *, int);
174 static void tfind_pc_command (char *, int);
175 static void tfind_tracepoint_command (char *, int);
176 static void tfind_line_command (char *, int);
177 static void tfind_range_command (char *, int);
178 static void tfind_outside_command (char *, int);
179 static void tdump_command (char *, int);
181 /* support routines */
183 struct collection_list;
184 static char *mem2hex (gdb_byte *, char *, int);
186 static struct command_line *
187 all_tracepoint_actions_and_cleanup (struct breakpoint *t);
189 extern void _initialize_tracepoint (void);
191 static struct trace_status trace_status;
193 const char *stop_reason_names[] = {
203 struct trace_status *
204 current_trace_status (void)
206 return &trace_status;
212 free_traceframe_info (struct traceframe_info *info)
216 VEC_free (mem_range_s, info->memory);
217 VEC_free (int, info->tvars);
223 /* Free and clear the traceframe info cache of the current
227 clear_traceframe_info (void)
229 free_traceframe_info (traceframe_info);
230 traceframe_info = NULL;
233 /* Set traceframe number to NUM. */
235 set_traceframe_num (int num)
237 traceframe_number = num;
238 set_internalvar_integer (lookup_internalvar ("trace_frame"), num);
241 /* Set tracepoint number to NUM. */
243 set_tracepoint_num (int num)
245 tracepoint_number = num;
246 set_internalvar_integer (lookup_internalvar ("tracepoint"), num);
249 /* Set externally visible debug variables for querying/printing
250 the traceframe context (line, function, file). */
253 set_traceframe_context (struct frame_info *trace_frame)
256 struct symbol *traceframe_fun;
257 struct symtab_and_line traceframe_sal;
259 /* Save as globals for internal use. */
260 if (trace_frame != NULL
261 && get_frame_pc_if_available (trace_frame, &trace_pc))
263 traceframe_sal = find_pc_line (trace_pc, 0);
264 traceframe_fun = find_pc_function (trace_pc);
266 /* Save linenumber as "$trace_line", a debugger variable visible to
268 set_internalvar_integer (lookup_internalvar ("trace_line"),
269 traceframe_sal.line);
273 init_sal (&traceframe_sal);
274 traceframe_fun = NULL;
275 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
278 /* Save func name as "$trace_func", a debugger variable visible to
280 if (traceframe_fun == NULL
281 || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
282 clear_internalvar (lookup_internalvar ("trace_func"));
284 set_internalvar_string (lookup_internalvar ("trace_func"),
285 SYMBOL_LINKAGE_NAME (traceframe_fun));
287 /* Save file name as "$trace_file", a debugger variable visible to
289 if (traceframe_sal.symtab == NULL)
290 clear_internalvar (lookup_internalvar ("trace_file"));
292 set_internalvar_string (lookup_internalvar ("trace_file"),
293 symtab_to_filename_for_display (traceframe_sal.symtab));
296 /* Create a new trace state variable with the given name. */
298 struct trace_state_variable *
299 create_trace_state_variable (const char *name)
301 struct trace_state_variable tsv;
303 memset (&tsv, 0, sizeof (tsv));
304 tsv.name = xstrdup (name);
305 tsv.number = next_tsv_number++;
306 return VEC_safe_push (tsv_s, tvariables, &tsv);
309 /* Look for a trace state variable of the given name. */
311 struct trace_state_variable *
312 find_trace_state_variable (const char *name)
314 struct trace_state_variable *tsv;
317 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
318 if (strcmp (name, tsv->name) == 0)
324 /* Look for a trace state variable of the given number. Return NULL if
327 struct trace_state_variable *
328 find_trace_state_variable_by_number (int number)
330 struct trace_state_variable *tsv;
333 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
334 if (tsv->number == number)
341 delete_trace_state_variable (const char *name)
343 struct trace_state_variable *tsv;
346 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
347 if (strcmp (name, tsv->name) == 0)
349 observer_notify_tsv_deleted (tsv);
351 xfree ((void *)tsv->name);
352 VEC_unordered_remove (tsv_s, tvariables, ix);
357 warning (_("No trace variable named \"$%s\", not deleting"), name);
360 /* Throws an error if NAME is not valid syntax for a trace state
364 validate_trace_state_variable_name (const char *name)
369 error (_("Must supply a non-empty variable name"));
371 /* All digits in the name is reserved for value history
373 for (p = name; isdigit (*p); p++)
376 error (_("$%s is not a valid trace state variable name"), name);
378 for (p = name; isalnum (*p) || *p == '_'; p++)
381 error (_("$%s is not a valid trace state variable name"), name);
384 /* The 'tvariable' command collects a name and optional expression to
385 evaluate into an initial value. */
388 trace_variable_command (char *args, int from_tty)
390 struct cleanup *old_chain;
392 struct trace_state_variable *tsv;
396 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
398 /* Only allow two syntaxes; "$name" and "$name=value". */
399 p = skip_spaces (args);
402 error (_("Name of trace variable should start with '$'"));
405 while (isalnum (*p) || *p == '_')
407 name = savestring (name, p - name);
408 old_chain = make_cleanup (xfree, name);
411 if (*p != '=' && *p != '\0')
412 error (_("Syntax must be $NAME [ = EXPR ]"));
414 validate_trace_state_variable_name (name);
417 initval = value_as_long (parse_and_eval (++p));
419 /* If the variable already exists, just change its initial value. */
420 tsv = find_trace_state_variable (name);
423 if (tsv->initial_value != initval)
425 tsv->initial_value = initval;
426 observer_notify_tsv_modified (tsv);
428 printf_filtered (_("Trace state variable $%s "
429 "now has initial value %s.\n"),
430 tsv->name, plongest (tsv->initial_value));
431 do_cleanups (old_chain);
435 /* Create a new variable. */
436 tsv = create_trace_state_variable (name);
437 tsv->initial_value = initval;
439 observer_notify_tsv_created (tsv);
441 printf_filtered (_("Trace state variable $%s "
442 "created, with initial value %s.\n"),
443 tsv->name, plongest (tsv->initial_value));
445 do_cleanups (old_chain);
449 delete_trace_variable_command (char *args, int from_tty)
453 struct cleanup *back_to;
457 if (query (_("Delete all trace state variables? ")))
458 VEC_free (tsv_s, tvariables);
460 observer_notify_tsv_deleted (NULL);
464 argv = gdb_buildargv (args);
465 back_to = make_cleanup_freeargv (argv);
467 for (ix = 0; argv[ix] != NULL; ix++)
469 if (*argv[ix] == '$')
470 delete_trace_state_variable (argv[ix] + 1);
472 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv[ix]);
475 do_cleanups (back_to);
481 tvariables_info_1 (void)
483 struct trace_state_variable *tsv;
486 struct cleanup *back_to;
487 struct ui_out *uiout = current_uiout;
489 if (VEC_length (tsv_s, tvariables) == 0 && !ui_out_is_mi_like_p (uiout))
491 printf_filtered (_("No trace state variables.\n"));
495 /* Try to acquire values from the target. */
496 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix, ++count)
497 tsv->value_known = target_get_trace_state_variable_value (tsv->number,
500 back_to = make_cleanup_ui_out_table_begin_end (uiout, 3,
501 count, "trace-variables");
502 ui_out_table_header (uiout, 15, ui_left, "name", "Name");
503 ui_out_table_header (uiout, 11, ui_left, "initial", "Initial");
504 ui_out_table_header (uiout, 11, ui_left, "current", "Current");
506 ui_out_table_body (uiout);
508 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
510 struct cleanup *back_to2;
514 back_to2 = make_cleanup_ui_out_tuple_begin_end (uiout, "variable");
516 name = concat ("$", tsv->name, (char *) NULL);
517 make_cleanup (xfree, name);
518 ui_out_field_string (uiout, "name", name);
519 ui_out_field_string (uiout, "initial", plongest (tsv->initial_value));
521 if (tsv->value_known)
522 c = plongest (tsv->value);
523 else if (ui_out_is_mi_like_p (uiout))
524 /* For MI, we prefer not to use magic string constants, but rather
525 omit the field completely. The difference between unknown and
526 undefined does not seem important enough to represent. */
528 else if (current_trace_status ()->running || traceframe_number >= 0)
529 /* The value is/was defined, but we don't have it. */
532 /* It is not meaningful to ask about the value. */
535 ui_out_field_string (uiout, "current", c);
536 ui_out_text (uiout, "\n");
538 do_cleanups (back_to2);
541 do_cleanups (back_to);
544 /* List all the trace state variables. */
547 tvariables_info (char *args, int from_tty)
549 tvariables_info_1 ();
552 /* Stash definitions of tsvs into the given file. */
555 save_trace_state_variables (struct ui_file *fp)
557 struct trace_state_variable *tsv;
560 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
562 fprintf_unfiltered (fp, "tvariable $%s", tsv->name);
563 if (tsv->initial_value)
564 fprintf_unfiltered (fp, " = %s", plongest (tsv->initial_value));
565 fprintf_unfiltered (fp, "\n");
569 /* ACTIONS functions: */
571 /* The three functions:
572 collect_pseudocommand,
573 while_stepping_pseudocommand, and
574 end_actions_pseudocommand
575 are placeholders for "commands" that are actually ONLY to be used
576 within a tracepoint action list. If the actual function is ever called,
577 it means that somebody issued the "command" at the top level,
578 which is always an error. */
581 end_actions_pseudocommand (char *args, int from_tty)
583 error (_("This command cannot be used at the top level."));
587 while_stepping_pseudocommand (char *args, int from_tty)
589 error (_("This command can only be used in a tracepoint actions list."));
593 collect_pseudocommand (char *args, int from_tty)
595 error (_("This command can only be used in a tracepoint actions list."));
599 teval_pseudocommand (char *args, int from_tty)
601 error (_("This command can only be used in a tracepoint actions list."));
604 /* Parse any collection options, such as /s for strings. */
607 decode_agent_options (const char *exp, int *trace_string)
609 struct value_print_options opts;
616 /* Call this to borrow the print elements default for collection
618 get_user_print_options (&opts);
623 if (target_supports_string_tracing ())
625 /* Allow an optional decimal number giving an explicit maximum
626 string length, defaulting it to the "print elements" value;
627 so "collect/s80 mystr" gets at most 80 bytes of string. */
628 *trace_string = opts.print_max;
630 if (*exp >= '0' && *exp <= '9')
631 *trace_string = atoi (exp);
632 while (*exp >= '0' && *exp <= '9')
636 error (_("Target does not support \"/s\" option for string tracing."));
639 error (_("Undefined collection format \"%c\"."), *exp);
641 exp = skip_spaces_const (exp);
646 /* Enter a list of actions for a tracepoint. */
648 actions_command (char *args, int from_tty)
650 struct tracepoint *t;
651 struct command_line *l;
653 t = get_tracepoint_by_number (&args, NULL);
657 xstrprintf ("Enter actions for tracepoint %d, one per line.",
659 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
661 l = read_command_lines (tmpbuf, from_tty, 1,
662 check_tracepoint_command, t);
663 do_cleanups (cleanups);
664 breakpoint_set_commands (&t->base, l);
666 /* else just return */
669 /* Report the results of checking the agent expression, as errors or
673 report_agent_reqs_errors (struct agent_expr *aexpr)
675 /* All of the "flaws" are serious bytecode generation issues that
676 should never occur. */
677 if (aexpr->flaw != agent_flaw_none)
678 internal_error (__FILE__, __LINE__, _("expression is malformed"));
680 /* If analysis shows a stack underflow, GDB must have done something
681 badly wrong in its bytecode generation. */
682 if (aexpr->min_height < 0)
683 internal_error (__FILE__, __LINE__,
684 _("expression has min height < 0"));
686 /* Issue this error if the stack is predicted to get too deep. The
687 limit is rather arbitrary; a better scheme might be for the
688 target to report how much stack it will have available. The
689 depth roughly corresponds to parenthesization, so a limit of 20
690 amounts to 20 levels of expression nesting, which is actually
691 a pretty big hairy expression. */
692 if (aexpr->max_height > 20)
693 error (_("Expression is too complicated."));
696 /* worker function */
698 validate_actionline (const char *line, struct breakpoint *b)
700 struct cmd_list_element *c;
701 struct cleanup *old_chain = NULL;
704 struct bp_location *loc;
705 struct tracepoint *t = (struct tracepoint *) b;
707 /* If EOF is typed, *line is NULL. */
711 p = skip_spaces_const (line);
713 /* Symbol lookup etc. */
714 if (*p == '\0') /* empty line: just prompt for another line. */
717 if (*p == '#') /* comment line */
720 c = lookup_cmd (&p, cmdlist, "", -1, 1);
722 error (_("`%s' is not a tracepoint action, or is ambiguous."), p);
724 if (cmd_cfunc_eq (c, collect_pseudocommand))
726 int trace_string = 0;
729 p = decode_agent_options (p, &trace_string);
732 { /* Repeat over a comma-separated list. */
733 QUIT; /* Allow user to bail out with ^C. */
734 p = skip_spaces_const (p);
736 if (*p == '$') /* Look for special pseudo-symbols. */
738 if (0 == strncasecmp ("reg", p + 1, 3)
739 || 0 == strncasecmp ("arg", p + 1, 3)
740 || 0 == strncasecmp ("loc", p + 1, 3)
741 || 0 == strncasecmp ("_ret", p + 1, 4)
742 || 0 == strncasecmp ("_sdata", p + 1, 6))
747 /* else fall thru, treat p as an expression and parse it! */
750 for (loc = t->base.loc; loc; loc = loc->next)
753 expression_up exp = parse_exp_1 (&p, loc->address,
754 block_for_pc (loc->address), 1);
756 if (exp->elts[0].opcode == OP_VAR_VALUE)
758 if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
760 error (_("constant `%s' (value %s) "
761 "will not be collected."),
762 SYMBOL_PRINT_NAME (exp->elts[2].symbol),
763 plongest (SYMBOL_VALUE (exp->elts[2].symbol)));
765 else if (SYMBOL_CLASS (exp->elts[2].symbol)
766 == LOC_OPTIMIZED_OUT)
768 error (_("`%s' is optimized away "
769 "and cannot be collected."),
770 SYMBOL_PRINT_NAME (exp->elts[2].symbol));
774 /* We have something to collect, make sure that the expr to
775 bytecode translator can handle it and that it's not too
777 agent_expr_up aexpr = gen_trace_for_expr (loc->address,
781 if (aexpr->len > MAX_AGENT_EXPR_LEN)
782 error (_("Expression is too complicated."));
784 ax_reqs (aexpr.get ());
786 report_agent_reqs_errors (aexpr.get ());
789 while (p && *p++ == ',');
792 else if (cmd_cfunc_eq (c, teval_pseudocommand))
795 { /* Repeat over a comma-separated list. */
796 QUIT; /* Allow user to bail out with ^C. */
797 p = skip_spaces_const (p);
800 for (loc = t->base.loc; loc; loc = loc->next)
804 /* Only expressions are allowed for this action. */
805 expression_up exp = parse_exp_1 (&p, loc->address,
806 block_for_pc (loc->address), 1);
808 /* We have something to evaluate, make sure that the expr to
809 bytecode translator can handle it and that it's not too
811 agent_expr_up aexpr = gen_eval_for_expr (loc->address, exp.get ());
813 if (aexpr->len > MAX_AGENT_EXPR_LEN)
814 error (_("Expression is too complicated."));
816 ax_reqs (aexpr.get ());
817 report_agent_reqs_errors (aexpr.get ());
820 while (p && *p++ == ',');
823 else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
827 p = skip_spaces_const (p);
828 t->step_count = strtol (p, &endp, 0);
829 if (endp == p || t->step_count == 0)
830 error (_("while-stepping step count `%s' is malformed."), line);
834 else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
838 error (_("`%s' is not a supported tracepoint action."), line);
842 memrange_absolute = -1
845 /* MEMRANGE functions: */
847 /* Compare memranges for std::sort. */
850 memrange_comp (const memrange &a, const memrange &b)
852 if (a.type == b.type)
854 if (a.type == memrange_absolute)
855 return (bfd_vma) a.start < (bfd_vma) b.start;
857 return a.start < b.start;
860 return a.type < b.type;
863 /* Sort the memrange list using std::sort, and merge adjacent memranges. */
866 memrange_sortmerge (std::vector<memrange> &memranges)
868 if (!memranges.empty ())
872 std::sort (memranges.begin (), memranges.end (), memrange_comp);
874 for (a = 0, b = 1; b < memranges.size (); b++)
876 /* If memrange b overlaps or is adjacent to memrange a,
878 if (memranges[a].type == memranges[b].type
879 && memranges[b].start <= memranges[a].end)
881 if (memranges[b].end > memranges[a].end)
882 memranges[a].end = memranges[b].end;
883 continue; /* next b, same a */
887 memranges[a] = memranges[b];
889 memranges.resize (a + 1);
893 /* Add a register to a collection list. */
896 collection_list::add_register (unsigned int regno)
899 printf_filtered ("collect register %d\n", regno);
900 if (regno >= (8 * sizeof (m_regs_mask)))
901 error (_("Internal: register number %d too large for tracepoint"),
903 m_regs_mask[regno / 8] |= 1 << (regno % 8);
906 /* Add a memrange to a collection list. */
909 collection_list::add_memrange (struct gdbarch *gdbarch,
910 int type, bfd_signed_vma base,
914 printf_filtered ("(%d,%s,%ld)\n", type, paddress (gdbarch, base), len);
916 /* type: memrange_absolute == memory, other n == basereg */
917 /* base: addr if memory, offset if reg relative. */
918 /* len: we actually save end (base + len) for convenience */
919 m_memranges.emplace_back (type, base, base + len);
921 if (type != memrange_absolute) /* Better collect the base register! */
925 /* Add a symbol to a collection list. */
928 collection_list::collect_symbol (struct symbol *sym,
929 struct gdbarch *gdbarch,
930 long frame_regno, long frame_offset,
936 bfd_signed_vma offset;
937 int treat_as_expr = 0;
939 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
940 switch (SYMBOL_CLASS (sym))
943 printf_filtered ("%s: don't know symbol class %d\n",
944 SYMBOL_PRINT_NAME (sym),
948 printf_filtered ("constant %s (value %s) will not be collected.\n",
949 SYMBOL_PRINT_NAME (sym), plongest (SYMBOL_VALUE (sym)));
952 offset = SYMBOL_VALUE_ADDRESS (sym);
955 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
956 SYMBOL_PRINT_NAME (sym), len,
957 paddress (gdbarch, offset));
959 /* A struct may be a C++ class with static fields, go to general
960 expression handling. */
961 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
964 add_memrange (gdbarch, memrange_absolute, offset, len);
967 reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
969 printf_filtered ("LOC_REG[parm] %s: ",
970 SYMBOL_PRINT_NAME (sym));
972 /* Check for doubles stored in two registers. */
973 /* FIXME: how about larger types stored in 3 or more regs? */
974 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
975 len > register_size (gdbarch, reg))
976 add_register (reg + 1);
979 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
980 printf_filtered (" (will not collect %s)\n",
981 SYMBOL_PRINT_NAME (sym));
985 offset = frame_offset + SYMBOL_VALUE (sym);
988 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
989 " from frame ptr reg %d\n",
990 SYMBOL_PRINT_NAME (sym), len,
991 paddress (gdbarch, offset), reg);
993 add_memrange (gdbarch, reg, offset, len);
995 case LOC_REGPARM_ADDR:
996 reg = SYMBOL_VALUE (sym);
1000 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset %s"
1002 SYMBOL_PRINT_NAME (sym), len,
1003 paddress (gdbarch, offset), reg);
1005 add_memrange (gdbarch, reg, offset, len);
1009 offset = frame_offset + SYMBOL_VALUE (sym);
1012 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
1013 " from frame ptr reg %d\n",
1014 SYMBOL_PRINT_NAME (sym), len,
1015 paddress (gdbarch, offset), reg);
1017 add_memrange (gdbarch, reg, offset, len);
1020 case LOC_UNRESOLVED:
1024 case LOC_OPTIMIZED_OUT:
1025 printf_filtered ("%s has been optimized out of existence.\n",
1026 SYMBOL_PRINT_NAME (sym));
1034 /* Expressions are the most general case. */
1037 struct cleanup *old_chain1 = NULL;
1039 agent_expr_up aexpr = gen_trace_for_var (scope, gdbarch,
1042 /* It can happen that the symbol is recorded as a computed
1043 location, but it's been optimized away and doesn't actually
1044 have a location expression. */
1047 printf_filtered ("%s has been optimized out of existence.\n",
1048 SYMBOL_PRINT_NAME (sym));
1052 ax_reqs (aexpr.get ());
1054 report_agent_reqs_errors (aexpr.get ());
1056 /* Take care of the registers. */
1057 if (aexpr->reg_mask_len > 0)
1059 for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1061 QUIT; /* Allow user to bail out with ^C. */
1062 if (aexpr->reg_mask[ndx1] != 0)
1064 /* Assume chars have 8 bits. */
1065 for (int ndx2 = 0; ndx2 < 8; ndx2++)
1066 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1067 /* It's used -- record it. */
1068 add_register (ndx1 * 8 + ndx2);
1073 add_aexpr (std::move (aexpr));
1077 /* Data to be passed around in the calls to the locals and args
1080 struct add_local_symbols_data
1082 struct collection_list *collect;
1083 struct gdbarch *gdbarch;
1091 /* The callback for the locals and args iterators. */
1094 do_collect_symbol (const char *print_name,
1098 struct add_local_symbols_data *p = (struct add_local_symbols_data *) cb_data;
1100 p->collect->collect_symbol (sym, p->gdbarch, p->frame_regno,
1101 p->frame_offset, p->pc, p->trace_string);
1104 p->collect->add_wholly_collected (print_name);
1108 collection_list::add_wholly_collected (const char *print_name)
1110 m_wholly_collected.push_back (print_name);
1113 /* Add all locals (or args) symbols to collection list. */
1116 collection_list::add_local_symbols (struct gdbarch *gdbarch, CORE_ADDR pc,
1117 long frame_regno, long frame_offset, int type,
1120 const struct block *block;
1121 struct add_local_symbols_data cb_data;
1123 cb_data.collect = this;
1124 cb_data.gdbarch = gdbarch;
1126 cb_data.frame_regno = frame_regno;
1127 cb_data.frame_offset = frame_offset;
1129 cb_data.trace_string = trace_string;
1133 block = block_for_pc (pc);
1136 warning (_("Can't collect locals; "
1137 "no symbol table info available.\n"));
1141 iterate_over_block_local_vars (block, do_collect_symbol, &cb_data);
1142 if (cb_data.count == 0)
1143 warning (_("No locals found in scope."));
1147 pc = get_pc_function_start (pc);
1148 block = block_for_pc (pc);
1151 warning (_("Can't collect args; no symbol table info available."));
1155 iterate_over_block_arg_vars (block, do_collect_symbol, &cb_data);
1156 if (cb_data.count == 0)
1157 warning (_("No args found in scope."));
1162 collection_list::add_static_trace_data ()
1165 printf_filtered ("collect static trace data\n");
1166 m_strace_data = true;
1169 collection_list::collection_list ()
1171 m_strace_data (false)
1173 m_memranges.reserve (128);
1174 m_aexprs.reserve (128);
1177 /* Reduce a collection list to string form (for gdb protocol). */
1180 collection_list::stringify ()
1182 char temp_buf[2048];
1185 char *(*str_list)[];
1189 count = 1 + 1 + m_memranges.size () + m_aexprs.size () + 1;
1190 str_list = (char *(*)[]) xmalloc (count * sizeof (char *));
1195 printf_filtered ("\nCollecting static trace data\n");
1198 (*str_list)[ndx] = savestring (temp_buf, end - temp_buf);
1202 for (i = sizeof (m_regs_mask) - 1; i > 0; i--)
1203 if (m_regs_mask[i] != 0) /* Skip leading zeroes in regs_mask. */
1205 if (m_regs_mask[i] != 0) /* Prepare to send regs_mask to the stub. */
1208 printf_filtered ("\nCollecting registers (mask): 0x");
1213 QUIT; /* Allow user to bail out with ^C. */
1215 printf_filtered ("%02X", m_regs_mask[i]);
1216 sprintf (end, "%02X", m_regs_mask[i]);
1219 (*str_list)[ndx] = xstrdup (temp_buf);
1223 printf_filtered ("\n");
1224 if (!m_memranges.empty () && info_verbose)
1225 printf_filtered ("Collecting memranges: \n");
1226 for (i = 0, count = 0, end = temp_buf; i < m_memranges.size (); i++)
1228 QUIT; /* Allow user to bail out with ^C. */
1231 printf_filtered ("(%d, %s, %ld)\n",
1232 m_memranges[i].type,
1233 paddress (target_gdbarch (),
1234 m_memranges[i].start),
1235 (long) (m_memranges[i].end
1236 - m_memranges[i].start));
1238 if (count + 27 > MAX_AGENT_EXPR_LEN)
1240 (*str_list)[ndx] = savestring (temp_buf, count);
1247 bfd_signed_vma length
1248 = m_memranges[i].end - m_memranges[i].start;
1250 /* The "%X" conversion specifier expects an unsigned argument,
1251 so passing -1 (memrange_absolute) to it directly gives you
1252 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1254 if (m_memranges[i].type == memrange_absolute)
1255 sprintf (end, "M-1,%s,%lX", phex_nz (m_memranges[i].start, 0),
1258 sprintf (end, "M%X,%s,%lX", m_memranges[i].type,
1259 phex_nz (m_memranges[i].start, 0), (long) length);
1262 count += strlen (end);
1263 end = temp_buf + count;
1266 for (i = 0; i < m_aexprs.size (); i++)
1268 QUIT; /* Allow user to bail out with ^C. */
1269 if ((count + 10 + 2 * m_aexprs[i]->len) > MAX_AGENT_EXPR_LEN)
1271 (*str_list)[ndx] = savestring (temp_buf, count);
1276 sprintf (end, "X%08X,", m_aexprs[i]->len);
1277 end += 10; /* 'X' + 8 hex digits + ',' */
1280 end = mem2hex (m_aexprs[i]->buf, end, m_aexprs[i]->len);
1281 count += 2 * m_aexprs[i]->len;
1286 (*str_list)[ndx] = savestring (temp_buf, count);
1291 (*str_list)[ndx] = NULL;
1302 /* Add the printed expression EXP to *LIST. */
1305 collection_list::append_exp (struct expression *exp)
1307 struct ui_file *tmp_stream = mem_fileopen ();
1309 print_expression (exp, tmp_stream);
1311 m_computed.push_back (ui_file_as_string (tmp_stream));
1312 ui_file_delete (tmp_stream);
1316 collection_list::finish ()
1318 memrange_sortmerge (m_memranges);
1322 encode_actions_1 (struct command_line *action,
1323 struct bp_location *tloc,
1325 LONGEST frame_offset,
1326 struct collection_list *collect,
1327 struct collection_list *stepping_list)
1329 const char *action_exp;
1331 struct value *tempval;
1332 struct cmd_list_element *cmd;
1334 for (; action; action = action->next)
1336 QUIT; /* Allow user to bail out with ^C. */
1337 action_exp = action->line;
1338 action_exp = skip_spaces_const (action_exp);
1340 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
1342 error (_("Bad action list item: %s"), action_exp);
1344 if (cmd_cfunc_eq (cmd, collect_pseudocommand))
1346 int trace_string = 0;
1348 if (*action_exp == '/')
1349 action_exp = decode_agent_options (action_exp, &trace_string);
1352 { /* Repeat over a comma-separated list. */
1353 QUIT; /* Allow user to bail out with ^C. */
1354 action_exp = skip_spaces_const (action_exp);
1356 if (0 == strncasecmp ("$reg", action_exp, 4))
1358 for (i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++)
1359 collect->add_register (i);
1360 action_exp = strchr (action_exp, ','); /* more? */
1362 else if (0 == strncasecmp ("$arg", action_exp, 4))
1364 collect->add_local_symbols (target_gdbarch (),
1370 action_exp = strchr (action_exp, ','); /* more? */
1372 else if (0 == strncasecmp ("$loc", action_exp, 4))
1374 collect->add_local_symbols (target_gdbarch (),
1380 action_exp = strchr (action_exp, ','); /* more? */
1382 else if (0 == strncasecmp ("$_ret", action_exp, 5))
1385 = gen_trace_for_return_address (tloc->address,
1389 ax_reqs (aexpr.get ());
1390 report_agent_reqs_errors (aexpr.get ());
1392 /* take care of the registers */
1393 if (aexpr->reg_mask_len > 0)
1395 for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1397 QUIT; /* allow user to bail out with ^C */
1398 if (aexpr->reg_mask[ndx1] != 0)
1400 /* assume chars have 8 bits */
1401 for (int ndx2 = 0; ndx2 < 8; ndx2++)
1402 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1404 /* It's used -- record it. */
1405 collect->add_register (ndx1 * 8 + ndx2);
1411 collect->add_aexpr (std::move (aexpr));
1412 action_exp = strchr (action_exp, ','); /* more? */
1414 else if (0 == strncasecmp ("$_sdata", action_exp, 7))
1416 collect->add_static_trace_data ();
1417 action_exp = strchr (action_exp, ','); /* more? */
1422 struct cleanup *old_chain1 = NULL;
1424 expression_up exp = parse_exp_1 (&action_exp, tloc->address,
1425 block_for_pc (tloc->address),
1428 switch (exp->elts[0].opcode)
1432 const char *name = &exp->elts[2].string;
1434 i = user_reg_map_name_to_regnum (target_gdbarch (),
1435 name, strlen (name));
1437 internal_error (__FILE__, __LINE__,
1438 _("Register $%s not available"),
1441 printf_filtered ("OP_REGISTER: ");
1442 collect->add_register (i);
1447 /* Safe because we know it's a simple expression. */
1448 tempval = evaluate_expression (exp.get ());
1449 addr = value_address (tempval);
1450 /* Initialize the TYPE_LENGTH if it is a typedef. */
1451 check_typedef (exp->elts[1].type);
1452 collect->add_memrange (target_gdbarch (),
1453 memrange_absolute, addr,
1454 TYPE_LENGTH (exp->elts[1].type));
1455 collect->append_exp (exp.get ());
1460 struct symbol *sym = exp->elts[2].symbol;
1461 char_ptr name = (char_ptr) SYMBOL_NATURAL_NAME (sym);
1463 collect->collect_symbol (exp->elts[2].symbol,
1469 collect->add_wholly_collected (name);
1473 default: /* Full-fledged expression. */
1474 agent_expr_up aexpr = gen_trace_for_expr (tloc->address,
1478 ax_reqs (aexpr.get ());
1480 report_agent_reqs_errors (aexpr.get ());
1482 /* Take care of the registers. */
1483 if (aexpr->reg_mask_len > 0)
1485 for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1487 QUIT; /* Allow user to bail out with ^C. */
1488 if (aexpr->reg_mask[ndx1] != 0)
1490 /* Assume chars have 8 bits. */
1491 for (int ndx2 = 0; ndx2 < 8; ndx2++)
1492 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1494 /* It's used -- record it. */
1495 collect->add_register (ndx1 * 8 + ndx2);
1501 collect->add_aexpr (std::move (aexpr));
1502 collect->append_exp (exp.get ());
1507 while (action_exp && *action_exp++ == ',');
1509 else if (cmd_cfunc_eq (cmd, teval_pseudocommand))
1512 { /* Repeat over a comma-separated list. */
1513 QUIT; /* Allow user to bail out with ^C. */
1514 action_exp = skip_spaces_const (action_exp);
1517 struct cleanup *old_chain1 = NULL;
1519 expression_up exp = parse_exp_1 (&action_exp, tloc->address,
1520 block_for_pc (tloc->address),
1523 agent_expr_up aexpr = gen_eval_for_expr (tloc->address,
1526 ax_reqs (aexpr.get ());
1527 report_agent_reqs_errors (aexpr.get ());
1529 /* Even though we're not officially collecting, add
1530 to the collect list anyway. */
1531 collect->add_aexpr (std::move (aexpr));
1534 while (action_exp && *action_exp++ == ',');
1536 else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
1538 /* We check against nested while-stepping when setting
1539 breakpoint action, so no way to run into nested
1541 gdb_assert (stepping_list);
1543 encode_actions_1 (action->body_list[0], tloc, frame_reg,
1544 frame_offset, stepping_list, NULL);
1547 error (_("Invalid tracepoint command '%s'"), action->line);
1551 /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST
1552 and STEPPING_LIST. */
1555 encode_actions (struct bp_location *tloc,
1556 struct collection_list *tracepoint_list,
1557 struct collection_list *stepping_list)
1559 struct command_line *actions;
1561 LONGEST frame_offset;
1563 gdbarch_virtual_frame_pointer (tloc->gdbarch,
1564 tloc->address, &frame_reg, &frame_offset);
1566 actions = all_tracepoint_actions_and_cleanup (tloc->owner);
1568 encode_actions_1 (actions, tloc, frame_reg, frame_offset,
1569 tracepoint_list, stepping_list);
1571 tracepoint_list->finish ();
1572 stepping_list->finish ();
1575 /* Render all actions into gdb protocol. */
1578 encode_actions_rsp (struct bp_location *tloc, char ***tdp_actions,
1579 char ***stepping_actions)
1581 struct collection_list tracepoint_list, stepping_list;
1583 *tdp_actions = NULL;
1584 *stepping_actions = NULL;
1586 encode_actions (tloc, &tracepoint_list, &stepping_list);
1588 *tdp_actions = tracepoint_list.stringify ();
1589 *stepping_actions = stepping_list.stringify ();
1593 collection_list::add_aexpr (agent_expr_up aexpr)
1595 m_aexprs.push_back (std::move (aexpr));
1599 process_tracepoint_on_disconnect (void)
1601 VEC(breakpoint_p) *tp_vec = NULL;
1603 struct breakpoint *b;
1604 int has_pending_p = 0;
1606 /* Check whether we still have pending tracepoint. If we have, warn the
1607 user that pending tracepoint will no longer work. */
1608 tp_vec = all_tracepoints ();
1609 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1618 struct bp_location *loc1;
1620 for (loc1 = b->loc; loc1; loc1 = loc1->next)
1622 if (loc1->shlib_disabled)
1633 VEC_free (breakpoint_p, tp_vec);
1636 warning (_("Pending tracepoints will not be resolved while"
1637 " GDB is disconnected\n"));
1640 /* Reset local state of tracing. */
1643 trace_reset_local_state (void)
1645 set_traceframe_num (-1);
1646 set_tracepoint_num (-1);
1647 set_traceframe_context (NULL);
1648 clear_traceframe_info ();
1652 start_tracing (char *notes)
1654 VEC(breakpoint_p) *tp_vec = NULL;
1656 struct breakpoint *b;
1657 struct trace_state_variable *tsv;
1658 int any_enabled = 0, num_to_download = 0;
1661 tp_vec = all_tracepoints ();
1663 /* No point in tracing without any tracepoints... */
1664 if (VEC_length (breakpoint_p, tp_vec) == 0)
1666 VEC_free (breakpoint_p, tp_vec);
1667 error (_("No tracepoints defined, not starting trace"));
1670 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1672 if (b->enable_state == bp_enabled)
1675 if ((b->type == bp_fast_tracepoint
1676 ? may_insert_fast_tracepoints
1677 : may_insert_tracepoints))
1680 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1681 (b->type == bp_fast_tracepoint ? "fast " : ""), b->number);
1686 if (target_supports_enable_disable_tracepoint ())
1687 warning (_("No tracepoints enabled"));
1690 /* No point in tracing with only disabled tracepoints that
1691 cannot be re-enabled. */
1692 VEC_free (breakpoint_p, tp_vec);
1693 error (_("No tracepoints enabled, not starting trace"));
1697 if (num_to_download <= 0)
1699 VEC_free (breakpoint_p, tp_vec);
1700 error (_("No tracepoints that may be downloaded, not starting trace"));
1703 target_trace_init ();
1705 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1707 struct tracepoint *t = (struct tracepoint *) b;
1708 struct bp_location *loc;
1709 int bp_location_downloaded = 0;
1711 /* Clear `inserted' flag. */
1712 for (loc = b->loc; loc; loc = loc->next)
1715 if ((b->type == bp_fast_tracepoint
1716 ? !may_insert_fast_tracepoints
1717 : !may_insert_tracepoints))
1720 t->number_on_target = 0;
1722 for (loc = b->loc; loc; loc = loc->next)
1724 /* Since tracepoint locations are never duplicated, `inserted'
1725 flag should be zero. */
1726 gdb_assert (!loc->inserted);
1728 target_download_tracepoint (loc);
1731 bp_location_downloaded = 1;
1734 t->number_on_target = b->number;
1736 for (loc = b->loc; loc; loc = loc->next)
1737 if (loc->probe.probe != NULL
1738 && loc->probe.probe->pops->set_semaphore != NULL)
1739 loc->probe.probe->pops->set_semaphore (loc->probe.probe,
1743 if (bp_location_downloaded)
1744 observer_notify_breakpoint_modified (b);
1746 VEC_free (breakpoint_p, tp_vec);
1748 /* Send down all the trace state variables too. */
1749 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
1751 target_download_trace_state_variable (tsv);
1754 /* Tell target to treat text-like sections as transparent. */
1755 target_trace_set_readonly_regions ();
1756 /* Set some mode flags. */
1757 target_set_disconnected_tracing (disconnected_tracing);
1758 target_set_circular_trace_buffer (circular_trace_buffer);
1759 target_set_trace_buffer_size (trace_buffer_size);
1762 notes = trace_notes;
1763 ret = target_set_trace_notes (trace_user, notes, NULL);
1765 if (!ret && (trace_user || notes))
1766 warning (_("Target does not support trace user/notes, info ignored"));
1768 /* Now insert traps and begin collecting data. */
1769 target_trace_start ();
1771 /* Reset our local state. */
1772 trace_reset_local_state ();
1773 current_trace_status()->running = 1;
1776 /* The tstart command requests the target to start a new trace run.
1777 The command passes any arguments it has to the target verbatim, as
1778 an optional "trace note". This is useful as for instance a warning
1779 to other users if the trace runs disconnected, and you don't want
1780 anybody else messing with the target. */
1783 tstart_command (char *args, int from_tty)
1785 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1787 if (current_trace_status ()->running)
1790 && !query (_("A trace is running already. Start a new run? ")))
1791 error (_("New trace run not started."));
1794 start_tracing (args);
1797 /* The tstop command stops the tracing run. The command passes any
1798 supplied arguments to the target verbatim as a "stop note"; if the
1799 target supports trace notes, then it will be reported back as part
1800 of the trace run's status. */
1803 tstop_command (char *args, int from_tty)
1805 if (!current_trace_status ()->running)
1806 error (_("Trace is not running."));
1808 stop_tracing (args);
1812 stop_tracing (char *note)
1815 VEC(breakpoint_p) *tp_vec = NULL;
1817 struct breakpoint *t;
1819 target_trace_stop ();
1821 tp_vec = all_tracepoints ();
1822 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
1824 struct bp_location *loc;
1826 if ((t->type == bp_fast_tracepoint
1827 ? !may_insert_fast_tracepoints
1828 : !may_insert_tracepoints))
1831 for (loc = t->loc; loc; loc = loc->next)
1833 /* GDB can be totally absent in some disconnected trace scenarios,
1834 but we don't really care if this semaphore goes out of sync.
1835 That's why we are decrementing it here, but not taking care
1837 if (loc->probe.probe != NULL
1838 && loc->probe.probe->pops->clear_semaphore != NULL)
1839 loc->probe.probe->pops->clear_semaphore (loc->probe.probe,
1845 VEC_free (breakpoint_p, tp_vec);
1848 note = trace_stop_notes;
1849 ret = target_set_trace_notes (NULL, NULL, note);
1852 warning (_("Target does not support trace notes, note ignored"));
1854 /* Should change in response to reply? */
1855 current_trace_status ()->running = 0;
1858 /* tstatus command */
1860 tstatus_command (char *args, int from_tty)
1862 struct trace_status *ts = current_trace_status ();
1864 VEC(breakpoint_p) *tp_vec = NULL;
1865 struct breakpoint *t;
1867 status = target_get_trace_status (ts);
1871 if (ts->filename != NULL)
1872 printf_filtered (_("Using a trace file.\n"));
1875 printf_filtered (_("Trace can not be run on this target.\n"));
1880 if (!ts->running_known)
1882 printf_filtered (_("Run/stop status is unknown.\n"));
1884 else if (ts->running)
1886 printf_filtered (_("Trace is running on the target.\n"));
1890 switch (ts->stop_reason)
1892 case trace_never_run:
1893 printf_filtered (_("No trace has been run on the target.\n"));
1895 case trace_stop_command:
1897 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1900 printf_filtered (_("Trace stopped by a tstop command.\n"));
1902 case trace_buffer_full:
1903 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1905 case trace_disconnected:
1906 printf_filtered (_("Trace stopped because of disconnection.\n"));
1908 case tracepoint_passcount:
1909 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1910 ts->stopping_tracepoint);
1912 case tracepoint_error:
1913 if (ts->stopping_tracepoint)
1914 printf_filtered (_("Trace stopped by an "
1915 "error (%s, tracepoint %d).\n"),
1916 ts->stop_desc, ts->stopping_tracepoint);
1918 printf_filtered (_("Trace stopped by an error (%s).\n"),
1921 case trace_stop_reason_unknown:
1922 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1925 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1931 if (ts->traceframes_created >= 0
1932 && ts->traceframe_count != ts->traceframes_created)
1934 printf_filtered (_("Buffer contains %d trace "
1935 "frames (of %d created total).\n"),
1936 ts->traceframe_count, ts->traceframes_created);
1938 else if (ts->traceframe_count >= 0)
1940 printf_filtered (_("Collected %d trace frames.\n"),
1941 ts->traceframe_count);
1944 if (ts->buffer_free >= 0)
1946 if (ts->buffer_size >= 0)
1948 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1949 ts->buffer_free, ts->buffer_size);
1950 if (ts->buffer_size > 0)
1951 printf_filtered (_(" (%d%% full)"),
1952 ((int) ((((long long) (ts->buffer_size
1953 - ts->buffer_free)) * 100)
1954 / ts->buffer_size)));
1955 printf_filtered (_(".\n"));
1958 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1962 if (ts->disconnected_tracing)
1963 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1965 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1967 if (ts->circular_buffer)
1968 printf_filtered (_("Trace buffer is circular.\n"));
1970 if (ts->user_name && strlen (ts->user_name) > 0)
1971 printf_filtered (_("Trace user is %s.\n"), ts->user_name);
1973 if (ts->notes && strlen (ts->notes) > 0)
1974 printf_filtered (_("Trace notes: %s.\n"), ts->notes);
1976 /* Now report on what we're doing with tfind. */
1977 if (traceframe_number >= 0)
1978 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1979 traceframe_number, tracepoint_number);
1981 printf_filtered (_("Not looking at any trace frame.\n"));
1983 /* Report start/stop times if supplied. */
1988 LONGEST run_time = ts->stop_time - ts->start_time;
1990 /* Reporting a run time is more readable than two long numbers. */
1991 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
1992 (long int) (ts->start_time / 1000000),
1993 (long int) (ts->start_time % 1000000),
1994 (long int) (run_time / 1000000),
1995 (long int) (run_time % 1000000));
1998 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
1999 (long int) (ts->start_time / 1000000),
2000 (long int) (ts->start_time % 1000000));
2002 else if (ts->stop_time)
2003 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
2004 (long int) (ts->stop_time / 1000000),
2005 (long int) (ts->stop_time % 1000000));
2007 /* Now report any per-tracepoint status available. */
2008 tp_vec = all_tracepoints ();
2010 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
2011 target_get_tracepoint_status (t, NULL);
2013 VEC_free (breakpoint_p, tp_vec);
2016 /* Report the trace status to uiout, in a way suitable for MI, and not
2017 suitable for CLI. If ON_STOP is true, suppress a few fields that
2018 are not meaningful in the -trace-stop response.
2020 The implementation is essentially parallel to trace_status_command, but
2021 merging them will result in unreadable code. */
2023 trace_status_mi (int on_stop)
2025 struct ui_out *uiout = current_uiout;
2026 struct trace_status *ts = current_trace_status ();
2029 status = target_get_trace_status (ts);
2031 if (status == -1 && ts->filename == NULL)
2033 ui_out_field_string (uiout, "supported", "0");
2037 if (ts->filename != NULL)
2038 ui_out_field_string (uiout, "supported", "file");
2040 ui_out_field_string (uiout, "supported", "1");
2042 if (ts->filename != NULL)
2043 ui_out_field_string (uiout, "trace-file", ts->filename);
2045 gdb_assert (ts->running_known);
2049 ui_out_field_string (uiout, "running", "1");
2051 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
2052 Given that the frontend gets the status either on -trace-stop, or from
2053 -trace-status after re-connection, it does not seem like this
2054 information is necessary for anything. It is not necessary for either
2055 figuring the vital state of the target nor for navigation of trace
2056 frames. If the frontend wants to show the current state is some
2057 configure dialog, it can request the value when such dialog is
2058 invoked by the user. */
2062 char *stop_reason = NULL;
2063 int stopping_tracepoint = -1;
2066 ui_out_field_string (uiout, "running", "0");
2068 if (ts->stop_reason != trace_stop_reason_unknown)
2070 switch (ts->stop_reason)
2072 case trace_stop_command:
2073 stop_reason = "request";
2075 case trace_buffer_full:
2076 stop_reason = "overflow";
2078 case trace_disconnected:
2079 stop_reason = "disconnection";
2081 case tracepoint_passcount:
2082 stop_reason = "passcount";
2083 stopping_tracepoint = ts->stopping_tracepoint;
2085 case tracepoint_error:
2086 stop_reason = "error";
2087 stopping_tracepoint = ts->stopping_tracepoint;
2093 ui_out_field_string (uiout, "stop-reason", stop_reason);
2094 if (stopping_tracepoint != -1)
2095 ui_out_field_int (uiout, "stopping-tracepoint",
2096 stopping_tracepoint);
2097 if (ts->stop_reason == tracepoint_error)
2098 ui_out_field_string (uiout, "error-description",
2104 if (ts->traceframe_count != -1)
2105 ui_out_field_int (uiout, "frames", ts->traceframe_count);
2106 if (ts->traceframes_created != -1)
2107 ui_out_field_int (uiout, "frames-created", ts->traceframes_created);
2108 if (ts->buffer_size != -1)
2109 ui_out_field_int (uiout, "buffer-size", ts->buffer_size);
2110 if (ts->buffer_free != -1)
2111 ui_out_field_int (uiout, "buffer-free", ts->buffer_free);
2113 ui_out_field_int (uiout, "disconnected", ts->disconnected_tracing);
2114 ui_out_field_int (uiout, "circular", ts->circular_buffer);
2116 ui_out_field_string (uiout, "user-name", ts->user_name);
2117 ui_out_field_string (uiout, "notes", ts->notes);
2122 xsnprintf (buf, sizeof buf, "%ld.%06ld",
2123 (long int) (ts->start_time / 1000000),
2124 (long int) (ts->start_time % 1000000));
2125 ui_out_field_string (uiout, "start-time", buf);
2126 xsnprintf (buf, sizeof buf, "%ld.%06ld",
2127 (long int) (ts->stop_time / 1000000),
2128 (long int) (ts->stop_time % 1000000));
2129 ui_out_field_string (uiout, "stop-time", buf);
2133 /* Check if a trace run is ongoing. If so, and FROM_TTY, query the
2134 user if she really wants to detach. */
2137 query_if_trace_running (int from_tty)
2142 /* It can happen that the target that was tracing went away on its
2143 own, and we didn't notice. Get a status update, and if the
2144 current target doesn't even do tracing, then assume it's not
2146 if (target_get_trace_status (current_trace_status ()) < 0)
2147 current_trace_status ()->running = 0;
2149 /* If running interactively, give the user the option to cancel and
2150 then decide what to do differently with the run. Scripts are
2151 just going to disconnect and let the target deal with it,
2152 according to how it's been instructed previously via
2153 disconnected-tracing. */
2154 if (current_trace_status ()->running)
2156 process_tracepoint_on_disconnect ();
2158 if (current_trace_status ()->disconnected_tracing)
2160 if (!query (_("Trace is running and will "
2161 "continue after detach; detach anyway? ")))
2162 error (_("Not confirmed."));
2166 if (!query (_("Trace is running but will "
2167 "stop on detach; detach anyway? ")))
2168 error (_("Not confirmed."));
2173 /* This function handles the details of what to do about an ongoing
2174 tracing run if the user has asked to detach or otherwise disconnect
2178 disconnect_tracing (void)
2180 /* Also we want to be out of tfind mode, otherwise things can get
2181 confusing upon reconnection. Just use these calls instead of
2182 full tfind_1 behavior because we're in the middle of detaching,
2183 and there's no point to updating current stack frame etc. */
2184 trace_reset_local_state ();
2187 /* Worker function for the various flavors of the tfind command. */
2189 tfind_1 (enum trace_find_type type, int num,
2190 CORE_ADDR addr1, CORE_ADDR addr2,
2193 int target_frameno = -1, target_tracept = -1;
2194 struct frame_id old_frame_id = null_frame_id;
2195 struct tracepoint *tp;
2196 struct ui_out *uiout = current_uiout;
2198 /* Only try to get the current stack frame if we have a chance of
2199 succeeding. In particular, if we're trying to get a first trace
2200 frame while all threads are running, it's not going to succeed,
2201 so leave it with a default value and let the frame comparison
2202 below (correctly) decide to print out the source location of the
2204 if (!(type == tfind_number && num == -1)
2205 && (has_stack_frames () || traceframe_number >= 0))
2206 old_frame_id = get_frame_id (get_current_frame ());
2208 target_frameno = target_trace_find (type, num, addr1, addr2,
2211 if (type == tfind_number
2213 && target_frameno == -1)
2215 /* We told the target to get out of tfind mode, and it did. */
2217 else if (target_frameno == -1)
2219 /* A request for a non-existent trace frame has failed.
2220 Our response will be different, depending on FROM_TTY:
2222 If FROM_TTY is true, meaning that this command was
2223 typed interactively by the user, then give an error
2224 and DO NOT change the state of traceframe_number etc.
2226 However if FROM_TTY is false, meaning that we're either
2227 in a script, a loop, or a user-defined command, then
2228 DON'T give an error, but DO change the state of
2229 traceframe_number etc. to invalid.
2231 The rationalle is that if you typed the command, you
2232 might just have committed a typo or something, and you'd
2233 like to NOT lose your current debugging state. However
2234 if you're in a user-defined command or especially in a
2235 loop, then you need a way to detect that the command
2236 failed WITHOUT aborting. This allows you to write
2237 scripts that search thru the trace buffer until the end,
2238 and then continue on to do something else. */
2241 error (_("Target failed to find requested trace frame."));
2245 printf_filtered ("End of trace buffer.\n");
2246 #if 0 /* dubious now? */
2247 /* The following will not recurse, since it's
2249 tfind_command ("-1", from_tty);
2254 tp = get_tracepoint_by_number_on_target (target_tracept);
2256 reinit_frame_cache ();
2257 target_dcache_invalidate ();
2259 set_tracepoint_num (tp ? tp->base.number : target_tracept);
2261 if (target_frameno != get_traceframe_number ())
2262 observer_notify_traceframe_changed (target_frameno, tracepoint_number);
2264 set_current_traceframe (target_frameno);
2266 if (target_frameno == -1)
2267 set_traceframe_context (NULL);
2269 set_traceframe_context (get_current_frame ());
2271 if (traceframe_number >= 0)
2273 /* Use different branches for MI and CLI to make CLI messages
2275 if (ui_out_is_mi_like_p (uiout))
2277 ui_out_field_string (uiout, "found", "1");
2278 ui_out_field_int (uiout, "tracepoint", tracepoint_number);
2279 ui_out_field_int (uiout, "traceframe", traceframe_number);
2283 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2284 traceframe_number, tracepoint_number);
2289 if (ui_out_is_mi_like_p (uiout))
2290 ui_out_field_string (uiout, "found", "0");
2291 else if (type == tfind_number && num == -1)
2292 printf_unfiltered (_("No longer looking at any trace frame\n"));
2293 else /* This case may never occur, check. */
2294 printf_unfiltered (_("No trace frame found\n"));
2297 /* If we're in nonstop mode and getting out of looking at trace
2298 frames, there won't be any current frame to go back to and
2301 && (has_stack_frames () || traceframe_number >= 0))
2303 enum print_what print_what;
2305 /* NOTE: in imitation of the step command, try to determine
2306 whether we have made a transition from one function to
2307 another. If so, we'll print the "stack frame" (ie. the new
2308 function and it's arguments) -- otherwise we'll just show the
2311 if (frame_id_eq (old_frame_id,
2312 get_frame_id (get_current_frame ())))
2313 print_what = SRC_LINE;
2315 print_what = SRC_AND_LOC;
2317 print_stack_frame (get_selected_frame (NULL), 1, print_what, 1);
2322 /* Error on looking at traceframes while trace is running. */
2325 check_trace_running (struct trace_status *status)
2327 if (status->running && status->filename == NULL)
2328 error (_("May not look at trace frames while trace is running."));
2331 /* trace_find_command takes a trace frame number n,
2332 sends "QTFrame:<n>" to the target,
2333 and accepts a reply that may contain several optional pieces
2334 of information: a frame number, a tracepoint number, and an
2335 indication of whether this is a trap frame or a stepping frame.
2337 The minimal response is just "OK" (which indicates that the
2338 target does not give us a frame number or a tracepoint number).
2339 Instead of that, the target may send us a string containing
2341 F<hexnum> (gives the selected frame number)
2342 T<hexnum> (gives the selected tracepoint number)
2347 tfind_command (char *args, int from_tty)
2348 { /* This should only be called with a numeric argument. */
2351 check_trace_running (current_trace_status ());
2353 if (args == 0 || *args == 0)
2354 { /* TFIND with no args means find NEXT trace frame. */
2355 if (traceframe_number == -1)
2356 frameno = 0; /* "next" is first one. */
2358 frameno = traceframe_number + 1;
2360 else if (0 == strcmp (args, "-"))
2362 if (traceframe_number == -1)
2363 error (_("not debugging trace buffer"));
2364 else if (from_tty && traceframe_number == 0)
2365 error (_("already at start of trace buffer"));
2367 frameno = traceframe_number - 1;
2369 /* A hack to work around eval's need for fp to have been collected. */
2370 else if (0 == strcmp (args, "-1"))
2373 frameno = parse_and_eval_long (args);
2376 error (_("invalid input (%d is less than zero)"), frameno);
2378 tfind_1 (tfind_number, frameno, 0, 0, from_tty);
2383 tfind_end_command (char *args, int from_tty)
2385 tfind_command ("-1", from_tty);
2390 tfind_start_command (char *args, int from_tty)
2392 tfind_command ("0", from_tty);
2395 /* tfind pc command */
2397 tfind_pc_command (char *args, int from_tty)
2401 check_trace_running (current_trace_status ());
2403 if (args == 0 || *args == 0)
2404 pc = regcache_read_pc (get_current_regcache ());
2406 pc = parse_and_eval_address (args);
2408 tfind_1 (tfind_pc, 0, pc, 0, from_tty);
2411 /* tfind tracepoint command */
2413 tfind_tracepoint_command (char *args, int from_tty)
2416 struct tracepoint *tp;
2418 check_trace_running (current_trace_status ());
2420 if (args == 0 || *args == 0)
2422 if (tracepoint_number == -1)
2423 error (_("No current tracepoint -- please supply an argument."));
2425 tdp = tracepoint_number; /* Default is current TDP. */
2428 tdp = parse_and_eval_long (args);
2430 /* If we have the tracepoint on hand, use the number that the
2431 target knows about (which may be different if we disconnected
2432 and reconnected). */
2433 tp = get_tracepoint (tdp);
2435 tdp = tp->number_on_target;
2437 tfind_1 (tfind_tp, tdp, 0, 0, from_tty);
2440 /* TFIND LINE command:
2442 This command will take a sourceline for argument, just like BREAK
2443 or TRACE (ie. anything that "decode_line_1" can handle).
2445 With no argument, this command will find the next trace frame
2446 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2449 tfind_line_command (char *args, int from_tty)
2451 static CORE_ADDR start_pc, end_pc;
2452 struct symtabs_and_lines sals;
2453 struct symtab_and_line sal;
2454 struct cleanup *old_chain;
2456 check_trace_running (current_trace_status ());
2458 if (args == 0 || *args == 0)
2460 sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
2462 sals.sals = XNEW (struct symtab_and_line);
2467 sals = decode_line_with_current_source (args, DECODE_LINE_FUNFIRSTLINE);
2471 old_chain = make_cleanup (xfree, sals.sals);
2472 if (sal.symtab == 0)
2473 error (_("No line number information available."));
2475 if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc))
2477 if (start_pc == end_pc)
2479 printf_filtered ("Line %d of \"%s\"",
2481 symtab_to_filename_for_display (sal.symtab));
2483 printf_filtered (" is at address ");
2484 print_address (get_current_arch (), start_pc, gdb_stdout);
2486 printf_filtered (" but contains no code.\n");
2487 sal = find_pc_line (start_pc, 0);
2489 && find_line_pc_range (sal, &start_pc, &end_pc)
2490 && start_pc != end_pc)
2491 printf_filtered ("Attempting to find line %d instead.\n",
2494 error (_("Cannot find a good line."));
2498 /* Is there any case in which we get here, and have an address
2499 which the user would want to see? If we have debugging
2500 symbols and no line numbers? */
2501 error (_("Line number %d is out of range for \"%s\"."),
2502 sal.line, symtab_to_filename_for_display (sal.symtab));
2504 /* Find within range of stated line. */
2506 tfind_1 (tfind_range, 0, start_pc, end_pc - 1, from_tty);
2508 tfind_1 (tfind_outside, 0, start_pc, end_pc - 1, from_tty);
2509 do_cleanups (old_chain);
2512 /* tfind range command */
2514 tfind_range_command (char *args, int from_tty)
2516 static CORE_ADDR start, stop;
2519 check_trace_running (current_trace_status ());
2521 if (args == 0 || *args == 0)
2522 { /* XXX FIXME: what should default behavior be? */
2523 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2527 if (0 != (tmp = strchr (args, ',')))
2529 *tmp++ = '\0'; /* Terminate start address. */
2530 tmp = skip_spaces (tmp);
2531 start = parse_and_eval_address (args);
2532 stop = parse_and_eval_address (tmp);
2535 { /* No explicit end address? */
2536 start = parse_and_eval_address (args);
2537 stop = start + 1; /* ??? */
2540 tfind_1 (tfind_range, 0, start, stop, from_tty);
2543 /* tfind outside command */
2545 tfind_outside_command (char *args, int from_tty)
2547 CORE_ADDR start, stop;
2550 if (current_trace_status ()->running
2551 && current_trace_status ()->filename == NULL)
2552 error (_("May not look at trace frames while trace is running."));
2554 if (args == 0 || *args == 0)
2555 { /* XXX FIXME: what should default behavior be? */
2556 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2560 if (0 != (tmp = strchr (args, ',')))
2562 *tmp++ = '\0'; /* Terminate start address. */
2563 tmp = skip_spaces (tmp);
2564 start = parse_and_eval_address (args);
2565 stop = parse_and_eval_address (tmp);
2568 { /* No explicit end address? */
2569 start = parse_and_eval_address (args);
2570 stop = start + 1; /* ??? */
2573 tfind_1 (tfind_outside, 0, start, stop, from_tty);
2576 /* info scope command: list the locals for a scope. */
2578 scope_info (char *args, int from_tty)
2580 struct symtabs_and_lines sals;
2582 struct bound_minimal_symbol msym;
2583 const struct block *block;
2584 const char *symname;
2585 char *save_args = args;
2586 struct block_iterator iter;
2588 struct gdbarch *gdbarch;
2590 struct event_location *location;
2591 struct cleanup *back_to;
2593 if (args == 0 || *args == 0)
2594 error (_("requires an argument (function, "
2595 "line or *addr) to define a scope"));
2597 location = string_to_event_location (&args, current_language);
2598 back_to = make_cleanup_delete_event_location (location);
2599 sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, NULL, 0);
2600 if (sals.nelts == 0)
2602 /* Presumably decode_line_1 has already warned. */
2603 do_cleanups (back_to);
2607 /* Resolve line numbers to PC. */
2608 resolve_sal_pc (&sals.sals[0]);
2609 block = block_for_pc (sals.sals[0].pc);
2613 QUIT; /* Allow user to bail out with ^C. */
2614 ALL_BLOCK_SYMBOLS (block, iter, sym)
2616 QUIT; /* Allow user to bail out with ^C. */
2618 printf_filtered ("Scope for %s:\n", save_args);
2621 symname = SYMBOL_PRINT_NAME (sym);
2622 if (symname == NULL || *symname == '\0')
2623 continue; /* Probably botched, certainly useless. */
2625 gdbarch = symbol_arch (sym);
2627 printf_filtered ("Symbol %s is ", symname);
2629 if (SYMBOL_COMPUTED_OPS (sym) != NULL)
2630 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym,
2631 BLOCK_START (block),
2635 switch (SYMBOL_CLASS (sym))
2638 case LOC_UNDEF: /* Messed up symbol? */
2639 printf_filtered ("a bogus symbol, class %d.\n",
2640 SYMBOL_CLASS (sym));
2641 count--; /* Don't count this one. */
2644 printf_filtered ("a constant with value %s (%s)",
2645 plongest (SYMBOL_VALUE (sym)),
2646 hex_string (SYMBOL_VALUE (sym)));
2648 case LOC_CONST_BYTES:
2649 printf_filtered ("constant bytes: ");
2650 if (SYMBOL_TYPE (sym))
2651 for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++)
2652 fprintf_filtered (gdb_stdout, " %02x",
2653 (unsigned) SYMBOL_VALUE_BYTES (sym)[j]);
2656 printf_filtered ("in static storage at address ");
2657 printf_filtered ("%s", paddress (gdbarch,
2658 SYMBOL_VALUE_ADDRESS (sym)));
2661 /* GDBARCH is the architecture associated with the objfile
2662 the symbol is defined in; the target architecture may be
2663 different, and may provide additional registers. However,
2664 we do not know the target architecture at this point.
2665 We assume the objfile architecture will contain all the
2666 standard registers that occur in debug info in that
2668 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym,
2671 if (SYMBOL_IS_ARGUMENT (sym))
2672 printf_filtered ("an argument in register $%s",
2673 gdbarch_register_name (gdbarch, regno));
2675 printf_filtered ("a local variable in register $%s",
2676 gdbarch_register_name (gdbarch, regno));
2679 printf_filtered ("an argument at stack/frame offset %s",
2680 plongest (SYMBOL_VALUE (sym)));
2683 printf_filtered ("a local variable at frame offset %s",
2684 plongest (SYMBOL_VALUE (sym)));
2687 printf_filtered ("a reference argument at offset %s",
2688 plongest (SYMBOL_VALUE (sym)));
2690 case LOC_REGPARM_ADDR:
2691 /* Note comment at LOC_REGISTER. */
2692 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym,
2694 printf_filtered ("the address of an argument, in register $%s",
2695 gdbarch_register_name (gdbarch, regno));
2698 printf_filtered ("a typedef.\n");
2701 printf_filtered ("a label at address ");
2702 printf_filtered ("%s", paddress (gdbarch,
2703 SYMBOL_VALUE_ADDRESS (sym)));
2706 printf_filtered ("a function at address ");
2707 printf_filtered ("%s",
2708 paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
2710 case LOC_UNRESOLVED:
2711 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
2713 if (msym.minsym == NULL)
2714 printf_filtered ("Unresolved Static");
2717 printf_filtered ("static storage at address ");
2718 printf_filtered ("%s",
2720 BMSYMBOL_VALUE_ADDRESS (msym)));
2723 case LOC_OPTIMIZED_OUT:
2724 printf_filtered ("optimized out.\n");
2727 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2730 if (SYMBOL_TYPE (sym))
2731 printf_filtered (", length %d.\n",
2732 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
2734 if (BLOCK_FUNCTION (block))
2737 block = BLOCK_SUPERBLOCK (block);
2740 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2742 do_cleanups (back_to);
2745 /* Helper for trace_dump_command. Dump the action list starting at
2746 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2747 actions of the body of a while-stepping action. STEPPING_FRAME is
2748 set if the current traceframe was determined to be a while-stepping
2752 trace_dump_actions (struct command_line *action,
2753 int stepping_actions, int stepping_frame,
2756 const char *action_exp, *next_comma;
2758 for (; action != NULL; action = action->next)
2760 struct cmd_list_element *cmd;
2762 QUIT; /* Allow user to bail out with ^C. */
2763 action_exp = action->line;
2764 action_exp = skip_spaces_const (action_exp);
2766 /* The collection actions to be done while stepping are
2767 bracketed by the commands "while-stepping" and "end". */
2769 if (*action_exp == '#') /* comment line */
2772 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
2774 error (_("Bad action list item: %s"), action_exp);
2776 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
2780 for (i = 0; i < action->body_count; ++i)
2781 trace_dump_actions (action->body_list[i],
2782 1, stepping_frame, from_tty);
2784 else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
2786 /* Display the collected data.
2787 For the trap frame, display only what was collected at
2788 the trap. Likewise for stepping frames, display only
2789 what was collected while stepping. This means that the
2790 two boolean variables, STEPPING_FRAME and
2791 STEPPING_ACTIONS should be equal. */
2792 if (stepping_frame == stepping_actions)
2795 struct cleanup *old_chain
2796 = make_cleanup (free_current_contents, &cmd);
2797 int trace_string = 0;
2799 if (*action_exp == '/')
2800 action_exp = decode_agent_options (action_exp, &trace_string);
2803 { /* Repeat over a comma-separated list. */
2804 QUIT; /* Allow user to bail out with ^C. */
2805 if (*action_exp == ',')
2807 action_exp = skip_spaces_const (action_exp);
2809 next_comma = strchr (action_exp, ',');
2811 if (0 == strncasecmp (action_exp, "$reg", 4))
2812 registers_info (NULL, from_tty);
2813 else if (0 == strncasecmp (action_exp, "$_ret", 5))
2815 else if (0 == strncasecmp (action_exp, "$loc", 4))
2816 locals_info (NULL, from_tty);
2817 else if (0 == strncasecmp (action_exp, "$arg", 4))
2818 args_info (NULL, from_tty);
2821 if (next_comma != NULL)
2823 size_t len = next_comma - action_exp;
2825 cmd = (char *) xrealloc (cmd, len + 1);
2826 memcpy (cmd, action_exp, len);
2831 size_t len = strlen (action_exp);
2833 cmd = (char *) xrealloc (cmd, len + 1);
2834 memcpy (cmd, action_exp, len + 1);
2837 printf_filtered ("%s = ", cmd);
2838 output_command_const (cmd, from_tty);
2839 printf_filtered ("\n");
2841 action_exp = next_comma;
2843 while (action_exp && *action_exp == ',');
2845 do_cleanups (old_chain);
2851 /* Return bp_location of the tracepoint associated with the current
2852 traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe
2853 is a stepping traceframe. */
2855 struct bp_location *
2856 get_traceframe_location (int *stepping_frame_p)
2858 struct tracepoint *t;
2859 struct bp_location *tloc;
2860 struct regcache *regcache;
2862 if (tracepoint_number == -1)
2863 error (_("No current trace frame."));
2865 t = get_tracepoint (tracepoint_number);
2868 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2871 /* The current frame is a trap frame if the frame PC is equal to the
2872 tracepoint PC. If not, then the current frame was collected
2873 during single-stepping. */
2874 regcache = get_current_regcache ();
2876 /* If the traceframe's address matches any of the tracepoint's
2877 locations, assume it is a direct hit rather than a while-stepping
2878 frame. (FIXME this is not reliable, should record each frame's
2880 for (tloc = t->base.loc; tloc; tloc = tloc->next)
2881 if (tloc->address == regcache_read_pc (regcache))
2883 *stepping_frame_p = 0;
2887 /* If this is a stepping frame, we don't know which location
2888 triggered. The first is as good (or bad) a guess as any... */
2889 *stepping_frame_p = 1;
2893 /* Return all the actions, including default collect, of a tracepoint
2894 T. It constructs cleanups into the chain, and leaves the caller to
2895 handle them (call do_cleanups). */
2897 static struct command_line *
2898 all_tracepoint_actions_and_cleanup (struct breakpoint *t)
2900 struct command_line *actions;
2902 actions = breakpoint_commands (t);
2904 /* If there are default expressions to collect, make up a collect
2905 action and prepend to the action list to encode. Note that since
2906 validation is per-tracepoint (local var "xyz" might be valid for
2907 one tracepoint and not another, etc), we make up the action on
2908 the fly, and don't cache it. */
2909 if (*default_collect)
2911 struct command_line *default_collect_action;
2912 char *default_collect_line;
2914 default_collect_line = xstrprintf ("collect %s", default_collect);
2915 make_cleanup (xfree, default_collect_line);
2917 validate_actionline (default_collect_line, t);
2918 default_collect_action = XNEW (struct command_line);
2919 make_cleanup (xfree, default_collect_action);
2920 default_collect_action->next = actions;
2921 default_collect_action->line = default_collect_line;
2922 actions = default_collect_action;
2928 /* The tdump command. */
2931 tdump_command (char *args, int from_tty)
2933 int stepping_frame = 0;
2934 struct bp_location *loc;
2935 struct cleanup *old_chain;
2936 struct command_line *actions;
2938 /* This throws an error is not inspecting a trace frame. */
2939 loc = get_traceframe_location (&stepping_frame);
2941 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2942 tracepoint_number, traceframe_number);
2944 /* This command only makes sense for the current frame, not the
2946 old_chain = make_cleanup_restore_current_thread ();
2947 select_frame (get_current_frame ());
2949 actions = all_tracepoint_actions_and_cleanup (loc->owner);
2951 trace_dump_actions (actions, 0, stepping_frame, from_tty);
2953 do_cleanups (old_chain);
2956 /* Encode a piece of a tracepoint's source-level definition in a form
2957 that is suitable for both protocol and saving in files. */
2958 /* This version does not do multiple encodes for long strings; it should
2959 return an offset to the next piece to encode. FIXME */
2962 encode_source_string (int tpnum, ULONGEST addr,
2963 char *srctype, const char *src, char *buf, int buf_size)
2965 if (80 + strlen (srctype) > buf_size)
2966 error (_("Buffer too small for source encoding"));
2967 sprintf (buf, "%x:%s:%s:%x:%x:",
2968 tpnum, phex_nz (addr, sizeof (addr)),
2969 srctype, 0, (int) strlen (src));
2970 if (strlen (buf) + strlen (src) * 2 >= buf_size)
2971 error (_("Source string too long for buffer"));
2972 bin2hex ((gdb_byte *) src, buf + strlen (buf), strlen (src));
2976 /* Tell the target what to do with an ongoing tracing run if GDB
2977 disconnects for some reason. */
2980 set_disconnected_tracing (char *args, int from_tty,
2981 struct cmd_list_element *c)
2983 target_set_disconnected_tracing (disconnected_tracing);
2987 set_circular_trace_buffer (char *args, int from_tty,
2988 struct cmd_list_element *c)
2990 target_set_circular_trace_buffer (circular_trace_buffer);
2994 set_trace_buffer_size (char *args, int from_tty,
2995 struct cmd_list_element *c)
2997 target_set_trace_buffer_size (trace_buffer_size);
3001 set_trace_user (char *args, int from_tty,
3002 struct cmd_list_element *c)
3006 ret = target_set_trace_notes (trace_user, NULL, NULL);
3009 warning (_("Target does not support trace notes, user ignored"));
3013 set_trace_notes (char *args, int from_tty,
3014 struct cmd_list_element *c)
3018 ret = target_set_trace_notes (NULL, trace_notes, NULL);
3021 warning (_("Target does not support trace notes, note ignored"));
3025 set_trace_stop_notes (char *args, int from_tty,
3026 struct cmd_list_element *c)
3030 ret = target_set_trace_notes (NULL, NULL, trace_stop_notes);
3033 warning (_("Target does not support trace notes, stop note ignored"));
3036 /* Convert the memory pointed to by mem into hex, placing result in buf.
3037 * Return a pointer to the last char put in buf (null)
3038 * "stolen" from sparc-stub.c
3041 static const char hexchars[] = "0123456789abcdef";
3044 mem2hex (gdb_byte *mem, char *buf, int count)
3052 *buf++ = hexchars[ch >> 4];
3053 *buf++ = hexchars[ch & 0xf];
3062 get_traceframe_number (void)
3064 return traceframe_number;
3068 get_tracepoint_number (void)
3070 return tracepoint_number;
3073 /* Make the traceframe NUM be the current trace frame. Does nothing
3074 if NUM is already current. */
3077 set_current_traceframe (int num)
3081 if (traceframe_number == num)
3083 /* Nothing to do. */
3087 newnum = target_trace_find (tfind_number, num, 0, 0, NULL);
3090 warning (_("could not change traceframe"));
3092 set_traceframe_num (newnum);
3094 /* Changing the traceframe changes our view of registers and of the
3096 registers_changed ();
3098 clear_traceframe_info ();
3101 /* A cleanup used when switching away and back from tfind mode. */
3103 struct current_traceframe_cleanup
3105 /* The traceframe we were inspecting. */
3106 int traceframe_number;
3110 do_restore_current_traceframe_cleanup (void *arg)
3112 struct current_traceframe_cleanup *old
3113 = (struct current_traceframe_cleanup *) arg;
3115 set_current_traceframe (old->traceframe_number);
3119 restore_current_traceframe_cleanup_dtor (void *arg)
3121 struct current_traceframe_cleanup *old
3122 = (struct current_traceframe_cleanup *) arg;
3128 make_cleanup_restore_current_traceframe (void)
3130 struct current_traceframe_cleanup *old =
3131 XNEW (struct current_traceframe_cleanup);
3133 old->traceframe_number = traceframe_number;
3135 return make_cleanup_dtor (do_restore_current_traceframe_cleanup, old,
3136 restore_current_traceframe_cleanup_dtor);
3139 /* Given a number and address, return an uploaded tracepoint with that
3140 number, creating if necessary. */
3142 struct uploaded_tp *
3143 get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp)
3145 struct uploaded_tp *utp;
3147 for (utp = *utpp; utp; utp = utp->next)
3148 if (utp->number == num && utp->addr == addr)
3151 utp = XCNEW (struct uploaded_tp);
3154 utp->actions = NULL;
3155 utp->step_actions = NULL;
3156 utp->cmd_strings = NULL;
3164 free_uploaded_tps (struct uploaded_tp **utpp)
3166 struct uploaded_tp *next_one;
3170 next_one = (*utpp)->next;
3176 /* Given a number and address, return an uploaded tracepoint with that
3177 number, creating if necessary. */
3179 struct uploaded_tsv *
3180 get_uploaded_tsv (int num, struct uploaded_tsv **utsvp)
3182 struct uploaded_tsv *utsv;
3184 for (utsv = *utsvp; utsv; utsv = utsv->next)
3185 if (utsv->number == num)
3188 utsv = XCNEW (struct uploaded_tsv);
3190 utsv->next = *utsvp;
3197 free_uploaded_tsvs (struct uploaded_tsv **utsvp)
3199 struct uploaded_tsv *next_one;
3203 next_one = (*utsvp)->next;
3209 /* FIXME this function is heuristic and will miss the cases where the
3210 conditional is semantically identical but differs in whitespace,
3211 such as "x == 0" vs "x==0". */
3214 cond_string_is_same (char *str1, char *str2)
3216 if (str1 == NULL || str2 == NULL)
3217 return (str1 == str2);
3219 return (strcmp (str1, str2) == 0);
3222 /* Look for an existing tracepoint that seems similar enough to the
3223 uploaded one. Enablement isn't compared, because the user can
3224 toggle that freely, and may have done so in anticipation of the
3225 next trace run. Return the location of matched tracepoint. */
3227 static struct bp_location *
3228 find_matching_tracepoint_location (struct uploaded_tp *utp)
3230 VEC(breakpoint_p) *tp_vec = all_tracepoints ();
3232 struct breakpoint *b;
3233 struct bp_location *loc;
3235 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
3237 struct tracepoint *t = (struct tracepoint *) b;
3239 if (b->type == utp->type
3240 && t->step_count == utp->step
3241 && t->pass_count == utp->pass
3242 && cond_string_is_same (t->base.cond_string, utp->cond_string)
3243 /* FIXME also test actions. */
3246 /* Scan the locations for an address match. */
3247 for (loc = b->loc; loc; loc = loc->next)
3249 if (loc->address == utp->addr)
3257 /* Given a list of tracepoints uploaded from a target, attempt to
3258 match them up with existing tracepoints, and create new ones if not
3262 merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps)
3264 struct uploaded_tp *utp;
3265 /* A set of tracepoints which are modified. */
3266 VEC(breakpoint_p) *modified_tp = NULL;
3268 struct breakpoint *b;
3270 /* Look for GDB tracepoints that match up with our uploaded versions. */
3271 for (utp = *uploaded_tps; utp; utp = utp->next)
3273 struct bp_location *loc;
3274 struct tracepoint *t;
3276 loc = find_matching_tracepoint_location (utp);
3281 /* Mark this location as already inserted. */
3283 t = (struct tracepoint *) loc->owner;
3284 printf_filtered (_("Assuming tracepoint %d is same "
3285 "as target's tracepoint %d at %s.\n"),
3286 loc->owner->number, utp->number,
3287 paddress (loc->gdbarch, utp->addr));
3289 /* The tracepoint LOC->owner was modified (the location LOC
3290 was marked as inserted in the target). Save it in
3291 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3292 observers will be notified later once for each tracepoint
3293 saved in MODIFIED_TP. */
3295 VEC_iterate (breakpoint_p, modified_tp, ix, b);
3297 if (b == loc->owner)
3303 VEC_safe_push (breakpoint_p, modified_tp, loc->owner);
3307 t = create_tracepoint_from_upload (utp);
3309 printf_filtered (_("Created tracepoint %d for "
3310 "target's tracepoint %d at %s.\n"),
3311 t->base.number, utp->number,
3312 paddress (get_current_arch (), utp->addr));
3314 printf_filtered (_("Failed to create tracepoint for target's "
3315 "tracepoint %d at %s, skipping it.\n"),
3317 paddress (get_current_arch (), utp->addr));
3319 /* Whether found or created, record the number used by the
3320 target, to help with mapping target tracepoints back to their
3321 counterparts here. */
3323 t->number_on_target = utp->number;
3326 /* Notify 'breakpoint-modified' observer that at least one of B's
3327 locations was changed. */
3328 for (ix = 0; VEC_iterate (breakpoint_p, modified_tp, ix, b); ix++)
3329 observer_notify_breakpoint_modified (b);
3331 VEC_free (breakpoint_p, modified_tp);
3332 free_uploaded_tps (uploaded_tps);
3335 /* Trace state variables don't have much to identify them beyond their
3336 name, so just use that to detect matches. */
3338 static struct trace_state_variable *
3339 find_matching_tsv (struct uploaded_tsv *utsv)
3344 return find_trace_state_variable (utsv->name);
3347 static struct trace_state_variable *
3348 create_tsv_from_upload (struct uploaded_tsv *utsv)
3350 const char *namebase;
3353 struct trace_state_variable *tsv;
3354 struct cleanup *old_chain;
3358 namebase = utsv->name;
3359 buf = xstrprintf ("%s", namebase);
3364 buf = xstrprintf ("%s_%d", namebase, try_num++);
3367 /* Fish for a name that is not in use. */
3368 /* (should check against all internal vars?) */
3369 while (find_trace_state_variable (buf))
3372 buf = xstrprintf ("%s_%d", namebase, try_num++);
3375 old_chain = make_cleanup (xfree, buf);
3377 /* We have an available name, create the variable. */
3378 tsv = create_trace_state_variable (buf);
3379 tsv->initial_value = utsv->initial_value;
3380 tsv->builtin = utsv->builtin;
3382 observer_notify_tsv_created (tsv);
3384 do_cleanups (old_chain);
3389 /* Given a list of uploaded trace state variables, try to match them
3390 up with existing variables, or create additional ones. */
3393 merge_uploaded_trace_state_variables (struct uploaded_tsv **uploaded_tsvs)
3396 struct uploaded_tsv *utsv;
3397 struct trace_state_variable *tsv;
3400 /* Most likely some numbers will have to be reassigned as part of
3401 the merge, so clear them all in anticipation. */
3402 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3405 for (utsv = *uploaded_tsvs; utsv; utsv = utsv->next)
3407 tsv = find_matching_tsv (utsv);
3411 printf_filtered (_("Assuming trace state variable $%s "
3412 "is same as target's variable %d.\n"),
3413 tsv->name, utsv->number);
3417 tsv = create_tsv_from_upload (utsv);
3419 printf_filtered (_("Created trace state variable "
3420 "$%s for target's variable %d.\n"),
3421 tsv->name, utsv->number);
3423 /* Give precedence to numberings that come from the target. */
3425 tsv->number = utsv->number;
3428 /* Renumber everything that didn't get a target-assigned number. */
3430 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3431 if (tsv->number > highest)
3432 highest = tsv->number;
3435 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3436 if (tsv->number == 0)
3437 tsv->number = highest++;
3439 free_uploaded_tsvs (uploaded_tsvs);
3442 /* Parse the part of trace status syntax that is shared between
3443 the remote protocol and the trace file reader. */
3446 parse_trace_status (char *line, struct trace_status *ts)
3448 char *p = line, *p1, *p2, *p3, *p_temp;
3452 ts->running_known = 1;
3453 ts->running = (*p++ == '1');
3454 ts->stop_reason = trace_stop_reason_unknown;
3455 xfree (ts->stop_desc);
3456 ts->stop_desc = NULL;
3457 ts->traceframe_count = -1;
3458 ts->traceframes_created = -1;
3459 ts->buffer_free = -1;
3460 ts->buffer_size = -1;
3461 ts->disconnected_tracing = 0;
3462 ts->circular_buffer = 0;
3463 xfree (ts->user_name);
3464 ts->user_name = NULL;
3467 ts->start_time = ts->stop_time = 0;
3471 p1 = strchr (p, ':');
3473 error (_("Malformed trace status, at %s\n\
3474 Status line: '%s'\n"), p, line);
3475 p3 = strchr (p, ';');
3477 p3 = p + strlen (p);
3478 if (strncmp (p, stop_reason_names[trace_buffer_full], p1 - p) == 0)
3480 p = unpack_varlen_hex (++p1, &val);
3481 ts->stop_reason = trace_buffer_full;
3483 else if (strncmp (p, stop_reason_names[trace_never_run], p1 - p) == 0)
3485 p = unpack_varlen_hex (++p1, &val);
3486 ts->stop_reason = trace_never_run;
3488 else if (strncmp (p, stop_reason_names[tracepoint_passcount],
3491 p = unpack_varlen_hex (++p1, &val);
3492 ts->stop_reason = tracepoint_passcount;
3493 ts->stopping_tracepoint = val;
3495 else if (strncmp (p, stop_reason_names[trace_stop_command], p1 - p) == 0)
3497 p2 = strchr (++p1, ':');
3505 ts->stop_desc = (char *) xmalloc (strlen (line));
3506 end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2);
3507 ts->stop_desc[end] = '\0';
3510 ts->stop_desc = xstrdup ("");
3512 p = unpack_varlen_hex (++p2, &val);
3513 ts->stop_reason = trace_stop_command;
3515 else if (strncmp (p, stop_reason_names[trace_disconnected], p1 - p) == 0)
3517 p = unpack_varlen_hex (++p1, &val);
3518 ts->stop_reason = trace_disconnected;
3520 else if (strncmp (p, stop_reason_names[tracepoint_error], p1 - p) == 0)
3522 p2 = strchr (++p1, ':');
3525 ts->stop_desc = (char *) xmalloc ((p2 - p1) / 2 + 1);
3526 end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2);
3527 ts->stop_desc[end] = '\0';
3530 ts->stop_desc = xstrdup ("");
3532 p = unpack_varlen_hex (++p2, &val);
3533 ts->stopping_tracepoint = val;
3534 ts->stop_reason = tracepoint_error;
3536 else if (strncmp (p, "tframes", p1 - p) == 0)
3538 p = unpack_varlen_hex (++p1, &val);
3539 ts->traceframe_count = val;
3541 else if (strncmp (p, "tcreated", p1 - p) == 0)
3543 p = unpack_varlen_hex (++p1, &val);
3544 ts->traceframes_created = val;
3546 else if (strncmp (p, "tfree", p1 - p) == 0)
3548 p = unpack_varlen_hex (++p1, &val);
3549 ts->buffer_free = val;
3551 else if (strncmp (p, "tsize", p1 - p) == 0)
3553 p = unpack_varlen_hex (++p1, &val);
3554 ts->buffer_size = val;
3556 else if (strncmp (p, "disconn", p1 - p) == 0)
3558 p = unpack_varlen_hex (++p1, &val);
3559 ts->disconnected_tracing = val;
3561 else if (strncmp (p, "circular", p1 - p) == 0)
3563 p = unpack_varlen_hex (++p1, &val);
3564 ts->circular_buffer = val;
3566 else if (strncmp (p, "starttime", p1 - p) == 0)
3568 p = unpack_varlen_hex (++p1, &val);
3569 ts->start_time = val;
3571 else if (strncmp (p, "stoptime", p1 - p) == 0)
3573 p = unpack_varlen_hex (++p1, &val);
3574 ts->stop_time = val;
3576 else if (strncmp (p, "username", p1 - p) == 0)
3579 ts->user_name = (char *) xmalloc (strlen (p) / 2);
3580 end = hex2bin (p1, (gdb_byte *) ts->user_name, (p3 - p1) / 2);
3581 ts->user_name[end] = '\0';
3584 else if (strncmp (p, "notes", p1 - p) == 0)
3587 ts->notes = (char *) xmalloc (strlen (p) / 2);
3588 end = hex2bin (p1, (gdb_byte *) ts->notes, (p3 - p1) / 2);
3589 ts->notes[end] = '\0';
3594 /* Silently skip unknown optional info. */
3595 p_temp = strchr (p1 + 1, ';');
3599 /* Must be at the end. */
3606 parse_tracepoint_status (char *p, struct breakpoint *bp,
3607 struct uploaded_tp *utp)
3610 struct tracepoint *tp = (struct tracepoint *) bp;
3612 p = unpack_varlen_hex (p, &uval);
3614 tp->base.hit_count += uval;
3616 utp->hit_count += uval;
3617 p = unpack_varlen_hex (p + 1, &uval);
3619 tp->traceframe_usage += uval;
3621 utp->traceframe_usage += uval;
3622 /* Ignore any extra, allowing for future extensions. */
3625 /* Given a line of text defining a part of a tracepoint, parse it into
3626 an "uploaded tracepoint". */
3629 parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
3633 ULONGEST num, addr, step, pass, orig_size, xlen, start;
3636 char *cond, *srctype, *buf;
3637 struct uploaded_tp *utp = NULL;
3640 /* Both tracepoint and action definitions start with the same number
3641 and address sequence. */
3643 p = unpack_varlen_hex (p, &num);
3644 p++; /* skip a colon */
3645 p = unpack_varlen_hex (p, &addr);
3646 p++; /* skip a colon */
3649 enabled = (*p++ == 'E');
3650 p++; /* skip a colon */
3651 p = unpack_varlen_hex (p, &step);
3652 p++; /* skip a colon */
3653 p = unpack_varlen_hex (p, &pass);
3654 type = bp_tracepoint;
3656 /* Thumb through optional fields. */
3659 p++; /* skip a colon */
3662 type = bp_fast_tracepoint;
3664 p = unpack_varlen_hex (p, &orig_size);
3668 type = bp_static_tracepoint;
3674 p = unpack_varlen_hex (p, &xlen);
3675 p++; /* skip a comma */
3676 cond = (char *) xmalloc (2 * xlen + 1);
3677 strncpy (cond, p, 2 * xlen);
3678 cond[2 * xlen] = '\0';
3682 warning (_("Unrecognized char '%c' in tracepoint "
3683 "definition, skipping rest"), *p);
3685 utp = get_uploaded_tp (num, addr, utpp);
3687 utp->enabled = enabled;
3692 else if (piece == 'A')
3694 utp = get_uploaded_tp (num, addr, utpp);
3695 VEC_safe_push (char_ptr, utp->actions, xstrdup (p));
3697 else if (piece == 'S')
3699 utp = get_uploaded_tp (num, addr, utpp);
3700 VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p));
3702 else if (piece == 'Z')
3704 /* Parse a chunk of source form definition. */
3705 utp = get_uploaded_tp (num, addr, utpp);
3707 p = strchr (p, ':');
3708 p++; /* skip a colon */
3709 p = unpack_varlen_hex (p, &start);
3710 p++; /* skip a colon */
3711 p = unpack_varlen_hex (p, &xlen);
3712 p++; /* skip a colon */
3714 buf = (char *) alloca (strlen (line));
3716 end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
3719 if (startswith (srctype, "at:"))
3720 utp->at_string = xstrdup (buf);
3721 else if (startswith (srctype, "cond:"))
3722 utp->cond_string = xstrdup (buf);
3723 else if (startswith (srctype, "cmd:"))
3724 VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf));
3726 else if (piece == 'V')
3728 utp = get_uploaded_tp (num, addr, utpp);
3730 parse_tracepoint_status (p, NULL, utp);
3734 /* Don't error out, the target might be sending us optional
3735 info that we don't care about. */
3736 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece);
3740 /* Convert a textual description of a trace state variable into an
3744 parse_tsv_definition (char *line, struct uploaded_tsv **utsvp)
3747 ULONGEST num, initval, builtin;
3749 struct uploaded_tsv *utsv = NULL;
3751 buf = (char *) alloca (strlen (line));
3754 p = unpack_varlen_hex (p, &num);
3755 p++; /* skip a colon */
3756 p = unpack_varlen_hex (p, &initval);
3757 p++; /* skip a colon */
3758 p = unpack_varlen_hex (p, &builtin);
3759 p++; /* skip a colon */
3760 end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
3763 utsv = get_uploaded_tsv (num, utsvp);
3764 utsv->initial_value = initval;
3765 utsv->builtin = builtin;
3766 utsv->name = xstrdup (buf);
3770 free_current_marker (void *arg)
3772 struct static_tracepoint_marker **marker_p
3773 = (struct static_tracepoint_marker **) arg;
3775 if (*marker_p != NULL)
3777 release_static_tracepoint_marker (*marker_p);
3784 /* Given a line of text defining a static tracepoint marker, parse it
3785 into a "static tracepoint marker" object. Throws an error is
3786 parsing fails. If PP is non-null, it points to one past the end of
3787 the parsed marker definition. */
3790 parse_static_tracepoint_marker_definition (char *line, char **pp,
3791 struct static_tracepoint_marker *marker)
3798 p = unpack_varlen_hex (p, &addr);
3799 p++; /* skip a colon */
3801 marker->gdbarch = target_gdbarch ();
3802 marker->address = (CORE_ADDR) addr;
3804 endp = strchr (p, ':');
3806 error (_("bad marker definition: %s"), line);
3808 marker->str_id = (char *) xmalloc (endp - p + 1);
3809 end = hex2bin (p, (gdb_byte *) marker->str_id, (endp - p + 1) / 2);
3810 marker->str_id[end] = '\0';
3813 p++; /* skip a colon */
3815 marker->extra = (char *) xmalloc (strlen (p) + 1);
3816 end = hex2bin (p, (gdb_byte *) marker->extra, strlen (p) / 2);
3817 marker->extra[end] = '\0';
3823 /* Release a static tracepoint marker's contents. Note that the
3824 object itself isn't released here. There objects are usually on
3828 release_static_tracepoint_marker (struct static_tracepoint_marker *marker)
3830 xfree (marker->str_id);
3831 marker->str_id = NULL;
3834 /* Print MARKER to gdb_stdout. */
3837 print_one_static_tracepoint_marker (int count,
3838 struct static_tracepoint_marker *marker)
3842 char wrap_indent[80];
3843 char extra_field_indent[80];
3844 struct ui_out *uiout = current_uiout;
3845 struct cleanup *bkpt_chain;
3846 VEC(breakpoint_p) *tracepoints;
3848 struct symtab_and_line sal;
3852 sal.pc = marker->address;
3854 tracepoints = static_tracepoints_here (marker->address);
3856 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "marker");
3858 /* A counter field to help readability. This is not a stable
3860 ui_out_field_int (uiout, "count", count);
3862 ui_out_field_string (uiout, "marker-id", marker->str_id);
3864 ui_out_field_fmt (uiout, "enabled", "%c",
3865 !VEC_empty (breakpoint_p, tracepoints) ? 'y' : 'n');
3866 ui_out_spaces (uiout, 2);
3868 strcpy (wrap_indent, " ");
3870 if (gdbarch_addr_bit (marker->gdbarch) <= 32)
3871 strcat (wrap_indent, " ");
3873 strcat (wrap_indent, " ");
3875 strcpy (extra_field_indent, " ");
3877 ui_out_field_core_addr (uiout, "addr", marker->gdbarch, marker->address);
3879 sal = find_pc_line (marker->address, 0);
3880 sym = find_pc_sect_function (marker->address, NULL);
3883 ui_out_text (uiout, "in ");
3884 ui_out_field_string (uiout, "func",
3885 SYMBOL_PRINT_NAME (sym));
3886 ui_out_wrap_hint (uiout, wrap_indent);
3887 ui_out_text (uiout, " at ");
3890 ui_out_field_skip (uiout, "func");
3892 if (sal.symtab != NULL)
3894 ui_out_field_string (uiout, "file",
3895 symtab_to_filename_for_display (sal.symtab));
3896 ui_out_text (uiout, ":");
3898 if (ui_out_is_mi_like_p (uiout))
3900 const char *fullname = symtab_to_fullname (sal.symtab);
3902 ui_out_field_string (uiout, "fullname", fullname);
3905 ui_out_field_skip (uiout, "fullname");
3907 ui_out_field_int (uiout, "line", sal.line);
3911 ui_out_field_skip (uiout, "fullname");
3912 ui_out_field_skip (uiout, "line");
3915 ui_out_text (uiout, "\n");
3916 ui_out_text (uiout, extra_field_indent);
3917 ui_out_text (uiout, _("Data: \""));
3918 ui_out_field_string (uiout, "extra-data", marker->extra);
3919 ui_out_text (uiout, "\"\n");
3921 if (!VEC_empty (breakpoint_p, tracepoints))
3923 struct cleanup *cleanup_chain;
3925 struct breakpoint *b;
3927 cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout,
3930 ui_out_text (uiout, extra_field_indent);
3931 ui_out_text (uiout, _("Probed by static tracepoints: "));
3932 for (ix = 0; VEC_iterate(breakpoint_p, tracepoints, ix, b); ix++)
3935 ui_out_text (uiout, ", ");
3936 ui_out_text (uiout, "#");
3937 ui_out_field_int (uiout, "tracepoint-id", b->number);
3940 do_cleanups (cleanup_chain);
3942 if (ui_out_is_mi_like_p (uiout))
3943 ui_out_field_int (uiout, "number-of-tracepoints",
3944 VEC_length(breakpoint_p, tracepoints));
3946 ui_out_text (uiout, "\n");
3948 VEC_free (breakpoint_p, tracepoints);
3950 do_cleanups (bkpt_chain);
3954 info_static_tracepoint_markers_command (char *arg, int from_tty)
3956 VEC(static_tracepoint_marker_p) *markers;
3957 struct cleanup *old_chain;
3958 struct static_tracepoint_marker *marker;
3959 struct ui_out *uiout = current_uiout;
3962 /* We don't have to check target_can_use_agent and agent's capability on
3963 static tracepoint here, in order to be compatible with older GDBserver.
3964 We don't check USE_AGENT is true or not, because static tracepoints
3965 don't work without in-process agent, so we don't bother users to type
3966 `set agent on' when to use static tracepoint. */
3969 = make_cleanup_ui_out_table_begin_end (uiout, 5, -1,
3970 "StaticTracepointMarkersTable");
3972 ui_out_table_header (uiout, 7, ui_left, "counter", "Cnt");
3974 ui_out_table_header (uiout, 40, ui_left, "marker-id", "ID");
3976 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb");
3977 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
3978 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");
3980 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");
3981 ui_out_table_header (uiout, 40, ui_noalign, "what", "What");
3983 ui_out_table_body (uiout);
3985 markers = target_static_tracepoint_markers_by_strid (NULL);
3986 make_cleanup (VEC_cleanup (static_tracepoint_marker_p), &markers);
3989 VEC_iterate (static_tracepoint_marker_p,
3990 markers, i, marker);
3993 print_one_static_tracepoint_marker (i + 1, marker);
3994 release_static_tracepoint_marker (marker);
3997 do_cleanups (old_chain);
4000 /* The $_sdata convenience variable is a bit special. We don't know
4001 for sure type of the value until we actually have a chance to fetch
4002 the data --- the size of the object depends on what has been
4003 collected. We solve this by making $_sdata be an internalvar that
4004 creates a new value on access. */
4006 /* Return a new value with the correct type for the sdata object of
4007 the current trace frame. Return a void value if there's no object
4010 static struct value *
4011 sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var,
4017 /* We need to read the whole object before we know its size. */
4018 size = target_read_alloc (¤t_target,
4019 TARGET_OBJECT_STATIC_TRACE_DATA,
4026 type = init_vector_type (builtin_type (gdbarch)->builtin_true_char,
4028 v = allocate_value (type);
4029 memcpy (value_contents_raw (v), buf, size);
4034 return allocate_value (builtin_type (gdbarch)->builtin_void);
4037 #if !defined(HAVE_LIBEXPAT)
4039 struct traceframe_info *
4040 parse_traceframe_info (const char *tframe_info)
4042 static int have_warned;
4047 warning (_("Can not parse XML trace frame info; XML support "
4048 "was disabled at compile time"));
4054 #else /* HAVE_LIBEXPAT */
4056 #include "xml-support.h"
4058 /* Handle the start of a <memory> element. */
4061 traceframe_info_start_memory (struct gdb_xml_parser *parser,
4062 const struct gdb_xml_element *element,
4063 void *user_data, VEC(gdb_xml_value_s) *attributes)
4065 struct traceframe_info *info = (struct traceframe_info *) user_data;
4066 struct mem_range *r = VEC_safe_push (mem_range_s, info->memory, NULL);
4067 ULONGEST *start_p, *length_p;
4070 = (ULONGEST *) xml_find_attribute (attributes, "start")->value;
4072 = (ULONGEST *) xml_find_attribute (attributes, "length")->value;
4074 r->start = *start_p;
4075 r->length = *length_p;
4078 /* Handle the start of a <tvar> element. */
4081 traceframe_info_start_tvar (struct gdb_xml_parser *parser,
4082 const struct gdb_xml_element *element,
4084 VEC(gdb_xml_value_s) *attributes)
4086 struct traceframe_info *info = (struct traceframe_info *) user_data;
4087 const char *id_attrib
4088 = (const char *) xml_find_attribute (attributes, "id")->value;
4089 int id = gdb_xml_parse_ulongest (parser, id_attrib);
4091 VEC_safe_push (int, info->tvars, id);
4094 /* Discard the constructed trace frame info (if an error occurs). */
4097 free_result (void *p)
4099 struct traceframe_info *result = (struct traceframe_info *) p;
4101 free_traceframe_info (result);
4104 /* The allowed elements and attributes for an XML memory map. */
4106 static const struct gdb_xml_attribute memory_attributes[] = {
4107 { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
4108 { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
4109 { NULL, GDB_XML_AF_NONE, NULL, NULL }
4112 static const struct gdb_xml_attribute tvar_attributes[] = {
4113 { "id", GDB_XML_AF_NONE, NULL, NULL },
4114 { NULL, GDB_XML_AF_NONE, NULL, NULL }
4117 static const struct gdb_xml_element traceframe_info_children[] = {
4118 { "memory", memory_attributes, NULL,
4119 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
4120 traceframe_info_start_memory, NULL },
4121 { "tvar", tvar_attributes, NULL,
4122 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
4123 traceframe_info_start_tvar, NULL },
4124 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
4127 static const struct gdb_xml_element traceframe_info_elements[] = {
4128 { "traceframe-info", NULL, traceframe_info_children, GDB_XML_EF_NONE,
4130 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
4133 /* Parse a traceframe-info XML document. */
4135 struct traceframe_info *
4136 parse_traceframe_info (const char *tframe_info)
4138 struct traceframe_info *result;
4139 struct cleanup *back_to;
4141 result = XCNEW (struct traceframe_info);
4142 back_to = make_cleanup (free_result, result);
4144 if (gdb_xml_parse_quick (_("trace frame info"),
4145 "traceframe-info.dtd", traceframe_info_elements,
4146 tframe_info, result) == 0)
4148 /* Parsed successfully, keep the result. */
4149 discard_cleanups (back_to);
4154 do_cleanups (back_to);
4158 #endif /* HAVE_LIBEXPAT */
4160 /* Returns the traceframe_info object for the current traceframe.
4161 This is where we avoid re-fetching the object from the target if we
4162 already have it cached. */
4164 struct traceframe_info *
4165 get_traceframe_info (void)
4167 if (traceframe_info == NULL)
4168 traceframe_info = target_traceframe_info ();
4170 return traceframe_info;
4173 /* If the target supports the query, return in RESULT the set of
4174 collected memory in the current traceframe, found within the LEN
4175 bytes range starting at MEMADDR. Returns true if the target
4176 supports the query, otherwise returns false, and RESULT is left
4180 traceframe_available_memory (VEC(mem_range_s) **result,
4181 CORE_ADDR memaddr, ULONGEST len)
4183 struct traceframe_info *info = get_traceframe_info ();
4187 struct mem_range *r;
4192 for (i = 0; VEC_iterate (mem_range_s, info->memory, i, r); i++)
4193 if (mem_ranges_overlap (r->start, r->length, memaddr, len))
4195 ULONGEST lo1, hi1, lo2, hi2;
4196 struct mem_range *nr;
4199 hi1 = memaddr + len;
4202 hi2 = r->start + r->length;
4204 nr = VEC_safe_push (mem_range_s, *result, NULL);
4206 nr->start = std::max (lo1, lo2);
4207 nr->length = std::min (hi1, hi2) - nr->start;
4210 normalize_mem_ranges (*result);
4217 /* Implementation of `sdata' variable. */
4219 static const struct internalvar_funcs sdata_funcs =
4226 /* module initialization */
4228 _initialize_tracepoint (void)
4230 struct cmd_list_element *c;
4232 /* Explicitly create without lookup, since that tries to create a
4233 value with a void typed value, and when we get here, gdbarch
4234 isn't initialized yet. At this point, we're quite sure there
4235 isn't another convenience variable of the same name. */
4236 create_internalvar_type_lazy ("_sdata", &sdata_funcs, NULL);
4238 traceframe_number = -1;
4239 tracepoint_number = -1;
4241 add_info ("scope", scope_info,
4242 _("List the variables local to a scope"));
4244 add_cmd ("tracepoints", class_trace, NULL,
4245 _("Tracing of program execution without stopping the program."),
4248 add_com ("tdump", class_trace, tdump_command,
4249 _("Print everything collected at the current tracepoint."));
4251 c = add_com ("tvariable", class_trace, trace_variable_command,_("\
4252 Define a trace state variable.\n\
4253 Argument is a $-prefixed name, optionally followed\n\
4254 by '=' and an expression that sets the initial value\n\
4255 at the start of tracing."));
4256 set_cmd_completer (c, expression_completer);
4258 add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\
4259 Delete one or more trace state variables.\n\
4260 Arguments are the names of the variables to delete.\n\
4261 If no arguments are supplied, delete all variables."), &deletelist);
4262 /* FIXME add a trace variable completer. */
4264 add_info ("tvariables", tvariables_info, _("\
4265 Status of trace state variables and their values.\n\
4268 add_info ("static-tracepoint-markers",
4269 info_static_tracepoint_markers_command, _("\
4270 List target static tracepoints markers.\n\
4273 add_prefix_cmd ("tfind", class_trace, tfind_command, _("\
4274 Select a trace frame;\n\
4275 No argument means forward by one frame; '-' means backward by one frame."),
4276 &tfindlist, "tfind ", 1, &cmdlist);
4278 add_cmd ("outside", class_trace, tfind_outside_command, _("\
4279 Select a trace frame whose PC is outside the given range (exclusive).\n\
4280 Usage: tfind outside addr1, addr2"),
4283 add_cmd ("range", class_trace, tfind_range_command, _("\
4284 Select a trace frame whose PC is in the given range (inclusive).\n\
4285 Usage: tfind range addr1,addr2"),
4288 add_cmd ("line", class_trace, tfind_line_command, _("\
4289 Select a trace frame by source line.\n\
4290 Argument can be a line number (with optional source file),\n\
4291 a function name, or '*' followed by an address.\n\
4292 Default argument is 'the next source line that was traced'."),
4295 add_cmd ("tracepoint", class_trace, tfind_tracepoint_command, _("\
4296 Select a trace frame by tracepoint number.\n\
4297 Default is the tracepoint for the current trace frame."),
4300 add_cmd ("pc", class_trace, tfind_pc_command, _("\
4301 Select a trace frame by PC.\n\
4302 Default is the current PC, or the PC of the current trace frame."),
4305 add_cmd ("end", class_trace, tfind_end_command, _("\
4306 De-select any trace frame and resume 'live' debugging."),
4309 add_alias_cmd ("none", "end", class_trace, 0, &tfindlist);
4311 add_cmd ("start", class_trace, tfind_start_command,
4312 _("Select the first trace frame in the trace buffer."),
4315 add_com ("tstatus", class_trace, tstatus_command,
4316 _("Display the status of the current trace data collection."));
4318 add_com ("tstop", class_trace, tstop_command, _("\
4319 Stop trace data collection.\n\
4320 Usage: tstop [ <notes> ... ]\n\
4321 Any arguments supplied are recorded with the trace as a stop reason and\n\
4322 reported by tstatus (if the target supports trace notes)."));
4324 add_com ("tstart", class_trace, tstart_command, _("\
4325 Start trace data collection.\n\
4326 Usage: tstart [ <notes> ... ]\n\
4327 Any arguments supplied are recorded with the trace as a note and\n\
4328 reported by tstatus (if the target supports trace notes)."));
4330 add_com ("end", class_trace, end_actions_pseudocommand, _("\
4331 Ends a list of commands or actions.\n\
4332 Several GDB commands allow you to enter a list of commands or actions.\n\
4333 Entering \"end\" on a line by itself is the normal way to terminate\n\
4335 Note: the \"end\" command cannot be used at the gdb prompt."));
4337 add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\
4338 Specify single-stepping behavior at a tracepoint.\n\
4339 Argument is number of instructions to trace in single-step mode\n\
4340 following the tracepoint. This command is normally followed by\n\
4341 one or more \"collect\" commands, to specify what to collect\n\
4342 while single-stepping.\n\n\
4343 Note: this command can only be used in a tracepoint \"actions\" list."));
4345 add_com_alias ("ws", "while-stepping", class_alias, 0);
4346 add_com_alias ("stepping", "while-stepping", class_alias, 0);
4348 add_com ("collect", class_trace, collect_pseudocommand, _("\
4349 Specify one or more data items to be collected at a tracepoint.\n\
4350 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4351 collect all data (variables, registers) referenced by that expression.\n\
4352 Also accepts the following special arguments:\n\
4353 $regs -- all registers.\n\
4354 $args -- all function arguments.\n\
4355 $locals -- all variables local to the block/function scope.\n\
4356 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
4357 Note: this command can only be used in a tracepoint \"actions\" list."));
4359 add_com ("teval", class_trace, teval_pseudocommand, _("\
4360 Specify one or more expressions to be evaluated at a tracepoint.\n\
4361 Accepts a comma-separated list of (one or more) expressions.\n\
4362 The result of each evaluation will be discarded.\n\
4363 Note: this command can only be used in a tracepoint \"actions\" list."));
4365 add_com ("actions", class_trace, actions_command, _("\
4366 Specify the actions to be taken at a tracepoint.\n\
4367 Tracepoint actions may include collecting of specified data,\n\
4368 single-stepping, or enabling/disabling other tracepoints,\n\
4369 depending on target's capabilities."));
4371 default_collect = xstrdup ("");
4372 add_setshow_string_cmd ("default-collect", class_trace,
4373 &default_collect, _("\
4374 Set the list of expressions to collect by default"), _("\
4375 Show the list of expressions to collect by default"), NULL,
4377 &setlist, &showlist);
4379 add_setshow_boolean_cmd ("disconnected-tracing", no_class,
4380 &disconnected_tracing, _("\
4381 Set whether tracing continues after GDB disconnects."), _("\
4382 Show whether tracing continues after GDB disconnects."), _("\
4383 Use this to continue a tracing run even if GDB disconnects\n\
4384 or detaches from the target. You can reconnect later and look at\n\
4385 trace data collected in the meantime."),
4386 set_disconnected_tracing,
4391 add_setshow_boolean_cmd ("circular-trace-buffer", no_class,
4392 &circular_trace_buffer, _("\
4393 Set target's use of circular trace buffer."), _("\
4394 Show target's use of circular trace buffer."), _("\
4395 Use this to make the trace buffer into a circular buffer,\n\
4396 which will discard traceframes (oldest first) instead of filling\n\
4397 up and stopping the trace run."),
4398 set_circular_trace_buffer,
4403 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class,
4404 &trace_buffer_size, _("\
4405 Set requested size of trace buffer."), _("\
4406 Show requested size of trace buffer."), _("\
4407 Use this to choose a size for the trace buffer. Some targets\n\
4408 may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
4409 disables any attempt to set the buffer size and lets the target choose."),
4410 set_trace_buffer_size, NULL,
4411 &setlist, &showlist);
4413 add_setshow_string_cmd ("trace-user", class_trace,
4415 Set the user name to use for current and future trace runs"), _("\
4416 Show the user name to use for current and future trace runs"), NULL,
4417 set_trace_user, NULL,
4418 &setlist, &showlist);
4420 add_setshow_string_cmd ("trace-notes", class_trace,
4422 Set notes string to use for current and future trace runs"), _("\
4423 Show the notes string to use for current and future trace runs"), NULL,
4424 set_trace_notes, NULL,
4425 &setlist, &showlist);
4427 add_setshow_string_cmd ("trace-stop-notes", class_trace,
4428 &trace_stop_notes, _("\
4429 Set notes string to use for future tstop commands"), _("\
4430 Show the notes string to use for future tstop commands"), NULL,
4431 set_trace_stop_notes, NULL,
4432 &setlist, &showlist);