1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997-2021 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"
39 #include "observable.h"
40 #include "user-regs.h"
44 #include "filenames.h"
45 #include "gdbthread.h"
52 #include "cli/cli-utils.h"
54 #include "gdbsupport/filestuff.h"
55 #include "gdbsupport/rsp-low.h"
56 #include "tracefile.h"
59 #include "cli/cli-style.h"
64 /* Maximum length of an agent aexpression.
65 This accounts for the fact that packets are limited to 400 bytes
66 (which includes everything -- including the checksum), and assumes
67 the worst case of maximum length for each of the pieces of a
70 NOTE: expressions get mem2hex'ed otherwise this would be twice as
71 large. (400 - 31)/2 == 184 */
72 #define MAX_AGENT_EXPR_LEN 184
74 /* A hook used to notify the UI of tracepoint operations. */
76 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
77 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
82 This module defines the following debugger commands:
83 trace : set a tracepoint on a function, line, or address.
84 info trace : list all debugger-defined tracepoints.
85 delete trace : delete one or more tracepoints.
86 enable trace : enable one or more tracepoints.
87 disable trace : disable one or more tracepoints.
88 actions : specify actions to be taken at a tracepoint.
89 passcount : specify a pass count for a tracepoint.
90 tstart : start a trace experiment.
91 tstop : stop a trace experiment.
92 tstatus : query the status of a trace experiment.
93 tfind : find a trace frame in the trace buffer.
94 tdump : print everything collected at the current tracepoint.
95 save-tracepoints : write tracepoint setup into a file.
97 This module defines the following user-visible debugger variables:
98 $trace_frame : sequence number of trace frame currently being debugged.
99 $trace_line : source line of trace frame currently being debugged.
100 $trace_file : source file of trace frame currently being debugged.
101 $tracepoint : tracepoint number of trace frame currently being debugged.
105 /* ======= Important global variables: ======= */
107 /* The list of all trace state variables. We don't retain pointers to
108 any of these for any reason - API is by name or number only - so it
109 works to have a vector of objects. */
111 static std::vector
<trace_state_variable
> tvariables
;
113 /* The next integer to assign to a variable. */
115 static int next_tsv_number
= 1;
117 /* Number of last traceframe collected. */
118 static int traceframe_number
;
120 /* Tracepoint for last traceframe collected. */
121 static int tracepoint_number
;
123 /* The traceframe info of the current traceframe. NULL if we haven't
124 yet attempted to fetch it, or if the target does not support
125 fetching this object, or if we're not inspecting a traceframe
127 static traceframe_info_up current_traceframe_info
;
129 /* Tracing command lists. */
130 static struct cmd_list_element
*tfindlist
;
132 /* List of expressions to collect by default at each tracepoint hit. */
133 char *default_collect
;
135 static bool disconnected_tracing
;
137 /* This variable controls whether we ask the target for a linear or
138 circular trace buffer. */
140 static bool circular_trace_buffer
;
142 /* This variable is the requested trace buffer size, or -1 to indicate
143 that we don't care and leave it up to the target to set a size. */
145 static int trace_buffer_size
= -1;
147 /* Textual notes applying to the current and/or future trace runs. */
149 static char *trace_user
= NULL
;
151 /* Textual notes applying to the current and/or future trace runs. */
153 static char *trace_notes
= NULL
;
155 /* Textual notes applying to the stopping of a trace. */
157 static char *trace_stop_notes
= NULL
;
159 /* support routines */
161 struct collection_list
;
162 static char *mem2hex (gdb_byte
*, char *, int);
164 static counted_command_line
all_tracepoint_actions (struct breakpoint
*);
166 static struct trace_status trace_status
;
168 const char *stop_reason_names
[] = {
178 struct trace_status
*
179 current_trace_status (void)
181 return &trace_status
;
184 /* Free and clear the traceframe info cache of the current
188 clear_traceframe_info (void)
190 current_traceframe_info
= NULL
;
193 /* Set traceframe number to NUM. */
195 set_traceframe_num (int num
)
197 traceframe_number
= num
;
198 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
201 /* Set tracepoint number to NUM. */
203 set_tracepoint_num (int num
)
205 tracepoint_number
= num
;
206 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
209 /* Set externally visible debug variables for querying/printing
210 the traceframe context (line, function, file). */
213 set_traceframe_context (struct frame_info
*trace_frame
)
216 struct symbol
*traceframe_fun
;
217 symtab_and_line traceframe_sal
;
219 /* Save as globals for internal use. */
220 if (trace_frame
!= NULL
221 && get_frame_pc_if_available (trace_frame
, &trace_pc
))
223 traceframe_sal
= find_pc_line (trace_pc
, 0);
224 traceframe_fun
= find_pc_function (trace_pc
);
226 /* Save linenumber as "$trace_line", a debugger variable visible to
228 set_internalvar_integer (lookup_internalvar ("trace_line"),
229 traceframe_sal
.line
);
233 traceframe_fun
= NULL
;
234 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
237 /* Save func name as "$trace_func", a debugger variable visible to
239 if (traceframe_fun
== NULL
240 || traceframe_fun
->linkage_name () == NULL
)
241 clear_internalvar (lookup_internalvar ("trace_func"));
243 set_internalvar_string (lookup_internalvar ("trace_func"),
244 traceframe_fun
->linkage_name ());
246 /* Save file name as "$trace_file", a debugger variable visible to
248 if (traceframe_sal
.symtab
== NULL
)
249 clear_internalvar (lookup_internalvar ("trace_file"));
251 set_internalvar_string (lookup_internalvar ("trace_file"),
252 symtab_to_filename_for_display (traceframe_sal
.symtab
));
255 /* Create a new trace state variable with the given name. */
257 struct trace_state_variable
*
258 create_trace_state_variable (const char *name
)
260 tvariables
.emplace_back (name
, next_tsv_number
++);
261 return &tvariables
.back ();
264 /* Look for a trace state variable of the given name. */
266 struct trace_state_variable
*
267 find_trace_state_variable (const char *name
)
269 for (trace_state_variable
&tsv
: tvariables
)
270 if (tsv
.name
== name
)
276 /* Look for a trace state variable of the given number. Return NULL if
279 struct trace_state_variable
*
280 find_trace_state_variable_by_number (int number
)
282 for (trace_state_variable
&tsv
: tvariables
)
283 if (tsv
.number
== number
)
290 delete_trace_state_variable (const char *name
)
292 for (auto it
= tvariables
.begin (); it
!= tvariables
.end (); it
++)
293 if (it
->name
== name
)
295 gdb::observers::tsv_deleted
.notify (&*it
);
296 tvariables
.erase (it
);
300 warning (_("No trace variable named \"$%s\", not deleting"), name
);
303 /* Throws an error if NAME is not valid syntax for a trace state
307 validate_trace_state_variable_name (const char *name
)
312 error (_("Must supply a non-empty variable name"));
314 /* All digits in the name is reserved for value history
316 for (p
= name
; isdigit (*p
); p
++)
319 error (_("$%s is not a valid trace state variable name"), name
);
321 for (p
= name
; isalnum (*p
) || *p
== '_'; p
++)
324 error (_("$%s is not a valid trace state variable name"), name
);
327 /* The 'tvariable' command collects a name and optional expression to
328 evaluate into an initial value. */
331 trace_variable_command (const char *args
, int from_tty
)
334 struct trace_state_variable
*tsv
;
335 const char *name_start
, *p
;
338 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
340 /* Only allow two syntaxes; "$name" and "$name=value". */
341 p
= skip_spaces (args
);
344 error (_("Name of trace variable should start with '$'"));
347 while (isalnum (*p
) || *p
== '_')
349 std::string
name (name_start
, p
- name_start
);
352 if (*p
!= '=' && *p
!= '\0')
353 error (_("Syntax must be $NAME [ = EXPR ]"));
355 validate_trace_state_variable_name (name
.c_str ());
358 initval
= value_as_long (parse_and_eval (++p
));
360 /* If the variable already exists, just change its initial value. */
361 tsv
= find_trace_state_variable (name
.c_str ());
364 if (tsv
->initial_value
!= initval
)
366 tsv
->initial_value
= initval
;
367 gdb::observers::tsv_modified
.notify (tsv
);
369 printf_filtered (_("Trace state variable $%s "
370 "now has initial value %s.\n"),
371 tsv
->name
.c_str (), plongest (tsv
->initial_value
));
375 /* Create a new variable. */
376 tsv
= create_trace_state_variable (name
.c_str ());
377 tsv
->initial_value
= initval
;
379 gdb::observers::tsv_created
.notify (tsv
);
381 printf_filtered (_("Trace state variable $%s "
382 "created, with initial value %s.\n"),
383 tsv
->name
.c_str (), plongest (tsv
->initial_value
));
387 delete_trace_variable_command (const char *args
, int from_tty
)
391 if (query (_("Delete all trace state variables? ")))
394 gdb::observers::tsv_deleted
.notify (NULL
);
398 gdb_argv
argv (args
);
400 for (char *arg
: argv
)
403 delete_trace_state_variable (arg
+ 1);
405 warning (_("Name \"%s\" not prefixed with '$', ignoring"), arg
);
412 tvariables_info_1 (void)
414 struct ui_out
*uiout
= current_uiout
;
416 /* Try to acquire values from the target. */
417 for (trace_state_variable
&tsv
: tvariables
)
419 = target_get_trace_state_variable_value (tsv
.number
, &tsv
.value
);
422 ui_out_emit_table
table_emitter (uiout
, 3, tvariables
.size (),
424 uiout
->table_header (15, ui_left
, "name", "Name");
425 uiout
->table_header (11, ui_left
, "initial", "Initial");
426 uiout
->table_header (11, ui_left
, "current", "Current");
428 uiout
->table_body ();
430 for (const trace_state_variable
&tsv
: tvariables
)
434 ui_out_emit_tuple
tuple_emitter (uiout
, "variable");
436 uiout
->field_string ("name", std::string ("$") + tsv
.name
);
437 uiout
->field_string ("initial", plongest (tsv
.initial_value
));
441 c
= plongest (tsv
.value
);
442 else if (uiout
->is_mi_like_p ())
443 /* For MI, we prefer not to use magic string constants, but rather
444 omit the field completely. The difference between unknown and
445 undefined does not seem important enough to represent. */
447 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
449 /* The value is/was defined, but we don't have it. */
451 style
= metadata_style
.style ();
455 /* It is not meaningful to ask about the value. */
457 style
= metadata_style
.style ();
460 uiout
->field_string ("current", c
, style
);
465 if (tvariables
.empty ())
466 uiout
->text (_("No trace state variables.\n"));
469 /* List all the trace state variables. */
472 info_tvariables_command (const char *args
, int from_tty
)
474 tvariables_info_1 ();
477 /* Stash definitions of tsvs into the given file. */
480 save_trace_state_variables (struct ui_file
*fp
)
482 for (const trace_state_variable
&tsv
: tvariables
)
484 fprintf_unfiltered (fp
, "tvariable $%s", tsv
.name
.c_str ());
485 if (tsv
.initial_value
)
486 fprintf_unfiltered (fp
, " = %s", plongest (tsv
.initial_value
));
487 fprintf_unfiltered (fp
, "\n");
491 /* ACTIONS functions: */
493 /* The three functions:
494 collect_pseudocommand,
495 while_stepping_pseudocommand, and
496 end_actions_pseudocommand
497 are placeholders for "commands" that are actually ONLY to be used
498 within a tracepoint action list. If the actual function is ever called,
499 it means that somebody issued the "command" at the top level,
500 which is always an error. */
503 end_actions_pseudocommand (const char *args
, int from_tty
)
505 error (_("This command cannot be used at the top level."));
509 while_stepping_pseudocommand (const char *args
, int from_tty
)
511 error (_("This command can only be used in a tracepoint actions list."));
515 collect_pseudocommand (const char *args
, int from_tty
)
517 error (_("This command can only be used in a tracepoint actions list."));
521 teval_pseudocommand (const char *args
, int from_tty
)
523 error (_("This command can only be used in a tracepoint actions list."));
526 /* Parse any collection options, such as /s for strings. */
529 decode_agent_options (const char *exp
, int *trace_string
)
531 struct value_print_options opts
;
538 /* Call this to borrow the print elements default for collection
540 get_user_print_options (&opts
);
545 if (target_supports_string_tracing ())
547 /* Allow an optional decimal number giving an explicit maximum
548 string length, defaulting it to the "print elements" value;
549 so "collect/s80 mystr" gets at most 80 bytes of string. */
550 *trace_string
= opts
.print_max
;
552 if (*exp
>= '0' && *exp
<= '9')
553 *trace_string
= atoi (exp
);
554 while (*exp
>= '0' && *exp
<= '9')
558 error (_("Target does not support \"/s\" option for string tracing."));
561 error (_("Undefined collection format \"%c\"."), *exp
);
563 exp
= skip_spaces (exp
);
568 /* Enter a list of actions for a tracepoint. */
570 actions_command (const char *args
, int from_tty
)
572 struct tracepoint
*t
;
574 t
= get_tracepoint_by_number (&args
, NULL
);
578 string_printf ("Enter actions for tracepoint %d, one per line.",
581 counted_command_line l
= read_command_lines (tmpbuf
.c_str (),
583 [=] (const char *line
)
585 validate_actionline (line
, t
);
587 breakpoint_set_commands (t
, std::move (l
));
589 /* else just return */
592 /* Report the results of checking the agent expression, as errors or
596 report_agent_reqs_errors (struct agent_expr
*aexpr
)
598 /* All of the "flaws" are serious bytecode generation issues that
599 should never occur. */
600 if (aexpr
->flaw
!= agent_flaw_none
)
601 internal_error (__FILE__
, __LINE__
, _("expression is malformed"));
603 /* If analysis shows a stack underflow, GDB must have done something
604 badly wrong in its bytecode generation. */
605 if (aexpr
->min_height
< 0)
606 internal_error (__FILE__
, __LINE__
,
607 _("expression has min height < 0"));
609 /* Issue this error if the stack is predicted to get too deep. The
610 limit is rather arbitrary; a better scheme might be for the
611 target to report how much stack it will have available. The
612 depth roughly corresponds to parenthesization, so a limit of 20
613 amounts to 20 levels of expression nesting, which is actually
614 a pretty big hairy expression. */
615 if (aexpr
->max_height
> 20)
616 error (_("Expression is too complicated."));
619 /* Call ax_reqs on AEXPR and raise an error if something is wrong. */
622 finalize_tracepoint_aexpr (struct agent_expr
*aexpr
)
626 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
627 error (_("Expression is too complicated."));
629 report_agent_reqs_errors (aexpr
);
632 /* worker function */
634 validate_actionline (const char *line
, struct breakpoint
*b
)
636 struct cmd_list_element
*c
;
639 struct bp_location
*loc
;
640 struct tracepoint
*t
= (struct tracepoint
*) b
;
642 /* If EOF is typed, *line is NULL. */
646 p
= skip_spaces (line
);
648 /* Symbol lookup etc. */
649 if (*p
== '\0') /* empty line: just prompt for another line. */
652 if (*p
== '#') /* comment line */
655 c
= lookup_cmd (&p
, cmdlist
, "", NULL
, -1, 1);
657 error (_("`%s' is not a tracepoint action, or is ambiguous."), p
);
659 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
661 int trace_string
= 0;
664 p
= decode_agent_options (p
, &trace_string
);
667 { /* Repeat over a comma-separated list. */
668 QUIT
; /* Allow user to bail out with ^C. */
671 if (*p
== '$') /* Look for special pseudo-symbols. */
673 if (0 == strncasecmp ("reg", p
+ 1, 3)
674 || 0 == strncasecmp ("arg", p
+ 1, 3)
675 || 0 == strncasecmp ("loc", p
+ 1, 3)
676 || 0 == strncasecmp ("_ret", p
+ 1, 4)
677 || 0 == strncasecmp ("_sdata", p
+ 1, 6))
682 /* else fall thru, treat p as an expression and parse it! */
685 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
688 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
689 block_for_pc (loc
->address
), 1);
691 if (exp
->first_opcode () == OP_VAR_VALUE
)
694 if (exp
->op
!= nullptr)
696 expr::var_value_operation
*vvop
697 = (dynamic_cast<expr::var_value_operation
*>
699 sym
= vvop
->get_symbol ();
702 sym
= exp
->elts
[2].symbol
;
704 if (SYMBOL_CLASS (sym
) == LOC_CONST
)
706 error (_("constant `%s' (value %s) "
707 "will not be collected."),
709 plongest (SYMBOL_VALUE (sym
)));
711 else if (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
)
713 error (_("`%s' is optimized away "
714 "and cannot be collected."),
719 /* We have something to collect, make sure that the expr to
720 bytecode translator can handle it and that it's not too
722 agent_expr_up aexpr
= gen_trace_for_expr (loc
->address
,
726 finalize_tracepoint_aexpr (aexpr
.get ());
729 while (p
&& *p
++ == ',');
732 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
735 { /* Repeat over a comma-separated list. */
736 QUIT
; /* Allow user to bail out with ^C. */
740 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
744 /* Only expressions are allowed for this action. */
745 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
746 block_for_pc (loc
->address
), 1);
748 /* We have something to evaluate, make sure that the expr to
749 bytecode translator can handle it and that it's not too
751 agent_expr_up aexpr
= gen_eval_for_expr (loc
->address
, exp
.get ());
753 finalize_tracepoint_aexpr (aexpr
.get ());
756 while (p
&& *p
++ == ',');
759 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
764 t
->step_count
= strtol (p
, &endp
, 0);
765 if (endp
== p
|| t
->step_count
== 0)
766 error (_("while-stepping step count `%s' is malformed."), line
);
770 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
774 error (_("`%s' is not a supported tracepoint action."), line
);
778 memrange_absolute
= -1
781 /* MEMRANGE functions: */
783 /* Compare memranges for std::sort. */
786 memrange_comp (const memrange
&a
, const memrange
&b
)
788 if (a
.type
== b
.type
)
790 if (a
.type
== memrange_absolute
)
791 return (bfd_vma
) a
.start
< (bfd_vma
) b
.start
;
793 return a
.start
< b
.start
;
796 return a
.type
< b
.type
;
799 /* Sort the memrange list using std::sort, and merge adjacent memranges. */
802 memrange_sortmerge (std::vector
<memrange
> &memranges
)
804 if (!memranges
.empty ())
808 std::sort (memranges
.begin (), memranges
.end (), memrange_comp
);
810 for (a
= 0, b
= 1; b
< memranges
.size (); b
++)
812 /* If memrange b overlaps or is adjacent to memrange a,
814 if (memranges
[a
].type
== memranges
[b
].type
815 && memranges
[b
].start
<= memranges
[a
].end
)
817 if (memranges
[b
].end
> memranges
[a
].end
)
818 memranges
[a
].end
= memranges
[b
].end
;
819 continue; /* next b, same a */
823 memranges
[a
] = memranges
[b
];
825 memranges
.resize (a
+ 1);
829 /* Add remote register number REGNO to the collection list mask. */
832 collection_list::add_remote_register (unsigned int regno
)
835 printf_filtered ("collect register %d\n", regno
);
837 m_regs_mask
.at (regno
/ 8) |= 1 << (regno
% 8);
840 /* Add all the registers from the mask in AEXPR to the mask in the
841 collection list. Registers in the AEXPR mask are already remote
845 collection_list::add_ax_registers (struct agent_expr
*aexpr
)
847 if (aexpr
->reg_mask_len
> 0)
849 for (int ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
851 QUIT
; /* Allow user to bail out with ^C. */
852 if (aexpr
->reg_mask
[ndx1
] != 0)
854 /* Assume chars have 8 bits. */
855 for (int ndx2
= 0; ndx2
< 8; ndx2
++)
856 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
857 /* It's used -- record it. */
858 add_remote_register (ndx1
* 8 + ndx2
);
864 /* If REGNO is raw, add its corresponding remote register number to
865 the mask. If REGNO is a pseudo-register, figure out the necessary
866 registers using a temporary agent expression, and add it to the
867 list if it needs more than just a mask. */
870 collection_list::add_local_register (struct gdbarch
*gdbarch
,
874 if (regno
< gdbarch_num_regs (gdbarch
))
876 int remote_regno
= gdbarch_remote_register_number (gdbarch
, regno
);
878 if (remote_regno
< 0)
879 error (_("Can't collect register %d"), regno
);
881 add_remote_register (remote_regno
);
885 agent_expr_up
aexpr (new agent_expr (gdbarch
, scope
));
887 ax_reg_mask (aexpr
.get (), regno
);
889 finalize_tracepoint_aexpr (aexpr
.get ());
891 add_ax_registers (aexpr
.get ());
893 /* Usually ax_reg_mask for a pseudo-regiser only sets the
894 corresponding raw registers in the ax mask, but if this isn't
895 the case add the expression that is generated to the
898 add_aexpr (std::move (aexpr
));
902 /* Add a memrange to a collection list. */
905 collection_list::add_memrange (struct gdbarch
*gdbarch
,
906 int type
, bfd_signed_vma base
,
907 unsigned long len
, CORE_ADDR scope
)
910 printf_filtered ("(%d,%s,%ld)\n", type
, paddress (gdbarch
, base
), len
);
912 /* type: memrange_absolute == memory, other n == basereg */
913 /* base: addr if memory, offset if reg relative. */
914 /* len: we actually save end (base + len) for convenience */
915 m_memranges
.emplace_back (type
, base
, base
+ len
);
917 if (type
!= memrange_absolute
) /* Better collect the base register! */
918 add_local_register (gdbarch
, type
, scope
);
921 /* Add a symbol to a collection list. */
924 collection_list::collect_symbol (struct symbol
*sym
,
925 struct gdbarch
*gdbarch
,
926 long frame_regno
, long frame_offset
,
932 bfd_signed_vma offset
;
933 int treat_as_expr
= 0;
935 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
936 switch (SYMBOL_CLASS (sym
))
939 printf_filtered ("%s: don't know symbol class %d\n",
940 sym
->print_name (), SYMBOL_CLASS (sym
));
943 printf_filtered ("constant %s (value %s) will not be collected.\n",
944 sym
->print_name (), plongest (SYMBOL_VALUE (sym
)));
947 offset
= SYMBOL_VALUE_ADDRESS (sym
);
950 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
951 sym
->print_name (), len
,
952 paddress (gdbarch
, offset
));
954 /* A struct may be a C++ class with static fields, go to general
955 expression handling. */
956 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_STRUCT
)
959 add_memrange (gdbarch
, memrange_absolute
, offset
, len
, scope
);
962 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
964 printf_filtered ("LOC_REG[parm] %s: ", sym
->print_name ());
965 add_local_register (gdbarch
, reg
, scope
);
966 /* Check for doubles stored in two registers. */
967 /* FIXME: how about larger types stored in 3 or more regs? */
968 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_FLT
&&
969 len
> register_size (gdbarch
, reg
))
970 add_local_register (gdbarch
, reg
+ 1, scope
);
973 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
974 printf_filtered (" (will not collect %s)\n", sym
->print_name ());
978 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
981 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
982 " from frame ptr reg %d\n", sym
->print_name (), len
,
983 paddress (gdbarch
, offset
), reg
);
985 add_memrange (gdbarch
, reg
, offset
, len
, scope
);
987 case LOC_REGPARM_ADDR
:
988 reg
= SYMBOL_VALUE (sym
);
992 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset %s"
993 " from reg %d\n", sym
->print_name (), len
,
994 paddress (gdbarch
, offset
), reg
);
996 add_memrange (gdbarch
, reg
, offset
, len
, scope
);
1000 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1003 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
1004 " from frame ptr reg %d\n", sym
->print_name (), len
,
1005 paddress (gdbarch
, offset
), reg
);
1007 add_memrange (gdbarch
, reg
, offset
, len
, scope
);
1010 case LOC_UNRESOLVED
:
1014 case LOC_OPTIMIZED_OUT
:
1015 printf_filtered ("%s has been optimized out of existence.\n",
1016 sym
->print_name ());
1024 /* Expressions are the most general case. */
1027 agent_expr_up aexpr
= gen_trace_for_var (scope
, gdbarch
,
1030 /* It can happen that the symbol is recorded as a computed
1031 location, but it's been optimized away and doesn't actually
1032 have a location expression. */
1035 printf_filtered ("%s has been optimized out of existence.\n",
1036 sym
->print_name ());
1040 finalize_tracepoint_aexpr (aexpr
.get ());
1042 /* Take care of the registers. */
1043 add_ax_registers (aexpr
.get ());
1045 add_aexpr (std::move (aexpr
));
1049 /* Data to be passed around in the calls to the locals and args
1052 struct add_local_symbols_data
1054 struct collection_list
*collect
;
1055 struct gdbarch
*gdbarch
;
1063 /* The callback for the locals and args iterators. */
1066 do_collect_symbol (const char *print_name
,
1070 struct add_local_symbols_data
*p
= (struct add_local_symbols_data
*) cb_data
;
1072 p
->collect
->collect_symbol (sym
, p
->gdbarch
, p
->frame_regno
,
1073 p
->frame_offset
, p
->pc
, p
->trace_string
);
1076 p
->collect
->add_wholly_collected (print_name
);
1080 collection_list::add_wholly_collected (const char *print_name
)
1082 m_wholly_collected
.push_back (print_name
);
1085 /* Add all locals (or args) symbols to collection list. */
1088 collection_list::add_local_symbols (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1089 long frame_regno
, long frame_offset
, int type
,
1092 const struct block
*block
;
1093 struct add_local_symbols_data cb_data
;
1095 cb_data
.collect
= this;
1096 cb_data
.gdbarch
= gdbarch
;
1098 cb_data
.frame_regno
= frame_regno
;
1099 cb_data
.frame_offset
= frame_offset
;
1101 cb_data
.trace_string
= trace_string
;
1105 block
= block_for_pc (pc
);
1108 warning (_("Can't collect locals; "
1109 "no symbol table info available.\n"));
1113 iterate_over_block_local_vars (block
, do_collect_symbol
, &cb_data
);
1114 if (cb_data
.count
== 0)
1115 warning (_("No locals found in scope."));
1119 pc
= get_pc_function_start (pc
);
1120 block
= block_for_pc (pc
);
1123 warning (_("Can't collect args; no symbol table info available."));
1127 iterate_over_block_arg_vars (block
, do_collect_symbol
, &cb_data
);
1128 if (cb_data
.count
== 0)
1129 warning (_("No args found in scope."));
1134 collection_list::add_static_trace_data ()
1137 printf_filtered ("collect static trace data\n");
1138 m_strace_data
= true;
1141 collection_list::collection_list ()
1142 : m_strace_data (false)
1144 int max_remote_regno
= 0;
1145 for (int i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
1147 int remote_regno
= (gdbarch_remote_register_number
1148 (target_gdbarch (), i
));
1150 if (remote_regno
>= 0 && remote_regno
> max_remote_regno
)
1151 max_remote_regno
= remote_regno
;
1154 m_regs_mask
.resize ((max_remote_regno
/ 8) + 1);
1156 m_memranges
.reserve (128);
1157 m_aexprs
.reserve (128);
1160 /* Reduce a collection list to string form (for gdb protocol). */
1162 std::vector
<std::string
>
1163 collection_list::stringify ()
1165 gdb::char_vector
temp_buf (2048);
1170 std::vector
<std::string
> str_list
;
1175 printf_filtered ("\nCollecting static trace data\n");
1176 end
= temp_buf
.data ();
1178 str_list
.emplace_back (temp_buf
.data (), end
- temp_buf
.data ());
1181 for (i
= m_regs_mask
.size () - 1; i
> 0; i
--)
1182 if (m_regs_mask
[i
] != 0) /* Skip leading zeroes in regs_mask. */
1184 if (m_regs_mask
[i
] != 0) /* Prepare to send regs_mask to the stub. */
1187 printf_filtered ("\nCollecting registers (mask): 0x");
1189 /* One char for 'R', one for the null terminator and two per
1191 std::size_t new_size
= (i
+ 1) * 2 + 2;
1192 if (new_size
> temp_buf
.size ())
1193 temp_buf
.resize (new_size
);
1195 end
= temp_buf
.data ();
1199 QUIT
; /* Allow user to bail out with ^C. */
1201 printf_filtered ("%02X", m_regs_mask
[i
]);
1203 end
= pack_hex_byte (end
, m_regs_mask
[i
]);
1207 str_list
.emplace_back (temp_buf
.data ());
1210 printf_filtered ("\n");
1211 if (!m_memranges
.empty () && info_verbose
)
1212 printf_filtered ("Collecting memranges: \n");
1213 for (i
= 0, count
= 0, end
= temp_buf
.data ();
1214 i
< m_memranges
.size (); i
++)
1216 QUIT
; /* Allow user to bail out with ^C. */
1219 printf_filtered ("(%d, %s, %ld)\n",
1220 m_memranges
[i
].type
,
1221 paddress (target_gdbarch (),
1222 m_memranges
[i
].start
),
1223 (long) (m_memranges
[i
].end
1224 - m_memranges
[i
].start
));
1226 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1228 str_list
.emplace_back (temp_buf
.data (), count
);
1230 end
= temp_buf
.data ();
1234 bfd_signed_vma length
1235 = m_memranges
[i
].end
- m_memranges
[i
].start
;
1237 /* The "%X" conversion specifier expects an unsigned argument,
1238 so passing -1 (memrange_absolute) to it directly gives you
1239 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1241 if (m_memranges
[i
].type
== memrange_absolute
)
1242 sprintf (end
, "M-1,%s,%lX", phex_nz (m_memranges
[i
].start
, 0),
1245 sprintf (end
, "M%X,%s,%lX", m_memranges
[i
].type
,
1246 phex_nz (m_memranges
[i
].start
, 0), (long) length
);
1249 count
+= strlen (end
);
1250 end
= temp_buf
.data () + count
;
1253 for (i
= 0; i
< m_aexprs
.size (); i
++)
1255 QUIT
; /* Allow user to bail out with ^C. */
1256 if ((count
+ 10 + 2 * m_aexprs
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1258 str_list
.emplace_back (temp_buf
.data (), count
);
1260 end
= temp_buf
.data ();
1262 sprintf (end
, "X%08X,", m_aexprs
[i
]->len
);
1263 end
+= 10; /* 'X' + 8 hex digits + ',' */
1266 end
= mem2hex (m_aexprs
[i
]->buf
, end
, m_aexprs
[i
]->len
);
1267 count
+= 2 * m_aexprs
[i
]->len
;
1272 str_list
.emplace_back (temp_buf
.data (), count
);
1274 end
= temp_buf
.data ();
1280 /* Add the expression STR to M_COMPUTED. */
1283 collection_list::append_exp (std::string
&&str
)
1285 m_computed
.push_back (std::move (str
));
1289 collection_list::finish ()
1291 memrange_sortmerge (m_memranges
);
1295 encode_actions_1 (struct command_line
*action
,
1296 struct bp_location
*tloc
,
1298 LONGEST frame_offset
,
1299 struct collection_list
*collect
,
1300 struct collection_list
*stepping_list
)
1302 const char *action_exp
;
1304 struct value
*tempval
;
1305 struct cmd_list_element
*cmd
;
1307 for (; action
; action
= action
->next
)
1309 QUIT
; /* Allow user to bail out with ^C. */
1310 action_exp
= action
->line
;
1311 action_exp
= skip_spaces (action_exp
);
1313 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", NULL
, -1, 1);
1315 error (_("Bad action list item: %s"), action_exp
);
1317 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1319 int trace_string
= 0;
1321 if (*action_exp
== '/')
1322 action_exp
= decode_agent_options (action_exp
, &trace_string
);
1325 { /* Repeat over a comma-separated list. */
1326 QUIT
; /* Allow user to bail out with ^C. */
1327 action_exp
= skip_spaces (action_exp
);
1329 if (0 == strncasecmp ("$reg", action_exp
, 4))
1331 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ());
1334 int remote_regno
= (gdbarch_remote_register_number
1335 (target_gdbarch (), i
));
1337 /* Ignore arch regnos without a corresponding
1338 remote regno. This can happen for regnos not
1340 if (remote_regno
>= 0)
1341 collect
->add_remote_register (remote_regno
);
1343 action_exp
= strchr (action_exp
, ','); /* more? */
1345 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1347 collect
->add_local_symbols (target_gdbarch (),
1353 action_exp
= strchr (action_exp
, ','); /* more? */
1355 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1357 collect
->add_local_symbols (target_gdbarch (),
1363 action_exp
= strchr (action_exp
, ','); /* more? */
1365 else if (0 == strncasecmp ("$_ret", action_exp
, 5))
1368 = gen_trace_for_return_address (tloc
->address
,
1372 finalize_tracepoint_aexpr (aexpr
.get ());
1374 /* take care of the registers */
1375 collect
->add_ax_registers (aexpr
.get ());
1377 collect
->add_aexpr (std::move (aexpr
));
1378 action_exp
= strchr (action_exp
, ','); /* more? */
1380 else if (0 == strncasecmp ("$_sdata", action_exp
, 7))
1382 collect
->add_static_trace_data ();
1383 action_exp
= strchr (action_exp
, ','); /* more? */
1389 const char *exp_start
= action_exp
;
1390 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1391 block_for_pc (tloc
->address
),
1394 switch (exp
->first_opcode ())
1399 if (exp
->op
!= nullptr)
1401 expr::register_operation
*regop
1402 = (dynamic_cast<expr::register_operation
*>
1404 name
= regop
->get_name ();
1407 name
= &exp
->elts
[2].string
;
1409 i
= user_reg_map_name_to_regnum (target_gdbarch (),
1410 name
, strlen (name
));
1412 internal_error (__FILE__
, __LINE__
,
1413 _("Register $%s not available"),
1416 printf_filtered ("OP_REGISTER: ");
1417 collect
->add_local_register (target_gdbarch (),
1424 /* Safe because we know it's a simple expression. */
1425 tempval
= evaluate_expression (exp
.get ());
1426 addr
= value_address (tempval
);
1428 if (exp
->op
!= nullptr)
1430 expr::unop_memval_operation
*memop
1431 = (dynamic_cast<expr::unop_memval_operation
*>
1433 type
= memop
->get_type ();
1436 type
= exp
->elts
[1].type
;
1437 /* Initialize the TYPE_LENGTH if it is a typedef. */
1438 check_typedef (type
);
1439 collect
->add_memrange (target_gdbarch (),
1440 memrange_absolute
, addr
,
1443 collect
->append_exp (std::string (exp_start
,
1452 if (exp
->op
!= nullptr)
1454 expr::var_value_operation
*vvo
1455 = (dynamic_cast<expr::var_value_operation
*>
1457 sym
= vvo
->get_symbol ();
1460 sym
= exp
->elts
[2].symbol
;
1461 const char *name
= sym
->natural_name ();
1463 collect
->collect_symbol (sym
,
1469 collect
->add_wholly_collected (name
);
1473 default: /* Full-fledged expression. */
1474 agent_expr_up aexpr
= gen_trace_for_expr (tloc
->address
,
1478 finalize_tracepoint_aexpr (aexpr
.get ());
1480 /* Take care of the registers. */
1481 collect
->add_ax_registers (aexpr
.get ());
1483 collect
->add_aexpr (std::move (aexpr
));
1484 collect
->append_exp (std::string (exp_start
,
1490 while (action_exp
&& *action_exp
++ == ',');
1492 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1495 { /* Repeat over a comma-separated list. */
1496 QUIT
; /* Allow user to bail out with ^C. */
1497 action_exp
= skip_spaces (action_exp
);
1500 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1501 block_for_pc (tloc
->address
),
1504 agent_expr_up aexpr
= gen_eval_for_expr (tloc
->address
,
1507 finalize_tracepoint_aexpr (aexpr
.get ());
1509 /* Even though we're not officially collecting, add
1510 to the collect list anyway. */
1511 collect
->add_aexpr (std::move (aexpr
));
1514 while (action_exp
&& *action_exp
++ == ',');
1516 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1518 /* We check against nested while-stepping when setting
1519 breakpoint action, so no way to run into nested
1521 gdb_assert (stepping_list
);
1523 encode_actions_1 (action
->body_list_0
.get (), tloc
, frame_reg
,
1524 frame_offset
, stepping_list
, NULL
);
1527 error (_("Invalid tracepoint command '%s'"), action
->line
);
1531 /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST
1532 and STEPPING_LIST. */
1535 encode_actions (struct bp_location
*tloc
,
1536 struct collection_list
*tracepoint_list
,
1537 struct collection_list
*stepping_list
)
1540 LONGEST frame_offset
;
1542 gdbarch_virtual_frame_pointer (tloc
->gdbarch
,
1543 tloc
->address
, &frame_reg
, &frame_offset
);
1545 counted_command_line actions
= all_tracepoint_actions (tloc
->owner
);
1546 encode_actions_1 (actions
.get (), tloc
, frame_reg
, frame_offset
,
1547 tracepoint_list
, stepping_list
);
1548 encode_actions_1 (breakpoint_commands (tloc
->owner
), tloc
,
1549 frame_reg
, frame_offset
, tracepoint_list
, stepping_list
);
1551 tracepoint_list
->finish ();
1552 stepping_list
->finish ();
1555 /* Render all actions into gdb protocol. */
1558 encode_actions_rsp (struct bp_location
*tloc
,
1559 std::vector
<std::string
> *tdp_actions
,
1560 std::vector
<std::string
> *stepping_actions
)
1562 struct collection_list tracepoint_list
, stepping_list
;
1564 encode_actions (tloc
, &tracepoint_list
, &stepping_list
);
1566 *tdp_actions
= tracepoint_list
.stringify ();
1567 *stepping_actions
= stepping_list
.stringify ();
1571 collection_list::add_aexpr (agent_expr_up aexpr
)
1573 m_aexprs
.push_back (std::move (aexpr
));
1577 process_tracepoint_on_disconnect (void)
1579 int has_pending_p
= 0;
1581 /* Check whether we still have pending tracepoint. If we have, warn the
1582 user that pending tracepoint will no longer work. */
1583 for (breakpoint
*b
: all_tracepoints ())
1592 struct bp_location
*loc1
;
1594 for (loc1
= b
->loc
; loc1
; loc1
= loc1
->next
)
1596 if (loc1
->shlib_disabled
)
1609 warning (_("Pending tracepoints will not be resolved while"
1610 " GDB is disconnected\n"));
1613 /* Reset local state of tracing. */
1616 trace_reset_local_state (void)
1618 set_traceframe_num (-1);
1619 set_tracepoint_num (-1);
1620 set_traceframe_context (NULL
);
1621 clear_traceframe_info ();
1625 start_tracing (const char *notes
)
1627 int any_enabled
= 0, num_to_download
= 0;
1630 std::vector
<breakpoint
*> tp_vec
= all_tracepoints ();
1632 /* No point in tracing without any tracepoints... */
1633 if (tp_vec
.empty ())
1634 error (_("No tracepoints defined, not starting trace"));
1636 for (breakpoint
*b
: tp_vec
)
1638 if (b
->enable_state
== bp_enabled
)
1641 if ((b
->type
== bp_fast_tracepoint
1642 ? may_insert_fast_tracepoints
1643 : may_insert_tracepoints
))
1646 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1647 (b
->type
== bp_fast_tracepoint
? "fast " : ""), b
->number
);
1652 if (target_supports_enable_disable_tracepoint ())
1653 warning (_("No tracepoints enabled"));
1656 /* No point in tracing with only disabled tracepoints that
1657 cannot be re-enabled. */
1658 error (_("No tracepoints enabled, not starting trace"));
1662 if (num_to_download
<= 0)
1663 error (_("No tracepoints that may be downloaded, not starting trace"));
1665 target_trace_init ();
1667 for (breakpoint
*b
: tp_vec
)
1669 struct tracepoint
*t
= (struct tracepoint
*) b
;
1670 struct bp_location
*loc
;
1671 int bp_location_downloaded
= 0;
1673 /* Clear `inserted' flag. */
1674 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1677 if ((b
->type
== bp_fast_tracepoint
1678 ? !may_insert_fast_tracepoints
1679 : !may_insert_tracepoints
))
1682 t
->number_on_target
= 0;
1684 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1686 /* Since tracepoint locations are never duplicated, `inserted'
1687 flag should be zero. */
1688 gdb_assert (!loc
->inserted
);
1690 target_download_tracepoint (loc
);
1693 bp_location_downloaded
= 1;
1696 t
->number_on_target
= b
->number
;
1698 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1699 if (loc
->probe
.prob
!= NULL
)
1700 loc
->probe
.prob
->set_semaphore (loc
->probe
.objfile
,
1703 if (bp_location_downloaded
)
1704 gdb::observers::breakpoint_modified
.notify (b
);
1707 /* Send down all the trace state variables too. */
1708 for (const trace_state_variable
&tsv
: tvariables
)
1709 target_download_trace_state_variable (tsv
);
1711 /* Tell target to treat text-like sections as transparent. */
1712 target_trace_set_readonly_regions ();
1713 /* Set some mode flags. */
1714 target_set_disconnected_tracing (disconnected_tracing
);
1715 target_set_circular_trace_buffer (circular_trace_buffer
);
1716 target_set_trace_buffer_size (trace_buffer_size
);
1719 notes
= trace_notes
;
1720 ret
= target_set_trace_notes (trace_user
, notes
, NULL
);
1722 if (!ret
&& (trace_user
|| notes
))
1723 warning (_("Target does not support trace user/notes, info ignored"));
1725 /* Now insert traps and begin collecting data. */
1726 target_trace_start ();
1728 /* Reset our local state. */
1729 trace_reset_local_state ();
1730 current_trace_status()->running
= 1;
1733 /* The tstart command requests the target to start a new trace run.
1734 The command passes any arguments it has to the target verbatim, as
1735 an optional "trace note". This is useful as for instance a warning
1736 to other users if the trace runs disconnected, and you don't want
1737 anybody else messing with the target. */
1740 tstart_command (const char *args
, int from_tty
)
1742 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1744 if (current_trace_status ()->running
)
1747 && !query (_("A trace is running already. Start a new run? ")))
1748 error (_("New trace run not started."));
1751 start_tracing (args
);
1754 /* The tstop command stops the tracing run. The command passes any
1755 supplied arguments to the target verbatim as a "stop note"; if the
1756 target supports trace notes, then it will be reported back as part
1757 of the trace run's status. */
1760 tstop_command (const char *args
, int from_tty
)
1762 if (!current_trace_status ()->running
)
1763 error (_("Trace is not running."));
1765 stop_tracing (args
);
1769 stop_tracing (const char *note
)
1773 target_trace_stop ();
1775 for (breakpoint
*t
: all_tracepoints ())
1777 struct bp_location
*loc
;
1779 if ((t
->type
== bp_fast_tracepoint
1780 ? !may_insert_fast_tracepoints
1781 : !may_insert_tracepoints
))
1784 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
1786 /* GDB can be totally absent in some disconnected trace scenarios,
1787 but we don't really care if this semaphore goes out of sync.
1788 That's why we are decrementing it here, but not taking care
1790 if (loc
->probe
.prob
!= NULL
)
1791 loc
->probe
.prob
->clear_semaphore (loc
->probe
.objfile
,
1797 note
= trace_stop_notes
;
1798 ret
= target_set_trace_notes (NULL
, NULL
, note
);
1801 warning (_("Target does not support trace notes, note ignored"));
1803 /* Should change in response to reply? */
1804 current_trace_status ()->running
= 0;
1807 /* tstatus command */
1809 tstatus_command (const char *args
, int from_tty
)
1811 struct trace_status
*ts
= current_trace_status ();
1814 status
= target_get_trace_status (ts
);
1818 if (ts
->filename
!= NULL
)
1819 printf_filtered (_("Using a trace file.\n"));
1822 printf_filtered (_("Trace can not be run on this target.\n"));
1827 if (!ts
->running_known
)
1829 printf_filtered (_("Run/stop status is unknown.\n"));
1831 else if (ts
->running
)
1833 printf_filtered (_("Trace is running on the target.\n"));
1837 switch (ts
->stop_reason
)
1839 case trace_never_run
:
1840 printf_filtered (_("No trace has been run on the target.\n"));
1842 case trace_stop_command
:
1844 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1847 printf_filtered (_("Trace stopped by a tstop command.\n"));
1849 case trace_buffer_full
:
1850 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1852 case trace_disconnected
:
1853 printf_filtered (_("Trace stopped because of disconnection.\n"));
1855 case tracepoint_passcount
:
1856 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1857 ts
->stopping_tracepoint
);
1859 case tracepoint_error
:
1860 if (ts
->stopping_tracepoint
)
1861 printf_filtered (_("Trace stopped by an "
1862 "error (%s, tracepoint %d).\n"),
1863 ts
->stop_desc
, ts
->stopping_tracepoint
);
1865 printf_filtered (_("Trace stopped by an error (%s).\n"),
1868 case trace_stop_reason_unknown
:
1869 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1872 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1878 if (ts
->traceframes_created
>= 0
1879 && ts
->traceframe_count
!= ts
->traceframes_created
)
1881 printf_filtered (_("Buffer contains %d trace "
1882 "frames (of %d created total).\n"),
1883 ts
->traceframe_count
, ts
->traceframes_created
);
1885 else if (ts
->traceframe_count
>= 0)
1887 printf_filtered (_("Collected %d trace frames.\n"),
1888 ts
->traceframe_count
);
1891 if (ts
->buffer_free
>= 0)
1893 if (ts
->buffer_size
>= 0)
1895 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1896 ts
->buffer_free
, ts
->buffer_size
);
1897 if (ts
->buffer_size
> 0)
1898 printf_filtered (_(" (%d%% full)"),
1899 ((int) ((((long long) (ts
->buffer_size
1900 - ts
->buffer_free
)) * 100)
1901 / ts
->buffer_size
)));
1902 printf_filtered (_(".\n"));
1905 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1909 if (ts
->disconnected_tracing
)
1910 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1912 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1914 if (ts
->circular_buffer
)
1915 printf_filtered (_("Trace buffer is circular.\n"));
1917 if (ts
->user_name
&& strlen (ts
->user_name
) > 0)
1918 printf_filtered (_("Trace user is %s.\n"), ts
->user_name
);
1920 if (ts
->notes
&& strlen (ts
->notes
) > 0)
1921 printf_filtered (_("Trace notes: %s.\n"), ts
->notes
);
1923 /* Now report on what we're doing with tfind. */
1924 if (traceframe_number
>= 0)
1925 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1926 traceframe_number
, tracepoint_number
);
1928 printf_filtered (_("Not looking at any trace frame.\n"));
1930 /* Report start/stop times if supplied. */
1935 LONGEST run_time
= ts
->stop_time
- ts
->start_time
;
1937 /* Reporting a run time is more readable than two long numbers. */
1938 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
1939 (long int) (ts
->start_time
/ 1000000),
1940 (long int) (ts
->start_time
% 1000000),
1941 (long int) (run_time
/ 1000000),
1942 (long int) (run_time
% 1000000));
1945 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
1946 (long int) (ts
->start_time
/ 1000000),
1947 (long int) (ts
->start_time
% 1000000));
1949 else if (ts
->stop_time
)
1950 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
1951 (long int) (ts
->stop_time
/ 1000000),
1952 (long int) (ts
->stop_time
% 1000000));
1954 /* Now report any per-tracepoint status available. */
1955 for (breakpoint
*t
: all_tracepoints ())
1956 target_get_tracepoint_status (t
, NULL
);
1959 /* Report the trace status to uiout, in a way suitable for MI, and not
1960 suitable for CLI. If ON_STOP is true, suppress a few fields that
1961 are not meaningful in the -trace-stop response.
1963 The implementation is essentially parallel to trace_status_command, but
1964 merging them will result in unreadable code. */
1966 trace_status_mi (int on_stop
)
1968 struct ui_out
*uiout
= current_uiout
;
1969 struct trace_status
*ts
= current_trace_status ();
1972 status
= target_get_trace_status (ts
);
1974 if (status
== -1 && ts
->filename
== NULL
)
1976 uiout
->field_string ("supported", "0");
1980 if (ts
->filename
!= NULL
)
1981 uiout
->field_string ("supported", "file");
1983 uiout
->field_string ("supported", "1");
1985 if (ts
->filename
!= NULL
)
1986 uiout
->field_string ("trace-file", ts
->filename
);
1988 gdb_assert (ts
->running_known
);
1992 uiout
->field_string ("running", "1");
1994 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
1995 Given that the frontend gets the status either on -trace-stop, or from
1996 -trace-status after re-connection, it does not seem like this
1997 information is necessary for anything. It is not necessary for either
1998 figuring the vital state of the target nor for navigation of trace
1999 frames. If the frontend wants to show the current state is some
2000 configure dialog, it can request the value when such dialog is
2001 invoked by the user. */
2005 const char *stop_reason
= NULL
;
2006 int stopping_tracepoint
= -1;
2009 uiout
->field_string ("running", "0");
2011 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
2013 switch (ts
->stop_reason
)
2015 case trace_stop_command
:
2016 stop_reason
= "request";
2018 case trace_buffer_full
:
2019 stop_reason
= "overflow";
2021 case trace_disconnected
:
2022 stop_reason
= "disconnection";
2024 case tracepoint_passcount
:
2025 stop_reason
= "passcount";
2026 stopping_tracepoint
= ts
->stopping_tracepoint
;
2028 case tracepoint_error
:
2029 stop_reason
= "error";
2030 stopping_tracepoint
= ts
->stopping_tracepoint
;
2036 uiout
->field_string ("stop-reason", stop_reason
);
2037 if (stopping_tracepoint
!= -1)
2038 uiout
->field_signed ("stopping-tracepoint",
2039 stopping_tracepoint
);
2040 if (ts
->stop_reason
== tracepoint_error
)
2041 uiout
->field_string ("error-description",
2047 if (ts
->traceframe_count
!= -1)
2048 uiout
->field_signed ("frames", ts
->traceframe_count
);
2049 if (ts
->traceframes_created
!= -1)
2050 uiout
->field_signed ("frames-created", ts
->traceframes_created
);
2051 if (ts
->buffer_size
!= -1)
2052 uiout
->field_signed ("buffer-size", ts
->buffer_size
);
2053 if (ts
->buffer_free
!= -1)
2054 uiout
->field_signed ("buffer-free", ts
->buffer_free
);
2056 uiout
->field_signed ("disconnected", ts
->disconnected_tracing
);
2057 uiout
->field_signed ("circular", ts
->circular_buffer
);
2059 uiout
->field_string ("user-name", ts
->user_name
);
2060 uiout
->field_string ("notes", ts
->notes
);
2065 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2066 (long int) (ts
->start_time
/ 1000000),
2067 (long int) (ts
->start_time
% 1000000));
2068 uiout
->field_string ("start-time", buf
);
2069 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2070 (long int) (ts
->stop_time
/ 1000000),
2071 (long int) (ts
->stop_time
% 1000000));
2072 uiout
->field_string ("stop-time", buf
);
2076 /* Check if a trace run is ongoing. If so, and FROM_TTY, query the
2077 user if she really wants to detach. */
2080 query_if_trace_running (int from_tty
)
2085 /* It can happen that the target that was tracing went away on its
2086 own, and we didn't notice. Get a status update, and if the
2087 current target doesn't even do tracing, then assume it's not
2089 if (target_get_trace_status (current_trace_status ()) < 0)
2090 current_trace_status ()->running
= 0;
2092 /* If running interactively, give the user the option to cancel and
2093 then decide what to do differently with the run. Scripts are
2094 just going to disconnect and let the target deal with it,
2095 according to how it's been instructed previously via
2096 disconnected-tracing. */
2097 if (current_trace_status ()->running
)
2099 process_tracepoint_on_disconnect ();
2101 if (current_trace_status ()->disconnected_tracing
)
2103 if (!query (_("Trace is running and will "
2104 "continue after detach; detach anyway? ")))
2105 error (_("Not confirmed."));
2109 if (!query (_("Trace is running but will "
2110 "stop on detach; detach anyway? ")))
2111 error (_("Not confirmed."));
2116 /* This function handles the details of what to do about an ongoing
2117 tracing run if the user has asked to detach or otherwise disconnect
2121 disconnect_tracing (void)
2123 /* Also we want to be out of tfind mode, otherwise things can get
2124 confusing upon reconnection. Just use these calls instead of
2125 full tfind_1 behavior because we're in the middle of detaching,
2126 and there's no point to updating current stack frame etc. */
2127 trace_reset_local_state ();
2130 /* Worker function for the various flavors of the tfind command. */
2132 tfind_1 (enum trace_find_type type
, int num
,
2133 CORE_ADDR addr1
, CORE_ADDR addr2
,
2136 int target_frameno
= -1, target_tracept
= -1;
2137 struct frame_id old_frame_id
= null_frame_id
;
2138 struct tracepoint
*tp
;
2139 struct ui_out
*uiout
= current_uiout
;
2141 /* Only try to get the current stack frame if we have a chance of
2142 succeeding. In particular, if we're trying to get a first trace
2143 frame while all threads are running, it's not going to succeed,
2144 so leave it with a default value and let the frame comparison
2145 below (correctly) decide to print out the source location of the
2147 if (!(type
== tfind_number
&& num
== -1)
2148 && (has_stack_frames () || traceframe_number
>= 0))
2149 old_frame_id
= get_frame_id (get_current_frame ());
2151 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
2154 if (type
== tfind_number
2156 && target_frameno
== -1)
2158 /* We told the target to get out of tfind mode, and it did. */
2160 else if (target_frameno
== -1)
2162 /* A request for a non-existent trace frame has failed.
2163 Our response will be different, depending on FROM_TTY:
2165 If FROM_TTY is true, meaning that this command was
2166 typed interactively by the user, then give an error
2167 and DO NOT change the state of traceframe_number etc.
2169 However if FROM_TTY is false, meaning that we're either
2170 in a script, a loop, or a user-defined command, then
2171 DON'T give an error, but DO change the state of
2172 traceframe_number etc. to invalid.
2174 The rationale is that if you typed the command, you
2175 might just have committed a typo or something, and you'd
2176 like to NOT lose your current debugging state. However
2177 if you're in a user-defined command or especially in a
2178 loop, then you need a way to detect that the command
2179 failed WITHOUT aborting. This allows you to write
2180 scripts that search thru the trace buffer until the end,
2181 and then continue on to do something else. */
2184 error (_("Target failed to find requested trace frame."));
2188 printf_filtered ("End of trace buffer.\n");
2189 #if 0 /* dubious now? */
2190 /* The following will not recurse, since it's
2192 tfind_command ("-1", from_tty
);
2197 tp
= get_tracepoint_by_number_on_target (target_tracept
);
2199 reinit_frame_cache ();
2200 target_dcache_invalidate ();
2202 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
2204 if (target_frameno
!= get_traceframe_number ())
2205 gdb::observers::traceframe_changed
.notify (target_frameno
, tracepoint_number
);
2207 set_current_traceframe (target_frameno
);
2209 if (target_frameno
== -1)
2210 set_traceframe_context (NULL
);
2212 set_traceframe_context (get_current_frame ());
2214 if (traceframe_number
>= 0)
2216 /* Use different branches for MI and CLI to make CLI messages
2218 if (uiout
->is_mi_like_p ())
2220 uiout
->field_string ("found", "1");
2221 uiout
->field_signed ("tracepoint", tracepoint_number
);
2222 uiout
->field_signed ("traceframe", traceframe_number
);
2226 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2227 traceframe_number
, tracepoint_number
);
2232 if (uiout
->is_mi_like_p ())
2233 uiout
->field_string ("found", "0");
2234 else if (type
== tfind_number
&& num
== -1)
2235 printf_unfiltered (_("No longer looking at any trace frame\n"));
2236 else /* This case may never occur, check. */
2237 printf_unfiltered (_("No trace frame found\n"));
2240 /* If we're in nonstop mode and getting out of looking at trace
2241 frames, there won't be any current frame to go back to and
2244 && (has_stack_frames () || traceframe_number
>= 0))
2246 enum print_what print_what
;
2248 /* NOTE: in imitation of the step command, try to determine
2249 whether we have made a transition from one function to
2250 another. If so, we'll print the "stack frame" (ie. the new
2251 function and it's arguments) -- otherwise we'll just show the
2254 if (frame_id_eq (old_frame_id
,
2255 get_frame_id (get_current_frame ())))
2256 print_what
= SRC_LINE
;
2258 print_what
= SRC_AND_LOC
;
2260 print_stack_frame (get_selected_frame (NULL
), 1, print_what
, 1);
2265 /* Error on looking at traceframes while trace is running. */
2268 check_trace_running (struct trace_status
*status
)
2270 if (status
->running
&& status
->filename
== NULL
)
2271 error (_("May not look at trace frames while trace is running."));
2274 /* trace_find_command takes a trace frame number n,
2275 sends "QTFrame:<n>" to the target,
2276 and accepts a reply that may contain several optional pieces
2277 of information: a frame number, a tracepoint number, and an
2278 indication of whether this is a trap frame or a stepping frame.
2280 The minimal response is just "OK" (which indicates that the
2281 target does not give us a frame number or a tracepoint number).
2282 Instead of that, the target may send us a string containing
2284 F<hexnum> (gives the selected frame number)
2285 T<hexnum> (gives the selected tracepoint number)
2290 tfind_command_1 (const char *args
, int from_tty
)
2291 { /* This should only be called with a numeric argument. */
2294 check_trace_running (current_trace_status ());
2296 if (args
== 0 || *args
== 0)
2297 { /* TFIND with no args means find NEXT trace frame. */
2298 if (traceframe_number
== -1)
2299 frameno
= 0; /* "next" is first one. */
2301 frameno
= traceframe_number
+ 1;
2303 else if (0 == strcmp (args
, "-"))
2305 if (traceframe_number
== -1)
2306 error (_("not debugging trace buffer"));
2307 else if (from_tty
&& traceframe_number
== 0)
2308 error (_("already at start of trace buffer"));
2310 frameno
= traceframe_number
- 1;
2312 /* A hack to work around eval's need for fp to have been collected. */
2313 else if (0 == strcmp (args
, "-1"))
2316 frameno
= parse_and_eval_long (args
);
2319 error (_("invalid input (%d is less than zero)"), frameno
);
2321 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
2325 tfind_command (const char *args
, int from_tty
)
2327 tfind_command_1 (args
, from_tty
);
2332 tfind_end_command (const char *args
, int from_tty
)
2334 tfind_command_1 ("-1", from_tty
);
2339 tfind_start_command (const char *args
, int from_tty
)
2341 tfind_command_1 ("0", from_tty
);
2344 /* tfind pc command */
2346 tfind_pc_command (const char *args
, int from_tty
)
2350 check_trace_running (current_trace_status ());
2352 if (args
== 0 || *args
== 0)
2353 pc
= regcache_read_pc (get_current_regcache ());
2355 pc
= parse_and_eval_address (args
);
2357 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
2360 /* tfind tracepoint command */
2362 tfind_tracepoint_command (const char *args
, int from_tty
)
2365 struct tracepoint
*tp
;
2367 check_trace_running (current_trace_status ());
2369 if (args
== 0 || *args
== 0)
2371 if (tracepoint_number
== -1)
2372 error (_("No current tracepoint -- please supply an argument."));
2374 tdp
= tracepoint_number
; /* Default is current TDP. */
2377 tdp
= parse_and_eval_long (args
);
2379 /* If we have the tracepoint on hand, use the number that the
2380 target knows about (which may be different if we disconnected
2381 and reconnected). */
2382 tp
= get_tracepoint (tdp
);
2384 tdp
= tp
->number_on_target
;
2386 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
2389 /* TFIND LINE command:
2391 This command will take a sourceline for argument, just like BREAK
2392 or TRACE (ie. anything that "decode_line_1" can handle).
2394 With no argument, this command will find the next trace frame
2395 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2398 tfind_line_command (const char *args
, int from_tty
)
2400 check_trace_running (current_trace_status ());
2402 symtab_and_line sal
;
2403 if (args
== 0 || *args
== 0)
2405 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2409 std::vector
<symtab_and_line
> sals
2410 = decode_line_with_current_source (args
, DECODE_LINE_FUNFIRSTLINE
);
2414 if (sal
.symtab
== 0)
2415 error (_("No line number information available."));
2417 CORE_ADDR start_pc
, end_pc
;
2418 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2420 if (start_pc
== end_pc
)
2422 printf_filtered ("Line %d of \"%s\"",
2424 symtab_to_filename_for_display (sal
.symtab
));
2426 printf_filtered (" is at address ");
2427 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2429 printf_filtered (" but contains no code.\n");
2430 sal
= find_pc_line (start_pc
, 0);
2432 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2433 && start_pc
!= end_pc
)
2434 printf_filtered ("Attempting to find line %d instead.\n",
2437 error (_("Cannot find a good line."));
2441 /* Is there any case in which we get here, and have an address
2442 which the user would want to see? If we have debugging
2443 symbols and no line numbers? */
2444 error (_("Line number %d is out of range for \"%s\"."),
2445 sal
.line
, symtab_to_filename_for_display (sal
.symtab
));
2447 /* Find within range of stated line. */
2449 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2451 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2454 /* tfind range command */
2456 tfind_range_command (const char *args
, int from_tty
)
2458 static CORE_ADDR start
, stop
;
2461 check_trace_running (current_trace_status ());
2463 if (args
== 0 || *args
== 0)
2464 { /* XXX FIXME: what should default behavior be? */
2465 printf_filtered ("Usage: tfind range STARTADDR, ENDADDR\n");
2469 if (0 != (tmp
= strchr (args
, ',')))
2471 std::string
start_addr (args
, tmp
);
2473 tmp
= skip_spaces (tmp
);
2474 start
= parse_and_eval_address (start_addr
.c_str ());
2475 stop
= parse_and_eval_address (tmp
);
2478 { /* No explicit end address? */
2479 start
= parse_and_eval_address (args
);
2480 stop
= start
+ 1; /* ??? */
2483 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2486 /* tfind outside command */
2488 tfind_outside_command (const char *args
, int from_tty
)
2490 CORE_ADDR start
, stop
;
2493 if (current_trace_status ()->running
2494 && current_trace_status ()->filename
== NULL
)
2495 error (_("May not look at trace frames while trace is running."));
2497 if (args
== 0 || *args
== 0)
2498 { /* XXX FIXME: what should default behavior be? */
2499 printf_filtered ("Usage: tfind outside STARTADDR, ENDADDR\n");
2503 if (0 != (tmp
= strchr (args
, ',')))
2505 std::string
start_addr (args
, tmp
);
2507 tmp
= skip_spaces (tmp
);
2508 start
= parse_and_eval_address (start_addr
.c_str ());
2509 stop
= parse_and_eval_address (tmp
);
2512 { /* No explicit end address? */
2513 start
= parse_and_eval_address (args
);
2514 stop
= start
+ 1; /* ??? */
2517 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2520 /* info scope command: list the locals for a scope. */
2522 info_scope_command (const char *args_in
, int from_tty
)
2525 struct bound_minimal_symbol msym
;
2526 const struct block
*block
;
2527 const char *symname
;
2528 const char *save_args
= args_in
;
2529 struct block_iterator iter
;
2531 struct gdbarch
*gdbarch
;
2533 const char *args
= args_in
;
2535 if (args
== 0 || *args
== 0)
2536 error (_("requires an argument (function, "
2537 "line or *addr) to define a scope"));
2539 event_location_up location
= string_to_event_location (&args
,
2541 std::vector
<symtab_and_line
> sals
2542 = decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
2546 /* Presumably decode_line_1 has already warned. */
2550 /* Resolve line numbers to PC. */
2551 resolve_sal_pc (&sals
[0]);
2552 block
= block_for_pc (sals
[0].pc
);
2556 QUIT
; /* Allow user to bail out with ^C. */
2557 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2559 QUIT
; /* Allow user to bail out with ^C. */
2561 printf_filtered ("Scope for %s:\n", save_args
);
2564 symname
= sym
->print_name ();
2565 if (symname
== NULL
|| *symname
== '\0')
2566 continue; /* Probably botched, certainly useless. */
2568 gdbarch
= symbol_arch (sym
);
2570 printf_filtered ("Symbol %s is ", symname
);
2572 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
2573 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
,
2574 BLOCK_ENTRY_PC (block
),
2578 switch (SYMBOL_CLASS (sym
))
2581 case LOC_UNDEF
: /* Messed up symbol? */
2582 printf_filtered ("a bogus symbol, class %d.\n",
2583 SYMBOL_CLASS (sym
));
2584 count
--; /* Don't count this one. */
2587 printf_filtered ("a constant with value %s (%s)",
2588 plongest (SYMBOL_VALUE (sym
)),
2589 hex_string (SYMBOL_VALUE (sym
)));
2591 case LOC_CONST_BYTES
:
2592 printf_filtered ("constant bytes: ");
2593 if (SYMBOL_TYPE (sym
))
2594 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2595 fprintf_filtered (gdb_stdout
, " %02x",
2596 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2599 printf_filtered ("in static storage at address ");
2600 printf_filtered ("%s", paddress (gdbarch
,
2601 SYMBOL_VALUE_ADDRESS (sym
)));
2604 /* GDBARCH is the architecture associated with the objfile
2605 the symbol is defined in; the target architecture may be
2606 different, and may provide additional registers. However,
2607 we do not know the target architecture at this point.
2608 We assume the objfile architecture will contain all the
2609 standard registers that occur in debug info in that
2611 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2614 if (SYMBOL_IS_ARGUMENT (sym
))
2615 printf_filtered ("an argument in register $%s",
2616 gdbarch_register_name (gdbarch
, regno
));
2618 printf_filtered ("a local variable in register $%s",
2619 gdbarch_register_name (gdbarch
, regno
));
2622 printf_filtered ("an argument at stack/frame offset %s",
2623 plongest (SYMBOL_VALUE (sym
)));
2626 printf_filtered ("a local variable at frame offset %s",
2627 plongest (SYMBOL_VALUE (sym
)));
2630 printf_filtered ("a reference argument at offset %s",
2631 plongest (SYMBOL_VALUE (sym
)));
2633 case LOC_REGPARM_ADDR
:
2634 /* Note comment at LOC_REGISTER. */
2635 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2637 printf_filtered ("the address of an argument, in register $%s",
2638 gdbarch_register_name (gdbarch
, regno
));
2641 printf_filtered ("a typedef.\n");
2644 printf_filtered ("a label at address ");
2645 printf_filtered ("%s", paddress (gdbarch
,
2646 SYMBOL_VALUE_ADDRESS (sym
)));
2649 printf_filtered ("a function at address ");
2650 printf_filtered ("%s",
2651 paddress (gdbarch
, BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
))));
2653 case LOC_UNRESOLVED
:
2654 msym
= lookup_minimal_symbol (sym
->linkage_name (),
2656 if (msym
.minsym
== NULL
)
2657 printf_filtered ("Unresolved Static");
2660 printf_filtered ("static storage at address ");
2661 printf_filtered ("%s",
2663 BMSYMBOL_VALUE_ADDRESS (msym
)));
2666 case LOC_OPTIMIZED_OUT
:
2667 printf_filtered ("optimized out.\n");
2670 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2673 if (SYMBOL_TYPE (sym
))
2675 struct type
*t
= check_typedef (SYMBOL_TYPE (sym
));
2677 printf_filtered (", length %s.\n", pulongest (TYPE_LENGTH (t
)));
2680 if (BLOCK_FUNCTION (block
))
2683 block
= BLOCK_SUPERBLOCK (block
);
2686 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2690 /* Helper for trace_dump_command. Dump the action list starting at
2691 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2692 actions of the body of a while-stepping action. STEPPING_FRAME is
2693 set if the current traceframe was determined to be a while-stepping
2697 trace_dump_actions (struct command_line
*action
,
2698 int stepping_actions
, int stepping_frame
,
2701 const char *action_exp
, *next_comma
;
2703 for (; action
!= NULL
; action
= action
->next
)
2705 struct cmd_list_element
*cmd
;
2707 QUIT
; /* Allow user to bail out with ^C. */
2708 action_exp
= action
->line
;
2709 action_exp
= skip_spaces (action_exp
);
2711 /* The collection actions to be done while stepping are
2712 bracketed by the commands "while-stepping" and "end". */
2714 if (*action_exp
== '#') /* comment line */
2717 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", NULL
, -1, 1);
2719 error (_("Bad action list item: %s"), action_exp
);
2721 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2723 gdb_assert (action
->body_list_1
== nullptr);
2724 trace_dump_actions (action
->body_list_0
.get (),
2725 1, stepping_frame
, from_tty
);
2727 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2729 /* Display the collected data.
2730 For the trap frame, display only what was collected at
2731 the trap. Likewise for stepping frames, display only
2732 what was collected while stepping. This means that the
2733 two boolean variables, STEPPING_FRAME and
2734 STEPPING_ACTIONS should be equal. */
2735 if (stepping_frame
== stepping_actions
)
2737 int trace_string
= 0;
2739 if (*action_exp
== '/')
2740 action_exp
= decode_agent_options (action_exp
, &trace_string
);
2743 { /* Repeat over a comma-separated list. */
2744 QUIT
; /* Allow user to bail out with ^C. */
2745 if (*action_exp
== ',')
2747 action_exp
= skip_spaces (action_exp
);
2749 next_comma
= strchr (action_exp
, ',');
2751 if (0 == strncasecmp (action_exp
, "$reg", 4))
2752 registers_info (NULL
, from_tty
);
2753 else if (0 == strncasecmp (action_exp
, "$_ret", 5))
2755 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2756 info_locals_command (NULL
, from_tty
);
2757 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2758 info_args_command (NULL
, from_tty
);
2761 std::string contents
;
2762 const char *exp
= action_exp
;
2763 if (next_comma
!= NULL
)
2765 size_t len
= next_comma
- action_exp
;
2766 contents
= std::string (action_exp
, len
);
2767 exp
= contents
.c_str ();
2770 printf_filtered ("%s = ", exp
);
2771 output_command (exp
, from_tty
);
2772 printf_filtered ("\n");
2774 action_exp
= next_comma
;
2776 while (action_exp
&& *action_exp
== ',');
2782 /* Return bp_location of the tracepoint associated with the current
2783 traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe
2784 is a stepping traceframe. */
2786 struct bp_location
*
2787 get_traceframe_location (int *stepping_frame_p
)
2789 struct tracepoint
*t
;
2790 struct bp_location
*tloc
;
2791 struct regcache
*regcache
;
2793 if (tracepoint_number
== -1)
2794 error (_("No current trace frame."));
2796 t
= get_tracepoint (tracepoint_number
);
2799 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2802 /* The current frame is a trap frame if the frame PC is equal to the
2803 tracepoint PC. If not, then the current frame was collected
2804 during single-stepping. */
2805 regcache
= get_current_regcache ();
2807 /* If the traceframe's address matches any of the tracepoint's
2808 locations, assume it is a direct hit rather than a while-stepping
2809 frame. (FIXME this is not reliable, should record each frame's
2811 for (tloc
= t
->loc
; tloc
; tloc
= tloc
->next
)
2812 if (tloc
->address
== regcache_read_pc (regcache
))
2814 *stepping_frame_p
= 0;
2818 /* If this is a stepping frame, we don't know which location
2819 triggered. The first is as good (or bad) a guess as any... */
2820 *stepping_frame_p
= 1;
2824 /* Return the default collect actions of a tracepoint T. */
2826 static counted_command_line
2827 all_tracepoint_actions (struct breakpoint
*t
)
2829 counted_command_line
actions (nullptr, command_lines_deleter ());
2831 /* If there are default expressions to collect, make up a collect
2832 action and prepend to the action list to encode. Note that since
2833 validation is per-tracepoint (local var "xyz" might be valid for
2834 one tracepoint and not another, etc), we make up the action on
2835 the fly, and don't cache it. */
2836 if (*default_collect
)
2838 gdb::unique_xmalloc_ptr
<char> default_collect_line
2839 (xstrprintf ("collect %s", default_collect
));
2841 validate_actionline (default_collect_line
.get (), t
);
2842 actions
.reset (new struct command_line (simple_control
,
2843 default_collect_line
.release ()),
2844 command_lines_deleter ());
2850 /* The tdump command. */
2853 tdump_command (const char *args
, int from_tty
)
2855 int stepping_frame
= 0;
2856 struct bp_location
*loc
;
2858 /* This throws an error is not inspecting a trace frame. */
2859 loc
= get_traceframe_location (&stepping_frame
);
2861 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2862 tracepoint_number
, traceframe_number
);
2864 /* This command only makes sense for the current frame, not the
2866 scoped_restore_current_thread restore_thread
;
2868 select_frame (get_current_frame ());
2870 counted_command_line actions
= all_tracepoint_actions (loc
->owner
);
2872 trace_dump_actions (actions
.get (), 0, stepping_frame
, from_tty
);
2873 trace_dump_actions (breakpoint_commands (loc
->owner
), 0, stepping_frame
,
2877 /* Encode a piece of a tracepoint's source-level definition in a form
2878 that is suitable for both protocol and saving in files. */
2879 /* This version does not do multiple encodes for long strings; it should
2880 return an offset to the next piece to encode. FIXME */
2883 encode_source_string (int tpnum
, ULONGEST addr
,
2884 const char *srctype
, const char *src
,
2885 char *buf
, int buf_size
)
2887 if (80 + strlen (srctype
) > buf_size
)
2888 error (_("Buffer too small for source encoding"));
2889 sprintf (buf
, "%x:%s:%s:%x:%x:",
2890 tpnum
, phex_nz (addr
, sizeof (addr
)),
2891 srctype
, 0, (int) strlen (src
));
2892 if (strlen (buf
) + strlen (src
) * 2 >= buf_size
)
2893 error (_("Source string too long for buffer"));
2894 bin2hex ((gdb_byte
*) src
, buf
+ strlen (buf
), strlen (src
));
2898 /* Tell the target what to do with an ongoing tracing run if GDB
2899 disconnects for some reason. */
2902 set_disconnected_tracing (const char *args
, int from_tty
,
2903 struct cmd_list_element
*c
)
2905 target_set_disconnected_tracing (disconnected_tracing
);
2909 set_circular_trace_buffer (const char *args
, int from_tty
,
2910 struct cmd_list_element
*c
)
2912 target_set_circular_trace_buffer (circular_trace_buffer
);
2916 set_trace_buffer_size (const char *args
, int from_tty
,
2917 struct cmd_list_element
*c
)
2919 target_set_trace_buffer_size (trace_buffer_size
);
2923 set_trace_user (const char *args
, int from_tty
,
2924 struct cmd_list_element
*c
)
2928 ret
= target_set_trace_notes (trace_user
, NULL
, NULL
);
2931 warning (_("Target does not support trace notes, user ignored"));
2935 set_trace_notes (const char *args
, int from_tty
,
2936 struct cmd_list_element
*c
)
2940 ret
= target_set_trace_notes (NULL
, trace_notes
, NULL
);
2943 warning (_("Target does not support trace notes, note ignored"));
2947 set_trace_stop_notes (const char *args
, int from_tty
,
2948 struct cmd_list_element
*c
)
2952 ret
= target_set_trace_notes (NULL
, NULL
, trace_stop_notes
);
2955 warning (_("Target does not support trace notes, stop note ignored"));
2958 /* Convert the memory pointed to by mem into hex, placing result in buf.
2959 * Return a pointer to the last char put in buf (null)
2960 * "stolen" from sparc-stub.c
2963 static const char hexchars
[] = "0123456789abcdef";
2966 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2974 *buf
++ = hexchars
[ch
>> 4];
2975 *buf
++ = hexchars
[ch
& 0xf];
2984 get_traceframe_number (void)
2986 return traceframe_number
;
2990 get_tracepoint_number (void)
2992 return tracepoint_number
;
2995 /* Make the traceframe NUM be the current trace frame. Does nothing
2996 if NUM is already current. */
2999 set_current_traceframe (int num
)
3003 if (traceframe_number
== num
)
3005 /* Nothing to do. */
3009 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
3012 warning (_("could not change traceframe"));
3014 set_traceframe_num (newnum
);
3016 /* Changing the traceframe changes our view of registers and of the
3018 registers_changed ();
3020 clear_traceframe_info ();
3023 scoped_restore_current_traceframe::scoped_restore_current_traceframe ()
3024 : m_traceframe_number (traceframe_number
)
3027 /* Given a number and address, return an uploaded tracepoint with that
3028 number, creating if necessary. */
3030 struct uploaded_tp
*
3031 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
3033 struct uploaded_tp
*utp
;
3035 for (utp
= *utpp
; utp
; utp
= utp
->next
)
3036 if (utp
->number
== num
&& utp
->addr
== addr
)
3039 utp
= new uploaded_tp
;
3049 free_uploaded_tps (struct uploaded_tp
**utpp
)
3051 struct uploaded_tp
*next_one
;
3055 next_one
= (*utpp
)->next
;
3061 /* Given a number and address, return an uploaded tracepoint with that
3062 number, creating if necessary. */
3064 struct uploaded_tsv
*
3065 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
3067 struct uploaded_tsv
*utsv
;
3069 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
3070 if (utsv
->number
== num
)
3073 utsv
= XCNEW (struct uploaded_tsv
);
3075 utsv
->next
= *utsvp
;
3082 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
3084 struct uploaded_tsv
*next_one
;
3088 next_one
= (*utsvp
)->next
;
3094 /* FIXME this function is heuristic and will miss the cases where the
3095 conditional is semantically identical but differs in whitespace,
3096 such as "x == 0" vs "x==0". */
3099 cond_string_is_same (char *str1
, char *str2
)
3101 if (str1
== NULL
|| str2
== NULL
)
3102 return (str1
== str2
);
3104 return (strcmp (str1
, str2
) == 0);
3107 /* Look for an existing tracepoint that seems similar enough to the
3108 uploaded one. Enablement isn't compared, because the user can
3109 toggle that freely, and may have done so in anticipation of the
3110 next trace run. Return the location of matched tracepoint. */
3112 static struct bp_location
*
3113 find_matching_tracepoint_location (struct uploaded_tp
*utp
)
3115 struct bp_location
*loc
;
3117 for (breakpoint
*b
: all_tracepoints ())
3119 struct tracepoint
*t
= (struct tracepoint
*) b
;
3121 if (b
->type
== utp
->type
3122 && t
->step_count
== utp
->step
3123 && t
->pass_count
== utp
->pass
3124 && cond_string_is_same (t
->cond_string
,
3125 utp
->cond_string
.get ())
3126 /* FIXME also test actions. */
3129 /* Scan the locations for an address match. */
3130 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3132 if (loc
->address
== utp
->addr
)
3140 /* Given a list of tracepoints uploaded from a target, attempt to
3141 match them up with existing tracepoints, and create new ones if not
3145 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
3147 struct uploaded_tp
*utp
;
3148 /* A set of tracepoints which are modified. */
3149 std::vector
<breakpoint
*> modified_tp
;
3151 /* Look for GDB tracepoints that match up with our uploaded versions. */
3152 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
3154 struct bp_location
*loc
;
3155 struct tracepoint
*t
;
3157 loc
= find_matching_tracepoint_location (utp
);
3162 /* Mark this location as already inserted. */
3164 t
= (struct tracepoint
*) loc
->owner
;
3165 printf_filtered (_("Assuming tracepoint %d is same "
3166 "as target's tracepoint %d at %s.\n"),
3167 loc
->owner
->number
, utp
->number
,
3168 paddress (loc
->gdbarch
, utp
->addr
));
3170 /* The tracepoint LOC->owner was modified (the location LOC
3171 was marked as inserted in the target). Save it in
3172 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3173 observers will be notified later once for each tracepoint
3174 saved in MODIFIED_TP. */
3175 for (breakpoint
*b
: modified_tp
)
3176 if (b
== loc
->owner
)
3182 modified_tp
.push_back (loc
->owner
);
3186 t
= create_tracepoint_from_upload (utp
);
3188 printf_filtered (_("Created tracepoint %d for "
3189 "target's tracepoint %d at %s.\n"),
3190 t
->number
, utp
->number
,
3191 paddress (get_current_arch (), utp
->addr
));
3193 printf_filtered (_("Failed to create tracepoint for target's "
3194 "tracepoint %d at %s, skipping it.\n"),
3196 paddress (get_current_arch (), utp
->addr
));
3198 /* Whether found or created, record the number used by the
3199 target, to help with mapping target tracepoints back to their
3200 counterparts here. */
3202 t
->number_on_target
= utp
->number
;
3205 /* Notify 'breakpoint-modified' observer that at least one of B's
3206 locations was changed. */
3207 for (breakpoint
*b
: modified_tp
)
3208 gdb::observers::breakpoint_modified
.notify (b
);
3210 free_uploaded_tps (uploaded_tps
);
3213 /* Trace state variables don't have much to identify them beyond their
3214 name, so just use that to detect matches. */
3216 static struct trace_state_variable
*
3217 find_matching_tsv (struct uploaded_tsv
*utsv
)
3222 return find_trace_state_variable (utsv
->name
);
3225 static struct trace_state_variable
*
3226 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
3228 const char *namebase
;
3231 struct trace_state_variable
*tsv
;
3235 namebase
= utsv
->name
;
3241 buf
= string_printf ("%s_%d", namebase
, try_num
++);
3244 /* Fish for a name that is not in use. */
3245 /* (should check against all internal vars?) */
3246 while (find_trace_state_variable (buf
.c_str ()))
3247 buf
= string_printf ("%s_%d", namebase
, try_num
++);
3249 /* We have an available name, create the variable. */
3250 tsv
= create_trace_state_variable (buf
.c_str ());
3251 tsv
->initial_value
= utsv
->initial_value
;
3252 tsv
->builtin
= utsv
->builtin
;
3254 gdb::observers::tsv_created
.notify (tsv
);
3259 /* Given a list of uploaded trace state variables, try to match them
3260 up with existing variables, or create additional ones. */
3263 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
3265 struct uploaded_tsv
*utsv
;
3268 /* Most likely some numbers will have to be reassigned as part of
3269 the merge, so clear them all in anticipation. */
3270 for (trace_state_variable
&tsv
: tvariables
)
3273 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
3275 struct trace_state_variable
*tsv
= find_matching_tsv (utsv
);
3279 printf_filtered (_("Assuming trace state variable $%s "
3280 "is same as target's variable %d.\n"),
3281 tsv
->name
.c_str (), utsv
->number
);
3285 tsv
= create_tsv_from_upload (utsv
);
3287 printf_filtered (_("Created trace state variable "
3288 "$%s for target's variable %d.\n"),
3289 tsv
->name
.c_str (), utsv
->number
);
3291 /* Give precedence to numberings that come from the target. */
3293 tsv
->number
= utsv
->number
;
3296 /* Renumber everything that didn't get a target-assigned number. */
3298 for (const trace_state_variable
&tsv
: tvariables
)
3299 highest
= std::max (tsv
.number
, highest
);
3302 for (trace_state_variable
&tsv
: tvariables
)
3303 if (tsv
.number
== 0)
3304 tsv
.number
= highest
++;
3306 free_uploaded_tsvs (uploaded_tsvs
);
3309 /* Parse the part of trace status syntax that is shared between
3310 the remote protocol and the trace file reader. */
3313 parse_trace_status (const char *line
, struct trace_status
*ts
)
3315 const char *p
= line
, *p1
, *p2
, *p3
, *p_temp
;
3319 ts
->running_known
= 1;
3320 ts
->running
= (*p
++ == '1');
3321 ts
->stop_reason
= trace_stop_reason_unknown
;
3322 xfree (ts
->stop_desc
);
3323 ts
->stop_desc
= NULL
;
3324 ts
->traceframe_count
= -1;
3325 ts
->traceframes_created
= -1;
3326 ts
->buffer_free
= -1;
3327 ts
->buffer_size
= -1;
3328 ts
->disconnected_tracing
= 0;
3329 ts
->circular_buffer
= 0;
3330 xfree (ts
->user_name
);
3331 ts
->user_name
= NULL
;
3334 ts
->start_time
= ts
->stop_time
= 0;
3338 p1
= strchr (p
, ':');
3340 error (_("Malformed trace status, at %s\n\
3341 Status line: '%s'\n"), p
, line
);
3342 p3
= strchr (p
, ';');
3344 p3
= p
+ strlen (p
);
3345 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
3347 p
= unpack_varlen_hex (++p1
, &val
);
3348 ts
->stop_reason
= trace_buffer_full
;
3350 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
3352 p
= unpack_varlen_hex (++p1
, &val
);
3353 ts
->stop_reason
= trace_never_run
;
3355 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
],
3358 p
= unpack_varlen_hex (++p1
, &val
);
3359 ts
->stop_reason
= tracepoint_passcount
;
3360 ts
->stopping_tracepoint
= val
;
3362 else if (strncmp (p
, stop_reason_names
[trace_stop_command
], p1
- p
) == 0)
3364 p2
= strchr (++p1
, ':');
3372 ts
->stop_desc
= (char *) xmalloc (strlen (line
));
3373 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3374 ts
->stop_desc
[end
] = '\0';
3377 ts
->stop_desc
= xstrdup ("");
3379 p
= unpack_varlen_hex (++p2
, &val
);
3380 ts
->stop_reason
= trace_stop_command
;
3382 else if (strncmp (p
, stop_reason_names
[trace_disconnected
], p1
- p
) == 0)
3384 p
= unpack_varlen_hex (++p1
, &val
);
3385 ts
->stop_reason
= trace_disconnected
;
3387 else if (strncmp (p
, stop_reason_names
[tracepoint_error
], p1
- p
) == 0)
3389 p2
= strchr (++p1
, ':');
3392 ts
->stop_desc
= (char *) xmalloc ((p2
- p1
) / 2 + 1);
3393 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3394 ts
->stop_desc
[end
] = '\0';
3397 ts
->stop_desc
= xstrdup ("");
3399 p
= unpack_varlen_hex (++p2
, &val
);
3400 ts
->stopping_tracepoint
= val
;
3401 ts
->stop_reason
= tracepoint_error
;
3403 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3405 p
= unpack_varlen_hex (++p1
, &val
);
3406 ts
->traceframe_count
= val
;
3408 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3410 p
= unpack_varlen_hex (++p1
, &val
);
3411 ts
->traceframes_created
= val
;
3413 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3415 p
= unpack_varlen_hex (++p1
, &val
);
3416 ts
->buffer_free
= val
;
3418 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3420 p
= unpack_varlen_hex (++p1
, &val
);
3421 ts
->buffer_size
= val
;
3423 else if (strncmp (p
, "disconn", p1
- p
) == 0)
3425 p
= unpack_varlen_hex (++p1
, &val
);
3426 ts
->disconnected_tracing
= val
;
3428 else if (strncmp (p
, "circular", p1
- p
) == 0)
3430 p
= unpack_varlen_hex (++p1
, &val
);
3431 ts
->circular_buffer
= val
;
3433 else if (strncmp (p
, "starttime", p1
- p
) == 0)
3435 p
= unpack_varlen_hex (++p1
, &val
);
3436 ts
->start_time
= val
;
3438 else if (strncmp (p
, "stoptime", p1
- p
) == 0)
3440 p
= unpack_varlen_hex (++p1
, &val
);
3441 ts
->stop_time
= val
;
3443 else if (strncmp (p
, "username", p1
- p
) == 0)
3446 ts
->user_name
= (char *) xmalloc (strlen (p
) / 2);
3447 end
= hex2bin (p1
, (gdb_byte
*) ts
->user_name
, (p3
- p1
) / 2);
3448 ts
->user_name
[end
] = '\0';
3451 else if (strncmp (p
, "notes", p1
- p
) == 0)
3454 ts
->notes
= (char *) xmalloc (strlen (p
) / 2);
3455 end
= hex2bin (p1
, (gdb_byte
*) ts
->notes
, (p3
- p1
) / 2);
3456 ts
->notes
[end
] = '\0';
3461 /* Silently skip unknown optional info. */
3462 p_temp
= strchr (p1
+ 1, ';');
3466 /* Must be at the end. */
3473 parse_tracepoint_status (const char *p
, struct breakpoint
*bp
,
3474 struct uploaded_tp
*utp
)
3477 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
3479 p
= unpack_varlen_hex (p
, &uval
);
3481 tp
->hit_count
+= uval
;
3483 utp
->hit_count
+= uval
;
3484 p
= unpack_varlen_hex (p
+ 1, &uval
);
3486 tp
->traceframe_usage
+= uval
;
3488 utp
->traceframe_usage
+= uval
;
3489 /* Ignore any extra, allowing for future extensions. */
3492 /* Given a line of text defining a part of a tracepoint, parse it into
3493 an "uploaded tracepoint". */
3496 parse_tracepoint_definition (const char *line
, struct uploaded_tp
**utpp
)
3500 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
, start
;
3503 const char *srctype
;
3505 struct uploaded_tp
*utp
= NULL
;
3508 /* Both tracepoint and action definitions start with the same number
3509 and address sequence. */
3511 p
= unpack_varlen_hex (p
, &num
);
3512 p
++; /* skip a colon */
3513 p
= unpack_varlen_hex (p
, &addr
);
3514 p
++; /* skip a colon */
3517 gdb::unique_xmalloc_ptr
<char[]> cond
;
3519 enabled
= (*p
++ == 'E');
3520 p
++; /* skip a colon */
3521 p
= unpack_varlen_hex (p
, &step
);
3522 p
++; /* skip a colon */
3523 p
= unpack_varlen_hex (p
, &pass
);
3524 type
= bp_tracepoint
;
3525 /* Thumb through optional fields. */
3528 p
++; /* skip a colon */
3531 type
= bp_fast_tracepoint
;
3533 p
= unpack_varlen_hex (p
, &orig_size
);
3537 type
= bp_static_tracepoint
;
3543 p
= unpack_varlen_hex (p
, &xlen
);
3544 p
++; /* skip a comma */
3545 cond
.reset ((char *) xmalloc (2 * xlen
+ 1));
3546 strncpy (&cond
[0], p
, 2 * xlen
);
3547 cond
[2 * xlen
] = '\0';
3551 warning (_("Unrecognized char '%c' in tracepoint "
3552 "definition, skipping rest"), *p
);
3554 utp
= get_uploaded_tp (num
, addr
, utpp
);
3556 utp
->enabled
= enabled
;
3559 utp
->cond
= std::move (cond
);
3561 else if (piece
== 'A')
3563 utp
= get_uploaded_tp (num
, addr
, utpp
);
3564 utp
->actions
.emplace_back (xstrdup (p
));
3566 else if (piece
== 'S')
3568 utp
= get_uploaded_tp (num
, addr
, utpp
);
3569 utp
->step_actions
.emplace_back (xstrdup (p
));
3571 else if (piece
== 'Z')
3573 /* Parse a chunk of source form definition. */
3574 utp
= get_uploaded_tp (num
, addr
, utpp
);
3576 p
= strchr (p
, ':');
3577 p
++; /* skip a colon */
3578 p
= unpack_varlen_hex (p
, &start
);
3579 p
++; /* skip a colon */
3580 p
= unpack_varlen_hex (p
, &xlen
);
3581 p
++; /* skip a colon */
3583 buf
= (char *) alloca (strlen (line
));
3585 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3588 if (startswith (srctype
, "at:"))
3589 utp
->at_string
.reset (xstrdup (buf
));
3590 else if (startswith (srctype
, "cond:"))
3591 utp
->cond_string
.reset (xstrdup (buf
));
3592 else if (startswith (srctype
, "cmd:"))
3593 utp
->cmd_strings
.emplace_back (xstrdup (buf
));
3595 else if (piece
== 'V')
3597 utp
= get_uploaded_tp (num
, addr
, utpp
);
3599 parse_tracepoint_status (p
, NULL
, utp
);
3603 /* Don't error out, the target might be sending us optional
3604 info that we don't care about. */
3605 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece
);
3609 /* Convert a textual description of a trace state variable into an
3613 parse_tsv_definition (const char *line
, struct uploaded_tsv
**utsvp
)
3617 ULONGEST num
, initval
, builtin
;
3619 struct uploaded_tsv
*utsv
= NULL
;
3621 buf
= (char *) alloca (strlen (line
));
3624 p
= unpack_varlen_hex (p
, &num
);
3625 p
++; /* skip a colon */
3626 p
= unpack_varlen_hex (p
, &initval
);
3627 p
++; /* skip a colon */
3628 p
= unpack_varlen_hex (p
, &builtin
);
3629 p
++; /* skip a colon */
3630 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3633 utsv
= get_uploaded_tsv (num
, utsvp
);
3634 utsv
->initial_value
= initval
;
3635 utsv
->builtin
= builtin
;
3636 utsv
->name
= xstrdup (buf
);
3639 /* Given a line of text defining a static tracepoint marker, parse it
3640 into a "static tracepoint marker" object. Throws an error is
3641 parsing fails. If PP is non-null, it points to one past the end of
3642 the parsed marker definition. */
3645 parse_static_tracepoint_marker_definition (const char *line
, const char **pp
,
3646 static_tracepoint_marker
*marker
)
3648 const char *p
, *endp
;
3652 p
= unpack_varlen_hex (p
, &addr
);
3653 p
++; /* skip a colon */
3655 marker
->gdbarch
= target_gdbarch ();
3656 marker
->address
= (CORE_ADDR
) addr
;
3658 endp
= strchr (p
, ':');
3660 error (_("bad marker definition: %s"), line
);
3662 marker
->str_id
= hex2str (p
, (endp
- p
) / 2);
3665 p
++; /* skip a colon */
3667 /* This definition may be followed by another one, separated by a comma. */
3669 endp
= strchr (p
, ',');
3670 if (endp
!= nullptr)
3673 hex_len
= strlen (p
);
3675 marker
->extra
= hex2str (p
, hex_len
/ 2);
3681 /* Print MARKER to gdb_stdout. */
3684 print_one_static_tracepoint_marker (int count
,
3685 const static_tracepoint_marker
&marker
)
3689 char wrap_indent
[80];
3690 char extra_field_indent
[80];
3691 struct ui_out
*uiout
= current_uiout
;
3693 symtab_and_line sal
;
3694 sal
.pc
= marker
.address
;
3696 std::vector
<breakpoint
*> tracepoints
3697 = static_tracepoints_here (marker
.address
);
3699 ui_out_emit_tuple
tuple_emitter (uiout
, "marker");
3701 /* A counter field to help readability. This is not a stable
3703 uiout
->field_signed ("count", count
);
3705 uiout
->field_string ("marker-id", marker
.str_id
.c_str ());
3707 uiout
->field_fmt ("enabled", "%c",
3708 !tracepoints
.empty () ? 'y' : 'n');
3711 strcpy (wrap_indent
, " ");
3713 if (gdbarch_addr_bit (marker
.gdbarch
) <= 32)
3714 strcat (wrap_indent
, " ");
3716 strcat (wrap_indent
, " ");
3718 strcpy (extra_field_indent
, " ");
3720 uiout
->field_core_addr ("addr", marker
.gdbarch
, marker
.address
);
3722 sal
= find_pc_line (marker
.address
, 0);
3723 sym
= find_pc_sect_function (marker
.address
, NULL
);
3726 uiout
->text ("in ");
3727 uiout
->field_string ("func", sym
->print_name (),
3728 function_name_style
.style ());
3729 uiout
->wrap_hint (wrap_indent
);
3730 uiout
->text (" at ");
3733 uiout
->field_skip ("func");
3735 if (sal
.symtab
!= NULL
)
3737 uiout
->field_string ("file",
3738 symtab_to_filename_for_display (sal
.symtab
),
3739 file_name_style
.style ());
3742 if (uiout
->is_mi_like_p ())
3744 const char *fullname
= symtab_to_fullname (sal
.symtab
);
3746 uiout
->field_string ("fullname", fullname
);
3749 uiout
->field_skip ("fullname");
3751 uiout
->field_signed ("line", sal
.line
);
3755 uiout
->field_skip ("fullname");
3756 uiout
->field_skip ("line");
3760 uiout
->text (extra_field_indent
);
3761 uiout
->text (_("Data: \""));
3762 uiout
->field_string ("extra-data", marker
.extra
.c_str ());
3763 uiout
->text ("\"\n");
3765 if (!tracepoints
.empty ())
3770 ui_out_emit_tuple
inner_tuple_emitter (uiout
, "tracepoints-at");
3772 uiout
->text (extra_field_indent
);
3773 uiout
->text (_("Probed by static tracepoints: "));
3774 for (ix
= 0; ix
< tracepoints
.size (); ix
++)
3779 uiout
->field_signed ("tracepoint-id", tracepoints
[ix
]->number
);
3783 if (uiout
->is_mi_like_p ())
3784 uiout
->field_signed ("number-of-tracepoints", tracepoints
.size ());
3791 info_static_tracepoint_markers_command (const char *arg
, int from_tty
)
3793 struct ui_out
*uiout
= current_uiout
;
3794 std::vector
<static_tracepoint_marker
> markers
3795 = target_static_tracepoint_markers_by_strid (NULL
);
3797 /* We don't have to check target_can_use_agent and agent's capability on
3798 static tracepoint here, in order to be compatible with older GDBserver.
3799 We don't check USE_AGENT is true or not, because static tracepoints
3800 don't work without in-process agent, so we don't bother users to type
3801 `set agent on' when to use static tracepoint. */
3803 ui_out_emit_table
table_emitter (uiout
, 5, -1,
3804 "StaticTracepointMarkersTable");
3806 uiout
->table_header (7, ui_left
, "counter", "Cnt");
3808 uiout
->table_header (40, ui_left
, "marker-id", "ID");
3810 uiout
->table_header (3, ui_left
, "enabled", "Enb");
3811 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
3812 uiout
->table_header (10, ui_left
, "addr", "Address");
3814 uiout
->table_header (18, ui_left
, "addr", "Address");
3815 uiout
->table_header (40, ui_noalign
, "what", "What");
3817 uiout
->table_body ();
3819 for (int i
= 0; i
< markers
.size (); i
++)
3820 print_one_static_tracepoint_marker (i
+ 1, markers
[i
]);
3823 /* The $_sdata convenience variable is a bit special. We don't know
3824 for sure type of the value until we actually have a chance to fetch
3825 the data --- the size of the object depends on what has been
3826 collected. We solve this by making $_sdata be an internalvar that
3827 creates a new value on access. */
3829 /* Return a new value with the correct type for the sdata object of
3830 the current trace frame. Return a void value if there's no object
3833 static struct value
*
3834 sdata_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
3837 /* We need to read the whole object before we know its size. */
3838 gdb::optional
<gdb::byte_vector
> buf
3839 = target_read_alloc (current_top_target (), TARGET_OBJECT_STATIC_TRACE_DATA
,
3846 type
= init_vector_type (builtin_type (gdbarch
)->builtin_true_char
,
3848 v
= allocate_value (type
);
3849 memcpy (value_contents_raw (v
), buf
->data (), buf
->size ());
3853 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
3856 #if !defined(HAVE_LIBEXPAT)
3858 struct std::unique_ptr
<traceframe_info
>
3859 parse_traceframe_info (const char *tframe_info
)
3861 static int have_warned
;
3866 warning (_("Can not parse XML trace frame info; XML support "
3867 "was disabled at compile time"));
3873 #else /* HAVE_LIBEXPAT */
3875 #include "xml-support.h"
3877 /* Handle the start of a <memory> element. */
3880 traceframe_info_start_memory (struct gdb_xml_parser
*parser
,
3881 const struct gdb_xml_element
*element
,
3883 std::vector
<gdb_xml_value
> &attributes
)
3885 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
3886 ULONGEST
*start_p
, *length_p
;
3889 = (ULONGEST
*) xml_find_attribute (attributes
, "start")->value
.get ();
3891 = (ULONGEST
*) xml_find_attribute (attributes
, "length")->value
.get ();
3893 info
->memory
.emplace_back (*start_p
, *length_p
);
3896 /* Handle the start of a <tvar> element. */
3899 traceframe_info_start_tvar (struct gdb_xml_parser
*parser
,
3900 const struct gdb_xml_element
*element
,
3902 std::vector
<gdb_xml_value
> &attributes
)
3904 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
3905 const char *id_attrib
3906 = (const char *) xml_find_attribute (attributes
, "id")->value
.get ();
3907 int id
= gdb_xml_parse_ulongest (parser
, id_attrib
);
3909 info
->tvars
.push_back (id
);
3912 /* The allowed elements and attributes for an XML memory map. */
3914 static const struct gdb_xml_attribute memory_attributes
[] = {
3915 { "start", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
3916 { "length", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
3917 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3920 static const struct gdb_xml_attribute tvar_attributes
[] = {
3921 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3922 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3925 static const struct gdb_xml_element traceframe_info_children
[] = {
3926 { "memory", memory_attributes
, NULL
,
3927 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3928 traceframe_info_start_memory
, NULL
},
3929 { "tvar", tvar_attributes
, NULL
,
3930 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3931 traceframe_info_start_tvar
, NULL
},
3932 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3935 static const struct gdb_xml_element traceframe_info_elements
[] = {
3936 { "traceframe-info", NULL
, traceframe_info_children
, GDB_XML_EF_NONE
,
3938 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3941 /* Parse a traceframe-info XML document. */
3944 parse_traceframe_info (const char *tframe_info
)
3946 traceframe_info_up
result (new traceframe_info
);
3948 if (gdb_xml_parse_quick (_("trace frame info"),
3949 "traceframe-info.dtd", traceframe_info_elements
,
3950 tframe_info
, result
.get ()) == 0)
3956 #endif /* HAVE_LIBEXPAT */
3958 /* Returns the traceframe_info object for the current traceframe.
3959 This is where we avoid re-fetching the object from the target if we
3960 already have it cached. */
3962 struct traceframe_info
*
3963 get_traceframe_info (void)
3965 if (current_traceframe_info
== NULL
)
3966 current_traceframe_info
= target_traceframe_info ();
3968 return current_traceframe_info
.get ();
3971 /* If the target supports the query, return in RESULT the set of
3972 collected memory in the current traceframe, found within the LEN
3973 bytes range starting at MEMADDR. Returns true if the target
3974 supports the query, otherwise returns false, and RESULT is left
3978 traceframe_available_memory (std::vector
<mem_range
> *result
,
3979 CORE_ADDR memaddr
, ULONGEST len
)
3981 struct traceframe_info
*info
= get_traceframe_info ();
3987 for (mem_range
&r
: info
->memory
)
3988 if (mem_ranges_overlap (r
.start
, r
.length
, memaddr
, len
))
3990 ULONGEST lo1
, hi1
, lo2
, hi2
;
3993 hi1
= memaddr
+ len
;
3996 hi2
= r
.start
+ r
.length
;
3998 CORE_ADDR start
= std::max (lo1
, lo2
);
3999 int length
= std::min (hi1
, hi2
) - start
;
4001 result
->emplace_back (start
, length
);
4004 normalize_mem_ranges (result
);
4011 /* Implementation of `sdata' variable. */
4013 static const struct internalvar_funcs sdata_funcs
=
4020 /* See tracepoint.h. */
4021 cmd_list_element
*while_stepping_cmd_element
= nullptr;
4023 /* module initialization */
4024 void _initialize_tracepoint ();
4026 _initialize_tracepoint ()
4028 struct cmd_list_element
*c
;
4030 /* Explicitly create without lookup, since that tries to create a
4031 value with a void typed value, and when we get here, gdbarch
4032 isn't initialized yet. At this point, we're quite sure there
4033 isn't another convenience variable of the same name. */
4034 create_internalvar_type_lazy ("_sdata", &sdata_funcs
, NULL
);
4036 traceframe_number
= -1;
4037 tracepoint_number
= -1;
4039 add_info ("scope", info_scope_command
,
4040 _("List the variables local to a scope."));
4042 add_cmd ("tracepoints", class_trace
,
4043 _("Tracing of program execution without stopping the program."),
4046 add_com ("tdump", class_trace
, tdump_command
,
4047 _("Print everything collected at the current tracepoint."));
4049 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
4050 Define a trace state variable.\n\
4051 Argument is a $-prefixed name, optionally followed\n\
4052 by '=' and an expression that sets the initial value\n\
4053 at the start of tracing."));
4054 set_cmd_completer (c
, expression_completer
);
4056 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
4057 Delete one or more trace state variables.\n\
4058 Arguments are the names of the variables to delete.\n\
4059 If no arguments are supplied, delete all variables."), &deletelist
);
4060 /* FIXME add a trace variable completer. */
4062 add_info ("tvariables", info_tvariables_command
, _("\
4063 Status of trace state variables and their values."));
4065 add_info ("static-tracepoint-markers",
4066 info_static_tracepoint_markers_command
, _("\
4067 List target static tracepoints markers."));
4069 add_prefix_cmd ("tfind", class_trace
, tfind_command
, _("\
4070 Select a trace frame.\n\
4071 No argument means forward by one frame; '-' means backward by one frame."),
4072 &tfindlist
, "tfind ", 1, &cmdlist
);
4074 add_cmd ("outside", class_trace
, tfind_outside_command
, _("\
4075 Select a trace frame whose PC is outside the given range (exclusive).\n\
4076 Usage: tfind outside ADDR1, ADDR2"),
4079 add_cmd ("range", class_trace
, tfind_range_command
, _("\
4080 Select a trace frame whose PC is in the given range (inclusive).\n\
4081 Usage: tfind range ADDR1, ADDR2"),
4084 add_cmd ("line", class_trace
, tfind_line_command
, _("\
4085 Select a trace frame by source line.\n\
4086 Argument can be a line number (with optional source file),\n\
4087 a function name, or '*' followed by an address.\n\
4088 Default argument is 'the next source line that was traced'."),
4091 add_cmd ("tracepoint", class_trace
, tfind_tracepoint_command
, _("\
4092 Select a trace frame by tracepoint number.\n\
4093 Default is the tracepoint for the current trace frame."),
4096 add_cmd ("pc", class_trace
, tfind_pc_command
, _("\
4097 Select a trace frame by PC.\n\
4098 Default is the current PC, or the PC of the current trace frame."),
4101 add_cmd ("end", class_trace
, tfind_end_command
, _("\
4102 De-select any trace frame and resume 'live' debugging."),
4105 add_alias_cmd ("none", "end", class_trace
, 0, &tfindlist
);
4107 add_cmd ("start", class_trace
, tfind_start_command
,
4108 _("Select the first trace frame in the trace buffer."),
4111 add_com ("tstatus", class_trace
, tstatus_command
,
4112 _("Display the status of the current trace data collection."));
4114 add_com ("tstop", class_trace
, tstop_command
, _("\
4115 Stop trace data collection.\n\
4116 Usage: tstop [NOTES]...\n\
4117 Any arguments supplied are recorded with the trace as a stop reason and\n\
4118 reported by tstatus (if the target supports trace notes)."));
4120 add_com ("tstart", class_trace
, tstart_command
, _("\
4121 Start trace data collection.\n\
4122 Usage: tstart [NOTES]...\n\
4123 Any arguments supplied are recorded with the trace as a note and\n\
4124 reported by tstatus (if the target supports trace notes)."));
4126 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
4127 Ends a list of commands or actions.\n\
4128 Several GDB commands allow you to enter a list of commands or actions.\n\
4129 Entering \"end\" on a line by itself is the normal way to terminate\n\
4131 Note: the \"end\" command cannot be used at the gdb prompt."));
4133 while_stepping_cmd_element
= add_com ("while-stepping", class_trace
,
4134 while_stepping_pseudocommand
, _("\
4135 Specify single-stepping behavior at a tracepoint.\n\
4136 Argument is number of instructions to trace in single-step mode\n\
4137 following the tracepoint. This command is normally followed by\n\
4138 one or more \"collect\" commands, to specify what to collect\n\
4139 while single-stepping.\n\n\
4140 Note: this command can only be used in a tracepoint \"actions\" list."));
4142 add_com_alias ("ws", "while-stepping", class_trace
, 0);
4143 add_com_alias ("stepping", "while-stepping", class_trace
, 0);
4145 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
4146 Specify one or more data items to be collected at a tracepoint.\n\
4147 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4148 collect all data (variables, registers) referenced by that expression.\n\
4149 Also accepts the following special arguments:\n\
4150 $regs -- all registers.\n\
4151 $args -- all function arguments.\n\
4152 $locals -- all variables local to the block/function scope.\n\
4153 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
4154 Note: this command can only be used in a tracepoint \"actions\" list."));
4156 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
4157 Specify one or more expressions to be evaluated at a tracepoint.\n\
4158 Accepts a comma-separated list of (one or more) expressions.\n\
4159 The result of each evaluation will be discarded.\n\
4160 Note: this command can only be used in a tracepoint \"actions\" list."));
4162 add_com ("actions", class_trace
, actions_command
, _("\
4163 Specify the actions to be taken at a tracepoint.\n\
4164 Tracepoint actions may include collecting of specified data,\n\
4165 single-stepping, or enabling/disabling other tracepoints,\n\
4166 depending on target's capabilities."));
4168 default_collect
= xstrdup ("");
4169 add_setshow_string_cmd ("default-collect", class_trace
,
4170 &default_collect
, _("\
4171 Set the list of expressions to collect by default."), _("\
4172 Show the list of expressions to collect by default."), NULL
,
4174 &setlist
, &showlist
);
4176 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
4177 &disconnected_tracing
, _("\
4178 Set whether tracing continues after GDB disconnects."), _("\
4179 Show whether tracing continues after GDB disconnects."), _("\
4180 Use this to continue a tracing run even if GDB disconnects\n\
4181 or detaches from the target. You can reconnect later and look at\n\
4182 trace data collected in the meantime."),
4183 set_disconnected_tracing
,
4188 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
4189 &circular_trace_buffer
, _("\
4190 Set target's use of circular trace buffer."), _("\
4191 Show target's use of circular trace buffer."), _("\
4192 Use this to make the trace buffer into a circular buffer,\n\
4193 which will discard traceframes (oldest first) instead of filling\n\
4194 up and stopping the trace run."),
4195 set_circular_trace_buffer
,
4200 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class
,
4201 &trace_buffer_size
, _("\
4202 Set requested size of trace buffer."), _("\
4203 Show requested size of trace buffer."), _("\
4204 Use this to choose a size for the trace buffer. Some targets\n\
4205 may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
4206 disables any attempt to set the buffer size and lets the target choose."),
4207 set_trace_buffer_size
, NULL
,
4208 &setlist
, &showlist
);
4210 add_setshow_string_cmd ("trace-user", class_trace
,
4212 Set the user name to use for current and future trace runs."), _("\
4213 Show the user name to use for current and future trace runs."), NULL
,
4214 set_trace_user
, NULL
,
4215 &setlist
, &showlist
);
4217 add_setshow_string_cmd ("trace-notes", class_trace
,
4219 Set notes string to use for current and future trace runs."), _("\
4220 Show the notes string to use for current and future trace runs."), NULL
,
4221 set_trace_notes
, NULL
,
4222 &setlist
, &showlist
);
4224 add_setshow_string_cmd ("trace-stop-notes", class_trace
,
4225 &trace_stop_notes
, _("\
4226 Set notes string to use for future tstop commands."), _("\
4227 Show the notes string to use for future tstop commands."), NULL
,
4228 set_trace_stop_notes
, NULL
,
4229 &setlist
, &showlist
);