1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997-2013 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"
30 #include "gdb_string.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"
53 #include "exceptions.h"
54 #include "cli/cli-utils.h"
57 /* readline include files */
58 #include "readline/readline.h"
59 #include "readline/history.h"
61 /* readline defines this. */
72 /* Maximum length of an agent aexpression.
73 This accounts for the fact that packets are limited to 400 bytes
74 (which includes everything -- including the checksum), and assumes
75 the worst case of maximum length for each of the pieces of a
78 NOTE: expressions get mem2hex'ed otherwise this would be twice as
79 large. (400 - 31)/2 == 184 */
80 #define MAX_AGENT_EXPR_LEN 184
84 /* A hook used to notify the UI of tracepoint operations. */
86 void (*deprecated_trace_find_hook) (char *arg, int from_tty);
87 void (*deprecated_trace_start_stop_hook) (int start, int from_tty);
89 extern void (*deprecated_readline_begin_hook) (char *, ...);
90 extern char *(*deprecated_readline_hook) (char *);
91 extern void (*deprecated_readline_end_hook) (void);
96 This module defines the following debugger commands:
97 trace : set a tracepoint on a function, line, or address.
98 info trace : list all debugger-defined tracepoints.
99 delete trace : delete one or more tracepoints.
100 enable trace : enable one or more tracepoints.
101 disable trace : disable one or more tracepoints.
102 actions : specify actions to be taken at a tracepoint.
103 passcount : specify a pass count for a tracepoint.
104 tstart : start a trace experiment.
105 tstop : stop a trace experiment.
106 tstatus : query the status of a trace experiment.
107 tfind : find a trace frame in the trace buffer.
108 tdump : print everything collected at the current tracepoint.
109 save-tracepoints : write tracepoint setup into a file.
111 This module defines the following user-visible debugger variables:
112 $trace_frame : sequence number of trace frame currently being debugged.
113 $trace_line : source line of trace frame currently being debugged.
114 $trace_file : source file of trace frame currently being debugged.
115 $tracepoint : tracepoint number of trace frame currently being debugged.
119 /* ======= Important global variables: ======= */
121 /* The list of all trace state variables. We don't retain pointers to
122 any of these for any reason - API is by name or number only - so it
123 works to have a vector of objects. */
125 typedef struct trace_state_variable tsv_s;
128 /* An object describing the contents of a traceframe. */
130 struct traceframe_info
132 /* Collected memory. */
133 VEC(mem_range_s) *memory;
136 static VEC(tsv_s) *tvariables;
138 /* The next integer to assign to a variable. */
140 static int next_tsv_number = 1;
142 /* Number of last traceframe collected. */
143 static int traceframe_number;
145 /* Tracepoint for last traceframe collected. */
146 static int tracepoint_number;
148 /* Symbol for function for last traceframe collected. */
149 static struct symbol *traceframe_fun;
151 /* Symtab and line for last traceframe collected. */
152 static struct symtab_and_line traceframe_sal;
154 /* The traceframe info of the current traceframe. NULL if we haven't
155 yet attempted to fetch it, or if the target does not support
156 fetching this object, or if we're not inspecting a traceframe
158 static struct traceframe_info *traceframe_info;
160 /* Tracing command lists. */
161 static struct cmd_list_element *tfindlist;
163 /* List of expressions to collect by default at each tracepoint hit. */
164 char *default_collect = "";
166 static int disconnected_tracing;
168 /* This variable controls whether we ask the target for a linear or
169 circular trace buffer. */
171 static int circular_trace_buffer;
173 /* This variable is the requested trace buffer size, or -1 to indicate
174 that we don't care and leave it up to the target to set a size. */
176 static int trace_buffer_size = -1;
178 /* Textual notes applying to the current and/or future trace runs. */
180 char *trace_user = NULL;
182 /* Textual notes applying to the current and/or future trace runs. */
184 char *trace_notes = NULL;
186 /* Textual notes applying to the stopping of a trace. */
188 char *trace_stop_notes = NULL;
190 /* ======= Important command functions: ======= */
191 static void trace_actions_command (char *, int);
192 static void trace_start_command (char *, int);
193 static void trace_stop_command (char *, int);
194 static void trace_status_command (char *, int);
195 static void trace_find_command (char *, int);
196 static void trace_find_pc_command (char *, int);
197 static void trace_find_tracepoint_command (char *, int);
198 static void trace_find_line_command (char *, int);
199 static void trace_find_range_command (char *, int);
200 static void trace_find_outside_command (char *, int);
201 static void trace_dump_command (char *, int);
203 /* support routines */
205 struct collection_list;
206 static void add_aexpr (struct collection_list *, struct agent_expr *);
207 static char *mem2hex (gdb_byte *, char *, int);
208 static void add_register (struct collection_list *collection,
211 static void free_uploaded_tps (struct uploaded_tp **utpp);
212 static void free_uploaded_tsvs (struct uploaded_tsv **utsvp);
215 extern void _initialize_tracepoint (void);
217 static struct trace_status trace_status;
219 char *stop_reason_names[] = {
229 struct trace_status *
230 current_trace_status (void)
232 return &trace_status;
238 free_traceframe_info (struct traceframe_info *info)
242 VEC_free (mem_range_s, info->memory);
248 /* Free and clear the traceframe info cache of the current
252 clear_traceframe_info (void)
254 free_traceframe_info (traceframe_info);
255 traceframe_info = NULL;
258 /* Set traceframe number to NUM. */
260 set_traceframe_num (int num)
262 traceframe_number = num;
263 set_internalvar_integer (lookup_internalvar ("trace_frame"), num);
266 /* Set tracepoint number to NUM. */
268 set_tracepoint_num (int num)
270 tracepoint_number = num;
271 set_internalvar_integer (lookup_internalvar ("tracepoint"), num);
274 /* Set externally visible debug variables for querying/printing
275 the traceframe context (line, function, file). */
278 set_traceframe_context (struct frame_info *trace_frame)
282 /* Save as globals for internal use. */
283 if (trace_frame != NULL
284 && get_frame_pc_if_available (trace_frame, &trace_pc))
286 traceframe_sal = find_pc_line (trace_pc, 0);
287 traceframe_fun = find_pc_function (trace_pc);
289 /* Save linenumber as "$trace_line", a debugger variable visible to
291 set_internalvar_integer (lookup_internalvar ("trace_line"),
292 traceframe_sal.line);
296 init_sal (&traceframe_sal);
297 traceframe_fun = NULL;
298 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
301 /* Save func name as "$trace_func", a debugger variable visible to
303 if (traceframe_fun == NULL
304 || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
305 clear_internalvar (lookup_internalvar ("trace_func"));
307 set_internalvar_string (lookup_internalvar ("trace_func"),
308 SYMBOL_LINKAGE_NAME (traceframe_fun));
310 /* Save file name as "$trace_file", a debugger variable visible to
312 if (traceframe_sal.symtab == NULL)
313 clear_internalvar (lookup_internalvar ("trace_file"));
315 set_internalvar_string (lookup_internalvar ("trace_file"),
316 symtab_to_filename_for_display (traceframe_sal.symtab));
319 /* Create a new trace state variable with the given name. */
321 struct trace_state_variable *
322 create_trace_state_variable (const char *name)
324 struct trace_state_variable tsv;
326 memset (&tsv, 0, sizeof (tsv));
327 tsv.name = xstrdup (name);
328 tsv.number = next_tsv_number++;
329 return VEC_safe_push (tsv_s, tvariables, &tsv);
332 /* Look for a trace state variable of the given name. */
334 struct trace_state_variable *
335 find_trace_state_variable (const char *name)
337 struct trace_state_variable *tsv;
340 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
341 if (strcmp (name, tsv->name) == 0)
348 delete_trace_state_variable (const char *name)
350 struct trace_state_variable *tsv;
353 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
354 if (strcmp (name, tsv->name) == 0)
356 observer_notify_tsv_deleted (tsv);
358 xfree ((void *)tsv->name);
359 VEC_unordered_remove (tsv_s, tvariables, ix);
364 warning (_("No trace variable named \"$%s\", not deleting"), name);
367 /* Throws an error if NAME is not valid syntax for a trace state
371 validate_trace_state_variable_name (const char *name)
376 error (_("Must supply a non-empty variable name"));
378 /* All digits in the name is reserved for value history
380 for (p = name; isdigit (*p); p++)
383 error (_("$%s is not a valid trace state variable name"), name);
385 for (p = name; isalnum (*p) || *p == '_'; p++)
388 error (_("$%s is not a valid trace state variable name"), name);
391 /* The 'tvariable' command collects a name and optional expression to
392 evaluate into an initial value. */
395 trace_variable_command (char *args, int from_tty)
397 struct cleanup *old_chain;
399 struct trace_state_variable *tsv;
403 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
405 /* Only allow two syntaxes; "$name" and "$name=value". */
406 p = skip_spaces (args);
409 error (_("Name of trace variable should start with '$'"));
412 while (isalnum (*p) || *p == '_')
414 name = savestring (name, p - name);
415 old_chain = make_cleanup (xfree, name);
418 if (*p != '=' && *p != '\0')
419 error (_("Syntax must be $NAME [ = EXPR ]"));
421 validate_trace_state_variable_name (name);
424 initval = value_as_long (parse_and_eval (++p));
426 /* If the variable already exists, just change its initial value. */
427 tsv = find_trace_state_variable (name);
430 if (tsv->initial_value != initval)
432 tsv->initial_value = initval;
433 observer_notify_tsv_modified (tsv);
435 printf_filtered (_("Trace state variable $%s "
436 "now has initial value %s.\n"),
437 tsv->name, plongest (tsv->initial_value));
438 do_cleanups (old_chain);
442 /* Create a new variable. */
443 tsv = create_trace_state_variable (name);
444 tsv->initial_value = initval;
446 observer_notify_tsv_created (tsv);
448 printf_filtered (_("Trace state variable $%s "
449 "created, with initial value %s.\n"),
450 tsv->name, plongest (tsv->initial_value));
452 do_cleanups (old_chain);
456 delete_trace_variable_command (char *args, int from_tty)
460 struct cleanup *back_to;
464 if (query (_("Delete all trace state variables? ")))
465 VEC_free (tsv_s, tvariables);
467 observer_notify_tsv_deleted (NULL);
471 argv = gdb_buildargv (args);
472 back_to = make_cleanup_freeargv (argv);
474 for (ix = 0; argv[ix] != NULL; ix++)
476 if (*argv[ix] == '$')
477 delete_trace_state_variable (argv[ix] + 1);
479 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv[ix]);
482 do_cleanups (back_to);
488 tvariables_info_1 (void)
490 struct trace_state_variable *tsv;
493 struct cleanup *back_to;
494 struct ui_out *uiout = current_uiout;
496 if (VEC_length (tsv_s, tvariables) == 0 && !ui_out_is_mi_like_p (uiout))
498 printf_filtered (_("No trace state variables.\n"));
502 /* Try to acquire values from the target. */
503 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix, ++count)
504 tsv->value_known = target_get_trace_state_variable_value (tsv->number,
507 back_to = make_cleanup_ui_out_table_begin_end (uiout, 3,
508 count, "trace-variables");
509 ui_out_table_header (uiout, 15, ui_left, "name", "Name");
510 ui_out_table_header (uiout, 11, ui_left, "initial", "Initial");
511 ui_out_table_header (uiout, 11, ui_left, "current", "Current");
513 ui_out_table_body (uiout);
515 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
517 struct cleanup *back_to2;
521 back_to2 = make_cleanup_ui_out_tuple_begin_end (uiout, "variable");
523 name = concat ("$", tsv->name, (char *) NULL);
524 make_cleanup (xfree, name);
525 ui_out_field_string (uiout, "name", name);
526 ui_out_field_string (uiout, "initial", plongest (tsv->initial_value));
528 if (tsv->value_known)
529 c = plongest (tsv->value);
530 else if (ui_out_is_mi_like_p (uiout))
531 /* For MI, we prefer not to use magic string constants, but rather
532 omit the field completely. The difference between unknown and
533 undefined does not seem important enough to represent. */
535 else if (current_trace_status ()->running || traceframe_number >= 0)
536 /* The value is/was defined, but we don't have it. */
539 /* It is not meaningful to ask about the value. */
542 ui_out_field_string (uiout, "current", c);
543 ui_out_text (uiout, "\n");
545 do_cleanups (back_to2);
548 do_cleanups (back_to);
551 /* List all the trace state variables. */
554 tvariables_info (char *args, int from_tty)
556 tvariables_info_1 ();
559 /* Stash definitions of tsvs into the given file. */
562 save_trace_state_variables (struct ui_file *fp)
564 struct trace_state_variable *tsv;
567 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
569 fprintf_unfiltered (fp, "tvariable $%s", tsv->name);
570 if (tsv->initial_value)
571 fprintf_unfiltered (fp, " = %s", plongest (tsv->initial_value));
572 fprintf_unfiltered (fp, "\n");
576 /* ACTIONS functions: */
578 /* The three functions:
579 collect_pseudocommand,
580 while_stepping_pseudocommand, and
581 end_actions_pseudocommand
582 are placeholders for "commands" that are actually ONLY to be used
583 within a tracepoint action list. If the actual function is ever called,
584 it means that somebody issued the "command" at the top level,
585 which is always an error. */
588 end_actions_pseudocommand (char *args, int from_tty)
590 error (_("This command cannot be used at the top level."));
594 while_stepping_pseudocommand (char *args, int from_tty)
596 error (_("This command can only be used in a tracepoint actions list."));
600 collect_pseudocommand (char *args, int from_tty)
602 error (_("This command can only be used in a tracepoint actions list."));
606 teval_pseudocommand (char *args, int from_tty)
608 error (_("This command can only be used in a tracepoint actions list."));
611 /* Parse any collection options, such as /s for strings. */
614 decode_agent_options (char *exp)
616 struct value_print_options opts;
621 /* Call this to borrow the print elements default for collection
623 get_user_print_options (&opts);
628 if (target_supports_string_tracing ())
630 /* Allow an optional decimal number giving an explicit maximum
631 string length, defaulting it to the "print elements" value;
632 so "collect/s80 mystr" gets at most 80 bytes of string. */
633 trace_string_kludge = opts.print_max;
635 if (*exp >= '0' && *exp <= '9')
636 trace_string_kludge = atoi (exp);
637 while (*exp >= '0' && *exp <= '9')
641 error (_("Target does not support \"/s\" option for string tracing."));
644 error (_("Undefined collection format \"%c\"."), *exp);
646 exp = skip_spaces (exp);
651 /* Enter a list of actions for a tracepoint. */
653 trace_actions_command (char *args, int from_tty)
655 struct tracepoint *t;
656 struct command_line *l;
658 t = get_tracepoint_by_number (&args, NULL, 1);
662 xstrprintf ("Enter actions for tracepoint %d, one per line.",
664 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
666 l = read_command_lines (tmpbuf, from_tty, 1,
667 check_tracepoint_command, t);
668 do_cleanups (cleanups);
669 breakpoint_set_commands (&t->base, l);
671 /* else just return */
674 /* Report the results of checking the agent expression, as errors or
678 report_agent_reqs_errors (struct agent_expr *aexpr)
680 /* All of the "flaws" are serious bytecode generation issues that
681 should never occur. */
682 if (aexpr->flaw != agent_flaw_none)
683 internal_error (__FILE__, __LINE__, _("expression is malformed"));
685 /* If analysis shows a stack underflow, GDB must have done something
686 badly wrong in its bytecode generation. */
687 if (aexpr->min_height < 0)
688 internal_error (__FILE__, __LINE__,
689 _("expression has min height < 0"));
691 /* Issue this error if the stack is predicted to get too deep. The
692 limit is rather arbitrary; a better scheme might be for the
693 target to report how much stack it will have available. The
694 depth roughly corresponds to parenthesization, so a limit of 20
695 amounts to 20 levels of expression nesting, which is actually
696 a pretty big hairy expression. */
697 if (aexpr->max_height > 20)
698 error (_("Expression is too complicated."));
701 /* worker function */
703 validate_actionline (char **line, struct breakpoint *b)
705 struct cmd_list_element *c;
706 struct expression *exp = NULL;
707 struct cleanup *old_chain = NULL;
709 struct bp_location *loc;
710 struct agent_expr *aexpr;
711 struct tracepoint *t = (struct tracepoint *) b;
713 /* If EOF is typed, *line is NULL. */
717 p = skip_spaces (*line);
719 /* Symbol lookup etc. */
720 if (*p == '\0') /* empty line: just prompt for another line. */
723 if (*p == '#') /* comment line */
726 c = lookup_cmd (&p, cmdlist, "", -1, 1);
728 error (_("`%s' is not a tracepoint action, or is ambiguous."), p);
730 if (cmd_cfunc_eq (c, collect_pseudocommand))
732 trace_string_kludge = 0;
734 p = decode_agent_options (p);
737 { /* Repeat over a comma-separated list. */
738 QUIT; /* Allow user to bail out with ^C. */
741 if (*p == '$') /* Look for special pseudo-symbols. */
743 if (0 == strncasecmp ("reg", p + 1, 3)
744 || 0 == strncasecmp ("arg", p + 1, 3)
745 || 0 == strncasecmp ("loc", p + 1, 3)
746 || 0 == strncasecmp ("_ret", p + 1, 4)
747 || 0 == strncasecmp ("_sdata", p + 1, 6))
752 /* else fall thru, treat p as an expression and parse it! */
755 for (loc = t->base.loc; loc; loc = loc->next)
758 exp = parse_exp_1 (&p, loc->address,
759 block_for_pc (loc->address), 1);
760 old_chain = make_cleanup (free_current_contents, &exp);
762 if (exp->elts[0].opcode == OP_VAR_VALUE)
764 if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
766 error (_("constant `%s' (value %s) "
767 "will not be collected."),
768 SYMBOL_PRINT_NAME (exp->elts[2].symbol),
769 plongest (SYMBOL_VALUE (exp->elts[2].symbol)));
771 else if (SYMBOL_CLASS (exp->elts[2].symbol)
772 == LOC_OPTIMIZED_OUT)
774 error (_("`%s' is optimized away "
775 "and cannot be collected."),
776 SYMBOL_PRINT_NAME (exp->elts[2].symbol));
780 /* We have something to collect, make sure that the expr to
781 bytecode translator can handle it and that it's not too
783 aexpr = gen_trace_for_expr (loc->address, exp);
784 make_cleanup_free_agent_expr (aexpr);
786 if (aexpr->len > MAX_AGENT_EXPR_LEN)
787 error (_("Expression is too complicated."));
791 report_agent_reqs_errors (aexpr);
793 do_cleanups (old_chain);
796 while (p && *p++ == ',');
799 else if (cmd_cfunc_eq (c, teval_pseudocommand))
802 { /* Repeat over a comma-separated list. */
803 QUIT; /* Allow user to bail out with ^C. */
807 for (loc = t->base.loc; loc; loc = loc->next)
810 /* Only expressions are allowed for this action. */
811 exp = parse_exp_1 (&p, loc->address,
812 block_for_pc (loc->address), 1);
813 old_chain = make_cleanup (free_current_contents, &exp);
815 /* We have something to evaluate, make sure that the expr to
816 bytecode translator can handle it and that it's not too
818 aexpr = gen_eval_for_expr (loc->address, exp);
819 make_cleanup_free_agent_expr (aexpr);
821 if (aexpr->len > MAX_AGENT_EXPR_LEN)
822 error (_("Expression is too complicated."));
825 report_agent_reqs_errors (aexpr);
827 do_cleanups (old_chain);
830 while (p && *p++ == ',');
833 else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
835 char *steparg; /* In case warning is necessary. */
840 if (*p == '\0' || (t->step_count = strtol (p, &p, 0)) == 0)
841 error (_("while-stepping step count `%s' is malformed."), *line);
844 else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
848 error (_("`%s' is not a supported tracepoint action."), *line);
852 memrange_absolute = -1
857 int type; /* memrange_absolute for absolute memory range,
858 else basereg number. */
859 bfd_signed_vma start;
863 struct collection_list
865 unsigned char regs_mask[32]; /* room for up to 256 regs */
868 struct memrange *list;
869 long aexpr_listsize; /* size of array pointed to by expr_list elt */
871 struct agent_expr **aexpr_list;
873 /* True is the user requested a collection of "$_sdata", "static
877 tracepoint_list, stepping_list;
879 /* MEMRANGE functions: */
881 static int memrange_cmp (const void *, const void *);
883 /* Compare memranges for qsort. */
885 memrange_cmp (const void *va, const void *vb)
887 const struct memrange *a = va, *b = vb;
889 if (a->type < b->type)
891 if (a->type > b->type)
893 if (a->type == memrange_absolute)
895 if ((bfd_vma) a->start < (bfd_vma) b->start)
897 if ((bfd_vma) a->start > (bfd_vma) b->start)
902 if (a->start < b->start)
904 if (a->start > b->start)
910 /* Sort the memrange list using qsort, and merge adjacent memranges. */
912 memrange_sortmerge (struct collection_list *memranges)
916 qsort (memranges->list, memranges->next_memrange,
917 sizeof (struct memrange), memrange_cmp);
918 if (memranges->next_memrange > 0)
920 for (a = 0, b = 1; b < memranges->next_memrange; b++)
922 /* If memrange b overlaps or is adjacent to memrange a,
924 if (memranges->list[a].type == memranges->list[b].type
925 && memranges->list[b].start <= memranges->list[a].end)
927 if (memranges->list[b].end > memranges->list[a].end)
928 memranges->list[a].end = memranges->list[b].end;
929 continue; /* next b, same a */
933 memcpy (&memranges->list[a], &memranges->list[b],
934 sizeof (struct memrange));
936 memranges->next_memrange = a + 1;
940 /* Add a register to a collection list. */
942 add_register (struct collection_list *collection, unsigned int regno)
945 printf_filtered ("collect register %d\n", regno);
946 if (regno >= (8 * sizeof (collection->regs_mask)))
947 error (_("Internal: register number %d too large for tracepoint"),
949 collection->regs_mask[regno / 8] |= 1 << (regno % 8);
952 /* Add a memrange to a collection list. */
954 add_memrange (struct collection_list *memranges,
955 int type, bfd_signed_vma base,
960 printf_filtered ("(%d,", type);
962 printf_filtered (",%ld)\n", len);
965 /* type: memrange_absolute == memory, other n == basereg */
966 memranges->list[memranges->next_memrange].type = type;
967 /* base: addr if memory, offset if reg relative. */
968 memranges->list[memranges->next_memrange].start = base;
969 /* len: we actually save end (base + len) for convenience */
970 memranges->list[memranges->next_memrange].end = base + len;
971 memranges->next_memrange++;
972 if (memranges->next_memrange >= memranges->listsize)
974 memranges->listsize *= 2;
975 memranges->list = xrealloc (memranges->list,
976 memranges->listsize);
979 if (type != memrange_absolute) /* Better collect the base register! */
980 add_register (memranges, type);
983 /* Add a symbol to a collection list. */
985 collect_symbol (struct collection_list *collect,
987 struct gdbarch *gdbarch,
988 long frame_regno, long frame_offset,
993 bfd_signed_vma offset;
994 int treat_as_expr = 0;
996 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
997 switch (SYMBOL_CLASS (sym))
1000 printf_filtered ("%s: don't know symbol class %d\n",
1001 SYMBOL_PRINT_NAME (sym),
1002 SYMBOL_CLASS (sym));
1005 printf_filtered ("constant %s (value %s) will not be collected.\n",
1006 SYMBOL_PRINT_NAME (sym), plongest (SYMBOL_VALUE (sym)));
1009 offset = SYMBOL_VALUE_ADDRESS (sym);
1014 sprintf_vma (tmp, offset);
1015 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1016 SYMBOL_PRINT_NAME (sym), len,
1019 /* A struct may be a C++ class with static fields, go to general
1020 expression handling. */
1021 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
1024 add_memrange (collect, memrange_absolute, offset, len);
1027 reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1029 printf_filtered ("LOC_REG[parm] %s: ",
1030 SYMBOL_PRINT_NAME (sym));
1031 add_register (collect, reg);
1032 /* Check for doubles stored in two registers. */
1033 /* FIXME: how about larger types stored in 3 or more regs? */
1034 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
1035 len > register_size (gdbarch, reg))
1036 add_register (collect, reg + 1);
1039 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1040 printf_filtered (" (will not collect %s)\n",
1041 SYMBOL_PRINT_NAME (sym));
1045 offset = frame_offset + SYMBOL_VALUE (sym);
1048 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1049 SYMBOL_PRINT_NAME (sym), len);
1050 printf_vma (offset);
1051 printf_filtered (" from frame ptr reg %d\n", reg);
1053 add_memrange (collect, reg, offset, len);
1055 case LOC_REGPARM_ADDR:
1056 reg = SYMBOL_VALUE (sym);
1060 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1061 SYMBOL_PRINT_NAME (sym), len);
1062 printf_vma (offset);
1063 printf_filtered (" from reg %d\n", reg);
1065 add_memrange (collect, reg, offset, len);
1069 offset = frame_offset + SYMBOL_VALUE (sym);
1072 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1073 SYMBOL_PRINT_NAME (sym), len);
1074 printf_vma (offset);
1075 printf_filtered (" from frame ptr reg %d\n", reg);
1077 add_memrange (collect, reg, offset, len);
1080 case LOC_UNRESOLVED:
1084 case LOC_OPTIMIZED_OUT:
1085 printf_filtered ("%s has been optimized out of existence.\n",
1086 SYMBOL_PRINT_NAME (sym));
1094 /* Expressions are the most general case. */
1097 struct agent_expr *aexpr;
1098 struct cleanup *old_chain1 = NULL;
1100 aexpr = gen_trace_for_var (scope, gdbarch, sym);
1102 /* It can happen that the symbol is recorded as a computed
1103 location, but it's been optimized away and doesn't actually
1104 have a location expression. */
1107 printf_filtered ("%s has been optimized out of existence.\n",
1108 SYMBOL_PRINT_NAME (sym));
1112 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1116 report_agent_reqs_errors (aexpr);
1118 discard_cleanups (old_chain1);
1119 add_aexpr (collect, aexpr);
1121 /* Take care of the registers. */
1122 if (aexpr->reg_mask_len > 0)
1126 for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1128 QUIT; /* Allow user to bail out with ^C. */
1129 if (aexpr->reg_mask[ndx1] != 0)
1131 /* Assume chars have 8 bits. */
1132 for (ndx2 = 0; ndx2 < 8; ndx2++)
1133 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1134 /* It's used -- record it. */
1135 add_register (collect, ndx1 * 8 + ndx2);
1142 /* Data to be passed around in the calls to the locals and args
1145 struct add_local_symbols_data
1147 struct collection_list *collect;
1148 struct gdbarch *gdbarch;
1155 /* The callback for the locals and args iterators. */
1158 do_collect_symbol (const char *print_name,
1162 struct add_local_symbols_data *p = cb_data;
1164 collect_symbol (p->collect, sym, p->gdbarch, p->frame_regno,
1165 p->frame_offset, p->pc);
1169 /* Add all locals (or args) symbols to collection list. */
1171 add_local_symbols (struct collection_list *collect,
1172 struct gdbarch *gdbarch, CORE_ADDR pc,
1173 long frame_regno, long frame_offset, int type)
1175 struct block *block;
1176 struct add_local_symbols_data cb_data;
1178 cb_data.collect = collect;
1179 cb_data.gdbarch = gdbarch;
1181 cb_data.frame_regno = frame_regno;
1182 cb_data.frame_offset = frame_offset;
1187 block = block_for_pc (pc);
1190 warning (_("Can't collect locals; "
1191 "no symbol table info available.\n"));
1195 iterate_over_block_local_vars (block, do_collect_symbol, &cb_data);
1196 if (cb_data.count == 0)
1197 warning (_("No locals found in scope."));
1201 pc = get_pc_function_start (pc);
1202 block = block_for_pc (pc);
1205 warning (_("Can't collect args; no symbol table info available."));
1209 iterate_over_block_arg_vars (block, do_collect_symbol, &cb_data);
1210 if (cb_data.count == 0)
1211 warning (_("No args found in scope."));
1216 add_static_trace_data (struct collection_list *collection)
1219 printf_filtered ("collect static trace data\n");
1220 collection->strace_data = 1;
1223 /* worker function */
1225 clear_collection_list (struct collection_list *list)
1229 list->next_memrange = 0;
1230 for (ndx = 0; ndx < list->next_aexpr_elt; ndx++)
1232 free_agent_expr (list->aexpr_list[ndx]);
1233 list->aexpr_list[ndx] = NULL;
1235 list->next_aexpr_elt = 0;
1236 memset (list->regs_mask, 0, sizeof (list->regs_mask));
1237 list->strace_data = 0;
1240 /* Reduce a collection list to string form (for gdb protocol). */
1242 stringify_collection_list (struct collection_list *list, char *string)
1244 char temp_buf[2048];
1248 char *(*str_list)[];
1252 count = 1 + 1 + list->next_memrange + list->next_aexpr_elt + 1;
1253 str_list = (char *(*)[]) xmalloc (count * sizeof (char *));
1255 if (list->strace_data)
1258 printf_filtered ("\nCollecting static trace data\n");
1261 (*str_list)[ndx] = savestring (temp_buf, end - temp_buf);
1265 for (i = sizeof (list->regs_mask) - 1; i > 0; i--)
1266 if (list->regs_mask[i] != 0) /* Skip leading zeroes in regs_mask. */
1268 if (list->regs_mask[i] != 0) /* Prepare to send regs_mask to the stub. */
1271 printf_filtered ("\nCollecting registers (mask): 0x");
1276 QUIT; /* Allow user to bail out with ^C. */
1278 printf_filtered ("%02X", list->regs_mask[i]);
1279 sprintf (end, "%02X", list->regs_mask[i]);
1282 (*str_list)[ndx] = xstrdup (temp_buf);
1286 printf_filtered ("\n");
1287 if (list->next_memrange > 0 && info_verbose)
1288 printf_filtered ("Collecting memranges: \n");
1289 for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++)
1291 QUIT; /* Allow user to bail out with ^C. */
1292 sprintf_vma (tmp2, list->list[i].start);
1295 printf_filtered ("(%d, %s, %ld)\n",
1298 (long) (list->list[i].end - list->list[i].start));
1300 if (count + 27 > MAX_AGENT_EXPR_LEN)
1302 (*str_list)[ndx] = savestring (temp_buf, count);
1309 bfd_signed_vma length = list->list[i].end - list->list[i].start;
1311 /* The "%X" conversion specifier expects an unsigned argument,
1312 so passing -1 (memrange_absolute) to it directly gives you
1313 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1315 if (list->list[i].type == memrange_absolute)
1316 sprintf (end, "M-1,%s,%lX", tmp2, (long) length);
1318 sprintf (end, "M%X,%s,%lX", list->list[i].type, tmp2, (long) length);
1321 count += strlen (end);
1322 end = temp_buf + count;
1325 for (i = 0; i < list->next_aexpr_elt; i++)
1327 QUIT; /* Allow user to bail out with ^C. */
1328 if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN)
1330 (*str_list)[ndx] = savestring (temp_buf, count);
1335 sprintf (end, "X%08X,", list->aexpr_list[i]->len);
1336 end += 10; /* 'X' + 8 hex digits + ',' */
1339 end = mem2hex (list->aexpr_list[i]->buf,
1340 end, list->aexpr_list[i]->len);
1341 count += 2 * list->aexpr_list[i]->len;
1346 (*str_list)[ndx] = savestring (temp_buf, count);
1351 (*str_list)[ndx] = NULL;
1364 encode_actions_1 (struct command_line *action,
1365 struct breakpoint *t,
1366 struct bp_location *tloc,
1368 LONGEST frame_offset,
1369 struct collection_list *collect,
1370 struct collection_list *stepping_list)
1373 struct expression *exp = NULL;
1375 struct value *tempval;
1376 struct cmd_list_element *cmd;
1377 struct agent_expr *aexpr;
1379 for (; action; action = action->next)
1381 QUIT; /* Allow user to bail out with ^C. */
1382 action_exp = action->line;
1383 action_exp = skip_spaces (action_exp);
1385 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
1387 error (_("Bad action list item: %s"), action_exp);
1389 if (cmd_cfunc_eq (cmd, collect_pseudocommand))
1391 trace_string_kludge = 0;
1392 if (*action_exp == '/')
1393 action_exp = decode_agent_options (action_exp);
1396 { /* Repeat over a comma-separated list. */
1397 QUIT; /* Allow user to bail out with ^C. */
1398 action_exp = skip_spaces (action_exp);
1400 if (0 == strncasecmp ("$reg", action_exp, 4))
1402 for (i = 0; i < gdbarch_num_regs (tloc->gdbarch); i++)
1403 add_register (collect, i);
1404 action_exp = strchr (action_exp, ','); /* more? */
1406 else if (0 == strncasecmp ("$arg", action_exp, 4))
1408 add_local_symbols (collect,
1414 action_exp = strchr (action_exp, ','); /* more? */
1416 else if (0 == strncasecmp ("$loc", action_exp, 4))
1418 add_local_symbols (collect,
1424 action_exp = strchr (action_exp, ','); /* more? */
1426 else if (0 == strncasecmp ("$_ret", action_exp, 5))
1428 struct cleanup *old_chain1 = NULL;
1430 aexpr = gen_trace_for_return_address (tloc->address,
1433 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1436 report_agent_reqs_errors (aexpr);
1438 discard_cleanups (old_chain1);
1439 add_aexpr (collect, aexpr);
1441 /* take care of the registers */
1442 if (aexpr->reg_mask_len > 0)
1446 for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1448 QUIT; /* allow user to bail out with ^C */
1449 if (aexpr->reg_mask[ndx1] != 0)
1451 /* assume chars have 8 bits */
1452 for (ndx2 = 0; ndx2 < 8; ndx2++)
1453 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1454 /* it's used -- record it */
1455 add_register (collect,
1461 action_exp = strchr (action_exp, ','); /* more? */
1463 else if (0 == strncasecmp ("$_sdata", action_exp, 7))
1465 add_static_trace_data (collect);
1466 action_exp = strchr (action_exp, ','); /* more? */
1471 struct cleanup *old_chain = NULL;
1472 struct cleanup *old_chain1 = NULL;
1474 exp = parse_exp_1 (&action_exp, tloc->address,
1475 block_for_pc (tloc->address), 1);
1476 old_chain = make_cleanup (free_current_contents, &exp);
1478 switch (exp->elts[0].opcode)
1482 const char *name = &exp->elts[2].string;
1484 i = user_reg_map_name_to_regnum (tloc->gdbarch,
1485 name, strlen (name));
1487 internal_error (__FILE__, __LINE__,
1488 _("Register $%s not available"),
1491 printf_filtered ("OP_REGISTER: ");
1492 add_register (collect, i);
1497 /* Safe because we know it's a simple expression. */
1498 tempval = evaluate_expression (exp);
1499 addr = value_address (tempval);
1500 /* Initialize the TYPE_LENGTH if it is a typedef. */
1501 check_typedef (exp->elts[1].type);
1502 add_memrange (collect, memrange_absolute, addr,
1503 TYPE_LENGTH (exp->elts[1].type));
1507 collect_symbol (collect,
1508 exp->elts[2].symbol,
1515 default: /* Full-fledged expression. */
1516 aexpr = gen_trace_for_expr (tloc->address, exp);
1518 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1522 report_agent_reqs_errors (aexpr);
1524 discard_cleanups (old_chain1);
1525 add_aexpr (collect, aexpr);
1527 /* Take care of the registers. */
1528 if (aexpr->reg_mask_len > 0)
1533 for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1535 QUIT; /* Allow user to bail out with ^C. */
1536 if (aexpr->reg_mask[ndx1] != 0)
1538 /* Assume chars have 8 bits. */
1539 for (ndx2 = 0; ndx2 < 8; ndx2++)
1540 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1541 /* It's used -- record it. */
1542 add_register (collect,
1549 do_cleanups (old_chain);
1552 while (action_exp && *action_exp++ == ',');
1554 else if (cmd_cfunc_eq (cmd, teval_pseudocommand))
1557 { /* Repeat over a comma-separated list. */
1558 QUIT; /* Allow user to bail out with ^C. */
1559 action_exp = skip_spaces (action_exp);
1562 struct cleanup *old_chain = NULL;
1563 struct cleanup *old_chain1 = NULL;
1565 exp = parse_exp_1 (&action_exp, tloc->address,
1566 block_for_pc (tloc->address), 1);
1567 old_chain = make_cleanup (free_current_contents, &exp);
1569 aexpr = gen_eval_for_expr (tloc->address, exp);
1570 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1573 report_agent_reqs_errors (aexpr);
1575 discard_cleanups (old_chain1);
1576 /* Even though we're not officially collecting, add
1577 to the collect list anyway. */
1578 add_aexpr (collect, aexpr);
1580 do_cleanups (old_chain);
1583 while (action_exp && *action_exp++ == ',');
1585 else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
1587 /* We check against nested while-stepping when setting
1588 breakpoint action, so no way to run into nested
1590 gdb_assert (stepping_list);
1592 encode_actions_1 (action->body_list[0], t, tloc, frame_reg,
1593 frame_offset, stepping_list, NULL);
1596 error (_("Invalid tracepoint command '%s'"), action->line);
1600 /* Render all actions into gdb protocol. */
1603 encode_actions (struct breakpoint *t, struct bp_location *tloc,
1604 char ***tdp_actions, char ***stepping_actions)
1606 static char tdp_buff[2048], step_buff[2048];
1607 char *default_collect_line = NULL;
1608 struct command_line *actions;
1609 struct command_line *default_collect_action = NULL;
1611 LONGEST frame_offset;
1612 struct cleanup *back_to;
1614 back_to = make_cleanup (null_cleanup, NULL);
1616 clear_collection_list (&tracepoint_list);
1617 clear_collection_list (&stepping_list);
1619 *tdp_actions = NULL;
1620 *stepping_actions = NULL;
1622 gdbarch_virtual_frame_pointer (tloc->gdbarch,
1623 tloc->address, &frame_reg, &frame_offset);
1625 actions = breakpoint_commands (t);
1627 /* If there are default expressions to collect, make up a collect
1628 action and prepend to the action list to encode. Note that since
1629 validation is per-tracepoint (local var "xyz" might be valid for
1630 one tracepoint and not another, etc), we make up the action on
1631 the fly, and don't cache it. */
1632 if (*default_collect)
1636 default_collect_line = xstrprintf ("collect %s", default_collect);
1637 make_cleanup (xfree, default_collect_line);
1639 line = default_collect_line;
1640 validate_actionline (&line, t);
1642 default_collect_action = xmalloc (sizeof (struct command_line));
1643 make_cleanup (xfree, default_collect_action);
1644 default_collect_action->next = actions;
1645 default_collect_action->line = line;
1646 actions = default_collect_action;
1648 encode_actions_1 (actions, t, tloc, frame_reg, frame_offset,
1649 &tracepoint_list, &stepping_list);
1651 memrange_sortmerge (&tracepoint_list);
1652 memrange_sortmerge (&stepping_list);
1654 *tdp_actions = stringify_collection_list (&tracepoint_list,
1656 *stepping_actions = stringify_collection_list (&stepping_list,
1659 do_cleanups (back_to);
1663 add_aexpr (struct collection_list *collect, struct agent_expr *aexpr)
1665 if (collect->next_aexpr_elt >= collect->aexpr_listsize)
1667 collect->aexpr_list =
1668 xrealloc (collect->aexpr_list,
1669 2 * collect->aexpr_listsize * sizeof (struct agent_expr *));
1670 collect->aexpr_listsize *= 2;
1672 collect->aexpr_list[collect->next_aexpr_elt] = aexpr;
1673 collect->next_aexpr_elt++;
1677 process_tracepoint_on_disconnect (void)
1679 VEC(breakpoint_p) *tp_vec = NULL;
1681 struct breakpoint *b;
1682 int has_pending_p = 0;
1684 /* Check whether we still have pending tracepoint. If we have, warn the
1685 user that pending tracepoint will no longer work. */
1686 tp_vec = all_tracepoints ();
1687 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1696 struct bp_location *loc1;
1698 for (loc1 = b->loc; loc1; loc1 = loc1->next)
1700 if (loc1->shlib_disabled)
1711 VEC_free (breakpoint_p, tp_vec);
1714 warning (_("Pending tracepoints will not be resolved while"
1715 " GDB is disconnected\n"));
1720 start_tracing (char *notes)
1722 VEC(breakpoint_p) *tp_vec = NULL;
1724 struct breakpoint *b;
1725 struct trace_state_variable *tsv;
1726 int any_enabled = 0, num_to_download = 0;
1729 tp_vec = all_tracepoints ();
1731 /* No point in tracing without any tracepoints... */
1732 if (VEC_length (breakpoint_p, tp_vec) == 0)
1734 VEC_free (breakpoint_p, tp_vec);
1735 error (_("No tracepoints defined, not starting trace"));
1738 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1740 struct tracepoint *t = (struct tracepoint *) b;
1741 struct bp_location *loc;
1743 if (b->enable_state == bp_enabled)
1746 if ((b->type == bp_fast_tracepoint
1747 ? may_insert_fast_tracepoints
1748 : may_insert_tracepoints))
1751 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1752 (b->type == bp_fast_tracepoint ? "fast " : ""), b->number);
1757 if (target_supports_enable_disable_tracepoint ())
1758 warning (_("No tracepoints enabled"));
1761 /* No point in tracing with only disabled tracepoints that
1762 cannot be re-enabled. */
1763 VEC_free (breakpoint_p, tp_vec);
1764 error (_("No tracepoints enabled, not starting trace"));
1768 if (num_to_download <= 0)
1770 VEC_free (breakpoint_p, tp_vec);
1771 error (_("No tracepoints that may be downloaded, not starting trace"));
1774 target_trace_init ();
1776 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1778 struct tracepoint *t = (struct tracepoint *) b;
1779 struct bp_location *loc;
1780 int bp_location_downloaded = 0;
1782 /* Clear `inserted' flag. */
1783 for (loc = b->loc; loc; loc = loc->next)
1786 if ((b->type == bp_fast_tracepoint
1787 ? !may_insert_fast_tracepoints
1788 : !may_insert_tracepoints))
1791 t->number_on_target = 0;
1793 for (loc = b->loc; loc; loc = loc->next)
1795 /* Since tracepoint locations are never duplicated, `inserted'
1796 flag should be zero. */
1797 gdb_assert (!loc->inserted);
1799 target_download_tracepoint (loc);
1802 bp_location_downloaded = 1;
1805 t->number_on_target = b->number;
1807 for (loc = b->loc; loc; loc = loc->next)
1808 if (loc->probe != NULL)
1809 loc->probe->pops->set_semaphore (loc->probe, loc->gdbarch);
1811 if (bp_location_downloaded)
1812 observer_notify_breakpoint_modified (b);
1814 VEC_free (breakpoint_p, tp_vec);
1816 /* Send down all the trace state variables too. */
1817 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
1819 target_download_trace_state_variable (tsv);
1822 /* Tell target to treat text-like sections as transparent. */
1823 target_trace_set_readonly_regions ();
1824 /* Set some mode flags. */
1825 target_set_disconnected_tracing (disconnected_tracing);
1826 target_set_circular_trace_buffer (circular_trace_buffer);
1827 target_set_trace_buffer_size (trace_buffer_size);
1830 notes = trace_notes;
1831 ret = target_set_trace_notes (trace_user, notes, NULL);
1833 if (!ret && (trace_user || notes))
1834 warning (_("Target does not support trace user/notes, info ignored"));
1836 /* Now insert traps and begin collecting data. */
1837 target_trace_start ();
1839 /* Reset our local state. */
1840 set_traceframe_num (-1);
1841 set_tracepoint_num (-1);
1842 set_traceframe_context (NULL);
1843 current_trace_status()->running = 1;
1844 clear_traceframe_info ();
1847 /* The tstart command requests the target to start a new trace run.
1848 The command passes any arguments it has to the target verbatim, as
1849 an optional "trace note". This is useful as for instance a warning
1850 to other users if the trace runs disconnected, and you don't want
1851 anybody else messing with the target. */
1854 trace_start_command (char *args, int from_tty)
1856 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1858 if (current_trace_status ()->running)
1861 && !query (_("A trace is running already. Start a new run? ")))
1862 error (_("New trace run not started."));
1865 start_tracing (args);
1868 /* The tstop command stops the tracing run. The command passes any
1869 supplied arguments to the target verbatim as a "stop note"; if the
1870 target supports trace notes, then it will be reported back as part
1871 of the trace run's status. */
1874 trace_stop_command (char *args, int from_tty)
1876 if (!current_trace_status ()->running)
1877 error (_("Trace is not running."));
1879 stop_tracing (args);
1883 stop_tracing (char *note)
1886 VEC(breakpoint_p) *tp_vec = NULL;
1888 struct breakpoint *t;
1890 target_trace_stop ();
1892 tp_vec = all_tracepoints ();
1893 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
1895 struct bp_location *loc;
1897 if ((t->type == bp_fast_tracepoint
1898 ? !may_insert_fast_tracepoints
1899 : !may_insert_tracepoints))
1902 for (loc = t->loc; loc; loc = loc->next)
1904 /* GDB can be totally absent in some disconnected trace scenarios,
1905 but we don't really care if this semaphore goes out of sync.
1906 That's why we are decrementing it here, but not taking care
1908 if (loc->probe != NULL)
1909 loc->probe->pops->clear_semaphore (loc->probe, loc->gdbarch);
1913 VEC_free (breakpoint_p, tp_vec);
1916 note = trace_stop_notes;
1917 ret = target_set_trace_notes (NULL, NULL, note);
1920 warning (_("Target does not support trace notes, note ignored"));
1922 /* Should change in response to reply? */
1923 current_trace_status ()->running = 0;
1926 /* tstatus command */
1928 trace_status_command (char *args, int from_tty)
1930 struct trace_status *ts = current_trace_status ();
1932 VEC(breakpoint_p) *tp_vec = NULL;
1933 struct breakpoint *t;
1935 status = target_get_trace_status (ts);
1939 if (ts->filename != NULL)
1940 printf_filtered (_("Using a trace file.\n"));
1943 printf_filtered (_("Trace can not be run on this target.\n"));
1948 if (!ts->running_known)
1950 printf_filtered (_("Run/stop status is unknown.\n"));
1952 else if (ts->running)
1954 printf_filtered (_("Trace is running on the target.\n"));
1958 switch (ts->stop_reason)
1960 case trace_never_run:
1961 printf_filtered (_("No trace has been run on the target.\n"));
1965 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1968 printf_filtered (_("Trace stopped by a tstop command.\n"));
1970 case trace_buffer_full:
1971 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1973 case trace_disconnected:
1974 printf_filtered (_("Trace stopped because of disconnection.\n"));
1976 case tracepoint_passcount:
1977 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1978 ts->stopping_tracepoint);
1980 case tracepoint_error:
1981 if (ts->stopping_tracepoint)
1982 printf_filtered (_("Trace stopped by an "
1983 "error (%s, tracepoint %d).\n"),
1984 ts->stop_desc, ts->stopping_tracepoint);
1986 printf_filtered (_("Trace stopped by an error (%s).\n"),
1989 case trace_stop_reason_unknown:
1990 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1993 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1999 if (ts->traceframes_created >= 0
2000 && ts->traceframe_count != ts->traceframes_created)
2002 printf_filtered (_("Buffer contains %d trace "
2003 "frames (of %d created total).\n"),
2004 ts->traceframe_count, ts->traceframes_created);
2006 else if (ts->traceframe_count >= 0)
2008 printf_filtered (_("Collected %d trace frames.\n"),
2009 ts->traceframe_count);
2012 if (ts->buffer_free >= 0)
2014 if (ts->buffer_size >= 0)
2016 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
2017 ts->buffer_free, ts->buffer_size);
2018 if (ts->buffer_size > 0)
2019 printf_filtered (_(" (%d%% full)"),
2020 ((int) ((((long long) (ts->buffer_size
2021 - ts->buffer_free)) * 100)
2022 / ts->buffer_size)));
2023 printf_filtered (_(".\n"));
2026 printf_filtered (_("Trace buffer has %d bytes free.\n"),
2030 if (ts->disconnected_tracing)
2031 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
2033 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
2035 if (ts->circular_buffer)
2036 printf_filtered (_("Trace buffer is circular.\n"));
2038 if (ts->user_name && strlen (ts->user_name) > 0)
2039 printf_filtered (_("Trace user is %s.\n"), ts->user_name);
2041 if (ts->notes && strlen (ts->notes) > 0)
2042 printf_filtered (_("Trace notes: %s.\n"), ts->notes);
2044 /* Now report on what we're doing with tfind. */
2045 if (traceframe_number >= 0)
2046 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
2047 traceframe_number, tracepoint_number);
2049 printf_filtered (_("Not looking at any trace frame.\n"));
2051 /* Report start/stop times if supplied. */
2056 LONGEST run_time = ts->stop_time - ts->start_time;
2058 /* Reporting a run time is more readable than two long numbers. */
2059 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
2060 (long int) ts->start_time / 1000000,
2061 (long int) ts->start_time % 1000000,
2062 (long int) run_time / 1000000,
2063 (long int) run_time % 1000000);
2066 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
2067 (long int) ts->start_time / 1000000,
2068 (long int) ts->start_time % 1000000);
2070 else if (ts->stop_time)
2071 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
2072 (long int) ts->stop_time / 1000000,
2073 (long int) ts->stop_time % 1000000);
2075 /* Now report any per-tracepoint status available. */
2076 tp_vec = all_tracepoints ();
2078 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
2079 target_get_tracepoint_status (t, NULL);
2081 VEC_free (breakpoint_p, tp_vec);
2084 /* Report the trace status to uiout, in a way suitable for MI, and not
2085 suitable for CLI. If ON_STOP is true, suppress a few fields that
2086 are not meaningful in the -trace-stop response.
2088 The implementation is essentially parallel to trace_status_command, but
2089 merging them will result in unreadable code. */
2091 trace_status_mi (int on_stop)
2093 struct ui_out *uiout = current_uiout;
2094 struct trace_status *ts = current_trace_status ();
2097 status = target_get_trace_status (ts);
2099 if (status == -1 && ts->filename == NULL)
2101 ui_out_field_string (uiout, "supported", "0");
2105 if (ts->filename != NULL)
2106 ui_out_field_string (uiout, "supported", "file");
2108 ui_out_field_string (uiout, "supported", "1");
2110 if (ts->filename != NULL)
2111 ui_out_field_string (uiout, "trace-file", ts->filename);
2113 gdb_assert (ts->running_known);
2117 ui_out_field_string (uiout, "running", "1");
2119 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
2120 Given that the frontend gets the status either on -trace-stop, or from
2121 -trace-status after re-connection, it does not seem like this
2122 information is necessary for anything. It is not necessary for either
2123 figuring the vital state of the target nor for navigation of trace
2124 frames. If the frontend wants to show the current state is some
2125 configure dialog, it can request the value when such dialog is
2126 invoked by the user. */
2130 char *stop_reason = NULL;
2131 int stopping_tracepoint = -1;
2134 ui_out_field_string (uiout, "running", "0");
2136 if (ts->stop_reason != trace_stop_reason_unknown)
2138 switch (ts->stop_reason)
2141 stop_reason = "request";
2143 case trace_buffer_full:
2144 stop_reason = "overflow";
2146 case trace_disconnected:
2147 stop_reason = "disconnection";
2149 case tracepoint_passcount:
2150 stop_reason = "passcount";
2151 stopping_tracepoint = ts->stopping_tracepoint;
2153 case tracepoint_error:
2154 stop_reason = "error";
2155 stopping_tracepoint = ts->stopping_tracepoint;
2161 ui_out_field_string (uiout, "stop-reason", stop_reason);
2162 if (stopping_tracepoint != -1)
2163 ui_out_field_int (uiout, "stopping-tracepoint",
2164 stopping_tracepoint);
2165 if (ts->stop_reason == tracepoint_error)
2166 ui_out_field_string (uiout, "error-description",
2172 if (ts->traceframe_count != -1)
2173 ui_out_field_int (uiout, "frames", ts->traceframe_count);
2174 if (ts->traceframes_created != -1)
2175 ui_out_field_int (uiout, "frames-created", ts->traceframes_created);
2176 if (ts->buffer_size != -1)
2177 ui_out_field_int (uiout, "buffer-size", ts->buffer_size);
2178 if (ts->buffer_free != -1)
2179 ui_out_field_int (uiout, "buffer-free", ts->buffer_free);
2181 ui_out_field_int (uiout, "disconnected", ts->disconnected_tracing);
2182 ui_out_field_int (uiout, "circular", ts->circular_buffer);
2184 ui_out_field_string (uiout, "user-name", ts->user_name);
2185 ui_out_field_string (uiout, "notes", ts->notes);
2190 xsnprintf (buf, sizeof buf, "%ld.%06ld",
2191 (long int) ts->start_time / 1000000,
2192 (long int) ts->start_time % 1000000);
2193 ui_out_field_string (uiout, "start-time", buf);
2194 xsnprintf (buf, sizeof buf, "%ld.%06ld",
2195 (long int) ts->stop_time / 1000000,
2196 (long int) ts->stop_time % 1000000);
2197 ui_out_field_string (uiout, "stop-time", buf);
2201 /* This function handles the details of what to do about an ongoing
2202 tracing run if the user has asked to detach or otherwise disconnect
2205 disconnect_tracing (int from_tty)
2207 /* It can happen that the target that was tracing went away on its
2208 own, and we didn't notice. Get a status update, and if the
2209 current target doesn't even do tracing, then assume it's not
2211 if (target_get_trace_status (current_trace_status ()) < 0)
2212 current_trace_status ()->running = 0;
2214 /* If running interactively, give the user the option to cancel and
2215 then decide what to do differently with the run. Scripts are
2216 just going to disconnect and let the target deal with it,
2217 according to how it's been instructed previously via
2218 disconnected-tracing. */
2219 if (current_trace_status ()->running && from_tty)
2221 process_tracepoint_on_disconnect ();
2223 if (current_trace_status ()->disconnected_tracing)
2225 if (!query (_("Trace is running and will "
2226 "continue after detach; detach anyway? ")))
2227 error (_("Not confirmed."));
2231 if (!query (_("Trace is running but will "
2232 "stop on detach; detach anyway? ")))
2233 error (_("Not confirmed."));
2237 /* Also we want to be out of tfind mode, otherwise things can get
2238 confusing upon reconnection. Just use these calls instead of
2239 full tfind_1 behavior because we're in the middle of detaching,
2240 and there's no point to updating current stack frame etc. */
2241 set_current_traceframe (-1);
2242 set_tracepoint_num (-1);
2243 set_traceframe_context (NULL);
2246 /* Worker function for the various flavors of the tfind command. */
2248 tfind_1 (enum trace_find_type type, int num,
2249 ULONGEST addr1, ULONGEST addr2,
2252 int target_frameno = -1, target_tracept = -1;
2253 struct frame_id old_frame_id = null_frame_id;
2254 struct tracepoint *tp;
2255 struct ui_out *uiout = current_uiout;
2257 /* Only try to get the current stack frame if we have a chance of
2258 succeeding. In particular, if we're trying to get a first trace
2259 frame while all threads are running, it's not going to succeed,
2260 so leave it with a default value and let the frame comparison
2261 below (correctly) decide to print out the source location of the
2263 if (!(type == tfind_number && num == -1)
2264 && (has_stack_frames () || traceframe_number >= 0))
2265 old_frame_id = get_frame_id (get_current_frame ());
2267 target_frameno = target_trace_find (type, num, addr1, addr2,
2270 if (type == tfind_number
2272 && target_frameno == -1)
2274 /* We told the target to get out of tfind mode, and it did. */
2276 else if (target_frameno == -1)
2278 /* A request for a non-existent trace frame has failed.
2279 Our response will be different, depending on FROM_TTY:
2281 If FROM_TTY is true, meaning that this command was
2282 typed interactively by the user, then give an error
2283 and DO NOT change the state of traceframe_number etc.
2285 However if FROM_TTY is false, meaning that we're either
2286 in a script, a loop, or a user-defined command, then
2287 DON'T give an error, but DO change the state of
2288 traceframe_number etc. to invalid.
2290 The rationalle is that if you typed the command, you
2291 might just have committed a typo or something, and you'd
2292 like to NOT lose your current debugging state. However
2293 if you're in a user-defined command or especially in a
2294 loop, then you need a way to detect that the command
2295 failed WITHOUT aborting. This allows you to write
2296 scripts that search thru the trace buffer until the end,
2297 and then continue on to do something else. */
2300 error (_("Target failed to find requested trace frame."));
2304 printf_filtered ("End of trace buffer.\n");
2305 #if 0 /* dubious now? */
2306 /* The following will not recurse, since it's
2308 trace_find_command ("-1", from_tty);
2313 tp = get_tracepoint_by_number_on_target (target_tracept);
2315 reinit_frame_cache ();
2316 target_dcache_invalidate ();
2318 set_tracepoint_num (tp ? tp->base.number : target_tracept);
2320 if (target_frameno != get_traceframe_number ())
2321 observer_notify_traceframe_changed (target_frameno, tracepoint_number);
2323 set_current_traceframe (target_frameno);
2325 if (target_frameno == -1)
2326 set_traceframe_context (NULL);
2328 set_traceframe_context (get_current_frame ());
2330 if (traceframe_number >= 0)
2332 /* Use different branches for MI and CLI to make CLI messages
2334 if (ui_out_is_mi_like_p (uiout))
2336 ui_out_field_string (uiout, "found", "1");
2337 ui_out_field_int (uiout, "tracepoint", tracepoint_number);
2338 ui_out_field_int (uiout, "traceframe", traceframe_number);
2342 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2343 traceframe_number, tracepoint_number);
2348 if (ui_out_is_mi_like_p (uiout))
2349 ui_out_field_string (uiout, "found", "0");
2350 else if (type == tfind_number && num == -1)
2351 printf_unfiltered (_("No longer looking at any trace frame\n"));
2352 else /* This case may never occur, check. */
2353 printf_unfiltered (_("No trace frame found\n"));
2356 /* If we're in nonstop mode and getting out of looking at trace
2357 frames, there won't be any current frame to go back to and
2360 && (has_stack_frames () || traceframe_number >= 0))
2362 enum print_what print_what;
2364 /* NOTE: in imitation of the step command, try to determine
2365 whether we have made a transition from one function to
2366 another. If so, we'll print the "stack frame" (ie. the new
2367 function and it's arguments) -- otherwise we'll just show the
2370 if (frame_id_eq (old_frame_id,
2371 get_frame_id (get_current_frame ())))
2372 print_what = SRC_LINE;
2374 print_what = SRC_AND_LOC;
2376 print_stack_frame (get_selected_frame (NULL), 1, print_what);
2381 /* trace_find_command takes a trace frame number n,
2382 sends "QTFrame:<n>" to the target,
2383 and accepts a reply that may contain several optional pieces
2384 of information: a frame number, a tracepoint number, and an
2385 indication of whether this is a trap frame or a stepping frame.
2387 The minimal response is just "OK" (which indicates that the
2388 target does not give us a frame number or a tracepoint number).
2389 Instead of that, the target may send us a string containing
2391 F<hexnum> (gives the selected frame number)
2392 T<hexnum> (gives the selected tracepoint number)
2397 trace_find_command (char *args, int from_tty)
2398 { /* This should only be called with a numeric argument. */
2401 if (current_trace_status ()->running
2402 && current_trace_status ()->filename == NULL)
2403 error (_("May not look at trace frames while trace is running."));
2405 if (args == 0 || *args == 0)
2406 { /* TFIND with no args means find NEXT trace frame. */
2407 if (traceframe_number == -1)
2408 frameno = 0; /* "next" is first one. */
2410 frameno = traceframe_number + 1;
2412 else if (0 == strcmp (args, "-"))
2414 if (traceframe_number == -1)
2415 error (_("not debugging trace buffer"));
2416 else if (from_tty && traceframe_number == 0)
2417 error (_("already at start of trace buffer"));
2419 frameno = traceframe_number - 1;
2421 /* A hack to work around eval's need for fp to have been collected. */
2422 else if (0 == strcmp (args, "-1"))
2425 frameno = parse_and_eval_long (args);
2428 error (_("invalid input (%d is less than zero)"), frameno);
2430 tfind_1 (tfind_number, frameno, 0, 0, from_tty);
2435 trace_find_end_command (char *args, int from_tty)
2437 trace_find_command ("-1", from_tty);
2442 trace_find_start_command (char *args, int from_tty)
2444 trace_find_command ("0", from_tty);
2447 /* tfind pc command */
2449 trace_find_pc_command (char *args, int from_tty)
2453 if (current_trace_status ()->running
2454 && current_trace_status ()->filename == NULL)
2455 error (_("May not look at trace frames while trace is running."));
2457 if (args == 0 || *args == 0)
2458 pc = regcache_read_pc (get_current_regcache ());
2460 pc = parse_and_eval_address (args);
2462 tfind_1 (tfind_pc, 0, pc, 0, from_tty);
2465 /* tfind tracepoint command */
2467 trace_find_tracepoint_command (char *args, int from_tty)
2470 struct tracepoint *tp;
2472 if (current_trace_status ()->running
2473 && current_trace_status ()->filename == NULL)
2474 error (_("May not look at trace frames while trace is running."));
2476 if (args == 0 || *args == 0)
2478 if (tracepoint_number == -1)
2479 error (_("No current tracepoint -- please supply an argument."));
2481 tdp = tracepoint_number; /* Default is current TDP. */
2484 tdp = parse_and_eval_long (args);
2486 /* If we have the tracepoint on hand, use the number that the
2487 target knows about (which may be different if we disconnected
2488 and reconnected). */
2489 tp = get_tracepoint (tdp);
2491 tdp = tp->number_on_target;
2493 tfind_1 (tfind_tp, tdp, 0, 0, from_tty);
2496 /* TFIND LINE command:
2498 This command will take a sourceline for argument, just like BREAK
2499 or TRACE (ie. anything that "decode_line_1" can handle).
2501 With no argument, this command will find the next trace frame
2502 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2505 trace_find_line_command (char *args, int from_tty)
2507 static CORE_ADDR start_pc, end_pc;
2508 struct symtabs_and_lines sals;
2509 struct symtab_and_line sal;
2510 struct cleanup *old_chain;
2512 if (current_trace_status ()->running
2513 && current_trace_status ()->filename == NULL)
2514 error (_("May not look at trace frames while trace is running."));
2516 if (args == 0 || *args == 0)
2518 sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
2520 sals.sals = (struct symtab_and_line *)
2521 xmalloc (sizeof (struct symtab_and_line));
2526 sals = decode_line_with_current_source (args, DECODE_LINE_FUNFIRSTLINE);
2530 old_chain = make_cleanup (xfree, sals.sals);
2531 if (sal.symtab == 0)
2532 error (_("No line number information available."));
2534 if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc))
2536 if (start_pc == end_pc)
2538 printf_filtered ("Line %d of \"%s\"",
2540 symtab_to_filename_for_display (sal.symtab));
2542 printf_filtered (" is at address ");
2543 print_address (get_current_arch (), start_pc, gdb_stdout);
2545 printf_filtered (" but contains no code.\n");
2546 sal = find_pc_line (start_pc, 0);
2548 && find_line_pc_range (sal, &start_pc, &end_pc)
2549 && start_pc != end_pc)
2550 printf_filtered ("Attempting to find line %d instead.\n",
2553 error (_("Cannot find a good line."));
2557 /* Is there any case in which we get here, and have an address
2558 which the user would want to see? If we have debugging
2559 symbols and no line numbers? */
2560 error (_("Line number %d is out of range for \"%s\"."),
2561 sal.line, symtab_to_filename_for_display (sal.symtab));
2563 /* Find within range of stated line. */
2565 tfind_1 (tfind_range, 0, start_pc, end_pc - 1, from_tty);
2567 tfind_1 (tfind_outside, 0, start_pc, end_pc - 1, from_tty);
2568 do_cleanups (old_chain);
2571 /* tfind range command */
2573 trace_find_range_command (char *args, int from_tty)
2575 static CORE_ADDR start, stop;
2578 if (current_trace_status ()->running
2579 && current_trace_status ()->filename == NULL)
2580 error (_("May not look at trace frames while trace is running."));
2582 if (args == 0 || *args == 0)
2583 { /* XXX FIXME: what should default behavior be? */
2584 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2588 if (0 != (tmp = strchr (args, ',')))
2590 *tmp++ = '\0'; /* Terminate start address. */
2591 tmp = skip_spaces (tmp);
2592 start = parse_and_eval_address (args);
2593 stop = parse_and_eval_address (tmp);
2596 { /* No explicit end address? */
2597 start = parse_and_eval_address (args);
2598 stop = start + 1; /* ??? */
2601 tfind_1 (tfind_range, 0, start, stop, from_tty);
2604 /* tfind outside command */
2606 trace_find_outside_command (char *args, int from_tty)
2608 CORE_ADDR start, stop;
2611 if (current_trace_status ()->running
2612 && current_trace_status ()->filename == NULL)
2613 error (_("May not look at trace frames while trace is running."));
2615 if (args == 0 || *args == 0)
2616 { /* XXX FIXME: what should default behavior be? */
2617 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2621 if (0 != (tmp = strchr (args, ',')))
2623 *tmp++ = '\0'; /* Terminate start address. */
2624 tmp = skip_spaces (tmp);
2625 start = parse_and_eval_address (args);
2626 stop = parse_and_eval_address (tmp);
2629 { /* No explicit end address? */
2630 start = parse_and_eval_address (args);
2631 stop = start + 1; /* ??? */
2634 tfind_1 (tfind_outside, 0, start, stop, from_tty);
2637 /* info scope command: list the locals for a scope. */
2639 scope_info (char *args, int from_tty)
2641 struct symtabs_and_lines sals;
2643 struct minimal_symbol *msym;
2644 struct block *block;
2645 const char *symname;
2646 char *save_args = args;
2647 struct block_iterator iter;
2649 struct gdbarch *gdbarch;
2652 if (args == 0 || *args == 0)
2653 error (_("requires an argument (function, "
2654 "line or *addr) to define a scope"));
2656 sals = decode_line_1 (&args, DECODE_LINE_FUNFIRSTLINE, NULL, 0);
2657 if (sals.nelts == 0)
2658 return; /* Presumably decode_line_1 has already warned. */
2660 /* Resolve line numbers to PC. */
2661 resolve_sal_pc (&sals.sals[0]);
2662 block = block_for_pc (sals.sals[0].pc);
2666 QUIT; /* Allow user to bail out with ^C. */
2667 ALL_BLOCK_SYMBOLS (block, iter, sym)
2669 QUIT; /* Allow user to bail out with ^C. */
2671 printf_filtered ("Scope for %s:\n", save_args);
2674 symname = SYMBOL_PRINT_NAME (sym);
2675 if (symname == NULL || *symname == '\0')
2676 continue; /* Probably botched, certainly useless. */
2678 gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile);
2680 printf_filtered ("Symbol %s is ", symname);
2681 switch (SYMBOL_CLASS (sym))
2684 case LOC_UNDEF: /* Messed up symbol? */
2685 printf_filtered ("a bogus symbol, class %d.\n",
2686 SYMBOL_CLASS (sym));
2687 count--; /* Don't count this one. */
2690 printf_filtered ("a constant with value %s (%s)",
2691 plongest (SYMBOL_VALUE (sym)),
2692 hex_string (SYMBOL_VALUE (sym)));
2694 case LOC_CONST_BYTES:
2695 printf_filtered ("constant bytes: ");
2696 if (SYMBOL_TYPE (sym))
2697 for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++)
2698 fprintf_filtered (gdb_stdout, " %02x",
2699 (unsigned) SYMBOL_VALUE_BYTES (sym)[j]);
2702 printf_filtered ("in static storage at address ");
2703 printf_filtered ("%s", paddress (gdbarch,
2704 SYMBOL_VALUE_ADDRESS (sym)));
2707 /* GDBARCH is the architecture associated with the objfile
2708 the symbol is defined in; the target architecture may be
2709 different, and may provide additional registers. However,
2710 we do not know the target architecture at this point.
2711 We assume the objfile architecture will contain all the
2712 standard registers that occur in debug info in that
2714 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym,
2717 if (SYMBOL_IS_ARGUMENT (sym))
2718 printf_filtered ("an argument in register $%s",
2719 gdbarch_register_name (gdbarch, regno));
2721 printf_filtered ("a local variable in register $%s",
2722 gdbarch_register_name (gdbarch, regno));
2725 printf_filtered ("an argument at stack/frame offset %s",
2726 plongest (SYMBOL_VALUE (sym)));
2729 printf_filtered ("a local variable at frame offset %s",
2730 plongest (SYMBOL_VALUE (sym)));
2733 printf_filtered ("a reference argument at offset %s",
2734 plongest (SYMBOL_VALUE (sym)));
2736 case LOC_REGPARM_ADDR:
2737 /* Note comment at LOC_REGISTER. */
2738 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym,
2740 printf_filtered ("the address of an argument, in register $%s",
2741 gdbarch_register_name (gdbarch, regno));
2744 printf_filtered ("a typedef.\n");
2747 printf_filtered ("a label at address ");
2748 printf_filtered ("%s", paddress (gdbarch,
2749 SYMBOL_VALUE_ADDRESS (sym)));
2752 printf_filtered ("a function at address ");
2753 printf_filtered ("%s",
2754 paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
2756 case LOC_UNRESOLVED:
2757 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
2760 printf_filtered ("Unresolved Static");
2763 printf_filtered ("static storage at address ");
2764 printf_filtered ("%s",
2765 paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym)));
2768 case LOC_OPTIMIZED_OUT:
2769 printf_filtered ("optimized out.\n");
2772 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym,
2773 BLOCK_START (block),
2777 if (SYMBOL_TYPE (sym))
2778 printf_filtered (", length %d.\n",
2779 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
2781 if (BLOCK_FUNCTION (block))
2784 block = BLOCK_SUPERBLOCK (block);
2787 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2791 /* worker function (cleanup) */
2793 replace_comma (void *data)
2800 /* Helper for trace_dump_command. Dump the action list starting at
2801 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2802 actions of the body of a while-stepping action. STEPPING_FRAME is
2803 set if the current traceframe was determined to be a while-stepping
2807 trace_dump_actions (struct command_line *action,
2808 int stepping_actions, int stepping_frame,
2811 char *action_exp, *next_comma;
2813 for (; action != NULL; action = action->next)
2815 struct cmd_list_element *cmd;
2817 QUIT; /* Allow user to bail out with ^C. */
2818 action_exp = action->line;
2819 action_exp = skip_spaces (action_exp);
2821 /* The collection actions to be done while stepping are
2822 bracketed by the commands "while-stepping" and "end". */
2824 if (*action_exp == '#') /* comment line */
2827 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
2829 error (_("Bad action list item: %s"), action_exp);
2831 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
2835 for (i = 0; i < action->body_count; ++i)
2836 trace_dump_actions (action->body_list[i],
2837 1, stepping_frame, from_tty);
2839 else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
2841 /* Display the collected data.
2842 For the trap frame, display only what was collected at
2843 the trap. Likewise for stepping frames, display only
2844 what was collected while stepping. This means that the
2845 two boolean variables, STEPPING_FRAME and
2846 STEPPING_ACTIONS should be equal. */
2847 if (stepping_frame == stepping_actions)
2849 if (*action_exp == '/')
2850 action_exp = decode_agent_options (action_exp);
2853 { /* Repeat over a comma-separated list. */
2854 QUIT; /* Allow user to bail out with ^C. */
2855 if (*action_exp == ',')
2857 action_exp = skip_spaces (action_exp);
2859 next_comma = strchr (action_exp, ',');
2861 if (0 == strncasecmp (action_exp, "$reg", 4))
2862 registers_info (NULL, from_tty);
2863 else if (0 == strncasecmp (action_exp, "$_ret", 5))
2865 else if (0 == strncasecmp (action_exp, "$loc", 4))
2866 locals_info (NULL, from_tty);
2867 else if (0 == strncasecmp (action_exp, "$arg", 4))
2868 args_info (NULL, from_tty);
2873 make_cleanup (replace_comma, next_comma);
2876 printf_filtered ("%s = ", action_exp);
2877 output_command (action_exp, from_tty);
2878 printf_filtered ("\n");
2882 action_exp = next_comma;
2884 while (action_exp && *action_exp == ',');
2890 /* The tdump command. */
2893 trace_dump_command (char *args, int from_tty)
2895 struct regcache *regcache;
2896 struct tracepoint *t;
2897 int stepping_frame = 0;
2898 struct bp_location *loc;
2899 char *line, *default_collect_line = NULL;
2900 struct command_line *actions, *default_collect_action = NULL;
2901 struct cleanup *old_chain = NULL;
2903 if (tracepoint_number == -1)
2905 warning (_("No current trace frame."));
2909 t = get_tracepoint (tracepoint_number);
2912 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2915 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2916 tracepoint_number, traceframe_number);
2918 /* The current frame is a trap frame if the frame PC is equal
2919 to the tracepoint PC. If not, then the current frame was
2920 collected during single-stepping. */
2922 regcache = get_current_regcache ();
2924 /* If the traceframe's address matches any of the tracepoint's
2925 locations, assume it is a direct hit rather than a while-stepping
2926 frame. (FIXME this is not reliable, should record each frame's
2929 for (loc = t->base.loc; loc; loc = loc->next)
2930 if (loc->address == regcache_read_pc (regcache))
2933 actions = breakpoint_commands (&t->base);
2935 /* If there is a default-collect list, make up a collect command,
2936 prepend to the tracepoint's commands, and pass the whole mess to
2937 the trace dump scanner. We need to validate because
2938 default-collect might have been junked since the trace run. */
2939 if (*default_collect)
2941 default_collect_line = xstrprintf ("collect %s", default_collect);
2942 old_chain = make_cleanup (xfree, default_collect_line);
2943 line = default_collect_line;
2944 validate_actionline (&line, &t->base);
2945 default_collect_action = xmalloc (sizeof (struct command_line));
2946 make_cleanup (xfree, default_collect_action);
2947 default_collect_action->next = actions;
2948 default_collect_action->line = line;
2949 actions = default_collect_action;
2952 trace_dump_actions (actions, 0, stepping_frame, from_tty);
2954 if (*default_collect)
2955 do_cleanups (old_chain);
2958 /* Encode a piece of a tracepoint's source-level definition in a form
2959 that is suitable for both protocol and saving in files. */
2960 /* This version does not do multiple encodes for long strings; it should
2961 return an offset to the next piece to encode. FIXME */
2964 encode_source_string (int tpnum, ULONGEST addr,
2965 char *srctype, char *src, char *buf, int buf_size)
2967 if (80 + strlen (srctype) > buf_size)
2968 error (_("Buffer too small for source encoding"));
2969 sprintf (buf, "%x:%s:%s:%x:%x:",
2970 tpnum, phex_nz (addr, sizeof (addr)),
2971 srctype, 0, (int) strlen (src));
2972 if (strlen (buf) + strlen (src) * 2 >= buf_size)
2973 error (_("Source string too long for buffer"));
2974 bin2hex (src, buf + strlen (buf), 0);
2978 extern int trace_regblock_size;
2980 /* Save tracepoint data to file named FILENAME. If TARGET_DOES_SAVE is
2981 non-zero, the save is performed on the target, otherwise GDB obtains all
2982 trace data and saves it locally. */
2985 trace_save (const char *filename, int target_does_save)
2987 struct cleanup *cleanup;
2989 struct trace_status *ts = current_trace_status ();
2992 struct uploaded_tp *uploaded_tps = NULL, *utp;
2993 struct uploaded_tsv *uploaded_tsvs = NULL, *utsv;
2997 ULONGEST offset = 0;
2998 #define MAX_TRACE_UPLOAD 2000
2999 gdb_byte buf[MAX_TRACE_UPLOAD];
3002 /* If the target is to save the data to a file on its own, then just
3003 send the command and be done with it. */
3004 if (target_does_save)
3006 err = target_save_trace_data (filename);
3008 error (_("Target failed to save trace data to '%s'."),
3013 /* Get the trace status first before opening the file, so if the
3014 target is losing, we can get out without touching files. */
3015 status = target_get_trace_status (ts);
3017 pathname = tilde_expand (filename);
3018 cleanup = make_cleanup (xfree, pathname);
3020 fp = fopen (pathname, "wb");
3022 error (_("Unable to open file '%s' for saving trace data (%s)"),
3023 filename, safe_strerror (errno));
3024 make_cleanup_fclose (fp);
3026 /* Write a file header, with a high-bit-set char to indicate a
3027 binary file, plus a hint as what this file is, and a version
3028 number in case of future needs. */
3029 written = fwrite ("\x7fTRACE0\n", 8, 1, fp);
3031 perror_with_name (pathname);
3033 /* Write descriptive info. */
3035 /* Write out the size of a register block. */
3036 fprintf (fp, "R %x\n", trace_regblock_size);
3038 /* Write out status of the tracing run (aka "tstatus" info). */
3039 fprintf (fp, "status %c;%s",
3040 (ts->running ? '1' : '0'), stop_reason_names[ts->stop_reason]);
3041 if (ts->stop_reason == tracepoint_error)
3043 char *buf = (char *) alloca (strlen (ts->stop_desc) * 2 + 1);
3045 bin2hex ((gdb_byte *) ts->stop_desc, buf, 0);
3046 fprintf (fp, ":%s", buf);
3048 fprintf (fp, ":%x", ts->stopping_tracepoint);
3049 if (ts->traceframe_count >= 0)
3050 fprintf (fp, ";tframes:%x", ts->traceframe_count);
3051 if (ts->traceframes_created >= 0)
3052 fprintf (fp, ";tcreated:%x", ts->traceframes_created);
3053 if (ts->buffer_free >= 0)
3054 fprintf (fp, ";tfree:%x", ts->buffer_free);
3055 if (ts->buffer_size >= 0)
3056 fprintf (fp, ";tsize:%x", ts->buffer_size);
3057 if (ts->disconnected_tracing)
3058 fprintf (fp, ";disconn:%x", ts->disconnected_tracing);
3059 if (ts->circular_buffer)
3060 fprintf (fp, ";circular:%x", ts->circular_buffer);
3063 /* Note that we want to upload tracepoints and save those, rather
3064 than simply writing out the local ones, because the user may have
3065 changed tracepoints in GDB in preparation for a future tracing
3066 run, or maybe just mass-deleted all types of breakpoints as part
3067 of cleaning up. So as not to contaminate the session, leave the
3068 data in its uploaded form, don't make into real tracepoints. */
3070 /* Get trace state variables first, they may be checked when parsing
3071 uploaded commands. */
3073 target_upload_trace_state_variables (&uploaded_tsvs);
3075 for (utsv = uploaded_tsvs; utsv; utsv = utsv->next)
3081 buf = (char *) xmalloc (strlen (utsv->name) * 2 + 1);
3082 bin2hex ((gdb_byte *) (utsv->name), buf, 0);
3085 fprintf (fp, "tsv %x:%s:%x:%s\n",
3086 utsv->number, phex_nz (utsv->initial_value, 8),
3087 utsv->builtin, buf);
3093 free_uploaded_tsvs (&uploaded_tsvs);
3095 target_upload_tracepoints (&uploaded_tps);
3097 for (utp = uploaded_tps; utp; utp = utp->next)
3098 target_get_tracepoint_status (NULL, utp);
3100 for (utp = uploaded_tps; utp; utp = utp->next)
3102 fprintf (fp, "tp T%x:%s:%c:%x:%x",
3103 utp->number, phex_nz (utp->addr, sizeof (utp->addr)),
3104 (utp->enabled ? 'E' : 'D'), utp->step, utp->pass);
3105 if (utp->type == bp_fast_tracepoint)
3106 fprintf (fp, ":F%x", utp->orig_size);
3108 fprintf (fp, ":X%x,%s", (unsigned int) strlen (utp->cond) / 2,
3111 for (a = 0; VEC_iterate (char_ptr, utp->actions, a, act); ++a)
3112 fprintf (fp, "tp A%x:%s:%s\n",
3113 utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
3114 for (a = 0; VEC_iterate (char_ptr, utp->step_actions, a, act); ++a)
3115 fprintf (fp, "tp S%x:%s:%s\n",
3116 utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
3119 encode_source_string (utp->number, utp->addr,
3120 "at", utp->at_string, buf, MAX_TRACE_UPLOAD);
3121 fprintf (fp, "tp Z%s\n", buf);
3123 if (utp->cond_string)
3125 encode_source_string (utp->number, utp->addr,
3126 "cond", utp->cond_string,
3127 buf, MAX_TRACE_UPLOAD);
3128 fprintf (fp, "tp Z%s\n", buf);
3130 for (a = 0; VEC_iterate (char_ptr, utp->cmd_strings, a, act); ++a)
3132 encode_source_string (utp->number, utp->addr, "cmd", act,
3133 buf, MAX_TRACE_UPLOAD);
3134 fprintf (fp, "tp Z%s\n", buf);
3136 fprintf (fp, "tp V%x:%s:%x:%s\n",
3137 utp->number, phex_nz (utp->addr, sizeof (utp->addr)),
3139 phex_nz (utp->traceframe_usage,
3140 sizeof (utp->traceframe_usage)));
3143 free_uploaded_tps (&uploaded_tps);
3145 /* Mark the end of the definition section. */
3148 /* Get and write the trace data proper. We ask for big blocks, in
3149 the hopes of efficiency, but will take less if the target has
3150 packet size limitations or some such. */
3153 gotten = target_get_raw_trace_data (buf, offset, MAX_TRACE_UPLOAD);
3155 error (_("Failure to get requested trace buffer data"));
3156 /* No more data is forthcoming, we're done. */
3159 written = fwrite (buf, gotten, 1, fp);
3161 perror_with_name (pathname);
3165 /* Mark the end of trace data. (We know that gotten is 0 at this point.) */
3166 written = fwrite (&gotten, 4, 1, fp);
3168 perror_with_name (pathname);
3170 do_cleanups (cleanup);
3174 trace_save_command (char *args, int from_tty)
3176 int target_does_save = 0;
3178 char *filename = NULL;
3179 struct cleanup *back_to;
3182 error_no_arg (_("file in which to save trace data"));
3184 argv = gdb_buildargv (args);
3185 back_to = make_cleanup_freeargv (argv);
3187 for (; *argv; ++argv)
3189 if (strcmp (*argv, "-r") == 0)
3190 target_does_save = 1;
3191 else if (**argv == '-')
3192 error (_("unknown option `%s'"), *argv);
3198 error_no_arg (_("file in which to save trace data"));
3200 trace_save (filename, target_does_save);
3203 printf_filtered (_("Trace data saved to file '%s'.\n"), filename);
3205 do_cleanups (back_to);
3208 /* Tell the target what to do with an ongoing tracing run if GDB
3209 disconnects for some reason. */
3212 set_disconnected_tracing (char *args, int from_tty,
3213 struct cmd_list_element *c)
3215 target_set_disconnected_tracing (disconnected_tracing);
3219 set_circular_trace_buffer (char *args, int from_tty,
3220 struct cmd_list_element *c)
3222 target_set_circular_trace_buffer (circular_trace_buffer);
3226 set_trace_buffer_size (char *args, int from_tty,
3227 struct cmd_list_element *c)
3229 target_set_trace_buffer_size (trace_buffer_size);
3233 set_trace_user (char *args, int from_tty,
3234 struct cmd_list_element *c)
3238 ret = target_set_trace_notes (trace_user, NULL, NULL);
3241 warning (_("Target does not support trace notes, user ignored"));
3245 set_trace_notes (char *args, int from_tty,
3246 struct cmd_list_element *c)
3250 ret = target_set_trace_notes (NULL, trace_notes, NULL);
3253 warning (_("Target does not support trace notes, note ignored"));
3257 set_trace_stop_notes (char *args, int from_tty,
3258 struct cmd_list_element *c)
3262 ret = target_set_trace_notes (NULL, NULL, trace_stop_notes);
3265 warning (_("Target does not support trace notes, stop note ignored"));
3268 /* Convert the memory pointed to by mem into hex, placing result in buf.
3269 * Return a pointer to the last char put in buf (null)
3270 * "stolen" from sparc-stub.c
3273 static const char hexchars[] = "0123456789abcdef";
3276 mem2hex (gdb_byte *mem, char *buf, int count)
3284 *buf++ = hexchars[ch >> 4];
3285 *buf++ = hexchars[ch & 0xf];
3294 get_traceframe_number (void)
3296 return traceframe_number;
3299 /* Make the traceframe NUM be the current trace frame. Does nothing
3300 if NUM is already current. */
3303 set_current_traceframe (int num)
3307 if (traceframe_number == num)
3309 /* Nothing to do. */
3313 newnum = target_trace_find (tfind_number, num, 0, 0, NULL);
3316 warning (_("could not change traceframe"));
3318 set_traceframe_num (newnum);
3320 /* Changing the traceframe changes our view of registers and of the
3322 registers_changed ();
3324 clear_traceframe_info ();
3327 /* Make the traceframe NUM be the current trace frame, and do nothing
3331 set_traceframe_number (int num)
3333 traceframe_number = num;
3336 /* A cleanup used when switching away and back from tfind mode. */
3338 struct current_traceframe_cleanup
3340 /* The traceframe we were inspecting. */
3341 int traceframe_number;
3345 do_restore_current_traceframe_cleanup (void *arg)
3347 struct current_traceframe_cleanup *old = arg;
3349 set_current_traceframe (old->traceframe_number);
3353 restore_current_traceframe_cleanup_dtor (void *arg)
3355 struct current_traceframe_cleanup *old = arg;
3361 make_cleanup_restore_current_traceframe (void)
3363 struct current_traceframe_cleanup *old;
3365 old = xmalloc (sizeof (struct current_traceframe_cleanup));
3366 old->traceframe_number = traceframe_number;
3368 return make_cleanup_dtor (do_restore_current_traceframe_cleanup, old,
3369 restore_current_traceframe_cleanup_dtor);
3373 make_cleanup_restore_traceframe_number (void)
3375 return make_cleanup_restore_integer (&traceframe_number);
3378 /* Given a number and address, return an uploaded tracepoint with that
3379 number, creating if necessary. */
3381 struct uploaded_tp *
3382 get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp)
3384 struct uploaded_tp *utp;
3386 for (utp = *utpp; utp; utp = utp->next)
3387 if (utp->number == num && utp->addr == addr)
3389 utp = (struct uploaded_tp *) xmalloc (sizeof (struct uploaded_tp));
3390 memset (utp, 0, sizeof (struct uploaded_tp));
3393 utp->actions = NULL;
3394 utp->step_actions = NULL;
3395 utp->cmd_strings = NULL;
3402 free_uploaded_tps (struct uploaded_tp **utpp)
3404 struct uploaded_tp *next_one;
3408 next_one = (*utpp)->next;
3414 /* Given a number and address, return an uploaded tracepoint with that
3415 number, creating if necessary. */
3417 static struct uploaded_tsv *
3418 get_uploaded_tsv (int num, struct uploaded_tsv **utsvp)
3420 struct uploaded_tsv *utsv;
3422 for (utsv = *utsvp; utsv; utsv = utsv->next)
3423 if (utsv->number == num)
3425 utsv = (struct uploaded_tsv *) xmalloc (sizeof (struct uploaded_tsv));
3426 memset (utsv, 0, sizeof (struct uploaded_tsv));
3428 utsv->next = *utsvp;
3434 free_uploaded_tsvs (struct uploaded_tsv **utsvp)
3436 struct uploaded_tsv *next_one;
3440 next_one = (*utsvp)->next;
3446 /* FIXME this function is heuristic and will miss the cases where the
3447 conditional is semantically identical but differs in whitespace,
3448 such as "x == 0" vs "x==0". */
3451 cond_string_is_same (char *str1, char *str2)
3453 if (str1 == NULL || str2 == NULL)
3454 return (str1 == str2);
3456 return (strcmp (str1, str2) == 0);
3459 /* Look for an existing tracepoint that seems similar enough to the
3460 uploaded one. Enablement isn't compared, because the user can
3461 toggle that freely, and may have done so in anticipation of the
3462 next trace run. Return the location of matched tracepoint. */
3464 static struct bp_location *
3465 find_matching_tracepoint_location (struct uploaded_tp *utp)
3467 VEC(breakpoint_p) *tp_vec = all_tracepoints ();
3469 struct breakpoint *b;
3470 struct bp_location *loc;
3472 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
3474 struct tracepoint *t = (struct tracepoint *) b;
3476 if (b->type == utp->type
3477 && t->step_count == utp->step
3478 && t->pass_count == utp->pass
3479 && cond_string_is_same (t->base.cond_string, utp->cond_string)
3480 /* FIXME also test actions. */
3483 /* Scan the locations for an address match. */
3484 for (loc = b->loc; loc; loc = loc->next)
3486 if (loc->address == utp->addr)
3494 /* Given a list of tracepoints uploaded from a target, attempt to
3495 match them up with existing tracepoints, and create new ones if not
3499 merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps)
3501 struct uploaded_tp *utp;
3502 /* A set of tracepoints which are modified. */
3503 VEC(breakpoint_p) *modified_tp = NULL;
3505 struct breakpoint *b;
3507 /* Look for GDB tracepoints that match up with our uploaded versions. */
3508 for (utp = *uploaded_tps; utp; utp = utp->next)
3510 struct bp_location *loc;
3511 struct tracepoint *t;
3513 loc = find_matching_tracepoint_location (utp);
3518 /* Mark this location as already inserted. */
3520 t = (struct tracepoint *) loc->owner;
3521 printf_filtered (_("Assuming tracepoint %d is same "
3522 "as target's tracepoint %d at %s.\n"),
3523 loc->owner->number, utp->number,
3524 paddress (loc->gdbarch, utp->addr));
3526 /* The tracepoint LOC->owner was modified (the location LOC
3527 was marked as inserted in the target). Save it in
3528 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3529 observers will be notified later once for each tracepoint
3530 saved in MODIFIED_TP. */
3532 VEC_iterate (breakpoint_p, modified_tp, ix, b);
3534 if (b == loc->owner)
3540 VEC_safe_push (breakpoint_p, modified_tp, loc->owner);
3544 t = create_tracepoint_from_upload (utp);
3546 printf_filtered (_("Created tracepoint %d for "
3547 "target's tracepoint %d at %s.\n"),
3548 t->base.number, utp->number,
3549 paddress (get_current_arch (), utp->addr));
3551 printf_filtered (_("Failed to create tracepoint for target's "
3552 "tracepoint %d at %s, skipping it.\n"),
3554 paddress (get_current_arch (), utp->addr));
3556 /* Whether found or created, record the number used by the
3557 target, to help with mapping target tracepoints back to their
3558 counterparts here. */
3560 t->number_on_target = utp->number;
3563 /* Notify 'breakpoint-modified' observer that at least one of B's
3564 locations was changed. */
3565 for (ix = 0; VEC_iterate (breakpoint_p, modified_tp, ix, b); ix++)
3566 observer_notify_breakpoint_modified (b);
3568 VEC_free (breakpoint_p, modified_tp);
3569 free_uploaded_tps (uploaded_tps);
3572 /* Trace state variables don't have much to identify them beyond their
3573 name, so just use that to detect matches. */
3575 static struct trace_state_variable *
3576 find_matching_tsv (struct uploaded_tsv *utsv)
3581 return find_trace_state_variable (utsv->name);
3584 static struct trace_state_variable *
3585 create_tsv_from_upload (struct uploaded_tsv *utsv)
3587 const char *namebase;
3590 struct trace_state_variable *tsv;
3591 struct cleanup *old_chain;
3595 namebase = utsv->name;
3596 buf = xstrprintf ("%s", namebase);
3601 buf = xstrprintf ("%s_%d", namebase, try_num++);
3604 /* Fish for a name that is not in use. */
3605 /* (should check against all internal vars?) */
3606 while (find_trace_state_variable (buf))
3609 buf = xstrprintf ("%s_%d", namebase, try_num++);
3612 old_chain = make_cleanup (xfree, buf);
3614 /* We have an available name, create the variable. */
3615 tsv = create_trace_state_variable (buf);
3616 tsv->initial_value = utsv->initial_value;
3617 tsv->builtin = utsv->builtin;
3619 observer_notify_tsv_created (tsv);
3621 do_cleanups (old_chain);
3626 /* Given a list of uploaded trace state variables, try to match them
3627 up with existing variables, or create additional ones. */
3630 merge_uploaded_trace_state_variables (struct uploaded_tsv **uploaded_tsvs)
3633 struct uploaded_tsv *utsv;
3634 struct trace_state_variable *tsv;
3637 /* Most likely some numbers will have to be reassigned as part of
3638 the merge, so clear them all in anticipation. */
3639 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3642 for (utsv = *uploaded_tsvs; utsv; utsv = utsv->next)
3644 tsv = find_matching_tsv (utsv);
3648 printf_filtered (_("Assuming trace state variable $%s "
3649 "is same as target's variable %d.\n"),
3650 tsv->name, utsv->number);
3654 tsv = create_tsv_from_upload (utsv);
3656 printf_filtered (_("Created trace state variable "
3657 "$%s for target's variable %d.\n"),
3658 tsv->name, utsv->number);
3660 /* Give precedence to numberings that come from the target. */
3662 tsv->number = utsv->number;
3665 /* Renumber everything that didn't get a target-assigned number. */
3667 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3668 if (tsv->number > highest)
3669 highest = tsv->number;
3672 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3673 if (tsv->number == 0)
3674 tsv->number = highest++;
3676 free_uploaded_tsvs (uploaded_tsvs);
3679 /* target tfile command */
3681 static struct target_ops tfile_ops;
3683 /* Fill in tfile_ops with its defined operations and properties. */
3685 #define TRACE_HEADER_SIZE 8
3687 static char *trace_filename;
3688 static int trace_fd = -1;
3689 static off_t trace_frames_offset;
3690 static off_t cur_offset;
3691 static int cur_data_size;
3692 int trace_regblock_size;
3694 static void tfile_interp_line (char *line,
3695 struct uploaded_tp **utpp,
3696 struct uploaded_tsv **utsvp);
3698 /* Read SIZE bytes into READBUF from the trace frame, starting at
3699 TRACE_FD's current position. Note that this call `read'
3700 underneath, hence it advances the file's seek position. Throws an
3701 error if the `read' syscall fails, or less than SIZE bytes are
3705 tfile_read (gdb_byte *readbuf, int size)
3709 gotten = read (trace_fd, readbuf, size);
3711 perror_with_name (trace_filename);
3712 else if (gotten < size)
3713 error (_("Premature end of file while reading trace file"));
3717 tfile_open (char *filename, int from_tty)
3719 volatile struct gdb_exception ex;
3721 struct cleanup *old_chain;
3724 char header[TRACE_HEADER_SIZE];
3725 char linebuf[1000]; /* Should be max remote packet size or so. */
3728 struct trace_status *ts;
3729 struct uploaded_tp *uploaded_tps = NULL;
3730 struct uploaded_tsv *uploaded_tsvs = NULL;
3732 target_preopen (from_tty);
3734 error (_("No trace file specified."));
3736 filename = tilde_expand (filename);
3737 if (!IS_ABSOLUTE_PATH(filename))
3739 temp = concat (current_directory, "/", filename, (char *) NULL);
3744 old_chain = make_cleanup (xfree, filename);
3746 flags = O_BINARY | O_LARGEFILE;
3748 scratch_chan = open (filename, flags, 0);
3749 if (scratch_chan < 0)
3750 perror_with_name (filename);
3752 /* Looks semi-reasonable. Toss the old trace file and work on the new. */
3754 discard_cleanups (old_chain); /* Don't free filename any more. */
3755 unpush_target (&tfile_ops);
3757 trace_filename = xstrdup (filename);
3758 trace_fd = scratch_chan;
3761 /* Read the file header and test for validity. */
3762 tfile_read ((gdb_byte *) &header, TRACE_HEADER_SIZE);
3764 bytes += TRACE_HEADER_SIZE;
3765 if (!(header[0] == 0x7f
3766 && (strncmp (header + 1, "TRACE0\n", 7) == 0)))
3767 error (_("File is not a valid trace file."));
3769 push_target (&tfile_ops);
3771 trace_regblock_size = 0;
3772 ts = current_trace_status ();
3773 /* We know we're working with a file. Record its name. */
3774 ts->filename = trace_filename;
3775 /* Set defaults in case there is no status line. */
3776 ts->running_known = 0;
3777 ts->stop_reason = trace_stop_reason_unknown;
3778 ts->traceframe_count = -1;
3779 ts->buffer_free = 0;
3780 ts->disconnected_tracing = 0;
3781 ts->circular_buffer = 0;
3783 TRY_CATCH (ex, RETURN_MASK_ALL)
3785 /* Read through a section of newline-terminated lines that
3786 define things like tracepoints. */
3790 tfile_read (&byte, 1);
3795 /* Empty line marks end of the definition section. */
3800 tfile_interp_line (linebuf, &uploaded_tps, &uploaded_tsvs);
3803 linebuf[i++] = byte;
3805 error (_("Excessively long lines in trace file"));
3808 /* Record the starting offset of the binary trace data. */
3809 trace_frames_offset = bytes;
3811 /* If we don't have a blocksize, we can't interpret the
3813 if (trace_regblock_size == 0)
3814 error (_("No register block size recorded in trace file"));
3818 /* Pop the partially set up target. */
3820 throw_exception (ex);
3823 inferior_appeared (current_inferior (), TFILE_PID);
3824 inferior_ptid = pid_to_ptid (TFILE_PID);
3825 add_thread_silent (inferior_ptid);
3827 if (ts->traceframe_count <= 0)
3828 warning (_("No traceframes present in this file."));
3830 /* Add the file's tracepoints and variables into the current mix. */
3832 /* Get trace state variables first, they may be checked when parsing
3833 uploaded commands. */
3834 merge_uploaded_trace_state_variables (&uploaded_tsvs);
3836 merge_uploaded_tracepoints (&uploaded_tps);
3838 post_create_inferior (&tfile_ops, from_tty);
3841 /* Interpret the given line from the definitions part of the trace
3845 tfile_interp_line (char *line,
3846 struct uploaded_tp **utpp, struct uploaded_tsv **utsvp)
3850 if (strncmp (p, "R ", strlen ("R ")) == 0)
3853 trace_regblock_size = strtol (p, &p, 16);
3855 else if (strncmp (p, "status ", strlen ("status ")) == 0)
3857 p += strlen ("status ");
3858 parse_trace_status (p, current_trace_status ());
3860 else if (strncmp (p, "tp ", strlen ("tp ")) == 0)
3862 p += strlen ("tp ");
3863 parse_tracepoint_definition (p, utpp);
3865 else if (strncmp (p, "tsv ", strlen ("tsv ")) == 0)
3867 p += strlen ("tsv ");
3868 parse_tsv_definition (p, utsvp);
3871 warning (_("Ignoring trace file definition \"%s\""), line);
3874 /* Parse the part of trace status syntax that is shared between
3875 the remote protocol and the trace file reader. */
3878 parse_trace_status (char *line, struct trace_status *ts)
3880 char *p = line, *p1, *p2, *p3, *p_temp;
3884 ts->running_known = 1;
3885 ts->running = (*p++ == '1');
3886 ts->stop_reason = trace_stop_reason_unknown;
3887 xfree (ts->stop_desc);
3888 ts->stop_desc = NULL;
3889 ts->traceframe_count = -1;
3890 ts->traceframes_created = -1;
3891 ts->buffer_free = -1;
3892 ts->buffer_size = -1;
3893 ts->disconnected_tracing = 0;
3894 ts->circular_buffer = 0;
3895 xfree (ts->user_name);
3896 ts->user_name = NULL;
3899 ts->start_time = ts->stop_time = 0;
3903 p1 = strchr (p, ':');
3905 error (_("Malformed trace status, at %s\n\
3906 Status line: '%s'\n"), p, line);
3907 p3 = strchr (p, ';');
3909 p3 = p + strlen (p);
3910 if (strncmp (p, stop_reason_names[trace_buffer_full], p1 - p) == 0)
3912 p = unpack_varlen_hex (++p1, &val);
3913 ts->stop_reason = trace_buffer_full;
3915 else if (strncmp (p, stop_reason_names[trace_never_run], p1 - p) == 0)
3917 p = unpack_varlen_hex (++p1, &val);
3918 ts->stop_reason = trace_never_run;
3920 else if (strncmp (p, stop_reason_names[tracepoint_passcount],
3923 p = unpack_varlen_hex (++p1, &val);
3924 ts->stop_reason = tracepoint_passcount;
3925 ts->stopping_tracepoint = val;
3927 else if (strncmp (p, stop_reason_names[tstop_command], p1 - p) == 0)
3929 p2 = strchr (++p1, ':');
3937 ts->stop_desc = xmalloc (strlen (line));
3938 end = hex2bin (p1, ts->stop_desc, (p2 - p1) / 2);
3939 ts->stop_desc[end] = '\0';
3942 ts->stop_desc = xstrdup ("");
3944 p = unpack_varlen_hex (++p2, &val);
3945 ts->stop_reason = tstop_command;
3947 else if (strncmp (p, stop_reason_names[trace_disconnected], p1 - p) == 0)
3949 p = unpack_varlen_hex (++p1, &val);
3950 ts->stop_reason = trace_disconnected;
3952 else if (strncmp (p, stop_reason_names[tracepoint_error], p1 - p) == 0)
3954 p2 = strchr (++p1, ':');
3957 ts->stop_desc = xmalloc ((p2 - p1) / 2 + 1);
3958 end = hex2bin (p1, ts->stop_desc, (p2 - p1) / 2);
3959 ts->stop_desc[end] = '\0';
3962 ts->stop_desc = xstrdup ("");
3964 p = unpack_varlen_hex (++p2, &val);
3965 ts->stopping_tracepoint = val;
3966 ts->stop_reason = tracepoint_error;
3968 else if (strncmp (p, "tframes", p1 - p) == 0)
3970 p = unpack_varlen_hex (++p1, &val);
3971 ts->traceframe_count = val;
3973 else if (strncmp (p, "tcreated", p1 - p) == 0)
3975 p = unpack_varlen_hex (++p1, &val);
3976 ts->traceframes_created = val;
3978 else if (strncmp (p, "tfree", p1 - p) == 0)
3980 p = unpack_varlen_hex (++p1, &val);
3981 ts->buffer_free = val;
3983 else if (strncmp (p, "tsize", p1 - p) == 0)
3985 p = unpack_varlen_hex (++p1, &val);
3986 ts->buffer_size = val;
3988 else if (strncmp (p, "disconn", p1 - p) == 0)
3990 p = unpack_varlen_hex (++p1, &val);
3991 ts->disconnected_tracing = val;
3993 else if (strncmp (p, "circular", p1 - p) == 0)
3995 p = unpack_varlen_hex (++p1, &val);
3996 ts->circular_buffer = val;
3998 else if (strncmp (p, "starttime", p1 - p) == 0)
4000 p = unpack_varlen_hex (++p1, &val);
4001 ts->start_time = val;
4003 else if (strncmp (p, "stoptime", p1 - p) == 0)
4005 p = unpack_varlen_hex (++p1, &val);
4006 ts->stop_time = val;
4008 else if (strncmp (p, "username", p1 - p) == 0)
4011 ts->user_name = xmalloc (strlen (p) / 2);
4012 end = hex2bin (p1, ts->user_name, (p3 - p1) / 2);
4013 ts->user_name[end] = '\0';
4016 else if (strncmp (p, "notes", p1 - p) == 0)
4019 ts->notes = xmalloc (strlen (p) / 2);
4020 end = hex2bin (p1, ts->notes, (p3 - p1) / 2);
4021 ts->notes[end] = '\0';
4026 /* Silently skip unknown optional info. */
4027 p_temp = strchr (p1 + 1, ';');
4031 /* Must be at the end. */
4038 parse_tracepoint_status (char *p, struct breakpoint *bp,
4039 struct uploaded_tp *utp)
4042 struct tracepoint *tp = (struct tracepoint *) bp;
4044 p = unpack_varlen_hex (p, &uval);
4046 tp->base.hit_count += uval;
4048 utp->hit_count += uval;
4049 p = unpack_varlen_hex (p + 1, &uval);
4051 tp->traceframe_usage += uval;
4053 utp->traceframe_usage += uval;
4054 /* Ignore any extra, allowing for future extensions. */
4057 /* Given a line of text defining a part of a tracepoint, parse it into
4058 an "uploaded tracepoint". */
4061 parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
4065 ULONGEST num, addr, step, pass, orig_size, xlen, start;
4068 char *cond, *srctype, *buf;
4069 struct uploaded_tp *utp = NULL;
4072 /* Both tracepoint and action definitions start with the same number
4073 and address sequence. */
4075 p = unpack_varlen_hex (p, &num);
4076 p++; /* skip a colon */
4077 p = unpack_varlen_hex (p, &addr);
4078 p++; /* skip a colon */
4081 enabled = (*p++ == 'E');
4082 p++; /* skip a colon */
4083 p = unpack_varlen_hex (p, &step);
4084 p++; /* skip a colon */
4085 p = unpack_varlen_hex (p, &pass);
4086 type = bp_tracepoint;
4088 /* Thumb through optional fields. */
4091 p++; /* skip a colon */
4094 type = bp_fast_tracepoint;
4096 p = unpack_varlen_hex (p, &orig_size);
4100 type = bp_static_tracepoint;
4106 p = unpack_varlen_hex (p, &xlen);
4107 p++; /* skip a comma */
4108 cond = (char *) xmalloc (2 * xlen + 1);
4109 strncpy (cond, p, 2 * xlen);
4110 cond[2 * xlen] = '\0';
4114 warning (_("Unrecognized char '%c' in tracepoint "
4115 "definition, skipping rest"), *p);
4117 utp = get_uploaded_tp (num, addr, utpp);
4119 utp->enabled = enabled;
4124 else if (piece == 'A')
4126 utp = get_uploaded_tp (num, addr, utpp);
4127 VEC_safe_push (char_ptr, utp->actions, xstrdup (p));
4129 else if (piece == 'S')
4131 utp = get_uploaded_tp (num, addr, utpp);
4132 VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p));
4134 else if (piece == 'Z')
4136 /* Parse a chunk of source form definition. */
4137 utp = get_uploaded_tp (num, addr, utpp);
4139 p = strchr (p, ':');
4140 p++; /* skip a colon */
4141 p = unpack_varlen_hex (p, &start);
4142 p++; /* skip a colon */
4143 p = unpack_varlen_hex (p, &xlen);
4144 p++; /* skip a colon */
4146 buf = alloca (strlen (line));
4148 end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
4151 if (strncmp (srctype, "at:", strlen ("at:")) == 0)
4152 utp->at_string = xstrdup (buf);
4153 else if (strncmp (srctype, "cond:", strlen ("cond:")) == 0)
4154 utp->cond_string = xstrdup (buf);
4155 else if (strncmp (srctype, "cmd:", strlen ("cmd:")) == 0)
4156 VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf));
4158 else if (piece == 'V')
4160 utp = get_uploaded_tp (num, addr, utpp);
4162 parse_tracepoint_status (p, NULL, utp);
4166 /* Don't error out, the target might be sending us optional
4167 info that we don't care about. */
4168 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece);
4172 /* Convert a textual description of a trace state variable into an
4176 parse_tsv_definition (char *line, struct uploaded_tsv **utsvp)
4179 ULONGEST num, initval, builtin;
4181 struct uploaded_tsv *utsv = NULL;
4183 buf = alloca (strlen (line));
4186 p = unpack_varlen_hex (p, &num);
4187 p++; /* skip a colon */
4188 p = unpack_varlen_hex (p, &initval);
4189 p++; /* skip a colon */
4190 p = unpack_varlen_hex (p, &builtin);
4191 p++; /* skip a colon */
4192 end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
4195 utsv = get_uploaded_tsv (num, utsvp);
4196 utsv->initial_value = initval;
4197 utsv->builtin = builtin;
4198 utsv->name = xstrdup (buf);
4201 /* Close the trace file and generally clean up. */
4204 tfile_close (int quitting)
4211 pid = ptid_get_pid (inferior_ptid);
4212 inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */
4213 exit_inferior_silent (pid);
4217 xfree (trace_filename);
4218 trace_filename = NULL;
4222 tfile_files_info (struct target_ops *t)
4224 printf_filtered ("\t`%s'\n", trace_filename);
4227 /* The trace status for a file is that tracing can never be run. */
4230 tfile_get_trace_status (struct trace_status *ts)
4232 /* Other bits of trace status were collected as part of opening the
4233 trace files, so nothing to do here. */
4239 tfile_get_tracepoint_status (struct breakpoint *tp, struct uploaded_tp *utp)
4241 /* Other bits of trace status were collected as part of opening the
4242 trace files, so nothing to do here. */
4245 /* Given the position of a traceframe in the file, figure out what
4246 address the frame was collected at. This would normally be the
4247 value of a collected PC register, but if not available, we
4251 tfile_get_traceframe_address (off_t tframe_offset)
4255 struct tracepoint *tp;
4256 off_t saved_offset = cur_offset;
4258 /* FIXME dig pc out of collected registers. */
4260 /* Fall back to using tracepoint address. */
4261 lseek (trace_fd, tframe_offset, SEEK_SET);
4262 tfile_read ((gdb_byte *) &tpnum, 2);
4263 tpnum = (short) extract_signed_integer ((gdb_byte *) &tpnum, 2,
4265 (target_gdbarch ()));
4267 tp = get_tracepoint_by_number_on_target (tpnum);
4268 /* FIXME this is a poor heuristic if multiple locations. */
4269 if (tp && tp->base.loc)
4270 addr = tp->base.loc->address;
4272 /* Restore our seek position. */
4273 cur_offset = saved_offset;
4274 lseek (trace_fd, cur_offset, SEEK_SET);
4278 /* Given a type of search and some parameters, scan the collection of
4279 traceframes in the file looking for a match. When found, return
4280 both the traceframe and tracepoint number, otherwise -1 for
4284 tfile_trace_find (enum trace_find_type type, int num,
4285 ULONGEST addr1, ULONGEST addr2, int *tpp)
4288 int tfnum = 0, found = 0;
4289 unsigned int data_size;
4290 struct tracepoint *tp;
4291 off_t offset, tframe_offset;
4301 lseek (trace_fd, trace_frames_offset, SEEK_SET);
4302 offset = trace_frames_offset;
4305 tframe_offset = offset;
4306 tfile_read ((gdb_byte *) &tpnum, 2);
4307 tpnum = (short) extract_signed_integer ((gdb_byte *) &tpnum, 2,
4309 (target_gdbarch ()));
4313 tfile_read ((gdb_byte *) &data_size, 4);
4314 data_size = (unsigned int) extract_unsigned_integer
4315 ((gdb_byte *) &data_size, 4,
4316 gdbarch_byte_order (target_gdbarch ()));
4319 if (type == tfind_number)
4321 /* Looking for a specific trace frame. */
4327 /* Start from the _next_ trace frame. */
4328 if (tfnum > traceframe_number)
4333 tfaddr = tfile_get_traceframe_address (tframe_offset);
4334 if (tfaddr == addr1)
4338 tp = get_tracepoint (num);
4339 if (tp && tpnum == tp->number_on_target)
4343 tfaddr = tfile_get_traceframe_address (tframe_offset);
4344 if (addr1 <= tfaddr && tfaddr <= addr2)
4348 tfaddr = tfile_get_traceframe_address (tframe_offset);
4349 if (!(addr1 <= tfaddr && tfaddr <= addr2))
4353 internal_error (__FILE__, __LINE__, _("unknown tfind type"));
4362 cur_offset = offset;
4363 cur_data_size = data_size;
4367 /* Skip past the traceframe's data. */
4368 lseek (trace_fd, data_size, SEEK_CUR);
4369 offset += data_size;
4370 /* Update our own count of traceframes. */
4373 /* Did not find what we were looking for. */
4379 /* Prototype of the callback passed to tframe_walk_blocks. */
4380 typedef int (*walk_blocks_callback_func) (char blocktype, void *data);
4382 /* Callback for traceframe_walk_blocks, used to find a given block
4383 type in a traceframe. */
4386 match_blocktype (char blocktype, void *data)
4388 char *wantedp = data;
4390 if (*wantedp == blocktype)
4396 /* Walk over all traceframe block starting at POS offset from
4397 CUR_OFFSET, and call CALLBACK for each block found, passing in DATA
4398 unmodified. If CALLBACK returns true, this returns the position in
4399 the traceframe where the block is found, relative to the start of
4400 the traceframe (cur_offset). Returns -1 if no callback call
4401 returned true, indicating that all blocks have been walked. */
4404 traceframe_walk_blocks (walk_blocks_callback_func callback,
4405 int pos, void *data)
4407 /* Iterate through a traceframe's blocks, looking for a block of the
4410 lseek (trace_fd, cur_offset + pos, SEEK_SET);
4411 while (pos < cur_data_size)
4413 unsigned short mlen;
4416 tfile_read (&block_type, 1);
4420 if ((*callback) (block_type, data))
4426 lseek (trace_fd, cur_offset + pos + trace_regblock_size, SEEK_SET);
4427 pos += trace_regblock_size;
4430 lseek (trace_fd, cur_offset + pos + 8, SEEK_SET);
4431 tfile_read ((gdb_byte *) &mlen, 2);
4432 mlen = (unsigned short)
4433 extract_unsigned_integer ((gdb_byte *) &mlen, 2,
4435 (target_gdbarch ()));
4436 lseek (trace_fd, mlen, SEEK_CUR);
4437 pos += (8 + 2 + mlen);
4440 lseek (trace_fd, cur_offset + pos + 4 + 8, SEEK_SET);
4444 error (_("Unknown block type '%c' (0x%x) in trace frame"),
4445 block_type, block_type);
4453 /* Convenience wrapper around traceframe_walk_blocks. Looks for the
4454 position offset of a block of type TYPE_WANTED in the current trace
4455 frame, starting at POS. Returns -1 if no such block was found. */
4458 traceframe_find_block_type (char type_wanted, int pos)
4460 return traceframe_walk_blocks (match_blocktype, pos, &type_wanted);
4463 /* Look for a block of saved registers in the traceframe, and get the
4464 requested register from it. */
4467 tfile_fetch_registers (struct target_ops *ops,
4468 struct regcache *regcache, int regno)
4470 struct gdbarch *gdbarch = get_regcache_arch (regcache);
4471 int offset, regn, regsize, pc_regno;
4474 /* An uninitialized reg size says we're not going to be
4475 successful at getting register blocks. */
4476 if (!trace_regblock_size)
4479 regs = alloca (trace_regblock_size);
4481 if (traceframe_find_block_type ('R', 0) >= 0)
4483 tfile_read (regs, trace_regblock_size);
4485 /* Assume the block is laid out in GDB register number order,
4486 each register with the size that it has in GDB. */
4488 for (regn = 0; regn < gdbarch_num_regs (gdbarch); regn++)
4490 regsize = register_size (gdbarch, regn);
4491 /* Make sure we stay within block bounds. */
4492 if (offset + regsize >= trace_regblock_size)
4494 if (regcache_register_status (regcache, regn) == REG_UNKNOWN)
4498 regcache_raw_supply (regcache, regno, regs + offset);
4501 else if (regno == -1)
4503 regcache_raw_supply (regcache, regn, regs + offset);
4511 /* We get here if no register data has been found. Mark registers
4513 for (regn = 0; regn < gdbarch_num_regs (gdbarch); regn++)
4514 regcache_raw_supply (regcache, regn, NULL);
4516 /* We can often usefully guess that the PC is going to be the same
4517 as the address of the tracepoint. */
4518 pc_regno = gdbarch_pc_regnum (gdbarch);
4519 if (pc_regno >= 0 && (regno == -1 || regno == pc_regno))
4521 struct tracepoint *tp = get_tracepoint (tracepoint_number);
4523 if (tp && tp->base.loc)
4525 /* But don't try to guess if tracepoint is multi-location... */
4526 if (tp->base.loc->next)
4528 warning (_("Tracepoint %d has multiple "
4529 "locations, cannot infer $pc"),
4533 /* ... or does while-stepping. */
4534 if (tp->step_count > 0)
4536 warning (_("Tracepoint %d does while-stepping, "
4537 "cannot infer $pc"),
4542 store_unsigned_integer (regs, register_size (gdbarch, pc_regno),
4543 gdbarch_byte_order (gdbarch),
4544 tp->base.loc->address);
4545 regcache_raw_supply (regcache, pc_regno, regs);
4551 tfile_xfer_partial (struct target_ops *ops, enum target_object object,
4552 const char *annex, gdb_byte *readbuf,
4553 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
4555 /* We're only doing regular memory for now. */
4556 if (object != TARGET_OBJECT_MEMORY)
4559 if (readbuf == NULL)
4560 error (_("tfile_xfer_partial: trace file is read-only"));
4562 if (traceframe_number != -1)
4566 /* Iterate through the traceframe's blocks, looking for
4568 while ((pos = traceframe_find_block_type ('M', pos)) >= 0)
4570 ULONGEST maddr, amt;
4571 unsigned short mlen;
4572 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
4574 tfile_read ((gdb_byte *) &maddr, 8);
4575 maddr = extract_unsigned_integer ((gdb_byte *) &maddr, 8,
4577 tfile_read ((gdb_byte *) &mlen, 2);
4578 mlen = (unsigned short)
4579 extract_unsigned_integer ((gdb_byte *) &mlen, 2, byte_order);
4581 /* If the block includes the first part of the desired
4582 range, return as much it has; GDB will re-request the
4583 remainder, which might be in a different block of this
4585 if (maddr <= offset && offset < (maddr + mlen))
4587 amt = (maddr + mlen) - offset;
4591 if (maddr != offset)
4592 lseek (trace_fd, offset - maddr, SEEK_CUR);
4593 tfile_read (readbuf, amt);
4597 /* Skip over this block. */
4598 pos += (8 + 2 + mlen);
4602 /* It's unduly pedantic to refuse to look at the executable for
4603 read-only pieces; so do the equivalent of readonly regions aka
4605 /* FIXME account for relocation at some point. */
4612 for (s = exec_bfd->sections; s; s = s->next)
4614 if ((s->flags & SEC_LOAD) == 0
4615 || (s->flags & SEC_READONLY) == 0)
4619 size = bfd_get_section_size (s);
4620 if (vma <= offset && offset < (vma + size))
4624 amt = (vma + size) - offset;
4628 amt = bfd_get_section_contents (exec_bfd, s,
4629 readbuf, offset - vma, amt);
4635 /* Indicate failure to find the requested memory block. */
4639 /* Iterate through the blocks of a trace frame, looking for a 'V'
4640 block with a matching tsv number. */
4643 tfile_get_trace_state_variable_value (int tsvnum, LONGEST *val)
4648 while ((pos = traceframe_find_block_type ('V', pos)) >= 0)
4652 tfile_read ((gdb_byte *) &vnum, 4);
4653 vnum = (int) extract_signed_integer ((gdb_byte *) &vnum, 4,
4655 (target_gdbarch ()));
4658 tfile_read ((gdb_byte *) val, 8);
4659 *val = extract_signed_integer ((gdb_byte *) val, 8,
4661 (target_gdbarch ()));
4667 /* Didn't find anything. */
4672 tfile_has_all_memory (struct target_ops *ops)
4678 tfile_has_memory (struct target_ops *ops)
4684 tfile_has_stack (struct target_ops *ops)
4686 return traceframe_number != -1;
4690 tfile_has_registers (struct target_ops *ops)
4692 return traceframe_number != -1;
4696 tfile_thread_alive (struct target_ops *ops, ptid_t ptid)
4701 /* Callback for traceframe_walk_blocks. Builds a traceframe_info
4702 object for the tfile target's current traceframe. */
4705 build_traceframe_info (char blocktype, void *data)
4707 struct traceframe_info *info = data;
4713 struct mem_range *r;
4715 unsigned short mlen;
4717 tfile_read ((gdb_byte *) &maddr, 8);
4718 maddr = extract_unsigned_integer ((gdb_byte *) &maddr, 8,
4720 (target_gdbarch ()));
4721 tfile_read ((gdb_byte *) &mlen, 2);
4722 mlen = (unsigned short)
4723 extract_unsigned_integer ((gdb_byte *) &mlen,
4724 2, gdbarch_byte_order
4725 (target_gdbarch ()));
4727 r = VEC_safe_push (mem_range_s, info->memory, NULL);
4740 warning (_("Unhandled trace block type (%d) '%c ' "
4741 "while building trace frame info."),
4742 blocktype, blocktype);
4749 static struct traceframe_info *
4750 tfile_traceframe_info (void)
4752 struct traceframe_info *info = XCNEW (struct traceframe_info);
4754 traceframe_walk_blocks (build_traceframe_info, 0, info);
4759 init_tfile_ops (void)
4761 tfile_ops.to_shortname = "tfile";
4762 tfile_ops.to_longname = "Local trace dump file";
4764 = "Use a trace file as a target. Specify the filename of the trace file.";
4765 tfile_ops.to_open = tfile_open;
4766 tfile_ops.to_close = tfile_close;
4767 tfile_ops.to_fetch_registers = tfile_fetch_registers;
4768 tfile_ops.to_xfer_partial = tfile_xfer_partial;
4769 tfile_ops.to_files_info = tfile_files_info;
4770 tfile_ops.to_get_trace_status = tfile_get_trace_status;
4771 tfile_ops.to_get_tracepoint_status = tfile_get_tracepoint_status;
4772 tfile_ops.to_trace_find = tfile_trace_find;
4773 tfile_ops.to_get_trace_state_variable_value
4774 = tfile_get_trace_state_variable_value;
4775 tfile_ops.to_stratum = process_stratum;
4776 tfile_ops.to_has_all_memory = tfile_has_all_memory;
4777 tfile_ops.to_has_memory = tfile_has_memory;
4778 tfile_ops.to_has_stack = tfile_has_stack;
4779 tfile_ops.to_has_registers = tfile_has_registers;
4780 tfile_ops.to_traceframe_info = tfile_traceframe_info;
4781 tfile_ops.to_thread_alive = tfile_thread_alive;
4782 tfile_ops.to_magic = OPS_MAGIC;
4786 free_current_marker (void *arg)
4788 struct static_tracepoint_marker **marker_p = arg;
4790 if (*marker_p != NULL)
4792 release_static_tracepoint_marker (*marker_p);
4799 /* Given a line of text defining a static tracepoint marker, parse it
4800 into a "static tracepoint marker" object. Throws an error is
4801 parsing fails. If PP is non-null, it points to one past the end of
4802 the parsed marker definition. */
4805 parse_static_tracepoint_marker_definition (char *line, char **pp,
4806 struct static_tracepoint_marker *marker)
4813 p = unpack_varlen_hex (p, &addr);
4814 p++; /* skip a colon */
4816 marker->gdbarch = target_gdbarch ();
4817 marker->address = (CORE_ADDR) addr;
4819 endp = strchr (p, ':');
4821 error (_("bad marker definition: %s"), line);
4823 marker->str_id = xmalloc (endp - p + 1);
4824 end = hex2bin (p, (gdb_byte *) marker->str_id, (endp - p + 1) / 2);
4825 marker->str_id[end] = '\0';
4828 p++; /* skip a colon */
4830 marker->extra = xmalloc (strlen (p) + 1);
4831 end = hex2bin (p, (gdb_byte *) marker->extra, strlen (p) / 2);
4832 marker->extra[end] = '\0';
4838 /* Release a static tracepoint marker's contents. Note that the
4839 object itself isn't released here. There objects are usually on
4843 release_static_tracepoint_marker (struct static_tracepoint_marker *marker)
4845 xfree (marker->str_id);
4846 marker->str_id = NULL;
4849 /* Print MARKER to gdb_stdout. */
4852 print_one_static_tracepoint_marker (int count,
4853 struct static_tracepoint_marker *marker)
4855 struct command_line *l;
4858 char wrap_indent[80];
4859 char extra_field_indent[80];
4860 struct ui_out *uiout = current_uiout;
4861 struct cleanup *bkpt_chain;
4862 VEC(breakpoint_p) *tracepoints;
4864 struct symtab_and_line sal;
4868 sal.pc = marker->address;
4870 tracepoints = static_tracepoints_here (marker->address);
4872 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "marker");
4874 /* A counter field to help readability. This is not a stable
4876 ui_out_field_int (uiout, "count", count);
4878 ui_out_field_string (uiout, "marker-id", marker->str_id);
4880 ui_out_field_fmt (uiout, "enabled", "%c",
4881 !VEC_empty (breakpoint_p, tracepoints) ? 'y' : 'n');
4882 ui_out_spaces (uiout, 2);
4884 strcpy (wrap_indent, " ");
4886 if (gdbarch_addr_bit (marker->gdbarch) <= 32)
4887 strcat (wrap_indent, " ");
4889 strcat (wrap_indent, " ");
4891 strcpy (extra_field_indent, " ");
4893 ui_out_field_core_addr (uiout, "addr", marker->gdbarch, marker->address);
4895 sal = find_pc_line (marker->address, 0);
4896 sym = find_pc_sect_function (marker->address, NULL);
4899 ui_out_text (uiout, "in ");
4900 ui_out_field_string (uiout, "func",
4901 SYMBOL_PRINT_NAME (sym));
4902 ui_out_wrap_hint (uiout, wrap_indent);
4903 ui_out_text (uiout, " at ");
4906 ui_out_field_skip (uiout, "func");
4908 if (sal.symtab != NULL)
4910 ui_out_field_string (uiout, "file",
4911 symtab_to_filename_for_display (sal.symtab));
4912 ui_out_text (uiout, ":");
4914 if (ui_out_is_mi_like_p (uiout))
4916 const char *fullname = symtab_to_fullname (sal.symtab);
4918 ui_out_field_string (uiout, "fullname", fullname);
4921 ui_out_field_skip (uiout, "fullname");
4923 ui_out_field_int (uiout, "line", sal.line);
4927 ui_out_field_skip (uiout, "fullname");
4928 ui_out_field_skip (uiout, "line");
4931 ui_out_text (uiout, "\n");
4932 ui_out_text (uiout, extra_field_indent);
4933 ui_out_text (uiout, _("Data: \""));
4934 ui_out_field_string (uiout, "extra-data", marker->extra);
4935 ui_out_text (uiout, "\"\n");
4937 if (!VEC_empty (breakpoint_p, tracepoints))
4939 struct cleanup *cleanup_chain;
4941 struct breakpoint *b;
4943 cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout,
4946 ui_out_text (uiout, extra_field_indent);
4947 ui_out_text (uiout, _("Probed by static tracepoints: "));
4948 for (ix = 0; VEC_iterate(breakpoint_p, tracepoints, ix, b); ix++)
4951 ui_out_text (uiout, ", ");
4952 ui_out_text (uiout, "#");
4953 ui_out_field_int (uiout, "tracepoint-id", b->number);
4956 do_cleanups (cleanup_chain);
4958 if (ui_out_is_mi_like_p (uiout))
4959 ui_out_field_int (uiout, "number-of-tracepoints",
4960 VEC_length(breakpoint_p, tracepoints));
4962 ui_out_text (uiout, "\n");
4964 VEC_free (breakpoint_p, tracepoints);
4966 do_cleanups (bkpt_chain);
4970 info_static_tracepoint_markers_command (char *arg, int from_tty)
4972 VEC(static_tracepoint_marker_p) *markers;
4973 struct cleanup *old_chain;
4974 struct static_tracepoint_marker *marker;
4975 struct ui_out *uiout = current_uiout;
4978 /* We don't have to check target_can_use_agent and agent's capability on
4979 static tracepoint here, in order to be compatible with older GDBserver.
4980 We don't check USE_AGENT is true or not, because static tracepoints
4981 don't work without in-process agent, so we don't bother users to type
4982 `set agent on' when to use static tracepoint. */
4985 = make_cleanup_ui_out_table_begin_end (uiout, 5, -1,
4986 "StaticTracepointMarkersTable");
4988 ui_out_table_header (uiout, 7, ui_left, "counter", "Cnt");
4990 ui_out_table_header (uiout, 40, ui_left, "marker-id", "ID");
4992 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb");
4993 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
4994 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");
4996 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");
4997 ui_out_table_header (uiout, 40, ui_noalign, "what", "What");
4999 ui_out_table_body (uiout);
5001 markers = target_static_tracepoint_markers_by_strid (NULL);
5002 make_cleanup (VEC_cleanup (static_tracepoint_marker_p), &markers);
5005 VEC_iterate (static_tracepoint_marker_p,
5006 markers, i, marker);
5009 print_one_static_tracepoint_marker (i + 1, marker);
5010 release_static_tracepoint_marker (marker);
5013 do_cleanups (old_chain);
5016 /* The $_sdata convenience variable is a bit special. We don't know
5017 for sure type of the value until we actually have a chance to fetch
5018 the data --- the size of the object depends on what has been
5019 collected. We solve this by making $_sdata be an internalvar that
5020 creates a new value on access. */
5022 /* Return a new value with the correct type for the sdata object of
5023 the current trace frame. Return a void value if there's no object
5026 static struct value *
5027 sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var,
5033 /* We need to read the whole object before we know its size. */
5034 size = target_read_alloc (¤t_target,
5035 TARGET_OBJECT_STATIC_TRACE_DATA,
5042 type = init_vector_type (builtin_type (gdbarch)->builtin_true_char,
5044 v = allocate_value (type);
5045 memcpy (value_contents_raw (v), buf, size);
5050 return allocate_value (builtin_type (gdbarch)->builtin_void);
5053 #if !defined(HAVE_LIBEXPAT)
5055 struct traceframe_info *
5056 parse_traceframe_info (const char *tframe_info)
5058 static int have_warned;
5063 warning (_("Can not parse XML trace frame info; XML support "
5064 "was disabled at compile time"));
5070 #else /* HAVE_LIBEXPAT */
5072 #include "xml-support.h"
5074 /* Handle the start of a <memory> element. */
5077 traceframe_info_start_memory (struct gdb_xml_parser *parser,
5078 const struct gdb_xml_element *element,
5079 void *user_data, VEC(gdb_xml_value_s) *attributes)
5081 struct traceframe_info *info = user_data;
5082 struct mem_range *r = VEC_safe_push (mem_range_s, info->memory, NULL);
5083 ULONGEST *start_p, *length_p;
5085 start_p = xml_find_attribute (attributes, "start")->value;
5086 length_p = xml_find_attribute (attributes, "length")->value;
5088 r->start = *start_p;
5089 r->length = *length_p;
5092 /* Discard the constructed trace frame info (if an error occurs). */
5095 free_result (void *p)
5097 struct traceframe_info *result = p;
5099 free_traceframe_info (result);
5102 /* The allowed elements and attributes for an XML memory map. */
5104 static const struct gdb_xml_attribute memory_attributes[] = {
5105 { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
5106 { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
5107 { NULL, GDB_XML_AF_NONE, NULL, NULL }
5110 static const struct gdb_xml_element traceframe_info_children[] = {
5111 { "memory", memory_attributes, NULL,
5112 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
5113 traceframe_info_start_memory, NULL },
5114 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
5117 static const struct gdb_xml_element traceframe_info_elements[] = {
5118 { "traceframe-info", NULL, traceframe_info_children, GDB_XML_EF_NONE,
5120 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
5123 /* Parse a traceframe-info XML document. */
5125 struct traceframe_info *
5126 parse_traceframe_info (const char *tframe_info)
5128 struct traceframe_info *result;
5129 struct cleanup *back_to;
5131 result = XCNEW (struct traceframe_info);
5132 back_to = make_cleanup (free_result, result);
5134 if (gdb_xml_parse_quick (_("trace frame info"),
5135 "traceframe-info.dtd", traceframe_info_elements,
5136 tframe_info, result) == 0)
5138 /* Parsed successfully, keep the result. */
5139 discard_cleanups (back_to);
5144 do_cleanups (back_to);
5148 #endif /* HAVE_LIBEXPAT */
5150 /* Returns the traceframe_info object for the current traceframe.
5151 This is where we avoid re-fetching the object from the target if we
5152 already have it cached. */
5154 static struct traceframe_info *
5155 get_traceframe_info (void)
5157 if (traceframe_info == NULL)
5158 traceframe_info = target_traceframe_info ();
5160 return traceframe_info;
5163 /* If the target supports the query, return in RESULT the set of
5164 collected memory in the current traceframe, found within the LEN
5165 bytes range starting at MEMADDR. Returns true if the target
5166 supports the query, otherwise returns false, and RESULT is left
5170 traceframe_available_memory (VEC(mem_range_s) **result,
5171 CORE_ADDR memaddr, ULONGEST len)
5173 struct traceframe_info *info = get_traceframe_info ();
5177 struct mem_range *r;
5182 for (i = 0; VEC_iterate (mem_range_s, info->memory, i, r); i++)
5183 if (mem_ranges_overlap (r->start, r->length, memaddr, len))
5185 ULONGEST lo1, hi1, lo2, hi2;
5186 struct mem_range *nr;
5189 hi1 = memaddr + len;
5192 hi2 = r->start + r->length;
5194 nr = VEC_safe_push (mem_range_s, *result, NULL);
5196 nr->start = max (lo1, lo2);
5197 nr->length = min (hi1, hi2) - nr->start;
5200 normalize_mem_ranges (*result);
5207 /* Implementation of `sdata' variable. */
5209 static const struct internalvar_funcs sdata_funcs =
5216 /* module initialization */
5218 _initialize_tracepoint (void)
5220 struct cmd_list_element *c;
5222 /* Explicitly create without lookup, since that tries to create a
5223 value with a void typed value, and when we get here, gdbarch
5224 isn't initialized yet. At this point, we're quite sure there
5225 isn't another convenience variable of the same name. */
5226 create_internalvar_type_lazy ("_sdata", &sdata_funcs, NULL);
5228 traceframe_number = -1;
5229 tracepoint_number = -1;
5231 if (tracepoint_list.list == NULL)
5233 tracepoint_list.listsize = 128;
5234 tracepoint_list.list = xmalloc
5235 (tracepoint_list.listsize * sizeof (struct memrange));
5237 if (tracepoint_list.aexpr_list == NULL)
5239 tracepoint_list.aexpr_listsize = 128;
5240 tracepoint_list.aexpr_list = xmalloc
5241 (tracepoint_list.aexpr_listsize * sizeof (struct agent_expr *));
5244 if (stepping_list.list == NULL)
5246 stepping_list.listsize = 128;
5247 stepping_list.list = xmalloc
5248 (stepping_list.listsize * sizeof (struct memrange));
5251 if (stepping_list.aexpr_list == NULL)
5253 stepping_list.aexpr_listsize = 128;
5254 stepping_list.aexpr_list = xmalloc
5255 (stepping_list.aexpr_listsize * sizeof (struct agent_expr *));
5258 add_info ("scope", scope_info,
5259 _("List the variables local to a scope"));
5261 add_cmd ("tracepoints", class_trace, NULL,
5262 _("Tracing of program execution without stopping the program."),
5265 add_com ("tdump", class_trace, trace_dump_command,
5266 _("Print everything collected at the current tracepoint."));
5268 add_com ("tsave", class_trace, trace_save_command, _("\
5269 Save the trace data to a file.\n\
5270 Use the '-r' option to direct the target to save directly to the file,\n\
5271 using its own filesystem."));
5273 c = add_com ("tvariable", class_trace, trace_variable_command,_("\
5274 Define a trace state variable.\n\
5275 Argument is a $-prefixed name, optionally followed\n\
5276 by '=' and an expression that sets the initial value\n\
5277 at the start of tracing."));
5278 set_cmd_completer (c, expression_completer);
5280 add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\
5281 Delete one or more trace state variables.\n\
5282 Arguments are the names of the variables to delete.\n\
5283 If no arguments are supplied, delete all variables."), &deletelist);
5284 /* FIXME add a trace variable completer. */
5286 add_info ("tvariables", tvariables_info, _("\
5287 Status of trace state variables and their values.\n\
5290 add_info ("static-tracepoint-markers",
5291 info_static_tracepoint_markers_command, _("\
5292 List target static tracepoints markers.\n\
5295 add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\
5296 Select a trace frame;\n\
5297 No argument means forward by one frame; '-' means backward by one frame."),
5298 &tfindlist, "tfind ", 1, &cmdlist);
5300 add_cmd ("outside", class_trace, trace_find_outside_command, _("\
5301 Select a trace frame whose PC is outside the given range (exclusive).\n\
5302 Usage: tfind outside addr1, addr2"),
5305 add_cmd ("range", class_trace, trace_find_range_command, _("\
5306 Select a trace frame whose PC is in the given range (inclusive).\n\
5307 Usage: tfind range addr1,addr2"),
5310 add_cmd ("line", class_trace, trace_find_line_command, _("\
5311 Select a trace frame by source line.\n\
5312 Argument can be a line number (with optional source file),\n\
5313 a function name, or '*' followed by an address.\n\
5314 Default argument is 'the next source line that was traced'."),
5317 add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, _("\
5318 Select a trace frame by tracepoint number.\n\
5319 Default is the tracepoint for the current trace frame."),
5322 add_cmd ("pc", class_trace, trace_find_pc_command, _("\
5323 Select a trace frame by PC.\n\
5324 Default is the current PC, or the PC of the current trace frame."),
5327 add_cmd ("end", class_trace, trace_find_end_command, _("\
5328 De-select any trace frame and resume 'live' debugging."),
5331 add_alias_cmd ("none", "end", class_trace, 0, &tfindlist);
5333 add_cmd ("start", class_trace, trace_find_start_command,
5334 _("Select the first trace frame in the trace buffer."),
5337 add_com ("tstatus", class_trace, trace_status_command,
5338 _("Display the status of the current trace data collection."));
5340 add_com ("tstop", class_trace, trace_stop_command, _("\
5341 Stop trace data collection.\n\
5342 Usage: tstop [ <notes> ... ]\n\
5343 Any arguments supplied are recorded with the trace as a stop reason and\n\
5344 reported by tstatus (if the target supports trace notes)."));
5346 add_com ("tstart", class_trace, trace_start_command, _("\
5347 Start trace data collection.\n\
5348 Usage: tstart [ <notes> ... ]\n\
5349 Any arguments supplied are recorded with the trace as a note and\n\
5350 reported by tstatus (if the target supports trace notes)."));
5352 add_com ("end", class_trace, end_actions_pseudocommand, _("\
5353 Ends a list of commands or actions.\n\
5354 Several GDB commands allow you to enter a list of commands or actions.\n\
5355 Entering \"end\" on a line by itself is the normal way to terminate\n\
5357 Note: the \"end\" command cannot be used at the gdb prompt."));
5359 add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\
5360 Specify single-stepping behavior at a tracepoint.\n\
5361 Argument is number of instructions to trace in single-step mode\n\
5362 following the tracepoint. This command is normally followed by\n\
5363 one or more \"collect\" commands, to specify what to collect\n\
5364 while single-stepping.\n\n\
5365 Note: this command can only be used in a tracepoint \"actions\" list."));
5367 add_com_alias ("ws", "while-stepping", class_alias, 0);
5368 add_com_alias ("stepping", "while-stepping", class_alias, 0);
5370 add_com ("collect", class_trace, collect_pseudocommand, _("\
5371 Specify one or more data items to be collected at a tracepoint.\n\
5372 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
5373 collect all data (variables, registers) referenced by that expression.\n\
5374 Also accepts the following special arguments:\n\
5375 $regs -- all registers.\n\
5376 $args -- all function arguments.\n\
5377 $locals -- all variables local to the block/function scope.\n\
5378 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
5379 Note: this command can only be used in a tracepoint \"actions\" list."));
5381 add_com ("teval", class_trace, teval_pseudocommand, _("\
5382 Specify one or more expressions to be evaluated at a tracepoint.\n\
5383 Accepts a comma-separated list of (one or more) expressions.\n\
5384 The result of each evaluation will be discarded.\n\
5385 Note: this command can only be used in a tracepoint \"actions\" list."));
5387 add_com ("actions", class_trace, trace_actions_command, _("\
5388 Specify the actions to be taken at a tracepoint.\n\
5389 Tracepoint actions may include collecting of specified data,\n\
5390 single-stepping, or enabling/disabling other tracepoints,\n\
5391 depending on target's capabilities."));
5393 default_collect = xstrdup ("");
5394 add_setshow_string_cmd ("default-collect", class_trace,
5395 &default_collect, _("\
5396 Set the list of expressions to collect by default"), _("\
5397 Show the list of expressions to collect by default"), NULL,
5399 &setlist, &showlist);
5401 add_setshow_boolean_cmd ("disconnected-tracing", no_class,
5402 &disconnected_tracing, _("\
5403 Set whether tracing continues after GDB disconnects."), _("\
5404 Show whether tracing continues after GDB disconnects."), _("\
5405 Use this to continue a tracing run even if GDB disconnects\n\
5406 or detaches from the target. You can reconnect later and look at\n\
5407 trace data collected in the meantime."),
5408 set_disconnected_tracing,
5413 add_setshow_boolean_cmd ("circular-trace-buffer", no_class,
5414 &circular_trace_buffer, _("\
5415 Set target's use of circular trace buffer."), _("\
5416 Show target's use of circular trace buffer."), _("\
5417 Use this to make the trace buffer into a circular buffer,\n\
5418 which will discard traceframes (oldest first) instead of filling\n\
5419 up and stopping the trace run."),
5420 set_circular_trace_buffer,
5425 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class,
5426 &trace_buffer_size, _("\
5427 Set requested size of trace buffer."), _("\
5428 Show requested size of trace buffer."), _("\
5429 Use this to choose a size for the trace buffer. Some targets\n\
5430 may have fixed or limited buffer sizes. A value of -1 disables\n\
5431 any attempt to set the buffer size and lets the target choose."),
5432 set_trace_buffer_size, NULL,
5433 &setlist, &showlist);
5435 add_setshow_string_cmd ("trace-user", class_trace,
5437 Set the user name to use for current and future trace runs"), _("\
5438 Show the user name to use for current and future trace runs"), NULL,
5439 set_trace_user, NULL,
5440 &setlist, &showlist);
5442 add_setshow_string_cmd ("trace-notes", class_trace,
5444 Set notes string to use for current and future trace runs"), _("\
5445 Show the notes string to use for current and future trace runs"), NULL,
5446 set_trace_notes, NULL,
5447 &setlist, &showlist);
5449 add_setshow_string_cmd ("trace-stop-notes", class_trace,
5450 &trace_stop_notes, _("\
5451 Set notes string to use for future tstop commands"), _("\
5452 Show the notes string to use for future tstop commands"), NULL,
5453 set_trace_stop_notes, NULL,
5454 &setlist, &showlist);
5458 add_target (&tfile_ops);