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
)
201 VEC_free (mem_range_s
, info
->memory
);
207 /* Free and clear the traceframe info cache of the current
211 clear_traceframe_info (void)
213 free_traceframe_info (current_traceframe_info
);
214 current_traceframe_info
= NULL
;
217 /* Set traceframe number to NUM. */
219 set_traceframe_num (int num
)
221 traceframe_number
= num
;
222 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
225 /* Set tracepoint number to NUM. */
227 set_tracepoint_num (int num
)
229 tracepoint_number
= num
;
230 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
233 /* Set externally visible debug variables for querying/printing
234 the traceframe context (line, function, file). */
237 set_traceframe_context (struct frame_info
*trace_frame
)
240 struct symbol
*traceframe_fun
;
241 symtab_and_line traceframe_sal
;
243 /* Save as globals for internal use. */
244 if (trace_frame
!= NULL
245 && get_frame_pc_if_available (trace_frame
, &trace_pc
))
247 traceframe_sal
= find_pc_line (trace_pc
, 0);
248 traceframe_fun
= find_pc_function (trace_pc
);
250 /* Save linenumber as "$trace_line", a debugger variable visible to
252 set_internalvar_integer (lookup_internalvar ("trace_line"),
253 traceframe_sal
.line
);
257 traceframe_fun
= NULL
;
258 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
261 /* Save func name as "$trace_func", a debugger variable visible to
263 if (traceframe_fun
== NULL
264 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
265 clear_internalvar (lookup_internalvar ("trace_func"));
267 set_internalvar_string (lookup_internalvar ("trace_func"),
268 SYMBOL_LINKAGE_NAME (traceframe_fun
));
270 /* Save file name as "$trace_file", a debugger variable visible to
272 if (traceframe_sal
.symtab
== NULL
)
273 clear_internalvar (lookup_internalvar ("trace_file"));
275 set_internalvar_string (lookup_internalvar ("trace_file"),
276 symtab_to_filename_for_display (traceframe_sal
.symtab
));
279 /* Create a new trace state variable with the given name. */
281 struct trace_state_variable
*
282 create_trace_state_variable (const char *name
)
284 struct trace_state_variable tsv
;
286 memset (&tsv
, 0, sizeof (tsv
));
287 tsv
.name
= xstrdup (name
);
288 tsv
.number
= next_tsv_number
++;
289 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
292 /* Look for a trace state variable of the given name. */
294 struct trace_state_variable
*
295 find_trace_state_variable (const char *name
)
297 struct trace_state_variable
*tsv
;
300 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
301 if (strcmp (name
, tsv
->name
) == 0)
307 /* Look for a trace state variable of the given number. Return NULL if
310 struct trace_state_variable
*
311 find_trace_state_variable_by_number (int number
)
313 struct trace_state_variable
*tsv
;
316 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
317 if (tsv
->number
== number
)
324 delete_trace_state_variable (const char *name
)
326 struct trace_state_variable
*tsv
;
329 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
330 if (strcmp (name
, tsv
->name
) == 0)
332 observer_notify_tsv_deleted (tsv
);
334 xfree ((void *)tsv
->name
);
335 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
340 warning (_("No trace variable named \"$%s\", not deleting"), name
);
343 /* Throws an error if NAME is not valid syntax for a trace state
347 validate_trace_state_variable_name (const char *name
)
352 error (_("Must supply a non-empty variable name"));
354 /* All digits in the name is reserved for value history
356 for (p
= name
; isdigit (*p
); p
++)
359 error (_("$%s is not a valid trace state variable name"), name
);
361 for (p
= name
; isalnum (*p
) || *p
== '_'; p
++)
364 error (_("$%s is not a valid trace state variable name"), name
);
367 /* The 'tvariable' command collects a name and optional expression to
368 evaluate into an initial value. */
371 trace_variable_command (char *args
, int from_tty
)
374 struct trace_state_variable
*tsv
;
375 char *name_start
, *p
;
378 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
380 /* Only allow two syntaxes; "$name" and "$name=value". */
381 p
= skip_spaces (args
);
384 error (_("Name of trace variable should start with '$'"));
387 while (isalnum (*p
) || *p
== '_')
389 std::string
name (name_start
, p
- name_start
);
392 if (*p
!= '=' && *p
!= '\0')
393 error (_("Syntax must be $NAME [ = EXPR ]"));
395 validate_trace_state_variable_name (name
.c_str ());
398 initval
= value_as_long (parse_and_eval (++p
));
400 /* If the variable already exists, just change its initial value. */
401 tsv
= find_trace_state_variable (name
.c_str ());
404 if (tsv
->initial_value
!= initval
)
406 tsv
->initial_value
= initval
;
407 observer_notify_tsv_modified (tsv
);
409 printf_filtered (_("Trace state variable $%s "
410 "now has initial value %s.\n"),
411 tsv
->name
, plongest (tsv
->initial_value
));
415 /* Create a new variable. */
416 tsv
= create_trace_state_variable (name
.c_str ());
417 tsv
->initial_value
= initval
;
419 observer_notify_tsv_created (tsv
);
421 printf_filtered (_("Trace state variable $%s "
422 "created, with initial value %s.\n"),
423 tsv
->name
, plongest (tsv
->initial_value
));
427 delete_trace_variable_command (const char *args
, int from_tty
)
431 if (query (_("Delete all trace state variables? ")))
432 VEC_free (tsv_s
, tvariables
);
434 observer_notify_tsv_deleted (NULL
);
438 gdb_argv
argv (args
);
440 for (char *arg
: argv
)
443 delete_trace_state_variable (arg
+ 1);
445 warning (_("Name \"%s\" not prefixed with '$', ignoring"), arg
);
452 tvariables_info_1 (void)
454 struct trace_state_variable
*tsv
;
457 struct ui_out
*uiout
= current_uiout
;
459 if (VEC_length (tsv_s
, tvariables
) == 0 && !uiout
->is_mi_like_p ())
461 printf_filtered (_("No trace state variables.\n"));
465 /* Try to acquire values from the target. */
466 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
, ++count
)
467 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
470 ui_out_emit_table
table_emitter (uiout
, 3, count
, "trace-variables");
471 uiout
->table_header (15, ui_left
, "name", "Name");
472 uiout
->table_header (11, ui_left
, "initial", "Initial");
473 uiout
->table_header (11, ui_left
, "current", "Current");
475 uiout
->table_body ();
477 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
481 ui_out_emit_tuple
tuple_emitter (uiout
, "variable");
483 std::string name
= std::string ("$") + tsv
->name
;
484 uiout
->field_string ("name", name
.c_str ());
485 uiout
->field_string ("initial", plongest (tsv
->initial_value
));
487 if (tsv
->value_known
)
488 c
= plongest (tsv
->value
);
489 else if (uiout
->is_mi_like_p ())
490 /* For MI, we prefer not to use magic string constants, but rather
491 omit the field completely. The difference between unknown and
492 undefined does not seem important enough to represent. */
494 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
495 /* The value is/was defined, but we don't have it. */
498 /* It is not meaningful to ask about the value. */
501 uiout
->field_string ("current", c
);
506 /* List all the trace state variables. */
509 info_tvariables_command (char *args
, int from_tty
)
511 tvariables_info_1 ();
514 /* Stash definitions of tsvs into the given file. */
517 save_trace_state_variables (struct ui_file
*fp
)
519 struct trace_state_variable
*tsv
;
522 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
524 fprintf_unfiltered (fp
, "tvariable $%s", tsv
->name
);
525 if (tsv
->initial_value
)
526 fprintf_unfiltered (fp
, " = %s", plongest (tsv
->initial_value
));
527 fprintf_unfiltered (fp
, "\n");
531 /* ACTIONS functions: */
533 /* The three functions:
534 collect_pseudocommand,
535 while_stepping_pseudocommand, and
536 end_actions_pseudocommand
537 are placeholders for "commands" that are actually ONLY to be used
538 within a tracepoint action list. If the actual function is ever called,
539 it means that somebody issued the "command" at the top level,
540 which is always an error. */
543 end_actions_pseudocommand (char *args
, int from_tty
)
545 error (_("This command cannot be used at the top level."));
549 while_stepping_pseudocommand (char *args
, int from_tty
)
551 error (_("This command can only be used in a tracepoint actions list."));
555 collect_pseudocommand (char *args
, int from_tty
)
557 error (_("This command can only be used in a tracepoint actions list."));
561 teval_pseudocommand (char *args
, int from_tty
)
563 error (_("This command can only be used in a tracepoint actions list."));
566 /* Parse any collection options, such as /s for strings. */
569 decode_agent_options (const char *exp
, int *trace_string
)
571 struct value_print_options opts
;
578 /* Call this to borrow the print elements default for collection
580 get_user_print_options (&opts
);
585 if (target_supports_string_tracing ())
587 /* Allow an optional decimal number giving an explicit maximum
588 string length, defaulting it to the "print elements" value;
589 so "collect/s80 mystr" gets at most 80 bytes of string. */
590 *trace_string
= opts
.print_max
;
592 if (*exp
>= '0' && *exp
<= '9')
593 *trace_string
= atoi (exp
);
594 while (*exp
>= '0' && *exp
<= '9')
598 error (_("Target does not support \"/s\" option for string tracing."));
601 error (_("Undefined collection format \"%c\"."), *exp
);
603 exp
= skip_spaces (exp
);
608 /* Enter a list of actions for a tracepoint. */
610 actions_command (char *args
, int from_tty
)
612 struct tracepoint
*t
;
614 t
= get_tracepoint_by_number (&args
, NULL
);
618 string_printf ("Enter actions for tracepoint %d, one per line.",
621 command_line_up l
= read_command_lines (&tmpbuf
[0], from_tty
, 1,
622 check_tracepoint_command
, t
);
623 breakpoint_set_commands (t
, std::move (l
));
625 /* else just return */
628 /* Report the results of checking the agent expression, as errors or
632 report_agent_reqs_errors (struct agent_expr
*aexpr
)
634 /* All of the "flaws" are serious bytecode generation issues that
635 should never occur. */
636 if (aexpr
->flaw
!= agent_flaw_none
)
637 internal_error (__FILE__
, __LINE__
, _("expression is malformed"));
639 /* If analysis shows a stack underflow, GDB must have done something
640 badly wrong in its bytecode generation. */
641 if (aexpr
->min_height
< 0)
642 internal_error (__FILE__
, __LINE__
,
643 _("expression has min height < 0"));
645 /* Issue this error if the stack is predicted to get too deep. The
646 limit is rather arbitrary; a better scheme might be for the
647 target to report how much stack it will have available. The
648 depth roughly corresponds to parenthesization, so a limit of 20
649 amounts to 20 levels of expression nesting, which is actually
650 a pretty big hairy expression. */
651 if (aexpr
->max_height
> 20)
652 error (_("Expression is too complicated."));
655 /* worker function */
657 validate_actionline (const char *line
, struct breakpoint
*b
)
659 struct cmd_list_element
*c
;
662 struct bp_location
*loc
;
663 struct tracepoint
*t
= (struct tracepoint
*) b
;
665 /* If EOF is typed, *line is NULL. */
669 p
= skip_spaces (line
);
671 /* Symbol lookup etc. */
672 if (*p
== '\0') /* empty line: just prompt for another line. */
675 if (*p
== '#') /* comment line */
678 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
680 error (_("`%s' is not a tracepoint action, or is ambiguous."), p
);
682 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
684 int trace_string
= 0;
687 p
= decode_agent_options (p
, &trace_string
);
690 { /* Repeat over a comma-separated list. */
691 QUIT
; /* Allow user to bail out with ^C. */
694 if (*p
== '$') /* Look for special pseudo-symbols. */
696 if (0 == strncasecmp ("reg", p
+ 1, 3)
697 || 0 == strncasecmp ("arg", p
+ 1, 3)
698 || 0 == strncasecmp ("loc", p
+ 1, 3)
699 || 0 == strncasecmp ("_ret", p
+ 1, 4)
700 || 0 == strncasecmp ("_sdata", p
+ 1, 6))
705 /* else fall thru, treat p as an expression and parse it! */
708 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
711 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
712 block_for_pc (loc
->address
), 1);
714 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
716 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
718 error (_("constant `%s' (value %s) "
719 "will not be collected."),
720 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
721 plongest (SYMBOL_VALUE (exp
->elts
[2].symbol
)));
723 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
)
724 == LOC_OPTIMIZED_OUT
)
726 error (_("`%s' is optimized away "
727 "and cannot be collected."),
728 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
732 /* We have something to collect, make sure that the expr to
733 bytecode translator can handle it and that it's not too
735 agent_expr_up aexpr
= gen_trace_for_expr (loc
->address
,
739 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
740 error (_("Expression is too complicated."));
742 ax_reqs (aexpr
.get ());
744 report_agent_reqs_errors (aexpr
.get ());
747 while (p
&& *p
++ == ',');
750 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
753 { /* Repeat over a comma-separated list. */
754 QUIT
; /* Allow user to bail out with ^C. */
758 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
762 /* Only expressions are allowed for this action. */
763 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
764 block_for_pc (loc
->address
), 1);
766 /* We have something to evaluate, make sure that the expr to
767 bytecode translator can handle it and that it's not too
769 agent_expr_up aexpr
= gen_eval_for_expr (loc
->address
, exp
.get ());
771 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
772 error (_("Expression is too complicated."));
774 ax_reqs (aexpr
.get ());
775 report_agent_reqs_errors (aexpr
.get ());
778 while (p
&& *p
++ == ',');
781 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
786 t
->step_count
= strtol (p
, &endp
, 0);
787 if (endp
== p
|| t
->step_count
== 0)
788 error (_("while-stepping step count `%s' is malformed."), line
);
792 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
796 error (_("`%s' is not a supported tracepoint action."), line
);
800 memrange_absolute
= -1
803 /* MEMRANGE functions: */
805 /* Compare memranges for std::sort. */
808 memrange_comp (const memrange
&a
, const memrange
&b
)
810 if (a
.type
== b
.type
)
812 if (a
.type
== memrange_absolute
)
813 return (bfd_vma
) a
.start
< (bfd_vma
) b
.start
;
815 return a
.start
< b
.start
;
818 return a
.type
< b
.type
;
821 /* Sort the memrange list using std::sort, and merge adjacent memranges. */
824 memrange_sortmerge (std::vector
<memrange
> &memranges
)
826 if (!memranges
.empty ())
830 std::sort (memranges
.begin (), memranges
.end (), memrange_comp
);
832 for (a
= 0, b
= 1; b
< memranges
.size (); b
++)
834 /* If memrange b overlaps or is adjacent to memrange a,
836 if (memranges
[a
].type
== memranges
[b
].type
837 && memranges
[b
].start
<= memranges
[a
].end
)
839 if (memranges
[b
].end
> memranges
[a
].end
)
840 memranges
[a
].end
= memranges
[b
].end
;
841 continue; /* next b, same a */
845 memranges
[a
] = memranges
[b
];
847 memranges
.resize (a
+ 1);
851 /* Add a register to a collection list. */
854 collection_list::add_register (unsigned int regno
)
857 printf_filtered ("collect register %d\n", regno
);
858 if (regno
>= (8 * sizeof (m_regs_mask
)))
859 error (_("Internal: register number %d too large for tracepoint"),
861 m_regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
864 /* Add a memrange to a collection list. */
867 collection_list::add_memrange (struct gdbarch
*gdbarch
,
868 int type
, bfd_signed_vma base
,
872 printf_filtered ("(%d,%s,%ld)\n", type
, paddress (gdbarch
, base
), len
);
874 /* type: memrange_absolute == memory, other n == basereg */
875 /* base: addr if memory, offset if reg relative. */
876 /* len: we actually save end (base + len) for convenience */
877 m_memranges
.emplace_back (type
, base
, base
+ len
);
879 if (type
!= memrange_absolute
) /* Better collect the base register! */
883 /* Add a symbol to a collection list. */
886 collection_list::collect_symbol (struct symbol
*sym
,
887 struct gdbarch
*gdbarch
,
888 long frame_regno
, long frame_offset
,
894 bfd_signed_vma offset
;
895 int treat_as_expr
= 0;
897 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
898 switch (SYMBOL_CLASS (sym
))
901 printf_filtered ("%s: don't know symbol class %d\n",
902 SYMBOL_PRINT_NAME (sym
),
906 printf_filtered ("constant %s (value %s) will not be collected.\n",
907 SYMBOL_PRINT_NAME (sym
), plongest (SYMBOL_VALUE (sym
)));
910 offset
= SYMBOL_VALUE_ADDRESS (sym
);
913 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
914 SYMBOL_PRINT_NAME (sym
), len
,
915 paddress (gdbarch
, offset
));
917 /* A struct may be a C++ class with static fields, go to general
918 expression handling. */
919 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
922 add_memrange (gdbarch
, memrange_absolute
, offset
, len
);
925 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
927 printf_filtered ("LOC_REG[parm] %s: ",
928 SYMBOL_PRINT_NAME (sym
));
930 /* Check for doubles stored in two registers. */
931 /* FIXME: how about larger types stored in 3 or more regs? */
932 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
933 len
> register_size (gdbarch
, reg
))
934 add_register (reg
+ 1);
937 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
938 printf_filtered (" (will not collect %s)\n",
939 SYMBOL_PRINT_NAME (sym
));
943 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
946 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
947 " from frame ptr reg %d\n",
948 SYMBOL_PRINT_NAME (sym
), len
,
949 paddress (gdbarch
, offset
), reg
);
951 add_memrange (gdbarch
, reg
, offset
, len
);
953 case LOC_REGPARM_ADDR
:
954 reg
= SYMBOL_VALUE (sym
);
958 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset %s"
960 SYMBOL_PRINT_NAME (sym
), len
,
961 paddress (gdbarch
, offset
), reg
);
963 add_memrange (gdbarch
, reg
, offset
, len
);
967 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
970 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
971 " from frame ptr reg %d\n",
972 SYMBOL_PRINT_NAME (sym
), len
,
973 paddress (gdbarch
, offset
), reg
);
975 add_memrange (gdbarch
, reg
, offset
, len
);
982 case LOC_OPTIMIZED_OUT
:
983 printf_filtered ("%s has been optimized out of existence.\n",
984 SYMBOL_PRINT_NAME (sym
));
992 /* Expressions are the most general case. */
995 agent_expr_up aexpr
= gen_trace_for_var (scope
, gdbarch
,
998 /* It can happen that the symbol is recorded as a computed
999 location, but it's been optimized away and doesn't actually
1000 have a location expression. */
1003 printf_filtered ("%s has been optimized out of existence.\n",
1004 SYMBOL_PRINT_NAME (sym
));
1008 ax_reqs (aexpr
.get ());
1010 report_agent_reqs_errors (aexpr
.get ());
1012 /* Take care of the registers. */
1013 if (aexpr
->reg_mask_len
> 0)
1015 for (int ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1017 QUIT
; /* Allow user to bail out with ^C. */
1018 if (aexpr
->reg_mask
[ndx1
] != 0)
1020 /* Assume chars have 8 bits. */
1021 for (int ndx2
= 0; ndx2
< 8; ndx2
++)
1022 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1023 /* It's used -- record it. */
1024 add_register (ndx1
* 8 + ndx2
);
1029 add_aexpr (std::move (aexpr
));
1033 /* Data to be passed around in the calls to the locals and args
1036 struct add_local_symbols_data
1038 struct collection_list
*collect
;
1039 struct gdbarch
*gdbarch
;
1047 /* The callback for the locals and args iterators. */
1050 do_collect_symbol (const char *print_name
,
1054 struct add_local_symbols_data
*p
= (struct add_local_symbols_data
*) cb_data
;
1056 p
->collect
->collect_symbol (sym
, p
->gdbarch
, p
->frame_regno
,
1057 p
->frame_offset
, p
->pc
, p
->trace_string
);
1060 p
->collect
->add_wholly_collected (print_name
);
1064 collection_list::add_wholly_collected (const char *print_name
)
1066 m_wholly_collected
.push_back (print_name
);
1069 /* Add all locals (or args) symbols to collection list. */
1072 collection_list::add_local_symbols (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1073 long frame_regno
, long frame_offset
, int type
,
1076 const struct block
*block
;
1077 struct add_local_symbols_data cb_data
;
1079 cb_data
.collect
= this;
1080 cb_data
.gdbarch
= gdbarch
;
1082 cb_data
.frame_regno
= frame_regno
;
1083 cb_data
.frame_offset
= frame_offset
;
1085 cb_data
.trace_string
= trace_string
;
1089 block
= block_for_pc (pc
);
1092 warning (_("Can't collect locals; "
1093 "no symbol table info available.\n"));
1097 iterate_over_block_local_vars (block
, do_collect_symbol
, &cb_data
);
1098 if (cb_data
.count
== 0)
1099 warning (_("No locals found in scope."));
1103 pc
= get_pc_function_start (pc
);
1104 block
= block_for_pc (pc
);
1107 warning (_("Can't collect args; no symbol table info available."));
1111 iterate_over_block_arg_vars (block
, do_collect_symbol
, &cb_data
);
1112 if (cb_data
.count
== 0)
1113 warning (_("No args found in scope."));
1118 collection_list::add_static_trace_data ()
1121 printf_filtered ("collect static trace data\n");
1122 m_strace_data
= true;
1125 collection_list::collection_list ()
1127 m_strace_data (false)
1129 m_memranges
.reserve (128);
1130 m_aexprs
.reserve (128);
1133 /* Reduce a collection list to string form (for gdb protocol). */
1136 collection_list::stringify ()
1138 char temp_buf
[2048];
1141 char *(*str_list
)[];
1145 count
= 1 + 1 + m_memranges
.size () + m_aexprs
.size () + 1;
1146 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1151 printf_filtered ("\nCollecting static trace data\n");
1154 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1158 for (i
= sizeof (m_regs_mask
) - 1; i
> 0; i
--)
1159 if (m_regs_mask
[i
] != 0) /* Skip leading zeroes in regs_mask. */
1161 if (m_regs_mask
[i
] != 0) /* Prepare to send regs_mask to the stub. */
1164 printf_filtered ("\nCollecting registers (mask): 0x");
1169 QUIT
; /* Allow user to bail out with ^C. */
1171 printf_filtered ("%02X", m_regs_mask
[i
]);
1172 sprintf (end
, "%02X", m_regs_mask
[i
]);
1175 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1179 printf_filtered ("\n");
1180 if (!m_memranges
.empty () && info_verbose
)
1181 printf_filtered ("Collecting memranges: \n");
1182 for (i
= 0, count
= 0, end
= temp_buf
; i
< m_memranges
.size (); i
++)
1184 QUIT
; /* Allow user to bail out with ^C. */
1187 printf_filtered ("(%d, %s, %ld)\n",
1188 m_memranges
[i
].type
,
1189 paddress (target_gdbarch (),
1190 m_memranges
[i
].start
),
1191 (long) (m_memranges
[i
].end
1192 - m_memranges
[i
].start
));
1194 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1196 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1203 bfd_signed_vma length
1204 = m_memranges
[i
].end
- m_memranges
[i
].start
;
1206 /* The "%X" conversion specifier expects an unsigned argument,
1207 so passing -1 (memrange_absolute) to it directly gives you
1208 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1210 if (m_memranges
[i
].type
== memrange_absolute
)
1211 sprintf (end
, "M-1,%s,%lX", phex_nz (m_memranges
[i
].start
, 0),
1214 sprintf (end
, "M%X,%s,%lX", m_memranges
[i
].type
,
1215 phex_nz (m_memranges
[i
].start
, 0), (long) length
);
1218 count
+= strlen (end
);
1219 end
= temp_buf
+ count
;
1222 for (i
= 0; i
< m_aexprs
.size (); i
++)
1224 QUIT
; /* Allow user to bail out with ^C. */
1225 if ((count
+ 10 + 2 * m_aexprs
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1227 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1232 sprintf (end
, "X%08X,", m_aexprs
[i
]->len
);
1233 end
+= 10; /* 'X' + 8 hex digits + ',' */
1236 end
= mem2hex (m_aexprs
[i
]->buf
, end
, m_aexprs
[i
]->len
);
1237 count
+= 2 * m_aexprs
[i
]->len
;
1242 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1247 (*str_list
)[ndx
] = NULL
;
1258 /* Add the printed expression EXP to *LIST. */
1261 collection_list::append_exp (struct expression
*exp
)
1263 string_file tmp_stream
;
1265 print_expression (exp
, &tmp_stream
);
1267 m_computed
.push_back (std::move (tmp_stream
.string ()));
1271 collection_list::finish ()
1273 memrange_sortmerge (m_memranges
);
1277 encode_actions_1 (struct command_line
*action
,
1278 struct bp_location
*tloc
,
1280 LONGEST frame_offset
,
1281 struct collection_list
*collect
,
1282 struct collection_list
*stepping_list
)
1284 const char *action_exp
;
1286 struct value
*tempval
;
1287 struct cmd_list_element
*cmd
;
1289 for (; action
; action
= action
->next
)
1291 QUIT
; /* Allow user to bail out with ^C. */
1292 action_exp
= action
->line
;
1293 action_exp
= skip_spaces (action_exp
);
1295 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1297 error (_("Bad action list item: %s"), action_exp
);
1299 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1301 int trace_string
= 0;
1303 if (*action_exp
== '/')
1304 action_exp
= decode_agent_options (action_exp
, &trace_string
);
1307 { /* Repeat over a comma-separated list. */
1308 QUIT
; /* Allow user to bail out with ^C. */
1309 action_exp
= skip_spaces (action_exp
);
1311 if (0 == strncasecmp ("$reg", action_exp
, 4))
1313 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
1314 collect
->add_register (i
);
1315 action_exp
= strchr (action_exp
, ','); /* more? */
1317 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1319 collect
->add_local_symbols (target_gdbarch (),
1325 action_exp
= strchr (action_exp
, ','); /* more? */
1327 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1329 collect
->add_local_symbols (target_gdbarch (),
1335 action_exp
= strchr (action_exp
, ','); /* more? */
1337 else if (0 == strncasecmp ("$_ret", action_exp
, 5))
1340 = gen_trace_for_return_address (tloc
->address
,
1344 ax_reqs (aexpr
.get ());
1345 report_agent_reqs_errors (aexpr
.get ());
1347 /* take care of the registers */
1348 if (aexpr
->reg_mask_len
> 0)
1350 for (int ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1352 QUIT
; /* allow user to bail out with ^C */
1353 if (aexpr
->reg_mask
[ndx1
] != 0)
1355 /* assume chars have 8 bits */
1356 for (int ndx2
= 0; ndx2
< 8; ndx2
++)
1357 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1359 /* It's used -- record it. */
1360 collect
->add_register (ndx1
* 8 + ndx2
);
1366 collect
->add_aexpr (std::move (aexpr
));
1367 action_exp
= strchr (action_exp
, ','); /* more? */
1369 else if (0 == strncasecmp ("$_sdata", action_exp
, 7))
1371 collect
->add_static_trace_data ();
1372 action_exp
= strchr (action_exp
, ','); /* more? */
1378 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1379 block_for_pc (tloc
->address
),
1382 switch (exp
->elts
[0].opcode
)
1386 const char *name
= &exp
->elts
[2].string
;
1388 i
= user_reg_map_name_to_regnum (target_gdbarch (),
1389 name
, strlen (name
));
1391 internal_error (__FILE__
, __LINE__
,
1392 _("Register $%s not available"),
1395 printf_filtered ("OP_REGISTER: ");
1396 collect
->add_register (i
);
1401 /* Safe because we know it's a simple expression. */
1402 tempval
= evaluate_expression (exp
.get ());
1403 addr
= value_address (tempval
);
1404 /* Initialize the TYPE_LENGTH if it is a typedef. */
1405 check_typedef (exp
->elts
[1].type
);
1406 collect
->add_memrange (target_gdbarch (),
1407 memrange_absolute
, addr
,
1408 TYPE_LENGTH (exp
->elts
[1].type
));
1409 collect
->append_exp (exp
.get ());
1414 struct symbol
*sym
= exp
->elts
[2].symbol
;
1415 char_ptr name
= (char_ptr
) SYMBOL_NATURAL_NAME (sym
);
1417 collect
->collect_symbol (exp
->elts
[2].symbol
,
1423 collect
->add_wholly_collected (name
);
1427 default: /* Full-fledged expression. */
1428 agent_expr_up aexpr
= gen_trace_for_expr (tloc
->address
,
1432 ax_reqs (aexpr
.get ());
1434 report_agent_reqs_errors (aexpr
.get ());
1436 /* Take care of the registers. */
1437 if (aexpr
->reg_mask_len
> 0)
1439 for (int ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1441 QUIT
; /* Allow user to bail out with ^C. */
1442 if (aexpr
->reg_mask
[ndx1
] != 0)
1444 /* Assume chars have 8 bits. */
1445 for (int ndx2
= 0; ndx2
< 8; ndx2
++)
1446 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1448 /* It's used -- record it. */
1449 collect
->add_register (ndx1
* 8 + ndx2
);
1455 collect
->add_aexpr (std::move (aexpr
));
1456 collect
->append_exp (exp
.get ());
1461 while (action_exp
&& *action_exp
++ == ',');
1463 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1466 { /* Repeat over a comma-separated list. */
1467 QUIT
; /* Allow user to bail out with ^C. */
1468 action_exp
= skip_spaces (action_exp
);
1471 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1472 block_for_pc (tloc
->address
),
1475 agent_expr_up aexpr
= gen_eval_for_expr (tloc
->address
,
1478 ax_reqs (aexpr
.get ());
1479 report_agent_reqs_errors (aexpr
.get ());
1481 /* Even though we're not officially collecting, add
1482 to the collect list anyway. */
1483 collect
->add_aexpr (std::move (aexpr
));
1486 while (action_exp
&& *action_exp
++ == ',');
1488 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1490 /* We check against nested while-stepping when setting
1491 breakpoint action, so no way to run into nested
1493 gdb_assert (stepping_list
);
1495 encode_actions_1 (action
->body_list
[0], tloc
, frame_reg
,
1496 frame_offset
, stepping_list
, NULL
);
1499 error (_("Invalid tracepoint command '%s'"), action
->line
);
1503 /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST
1504 and STEPPING_LIST. */
1507 encode_actions (struct bp_location
*tloc
,
1508 struct collection_list
*tracepoint_list
,
1509 struct collection_list
*stepping_list
)
1511 struct command_line
*actions
;
1513 LONGEST frame_offset
;
1515 gdbarch_virtual_frame_pointer (tloc
->gdbarch
,
1516 tloc
->address
, &frame_reg
, &frame_offset
);
1518 actions
= all_tracepoint_actions_and_cleanup (tloc
->owner
);
1520 encode_actions_1 (actions
, tloc
, frame_reg
, frame_offset
,
1521 tracepoint_list
, stepping_list
);
1523 tracepoint_list
->finish ();
1524 stepping_list
->finish ();
1527 /* Render all actions into gdb protocol. */
1530 encode_actions_rsp (struct bp_location
*tloc
, char ***tdp_actions
,
1531 char ***stepping_actions
)
1533 struct collection_list tracepoint_list
, stepping_list
;
1535 *tdp_actions
= NULL
;
1536 *stepping_actions
= NULL
;
1538 encode_actions (tloc
, &tracepoint_list
, &stepping_list
);
1540 *tdp_actions
= tracepoint_list
.stringify ();
1541 *stepping_actions
= stepping_list
.stringify ();
1545 collection_list::add_aexpr (agent_expr_up aexpr
)
1547 m_aexprs
.push_back (std::move (aexpr
));
1551 process_tracepoint_on_disconnect (void)
1553 VEC(breakpoint_p
) *tp_vec
= NULL
;
1555 struct breakpoint
*b
;
1556 int has_pending_p
= 0;
1558 /* Check whether we still have pending tracepoint. If we have, warn the
1559 user that pending tracepoint will no longer work. */
1560 tp_vec
= all_tracepoints ();
1561 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1570 struct bp_location
*loc1
;
1572 for (loc1
= b
->loc
; loc1
; loc1
= loc1
->next
)
1574 if (loc1
->shlib_disabled
)
1585 VEC_free (breakpoint_p
, tp_vec
);
1588 warning (_("Pending tracepoints will not be resolved while"
1589 " GDB is disconnected\n"));
1592 /* Reset local state of tracing. */
1595 trace_reset_local_state (void)
1597 set_traceframe_num (-1);
1598 set_tracepoint_num (-1);
1599 set_traceframe_context (NULL
);
1600 clear_traceframe_info ();
1604 start_tracing (char *notes
)
1606 VEC(breakpoint_p
) *tp_vec
= NULL
;
1608 struct breakpoint
*b
;
1609 struct trace_state_variable
*tsv
;
1610 int any_enabled
= 0, num_to_download
= 0;
1613 tp_vec
= all_tracepoints ();
1615 /* No point in tracing without any tracepoints... */
1616 if (VEC_length (breakpoint_p
, tp_vec
) == 0)
1618 VEC_free (breakpoint_p
, tp_vec
);
1619 error (_("No tracepoints defined, not starting trace"));
1622 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1624 if (b
->enable_state
== bp_enabled
)
1627 if ((b
->type
== bp_fast_tracepoint
1628 ? may_insert_fast_tracepoints
1629 : may_insert_tracepoints
))
1632 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1633 (b
->type
== bp_fast_tracepoint
? "fast " : ""), b
->number
);
1638 if (target_supports_enable_disable_tracepoint ())
1639 warning (_("No tracepoints enabled"));
1642 /* No point in tracing with only disabled tracepoints that
1643 cannot be re-enabled. */
1644 VEC_free (breakpoint_p
, tp_vec
);
1645 error (_("No tracepoints enabled, not starting trace"));
1649 if (num_to_download
<= 0)
1651 VEC_free (breakpoint_p
, tp_vec
);
1652 error (_("No tracepoints that may be downloaded, not starting trace"));
1655 target_trace_init ();
1657 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1659 struct tracepoint
*t
= (struct tracepoint
*) b
;
1660 struct bp_location
*loc
;
1661 int bp_location_downloaded
= 0;
1663 /* Clear `inserted' flag. */
1664 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1667 if ((b
->type
== bp_fast_tracepoint
1668 ? !may_insert_fast_tracepoints
1669 : !may_insert_tracepoints
))
1672 t
->number_on_target
= 0;
1674 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1676 /* Since tracepoint locations are never duplicated, `inserted'
1677 flag should be zero. */
1678 gdb_assert (!loc
->inserted
);
1680 target_download_tracepoint (loc
);
1683 bp_location_downloaded
= 1;
1686 t
->number_on_target
= b
->number
;
1688 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1689 if (loc
->probe
.probe
!= NULL
1690 && loc
->probe
.probe
->pops
->set_semaphore
!= NULL
)
1691 loc
->probe
.probe
->pops
->set_semaphore (loc
->probe
.probe
,
1695 if (bp_location_downloaded
)
1696 observer_notify_breakpoint_modified (b
);
1698 VEC_free (breakpoint_p
, tp_vec
);
1700 /* Send down all the trace state variables too. */
1701 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1703 target_download_trace_state_variable (tsv
);
1706 /* Tell target to treat text-like sections as transparent. */
1707 target_trace_set_readonly_regions ();
1708 /* Set some mode flags. */
1709 target_set_disconnected_tracing (disconnected_tracing
);
1710 target_set_circular_trace_buffer (circular_trace_buffer
);
1711 target_set_trace_buffer_size (trace_buffer_size
);
1714 notes
= trace_notes
;
1715 ret
= target_set_trace_notes (trace_user
, notes
, NULL
);
1717 if (!ret
&& (trace_user
|| notes
))
1718 warning (_("Target does not support trace user/notes, info ignored"));
1720 /* Now insert traps and begin collecting data. */
1721 target_trace_start ();
1723 /* Reset our local state. */
1724 trace_reset_local_state ();
1725 current_trace_status()->running
= 1;
1728 /* The tstart command requests the target to start a new trace run.
1729 The command passes any arguments it has to the target verbatim, as
1730 an optional "trace note". This is useful as for instance a warning
1731 to other users if the trace runs disconnected, and you don't want
1732 anybody else messing with the target. */
1735 tstart_command (char *args
, int from_tty
)
1737 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1739 if (current_trace_status ()->running
)
1742 && !query (_("A trace is running already. Start a new run? ")))
1743 error (_("New trace run not started."));
1746 start_tracing (args
);
1749 /* The tstop command stops the tracing run. The command passes any
1750 supplied arguments to the target verbatim as a "stop note"; if the
1751 target supports trace notes, then it will be reported back as part
1752 of the trace run's status. */
1755 tstop_command (char *args
, int from_tty
)
1757 if (!current_trace_status ()->running
)
1758 error (_("Trace is not running."));
1760 stop_tracing (args
);
1764 stop_tracing (char *note
)
1767 VEC(breakpoint_p
) *tp_vec
= NULL
;
1769 struct breakpoint
*t
;
1771 target_trace_stop ();
1773 tp_vec
= all_tracepoints ();
1774 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1776 struct bp_location
*loc
;
1778 if ((t
->type
== bp_fast_tracepoint
1779 ? !may_insert_fast_tracepoints
1780 : !may_insert_tracepoints
))
1783 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
1785 /* GDB can be totally absent in some disconnected trace scenarios,
1786 but we don't really care if this semaphore goes out of sync.
1787 That's why we are decrementing it here, but not taking care
1789 if (loc
->probe
.probe
!= NULL
1790 && loc
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
1791 loc
->probe
.probe
->pops
->clear_semaphore (loc
->probe
.probe
,
1797 VEC_free (breakpoint_p
, tp_vec
);
1800 note
= trace_stop_notes
;
1801 ret
= target_set_trace_notes (NULL
, NULL
, note
);
1804 warning (_("Target does not support trace notes, note ignored"));
1806 /* Should change in response to reply? */
1807 current_trace_status ()->running
= 0;
1810 /* tstatus command */
1812 tstatus_command (char *args
, int from_tty
)
1814 struct trace_status
*ts
= current_trace_status ();
1816 VEC(breakpoint_p
) *tp_vec
= NULL
;
1817 struct breakpoint
*t
;
1819 status
= target_get_trace_status (ts
);
1823 if (ts
->filename
!= NULL
)
1824 printf_filtered (_("Using a trace file.\n"));
1827 printf_filtered (_("Trace can not be run on this target.\n"));
1832 if (!ts
->running_known
)
1834 printf_filtered (_("Run/stop status is unknown.\n"));
1836 else if (ts
->running
)
1838 printf_filtered (_("Trace is running on the target.\n"));
1842 switch (ts
->stop_reason
)
1844 case trace_never_run
:
1845 printf_filtered (_("No trace has been run on the target.\n"));
1847 case trace_stop_command
:
1849 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1852 printf_filtered (_("Trace stopped by a tstop command.\n"));
1854 case trace_buffer_full
:
1855 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1857 case trace_disconnected
:
1858 printf_filtered (_("Trace stopped because of disconnection.\n"));
1860 case tracepoint_passcount
:
1861 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1862 ts
->stopping_tracepoint
);
1864 case tracepoint_error
:
1865 if (ts
->stopping_tracepoint
)
1866 printf_filtered (_("Trace stopped by an "
1867 "error (%s, tracepoint %d).\n"),
1868 ts
->stop_desc
, ts
->stopping_tracepoint
);
1870 printf_filtered (_("Trace stopped by an error (%s).\n"),
1873 case trace_stop_reason_unknown
:
1874 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1877 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1883 if (ts
->traceframes_created
>= 0
1884 && ts
->traceframe_count
!= ts
->traceframes_created
)
1886 printf_filtered (_("Buffer contains %d trace "
1887 "frames (of %d created total).\n"),
1888 ts
->traceframe_count
, ts
->traceframes_created
);
1890 else if (ts
->traceframe_count
>= 0)
1892 printf_filtered (_("Collected %d trace frames.\n"),
1893 ts
->traceframe_count
);
1896 if (ts
->buffer_free
>= 0)
1898 if (ts
->buffer_size
>= 0)
1900 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1901 ts
->buffer_free
, ts
->buffer_size
);
1902 if (ts
->buffer_size
> 0)
1903 printf_filtered (_(" (%d%% full)"),
1904 ((int) ((((long long) (ts
->buffer_size
1905 - ts
->buffer_free
)) * 100)
1906 / ts
->buffer_size
)));
1907 printf_filtered (_(".\n"));
1910 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1914 if (ts
->disconnected_tracing
)
1915 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1917 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1919 if (ts
->circular_buffer
)
1920 printf_filtered (_("Trace buffer is circular.\n"));
1922 if (ts
->user_name
&& strlen (ts
->user_name
) > 0)
1923 printf_filtered (_("Trace user is %s.\n"), ts
->user_name
);
1925 if (ts
->notes
&& strlen (ts
->notes
) > 0)
1926 printf_filtered (_("Trace notes: %s.\n"), ts
->notes
);
1928 /* Now report on what we're doing with tfind. */
1929 if (traceframe_number
>= 0)
1930 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1931 traceframe_number
, tracepoint_number
);
1933 printf_filtered (_("Not looking at any trace frame.\n"));
1935 /* Report start/stop times if supplied. */
1940 LONGEST run_time
= ts
->stop_time
- ts
->start_time
;
1942 /* Reporting a run time is more readable than two long numbers. */
1943 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
1944 (long int) (ts
->start_time
/ 1000000),
1945 (long int) (ts
->start_time
% 1000000),
1946 (long int) (run_time
/ 1000000),
1947 (long int) (run_time
% 1000000));
1950 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
1951 (long int) (ts
->start_time
/ 1000000),
1952 (long int) (ts
->start_time
% 1000000));
1954 else if (ts
->stop_time
)
1955 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
1956 (long int) (ts
->stop_time
/ 1000000),
1957 (long int) (ts
->stop_time
% 1000000));
1959 /* Now report any per-tracepoint status available. */
1960 tp_vec
= all_tracepoints ();
1962 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1963 target_get_tracepoint_status (t
, NULL
);
1965 VEC_free (breakpoint_p
, tp_vec
);
1968 /* Report the trace status to uiout, in a way suitable for MI, and not
1969 suitable for CLI. If ON_STOP is true, suppress a few fields that
1970 are not meaningful in the -trace-stop response.
1972 The implementation is essentially parallel to trace_status_command, but
1973 merging them will result in unreadable code. */
1975 trace_status_mi (int on_stop
)
1977 struct ui_out
*uiout
= current_uiout
;
1978 struct trace_status
*ts
= current_trace_status ();
1981 status
= target_get_trace_status (ts
);
1983 if (status
== -1 && ts
->filename
== NULL
)
1985 uiout
->field_string ("supported", "0");
1989 if (ts
->filename
!= NULL
)
1990 uiout
->field_string ("supported", "file");
1992 uiout
->field_string ("supported", "1");
1994 if (ts
->filename
!= NULL
)
1995 uiout
->field_string ("trace-file", ts
->filename
);
1997 gdb_assert (ts
->running_known
);
2001 uiout
->field_string ("running", "1");
2003 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
2004 Given that the frontend gets the status either on -trace-stop, or from
2005 -trace-status after re-connection, it does not seem like this
2006 information is necessary for anything. It is not necessary for either
2007 figuring the vital state of the target nor for navigation of trace
2008 frames. If the frontend wants to show the current state is some
2009 configure dialog, it can request the value when such dialog is
2010 invoked by the user. */
2014 const char *stop_reason
= NULL
;
2015 int stopping_tracepoint
= -1;
2018 uiout
->field_string ("running", "0");
2020 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
2022 switch (ts
->stop_reason
)
2024 case trace_stop_command
:
2025 stop_reason
= "request";
2027 case trace_buffer_full
:
2028 stop_reason
= "overflow";
2030 case trace_disconnected
:
2031 stop_reason
= "disconnection";
2033 case tracepoint_passcount
:
2034 stop_reason
= "passcount";
2035 stopping_tracepoint
= ts
->stopping_tracepoint
;
2037 case tracepoint_error
:
2038 stop_reason
= "error";
2039 stopping_tracepoint
= ts
->stopping_tracepoint
;
2045 uiout
->field_string ("stop-reason", stop_reason
);
2046 if (stopping_tracepoint
!= -1)
2047 uiout
->field_int ("stopping-tracepoint",
2048 stopping_tracepoint
);
2049 if (ts
->stop_reason
== tracepoint_error
)
2050 uiout
->field_string ("error-description",
2056 if (ts
->traceframe_count
!= -1)
2057 uiout
->field_int ("frames", ts
->traceframe_count
);
2058 if (ts
->traceframes_created
!= -1)
2059 uiout
->field_int ("frames-created", ts
->traceframes_created
);
2060 if (ts
->buffer_size
!= -1)
2061 uiout
->field_int ("buffer-size", ts
->buffer_size
);
2062 if (ts
->buffer_free
!= -1)
2063 uiout
->field_int ("buffer-free", ts
->buffer_free
);
2065 uiout
->field_int ("disconnected", ts
->disconnected_tracing
);
2066 uiout
->field_int ("circular", ts
->circular_buffer
);
2068 uiout
->field_string ("user-name", ts
->user_name
);
2069 uiout
->field_string ("notes", ts
->notes
);
2074 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2075 (long int) (ts
->start_time
/ 1000000),
2076 (long int) (ts
->start_time
% 1000000));
2077 uiout
->field_string ("start-time", buf
);
2078 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2079 (long int) (ts
->stop_time
/ 1000000),
2080 (long int) (ts
->stop_time
% 1000000));
2081 uiout
->field_string ("stop-time", buf
);
2085 /* Check if a trace run is ongoing. If so, and FROM_TTY, query the
2086 user if she really wants to detach. */
2089 query_if_trace_running (int from_tty
)
2094 /* It can happen that the target that was tracing went away on its
2095 own, and we didn't notice. Get a status update, and if the
2096 current target doesn't even do tracing, then assume it's not
2098 if (target_get_trace_status (current_trace_status ()) < 0)
2099 current_trace_status ()->running
= 0;
2101 /* If running interactively, give the user the option to cancel and
2102 then decide what to do differently with the run. Scripts are
2103 just going to disconnect and let the target deal with it,
2104 according to how it's been instructed previously via
2105 disconnected-tracing. */
2106 if (current_trace_status ()->running
)
2108 process_tracepoint_on_disconnect ();
2110 if (current_trace_status ()->disconnected_tracing
)
2112 if (!query (_("Trace is running and will "
2113 "continue after detach; detach anyway? ")))
2114 error (_("Not confirmed."));
2118 if (!query (_("Trace is running but will "
2119 "stop on detach; detach anyway? ")))
2120 error (_("Not confirmed."));
2125 /* This function handles the details of what to do about an ongoing
2126 tracing run if the user has asked to detach or otherwise disconnect
2130 disconnect_tracing (void)
2132 /* Also we want to be out of tfind mode, otherwise things can get
2133 confusing upon reconnection. Just use these calls instead of
2134 full tfind_1 behavior because we're in the middle of detaching,
2135 and there's no point to updating current stack frame etc. */
2136 trace_reset_local_state ();
2139 /* Worker function for the various flavors of the tfind command. */
2141 tfind_1 (enum trace_find_type type
, int num
,
2142 CORE_ADDR addr1
, CORE_ADDR addr2
,
2145 int target_frameno
= -1, target_tracept
= -1;
2146 struct frame_id old_frame_id
= null_frame_id
;
2147 struct tracepoint
*tp
;
2148 struct ui_out
*uiout
= current_uiout
;
2150 /* Only try to get the current stack frame if we have a chance of
2151 succeeding. In particular, if we're trying to get a first trace
2152 frame while all threads are running, it's not going to succeed,
2153 so leave it with a default value and let the frame comparison
2154 below (correctly) decide to print out the source location of the
2156 if (!(type
== tfind_number
&& num
== -1)
2157 && (has_stack_frames () || traceframe_number
>= 0))
2158 old_frame_id
= get_frame_id (get_current_frame ());
2160 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
2163 if (type
== tfind_number
2165 && target_frameno
== -1)
2167 /* We told the target to get out of tfind mode, and it did. */
2169 else if (target_frameno
== -1)
2171 /* A request for a non-existent trace frame has failed.
2172 Our response will be different, depending on FROM_TTY:
2174 If FROM_TTY is true, meaning that this command was
2175 typed interactively by the user, then give an error
2176 and DO NOT change the state of traceframe_number etc.
2178 However if FROM_TTY is false, meaning that we're either
2179 in a script, a loop, or a user-defined command, then
2180 DON'T give an error, but DO change the state of
2181 traceframe_number etc. to invalid.
2183 The rationalle is that if you typed the command, you
2184 might just have committed a typo or something, and you'd
2185 like to NOT lose your current debugging state. However
2186 if you're in a user-defined command or especially in a
2187 loop, then you need a way to detect that the command
2188 failed WITHOUT aborting. This allows you to write
2189 scripts that search thru the trace buffer until the end,
2190 and then continue on to do something else. */
2193 error (_("Target failed to find requested trace frame."));
2197 printf_filtered ("End of trace buffer.\n");
2198 #if 0 /* dubious now? */
2199 /* The following will not recurse, since it's
2201 tfind_command ("-1", from_tty
);
2206 tp
= get_tracepoint_by_number_on_target (target_tracept
);
2208 reinit_frame_cache ();
2209 target_dcache_invalidate ();
2211 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
2213 if (target_frameno
!= get_traceframe_number ())
2214 observer_notify_traceframe_changed (target_frameno
, tracepoint_number
);
2216 set_current_traceframe (target_frameno
);
2218 if (target_frameno
== -1)
2219 set_traceframe_context (NULL
);
2221 set_traceframe_context (get_current_frame ());
2223 if (traceframe_number
>= 0)
2225 /* Use different branches for MI and CLI to make CLI messages
2227 if (uiout
->is_mi_like_p ())
2229 uiout
->field_string ("found", "1");
2230 uiout
->field_int ("tracepoint", tracepoint_number
);
2231 uiout
->field_int ("traceframe", traceframe_number
);
2235 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2236 traceframe_number
, tracepoint_number
);
2241 if (uiout
->is_mi_like_p ())
2242 uiout
->field_string ("found", "0");
2243 else if (type
== tfind_number
&& num
== -1)
2244 printf_unfiltered (_("No longer looking at any trace frame\n"));
2245 else /* This case may never occur, check. */
2246 printf_unfiltered (_("No trace frame found\n"));
2249 /* If we're in nonstop mode and getting out of looking at trace
2250 frames, there won't be any current frame to go back to and
2253 && (has_stack_frames () || traceframe_number
>= 0))
2255 enum print_what print_what
;
2257 /* NOTE: in imitation of the step command, try to determine
2258 whether we have made a transition from one function to
2259 another. If so, we'll print the "stack frame" (ie. the new
2260 function and it's arguments) -- otherwise we'll just show the
2263 if (frame_id_eq (old_frame_id
,
2264 get_frame_id (get_current_frame ())))
2265 print_what
= SRC_LINE
;
2267 print_what
= SRC_AND_LOC
;
2269 print_stack_frame (get_selected_frame (NULL
), 1, print_what
, 1);
2274 /* Error on looking at traceframes while trace is running. */
2277 check_trace_running (struct trace_status
*status
)
2279 if (status
->running
&& status
->filename
== NULL
)
2280 error (_("May not look at trace frames while trace is running."));
2283 /* trace_find_command takes a trace frame number n,
2284 sends "QTFrame:<n>" to the target,
2285 and accepts a reply that may contain several optional pieces
2286 of information: a frame number, a tracepoint number, and an
2287 indication of whether this is a trap frame or a stepping frame.
2289 The minimal response is just "OK" (which indicates that the
2290 target does not give us a frame number or a tracepoint number).
2291 Instead of that, the target may send us a string containing
2293 F<hexnum> (gives the selected frame number)
2294 T<hexnum> (gives the selected tracepoint number)
2299 tfind_command_1 (const char *args
, int from_tty
)
2300 { /* This should only be called with a numeric argument. */
2303 check_trace_running (current_trace_status ());
2305 if (args
== 0 || *args
== 0)
2306 { /* TFIND with no args means find NEXT trace frame. */
2307 if (traceframe_number
== -1)
2308 frameno
= 0; /* "next" is first one. */
2310 frameno
= traceframe_number
+ 1;
2312 else if (0 == strcmp (args
, "-"))
2314 if (traceframe_number
== -1)
2315 error (_("not debugging trace buffer"));
2316 else if (from_tty
&& traceframe_number
== 0)
2317 error (_("already at start of trace buffer"));
2319 frameno
= traceframe_number
- 1;
2321 /* A hack to work around eval's need for fp to have been collected. */
2322 else if (0 == strcmp (args
, "-1"))
2325 frameno
= parse_and_eval_long (args
);
2328 error (_("invalid input (%d is less than zero)"), frameno
);
2330 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
2334 tfind_command (const char *args
, int from_tty
)
2336 tfind_command_1 (const_cast<char *> (args
), from_tty
);
2341 tfind_end_command (const char *args
, int from_tty
)
2343 tfind_command_1 ("-1", from_tty
);
2348 tfind_start_command (const char *args
, int from_tty
)
2350 tfind_command_1 ("0", from_tty
);
2353 /* tfind pc command */
2355 tfind_pc_command (const char *args
, int from_tty
)
2359 check_trace_running (current_trace_status ());
2361 if (args
== 0 || *args
== 0)
2362 pc
= regcache_read_pc (get_current_regcache ());
2364 pc
= parse_and_eval_address (args
);
2366 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
2369 /* tfind tracepoint command */
2371 tfind_tracepoint_command (const char *args
, int from_tty
)
2374 struct tracepoint
*tp
;
2376 check_trace_running (current_trace_status ());
2378 if (args
== 0 || *args
== 0)
2380 if (tracepoint_number
== -1)
2381 error (_("No current tracepoint -- please supply an argument."));
2383 tdp
= tracepoint_number
; /* Default is current TDP. */
2386 tdp
= parse_and_eval_long (args
);
2388 /* If we have the tracepoint on hand, use the number that the
2389 target knows about (which may be different if we disconnected
2390 and reconnected). */
2391 tp
= get_tracepoint (tdp
);
2393 tdp
= tp
->number_on_target
;
2395 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
2398 /* TFIND LINE command:
2400 This command will take a sourceline for argument, just like BREAK
2401 or TRACE (ie. anything that "decode_line_1" can handle).
2403 With no argument, this command will find the next trace frame
2404 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2407 tfind_line_command (const char *args
, int from_tty
)
2409 check_trace_running (current_trace_status ());
2411 symtab_and_line sal
;
2412 if (args
== 0 || *args
== 0)
2414 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2418 std::vector
<symtab_and_line
> sals
2419 = decode_line_with_current_source (args
, DECODE_LINE_FUNFIRSTLINE
);
2423 if (sal
.symtab
== 0)
2424 error (_("No line number information available."));
2426 CORE_ADDR start_pc
, end_pc
;
2427 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2429 if (start_pc
== end_pc
)
2431 printf_filtered ("Line %d of \"%s\"",
2433 symtab_to_filename_for_display (sal
.symtab
));
2435 printf_filtered (" is at address ");
2436 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2438 printf_filtered (" but contains no code.\n");
2439 sal
= find_pc_line (start_pc
, 0);
2441 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2442 && start_pc
!= end_pc
)
2443 printf_filtered ("Attempting to find line %d instead.\n",
2446 error (_("Cannot find a good line."));
2450 /* Is there any case in which we get here, and have an address
2451 which the user would want to see? If we have debugging
2452 symbols and no line numbers? */
2453 error (_("Line number %d is out of range for \"%s\"."),
2454 sal
.line
, symtab_to_filename_for_display (sal
.symtab
));
2456 /* Find within range of stated line. */
2458 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2460 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2463 /* tfind range command */
2465 tfind_range_command (const char *args
, int from_tty
)
2467 static CORE_ADDR start
, stop
;
2470 check_trace_running (current_trace_status ());
2472 if (args
== 0 || *args
== 0)
2473 { /* XXX FIXME: what should default behavior be? */
2474 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2478 if (0 != (tmp
= strchr (args
, ',')))
2480 std::string
start_addr (args
, tmp
);
2482 tmp
= skip_spaces (tmp
);
2483 start
= parse_and_eval_address (start_addr
.c_str ());
2484 stop
= parse_and_eval_address (tmp
);
2487 { /* No explicit end address? */
2488 start
= parse_and_eval_address (args
);
2489 stop
= start
+ 1; /* ??? */
2492 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2495 /* tfind outside command */
2497 tfind_outside_command (const char *args
, int from_tty
)
2499 CORE_ADDR start
, stop
;
2502 if (current_trace_status ()->running
2503 && current_trace_status ()->filename
== NULL
)
2504 error (_("May not look at trace frames while trace is running."));
2506 if (args
== 0 || *args
== 0)
2507 { /* XXX FIXME: what should default behavior be? */
2508 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2512 if (0 != (tmp
= strchr (args
, ',')))
2514 std::string
start_addr (args
, tmp
);
2516 tmp
= skip_spaces (tmp
);
2517 start
= parse_and_eval_address (start_addr
.c_str ());
2518 stop
= parse_and_eval_address (tmp
);
2521 { /* No explicit end address? */
2522 start
= parse_and_eval_address (args
);
2523 stop
= start
+ 1; /* ??? */
2526 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2529 /* info scope command: list the locals for a scope. */
2531 info_scope_command (char *args_in
, int from_tty
)
2534 struct bound_minimal_symbol msym
;
2535 const struct block
*block
;
2536 const char *symname
;
2537 const char *save_args
= args_in
;
2538 struct block_iterator iter
;
2540 struct gdbarch
*gdbarch
;
2542 const char *args
= args_in
;
2544 if (args
== 0 || *args
== 0)
2545 error (_("requires an argument (function, "
2546 "line or *addr) to define a scope"));
2548 event_location_up location
= string_to_event_location (&args
,
2550 std::vector
<symtab_and_line
> sals
2551 = decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
2555 /* Presumably decode_line_1 has already warned. */
2559 /* Resolve line numbers to PC. */
2560 resolve_sal_pc (&sals
[0]);
2561 block
= block_for_pc (sals
[0].pc
);
2565 QUIT
; /* Allow user to bail out with ^C. */
2566 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2568 QUIT
; /* Allow user to bail out with ^C. */
2570 printf_filtered ("Scope for %s:\n", save_args
);
2573 symname
= SYMBOL_PRINT_NAME (sym
);
2574 if (symname
== NULL
|| *symname
== '\0')
2575 continue; /* Probably botched, certainly useless. */
2577 gdbarch
= symbol_arch (sym
);
2579 printf_filtered ("Symbol %s is ", symname
);
2581 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
2582 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
,
2583 BLOCK_START (block
),
2587 switch (SYMBOL_CLASS (sym
))
2590 case LOC_UNDEF
: /* Messed up symbol? */
2591 printf_filtered ("a bogus symbol, class %d.\n",
2592 SYMBOL_CLASS (sym
));
2593 count
--; /* Don't count this one. */
2596 printf_filtered ("a constant with value %s (%s)",
2597 plongest (SYMBOL_VALUE (sym
)),
2598 hex_string (SYMBOL_VALUE (sym
)));
2600 case LOC_CONST_BYTES
:
2601 printf_filtered ("constant bytes: ");
2602 if (SYMBOL_TYPE (sym
))
2603 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2604 fprintf_filtered (gdb_stdout
, " %02x",
2605 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2608 printf_filtered ("in static storage at address ");
2609 printf_filtered ("%s", paddress (gdbarch
,
2610 SYMBOL_VALUE_ADDRESS (sym
)));
2613 /* GDBARCH is the architecture associated with the objfile
2614 the symbol is defined in; the target architecture may be
2615 different, and may provide additional registers. However,
2616 we do not know the target architecture at this point.
2617 We assume the objfile architecture will contain all the
2618 standard registers that occur in debug info in that
2620 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2623 if (SYMBOL_IS_ARGUMENT (sym
))
2624 printf_filtered ("an argument in register $%s",
2625 gdbarch_register_name (gdbarch
, regno
));
2627 printf_filtered ("a local variable in register $%s",
2628 gdbarch_register_name (gdbarch
, regno
));
2631 printf_filtered ("an argument at stack/frame offset %s",
2632 plongest (SYMBOL_VALUE (sym
)));
2635 printf_filtered ("a local variable at frame offset %s",
2636 plongest (SYMBOL_VALUE (sym
)));
2639 printf_filtered ("a reference argument at offset %s",
2640 plongest (SYMBOL_VALUE (sym
)));
2642 case LOC_REGPARM_ADDR
:
2643 /* Note comment at LOC_REGISTER. */
2644 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2646 printf_filtered ("the address of an argument, in register $%s",
2647 gdbarch_register_name (gdbarch
, regno
));
2650 printf_filtered ("a typedef.\n");
2653 printf_filtered ("a label at address ");
2654 printf_filtered ("%s", paddress (gdbarch
,
2655 SYMBOL_VALUE_ADDRESS (sym
)));
2658 printf_filtered ("a function at address ");
2659 printf_filtered ("%s",
2660 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2662 case LOC_UNRESOLVED
:
2663 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2665 if (msym
.minsym
== NULL
)
2666 printf_filtered ("Unresolved Static");
2669 printf_filtered ("static storage at address ");
2670 printf_filtered ("%s",
2672 BMSYMBOL_VALUE_ADDRESS (msym
)));
2675 case LOC_OPTIMIZED_OUT
:
2676 printf_filtered ("optimized out.\n");
2679 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2682 if (SYMBOL_TYPE (sym
))
2683 printf_filtered (", length %d.\n",
2684 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2686 if (BLOCK_FUNCTION (block
))
2689 block
= BLOCK_SUPERBLOCK (block
);
2692 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2696 /* Helper for trace_dump_command. Dump the action list starting at
2697 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2698 actions of the body of a while-stepping action. STEPPING_FRAME is
2699 set if the current traceframe was determined to be a while-stepping
2703 trace_dump_actions (struct command_line
*action
,
2704 int stepping_actions
, int stepping_frame
,
2707 const char *action_exp
, *next_comma
;
2709 for (; action
!= NULL
; action
= action
->next
)
2711 struct cmd_list_element
*cmd
;
2713 QUIT
; /* Allow user to bail out with ^C. */
2714 action_exp
= action
->line
;
2715 action_exp
= skip_spaces (action_exp
);
2717 /* The collection actions to be done while stepping are
2718 bracketed by the commands "while-stepping" and "end". */
2720 if (*action_exp
== '#') /* comment line */
2723 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2725 error (_("Bad action list item: %s"), action_exp
);
2727 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2731 for (i
= 0; i
< action
->body_count
; ++i
)
2732 trace_dump_actions (action
->body_list
[i
],
2733 1, stepping_frame
, from_tty
);
2735 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2737 /* Display the collected data.
2738 For the trap frame, display only what was collected at
2739 the trap. Likewise for stepping frames, display only
2740 what was collected while stepping. This means that the
2741 two boolean variables, STEPPING_FRAME and
2742 STEPPING_ACTIONS should be equal. */
2743 if (stepping_frame
== stepping_actions
)
2746 struct cleanup
*old_chain
2747 = make_cleanup (free_current_contents
, &cmd
);
2748 int trace_string
= 0;
2750 if (*action_exp
== '/')
2751 action_exp
= decode_agent_options (action_exp
, &trace_string
);
2754 { /* Repeat over a comma-separated list. */
2755 QUIT
; /* Allow user to bail out with ^C. */
2756 if (*action_exp
== ',')
2758 action_exp
= skip_spaces (action_exp
);
2760 next_comma
= strchr (action_exp
, ',');
2762 if (0 == strncasecmp (action_exp
, "$reg", 4))
2763 registers_info (NULL
, from_tty
);
2764 else if (0 == strncasecmp (action_exp
, "$_ret", 5))
2766 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2767 info_locals_command (NULL
, from_tty
);
2768 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2769 info_args_command (NULL
, from_tty
);
2772 if (next_comma
!= NULL
)
2774 size_t len
= next_comma
- action_exp
;
2776 cmd
= (char *) xrealloc (cmd
, len
+ 1);
2777 memcpy (cmd
, action_exp
, len
);
2782 size_t len
= strlen (action_exp
);
2784 cmd
= (char *) xrealloc (cmd
, len
+ 1);
2785 memcpy (cmd
, action_exp
, len
+ 1);
2788 printf_filtered ("%s = ", cmd
);
2789 output_command_const (cmd
, from_tty
);
2790 printf_filtered ("\n");
2792 action_exp
= next_comma
;
2794 while (action_exp
&& *action_exp
== ',');
2796 do_cleanups (old_chain
);
2802 /* Return bp_location of the tracepoint associated with the current
2803 traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe
2804 is a stepping traceframe. */
2806 struct bp_location
*
2807 get_traceframe_location (int *stepping_frame_p
)
2809 struct tracepoint
*t
;
2810 struct bp_location
*tloc
;
2811 struct regcache
*regcache
;
2813 if (tracepoint_number
== -1)
2814 error (_("No current trace frame."));
2816 t
= get_tracepoint (tracepoint_number
);
2819 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2822 /* The current frame is a trap frame if the frame PC is equal to the
2823 tracepoint PC. If not, then the current frame was collected
2824 during single-stepping. */
2825 regcache
= get_current_regcache ();
2827 /* If the traceframe's address matches any of the tracepoint's
2828 locations, assume it is a direct hit rather than a while-stepping
2829 frame. (FIXME this is not reliable, should record each frame's
2831 for (tloc
= t
->loc
; tloc
; tloc
= tloc
->next
)
2832 if (tloc
->address
== regcache_read_pc (regcache
))
2834 *stepping_frame_p
= 0;
2838 /* If this is a stepping frame, we don't know which location
2839 triggered. The first is as good (or bad) a guess as any... */
2840 *stepping_frame_p
= 1;
2844 /* Return all the actions, including default collect, of a tracepoint
2845 T. It constructs cleanups into the chain, and leaves the caller to
2846 handle them (call do_cleanups). */
2848 static struct command_line
*
2849 all_tracepoint_actions_and_cleanup (struct breakpoint
*t
)
2851 struct command_line
*actions
;
2853 actions
= breakpoint_commands (t
);
2855 /* If there are default expressions to collect, make up a collect
2856 action and prepend to the action list to encode. Note that since
2857 validation is per-tracepoint (local var "xyz" might be valid for
2858 one tracepoint and not another, etc), we make up the action on
2859 the fly, and don't cache it. */
2860 if (*default_collect
)
2862 struct command_line
*default_collect_action
;
2863 char *default_collect_line
;
2865 default_collect_line
= xstrprintf ("collect %s", default_collect
);
2866 make_cleanup (xfree
, default_collect_line
);
2868 validate_actionline (default_collect_line
, t
);
2869 default_collect_action
= XNEW (struct command_line
);
2870 make_cleanup (xfree
, default_collect_action
);
2871 default_collect_action
->next
= actions
;
2872 default_collect_action
->line
= default_collect_line
;
2873 actions
= default_collect_action
;
2879 /* The tdump command. */
2882 tdump_command (char *args
, int from_tty
)
2884 int stepping_frame
= 0;
2885 struct bp_location
*loc
;
2886 struct command_line
*actions
;
2888 /* This throws an error is not inspecting a trace frame. */
2889 loc
= get_traceframe_location (&stepping_frame
);
2891 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2892 tracepoint_number
, traceframe_number
);
2894 /* This command only makes sense for the current frame, not the
2896 scoped_restore_current_thread restore_thread
;
2898 select_frame (get_current_frame ());
2900 actions
= all_tracepoint_actions_and_cleanup (loc
->owner
);
2902 trace_dump_actions (actions
, 0, stepping_frame
, from_tty
);
2905 /* Encode a piece of a tracepoint's source-level definition in a form
2906 that is suitable for both protocol and saving in files. */
2907 /* This version does not do multiple encodes for long strings; it should
2908 return an offset to the next piece to encode. FIXME */
2911 encode_source_string (int tpnum
, ULONGEST addr
,
2912 const char *srctype
, const char *src
,
2913 char *buf
, int buf_size
)
2915 if (80 + strlen (srctype
) > buf_size
)
2916 error (_("Buffer too small for source encoding"));
2917 sprintf (buf
, "%x:%s:%s:%x:%x:",
2918 tpnum
, phex_nz (addr
, sizeof (addr
)),
2919 srctype
, 0, (int) strlen (src
));
2920 if (strlen (buf
) + strlen (src
) * 2 >= buf_size
)
2921 error (_("Source string too long for buffer"));
2922 bin2hex ((gdb_byte
*) src
, buf
+ strlen (buf
), strlen (src
));
2926 /* Tell the target what to do with an ongoing tracing run if GDB
2927 disconnects for some reason. */
2930 set_disconnected_tracing (char *args
, int from_tty
,
2931 struct cmd_list_element
*c
)
2933 target_set_disconnected_tracing (disconnected_tracing
);
2937 set_circular_trace_buffer (char *args
, int from_tty
,
2938 struct cmd_list_element
*c
)
2940 target_set_circular_trace_buffer (circular_trace_buffer
);
2944 set_trace_buffer_size (char *args
, int from_tty
,
2945 struct cmd_list_element
*c
)
2947 target_set_trace_buffer_size (trace_buffer_size
);
2951 set_trace_user (char *args
, int from_tty
,
2952 struct cmd_list_element
*c
)
2956 ret
= target_set_trace_notes (trace_user
, NULL
, NULL
);
2959 warning (_("Target does not support trace notes, user ignored"));
2963 set_trace_notes (char *args
, int from_tty
,
2964 struct cmd_list_element
*c
)
2968 ret
= target_set_trace_notes (NULL
, trace_notes
, NULL
);
2971 warning (_("Target does not support trace notes, note ignored"));
2975 set_trace_stop_notes (char *args
, int from_tty
,
2976 struct cmd_list_element
*c
)
2980 ret
= target_set_trace_notes (NULL
, NULL
, trace_stop_notes
);
2983 warning (_("Target does not support trace notes, stop note ignored"));
2986 /* Convert the memory pointed to by mem into hex, placing result in buf.
2987 * Return a pointer to the last char put in buf (null)
2988 * "stolen" from sparc-stub.c
2991 static const char hexchars
[] = "0123456789abcdef";
2994 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
3002 *buf
++ = hexchars
[ch
>> 4];
3003 *buf
++ = hexchars
[ch
& 0xf];
3012 get_traceframe_number (void)
3014 return traceframe_number
;
3018 get_tracepoint_number (void)
3020 return tracepoint_number
;
3023 /* Make the traceframe NUM be the current trace frame. Does nothing
3024 if NUM is already current. */
3027 set_current_traceframe (int num
)
3031 if (traceframe_number
== num
)
3033 /* Nothing to do. */
3037 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
3040 warning (_("could not change traceframe"));
3042 set_traceframe_num (newnum
);
3044 /* Changing the traceframe changes our view of registers and of the
3046 registers_changed ();
3048 clear_traceframe_info ();
3051 /* A cleanup used when switching away and back from tfind mode. */
3053 struct current_traceframe_cleanup
3055 /* The traceframe we were inspecting. */
3056 int traceframe_number
;
3060 do_restore_current_traceframe_cleanup (void *arg
)
3062 struct current_traceframe_cleanup
*old
3063 = (struct current_traceframe_cleanup
*) arg
;
3065 set_current_traceframe (old
->traceframe_number
);
3069 restore_current_traceframe_cleanup_dtor (void *arg
)
3071 struct current_traceframe_cleanup
*old
3072 = (struct current_traceframe_cleanup
*) arg
;
3078 make_cleanup_restore_current_traceframe (void)
3080 struct current_traceframe_cleanup
*old
=
3081 XNEW (struct current_traceframe_cleanup
);
3083 old
->traceframe_number
= traceframe_number
;
3085 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
3086 restore_current_traceframe_cleanup_dtor
);
3089 /* Given a number and address, return an uploaded tracepoint with that
3090 number, creating if necessary. */
3092 struct uploaded_tp
*
3093 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
3095 struct uploaded_tp
*utp
;
3097 for (utp
= *utpp
; utp
; utp
= utp
->next
)
3098 if (utp
->number
== num
&& utp
->addr
== addr
)
3101 utp
= XCNEW (struct uploaded_tp
);
3104 utp
->actions
= NULL
;
3105 utp
->step_actions
= NULL
;
3106 utp
->cmd_strings
= NULL
;
3114 free_uploaded_tps (struct uploaded_tp
**utpp
)
3116 struct uploaded_tp
*next_one
;
3120 next_one
= (*utpp
)->next
;
3126 /* Given a number and address, return an uploaded tracepoint with that
3127 number, creating if necessary. */
3129 struct uploaded_tsv
*
3130 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
3132 struct uploaded_tsv
*utsv
;
3134 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
3135 if (utsv
->number
== num
)
3138 utsv
= XCNEW (struct uploaded_tsv
);
3140 utsv
->next
= *utsvp
;
3147 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
3149 struct uploaded_tsv
*next_one
;
3153 next_one
= (*utsvp
)->next
;
3159 /* FIXME this function is heuristic and will miss the cases where the
3160 conditional is semantically identical but differs in whitespace,
3161 such as "x == 0" vs "x==0". */
3164 cond_string_is_same (char *str1
, char *str2
)
3166 if (str1
== NULL
|| str2
== NULL
)
3167 return (str1
== str2
);
3169 return (strcmp (str1
, str2
) == 0);
3172 /* Look for an existing tracepoint that seems similar enough to the
3173 uploaded one. Enablement isn't compared, because the user can
3174 toggle that freely, and may have done so in anticipation of the
3175 next trace run. Return the location of matched tracepoint. */
3177 static struct bp_location
*
3178 find_matching_tracepoint_location (struct uploaded_tp
*utp
)
3180 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
3182 struct breakpoint
*b
;
3183 struct bp_location
*loc
;
3185 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
3187 struct tracepoint
*t
= (struct tracepoint
*) b
;
3189 if (b
->type
== utp
->type
3190 && t
->step_count
== utp
->step
3191 && t
->pass_count
== utp
->pass
3192 && cond_string_is_same (t
->cond_string
, utp
->cond_string
)
3193 /* FIXME also test actions. */
3196 /* Scan the locations for an address match. */
3197 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3199 if (loc
->address
== utp
->addr
)
3207 /* Given a list of tracepoints uploaded from a target, attempt to
3208 match them up with existing tracepoints, and create new ones if not
3212 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
3214 struct uploaded_tp
*utp
;
3215 /* A set of tracepoints which are modified. */
3216 VEC(breakpoint_p
) *modified_tp
= NULL
;
3218 struct breakpoint
*b
;
3220 /* Look for GDB tracepoints that match up with our uploaded versions. */
3221 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
3223 struct bp_location
*loc
;
3224 struct tracepoint
*t
;
3226 loc
= find_matching_tracepoint_location (utp
);
3231 /* Mark this location as already inserted. */
3233 t
= (struct tracepoint
*) loc
->owner
;
3234 printf_filtered (_("Assuming tracepoint %d is same "
3235 "as target's tracepoint %d at %s.\n"),
3236 loc
->owner
->number
, utp
->number
,
3237 paddress (loc
->gdbarch
, utp
->addr
));
3239 /* The tracepoint LOC->owner was modified (the location LOC
3240 was marked as inserted in the target). Save it in
3241 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3242 observers will be notified later once for each tracepoint
3243 saved in MODIFIED_TP. */
3245 VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
);
3247 if (b
== loc
->owner
)
3253 VEC_safe_push (breakpoint_p
, modified_tp
, loc
->owner
);
3257 t
= create_tracepoint_from_upload (utp
);
3259 printf_filtered (_("Created tracepoint %d for "
3260 "target's tracepoint %d at %s.\n"),
3261 t
->number
, utp
->number
,
3262 paddress (get_current_arch (), utp
->addr
));
3264 printf_filtered (_("Failed to create tracepoint for target's "
3265 "tracepoint %d at %s, skipping it.\n"),
3267 paddress (get_current_arch (), utp
->addr
));
3269 /* Whether found or created, record the number used by the
3270 target, to help with mapping target tracepoints back to their
3271 counterparts here. */
3273 t
->number_on_target
= utp
->number
;
3276 /* Notify 'breakpoint-modified' observer that at least one of B's
3277 locations was changed. */
3278 for (ix
= 0; VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
); ix
++)
3279 observer_notify_breakpoint_modified (b
);
3281 VEC_free (breakpoint_p
, modified_tp
);
3282 free_uploaded_tps (uploaded_tps
);
3285 /* Trace state variables don't have much to identify them beyond their
3286 name, so just use that to detect matches. */
3288 static struct trace_state_variable
*
3289 find_matching_tsv (struct uploaded_tsv
*utsv
)
3294 return find_trace_state_variable (utsv
->name
);
3297 static struct trace_state_variable
*
3298 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
3300 const char *namebase
;
3303 struct trace_state_variable
*tsv
;
3304 struct cleanup
*old_chain
;
3308 namebase
= utsv
->name
;
3314 buf
= string_printf ("%s_%d", namebase
, try_num
++);
3317 /* Fish for a name that is not in use. */
3318 /* (should check against all internal vars?) */
3319 while (find_trace_state_variable (buf
.c_str ()))
3320 buf
= string_printf ("%s_%d", namebase
, try_num
++);
3322 /* We have an available name, create the variable. */
3323 tsv
= create_trace_state_variable (buf
.c_str ());
3324 tsv
->initial_value
= utsv
->initial_value
;
3325 tsv
->builtin
= utsv
->builtin
;
3327 observer_notify_tsv_created (tsv
);
3332 /* Given a list of uploaded trace state variables, try to match them
3333 up with existing variables, or create additional ones. */
3336 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
3339 struct uploaded_tsv
*utsv
;
3340 struct trace_state_variable
*tsv
;
3343 /* Most likely some numbers will have to be reassigned as part of
3344 the merge, so clear them all in anticipation. */
3345 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3348 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
3350 tsv
= find_matching_tsv (utsv
);
3354 printf_filtered (_("Assuming trace state variable $%s "
3355 "is same as target's variable %d.\n"),
3356 tsv
->name
, utsv
->number
);
3360 tsv
= create_tsv_from_upload (utsv
);
3362 printf_filtered (_("Created trace state variable "
3363 "$%s for target's variable %d.\n"),
3364 tsv
->name
, utsv
->number
);
3366 /* Give precedence to numberings that come from the target. */
3368 tsv
->number
= utsv
->number
;
3371 /* Renumber everything that didn't get a target-assigned number. */
3373 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3374 if (tsv
->number
> highest
)
3375 highest
= tsv
->number
;
3378 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3379 if (tsv
->number
== 0)
3380 tsv
->number
= highest
++;
3382 free_uploaded_tsvs (uploaded_tsvs
);
3385 /* Parse the part of trace status syntax that is shared between
3386 the remote protocol and the trace file reader. */
3389 parse_trace_status (const char *line
, struct trace_status
*ts
)
3391 const char *p
= line
, *p1
, *p2
, *p3
, *p_temp
;
3395 ts
->running_known
= 1;
3396 ts
->running
= (*p
++ == '1');
3397 ts
->stop_reason
= trace_stop_reason_unknown
;
3398 xfree (ts
->stop_desc
);
3399 ts
->stop_desc
= NULL
;
3400 ts
->traceframe_count
= -1;
3401 ts
->traceframes_created
= -1;
3402 ts
->buffer_free
= -1;
3403 ts
->buffer_size
= -1;
3404 ts
->disconnected_tracing
= 0;
3405 ts
->circular_buffer
= 0;
3406 xfree (ts
->user_name
);
3407 ts
->user_name
= NULL
;
3410 ts
->start_time
= ts
->stop_time
= 0;
3414 p1
= strchr (p
, ':');
3416 error (_("Malformed trace status, at %s\n\
3417 Status line: '%s'\n"), p
, line
);
3418 p3
= strchr (p
, ';');
3420 p3
= p
+ strlen (p
);
3421 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
3423 p
= unpack_varlen_hex (++p1
, &val
);
3424 ts
->stop_reason
= trace_buffer_full
;
3426 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
3428 p
= unpack_varlen_hex (++p1
, &val
);
3429 ts
->stop_reason
= trace_never_run
;
3431 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
],
3434 p
= unpack_varlen_hex (++p1
, &val
);
3435 ts
->stop_reason
= tracepoint_passcount
;
3436 ts
->stopping_tracepoint
= val
;
3438 else if (strncmp (p
, stop_reason_names
[trace_stop_command
], p1
- p
) == 0)
3440 p2
= strchr (++p1
, ':');
3448 ts
->stop_desc
= (char *) xmalloc (strlen (line
));
3449 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3450 ts
->stop_desc
[end
] = '\0';
3453 ts
->stop_desc
= xstrdup ("");
3455 p
= unpack_varlen_hex (++p2
, &val
);
3456 ts
->stop_reason
= trace_stop_command
;
3458 else if (strncmp (p
, stop_reason_names
[trace_disconnected
], p1
- p
) == 0)
3460 p
= unpack_varlen_hex (++p1
, &val
);
3461 ts
->stop_reason
= trace_disconnected
;
3463 else if (strncmp (p
, stop_reason_names
[tracepoint_error
], p1
- p
) == 0)
3465 p2
= strchr (++p1
, ':');
3468 ts
->stop_desc
= (char *) xmalloc ((p2
- p1
) / 2 + 1);
3469 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3470 ts
->stop_desc
[end
] = '\0';
3473 ts
->stop_desc
= xstrdup ("");
3475 p
= unpack_varlen_hex (++p2
, &val
);
3476 ts
->stopping_tracepoint
= val
;
3477 ts
->stop_reason
= tracepoint_error
;
3479 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3481 p
= unpack_varlen_hex (++p1
, &val
);
3482 ts
->traceframe_count
= val
;
3484 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3486 p
= unpack_varlen_hex (++p1
, &val
);
3487 ts
->traceframes_created
= val
;
3489 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3491 p
= unpack_varlen_hex (++p1
, &val
);
3492 ts
->buffer_free
= val
;
3494 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3496 p
= unpack_varlen_hex (++p1
, &val
);
3497 ts
->buffer_size
= val
;
3499 else if (strncmp (p
, "disconn", p1
- p
) == 0)
3501 p
= unpack_varlen_hex (++p1
, &val
);
3502 ts
->disconnected_tracing
= val
;
3504 else if (strncmp (p
, "circular", p1
- p
) == 0)
3506 p
= unpack_varlen_hex (++p1
, &val
);
3507 ts
->circular_buffer
= val
;
3509 else if (strncmp (p
, "starttime", p1
- p
) == 0)
3511 p
= unpack_varlen_hex (++p1
, &val
);
3512 ts
->start_time
= val
;
3514 else if (strncmp (p
, "stoptime", p1
- p
) == 0)
3516 p
= unpack_varlen_hex (++p1
, &val
);
3517 ts
->stop_time
= val
;
3519 else if (strncmp (p
, "username", p1
- p
) == 0)
3522 ts
->user_name
= (char *) xmalloc (strlen (p
) / 2);
3523 end
= hex2bin (p1
, (gdb_byte
*) ts
->user_name
, (p3
- p1
) / 2);
3524 ts
->user_name
[end
] = '\0';
3527 else if (strncmp (p
, "notes", p1
- p
) == 0)
3530 ts
->notes
= (char *) xmalloc (strlen (p
) / 2);
3531 end
= hex2bin (p1
, (gdb_byte
*) ts
->notes
, (p3
- p1
) / 2);
3532 ts
->notes
[end
] = '\0';
3537 /* Silently skip unknown optional info. */
3538 p_temp
= strchr (p1
+ 1, ';');
3542 /* Must be at the end. */
3549 parse_tracepoint_status (const char *p
, struct breakpoint
*bp
,
3550 struct uploaded_tp
*utp
)
3553 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
3555 p
= unpack_varlen_hex (p
, &uval
);
3557 tp
->hit_count
+= uval
;
3559 utp
->hit_count
+= uval
;
3560 p
= unpack_varlen_hex (p
+ 1, &uval
);
3562 tp
->traceframe_usage
+= uval
;
3564 utp
->traceframe_usage
+= uval
;
3565 /* Ignore any extra, allowing for future extensions. */
3568 /* Given a line of text defining a part of a tracepoint, parse it into
3569 an "uploaded tracepoint". */
3572 parse_tracepoint_definition (const char *line
, struct uploaded_tp
**utpp
)
3576 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
, start
;
3579 const char *srctype
;
3581 struct uploaded_tp
*utp
= NULL
;
3584 /* Both tracepoint and action definitions start with the same number
3585 and address sequence. */
3587 p
= unpack_varlen_hex (p
, &num
);
3588 p
++; /* skip a colon */
3589 p
= unpack_varlen_hex (p
, &addr
);
3590 p
++; /* skip a colon */
3593 enabled
= (*p
++ == 'E');
3594 p
++; /* skip a colon */
3595 p
= unpack_varlen_hex (p
, &step
);
3596 p
++; /* skip a colon */
3597 p
= unpack_varlen_hex (p
, &pass
);
3598 type
= bp_tracepoint
;
3600 /* Thumb through optional fields. */
3603 p
++; /* skip a colon */
3606 type
= bp_fast_tracepoint
;
3608 p
= unpack_varlen_hex (p
, &orig_size
);
3612 type
= bp_static_tracepoint
;
3618 p
= unpack_varlen_hex (p
, &xlen
);
3619 p
++; /* skip a comma */
3620 cond
= (char *) xmalloc (2 * xlen
+ 1);
3621 strncpy (cond
, p
, 2 * xlen
);
3622 cond
[2 * xlen
] = '\0';
3626 warning (_("Unrecognized char '%c' in tracepoint "
3627 "definition, skipping rest"), *p
);
3629 utp
= get_uploaded_tp (num
, addr
, utpp
);
3631 utp
->enabled
= enabled
;
3636 else if (piece
== 'A')
3638 utp
= get_uploaded_tp (num
, addr
, utpp
);
3639 VEC_safe_push (char_ptr
, utp
->actions
, xstrdup (p
));
3641 else if (piece
== 'S')
3643 utp
= get_uploaded_tp (num
, addr
, utpp
);
3644 VEC_safe_push (char_ptr
, utp
->step_actions
, xstrdup (p
));
3646 else if (piece
== 'Z')
3648 /* Parse a chunk of source form definition. */
3649 utp
= get_uploaded_tp (num
, addr
, utpp
);
3651 p
= strchr (p
, ':');
3652 p
++; /* skip a colon */
3653 p
= unpack_varlen_hex (p
, &start
);
3654 p
++; /* skip a colon */
3655 p
= unpack_varlen_hex (p
, &xlen
);
3656 p
++; /* skip a colon */
3658 buf
= (char *) alloca (strlen (line
));
3660 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3663 if (startswith (srctype
, "at:"))
3664 utp
->at_string
= xstrdup (buf
);
3665 else if (startswith (srctype
, "cond:"))
3666 utp
->cond_string
= xstrdup (buf
);
3667 else if (startswith (srctype
, "cmd:"))
3668 VEC_safe_push (char_ptr
, utp
->cmd_strings
, xstrdup (buf
));
3670 else if (piece
== 'V')
3672 utp
= get_uploaded_tp (num
, addr
, utpp
);
3674 parse_tracepoint_status (p
, NULL
, utp
);
3678 /* Don't error out, the target might be sending us optional
3679 info that we don't care about. */
3680 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece
);
3684 /* Convert a textual description of a trace state variable into an
3688 parse_tsv_definition (const char *line
, struct uploaded_tsv
**utsvp
)
3692 ULONGEST num
, initval
, builtin
;
3694 struct uploaded_tsv
*utsv
= NULL
;
3696 buf
= (char *) alloca (strlen (line
));
3699 p
= unpack_varlen_hex (p
, &num
);
3700 p
++; /* skip a colon */
3701 p
= unpack_varlen_hex (p
, &initval
);
3702 p
++; /* skip a colon */
3703 p
= unpack_varlen_hex (p
, &builtin
);
3704 p
++; /* skip a colon */
3705 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3708 utsv
= get_uploaded_tsv (num
, utsvp
);
3709 utsv
->initial_value
= initval
;
3710 utsv
->builtin
= builtin
;
3711 utsv
->name
= xstrdup (buf
);
3715 free_current_marker (void *arg
)
3717 struct static_tracepoint_marker
**marker_p
3718 = (struct static_tracepoint_marker
**) arg
;
3720 if (*marker_p
!= NULL
)
3722 release_static_tracepoint_marker (*marker_p
);
3729 /* Given a line of text defining a static tracepoint marker, parse it
3730 into a "static tracepoint marker" object. Throws an error is
3731 parsing fails. If PP is non-null, it points to one past the end of
3732 the parsed marker definition. */
3735 parse_static_tracepoint_marker_definition (const char *line
, const char **pp
,
3736 struct static_tracepoint_marker
*marker
)
3738 const char *p
, *endp
;
3743 p
= unpack_varlen_hex (p
, &addr
);
3744 p
++; /* skip a colon */
3746 marker
->gdbarch
= target_gdbarch ();
3747 marker
->address
= (CORE_ADDR
) addr
;
3749 endp
= strchr (p
, ':');
3751 error (_("bad marker definition: %s"), line
);
3753 marker
->str_id
= (char *) xmalloc (endp
- p
+ 1);
3754 end
= hex2bin (p
, (gdb_byte
*) marker
->str_id
, (endp
- p
+ 1) / 2);
3755 marker
->str_id
[end
] = '\0';
3758 p
++; /* skip a colon */
3760 marker
->extra
= (char *) xmalloc (strlen (p
) + 1);
3761 end
= hex2bin (p
, (gdb_byte
*) marker
->extra
, strlen (p
) / 2);
3762 marker
->extra
[end
] = '\0';
3768 /* Release a static tracepoint marker's contents. Note that the
3769 object itself isn't released here. There objects are usually on
3773 release_static_tracepoint_marker (struct static_tracepoint_marker
*marker
)
3775 xfree (marker
->str_id
);
3776 marker
->str_id
= NULL
;
3779 /* Print MARKER to gdb_stdout. */
3782 print_one_static_tracepoint_marker (int count
,
3783 struct static_tracepoint_marker
*marker
)
3787 char wrap_indent
[80];
3788 char extra_field_indent
[80];
3789 struct ui_out
*uiout
= current_uiout
;
3790 VEC(breakpoint_p
) *tracepoints
;
3792 symtab_and_line sal
;
3793 sal
.pc
= marker
->address
;
3795 tracepoints
= static_tracepoints_here (marker
->address
);
3797 ui_out_emit_tuple
tuple_emitter (uiout
, "marker");
3799 /* A counter field to help readability. This is not a stable
3801 uiout
->field_int ("count", count
);
3803 uiout
->field_string ("marker-id", marker
->str_id
);
3805 uiout
->field_fmt ("enabled", "%c",
3806 !VEC_empty (breakpoint_p
, tracepoints
) ? 'y' : 'n');
3809 strcpy (wrap_indent
, " ");
3811 if (gdbarch_addr_bit (marker
->gdbarch
) <= 32)
3812 strcat (wrap_indent
, " ");
3814 strcat (wrap_indent
, " ");
3816 strcpy (extra_field_indent
, " ");
3818 uiout
->field_core_addr ("addr", marker
->gdbarch
, marker
->address
);
3820 sal
= find_pc_line (marker
->address
, 0);
3821 sym
= find_pc_sect_function (marker
->address
, NULL
);
3824 uiout
->text ("in ");
3825 uiout
->field_string ("func",
3826 SYMBOL_PRINT_NAME (sym
));
3827 uiout
->wrap_hint (wrap_indent
);
3828 uiout
->text (" at ");
3831 uiout
->field_skip ("func");
3833 if (sal
.symtab
!= NULL
)
3835 uiout
->field_string ("file",
3836 symtab_to_filename_for_display (sal
.symtab
));
3839 if (uiout
->is_mi_like_p ())
3841 const char *fullname
= symtab_to_fullname (sal
.symtab
);
3843 uiout
->field_string ("fullname", fullname
);
3846 uiout
->field_skip ("fullname");
3848 uiout
->field_int ("line", sal
.line
);
3852 uiout
->field_skip ("fullname");
3853 uiout
->field_skip ("line");
3857 uiout
->text (extra_field_indent
);
3858 uiout
->text (_("Data: \""));
3859 uiout
->field_string ("extra-data", marker
->extra
);
3860 uiout
->text ("\"\n");
3862 if (!VEC_empty (breakpoint_p
, tracepoints
))
3865 struct breakpoint
*b
;
3868 ui_out_emit_tuple
tuple_emitter (uiout
, "tracepoints-at");
3870 uiout
->text (extra_field_indent
);
3871 uiout
->text (_("Probed by static tracepoints: "));
3872 for (ix
= 0; VEC_iterate(breakpoint_p
, tracepoints
, ix
, b
); ix
++)
3877 uiout
->field_int ("tracepoint-id", b
->number
);
3881 if (uiout
->is_mi_like_p ())
3882 uiout
->field_int ("number-of-tracepoints",
3883 VEC_length(breakpoint_p
, tracepoints
));
3887 VEC_free (breakpoint_p
, tracepoints
);
3891 info_static_tracepoint_markers_command (char *arg
, int from_tty
)
3893 VEC(static_tracepoint_marker_p
) *markers
;
3894 struct cleanup
*old_chain
;
3895 struct static_tracepoint_marker
*marker
;
3896 struct ui_out
*uiout
= current_uiout
;
3899 /* We don't have to check target_can_use_agent and agent's capability on
3900 static tracepoint here, in order to be compatible with older GDBserver.
3901 We don't check USE_AGENT is true or not, because static tracepoints
3902 don't work without in-process agent, so we don't bother users to type
3903 `set agent on' when to use static tracepoint. */
3905 ui_out_emit_table
table_emitter (uiout
, 5, -1,
3906 "StaticTracepointMarkersTable");
3908 uiout
->table_header (7, ui_left
, "counter", "Cnt");
3910 uiout
->table_header (40, ui_left
, "marker-id", "ID");
3912 uiout
->table_header (3, ui_left
, "enabled", "Enb");
3913 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
3914 uiout
->table_header (10, ui_left
, "addr", "Address");
3916 uiout
->table_header (18, ui_left
, "addr", "Address");
3917 uiout
->table_header (40, ui_noalign
, "what", "What");
3919 uiout
->table_body ();
3921 markers
= target_static_tracepoint_markers_by_strid (NULL
);
3922 old_chain
= make_cleanup (VEC_cleanup (static_tracepoint_marker_p
), &markers
);
3925 VEC_iterate (static_tracepoint_marker_p
,
3926 markers
, i
, marker
);
3929 print_one_static_tracepoint_marker (i
+ 1, marker
);
3930 release_static_tracepoint_marker (marker
);
3933 do_cleanups (old_chain
);
3936 /* The $_sdata convenience variable is a bit special. We don't know
3937 for sure type of the value until we actually have a chance to fetch
3938 the data --- the size of the object depends on what has been
3939 collected. We solve this by making $_sdata be an internalvar that
3940 creates a new value on access. */
3942 /* Return a new value with the correct type for the sdata object of
3943 the current trace frame. Return a void value if there's no object
3946 static struct value
*
3947 sdata_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
3953 /* We need to read the whole object before we know its size. */
3954 size
= target_read_alloc (¤t_target
,
3955 TARGET_OBJECT_STATIC_TRACE_DATA
,
3962 type
= init_vector_type (builtin_type (gdbarch
)->builtin_true_char
,
3964 v
= allocate_value (type
);
3965 memcpy (value_contents_raw (v
), buf
, size
);
3970 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
3973 #if !defined(HAVE_LIBEXPAT)
3975 struct traceframe_info
*
3976 parse_traceframe_info (const char *tframe_info
)
3978 static int have_warned
;
3983 warning (_("Can not parse XML trace frame info; XML support "
3984 "was disabled at compile time"));
3990 #else /* HAVE_LIBEXPAT */
3992 #include "xml-support.h"
3994 /* Handle the start of a <memory> element. */
3997 traceframe_info_start_memory (struct gdb_xml_parser
*parser
,
3998 const struct gdb_xml_element
*element
,
3999 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
4001 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
4002 struct mem_range
*r
= VEC_safe_push (mem_range_s
, info
->memory
, NULL
);
4003 ULONGEST
*start_p
, *length_p
;
4006 = (ULONGEST
*) xml_find_attribute (attributes
, "start")->value
;
4008 = (ULONGEST
*) xml_find_attribute (attributes
, "length")->value
;
4010 r
->start
= *start_p
;
4011 r
->length
= *length_p
;
4014 /* Handle the start of a <tvar> element. */
4017 traceframe_info_start_tvar (struct gdb_xml_parser
*parser
,
4018 const struct gdb_xml_element
*element
,
4020 VEC(gdb_xml_value_s
) *attributes
)
4022 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
4023 const char *id_attrib
4024 = (const char *) xml_find_attribute (attributes
, "id")->value
;
4025 int id
= gdb_xml_parse_ulongest (parser
, id_attrib
);
4027 info
->tvars
.push_back (id
);
4030 /* Discard the constructed trace frame info (if an error occurs). */
4033 free_result (void *p
)
4035 struct traceframe_info
*result
= (struct traceframe_info
*) p
;
4037 free_traceframe_info (result
);
4040 /* The allowed elements and attributes for an XML memory map. */
4042 static const struct gdb_xml_attribute memory_attributes
[] = {
4043 { "start", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
4044 { "length", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
4045 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
4048 static const struct gdb_xml_attribute tvar_attributes
[] = {
4049 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
4050 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
4053 static const struct gdb_xml_element traceframe_info_children
[] = {
4054 { "memory", memory_attributes
, NULL
,
4055 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
4056 traceframe_info_start_memory
, NULL
},
4057 { "tvar", tvar_attributes
, NULL
,
4058 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
4059 traceframe_info_start_tvar
, NULL
},
4060 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
4063 static const struct gdb_xml_element traceframe_info_elements
[] = {
4064 { "traceframe-info", NULL
, traceframe_info_children
, GDB_XML_EF_NONE
,
4066 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
4069 /* Parse a traceframe-info XML document. */
4071 struct traceframe_info
*
4072 parse_traceframe_info (const char *tframe_info
)
4074 traceframe_info
*result
= new traceframe_info
;
4075 struct cleanup
*back_to
;
4077 back_to
= make_cleanup (free_result
, result
);
4079 if (gdb_xml_parse_quick (_("trace frame info"),
4080 "traceframe-info.dtd", traceframe_info_elements
,
4081 tframe_info
, result
) == 0)
4083 /* Parsed successfully, keep the result. */
4084 discard_cleanups (back_to
);
4089 do_cleanups (back_to
);
4093 #endif /* HAVE_LIBEXPAT */
4095 /* Returns the traceframe_info object for the current traceframe.
4096 This is where we avoid re-fetching the object from the target if we
4097 already have it cached. */
4099 struct traceframe_info
*
4100 get_traceframe_info (void)
4102 if (current_traceframe_info
== NULL
)
4103 current_traceframe_info
= target_traceframe_info ();
4105 return current_traceframe_info
;
4108 /* If the target supports the query, return in RESULT the set of
4109 collected memory in the current traceframe, found within the LEN
4110 bytes range starting at MEMADDR. Returns true if the target
4111 supports the query, otherwise returns false, and RESULT is left
4115 traceframe_available_memory (VEC(mem_range_s
) **result
,
4116 CORE_ADDR memaddr
, ULONGEST len
)
4118 struct traceframe_info
*info
= get_traceframe_info ();
4122 struct mem_range
*r
;
4127 for (i
= 0; VEC_iterate (mem_range_s
, info
->memory
, i
, r
); i
++)
4128 if (mem_ranges_overlap (r
->start
, r
->length
, memaddr
, len
))
4130 ULONGEST lo1
, hi1
, lo2
, hi2
;
4131 struct mem_range
*nr
;
4134 hi1
= memaddr
+ len
;
4137 hi2
= r
->start
+ r
->length
;
4139 nr
= VEC_safe_push (mem_range_s
, *result
, NULL
);
4141 nr
->start
= std::max (lo1
, lo2
);
4142 nr
->length
= std::min (hi1
, hi2
) - nr
->start
;
4145 normalize_mem_ranges (*result
);
4152 /* Implementation of `sdata' variable. */
4154 static const struct internalvar_funcs sdata_funcs
=
4161 /* module initialization */
4163 _initialize_tracepoint (void)
4165 struct cmd_list_element
*c
;
4167 /* Explicitly create without lookup, since that tries to create a
4168 value with a void typed value, and when we get here, gdbarch
4169 isn't initialized yet. At this point, we're quite sure there
4170 isn't another convenience variable of the same name. */
4171 create_internalvar_type_lazy ("_sdata", &sdata_funcs
, NULL
);
4173 traceframe_number
= -1;
4174 tracepoint_number
= -1;
4176 add_info ("scope", info_scope_command
,
4177 _("List the variables local to a scope"));
4179 add_cmd ("tracepoints", class_trace
,
4180 _("Tracing of program execution without stopping the program."),
4183 add_com ("tdump", class_trace
, tdump_command
,
4184 _("Print everything collected at the current tracepoint."));
4186 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
4187 Define a trace state variable.\n\
4188 Argument is a $-prefixed name, optionally followed\n\
4189 by '=' and an expression that sets the initial value\n\
4190 at the start of tracing."));
4191 set_cmd_completer (c
, expression_completer
);
4193 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
4194 Delete one or more trace state variables.\n\
4195 Arguments are the names of the variables to delete.\n\
4196 If no arguments are supplied, delete all variables."), &deletelist
);
4197 /* FIXME add a trace variable completer. */
4199 add_info ("tvariables", info_tvariables_command
, _("\
4200 Status of trace state variables and their values.\n\
4203 add_info ("static-tracepoint-markers",
4204 info_static_tracepoint_markers_command
, _("\
4205 List target static tracepoints markers.\n\
4208 add_prefix_cmd ("tfind", class_trace
, tfind_command
, _("\
4209 Select a trace frame;\n\
4210 No argument means forward by one frame; '-' means backward by one frame."),
4211 &tfindlist
, "tfind ", 1, &cmdlist
);
4213 add_cmd ("outside", class_trace
, tfind_outside_command
, _("\
4214 Select a trace frame whose PC is outside the given range (exclusive).\n\
4215 Usage: tfind outside addr1, addr2"),
4218 add_cmd ("range", class_trace
, tfind_range_command
, _("\
4219 Select a trace frame whose PC is in the given range (inclusive).\n\
4220 Usage: tfind range addr1,addr2"),
4223 add_cmd ("line", class_trace
, tfind_line_command
, _("\
4224 Select a trace frame by source line.\n\
4225 Argument can be a line number (with optional source file),\n\
4226 a function name, or '*' followed by an address.\n\
4227 Default argument is 'the next source line that was traced'."),
4230 add_cmd ("tracepoint", class_trace
, tfind_tracepoint_command
, _("\
4231 Select a trace frame by tracepoint number.\n\
4232 Default is the tracepoint for the current trace frame."),
4235 add_cmd ("pc", class_trace
, tfind_pc_command
, _("\
4236 Select a trace frame by PC.\n\
4237 Default is the current PC, or the PC of the current trace frame."),
4240 add_cmd ("end", class_trace
, tfind_end_command
, _("\
4241 De-select any trace frame and resume 'live' debugging."),
4244 add_alias_cmd ("none", "end", class_trace
, 0, &tfindlist
);
4246 add_cmd ("start", class_trace
, tfind_start_command
,
4247 _("Select the first trace frame in the trace buffer."),
4250 add_com ("tstatus", class_trace
, tstatus_command
,
4251 _("Display the status of the current trace data collection."));
4253 add_com ("tstop", class_trace
, tstop_command
, _("\
4254 Stop trace data collection.\n\
4255 Usage: tstop [ <notes> ... ]\n\
4256 Any arguments supplied are recorded with the trace as a stop reason and\n\
4257 reported by tstatus (if the target supports trace notes)."));
4259 add_com ("tstart", class_trace
, tstart_command
, _("\
4260 Start trace data collection.\n\
4261 Usage: tstart [ <notes> ... ]\n\
4262 Any arguments supplied are recorded with the trace as a note and\n\
4263 reported by tstatus (if the target supports trace notes)."));
4265 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
4266 Ends a list of commands or actions.\n\
4267 Several GDB commands allow you to enter a list of commands or actions.\n\
4268 Entering \"end\" on a line by itself is the normal way to terminate\n\
4270 Note: the \"end\" command cannot be used at the gdb prompt."));
4272 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
4273 Specify single-stepping behavior at a tracepoint.\n\
4274 Argument is number of instructions to trace in single-step mode\n\
4275 following the tracepoint. This command is normally followed by\n\
4276 one or more \"collect\" commands, to specify what to collect\n\
4277 while single-stepping.\n\n\
4278 Note: this command can only be used in a tracepoint \"actions\" list."));
4280 add_com_alias ("ws", "while-stepping", class_alias
, 0);
4281 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
4283 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
4284 Specify one or more data items to be collected at a tracepoint.\n\
4285 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4286 collect all data (variables, registers) referenced by that expression.\n\
4287 Also accepts the following special arguments:\n\
4288 $regs -- all registers.\n\
4289 $args -- all function arguments.\n\
4290 $locals -- all variables local to the block/function scope.\n\
4291 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
4292 Note: this command can only be used in a tracepoint \"actions\" list."));
4294 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
4295 Specify one or more expressions to be evaluated at a tracepoint.\n\
4296 Accepts a comma-separated list of (one or more) expressions.\n\
4297 The result of each evaluation will be discarded.\n\
4298 Note: this command can only be used in a tracepoint \"actions\" list."));
4300 add_com ("actions", class_trace
, actions_command
, _("\
4301 Specify the actions to be taken at a tracepoint.\n\
4302 Tracepoint actions may include collecting of specified data,\n\
4303 single-stepping, or enabling/disabling other tracepoints,\n\
4304 depending on target's capabilities."));
4306 default_collect
= xstrdup ("");
4307 add_setshow_string_cmd ("default-collect", class_trace
,
4308 &default_collect
, _("\
4309 Set the list of expressions to collect by default"), _("\
4310 Show the list of expressions to collect by default"), NULL
,
4312 &setlist
, &showlist
);
4314 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
4315 &disconnected_tracing
, _("\
4316 Set whether tracing continues after GDB disconnects."), _("\
4317 Show whether tracing continues after GDB disconnects."), _("\
4318 Use this to continue a tracing run even if GDB disconnects\n\
4319 or detaches from the target. You can reconnect later and look at\n\
4320 trace data collected in the meantime."),
4321 set_disconnected_tracing
,
4326 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
4327 &circular_trace_buffer
, _("\
4328 Set target's use of circular trace buffer."), _("\
4329 Show target's use of circular trace buffer."), _("\
4330 Use this to make the trace buffer into a circular buffer,\n\
4331 which will discard traceframes (oldest first) instead of filling\n\
4332 up and stopping the trace run."),
4333 set_circular_trace_buffer
,
4338 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class
,
4339 &trace_buffer_size
, _("\
4340 Set requested size of trace buffer."), _("\
4341 Show requested size of trace buffer."), _("\
4342 Use this to choose a size for the trace buffer. Some targets\n\
4343 may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
4344 disables any attempt to set the buffer size and lets the target choose."),
4345 set_trace_buffer_size
, NULL
,
4346 &setlist
, &showlist
);
4348 add_setshow_string_cmd ("trace-user", class_trace
,
4350 Set the user name to use for current and future trace runs"), _("\
4351 Show the user name to use for current and future trace runs"), NULL
,
4352 set_trace_user
, NULL
,
4353 &setlist
, &showlist
);
4355 add_setshow_string_cmd ("trace-notes", class_trace
,
4357 Set notes string to use for current and future trace runs"), _("\
4358 Show the notes string to use for current and future trace runs"), NULL
,
4359 set_trace_notes
, NULL
,
4360 &setlist
, &showlist
);
4362 add_setshow_string_cmd ("trace-stop-notes", class_trace
,
4363 &trace_stop_notes
, _("\
4364 Set notes string to use for future tstop commands"), _("\
4365 Show the notes string to use for future tstop commands"), NULL
,
4366 set_trace_stop_notes
, NULL
,
4367 &setlist
, &showlist
);