1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
25 #include "expression.h"
29 #include "target-dcache.h"
32 #include "breakpoint.h"
33 #include "tracepoint.h"
36 #include "completer.h"
38 #include "dictionary.h"
40 #include "user-regs.h"
44 #include "filenames.h"
45 #include "gdbthread.h"
52 #include "cli/cli-utils.h"
55 #include "filestuff.h"
57 #include "tracefile.h"
61 /* readline include files */
62 #include "readline/readline.h"
63 #include "readline/history.h"
65 /* readline defines this. */
70 /* Maximum length of an agent aexpression.
71 This accounts for the fact that packets are limited to 400 bytes
72 (which includes everything -- including the checksum), and assumes
73 the worst case of maximum length for each of the pieces of a
76 NOTE: expressions get mem2hex'ed otherwise this would be twice as
77 large. (400 - 31)/2 == 184 */
78 #define MAX_AGENT_EXPR_LEN 184
80 /* A hook used to notify the UI of tracepoint operations. */
82 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
83 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
88 This module defines the following debugger commands:
89 trace : set a tracepoint on a function, line, or address.
90 info trace : list all debugger-defined tracepoints.
91 delete trace : delete one or more tracepoints.
92 enable trace : enable one or more tracepoints.
93 disable trace : disable one or more tracepoints.
94 actions : specify actions to be taken at a tracepoint.
95 passcount : specify a pass count for a tracepoint.
96 tstart : start a trace experiment.
97 tstop : stop a trace experiment.
98 tstatus : query the status of a trace experiment.
99 tfind : find a trace frame in the trace buffer.
100 tdump : print everything collected at the current tracepoint.
101 save-tracepoints : write tracepoint setup into a file.
103 This module defines the following user-visible debugger variables:
104 $trace_frame : sequence number of trace frame currently being debugged.
105 $trace_line : source line of trace frame currently being debugged.
106 $trace_file : source file of trace frame currently being debugged.
107 $tracepoint : tracepoint number of trace frame currently being debugged.
111 /* ======= Important global variables: ======= */
113 /* The list of all trace state variables. We don't retain pointers to
114 any of these for any reason - API is by name or number only - so it
115 works to have a vector of objects. */
117 typedef struct trace_state_variable tsv_s
;
120 static VEC(tsv_s
) *tvariables
;
122 /* The next integer to assign to a variable. */
124 static int next_tsv_number
= 1;
126 /* Number of last traceframe collected. */
127 static int traceframe_number
;
129 /* Tracepoint for last traceframe collected. */
130 static int tracepoint_number
;
132 /* The traceframe info of the current traceframe. NULL if we haven't
133 yet attempted to fetch it, or if the target does not support
134 fetching this object, or if we're not inspecting a traceframe
136 static struct traceframe_info
*current_traceframe_info
;
138 /* Tracing command lists. */
139 static struct cmd_list_element
*tfindlist
;
141 /* List of expressions to collect by default at each tracepoint hit. */
142 char *default_collect
;
144 static int disconnected_tracing
;
146 /* This variable controls whether we ask the target for a linear or
147 circular trace buffer. */
149 static int circular_trace_buffer
;
151 /* This variable is the requested trace buffer size, or -1 to indicate
152 that we don't care and leave it up to the target to set a size. */
154 static int trace_buffer_size
= -1;
156 /* Textual notes applying to the current and/or future trace runs. */
158 char *trace_user
= NULL
;
160 /* Textual notes applying to the current and/or future trace runs. */
162 char *trace_notes
= NULL
;
164 /* Textual notes applying to the stopping of a trace. */
166 char *trace_stop_notes
= NULL
;
168 /* support routines */
170 struct collection_list
;
171 static char *mem2hex (gdb_byte
*, char *, int);
173 static struct command_line
*
174 all_tracepoint_actions_and_cleanup (struct breakpoint
*t
);
176 static struct trace_status trace_status
;
178 const char *stop_reason_names
[] = {
188 struct trace_status
*
189 current_trace_status (void)
191 return &trace_status
;
197 free_traceframe_info (struct traceframe_info
*info
)
202 /* Free and clear the traceframe info cache of the current
206 clear_traceframe_info (void)
208 free_traceframe_info (current_traceframe_info
);
209 current_traceframe_info
= NULL
;
212 /* Set traceframe number to NUM. */
214 set_traceframe_num (int num
)
216 traceframe_number
= num
;
217 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
220 /* Set tracepoint number to NUM. */
222 set_tracepoint_num (int num
)
224 tracepoint_number
= num
;
225 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
228 /* Set externally visible debug variables for querying/printing
229 the traceframe context (line, function, file). */
232 set_traceframe_context (struct frame_info
*trace_frame
)
235 struct symbol
*traceframe_fun
;
236 symtab_and_line traceframe_sal
;
238 /* Save as globals for internal use. */
239 if (trace_frame
!= NULL
240 && get_frame_pc_if_available (trace_frame
, &trace_pc
))
242 traceframe_sal
= find_pc_line (trace_pc
, 0);
243 traceframe_fun
= find_pc_function (trace_pc
);
245 /* Save linenumber as "$trace_line", a debugger variable visible to
247 set_internalvar_integer (lookup_internalvar ("trace_line"),
248 traceframe_sal
.line
);
252 traceframe_fun
= NULL
;
253 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
256 /* Save func name as "$trace_func", a debugger variable visible to
258 if (traceframe_fun
== NULL
259 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
260 clear_internalvar (lookup_internalvar ("trace_func"));
262 set_internalvar_string (lookup_internalvar ("trace_func"),
263 SYMBOL_LINKAGE_NAME (traceframe_fun
));
265 /* Save file name as "$trace_file", a debugger variable visible to
267 if (traceframe_sal
.symtab
== NULL
)
268 clear_internalvar (lookup_internalvar ("trace_file"));
270 set_internalvar_string (lookup_internalvar ("trace_file"),
271 symtab_to_filename_for_display (traceframe_sal
.symtab
));
274 /* Create a new trace state variable with the given name. */
276 struct trace_state_variable
*
277 create_trace_state_variable (const char *name
)
279 struct trace_state_variable tsv
;
281 memset (&tsv
, 0, sizeof (tsv
));
282 tsv
.name
= xstrdup (name
);
283 tsv
.number
= next_tsv_number
++;
284 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
287 /* Look for a trace state variable of the given name. */
289 struct trace_state_variable
*
290 find_trace_state_variable (const char *name
)
292 struct trace_state_variable
*tsv
;
295 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
296 if (strcmp (name
, tsv
->name
) == 0)
302 /* Look for a trace state variable of the given number. Return NULL if
305 struct trace_state_variable
*
306 find_trace_state_variable_by_number (int number
)
308 struct trace_state_variable
*tsv
;
311 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
312 if (tsv
->number
== number
)
319 delete_trace_state_variable (const char *name
)
321 struct trace_state_variable
*tsv
;
324 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
325 if (strcmp (name
, tsv
->name
) == 0)
327 observer_notify_tsv_deleted (tsv
);
329 xfree ((void *)tsv
->name
);
330 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
335 warning (_("No trace variable named \"$%s\", not deleting"), name
);
338 /* Throws an error if NAME is not valid syntax for a trace state
342 validate_trace_state_variable_name (const char *name
)
347 error (_("Must supply a non-empty variable name"));
349 /* All digits in the name is reserved for value history
351 for (p
= name
; isdigit (*p
); p
++)
354 error (_("$%s is not a valid trace state variable name"), name
);
356 for (p
= name
; isalnum (*p
) || *p
== '_'; p
++)
359 error (_("$%s is not a valid trace state variable name"), name
);
362 /* The 'tvariable' command collects a name and optional expression to
363 evaluate into an initial value. */
366 trace_variable_command (char *args
, int from_tty
)
369 struct trace_state_variable
*tsv
;
370 char *name_start
, *p
;
373 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
375 /* Only allow two syntaxes; "$name" and "$name=value". */
376 p
= skip_spaces (args
);
379 error (_("Name of trace variable should start with '$'"));
382 while (isalnum (*p
) || *p
== '_')
384 std::string
name (name_start
, p
- name_start
);
387 if (*p
!= '=' && *p
!= '\0')
388 error (_("Syntax must be $NAME [ = EXPR ]"));
390 validate_trace_state_variable_name (name
.c_str ());
393 initval
= value_as_long (parse_and_eval (++p
));
395 /* If the variable already exists, just change its initial value. */
396 tsv
= find_trace_state_variable (name
.c_str ());
399 if (tsv
->initial_value
!= initval
)
401 tsv
->initial_value
= initval
;
402 observer_notify_tsv_modified (tsv
);
404 printf_filtered (_("Trace state variable $%s "
405 "now has initial value %s.\n"),
406 tsv
->name
, plongest (tsv
->initial_value
));
410 /* Create a new variable. */
411 tsv
= create_trace_state_variable (name
.c_str ());
412 tsv
->initial_value
= initval
;
414 observer_notify_tsv_created (tsv
);
416 printf_filtered (_("Trace state variable $%s "
417 "created, with initial value %s.\n"),
418 tsv
->name
, plongest (tsv
->initial_value
));
422 delete_trace_variable_command (const char *args
, int from_tty
)
426 if (query (_("Delete all trace state variables? ")))
427 VEC_free (tsv_s
, tvariables
);
429 observer_notify_tsv_deleted (NULL
);
433 gdb_argv
argv (args
);
435 for (char *arg
: argv
)
438 delete_trace_state_variable (arg
+ 1);
440 warning (_("Name \"%s\" not prefixed with '$', ignoring"), arg
);
447 tvariables_info_1 (void)
449 struct trace_state_variable
*tsv
;
452 struct ui_out
*uiout
= current_uiout
;
454 if (VEC_length (tsv_s
, tvariables
) == 0 && !uiout
->is_mi_like_p ())
456 printf_filtered (_("No trace state variables.\n"));
460 /* Try to acquire values from the target. */
461 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
, ++count
)
462 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
465 ui_out_emit_table
table_emitter (uiout
, 3, count
, "trace-variables");
466 uiout
->table_header (15, ui_left
, "name", "Name");
467 uiout
->table_header (11, ui_left
, "initial", "Initial");
468 uiout
->table_header (11, ui_left
, "current", "Current");
470 uiout
->table_body ();
472 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
476 ui_out_emit_tuple
tuple_emitter (uiout
, "variable");
478 std::string name
= std::string ("$") + tsv
->name
;
479 uiout
->field_string ("name", name
.c_str ());
480 uiout
->field_string ("initial", plongest (tsv
->initial_value
));
482 if (tsv
->value_known
)
483 c
= plongest (tsv
->value
);
484 else if (uiout
->is_mi_like_p ())
485 /* For MI, we prefer not to use magic string constants, but rather
486 omit the field completely. The difference between unknown and
487 undefined does not seem important enough to represent. */
489 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
490 /* The value is/was defined, but we don't have it. */
493 /* It is not meaningful to ask about the value. */
496 uiout
->field_string ("current", c
);
501 /* List all the trace state variables. */
504 info_tvariables_command (char *args
, int from_tty
)
506 tvariables_info_1 ();
509 /* Stash definitions of tsvs into the given file. */
512 save_trace_state_variables (struct ui_file
*fp
)
514 struct trace_state_variable
*tsv
;
517 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
519 fprintf_unfiltered (fp
, "tvariable $%s", tsv
->name
);
520 if (tsv
->initial_value
)
521 fprintf_unfiltered (fp
, " = %s", plongest (tsv
->initial_value
));
522 fprintf_unfiltered (fp
, "\n");
526 /* ACTIONS functions: */
528 /* The three functions:
529 collect_pseudocommand,
530 while_stepping_pseudocommand, and
531 end_actions_pseudocommand
532 are placeholders for "commands" that are actually ONLY to be used
533 within a tracepoint action list. If the actual function is ever called,
534 it means that somebody issued the "command" at the top level,
535 which is always an error. */
538 end_actions_pseudocommand (char *args
, int from_tty
)
540 error (_("This command cannot be used at the top level."));
544 while_stepping_pseudocommand (char *args
, int from_tty
)
546 error (_("This command can only be used in a tracepoint actions list."));
550 collect_pseudocommand (char *args
, int from_tty
)
552 error (_("This command can only be used in a tracepoint actions list."));
556 teval_pseudocommand (char *args
, int from_tty
)
558 error (_("This command can only be used in a tracepoint actions list."));
561 /* Parse any collection options, such as /s for strings. */
564 decode_agent_options (const char *exp
, int *trace_string
)
566 struct value_print_options opts
;
573 /* Call this to borrow the print elements default for collection
575 get_user_print_options (&opts
);
580 if (target_supports_string_tracing ())
582 /* Allow an optional decimal number giving an explicit maximum
583 string length, defaulting it to the "print elements" value;
584 so "collect/s80 mystr" gets at most 80 bytes of string. */
585 *trace_string
= opts
.print_max
;
587 if (*exp
>= '0' && *exp
<= '9')
588 *trace_string
= atoi (exp
);
589 while (*exp
>= '0' && *exp
<= '9')
593 error (_("Target does not support \"/s\" option for string tracing."));
596 error (_("Undefined collection format \"%c\"."), *exp
);
598 exp
= skip_spaces (exp
);
603 /* Enter a list of actions for a tracepoint. */
605 actions_command (char *args
, int from_tty
)
607 struct tracepoint
*t
;
609 t
= get_tracepoint_by_number (&args
, NULL
);
613 string_printf ("Enter actions for tracepoint %d, one per line.",
616 command_line_up l
= read_command_lines (&tmpbuf
[0], from_tty
, 1,
617 check_tracepoint_command
, t
);
618 breakpoint_set_commands (t
, std::move (l
));
620 /* else just return */
623 /* Report the results of checking the agent expression, as errors or
627 report_agent_reqs_errors (struct agent_expr
*aexpr
)
629 /* All of the "flaws" are serious bytecode generation issues that
630 should never occur. */
631 if (aexpr
->flaw
!= agent_flaw_none
)
632 internal_error (__FILE__
, __LINE__
, _("expression is malformed"));
634 /* If analysis shows a stack underflow, GDB must have done something
635 badly wrong in its bytecode generation. */
636 if (aexpr
->min_height
< 0)
637 internal_error (__FILE__
, __LINE__
,
638 _("expression has min height < 0"));
640 /* Issue this error if the stack is predicted to get too deep. The
641 limit is rather arbitrary; a better scheme might be for the
642 target to report how much stack it will have available. The
643 depth roughly corresponds to parenthesization, so a limit of 20
644 amounts to 20 levels of expression nesting, which is actually
645 a pretty big hairy expression. */
646 if (aexpr
->max_height
> 20)
647 error (_("Expression is too complicated."));
650 /* worker function */
652 validate_actionline (const char *line
, struct breakpoint
*b
)
654 struct cmd_list_element
*c
;
657 struct bp_location
*loc
;
658 struct tracepoint
*t
= (struct tracepoint
*) b
;
660 /* If EOF is typed, *line is NULL. */
664 p
= skip_spaces (line
);
666 /* Symbol lookup etc. */
667 if (*p
== '\0') /* empty line: just prompt for another line. */
670 if (*p
== '#') /* comment line */
673 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
675 error (_("`%s' is not a tracepoint action, or is ambiguous."), p
);
677 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
679 int trace_string
= 0;
682 p
= decode_agent_options (p
, &trace_string
);
685 { /* Repeat over a comma-separated list. */
686 QUIT
; /* Allow user to bail out with ^C. */
689 if (*p
== '$') /* Look for special pseudo-symbols. */
691 if (0 == strncasecmp ("reg", p
+ 1, 3)
692 || 0 == strncasecmp ("arg", p
+ 1, 3)
693 || 0 == strncasecmp ("loc", p
+ 1, 3)
694 || 0 == strncasecmp ("_ret", p
+ 1, 4)
695 || 0 == strncasecmp ("_sdata", p
+ 1, 6))
700 /* else fall thru, treat p as an expression and parse it! */
703 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
706 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
707 block_for_pc (loc
->address
), 1);
709 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
711 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
713 error (_("constant `%s' (value %s) "
714 "will not be collected."),
715 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
716 plongest (SYMBOL_VALUE (exp
->elts
[2].symbol
)));
718 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
)
719 == LOC_OPTIMIZED_OUT
)
721 error (_("`%s' is optimized away "
722 "and cannot be collected."),
723 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
727 /* We have something to collect, make sure that the expr to
728 bytecode translator can handle it and that it's not too
730 agent_expr_up aexpr
= gen_trace_for_expr (loc
->address
,
734 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
735 error (_("Expression is too complicated."));
737 ax_reqs (aexpr
.get ());
739 report_agent_reqs_errors (aexpr
.get ());
742 while (p
&& *p
++ == ',');
745 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
748 { /* Repeat over a comma-separated list. */
749 QUIT
; /* Allow user to bail out with ^C. */
753 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
757 /* Only expressions are allowed for this action. */
758 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
759 block_for_pc (loc
->address
), 1);
761 /* We have something to evaluate, make sure that the expr to
762 bytecode translator can handle it and that it's not too
764 agent_expr_up aexpr
= gen_eval_for_expr (loc
->address
, exp
.get ());
766 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
767 error (_("Expression is too complicated."));
769 ax_reqs (aexpr
.get ());
770 report_agent_reqs_errors (aexpr
.get ());
773 while (p
&& *p
++ == ',');
776 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
781 t
->step_count
= strtol (p
, &endp
, 0);
782 if (endp
== p
|| t
->step_count
== 0)
783 error (_("while-stepping step count `%s' is malformed."), line
);
787 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
791 error (_("`%s' is not a supported tracepoint action."), line
);
795 memrange_absolute
= -1
798 /* MEMRANGE functions: */
800 /* Compare memranges for std::sort. */
803 memrange_comp (const memrange
&a
, const memrange
&b
)
805 if (a
.type
== b
.type
)
807 if (a
.type
== memrange_absolute
)
808 return (bfd_vma
) a
.start
< (bfd_vma
) b
.start
;
810 return a
.start
< b
.start
;
813 return a
.type
< b
.type
;
816 /* Sort the memrange list using std::sort, and merge adjacent memranges. */
819 memrange_sortmerge (std::vector
<memrange
> &memranges
)
821 if (!memranges
.empty ())
825 std::sort (memranges
.begin (), memranges
.end (), memrange_comp
);
827 for (a
= 0, b
= 1; b
< memranges
.size (); b
++)
829 /* If memrange b overlaps or is adjacent to memrange a,
831 if (memranges
[a
].type
== memranges
[b
].type
832 && memranges
[b
].start
<= memranges
[a
].end
)
834 if (memranges
[b
].end
> memranges
[a
].end
)
835 memranges
[a
].end
= memranges
[b
].end
;
836 continue; /* next b, same a */
840 memranges
[a
] = memranges
[b
];
842 memranges
.resize (a
+ 1);
846 /* Add a register to a collection list. */
849 collection_list::add_register (unsigned int regno
)
852 printf_filtered ("collect register %d\n", regno
);
853 if (regno
>= (8 * sizeof (m_regs_mask
)))
854 error (_("Internal: register number %d too large for tracepoint"),
856 m_regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
859 /* Add a memrange to a collection list. */
862 collection_list::add_memrange (struct gdbarch
*gdbarch
,
863 int type
, bfd_signed_vma base
,
867 printf_filtered ("(%d,%s,%ld)\n", type
, paddress (gdbarch
, base
), len
);
869 /* type: memrange_absolute == memory, other n == basereg */
870 /* base: addr if memory, offset if reg relative. */
871 /* len: we actually save end (base + len) for convenience */
872 m_memranges
.emplace_back (type
, base
, base
+ len
);
874 if (type
!= memrange_absolute
) /* Better collect the base register! */
878 /* Add a symbol to a collection list. */
881 collection_list::collect_symbol (struct symbol
*sym
,
882 struct gdbarch
*gdbarch
,
883 long frame_regno
, long frame_offset
,
889 bfd_signed_vma offset
;
890 int treat_as_expr
= 0;
892 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
893 switch (SYMBOL_CLASS (sym
))
896 printf_filtered ("%s: don't know symbol class %d\n",
897 SYMBOL_PRINT_NAME (sym
),
901 printf_filtered ("constant %s (value %s) will not be collected.\n",
902 SYMBOL_PRINT_NAME (sym
), plongest (SYMBOL_VALUE (sym
)));
905 offset
= SYMBOL_VALUE_ADDRESS (sym
);
908 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
909 SYMBOL_PRINT_NAME (sym
), len
,
910 paddress (gdbarch
, offset
));
912 /* A struct may be a C++ class with static fields, go to general
913 expression handling. */
914 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
917 add_memrange (gdbarch
, memrange_absolute
, offset
, len
);
920 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
922 printf_filtered ("LOC_REG[parm] %s: ",
923 SYMBOL_PRINT_NAME (sym
));
925 /* Check for doubles stored in two registers. */
926 /* FIXME: how about larger types stored in 3 or more regs? */
927 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
928 len
> register_size (gdbarch
, reg
))
929 add_register (reg
+ 1);
932 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
933 printf_filtered (" (will not collect %s)\n",
934 SYMBOL_PRINT_NAME (sym
));
938 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
941 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
942 " from frame ptr reg %d\n",
943 SYMBOL_PRINT_NAME (sym
), len
,
944 paddress (gdbarch
, offset
), reg
);
946 add_memrange (gdbarch
, reg
, offset
, len
);
948 case LOC_REGPARM_ADDR
:
949 reg
= SYMBOL_VALUE (sym
);
953 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset %s"
955 SYMBOL_PRINT_NAME (sym
), len
,
956 paddress (gdbarch
, offset
), reg
);
958 add_memrange (gdbarch
, reg
, offset
, len
);
962 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
965 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
966 " from frame ptr reg %d\n",
967 SYMBOL_PRINT_NAME (sym
), len
,
968 paddress (gdbarch
, offset
), reg
);
970 add_memrange (gdbarch
, reg
, offset
, len
);
977 case LOC_OPTIMIZED_OUT
:
978 printf_filtered ("%s has been optimized out of existence.\n",
979 SYMBOL_PRINT_NAME (sym
));
987 /* Expressions are the most general case. */
990 agent_expr_up aexpr
= gen_trace_for_var (scope
, gdbarch
,
993 /* It can happen that the symbol is recorded as a computed
994 location, but it's been optimized away and doesn't actually
995 have a location expression. */
998 printf_filtered ("%s has been optimized out of existence.\n",
999 SYMBOL_PRINT_NAME (sym
));
1003 ax_reqs (aexpr
.get ());
1005 report_agent_reqs_errors (aexpr
.get ());
1007 /* Take care of the registers. */
1008 if (aexpr
->reg_mask_len
> 0)
1010 for (int ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1012 QUIT
; /* Allow user to bail out with ^C. */
1013 if (aexpr
->reg_mask
[ndx1
] != 0)
1015 /* Assume chars have 8 bits. */
1016 for (int ndx2
= 0; ndx2
< 8; ndx2
++)
1017 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1018 /* It's used -- record it. */
1019 add_register (ndx1
* 8 + ndx2
);
1024 add_aexpr (std::move (aexpr
));
1028 /* Data to be passed around in the calls to the locals and args
1031 struct add_local_symbols_data
1033 struct collection_list
*collect
;
1034 struct gdbarch
*gdbarch
;
1042 /* The callback for the locals and args iterators. */
1045 do_collect_symbol (const char *print_name
,
1049 struct add_local_symbols_data
*p
= (struct add_local_symbols_data
*) cb_data
;
1051 p
->collect
->collect_symbol (sym
, p
->gdbarch
, p
->frame_regno
,
1052 p
->frame_offset
, p
->pc
, p
->trace_string
);
1055 p
->collect
->add_wholly_collected (print_name
);
1059 collection_list::add_wholly_collected (const char *print_name
)
1061 m_wholly_collected
.push_back (print_name
);
1064 /* Add all locals (or args) symbols to collection list. */
1067 collection_list::add_local_symbols (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1068 long frame_regno
, long frame_offset
, int type
,
1071 const struct block
*block
;
1072 struct add_local_symbols_data cb_data
;
1074 cb_data
.collect
= this;
1075 cb_data
.gdbarch
= gdbarch
;
1077 cb_data
.frame_regno
= frame_regno
;
1078 cb_data
.frame_offset
= frame_offset
;
1080 cb_data
.trace_string
= trace_string
;
1084 block
= block_for_pc (pc
);
1087 warning (_("Can't collect locals; "
1088 "no symbol table info available.\n"));
1092 iterate_over_block_local_vars (block
, do_collect_symbol
, &cb_data
);
1093 if (cb_data
.count
== 0)
1094 warning (_("No locals found in scope."));
1098 pc
= get_pc_function_start (pc
);
1099 block
= block_for_pc (pc
);
1102 warning (_("Can't collect args; no symbol table info available."));
1106 iterate_over_block_arg_vars (block
, do_collect_symbol
, &cb_data
);
1107 if (cb_data
.count
== 0)
1108 warning (_("No args found in scope."));
1113 collection_list::add_static_trace_data ()
1116 printf_filtered ("collect static trace data\n");
1117 m_strace_data
= true;
1120 collection_list::collection_list ()
1122 m_strace_data (false)
1124 m_memranges
.reserve (128);
1125 m_aexprs
.reserve (128);
1128 /* Reduce a collection list to string form (for gdb protocol). */
1131 collection_list::stringify ()
1133 char temp_buf
[2048];
1136 char *(*str_list
)[];
1140 count
= 1 + 1 + m_memranges
.size () + m_aexprs
.size () + 1;
1141 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1146 printf_filtered ("\nCollecting static trace data\n");
1149 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1153 for (i
= sizeof (m_regs_mask
) - 1; i
> 0; i
--)
1154 if (m_regs_mask
[i
] != 0) /* Skip leading zeroes in regs_mask. */
1156 if (m_regs_mask
[i
] != 0) /* Prepare to send regs_mask to the stub. */
1159 printf_filtered ("\nCollecting registers (mask): 0x");
1164 QUIT
; /* Allow user to bail out with ^C. */
1166 printf_filtered ("%02X", m_regs_mask
[i
]);
1167 sprintf (end
, "%02X", m_regs_mask
[i
]);
1170 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1174 printf_filtered ("\n");
1175 if (!m_memranges
.empty () && info_verbose
)
1176 printf_filtered ("Collecting memranges: \n");
1177 for (i
= 0, count
= 0, end
= temp_buf
; i
< m_memranges
.size (); i
++)
1179 QUIT
; /* Allow user to bail out with ^C. */
1182 printf_filtered ("(%d, %s, %ld)\n",
1183 m_memranges
[i
].type
,
1184 paddress (target_gdbarch (),
1185 m_memranges
[i
].start
),
1186 (long) (m_memranges
[i
].end
1187 - m_memranges
[i
].start
));
1189 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1191 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1198 bfd_signed_vma length
1199 = m_memranges
[i
].end
- m_memranges
[i
].start
;
1201 /* The "%X" conversion specifier expects an unsigned argument,
1202 so passing -1 (memrange_absolute) to it directly gives you
1203 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1205 if (m_memranges
[i
].type
== memrange_absolute
)
1206 sprintf (end
, "M-1,%s,%lX", phex_nz (m_memranges
[i
].start
, 0),
1209 sprintf (end
, "M%X,%s,%lX", m_memranges
[i
].type
,
1210 phex_nz (m_memranges
[i
].start
, 0), (long) length
);
1213 count
+= strlen (end
);
1214 end
= temp_buf
+ count
;
1217 for (i
= 0; i
< m_aexprs
.size (); i
++)
1219 QUIT
; /* Allow user to bail out with ^C. */
1220 if ((count
+ 10 + 2 * m_aexprs
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1222 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1227 sprintf (end
, "X%08X,", m_aexprs
[i
]->len
);
1228 end
+= 10; /* 'X' + 8 hex digits + ',' */
1231 end
= mem2hex (m_aexprs
[i
]->buf
, end
, m_aexprs
[i
]->len
);
1232 count
+= 2 * m_aexprs
[i
]->len
;
1237 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1242 (*str_list
)[ndx
] = NULL
;
1253 /* Add the printed expression EXP to *LIST. */
1256 collection_list::append_exp (struct expression
*exp
)
1258 string_file tmp_stream
;
1260 print_expression (exp
, &tmp_stream
);
1262 m_computed
.push_back (std::move (tmp_stream
.string ()));
1266 collection_list::finish ()
1268 memrange_sortmerge (m_memranges
);
1272 encode_actions_1 (struct command_line
*action
,
1273 struct bp_location
*tloc
,
1275 LONGEST frame_offset
,
1276 struct collection_list
*collect
,
1277 struct collection_list
*stepping_list
)
1279 const char *action_exp
;
1281 struct value
*tempval
;
1282 struct cmd_list_element
*cmd
;
1284 for (; action
; action
= action
->next
)
1286 QUIT
; /* Allow user to bail out with ^C. */
1287 action_exp
= action
->line
;
1288 action_exp
= skip_spaces (action_exp
);
1290 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1292 error (_("Bad action list item: %s"), action_exp
);
1294 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1296 int trace_string
= 0;
1298 if (*action_exp
== '/')
1299 action_exp
= decode_agent_options (action_exp
, &trace_string
);
1302 { /* Repeat over a comma-separated list. */
1303 QUIT
; /* Allow user to bail out with ^C. */
1304 action_exp
= skip_spaces (action_exp
);
1306 if (0 == strncasecmp ("$reg", action_exp
, 4))
1308 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
1309 collect
->add_register (i
);
1310 action_exp
= strchr (action_exp
, ','); /* more? */
1312 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1314 collect
->add_local_symbols (target_gdbarch (),
1320 action_exp
= strchr (action_exp
, ','); /* more? */
1322 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1324 collect
->add_local_symbols (target_gdbarch (),
1330 action_exp
= strchr (action_exp
, ','); /* more? */
1332 else if (0 == strncasecmp ("$_ret", action_exp
, 5))
1335 = gen_trace_for_return_address (tloc
->address
,
1339 ax_reqs (aexpr
.get ());
1340 report_agent_reqs_errors (aexpr
.get ());
1342 /* take care of the registers */
1343 if (aexpr
->reg_mask_len
> 0)
1345 for (int ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1347 QUIT
; /* allow user to bail out with ^C */
1348 if (aexpr
->reg_mask
[ndx1
] != 0)
1350 /* assume chars have 8 bits */
1351 for (int ndx2
= 0; ndx2
< 8; ndx2
++)
1352 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1354 /* It's used -- record it. */
1355 collect
->add_register (ndx1
* 8 + ndx2
);
1361 collect
->add_aexpr (std::move (aexpr
));
1362 action_exp
= strchr (action_exp
, ','); /* more? */
1364 else if (0 == strncasecmp ("$_sdata", action_exp
, 7))
1366 collect
->add_static_trace_data ();
1367 action_exp
= strchr (action_exp
, ','); /* more? */
1373 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1374 block_for_pc (tloc
->address
),
1377 switch (exp
->elts
[0].opcode
)
1381 const char *name
= &exp
->elts
[2].string
;
1383 i
= user_reg_map_name_to_regnum (target_gdbarch (),
1384 name
, strlen (name
));
1386 internal_error (__FILE__
, __LINE__
,
1387 _("Register $%s not available"),
1390 printf_filtered ("OP_REGISTER: ");
1391 collect
->add_register (i
);
1396 /* Safe because we know it's a simple expression. */
1397 tempval
= evaluate_expression (exp
.get ());
1398 addr
= value_address (tempval
);
1399 /* Initialize the TYPE_LENGTH if it is a typedef. */
1400 check_typedef (exp
->elts
[1].type
);
1401 collect
->add_memrange (target_gdbarch (),
1402 memrange_absolute
, addr
,
1403 TYPE_LENGTH (exp
->elts
[1].type
));
1404 collect
->append_exp (exp
.get ());
1409 struct symbol
*sym
= exp
->elts
[2].symbol
;
1410 char_ptr name
= (char_ptr
) SYMBOL_NATURAL_NAME (sym
);
1412 collect
->collect_symbol (exp
->elts
[2].symbol
,
1418 collect
->add_wholly_collected (name
);
1422 default: /* Full-fledged expression. */
1423 agent_expr_up aexpr
= gen_trace_for_expr (tloc
->address
,
1427 ax_reqs (aexpr
.get ());
1429 report_agent_reqs_errors (aexpr
.get ());
1431 /* Take care of the registers. */
1432 if (aexpr
->reg_mask_len
> 0)
1434 for (int ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1436 QUIT
; /* Allow user to bail out with ^C. */
1437 if (aexpr
->reg_mask
[ndx1
] != 0)
1439 /* Assume chars have 8 bits. */
1440 for (int ndx2
= 0; ndx2
< 8; ndx2
++)
1441 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1443 /* It's used -- record it. */
1444 collect
->add_register (ndx1
* 8 + ndx2
);
1450 collect
->add_aexpr (std::move (aexpr
));
1451 collect
->append_exp (exp
.get ());
1456 while (action_exp
&& *action_exp
++ == ',');
1458 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1461 { /* Repeat over a comma-separated list. */
1462 QUIT
; /* Allow user to bail out with ^C. */
1463 action_exp
= skip_spaces (action_exp
);
1466 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1467 block_for_pc (tloc
->address
),
1470 agent_expr_up aexpr
= gen_eval_for_expr (tloc
->address
,
1473 ax_reqs (aexpr
.get ());
1474 report_agent_reqs_errors (aexpr
.get ());
1476 /* Even though we're not officially collecting, add
1477 to the collect list anyway. */
1478 collect
->add_aexpr (std::move (aexpr
));
1481 while (action_exp
&& *action_exp
++ == ',');
1483 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1485 /* We check against nested while-stepping when setting
1486 breakpoint action, so no way to run into nested
1488 gdb_assert (stepping_list
);
1490 encode_actions_1 (action
->body_list
[0], tloc
, frame_reg
,
1491 frame_offset
, stepping_list
, NULL
);
1494 error (_("Invalid tracepoint command '%s'"), action
->line
);
1498 /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST
1499 and STEPPING_LIST. */
1502 encode_actions (struct bp_location
*tloc
,
1503 struct collection_list
*tracepoint_list
,
1504 struct collection_list
*stepping_list
)
1506 struct command_line
*actions
;
1508 LONGEST frame_offset
;
1510 gdbarch_virtual_frame_pointer (tloc
->gdbarch
,
1511 tloc
->address
, &frame_reg
, &frame_offset
);
1513 actions
= all_tracepoint_actions_and_cleanup (tloc
->owner
);
1515 encode_actions_1 (actions
, tloc
, frame_reg
, frame_offset
,
1516 tracepoint_list
, stepping_list
);
1518 tracepoint_list
->finish ();
1519 stepping_list
->finish ();
1522 /* Render all actions into gdb protocol. */
1525 encode_actions_rsp (struct bp_location
*tloc
, char ***tdp_actions
,
1526 char ***stepping_actions
)
1528 struct collection_list tracepoint_list
, stepping_list
;
1530 *tdp_actions
= NULL
;
1531 *stepping_actions
= NULL
;
1533 encode_actions (tloc
, &tracepoint_list
, &stepping_list
);
1535 *tdp_actions
= tracepoint_list
.stringify ();
1536 *stepping_actions
= stepping_list
.stringify ();
1540 collection_list::add_aexpr (agent_expr_up aexpr
)
1542 m_aexprs
.push_back (std::move (aexpr
));
1546 process_tracepoint_on_disconnect (void)
1548 VEC(breakpoint_p
) *tp_vec
= NULL
;
1550 struct breakpoint
*b
;
1551 int has_pending_p
= 0;
1553 /* Check whether we still have pending tracepoint. If we have, warn the
1554 user that pending tracepoint will no longer work. */
1555 tp_vec
= all_tracepoints ();
1556 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1565 struct bp_location
*loc1
;
1567 for (loc1
= b
->loc
; loc1
; loc1
= loc1
->next
)
1569 if (loc1
->shlib_disabled
)
1580 VEC_free (breakpoint_p
, tp_vec
);
1583 warning (_("Pending tracepoints will not be resolved while"
1584 " GDB is disconnected\n"));
1587 /* Reset local state of tracing. */
1590 trace_reset_local_state (void)
1592 set_traceframe_num (-1);
1593 set_tracepoint_num (-1);
1594 set_traceframe_context (NULL
);
1595 clear_traceframe_info ();
1599 start_tracing (char *notes
)
1601 VEC(breakpoint_p
) *tp_vec
= NULL
;
1603 struct breakpoint
*b
;
1604 struct trace_state_variable
*tsv
;
1605 int any_enabled
= 0, num_to_download
= 0;
1608 tp_vec
= all_tracepoints ();
1610 /* No point in tracing without any tracepoints... */
1611 if (VEC_length (breakpoint_p
, tp_vec
) == 0)
1613 VEC_free (breakpoint_p
, tp_vec
);
1614 error (_("No tracepoints defined, not starting trace"));
1617 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1619 if (b
->enable_state
== bp_enabled
)
1622 if ((b
->type
== bp_fast_tracepoint
1623 ? may_insert_fast_tracepoints
1624 : may_insert_tracepoints
))
1627 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1628 (b
->type
== bp_fast_tracepoint
? "fast " : ""), b
->number
);
1633 if (target_supports_enable_disable_tracepoint ())
1634 warning (_("No tracepoints enabled"));
1637 /* No point in tracing with only disabled tracepoints that
1638 cannot be re-enabled. */
1639 VEC_free (breakpoint_p
, tp_vec
);
1640 error (_("No tracepoints enabled, not starting trace"));
1644 if (num_to_download
<= 0)
1646 VEC_free (breakpoint_p
, tp_vec
);
1647 error (_("No tracepoints that may be downloaded, not starting trace"));
1650 target_trace_init ();
1652 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1654 struct tracepoint
*t
= (struct tracepoint
*) b
;
1655 struct bp_location
*loc
;
1656 int bp_location_downloaded
= 0;
1658 /* Clear `inserted' flag. */
1659 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1662 if ((b
->type
== bp_fast_tracepoint
1663 ? !may_insert_fast_tracepoints
1664 : !may_insert_tracepoints
))
1667 t
->number_on_target
= 0;
1669 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1671 /* Since tracepoint locations are never duplicated, `inserted'
1672 flag should be zero. */
1673 gdb_assert (!loc
->inserted
);
1675 target_download_tracepoint (loc
);
1678 bp_location_downloaded
= 1;
1681 t
->number_on_target
= b
->number
;
1683 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1684 if (loc
->probe
.probe
!= NULL
1685 && loc
->probe
.probe
->pops
->set_semaphore
!= NULL
)
1686 loc
->probe
.probe
->pops
->set_semaphore (loc
->probe
.probe
,
1690 if (bp_location_downloaded
)
1691 observer_notify_breakpoint_modified (b
);
1693 VEC_free (breakpoint_p
, tp_vec
);
1695 /* Send down all the trace state variables too. */
1696 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1698 target_download_trace_state_variable (tsv
);
1701 /* Tell target to treat text-like sections as transparent. */
1702 target_trace_set_readonly_regions ();
1703 /* Set some mode flags. */
1704 target_set_disconnected_tracing (disconnected_tracing
);
1705 target_set_circular_trace_buffer (circular_trace_buffer
);
1706 target_set_trace_buffer_size (trace_buffer_size
);
1709 notes
= trace_notes
;
1710 ret
= target_set_trace_notes (trace_user
, notes
, NULL
);
1712 if (!ret
&& (trace_user
|| notes
))
1713 warning (_("Target does not support trace user/notes, info ignored"));
1715 /* Now insert traps and begin collecting data. */
1716 target_trace_start ();
1718 /* Reset our local state. */
1719 trace_reset_local_state ();
1720 current_trace_status()->running
= 1;
1723 /* The tstart command requests the target to start a new trace run.
1724 The command passes any arguments it has to the target verbatim, as
1725 an optional "trace note". This is useful as for instance a warning
1726 to other users if the trace runs disconnected, and you don't want
1727 anybody else messing with the target. */
1730 tstart_command (char *args
, int from_tty
)
1732 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1734 if (current_trace_status ()->running
)
1737 && !query (_("A trace is running already. Start a new run? ")))
1738 error (_("New trace run not started."));
1741 start_tracing (args
);
1744 /* The tstop command stops the tracing run. The command passes any
1745 supplied arguments to the target verbatim as a "stop note"; if the
1746 target supports trace notes, then it will be reported back as part
1747 of the trace run's status. */
1750 tstop_command (char *args
, int from_tty
)
1752 if (!current_trace_status ()->running
)
1753 error (_("Trace is not running."));
1755 stop_tracing (args
);
1759 stop_tracing (char *note
)
1762 VEC(breakpoint_p
) *tp_vec
= NULL
;
1764 struct breakpoint
*t
;
1766 target_trace_stop ();
1768 tp_vec
= all_tracepoints ();
1769 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1771 struct bp_location
*loc
;
1773 if ((t
->type
== bp_fast_tracepoint
1774 ? !may_insert_fast_tracepoints
1775 : !may_insert_tracepoints
))
1778 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
1780 /* GDB can be totally absent in some disconnected trace scenarios,
1781 but we don't really care if this semaphore goes out of sync.
1782 That's why we are decrementing it here, but not taking care
1784 if (loc
->probe
.probe
!= NULL
1785 && loc
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
1786 loc
->probe
.probe
->pops
->clear_semaphore (loc
->probe
.probe
,
1792 VEC_free (breakpoint_p
, tp_vec
);
1795 note
= trace_stop_notes
;
1796 ret
= target_set_trace_notes (NULL
, NULL
, note
);
1799 warning (_("Target does not support trace notes, note ignored"));
1801 /* Should change in response to reply? */
1802 current_trace_status ()->running
= 0;
1805 /* tstatus command */
1807 tstatus_command (char *args
, int from_tty
)
1809 struct trace_status
*ts
= current_trace_status ();
1811 VEC(breakpoint_p
) *tp_vec
= NULL
;
1812 struct breakpoint
*t
;
1814 status
= target_get_trace_status (ts
);
1818 if (ts
->filename
!= NULL
)
1819 printf_filtered (_("Using a trace file.\n"));
1822 printf_filtered (_("Trace can not be run on this target.\n"));
1827 if (!ts
->running_known
)
1829 printf_filtered (_("Run/stop status is unknown.\n"));
1831 else if (ts
->running
)
1833 printf_filtered (_("Trace is running on the target.\n"));
1837 switch (ts
->stop_reason
)
1839 case trace_never_run
:
1840 printf_filtered (_("No trace has been run on the target.\n"));
1842 case trace_stop_command
:
1844 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1847 printf_filtered (_("Trace stopped by a tstop command.\n"));
1849 case trace_buffer_full
:
1850 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1852 case trace_disconnected
:
1853 printf_filtered (_("Trace stopped because of disconnection.\n"));
1855 case tracepoint_passcount
:
1856 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1857 ts
->stopping_tracepoint
);
1859 case tracepoint_error
:
1860 if (ts
->stopping_tracepoint
)
1861 printf_filtered (_("Trace stopped by an "
1862 "error (%s, tracepoint %d).\n"),
1863 ts
->stop_desc
, ts
->stopping_tracepoint
);
1865 printf_filtered (_("Trace stopped by an error (%s).\n"),
1868 case trace_stop_reason_unknown
:
1869 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1872 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1878 if (ts
->traceframes_created
>= 0
1879 && ts
->traceframe_count
!= ts
->traceframes_created
)
1881 printf_filtered (_("Buffer contains %d trace "
1882 "frames (of %d created total).\n"),
1883 ts
->traceframe_count
, ts
->traceframes_created
);
1885 else if (ts
->traceframe_count
>= 0)
1887 printf_filtered (_("Collected %d trace frames.\n"),
1888 ts
->traceframe_count
);
1891 if (ts
->buffer_free
>= 0)
1893 if (ts
->buffer_size
>= 0)
1895 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1896 ts
->buffer_free
, ts
->buffer_size
);
1897 if (ts
->buffer_size
> 0)
1898 printf_filtered (_(" (%d%% full)"),
1899 ((int) ((((long long) (ts
->buffer_size
1900 - ts
->buffer_free
)) * 100)
1901 / ts
->buffer_size
)));
1902 printf_filtered (_(".\n"));
1905 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1909 if (ts
->disconnected_tracing
)
1910 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1912 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1914 if (ts
->circular_buffer
)
1915 printf_filtered (_("Trace buffer is circular.\n"));
1917 if (ts
->user_name
&& strlen (ts
->user_name
) > 0)
1918 printf_filtered (_("Trace user is %s.\n"), ts
->user_name
);
1920 if (ts
->notes
&& strlen (ts
->notes
) > 0)
1921 printf_filtered (_("Trace notes: %s.\n"), ts
->notes
);
1923 /* Now report on what we're doing with tfind. */
1924 if (traceframe_number
>= 0)
1925 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1926 traceframe_number
, tracepoint_number
);
1928 printf_filtered (_("Not looking at any trace frame.\n"));
1930 /* Report start/stop times if supplied. */
1935 LONGEST run_time
= ts
->stop_time
- ts
->start_time
;
1937 /* Reporting a run time is more readable than two long numbers. */
1938 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
1939 (long int) (ts
->start_time
/ 1000000),
1940 (long int) (ts
->start_time
% 1000000),
1941 (long int) (run_time
/ 1000000),
1942 (long int) (run_time
% 1000000));
1945 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
1946 (long int) (ts
->start_time
/ 1000000),
1947 (long int) (ts
->start_time
% 1000000));
1949 else if (ts
->stop_time
)
1950 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
1951 (long int) (ts
->stop_time
/ 1000000),
1952 (long int) (ts
->stop_time
% 1000000));
1954 /* Now report any per-tracepoint status available. */
1955 tp_vec
= all_tracepoints ();
1957 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1958 target_get_tracepoint_status (t
, NULL
);
1960 VEC_free (breakpoint_p
, tp_vec
);
1963 /* Report the trace status to uiout, in a way suitable for MI, and not
1964 suitable for CLI. If ON_STOP is true, suppress a few fields that
1965 are not meaningful in the -trace-stop response.
1967 The implementation is essentially parallel to trace_status_command, but
1968 merging them will result in unreadable code. */
1970 trace_status_mi (int on_stop
)
1972 struct ui_out
*uiout
= current_uiout
;
1973 struct trace_status
*ts
= current_trace_status ();
1976 status
= target_get_trace_status (ts
);
1978 if (status
== -1 && ts
->filename
== NULL
)
1980 uiout
->field_string ("supported", "0");
1984 if (ts
->filename
!= NULL
)
1985 uiout
->field_string ("supported", "file");
1987 uiout
->field_string ("supported", "1");
1989 if (ts
->filename
!= NULL
)
1990 uiout
->field_string ("trace-file", ts
->filename
);
1992 gdb_assert (ts
->running_known
);
1996 uiout
->field_string ("running", "1");
1998 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
1999 Given that the frontend gets the status either on -trace-stop, or from
2000 -trace-status after re-connection, it does not seem like this
2001 information is necessary for anything. It is not necessary for either
2002 figuring the vital state of the target nor for navigation of trace
2003 frames. If the frontend wants to show the current state is some
2004 configure dialog, it can request the value when such dialog is
2005 invoked by the user. */
2009 const char *stop_reason
= NULL
;
2010 int stopping_tracepoint
= -1;
2013 uiout
->field_string ("running", "0");
2015 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
2017 switch (ts
->stop_reason
)
2019 case trace_stop_command
:
2020 stop_reason
= "request";
2022 case trace_buffer_full
:
2023 stop_reason
= "overflow";
2025 case trace_disconnected
:
2026 stop_reason
= "disconnection";
2028 case tracepoint_passcount
:
2029 stop_reason
= "passcount";
2030 stopping_tracepoint
= ts
->stopping_tracepoint
;
2032 case tracepoint_error
:
2033 stop_reason
= "error";
2034 stopping_tracepoint
= ts
->stopping_tracepoint
;
2040 uiout
->field_string ("stop-reason", stop_reason
);
2041 if (stopping_tracepoint
!= -1)
2042 uiout
->field_int ("stopping-tracepoint",
2043 stopping_tracepoint
);
2044 if (ts
->stop_reason
== tracepoint_error
)
2045 uiout
->field_string ("error-description",
2051 if (ts
->traceframe_count
!= -1)
2052 uiout
->field_int ("frames", ts
->traceframe_count
);
2053 if (ts
->traceframes_created
!= -1)
2054 uiout
->field_int ("frames-created", ts
->traceframes_created
);
2055 if (ts
->buffer_size
!= -1)
2056 uiout
->field_int ("buffer-size", ts
->buffer_size
);
2057 if (ts
->buffer_free
!= -1)
2058 uiout
->field_int ("buffer-free", ts
->buffer_free
);
2060 uiout
->field_int ("disconnected", ts
->disconnected_tracing
);
2061 uiout
->field_int ("circular", ts
->circular_buffer
);
2063 uiout
->field_string ("user-name", ts
->user_name
);
2064 uiout
->field_string ("notes", ts
->notes
);
2069 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2070 (long int) (ts
->start_time
/ 1000000),
2071 (long int) (ts
->start_time
% 1000000));
2072 uiout
->field_string ("start-time", buf
);
2073 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2074 (long int) (ts
->stop_time
/ 1000000),
2075 (long int) (ts
->stop_time
% 1000000));
2076 uiout
->field_string ("stop-time", buf
);
2080 /* Check if a trace run is ongoing. If so, and FROM_TTY, query the
2081 user if she really wants to detach. */
2084 query_if_trace_running (int from_tty
)
2089 /* It can happen that the target that was tracing went away on its
2090 own, and we didn't notice. Get a status update, and if the
2091 current target doesn't even do tracing, then assume it's not
2093 if (target_get_trace_status (current_trace_status ()) < 0)
2094 current_trace_status ()->running
= 0;
2096 /* If running interactively, give the user the option to cancel and
2097 then decide what to do differently with the run. Scripts are
2098 just going to disconnect and let the target deal with it,
2099 according to how it's been instructed previously via
2100 disconnected-tracing. */
2101 if (current_trace_status ()->running
)
2103 process_tracepoint_on_disconnect ();
2105 if (current_trace_status ()->disconnected_tracing
)
2107 if (!query (_("Trace is running and will "
2108 "continue after detach; detach anyway? ")))
2109 error (_("Not confirmed."));
2113 if (!query (_("Trace is running but will "
2114 "stop on detach; detach anyway? ")))
2115 error (_("Not confirmed."));
2120 /* This function handles the details of what to do about an ongoing
2121 tracing run if the user has asked to detach or otherwise disconnect
2125 disconnect_tracing (void)
2127 /* Also we want to be out of tfind mode, otherwise things can get
2128 confusing upon reconnection. Just use these calls instead of
2129 full tfind_1 behavior because we're in the middle of detaching,
2130 and there's no point to updating current stack frame etc. */
2131 trace_reset_local_state ();
2134 /* Worker function for the various flavors of the tfind command. */
2136 tfind_1 (enum trace_find_type type
, int num
,
2137 CORE_ADDR addr1
, CORE_ADDR addr2
,
2140 int target_frameno
= -1, target_tracept
= -1;
2141 struct frame_id old_frame_id
= null_frame_id
;
2142 struct tracepoint
*tp
;
2143 struct ui_out
*uiout
= current_uiout
;
2145 /* Only try to get the current stack frame if we have a chance of
2146 succeeding. In particular, if we're trying to get a first trace
2147 frame while all threads are running, it's not going to succeed,
2148 so leave it with a default value and let the frame comparison
2149 below (correctly) decide to print out the source location of the
2151 if (!(type
== tfind_number
&& num
== -1)
2152 && (has_stack_frames () || traceframe_number
>= 0))
2153 old_frame_id
= get_frame_id (get_current_frame ());
2155 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
2158 if (type
== tfind_number
2160 && target_frameno
== -1)
2162 /* We told the target to get out of tfind mode, and it did. */
2164 else if (target_frameno
== -1)
2166 /* A request for a non-existent trace frame has failed.
2167 Our response will be different, depending on FROM_TTY:
2169 If FROM_TTY is true, meaning that this command was
2170 typed interactively by the user, then give an error
2171 and DO NOT change the state of traceframe_number etc.
2173 However if FROM_TTY is false, meaning that we're either
2174 in a script, a loop, or a user-defined command, then
2175 DON'T give an error, but DO change the state of
2176 traceframe_number etc. to invalid.
2178 The rationalle is that if you typed the command, you
2179 might just have committed a typo or something, and you'd
2180 like to NOT lose your current debugging state. However
2181 if you're in a user-defined command or especially in a
2182 loop, then you need a way to detect that the command
2183 failed WITHOUT aborting. This allows you to write
2184 scripts that search thru the trace buffer until the end,
2185 and then continue on to do something else. */
2188 error (_("Target failed to find requested trace frame."));
2192 printf_filtered ("End of trace buffer.\n");
2193 #if 0 /* dubious now? */
2194 /* The following will not recurse, since it's
2196 tfind_command ("-1", from_tty
);
2201 tp
= get_tracepoint_by_number_on_target (target_tracept
);
2203 reinit_frame_cache ();
2204 target_dcache_invalidate ();
2206 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
2208 if (target_frameno
!= get_traceframe_number ())
2209 observer_notify_traceframe_changed (target_frameno
, tracepoint_number
);
2211 set_current_traceframe (target_frameno
);
2213 if (target_frameno
== -1)
2214 set_traceframe_context (NULL
);
2216 set_traceframe_context (get_current_frame ());
2218 if (traceframe_number
>= 0)
2220 /* Use different branches for MI and CLI to make CLI messages
2222 if (uiout
->is_mi_like_p ())
2224 uiout
->field_string ("found", "1");
2225 uiout
->field_int ("tracepoint", tracepoint_number
);
2226 uiout
->field_int ("traceframe", traceframe_number
);
2230 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2231 traceframe_number
, tracepoint_number
);
2236 if (uiout
->is_mi_like_p ())
2237 uiout
->field_string ("found", "0");
2238 else if (type
== tfind_number
&& num
== -1)
2239 printf_unfiltered (_("No longer looking at any trace frame\n"));
2240 else /* This case may never occur, check. */
2241 printf_unfiltered (_("No trace frame found\n"));
2244 /* If we're in nonstop mode and getting out of looking at trace
2245 frames, there won't be any current frame to go back to and
2248 && (has_stack_frames () || traceframe_number
>= 0))
2250 enum print_what print_what
;
2252 /* NOTE: in imitation of the step command, try to determine
2253 whether we have made a transition from one function to
2254 another. If so, we'll print the "stack frame" (ie. the new
2255 function and it's arguments) -- otherwise we'll just show the
2258 if (frame_id_eq (old_frame_id
,
2259 get_frame_id (get_current_frame ())))
2260 print_what
= SRC_LINE
;
2262 print_what
= SRC_AND_LOC
;
2264 print_stack_frame (get_selected_frame (NULL
), 1, print_what
, 1);
2269 /* Error on looking at traceframes while trace is running. */
2272 check_trace_running (struct trace_status
*status
)
2274 if (status
->running
&& status
->filename
== NULL
)
2275 error (_("May not look at trace frames while trace is running."));
2278 /* trace_find_command takes a trace frame number n,
2279 sends "QTFrame:<n>" to the target,
2280 and accepts a reply that may contain several optional pieces
2281 of information: a frame number, a tracepoint number, and an
2282 indication of whether this is a trap frame or a stepping frame.
2284 The minimal response is just "OK" (which indicates that the
2285 target does not give us a frame number or a tracepoint number).
2286 Instead of that, the target may send us a string containing
2288 F<hexnum> (gives the selected frame number)
2289 T<hexnum> (gives the selected tracepoint number)
2294 tfind_command_1 (const char *args
, int from_tty
)
2295 { /* This should only be called with a numeric argument. */
2298 check_trace_running (current_trace_status ());
2300 if (args
== 0 || *args
== 0)
2301 { /* TFIND with no args means find NEXT trace frame. */
2302 if (traceframe_number
== -1)
2303 frameno
= 0; /* "next" is first one. */
2305 frameno
= traceframe_number
+ 1;
2307 else if (0 == strcmp (args
, "-"))
2309 if (traceframe_number
== -1)
2310 error (_("not debugging trace buffer"));
2311 else if (from_tty
&& traceframe_number
== 0)
2312 error (_("already at start of trace buffer"));
2314 frameno
= traceframe_number
- 1;
2316 /* A hack to work around eval's need for fp to have been collected. */
2317 else if (0 == strcmp (args
, "-1"))
2320 frameno
= parse_and_eval_long (args
);
2323 error (_("invalid input (%d is less than zero)"), frameno
);
2325 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
2329 tfind_command (const char *args
, int from_tty
)
2331 tfind_command_1 (const_cast<char *> (args
), from_tty
);
2336 tfind_end_command (const char *args
, int from_tty
)
2338 tfind_command_1 ("-1", from_tty
);
2343 tfind_start_command (const char *args
, int from_tty
)
2345 tfind_command_1 ("0", from_tty
);
2348 /* tfind pc command */
2350 tfind_pc_command (const char *args
, int from_tty
)
2354 check_trace_running (current_trace_status ());
2356 if (args
== 0 || *args
== 0)
2357 pc
= regcache_read_pc (get_current_regcache ());
2359 pc
= parse_and_eval_address (args
);
2361 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
2364 /* tfind tracepoint command */
2366 tfind_tracepoint_command (const char *args
, int from_tty
)
2369 struct tracepoint
*tp
;
2371 check_trace_running (current_trace_status ());
2373 if (args
== 0 || *args
== 0)
2375 if (tracepoint_number
== -1)
2376 error (_("No current tracepoint -- please supply an argument."));
2378 tdp
= tracepoint_number
; /* Default is current TDP. */
2381 tdp
= parse_and_eval_long (args
);
2383 /* If we have the tracepoint on hand, use the number that the
2384 target knows about (which may be different if we disconnected
2385 and reconnected). */
2386 tp
= get_tracepoint (tdp
);
2388 tdp
= tp
->number_on_target
;
2390 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
2393 /* TFIND LINE command:
2395 This command will take a sourceline for argument, just like BREAK
2396 or TRACE (ie. anything that "decode_line_1" can handle).
2398 With no argument, this command will find the next trace frame
2399 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2402 tfind_line_command (const char *args
, int from_tty
)
2404 check_trace_running (current_trace_status ());
2406 symtab_and_line sal
;
2407 if (args
== 0 || *args
== 0)
2409 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2413 std::vector
<symtab_and_line
> sals
2414 = decode_line_with_current_source (args
, DECODE_LINE_FUNFIRSTLINE
);
2418 if (sal
.symtab
== 0)
2419 error (_("No line number information available."));
2421 CORE_ADDR start_pc
, end_pc
;
2422 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2424 if (start_pc
== end_pc
)
2426 printf_filtered ("Line %d of \"%s\"",
2428 symtab_to_filename_for_display (sal
.symtab
));
2430 printf_filtered (" is at address ");
2431 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2433 printf_filtered (" but contains no code.\n");
2434 sal
= find_pc_line (start_pc
, 0);
2436 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2437 && start_pc
!= end_pc
)
2438 printf_filtered ("Attempting to find line %d instead.\n",
2441 error (_("Cannot find a good line."));
2445 /* Is there any case in which we get here, and have an address
2446 which the user would want to see? If we have debugging
2447 symbols and no line numbers? */
2448 error (_("Line number %d is out of range for \"%s\"."),
2449 sal
.line
, symtab_to_filename_for_display (sal
.symtab
));
2451 /* Find within range of stated line. */
2453 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2455 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2458 /* tfind range command */
2460 tfind_range_command (const char *args
, int from_tty
)
2462 static CORE_ADDR start
, stop
;
2465 check_trace_running (current_trace_status ());
2467 if (args
== 0 || *args
== 0)
2468 { /* XXX FIXME: what should default behavior be? */
2469 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2473 if (0 != (tmp
= strchr (args
, ',')))
2475 std::string
start_addr (args
, tmp
);
2477 tmp
= skip_spaces (tmp
);
2478 start
= parse_and_eval_address (start_addr
.c_str ());
2479 stop
= parse_and_eval_address (tmp
);
2482 { /* No explicit end address? */
2483 start
= parse_and_eval_address (args
);
2484 stop
= start
+ 1; /* ??? */
2487 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2490 /* tfind outside command */
2492 tfind_outside_command (const char *args
, int from_tty
)
2494 CORE_ADDR start
, stop
;
2497 if (current_trace_status ()->running
2498 && current_trace_status ()->filename
== NULL
)
2499 error (_("May not look at trace frames while trace is running."));
2501 if (args
== 0 || *args
== 0)
2502 { /* XXX FIXME: what should default behavior be? */
2503 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2507 if (0 != (tmp
= strchr (args
, ',')))
2509 std::string
start_addr (args
, tmp
);
2511 tmp
= skip_spaces (tmp
);
2512 start
= parse_and_eval_address (start_addr
.c_str ());
2513 stop
= parse_and_eval_address (tmp
);
2516 { /* No explicit end address? */
2517 start
= parse_and_eval_address (args
);
2518 stop
= start
+ 1; /* ??? */
2521 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2524 /* info scope command: list the locals for a scope. */
2526 info_scope_command (char *args_in
, int from_tty
)
2529 struct bound_minimal_symbol msym
;
2530 const struct block
*block
;
2531 const char *symname
;
2532 const char *save_args
= args_in
;
2533 struct block_iterator iter
;
2535 struct gdbarch
*gdbarch
;
2537 const char *args
= args_in
;
2539 if (args
== 0 || *args
== 0)
2540 error (_("requires an argument (function, "
2541 "line or *addr) to define a scope"));
2543 event_location_up location
= string_to_event_location (&args
,
2545 std::vector
<symtab_and_line
> sals
2546 = decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
2550 /* Presumably decode_line_1 has already warned. */
2554 /* Resolve line numbers to PC. */
2555 resolve_sal_pc (&sals
[0]);
2556 block
= block_for_pc (sals
[0].pc
);
2560 QUIT
; /* Allow user to bail out with ^C. */
2561 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2563 QUIT
; /* Allow user to bail out with ^C. */
2565 printf_filtered ("Scope for %s:\n", save_args
);
2568 symname
= SYMBOL_PRINT_NAME (sym
);
2569 if (symname
== NULL
|| *symname
== '\0')
2570 continue; /* Probably botched, certainly useless. */
2572 gdbarch
= symbol_arch (sym
);
2574 printf_filtered ("Symbol %s is ", symname
);
2576 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
2577 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
,
2578 BLOCK_START (block
),
2582 switch (SYMBOL_CLASS (sym
))
2585 case LOC_UNDEF
: /* Messed up symbol? */
2586 printf_filtered ("a bogus symbol, class %d.\n",
2587 SYMBOL_CLASS (sym
));
2588 count
--; /* Don't count this one. */
2591 printf_filtered ("a constant with value %s (%s)",
2592 plongest (SYMBOL_VALUE (sym
)),
2593 hex_string (SYMBOL_VALUE (sym
)));
2595 case LOC_CONST_BYTES
:
2596 printf_filtered ("constant bytes: ");
2597 if (SYMBOL_TYPE (sym
))
2598 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2599 fprintf_filtered (gdb_stdout
, " %02x",
2600 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2603 printf_filtered ("in static storage at address ");
2604 printf_filtered ("%s", paddress (gdbarch
,
2605 SYMBOL_VALUE_ADDRESS (sym
)));
2608 /* GDBARCH is the architecture associated with the objfile
2609 the symbol is defined in; the target architecture may be
2610 different, and may provide additional registers. However,
2611 we do not know the target architecture at this point.
2612 We assume the objfile architecture will contain all the
2613 standard registers that occur in debug info in that
2615 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2618 if (SYMBOL_IS_ARGUMENT (sym
))
2619 printf_filtered ("an argument in register $%s",
2620 gdbarch_register_name (gdbarch
, regno
));
2622 printf_filtered ("a local variable in register $%s",
2623 gdbarch_register_name (gdbarch
, regno
));
2626 printf_filtered ("an argument at stack/frame offset %s",
2627 plongest (SYMBOL_VALUE (sym
)));
2630 printf_filtered ("a local variable at frame offset %s",
2631 plongest (SYMBOL_VALUE (sym
)));
2634 printf_filtered ("a reference argument at offset %s",
2635 plongest (SYMBOL_VALUE (sym
)));
2637 case LOC_REGPARM_ADDR
:
2638 /* Note comment at LOC_REGISTER. */
2639 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2641 printf_filtered ("the address of an argument, in register $%s",
2642 gdbarch_register_name (gdbarch
, regno
));
2645 printf_filtered ("a typedef.\n");
2648 printf_filtered ("a label at address ");
2649 printf_filtered ("%s", paddress (gdbarch
,
2650 SYMBOL_VALUE_ADDRESS (sym
)));
2653 printf_filtered ("a function at address ");
2654 printf_filtered ("%s",
2655 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2657 case LOC_UNRESOLVED
:
2658 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2660 if (msym
.minsym
== NULL
)
2661 printf_filtered ("Unresolved Static");
2664 printf_filtered ("static storage at address ");
2665 printf_filtered ("%s",
2667 BMSYMBOL_VALUE_ADDRESS (msym
)));
2670 case LOC_OPTIMIZED_OUT
:
2671 printf_filtered ("optimized out.\n");
2674 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2677 if (SYMBOL_TYPE (sym
))
2678 printf_filtered (", length %d.\n",
2679 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2681 if (BLOCK_FUNCTION (block
))
2684 block
= BLOCK_SUPERBLOCK (block
);
2687 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2691 /* Helper for trace_dump_command. Dump the action list starting at
2692 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2693 actions of the body of a while-stepping action. STEPPING_FRAME is
2694 set if the current traceframe was determined to be a while-stepping
2698 trace_dump_actions (struct command_line
*action
,
2699 int stepping_actions
, int stepping_frame
,
2702 const char *action_exp
, *next_comma
;
2704 for (; action
!= NULL
; action
= action
->next
)
2706 struct cmd_list_element
*cmd
;
2708 QUIT
; /* Allow user to bail out with ^C. */
2709 action_exp
= action
->line
;
2710 action_exp
= skip_spaces (action_exp
);
2712 /* The collection actions to be done while stepping are
2713 bracketed by the commands "while-stepping" and "end". */
2715 if (*action_exp
== '#') /* comment line */
2718 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2720 error (_("Bad action list item: %s"), action_exp
);
2722 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2726 for (i
= 0; i
< action
->body_count
; ++i
)
2727 trace_dump_actions (action
->body_list
[i
],
2728 1, stepping_frame
, from_tty
);
2730 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2732 /* Display the collected data.
2733 For the trap frame, display only what was collected at
2734 the trap. Likewise for stepping frames, display only
2735 what was collected while stepping. This means that the
2736 two boolean variables, STEPPING_FRAME and
2737 STEPPING_ACTIONS should be equal. */
2738 if (stepping_frame
== stepping_actions
)
2741 struct cleanup
*old_chain
2742 = make_cleanup (free_current_contents
, &cmd
);
2743 int trace_string
= 0;
2745 if (*action_exp
== '/')
2746 action_exp
= decode_agent_options (action_exp
, &trace_string
);
2749 { /* Repeat over a comma-separated list. */
2750 QUIT
; /* Allow user to bail out with ^C. */
2751 if (*action_exp
== ',')
2753 action_exp
= skip_spaces (action_exp
);
2755 next_comma
= strchr (action_exp
, ',');
2757 if (0 == strncasecmp (action_exp
, "$reg", 4))
2758 registers_info (NULL
, from_tty
);
2759 else if (0 == strncasecmp (action_exp
, "$_ret", 5))
2761 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2762 info_locals_command (NULL
, from_tty
);
2763 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2764 info_args_command (NULL
, from_tty
);
2767 if (next_comma
!= NULL
)
2769 size_t len
= next_comma
- action_exp
;
2771 cmd
= (char *) xrealloc (cmd
, len
+ 1);
2772 memcpy (cmd
, action_exp
, len
);
2777 size_t len
= strlen (action_exp
);
2779 cmd
= (char *) xrealloc (cmd
, len
+ 1);
2780 memcpy (cmd
, action_exp
, len
+ 1);
2783 printf_filtered ("%s = ", cmd
);
2784 output_command_const (cmd
, from_tty
);
2785 printf_filtered ("\n");
2787 action_exp
= next_comma
;
2789 while (action_exp
&& *action_exp
== ',');
2791 do_cleanups (old_chain
);
2797 /* Return bp_location of the tracepoint associated with the current
2798 traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe
2799 is a stepping traceframe. */
2801 struct bp_location
*
2802 get_traceframe_location (int *stepping_frame_p
)
2804 struct tracepoint
*t
;
2805 struct bp_location
*tloc
;
2806 struct regcache
*regcache
;
2808 if (tracepoint_number
== -1)
2809 error (_("No current trace frame."));
2811 t
= get_tracepoint (tracepoint_number
);
2814 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2817 /* The current frame is a trap frame if the frame PC is equal to the
2818 tracepoint PC. If not, then the current frame was collected
2819 during single-stepping. */
2820 regcache
= get_current_regcache ();
2822 /* If the traceframe's address matches any of the tracepoint's
2823 locations, assume it is a direct hit rather than a while-stepping
2824 frame. (FIXME this is not reliable, should record each frame's
2826 for (tloc
= t
->loc
; tloc
; tloc
= tloc
->next
)
2827 if (tloc
->address
== regcache_read_pc (regcache
))
2829 *stepping_frame_p
= 0;
2833 /* If this is a stepping frame, we don't know which location
2834 triggered. The first is as good (or bad) a guess as any... */
2835 *stepping_frame_p
= 1;
2839 /* Return all the actions, including default collect, of a tracepoint
2840 T. It constructs cleanups into the chain, and leaves the caller to
2841 handle them (call do_cleanups). */
2843 static struct command_line
*
2844 all_tracepoint_actions_and_cleanup (struct breakpoint
*t
)
2846 struct command_line
*actions
;
2848 actions
= breakpoint_commands (t
);
2850 /* If there are default expressions to collect, make up a collect
2851 action and prepend to the action list to encode. Note that since
2852 validation is per-tracepoint (local var "xyz" might be valid for
2853 one tracepoint and not another, etc), we make up the action on
2854 the fly, and don't cache it. */
2855 if (*default_collect
)
2857 struct command_line
*default_collect_action
;
2858 char *default_collect_line
;
2860 default_collect_line
= xstrprintf ("collect %s", default_collect
);
2861 make_cleanup (xfree
, default_collect_line
);
2863 validate_actionline (default_collect_line
, t
);
2864 default_collect_action
= XNEW (struct command_line
);
2865 make_cleanup (xfree
, default_collect_action
);
2866 default_collect_action
->next
= actions
;
2867 default_collect_action
->line
= default_collect_line
;
2868 actions
= default_collect_action
;
2874 /* The tdump command. */
2877 tdump_command (char *args
, int from_tty
)
2879 int stepping_frame
= 0;
2880 struct bp_location
*loc
;
2881 struct command_line
*actions
;
2883 /* This throws an error is not inspecting a trace frame. */
2884 loc
= get_traceframe_location (&stepping_frame
);
2886 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2887 tracepoint_number
, traceframe_number
);
2889 /* This command only makes sense for the current frame, not the
2891 scoped_restore_current_thread restore_thread
;
2893 select_frame (get_current_frame ());
2895 actions
= all_tracepoint_actions_and_cleanup (loc
->owner
);
2897 trace_dump_actions (actions
, 0, stepping_frame
, from_tty
);
2900 /* Encode a piece of a tracepoint's source-level definition in a form
2901 that is suitable for both protocol and saving in files. */
2902 /* This version does not do multiple encodes for long strings; it should
2903 return an offset to the next piece to encode. FIXME */
2906 encode_source_string (int tpnum
, ULONGEST addr
,
2907 const char *srctype
, const char *src
,
2908 char *buf
, int buf_size
)
2910 if (80 + strlen (srctype
) > buf_size
)
2911 error (_("Buffer too small for source encoding"));
2912 sprintf (buf
, "%x:%s:%s:%x:%x:",
2913 tpnum
, phex_nz (addr
, sizeof (addr
)),
2914 srctype
, 0, (int) strlen (src
));
2915 if (strlen (buf
) + strlen (src
) * 2 >= buf_size
)
2916 error (_("Source string too long for buffer"));
2917 bin2hex ((gdb_byte
*) src
, buf
+ strlen (buf
), strlen (src
));
2921 /* Tell the target what to do with an ongoing tracing run if GDB
2922 disconnects for some reason. */
2925 set_disconnected_tracing (char *args
, int from_tty
,
2926 struct cmd_list_element
*c
)
2928 target_set_disconnected_tracing (disconnected_tracing
);
2932 set_circular_trace_buffer (char *args
, int from_tty
,
2933 struct cmd_list_element
*c
)
2935 target_set_circular_trace_buffer (circular_trace_buffer
);
2939 set_trace_buffer_size (char *args
, int from_tty
,
2940 struct cmd_list_element
*c
)
2942 target_set_trace_buffer_size (trace_buffer_size
);
2946 set_trace_user (char *args
, int from_tty
,
2947 struct cmd_list_element
*c
)
2951 ret
= target_set_trace_notes (trace_user
, NULL
, NULL
);
2954 warning (_("Target does not support trace notes, user ignored"));
2958 set_trace_notes (char *args
, int from_tty
,
2959 struct cmd_list_element
*c
)
2963 ret
= target_set_trace_notes (NULL
, trace_notes
, NULL
);
2966 warning (_("Target does not support trace notes, note ignored"));
2970 set_trace_stop_notes (char *args
, int from_tty
,
2971 struct cmd_list_element
*c
)
2975 ret
= target_set_trace_notes (NULL
, NULL
, trace_stop_notes
);
2978 warning (_("Target does not support trace notes, stop note ignored"));
2981 /* Convert the memory pointed to by mem into hex, placing result in buf.
2982 * Return a pointer to the last char put in buf (null)
2983 * "stolen" from sparc-stub.c
2986 static const char hexchars
[] = "0123456789abcdef";
2989 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2997 *buf
++ = hexchars
[ch
>> 4];
2998 *buf
++ = hexchars
[ch
& 0xf];
3007 get_traceframe_number (void)
3009 return traceframe_number
;
3013 get_tracepoint_number (void)
3015 return tracepoint_number
;
3018 /* Make the traceframe NUM be the current trace frame. Does nothing
3019 if NUM is already current. */
3022 set_current_traceframe (int num
)
3026 if (traceframe_number
== num
)
3028 /* Nothing to do. */
3032 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
3035 warning (_("could not change traceframe"));
3037 set_traceframe_num (newnum
);
3039 /* Changing the traceframe changes our view of registers and of the
3041 registers_changed ();
3043 clear_traceframe_info ();
3046 /* A cleanup used when switching away and back from tfind mode. */
3048 struct current_traceframe_cleanup
3050 /* The traceframe we were inspecting. */
3051 int traceframe_number
;
3055 do_restore_current_traceframe_cleanup (void *arg
)
3057 struct current_traceframe_cleanup
*old
3058 = (struct current_traceframe_cleanup
*) arg
;
3060 set_current_traceframe (old
->traceframe_number
);
3064 restore_current_traceframe_cleanup_dtor (void *arg
)
3066 struct current_traceframe_cleanup
*old
3067 = (struct current_traceframe_cleanup
*) arg
;
3073 make_cleanup_restore_current_traceframe (void)
3075 struct current_traceframe_cleanup
*old
=
3076 XNEW (struct current_traceframe_cleanup
);
3078 old
->traceframe_number
= traceframe_number
;
3080 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
3081 restore_current_traceframe_cleanup_dtor
);
3084 /* Given a number and address, return an uploaded tracepoint with that
3085 number, creating if necessary. */
3087 struct uploaded_tp
*
3088 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
3090 struct uploaded_tp
*utp
;
3092 for (utp
= *utpp
; utp
; utp
= utp
->next
)
3093 if (utp
->number
== num
&& utp
->addr
== addr
)
3096 utp
= XCNEW (struct uploaded_tp
);
3099 utp
->actions
= NULL
;
3100 utp
->step_actions
= NULL
;
3101 utp
->cmd_strings
= NULL
;
3109 free_uploaded_tps (struct uploaded_tp
**utpp
)
3111 struct uploaded_tp
*next_one
;
3115 next_one
= (*utpp
)->next
;
3121 /* Given a number and address, return an uploaded tracepoint with that
3122 number, creating if necessary. */
3124 struct uploaded_tsv
*
3125 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
3127 struct uploaded_tsv
*utsv
;
3129 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
3130 if (utsv
->number
== num
)
3133 utsv
= XCNEW (struct uploaded_tsv
);
3135 utsv
->next
= *utsvp
;
3142 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
3144 struct uploaded_tsv
*next_one
;
3148 next_one
= (*utsvp
)->next
;
3154 /* FIXME this function is heuristic and will miss the cases where the
3155 conditional is semantically identical but differs in whitespace,
3156 such as "x == 0" vs "x==0". */
3159 cond_string_is_same (char *str1
, char *str2
)
3161 if (str1
== NULL
|| str2
== NULL
)
3162 return (str1
== str2
);
3164 return (strcmp (str1
, str2
) == 0);
3167 /* Look for an existing tracepoint that seems similar enough to the
3168 uploaded one. Enablement isn't compared, because the user can
3169 toggle that freely, and may have done so in anticipation of the
3170 next trace run. Return the location of matched tracepoint. */
3172 static struct bp_location
*
3173 find_matching_tracepoint_location (struct uploaded_tp
*utp
)
3175 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
3177 struct breakpoint
*b
;
3178 struct bp_location
*loc
;
3180 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
3182 struct tracepoint
*t
= (struct tracepoint
*) b
;
3184 if (b
->type
== utp
->type
3185 && t
->step_count
== utp
->step
3186 && t
->pass_count
== utp
->pass
3187 && cond_string_is_same (t
->cond_string
, utp
->cond_string
)
3188 /* FIXME also test actions. */
3191 /* Scan the locations for an address match. */
3192 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3194 if (loc
->address
== utp
->addr
)
3202 /* Given a list of tracepoints uploaded from a target, attempt to
3203 match them up with existing tracepoints, and create new ones if not
3207 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
3209 struct uploaded_tp
*utp
;
3210 /* A set of tracepoints which are modified. */
3211 VEC(breakpoint_p
) *modified_tp
= NULL
;
3213 struct breakpoint
*b
;
3215 /* Look for GDB tracepoints that match up with our uploaded versions. */
3216 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
3218 struct bp_location
*loc
;
3219 struct tracepoint
*t
;
3221 loc
= find_matching_tracepoint_location (utp
);
3226 /* Mark this location as already inserted. */
3228 t
= (struct tracepoint
*) loc
->owner
;
3229 printf_filtered (_("Assuming tracepoint %d is same "
3230 "as target's tracepoint %d at %s.\n"),
3231 loc
->owner
->number
, utp
->number
,
3232 paddress (loc
->gdbarch
, utp
->addr
));
3234 /* The tracepoint LOC->owner was modified (the location LOC
3235 was marked as inserted in the target). Save it in
3236 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3237 observers will be notified later once for each tracepoint
3238 saved in MODIFIED_TP. */
3240 VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
);
3242 if (b
== loc
->owner
)
3248 VEC_safe_push (breakpoint_p
, modified_tp
, loc
->owner
);
3252 t
= create_tracepoint_from_upload (utp
);
3254 printf_filtered (_("Created tracepoint %d for "
3255 "target's tracepoint %d at %s.\n"),
3256 t
->number
, utp
->number
,
3257 paddress (get_current_arch (), utp
->addr
));
3259 printf_filtered (_("Failed to create tracepoint for target's "
3260 "tracepoint %d at %s, skipping it.\n"),
3262 paddress (get_current_arch (), utp
->addr
));
3264 /* Whether found or created, record the number used by the
3265 target, to help with mapping target tracepoints back to their
3266 counterparts here. */
3268 t
->number_on_target
= utp
->number
;
3271 /* Notify 'breakpoint-modified' observer that at least one of B's
3272 locations was changed. */
3273 for (ix
= 0; VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
); ix
++)
3274 observer_notify_breakpoint_modified (b
);
3276 VEC_free (breakpoint_p
, modified_tp
);
3277 free_uploaded_tps (uploaded_tps
);
3280 /* Trace state variables don't have much to identify them beyond their
3281 name, so just use that to detect matches. */
3283 static struct trace_state_variable
*
3284 find_matching_tsv (struct uploaded_tsv
*utsv
)
3289 return find_trace_state_variable (utsv
->name
);
3292 static struct trace_state_variable
*
3293 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
3295 const char *namebase
;
3298 struct trace_state_variable
*tsv
;
3299 struct cleanup
*old_chain
;
3303 namebase
= utsv
->name
;
3309 buf
= string_printf ("%s_%d", namebase
, try_num
++);
3312 /* Fish for a name that is not in use. */
3313 /* (should check against all internal vars?) */
3314 while (find_trace_state_variable (buf
.c_str ()))
3315 buf
= string_printf ("%s_%d", namebase
, try_num
++);
3317 /* We have an available name, create the variable. */
3318 tsv
= create_trace_state_variable (buf
.c_str ());
3319 tsv
->initial_value
= utsv
->initial_value
;
3320 tsv
->builtin
= utsv
->builtin
;
3322 observer_notify_tsv_created (tsv
);
3327 /* Given a list of uploaded trace state variables, try to match them
3328 up with existing variables, or create additional ones. */
3331 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
3334 struct uploaded_tsv
*utsv
;
3335 struct trace_state_variable
*tsv
;
3338 /* Most likely some numbers will have to be reassigned as part of
3339 the merge, so clear them all in anticipation. */
3340 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3343 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
3345 tsv
= find_matching_tsv (utsv
);
3349 printf_filtered (_("Assuming trace state variable $%s "
3350 "is same as target's variable %d.\n"),
3351 tsv
->name
, utsv
->number
);
3355 tsv
= create_tsv_from_upload (utsv
);
3357 printf_filtered (_("Created trace state variable "
3358 "$%s for target's variable %d.\n"),
3359 tsv
->name
, utsv
->number
);
3361 /* Give precedence to numberings that come from the target. */
3363 tsv
->number
= utsv
->number
;
3366 /* Renumber everything that didn't get a target-assigned number. */
3368 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3369 if (tsv
->number
> highest
)
3370 highest
= tsv
->number
;
3373 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3374 if (tsv
->number
== 0)
3375 tsv
->number
= highest
++;
3377 free_uploaded_tsvs (uploaded_tsvs
);
3380 /* Parse the part of trace status syntax that is shared between
3381 the remote protocol and the trace file reader. */
3384 parse_trace_status (const char *line
, struct trace_status
*ts
)
3386 const char *p
= line
, *p1
, *p2
, *p3
, *p_temp
;
3390 ts
->running_known
= 1;
3391 ts
->running
= (*p
++ == '1');
3392 ts
->stop_reason
= trace_stop_reason_unknown
;
3393 xfree (ts
->stop_desc
);
3394 ts
->stop_desc
= NULL
;
3395 ts
->traceframe_count
= -1;
3396 ts
->traceframes_created
= -1;
3397 ts
->buffer_free
= -1;
3398 ts
->buffer_size
= -1;
3399 ts
->disconnected_tracing
= 0;
3400 ts
->circular_buffer
= 0;
3401 xfree (ts
->user_name
);
3402 ts
->user_name
= NULL
;
3405 ts
->start_time
= ts
->stop_time
= 0;
3409 p1
= strchr (p
, ':');
3411 error (_("Malformed trace status, at %s\n\
3412 Status line: '%s'\n"), p
, line
);
3413 p3
= strchr (p
, ';');
3415 p3
= p
+ strlen (p
);
3416 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
3418 p
= unpack_varlen_hex (++p1
, &val
);
3419 ts
->stop_reason
= trace_buffer_full
;
3421 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
3423 p
= unpack_varlen_hex (++p1
, &val
);
3424 ts
->stop_reason
= trace_never_run
;
3426 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
],
3429 p
= unpack_varlen_hex (++p1
, &val
);
3430 ts
->stop_reason
= tracepoint_passcount
;
3431 ts
->stopping_tracepoint
= val
;
3433 else if (strncmp (p
, stop_reason_names
[trace_stop_command
], p1
- p
) == 0)
3435 p2
= strchr (++p1
, ':');
3443 ts
->stop_desc
= (char *) xmalloc (strlen (line
));
3444 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3445 ts
->stop_desc
[end
] = '\0';
3448 ts
->stop_desc
= xstrdup ("");
3450 p
= unpack_varlen_hex (++p2
, &val
);
3451 ts
->stop_reason
= trace_stop_command
;
3453 else if (strncmp (p
, stop_reason_names
[trace_disconnected
], p1
- p
) == 0)
3455 p
= unpack_varlen_hex (++p1
, &val
);
3456 ts
->stop_reason
= trace_disconnected
;
3458 else if (strncmp (p
, stop_reason_names
[tracepoint_error
], p1
- p
) == 0)
3460 p2
= strchr (++p1
, ':');
3463 ts
->stop_desc
= (char *) xmalloc ((p2
- p1
) / 2 + 1);
3464 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3465 ts
->stop_desc
[end
] = '\0';
3468 ts
->stop_desc
= xstrdup ("");
3470 p
= unpack_varlen_hex (++p2
, &val
);
3471 ts
->stopping_tracepoint
= val
;
3472 ts
->stop_reason
= tracepoint_error
;
3474 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3476 p
= unpack_varlen_hex (++p1
, &val
);
3477 ts
->traceframe_count
= val
;
3479 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3481 p
= unpack_varlen_hex (++p1
, &val
);
3482 ts
->traceframes_created
= val
;
3484 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3486 p
= unpack_varlen_hex (++p1
, &val
);
3487 ts
->buffer_free
= val
;
3489 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3491 p
= unpack_varlen_hex (++p1
, &val
);
3492 ts
->buffer_size
= val
;
3494 else if (strncmp (p
, "disconn", p1
- p
) == 0)
3496 p
= unpack_varlen_hex (++p1
, &val
);
3497 ts
->disconnected_tracing
= val
;
3499 else if (strncmp (p
, "circular", p1
- p
) == 0)
3501 p
= unpack_varlen_hex (++p1
, &val
);
3502 ts
->circular_buffer
= val
;
3504 else if (strncmp (p
, "starttime", p1
- p
) == 0)
3506 p
= unpack_varlen_hex (++p1
, &val
);
3507 ts
->start_time
= val
;
3509 else if (strncmp (p
, "stoptime", p1
- p
) == 0)
3511 p
= unpack_varlen_hex (++p1
, &val
);
3512 ts
->stop_time
= val
;
3514 else if (strncmp (p
, "username", p1
- p
) == 0)
3517 ts
->user_name
= (char *) xmalloc (strlen (p
) / 2);
3518 end
= hex2bin (p1
, (gdb_byte
*) ts
->user_name
, (p3
- p1
) / 2);
3519 ts
->user_name
[end
] = '\0';
3522 else if (strncmp (p
, "notes", p1
- p
) == 0)
3525 ts
->notes
= (char *) xmalloc (strlen (p
) / 2);
3526 end
= hex2bin (p1
, (gdb_byte
*) ts
->notes
, (p3
- p1
) / 2);
3527 ts
->notes
[end
] = '\0';
3532 /* Silently skip unknown optional info. */
3533 p_temp
= strchr (p1
+ 1, ';');
3537 /* Must be at the end. */
3544 parse_tracepoint_status (const char *p
, struct breakpoint
*bp
,
3545 struct uploaded_tp
*utp
)
3548 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
3550 p
= unpack_varlen_hex (p
, &uval
);
3552 tp
->hit_count
+= uval
;
3554 utp
->hit_count
+= uval
;
3555 p
= unpack_varlen_hex (p
+ 1, &uval
);
3557 tp
->traceframe_usage
+= uval
;
3559 utp
->traceframe_usage
+= uval
;
3560 /* Ignore any extra, allowing for future extensions. */
3563 /* Given a line of text defining a part of a tracepoint, parse it into
3564 an "uploaded tracepoint". */
3567 parse_tracepoint_definition (const char *line
, struct uploaded_tp
**utpp
)
3571 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
, start
;
3574 const char *srctype
;
3576 struct uploaded_tp
*utp
= NULL
;
3579 /* Both tracepoint and action definitions start with the same number
3580 and address sequence. */
3582 p
= unpack_varlen_hex (p
, &num
);
3583 p
++; /* skip a colon */
3584 p
= unpack_varlen_hex (p
, &addr
);
3585 p
++; /* skip a colon */
3588 enabled
= (*p
++ == 'E');
3589 p
++; /* skip a colon */
3590 p
= unpack_varlen_hex (p
, &step
);
3591 p
++; /* skip a colon */
3592 p
= unpack_varlen_hex (p
, &pass
);
3593 type
= bp_tracepoint
;
3595 /* Thumb through optional fields. */
3598 p
++; /* skip a colon */
3601 type
= bp_fast_tracepoint
;
3603 p
= unpack_varlen_hex (p
, &orig_size
);
3607 type
= bp_static_tracepoint
;
3613 p
= unpack_varlen_hex (p
, &xlen
);
3614 p
++; /* skip a comma */
3615 cond
= (char *) xmalloc (2 * xlen
+ 1);
3616 strncpy (cond
, p
, 2 * xlen
);
3617 cond
[2 * xlen
] = '\0';
3621 warning (_("Unrecognized char '%c' in tracepoint "
3622 "definition, skipping rest"), *p
);
3624 utp
= get_uploaded_tp (num
, addr
, utpp
);
3626 utp
->enabled
= enabled
;
3631 else if (piece
== 'A')
3633 utp
= get_uploaded_tp (num
, addr
, utpp
);
3634 VEC_safe_push (char_ptr
, utp
->actions
, xstrdup (p
));
3636 else if (piece
== 'S')
3638 utp
= get_uploaded_tp (num
, addr
, utpp
);
3639 VEC_safe_push (char_ptr
, utp
->step_actions
, xstrdup (p
));
3641 else if (piece
== 'Z')
3643 /* Parse a chunk of source form definition. */
3644 utp
= get_uploaded_tp (num
, addr
, utpp
);
3646 p
= strchr (p
, ':');
3647 p
++; /* skip a colon */
3648 p
= unpack_varlen_hex (p
, &start
);
3649 p
++; /* skip a colon */
3650 p
= unpack_varlen_hex (p
, &xlen
);
3651 p
++; /* skip a colon */
3653 buf
= (char *) alloca (strlen (line
));
3655 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3658 if (startswith (srctype
, "at:"))
3659 utp
->at_string
= xstrdup (buf
);
3660 else if (startswith (srctype
, "cond:"))
3661 utp
->cond_string
= xstrdup (buf
);
3662 else if (startswith (srctype
, "cmd:"))
3663 VEC_safe_push (char_ptr
, utp
->cmd_strings
, xstrdup (buf
));
3665 else if (piece
== 'V')
3667 utp
= get_uploaded_tp (num
, addr
, utpp
);
3669 parse_tracepoint_status (p
, NULL
, utp
);
3673 /* Don't error out, the target might be sending us optional
3674 info that we don't care about. */
3675 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece
);
3679 /* Convert a textual description of a trace state variable into an
3683 parse_tsv_definition (const char *line
, struct uploaded_tsv
**utsvp
)
3687 ULONGEST num
, initval
, builtin
;
3689 struct uploaded_tsv
*utsv
= NULL
;
3691 buf
= (char *) alloca (strlen (line
));
3694 p
= unpack_varlen_hex (p
, &num
);
3695 p
++; /* skip a colon */
3696 p
= unpack_varlen_hex (p
, &initval
);
3697 p
++; /* skip a colon */
3698 p
= unpack_varlen_hex (p
, &builtin
);
3699 p
++; /* skip a colon */
3700 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3703 utsv
= get_uploaded_tsv (num
, utsvp
);
3704 utsv
->initial_value
= initval
;
3705 utsv
->builtin
= builtin
;
3706 utsv
->name
= xstrdup (buf
);
3710 free_current_marker (void *arg
)
3712 struct static_tracepoint_marker
**marker_p
3713 = (struct static_tracepoint_marker
**) arg
;
3715 if (*marker_p
!= NULL
)
3717 release_static_tracepoint_marker (*marker_p
);
3724 /* Given a line of text defining a static tracepoint marker, parse it
3725 into a "static tracepoint marker" object. Throws an error is
3726 parsing fails. If PP is non-null, it points to one past the end of
3727 the parsed marker definition. */
3730 parse_static_tracepoint_marker_definition (const char *line
, const char **pp
,
3731 struct static_tracepoint_marker
*marker
)
3733 const char *p
, *endp
;
3738 p
= unpack_varlen_hex (p
, &addr
);
3739 p
++; /* skip a colon */
3741 marker
->gdbarch
= target_gdbarch ();
3742 marker
->address
= (CORE_ADDR
) addr
;
3744 endp
= strchr (p
, ':');
3746 error (_("bad marker definition: %s"), line
);
3748 marker
->str_id
= (char *) xmalloc (endp
- p
+ 1);
3749 end
= hex2bin (p
, (gdb_byte
*) marker
->str_id
, (endp
- p
+ 1) / 2);
3750 marker
->str_id
[end
] = '\0';
3753 p
++; /* skip a colon */
3755 marker
->extra
= (char *) xmalloc (strlen (p
) + 1);
3756 end
= hex2bin (p
, (gdb_byte
*) marker
->extra
, strlen (p
) / 2);
3757 marker
->extra
[end
] = '\0';
3763 /* Release a static tracepoint marker's contents. Note that the
3764 object itself isn't released here. There objects are usually on
3768 release_static_tracepoint_marker (struct static_tracepoint_marker
*marker
)
3770 xfree (marker
->str_id
);
3771 marker
->str_id
= NULL
;
3774 /* Print MARKER to gdb_stdout. */
3777 print_one_static_tracepoint_marker (int count
,
3778 struct static_tracepoint_marker
*marker
)
3782 char wrap_indent
[80];
3783 char extra_field_indent
[80];
3784 struct ui_out
*uiout
= current_uiout
;
3785 VEC(breakpoint_p
) *tracepoints
;
3787 symtab_and_line sal
;
3788 sal
.pc
= marker
->address
;
3790 tracepoints
= static_tracepoints_here (marker
->address
);
3792 ui_out_emit_tuple
tuple_emitter (uiout
, "marker");
3794 /* A counter field to help readability. This is not a stable
3796 uiout
->field_int ("count", count
);
3798 uiout
->field_string ("marker-id", marker
->str_id
);
3800 uiout
->field_fmt ("enabled", "%c",
3801 !VEC_empty (breakpoint_p
, tracepoints
) ? 'y' : 'n');
3804 strcpy (wrap_indent
, " ");
3806 if (gdbarch_addr_bit (marker
->gdbarch
) <= 32)
3807 strcat (wrap_indent
, " ");
3809 strcat (wrap_indent
, " ");
3811 strcpy (extra_field_indent
, " ");
3813 uiout
->field_core_addr ("addr", marker
->gdbarch
, marker
->address
);
3815 sal
= find_pc_line (marker
->address
, 0);
3816 sym
= find_pc_sect_function (marker
->address
, NULL
);
3819 uiout
->text ("in ");
3820 uiout
->field_string ("func",
3821 SYMBOL_PRINT_NAME (sym
));
3822 uiout
->wrap_hint (wrap_indent
);
3823 uiout
->text (" at ");
3826 uiout
->field_skip ("func");
3828 if (sal
.symtab
!= NULL
)
3830 uiout
->field_string ("file",
3831 symtab_to_filename_for_display (sal
.symtab
));
3834 if (uiout
->is_mi_like_p ())
3836 const char *fullname
= symtab_to_fullname (sal
.symtab
);
3838 uiout
->field_string ("fullname", fullname
);
3841 uiout
->field_skip ("fullname");
3843 uiout
->field_int ("line", sal
.line
);
3847 uiout
->field_skip ("fullname");
3848 uiout
->field_skip ("line");
3852 uiout
->text (extra_field_indent
);
3853 uiout
->text (_("Data: \""));
3854 uiout
->field_string ("extra-data", marker
->extra
);
3855 uiout
->text ("\"\n");
3857 if (!VEC_empty (breakpoint_p
, tracepoints
))
3860 struct breakpoint
*b
;
3863 ui_out_emit_tuple
tuple_emitter (uiout
, "tracepoints-at");
3865 uiout
->text (extra_field_indent
);
3866 uiout
->text (_("Probed by static tracepoints: "));
3867 for (ix
= 0; VEC_iterate(breakpoint_p
, tracepoints
, ix
, b
); ix
++)
3872 uiout
->field_int ("tracepoint-id", b
->number
);
3876 if (uiout
->is_mi_like_p ())
3877 uiout
->field_int ("number-of-tracepoints",
3878 VEC_length(breakpoint_p
, tracepoints
));
3882 VEC_free (breakpoint_p
, tracepoints
);
3886 info_static_tracepoint_markers_command (char *arg
, int from_tty
)
3888 VEC(static_tracepoint_marker_p
) *markers
;
3889 struct cleanup
*old_chain
;
3890 struct static_tracepoint_marker
*marker
;
3891 struct ui_out
*uiout
= current_uiout
;
3894 /* We don't have to check target_can_use_agent and agent's capability on
3895 static tracepoint here, in order to be compatible with older GDBserver.
3896 We don't check USE_AGENT is true or not, because static tracepoints
3897 don't work without in-process agent, so we don't bother users to type
3898 `set agent on' when to use static tracepoint. */
3900 ui_out_emit_table
table_emitter (uiout
, 5, -1,
3901 "StaticTracepointMarkersTable");
3903 uiout
->table_header (7, ui_left
, "counter", "Cnt");
3905 uiout
->table_header (40, ui_left
, "marker-id", "ID");
3907 uiout
->table_header (3, ui_left
, "enabled", "Enb");
3908 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
3909 uiout
->table_header (10, ui_left
, "addr", "Address");
3911 uiout
->table_header (18, ui_left
, "addr", "Address");
3912 uiout
->table_header (40, ui_noalign
, "what", "What");
3914 uiout
->table_body ();
3916 markers
= target_static_tracepoint_markers_by_strid (NULL
);
3917 old_chain
= make_cleanup (VEC_cleanup (static_tracepoint_marker_p
), &markers
);
3920 VEC_iterate (static_tracepoint_marker_p
,
3921 markers
, i
, marker
);
3924 print_one_static_tracepoint_marker (i
+ 1, marker
);
3925 release_static_tracepoint_marker (marker
);
3928 do_cleanups (old_chain
);
3931 /* The $_sdata convenience variable is a bit special. We don't know
3932 for sure type of the value until we actually have a chance to fetch
3933 the data --- the size of the object depends on what has been
3934 collected. We solve this by making $_sdata be an internalvar that
3935 creates a new value on access. */
3937 /* Return a new value with the correct type for the sdata object of
3938 the current trace frame. Return a void value if there's no object
3941 static struct value
*
3942 sdata_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
3948 /* We need to read the whole object before we know its size. */
3949 size
= target_read_alloc (¤t_target
,
3950 TARGET_OBJECT_STATIC_TRACE_DATA
,
3957 type
= init_vector_type (builtin_type (gdbarch
)->builtin_true_char
,
3959 v
= allocate_value (type
);
3960 memcpy (value_contents_raw (v
), buf
, size
);
3965 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
3968 #if !defined(HAVE_LIBEXPAT)
3970 struct traceframe_info
*
3971 parse_traceframe_info (const char *tframe_info
)
3973 static int have_warned
;
3978 warning (_("Can not parse XML trace frame info; XML support "
3979 "was disabled at compile time"));
3985 #else /* HAVE_LIBEXPAT */
3987 #include "xml-support.h"
3989 /* Handle the start of a <memory> element. */
3992 traceframe_info_start_memory (struct gdb_xml_parser
*parser
,
3993 const struct gdb_xml_element
*element
,
3994 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
3996 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
3997 ULONGEST
*start_p
, *length_p
;
4000 = (ULONGEST
*) xml_find_attribute (attributes
, "start")->value
;
4002 = (ULONGEST
*) xml_find_attribute (attributes
, "length")->value
;
4004 info
->memory
.emplace_back (*start_p
, *length_p
);
4007 /* Handle the start of a <tvar> element. */
4010 traceframe_info_start_tvar (struct gdb_xml_parser
*parser
,
4011 const struct gdb_xml_element
*element
,
4013 VEC(gdb_xml_value_s
) *attributes
)
4015 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
4016 const char *id_attrib
4017 = (const char *) xml_find_attribute (attributes
, "id")->value
;
4018 int id
= gdb_xml_parse_ulongest (parser
, id_attrib
);
4020 info
->tvars
.push_back (id
);
4023 /* Discard the constructed trace frame info (if an error occurs). */
4026 free_result (void *p
)
4028 struct traceframe_info
*result
= (struct traceframe_info
*) p
;
4030 free_traceframe_info (result
);
4033 /* The allowed elements and attributes for an XML memory map. */
4035 static const struct gdb_xml_attribute memory_attributes
[] = {
4036 { "start", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
4037 { "length", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
4038 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
4041 static const struct gdb_xml_attribute tvar_attributes
[] = {
4042 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
4043 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
4046 static const struct gdb_xml_element traceframe_info_children
[] = {
4047 { "memory", memory_attributes
, NULL
,
4048 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
4049 traceframe_info_start_memory
, NULL
},
4050 { "tvar", tvar_attributes
, NULL
,
4051 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
4052 traceframe_info_start_tvar
, NULL
},
4053 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
4056 static const struct gdb_xml_element traceframe_info_elements
[] = {
4057 { "traceframe-info", NULL
, traceframe_info_children
, GDB_XML_EF_NONE
,
4059 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
4062 /* Parse a traceframe-info XML document. */
4064 struct traceframe_info
*
4065 parse_traceframe_info (const char *tframe_info
)
4067 traceframe_info
*result
= new traceframe_info
;
4068 struct cleanup
*back_to
;
4070 back_to
= make_cleanup (free_result
, result
);
4072 if (gdb_xml_parse_quick (_("trace frame info"),
4073 "traceframe-info.dtd", traceframe_info_elements
,
4074 tframe_info
, result
) == 0)
4076 /* Parsed successfully, keep the result. */
4077 discard_cleanups (back_to
);
4082 do_cleanups (back_to
);
4086 #endif /* HAVE_LIBEXPAT */
4088 /* Returns the traceframe_info object for the current traceframe.
4089 This is where we avoid re-fetching the object from the target if we
4090 already have it cached. */
4092 struct traceframe_info
*
4093 get_traceframe_info (void)
4095 if (current_traceframe_info
== NULL
)
4096 current_traceframe_info
= target_traceframe_info ();
4098 return current_traceframe_info
;
4101 /* If the target supports the query, return in RESULT the set of
4102 collected memory in the current traceframe, found within the LEN
4103 bytes range starting at MEMADDR. Returns true if the target
4104 supports the query, otherwise returns false, and RESULT is left
4108 traceframe_available_memory (VEC(mem_range_s
) **result
,
4109 CORE_ADDR memaddr
, ULONGEST len
)
4111 struct traceframe_info
*info
= get_traceframe_info ();
4117 for (mem_range
&r
: info
->memory
)
4118 if (mem_ranges_overlap (r
.start
, r
.length
, memaddr
, len
))
4120 ULONGEST lo1
, hi1
, lo2
, hi2
;
4121 struct mem_range
*nr
;
4124 hi1
= memaddr
+ len
;
4127 hi2
= r
.start
+ r
.length
;
4129 nr
= VEC_safe_push (mem_range_s
, *result
, NULL
);
4131 nr
->start
= std::max (lo1
, lo2
);
4132 nr
->length
= std::min (hi1
, hi2
) - nr
->start
;
4135 normalize_mem_ranges (*result
);
4142 /* Implementation of `sdata' variable. */
4144 static const struct internalvar_funcs sdata_funcs
=
4151 /* module initialization */
4153 _initialize_tracepoint (void)
4155 struct cmd_list_element
*c
;
4157 /* Explicitly create without lookup, since that tries to create a
4158 value with a void typed value, and when we get here, gdbarch
4159 isn't initialized yet. At this point, we're quite sure there
4160 isn't another convenience variable of the same name. */
4161 create_internalvar_type_lazy ("_sdata", &sdata_funcs
, NULL
);
4163 traceframe_number
= -1;
4164 tracepoint_number
= -1;
4166 add_info ("scope", info_scope_command
,
4167 _("List the variables local to a scope"));
4169 add_cmd ("tracepoints", class_trace
,
4170 _("Tracing of program execution without stopping the program."),
4173 add_com ("tdump", class_trace
, tdump_command
,
4174 _("Print everything collected at the current tracepoint."));
4176 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
4177 Define a trace state variable.\n\
4178 Argument is a $-prefixed name, optionally followed\n\
4179 by '=' and an expression that sets the initial value\n\
4180 at the start of tracing."));
4181 set_cmd_completer (c
, expression_completer
);
4183 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
4184 Delete one or more trace state variables.\n\
4185 Arguments are the names of the variables to delete.\n\
4186 If no arguments are supplied, delete all variables."), &deletelist
);
4187 /* FIXME add a trace variable completer. */
4189 add_info ("tvariables", info_tvariables_command
, _("\
4190 Status of trace state variables and their values.\n\
4193 add_info ("static-tracepoint-markers",
4194 info_static_tracepoint_markers_command
, _("\
4195 List target static tracepoints markers.\n\
4198 add_prefix_cmd ("tfind", class_trace
, tfind_command
, _("\
4199 Select a trace frame;\n\
4200 No argument means forward by one frame; '-' means backward by one frame."),
4201 &tfindlist
, "tfind ", 1, &cmdlist
);
4203 add_cmd ("outside", class_trace
, tfind_outside_command
, _("\
4204 Select a trace frame whose PC is outside the given range (exclusive).\n\
4205 Usage: tfind outside addr1, addr2"),
4208 add_cmd ("range", class_trace
, tfind_range_command
, _("\
4209 Select a trace frame whose PC is in the given range (inclusive).\n\
4210 Usage: tfind range addr1,addr2"),
4213 add_cmd ("line", class_trace
, tfind_line_command
, _("\
4214 Select a trace frame by source line.\n\
4215 Argument can be a line number (with optional source file),\n\
4216 a function name, or '*' followed by an address.\n\
4217 Default argument is 'the next source line that was traced'."),
4220 add_cmd ("tracepoint", class_trace
, tfind_tracepoint_command
, _("\
4221 Select a trace frame by tracepoint number.\n\
4222 Default is the tracepoint for the current trace frame."),
4225 add_cmd ("pc", class_trace
, tfind_pc_command
, _("\
4226 Select a trace frame by PC.\n\
4227 Default is the current PC, or the PC of the current trace frame."),
4230 add_cmd ("end", class_trace
, tfind_end_command
, _("\
4231 De-select any trace frame and resume 'live' debugging."),
4234 add_alias_cmd ("none", "end", class_trace
, 0, &tfindlist
);
4236 add_cmd ("start", class_trace
, tfind_start_command
,
4237 _("Select the first trace frame in the trace buffer."),
4240 add_com ("tstatus", class_trace
, tstatus_command
,
4241 _("Display the status of the current trace data collection."));
4243 add_com ("tstop", class_trace
, tstop_command
, _("\
4244 Stop trace data collection.\n\
4245 Usage: tstop [ <notes> ... ]\n\
4246 Any arguments supplied are recorded with the trace as a stop reason and\n\
4247 reported by tstatus (if the target supports trace notes)."));
4249 add_com ("tstart", class_trace
, tstart_command
, _("\
4250 Start trace data collection.\n\
4251 Usage: tstart [ <notes> ... ]\n\
4252 Any arguments supplied are recorded with the trace as a note and\n\
4253 reported by tstatus (if the target supports trace notes)."));
4255 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
4256 Ends a list of commands or actions.\n\
4257 Several GDB commands allow you to enter a list of commands or actions.\n\
4258 Entering \"end\" on a line by itself is the normal way to terminate\n\
4260 Note: the \"end\" command cannot be used at the gdb prompt."));
4262 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
4263 Specify single-stepping behavior at a tracepoint.\n\
4264 Argument is number of instructions to trace in single-step mode\n\
4265 following the tracepoint. This command is normally followed by\n\
4266 one or more \"collect\" commands, to specify what to collect\n\
4267 while single-stepping.\n\n\
4268 Note: this command can only be used in a tracepoint \"actions\" list."));
4270 add_com_alias ("ws", "while-stepping", class_alias
, 0);
4271 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
4273 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
4274 Specify one or more data items to be collected at a tracepoint.\n\
4275 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4276 collect all data (variables, registers) referenced by that expression.\n\
4277 Also accepts the following special arguments:\n\
4278 $regs -- all registers.\n\
4279 $args -- all function arguments.\n\
4280 $locals -- all variables local to the block/function scope.\n\
4281 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
4282 Note: this command can only be used in a tracepoint \"actions\" list."));
4284 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
4285 Specify one or more expressions to be evaluated at a tracepoint.\n\
4286 Accepts a comma-separated list of (one or more) expressions.\n\
4287 The result of each evaluation will be discarded.\n\
4288 Note: this command can only be used in a tracepoint \"actions\" list."));
4290 add_com ("actions", class_trace
, actions_command
, _("\
4291 Specify the actions to be taken at a tracepoint.\n\
4292 Tracepoint actions may include collecting of specified data,\n\
4293 single-stepping, or enabling/disabling other tracepoints,\n\
4294 depending on target's capabilities."));
4296 default_collect
= xstrdup ("");
4297 add_setshow_string_cmd ("default-collect", class_trace
,
4298 &default_collect
, _("\
4299 Set the list of expressions to collect by default"), _("\
4300 Show the list of expressions to collect by default"), NULL
,
4302 &setlist
, &showlist
);
4304 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
4305 &disconnected_tracing
, _("\
4306 Set whether tracing continues after GDB disconnects."), _("\
4307 Show whether tracing continues after GDB disconnects."), _("\
4308 Use this to continue a tracing run even if GDB disconnects\n\
4309 or detaches from the target. You can reconnect later and look at\n\
4310 trace data collected in the meantime."),
4311 set_disconnected_tracing
,
4316 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
4317 &circular_trace_buffer
, _("\
4318 Set target's use of circular trace buffer."), _("\
4319 Show target's use of circular trace buffer."), _("\
4320 Use this to make the trace buffer into a circular buffer,\n\
4321 which will discard traceframes (oldest first) instead of filling\n\
4322 up and stopping the trace run."),
4323 set_circular_trace_buffer
,
4328 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class
,
4329 &trace_buffer_size
, _("\
4330 Set requested size of trace buffer."), _("\
4331 Show requested size of trace buffer."), _("\
4332 Use this to choose a size for the trace buffer. Some targets\n\
4333 may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
4334 disables any attempt to set the buffer size and lets the target choose."),
4335 set_trace_buffer_size
, NULL
,
4336 &setlist
, &showlist
);
4338 add_setshow_string_cmd ("trace-user", class_trace
,
4340 Set the user name to use for current and future trace runs"), _("\
4341 Show the user name to use for current and future trace runs"), NULL
,
4342 set_trace_user
, NULL
,
4343 &setlist
, &showlist
);
4345 add_setshow_string_cmd ("trace-notes", class_trace
,
4347 Set notes string to use for current and future trace runs"), _("\
4348 Show the notes string to use for current and future trace runs"), NULL
,
4349 set_trace_notes
, NULL
,
4350 &setlist
, &showlist
);
4352 add_setshow_string_cmd ("trace-stop-notes", class_trace
,
4353 &trace_stop_notes
, _("\
4354 Set notes string to use for future tstop commands"), _("\
4355 Show the notes string to use for future tstop commands"), NULL
,
4356 set_trace_stop_notes
, NULL
,
4357 &setlist
, &showlist
);