1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997-2019 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"
63 /* Maximum length of an agent aexpression.
64 This accounts for the fact that packets are limited to 400 bytes
65 (which includes everything -- including the checksum), and assumes
66 the worst case of maximum length for each of the pieces of a
69 NOTE: expressions get mem2hex'ed otherwise this would be twice as
70 large. (400 - 31)/2 == 184 */
71 #define MAX_AGENT_EXPR_LEN 184
73 /* A hook used to notify the UI of tracepoint operations. */
75 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
76 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
81 This module defines the following debugger commands:
82 trace : set a tracepoint on a function, line, or address.
83 info trace : list all debugger-defined tracepoints.
84 delete trace : delete one or more tracepoints.
85 enable trace : enable one or more tracepoints.
86 disable trace : disable one or more tracepoints.
87 actions : specify actions to be taken at a tracepoint.
88 passcount : specify a pass count for a tracepoint.
89 tstart : start a trace experiment.
90 tstop : stop a trace experiment.
91 tstatus : query the status of a trace experiment.
92 tfind : find a trace frame in the trace buffer.
93 tdump : print everything collected at the current tracepoint.
94 save-tracepoints : write tracepoint setup into a file.
96 This module defines the following user-visible debugger variables:
97 $trace_frame : sequence number of trace frame currently being debugged.
98 $trace_line : source line of trace frame currently being debugged.
99 $trace_file : source file of trace frame currently being debugged.
100 $tracepoint : tracepoint number of trace frame currently being debugged.
104 /* ======= Important global variables: ======= */
106 /* The list of all trace state variables. We don't retain pointers to
107 any of these for any reason - API is by name or number only - so it
108 works to have a vector of objects. */
110 static std::vector
<trace_state_variable
> tvariables
;
112 /* The next integer to assign to a variable. */
114 static int next_tsv_number
= 1;
116 /* Number of last traceframe collected. */
117 static int traceframe_number
;
119 /* Tracepoint for last traceframe collected. */
120 static int tracepoint_number
;
122 /* The traceframe info of the current traceframe. NULL if we haven't
123 yet attempted to fetch it, or if the target does not support
124 fetching this object, or if we're not inspecting a traceframe
126 static traceframe_info_up current_traceframe_info
;
128 /* Tracing command lists. */
129 static struct cmd_list_element
*tfindlist
;
131 /* List of expressions to collect by default at each tracepoint hit. */
132 char *default_collect
;
134 static bool disconnected_tracing
;
136 /* This variable controls whether we ask the target for a linear or
137 circular trace buffer. */
139 static bool circular_trace_buffer
;
141 /* This variable is the requested trace buffer size, or -1 to indicate
142 that we don't care and leave it up to the target to set a size. */
144 static int trace_buffer_size
= -1;
146 /* Textual notes applying to the current and/or future trace runs. */
148 char *trace_user
= NULL
;
150 /* Textual notes applying to the current and/or future trace runs. */
152 char *trace_notes
= NULL
;
154 /* Textual notes applying to the stopping of a trace. */
156 char *trace_stop_notes
= NULL
;
158 /* support routines */
160 struct collection_list
;
161 static char *mem2hex (gdb_byte
*, char *, int);
163 static counted_command_line
all_tracepoint_actions (struct breakpoint
*);
165 static struct trace_status trace_status
;
167 const char *stop_reason_names
[] = {
177 struct trace_status
*
178 current_trace_status (void)
180 return &trace_status
;
183 /* Free and clear the traceframe info cache of the current
187 clear_traceframe_info (void)
189 current_traceframe_info
= NULL
;
192 /* Set traceframe number to NUM. */
194 set_traceframe_num (int num
)
196 traceframe_number
= num
;
197 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
200 /* Set tracepoint number to NUM. */
202 set_tracepoint_num (int num
)
204 tracepoint_number
= num
;
205 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
208 /* Set externally visible debug variables for querying/printing
209 the traceframe context (line, function, file). */
212 set_traceframe_context (struct frame_info
*trace_frame
)
215 struct symbol
*traceframe_fun
;
216 symtab_and_line traceframe_sal
;
218 /* Save as globals for internal use. */
219 if (trace_frame
!= NULL
220 && get_frame_pc_if_available (trace_frame
, &trace_pc
))
222 traceframe_sal
= find_pc_line (trace_pc
, 0);
223 traceframe_fun
= find_pc_function (trace_pc
);
225 /* Save linenumber as "$trace_line", a debugger variable visible to
227 set_internalvar_integer (lookup_internalvar ("trace_line"),
228 traceframe_sal
.line
);
232 traceframe_fun
= NULL
;
233 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
236 /* Save func name as "$trace_func", a debugger variable visible to
238 if (traceframe_fun
== NULL
239 || traceframe_fun
->linkage_name () == NULL
)
240 clear_internalvar (lookup_internalvar ("trace_func"));
242 set_internalvar_string (lookup_internalvar ("trace_func"),
243 traceframe_fun
->linkage_name ());
245 /* Save file name as "$trace_file", a debugger variable visible to
247 if (traceframe_sal
.symtab
== NULL
)
248 clear_internalvar (lookup_internalvar ("trace_file"));
250 set_internalvar_string (lookup_internalvar ("trace_file"),
251 symtab_to_filename_for_display (traceframe_sal
.symtab
));
254 /* Create a new trace state variable with the given name. */
256 struct trace_state_variable
*
257 create_trace_state_variable (const char *name
)
259 tvariables
.emplace_back (name
, next_tsv_number
++);
260 return &tvariables
.back ();
263 /* Look for a trace state variable of the given name. */
265 struct trace_state_variable
*
266 find_trace_state_variable (const char *name
)
268 for (trace_state_variable
&tsv
: tvariables
)
269 if (tsv
.name
== name
)
275 /* Look for a trace state variable of the given number. Return NULL if
278 struct trace_state_variable
*
279 find_trace_state_variable_by_number (int number
)
281 for (trace_state_variable
&tsv
: tvariables
)
282 if (tsv
.number
== number
)
289 delete_trace_state_variable (const char *name
)
291 for (auto it
= tvariables
.begin (); it
!= tvariables
.end (); it
++)
292 if (it
->name
== name
)
294 gdb::observers::tsv_deleted
.notify (&*it
);
295 tvariables
.erase (it
);
299 warning (_("No trace variable named \"$%s\", not deleting"), name
);
302 /* Throws an error if NAME is not valid syntax for a trace state
306 validate_trace_state_variable_name (const char *name
)
311 error (_("Must supply a non-empty variable name"));
313 /* All digits in the name is reserved for value history
315 for (p
= name
; isdigit (*p
); p
++)
318 error (_("$%s is not a valid trace state variable name"), name
);
320 for (p
= name
; isalnum (*p
) || *p
== '_'; p
++)
323 error (_("$%s is not a valid trace state variable name"), name
);
326 /* The 'tvariable' command collects a name and optional expression to
327 evaluate into an initial value. */
330 trace_variable_command (const char *args
, int from_tty
)
333 struct trace_state_variable
*tsv
;
334 const char *name_start
, *p
;
337 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
339 /* Only allow two syntaxes; "$name" and "$name=value". */
340 p
= skip_spaces (args
);
343 error (_("Name of trace variable should start with '$'"));
346 while (isalnum (*p
) || *p
== '_')
348 std::string
name (name_start
, p
- name_start
);
351 if (*p
!= '=' && *p
!= '\0')
352 error (_("Syntax must be $NAME [ = EXPR ]"));
354 validate_trace_state_variable_name (name
.c_str ());
357 initval
= value_as_long (parse_and_eval (++p
));
359 /* If the variable already exists, just change its initial value. */
360 tsv
= find_trace_state_variable (name
.c_str ());
363 if (tsv
->initial_value
!= initval
)
365 tsv
->initial_value
= initval
;
366 gdb::observers::tsv_modified
.notify (tsv
);
368 printf_filtered (_("Trace state variable $%s "
369 "now has initial value %s.\n"),
370 tsv
->name
.c_str (), plongest (tsv
->initial_value
));
374 /* Create a new variable. */
375 tsv
= create_trace_state_variable (name
.c_str ());
376 tsv
->initial_value
= initval
;
378 gdb::observers::tsv_created
.notify (tsv
);
380 printf_filtered (_("Trace state variable $%s "
381 "created, with initial value %s.\n"),
382 tsv
->name
.c_str (), plongest (tsv
->initial_value
));
386 delete_trace_variable_command (const char *args
, int from_tty
)
390 if (query (_("Delete all trace state variables? ")))
393 gdb::observers::tsv_deleted
.notify (NULL
);
397 gdb_argv
argv (args
);
399 for (char *arg
: argv
)
402 delete_trace_state_variable (arg
+ 1);
404 warning (_("Name \"%s\" not prefixed with '$', ignoring"), arg
);
411 tvariables_info_1 (void)
413 struct ui_out
*uiout
= current_uiout
;
415 /* Try to acquire values from the target. */
416 for (trace_state_variable
&tsv
: tvariables
)
418 = target_get_trace_state_variable_value (tsv
.number
, &tsv
.value
);
421 ui_out_emit_table
table_emitter (uiout
, 3, tvariables
.size (),
423 uiout
->table_header (15, ui_left
, "name", "Name");
424 uiout
->table_header (11, ui_left
, "initial", "Initial");
425 uiout
->table_header (11, ui_left
, "current", "Current");
427 uiout
->table_body ();
429 for (const trace_state_variable
&tsv
: tvariables
)
433 ui_out_emit_tuple
tuple_emitter (uiout
, "variable");
435 uiout
->field_string ("name", std::string ("$") + tsv
.name
);
436 uiout
->field_string ("initial", plongest (tsv
.initial_value
));
440 c
= plongest (tsv
.value
);
441 else if (uiout
->is_mi_like_p ())
442 /* For MI, we prefer not to use magic string constants, but rather
443 omit the field completely. The difference between unknown and
444 undefined does not seem important enough to represent. */
446 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
448 /* The value is/was defined, but we don't have it. */
450 style
= metadata_style
.style ();
454 /* It is not meaningful to ask about the value. */
456 style
= metadata_style
.style ();
459 uiout
->field_string ("current", c
, style
);
464 if (tvariables
.empty ())
465 uiout
->text (_("No trace state variables.\n"));
468 /* List all the trace state variables. */
471 info_tvariables_command (const char *args
, int from_tty
)
473 tvariables_info_1 ();
476 /* Stash definitions of tsvs into the given file. */
479 save_trace_state_variables (struct ui_file
*fp
)
481 for (const trace_state_variable
&tsv
: tvariables
)
483 fprintf_unfiltered (fp
, "tvariable $%s", tsv
.name
.c_str ());
484 if (tsv
.initial_value
)
485 fprintf_unfiltered (fp
, " = %s", plongest (tsv
.initial_value
));
486 fprintf_unfiltered (fp
, "\n");
490 /* ACTIONS functions: */
492 /* The three functions:
493 collect_pseudocommand,
494 while_stepping_pseudocommand, and
495 end_actions_pseudocommand
496 are placeholders for "commands" that are actually ONLY to be used
497 within a tracepoint action list. If the actual function is ever called,
498 it means that somebody issued the "command" at the top level,
499 which is always an error. */
502 end_actions_pseudocommand (const char *args
, int from_tty
)
504 error (_("This command cannot be used at the top level."));
508 while_stepping_pseudocommand (const char *args
, int from_tty
)
510 error (_("This command can only be used in a tracepoint actions list."));
514 collect_pseudocommand (const char *args
, int from_tty
)
516 error (_("This command can only be used in a tracepoint actions list."));
520 teval_pseudocommand (const char *args
, int from_tty
)
522 error (_("This command can only be used in a tracepoint actions list."));
525 /* Parse any collection options, such as /s for strings. */
528 decode_agent_options (const char *exp
, int *trace_string
)
530 struct value_print_options opts
;
537 /* Call this to borrow the print elements default for collection
539 get_user_print_options (&opts
);
544 if (target_supports_string_tracing ())
546 /* Allow an optional decimal number giving an explicit maximum
547 string length, defaulting it to the "print elements" value;
548 so "collect/s80 mystr" gets at most 80 bytes of string. */
549 *trace_string
= opts
.print_max
;
551 if (*exp
>= '0' && *exp
<= '9')
552 *trace_string
= atoi (exp
);
553 while (*exp
>= '0' && *exp
<= '9')
557 error (_("Target does not support \"/s\" option for string tracing."));
560 error (_("Undefined collection format \"%c\"."), *exp
);
562 exp
= skip_spaces (exp
);
567 /* Enter a list of actions for a tracepoint. */
569 actions_command (const char *args
, int from_tty
)
571 struct tracepoint
*t
;
573 t
= get_tracepoint_by_number (&args
, NULL
);
577 string_printf ("Enter actions for tracepoint %d, one per line.",
580 counted_command_line l
= read_command_lines (tmpbuf
.c_str (),
582 [=] (const char *line
)
584 validate_actionline (line
, t
);
586 breakpoint_set_commands (t
, std::move (l
));
588 /* else just return */
591 /* Report the results of checking the agent expression, as errors or
595 report_agent_reqs_errors (struct agent_expr
*aexpr
)
597 /* All of the "flaws" are serious bytecode generation issues that
598 should never occur. */
599 if (aexpr
->flaw
!= agent_flaw_none
)
600 internal_error (__FILE__
, __LINE__
, _("expression is malformed"));
602 /* If analysis shows a stack underflow, GDB must have done something
603 badly wrong in its bytecode generation. */
604 if (aexpr
->min_height
< 0)
605 internal_error (__FILE__
, __LINE__
,
606 _("expression has min height < 0"));
608 /* Issue this error if the stack is predicted to get too deep. The
609 limit is rather arbitrary; a better scheme might be for the
610 target to report how much stack it will have available. The
611 depth roughly corresponds to parenthesization, so a limit of 20
612 amounts to 20 levels of expression nesting, which is actually
613 a pretty big hairy expression. */
614 if (aexpr
->max_height
> 20)
615 error (_("Expression is too complicated."));
618 /* Call ax_reqs on AEXPR and raise an error if something is wrong. */
621 finalize_tracepoint_aexpr (struct agent_expr
*aexpr
)
625 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
626 error (_("Expression is too complicated."));
628 report_agent_reqs_errors (aexpr
);
631 /* worker function */
633 validate_actionline (const char *line
, struct breakpoint
*b
)
635 struct cmd_list_element
*c
;
638 struct bp_location
*loc
;
639 struct tracepoint
*t
= (struct tracepoint
*) b
;
641 /* If EOF is typed, *line is NULL. */
645 p
= skip_spaces (line
);
647 /* Symbol lookup etc. */
648 if (*p
== '\0') /* empty line: just prompt for another line. */
651 if (*p
== '#') /* comment line */
654 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
656 error (_("`%s' is not a tracepoint action, or is ambiguous."), p
);
658 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
660 int trace_string
= 0;
663 p
= decode_agent_options (p
, &trace_string
);
666 { /* Repeat over a comma-separated list. */
667 QUIT
; /* Allow user to bail out with ^C. */
670 if (*p
== '$') /* Look for special pseudo-symbols. */
672 if (0 == strncasecmp ("reg", p
+ 1, 3)
673 || 0 == strncasecmp ("arg", p
+ 1, 3)
674 || 0 == strncasecmp ("loc", p
+ 1, 3)
675 || 0 == strncasecmp ("_ret", p
+ 1, 4)
676 || 0 == strncasecmp ("_sdata", p
+ 1, 6))
681 /* else fall thru, treat p as an expression and parse it! */
684 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
687 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
688 block_for_pc (loc
->address
), 1);
690 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
692 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
694 error (_("constant `%s' (value %s) "
695 "will not be collected."),
696 exp
->elts
[2].symbol
->print_name (),
697 plongest (SYMBOL_VALUE (exp
->elts
[2].symbol
)));
699 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
)
700 == LOC_OPTIMIZED_OUT
)
702 error (_("`%s' is optimized away "
703 "and cannot be collected."),
704 exp
->elts
[2].symbol
->print_name ());
708 /* We have something to collect, make sure that the expr to
709 bytecode translator can handle it and that it's not too
711 agent_expr_up aexpr
= gen_trace_for_expr (loc
->address
,
715 finalize_tracepoint_aexpr (aexpr
.get ());
718 while (p
&& *p
++ == ',');
721 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
724 { /* Repeat over a comma-separated list. */
725 QUIT
; /* Allow user to bail out with ^C. */
729 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
733 /* Only expressions are allowed for this action. */
734 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
735 block_for_pc (loc
->address
), 1);
737 /* We have something to evaluate, make sure that the expr to
738 bytecode translator can handle it and that it's not too
740 agent_expr_up aexpr
= gen_eval_for_expr (loc
->address
, exp
.get ());
742 finalize_tracepoint_aexpr (aexpr
.get ());
745 while (p
&& *p
++ == ',');
748 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
753 t
->step_count
= strtol (p
, &endp
, 0);
754 if (endp
== p
|| t
->step_count
== 0)
755 error (_("while-stepping step count `%s' is malformed."), line
);
759 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
763 error (_("`%s' is not a supported tracepoint action."), line
);
767 memrange_absolute
= -1
770 /* MEMRANGE functions: */
772 /* Compare memranges for std::sort. */
775 memrange_comp (const memrange
&a
, const memrange
&b
)
777 if (a
.type
== b
.type
)
779 if (a
.type
== memrange_absolute
)
780 return (bfd_vma
) a
.start
< (bfd_vma
) b
.start
;
782 return a
.start
< b
.start
;
785 return a
.type
< b
.type
;
788 /* Sort the memrange list using std::sort, and merge adjacent memranges. */
791 memrange_sortmerge (std::vector
<memrange
> &memranges
)
793 if (!memranges
.empty ())
797 std::sort (memranges
.begin (), memranges
.end (), memrange_comp
);
799 for (a
= 0, b
= 1; b
< memranges
.size (); b
++)
801 /* If memrange b overlaps or is adjacent to memrange a,
803 if (memranges
[a
].type
== memranges
[b
].type
804 && memranges
[b
].start
<= memranges
[a
].end
)
806 if (memranges
[b
].end
> memranges
[a
].end
)
807 memranges
[a
].end
= memranges
[b
].end
;
808 continue; /* next b, same a */
812 memranges
[a
] = memranges
[b
];
814 memranges
.resize (a
+ 1);
818 /* Add remote register number REGNO to the collection list mask. */
821 collection_list::add_remote_register (unsigned int regno
)
824 printf_filtered ("collect register %d\n", regno
);
826 m_regs_mask
.at (regno
/ 8) |= 1 << (regno
% 8);
829 /* Add all the registers from the mask in AEXPR to the mask in the
830 collection list. Registers in the AEXPR mask are already remote
834 collection_list::add_ax_registers (struct agent_expr
*aexpr
)
836 if (aexpr
->reg_mask_len
> 0)
838 for (int ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
840 QUIT
; /* Allow user to bail out with ^C. */
841 if (aexpr
->reg_mask
[ndx1
] != 0)
843 /* Assume chars have 8 bits. */
844 for (int ndx2
= 0; ndx2
< 8; ndx2
++)
845 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
846 /* It's used -- record it. */
847 add_remote_register (ndx1
* 8 + ndx2
);
853 /* If REGNO is raw, add its corresponding remote register number to
854 the mask. If REGNO is a pseudo-register, figure out the necessary
855 registers using a temporary agent expression, and add it to the
856 list if it needs more than just a mask. */
859 collection_list::add_local_register (struct gdbarch
*gdbarch
,
863 if (regno
< gdbarch_num_regs (gdbarch
))
865 int remote_regno
= gdbarch_remote_register_number (gdbarch
, regno
);
867 if (remote_regno
< 0)
868 error (_("Can't collect register %d"), regno
);
870 add_remote_register (remote_regno
);
874 agent_expr_up
aexpr (new agent_expr (gdbarch
, scope
));
876 ax_reg_mask (aexpr
.get (), regno
);
878 finalize_tracepoint_aexpr (aexpr
.get ());
880 add_ax_registers (aexpr
.get ());
882 /* Usually ax_reg_mask for a pseudo-regiser only sets the
883 corresponding raw registers in the ax mask, but if this isn't
884 the case add the expression that is generated to the
887 add_aexpr (std::move (aexpr
));
891 /* Add a memrange to a collection list. */
894 collection_list::add_memrange (struct gdbarch
*gdbarch
,
895 int type
, bfd_signed_vma base
,
896 unsigned long len
, CORE_ADDR scope
)
899 printf_filtered ("(%d,%s,%ld)\n", type
, paddress (gdbarch
, base
), len
);
901 /* type: memrange_absolute == memory, other n == basereg */
902 /* base: addr if memory, offset if reg relative. */
903 /* len: we actually save end (base + len) for convenience */
904 m_memranges
.emplace_back (type
, base
, base
+ len
);
906 if (type
!= memrange_absolute
) /* Better collect the base register! */
907 add_local_register (gdbarch
, type
, scope
);
910 /* Add a symbol to a collection list. */
913 collection_list::collect_symbol (struct symbol
*sym
,
914 struct gdbarch
*gdbarch
,
915 long frame_regno
, long frame_offset
,
921 bfd_signed_vma offset
;
922 int treat_as_expr
= 0;
924 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
925 switch (SYMBOL_CLASS (sym
))
928 printf_filtered ("%s: don't know symbol class %d\n",
929 sym
->print_name (), SYMBOL_CLASS (sym
));
932 printf_filtered ("constant %s (value %s) will not be collected.\n",
933 sym
->print_name (), plongest (SYMBOL_VALUE (sym
)));
936 offset
= SYMBOL_VALUE_ADDRESS (sym
);
939 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
940 sym
->print_name (), len
,
941 paddress (gdbarch
, offset
));
943 /* A struct may be a C++ class with static fields, go to general
944 expression handling. */
945 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
948 add_memrange (gdbarch
, memrange_absolute
, offset
, len
, scope
);
951 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
953 printf_filtered ("LOC_REG[parm] %s: ", sym
->print_name ());
954 add_local_register (gdbarch
, reg
, scope
);
955 /* Check for doubles stored in two registers. */
956 /* FIXME: how about larger types stored in 3 or more regs? */
957 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
958 len
> register_size (gdbarch
, reg
))
959 add_local_register (gdbarch
, reg
+ 1, scope
);
962 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
963 printf_filtered (" (will not collect %s)\n", sym
->print_name ());
967 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
970 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
971 " from frame ptr reg %d\n", sym
->print_name (), len
,
972 paddress (gdbarch
, offset
), reg
);
974 add_memrange (gdbarch
, reg
, offset
, len
, scope
);
976 case LOC_REGPARM_ADDR
:
977 reg
= SYMBOL_VALUE (sym
);
981 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset %s"
982 " from reg %d\n", sym
->print_name (), len
,
983 paddress (gdbarch
, offset
), reg
);
985 add_memrange (gdbarch
, reg
, offset
, len
, scope
);
989 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
992 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
993 " from frame ptr reg %d\n", sym
->print_name (), len
,
994 paddress (gdbarch
, offset
), reg
);
996 add_memrange (gdbarch
, reg
, offset
, len
, scope
);
1003 case LOC_OPTIMIZED_OUT
:
1004 printf_filtered ("%s has been optimized out of existence.\n",
1005 sym
->print_name ());
1013 /* Expressions are the most general case. */
1016 agent_expr_up aexpr
= gen_trace_for_var (scope
, gdbarch
,
1019 /* It can happen that the symbol is recorded as a computed
1020 location, but it's been optimized away and doesn't actually
1021 have a location expression. */
1024 printf_filtered ("%s has been optimized out of existence.\n",
1025 sym
->print_name ());
1029 finalize_tracepoint_aexpr (aexpr
.get ());
1031 /* Take care of the registers. */
1032 add_ax_registers (aexpr
.get ());
1034 add_aexpr (std::move (aexpr
));
1038 /* Data to be passed around in the calls to the locals and args
1041 struct add_local_symbols_data
1043 struct collection_list
*collect
;
1044 struct gdbarch
*gdbarch
;
1052 /* The callback for the locals and args iterators. */
1055 do_collect_symbol (const char *print_name
,
1059 struct add_local_symbols_data
*p
= (struct add_local_symbols_data
*) cb_data
;
1061 p
->collect
->collect_symbol (sym
, p
->gdbarch
, p
->frame_regno
,
1062 p
->frame_offset
, p
->pc
, p
->trace_string
);
1065 p
->collect
->add_wholly_collected (print_name
);
1069 collection_list::add_wholly_collected (const char *print_name
)
1071 m_wholly_collected
.push_back (print_name
);
1074 /* Add all locals (or args) symbols to collection list. */
1077 collection_list::add_local_symbols (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1078 long frame_regno
, long frame_offset
, int type
,
1081 const struct block
*block
;
1082 struct add_local_symbols_data cb_data
;
1084 cb_data
.collect
= this;
1085 cb_data
.gdbarch
= gdbarch
;
1087 cb_data
.frame_regno
= frame_regno
;
1088 cb_data
.frame_offset
= frame_offset
;
1090 cb_data
.trace_string
= trace_string
;
1094 block
= block_for_pc (pc
);
1097 warning (_("Can't collect locals; "
1098 "no symbol table info available.\n"));
1102 iterate_over_block_local_vars (block
, do_collect_symbol
, &cb_data
);
1103 if (cb_data
.count
== 0)
1104 warning (_("No locals found in scope."));
1108 pc
= get_pc_function_start (pc
);
1109 block
= block_for_pc (pc
);
1112 warning (_("Can't collect args; no symbol table info available."));
1116 iterate_over_block_arg_vars (block
, do_collect_symbol
, &cb_data
);
1117 if (cb_data
.count
== 0)
1118 warning (_("No args found in scope."));
1123 collection_list::add_static_trace_data ()
1126 printf_filtered ("collect static trace data\n");
1127 m_strace_data
= true;
1130 collection_list::collection_list ()
1131 : m_strace_data (false)
1133 int max_remote_regno
= 0;
1134 for (int i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
1136 int remote_regno
= (gdbarch_remote_register_number
1137 (target_gdbarch (), i
));
1139 if (remote_regno
>= 0 && remote_regno
> max_remote_regno
)
1140 max_remote_regno
= remote_regno
;
1143 m_regs_mask
.resize ((max_remote_regno
/ 8) + 1);
1145 m_memranges
.reserve (128);
1146 m_aexprs
.reserve (128);
1149 /* Reduce a collection list to string form (for gdb protocol). */
1151 std::vector
<std::string
>
1152 collection_list::stringify ()
1154 gdb::char_vector
temp_buf (2048);
1159 std::vector
<std::string
> str_list
;
1164 printf_filtered ("\nCollecting static trace data\n");
1165 end
= temp_buf
.data ();
1167 str_list
.emplace_back (temp_buf
.data (), end
- temp_buf
.data ());
1170 for (i
= m_regs_mask
.size () - 1; i
> 0; i
--)
1171 if (m_regs_mask
[i
] != 0) /* Skip leading zeroes in regs_mask. */
1173 if (m_regs_mask
[i
] != 0) /* Prepare to send regs_mask to the stub. */
1176 printf_filtered ("\nCollecting registers (mask): 0x");
1178 /* One char for 'R', one for the null terminator and two per
1180 std::size_t new_size
= (i
+ 1) * 2 + 2;
1181 if (new_size
> temp_buf
.size ())
1182 temp_buf
.resize (new_size
);
1184 end
= temp_buf
.data ();
1188 QUIT
; /* Allow user to bail out with ^C. */
1190 printf_filtered ("%02X", m_regs_mask
[i
]);
1192 end
= pack_hex_byte (end
, m_regs_mask
[i
]);
1196 str_list
.emplace_back (temp_buf
.data ());
1199 printf_filtered ("\n");
1200 if (!m_memranges
.empty () && info_verbose
)
1201 printf_filtered ("Collecting memranges: \n");
1202 for (i
= 0, count
= 0, end
= temp_buf
.data ();
1203 i
< m_memranges
.size (); i
++)
1205 QUIT
; /* Allow user to bail out with ^C. */
1208 printf_filtered ("(%d, %s, %ld)\n",
1209 m_memranges
[i
].type
,
1210 paddress (target_gdbarch (),
1211 m_memranges
[i
].start
),
1212 (long) (m_memranges
[i
].end
1213 - m_memranges
[i
].start
));
1215 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1217 str_list
.emplace_back (temp_buf
.data (), count
);
1219 end
= temp_buf
.data ();
1223 bfd_signed_vma length
1224 = m_memranges
[i
].end
- m_memranges
[i
].start
;
1226 /* The "%X" conversion specifier expects an unsigned argument,
1227 so passing -1 (memrange_absolute) to it directly gives you
1228 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1230 if (m_memranges
[i
].type
== memrange_absolute
)
1231 sprintf (end
, "M-1,%s,%lX", phex_nz (m_memranges
[i
].start
, 0),
1234 sprintf (end
, "M%X,%s,%lX", m_memranges
[i
].type
,
1235 phex_nz (m_memranges
[i
].start
, 0), (long) length
);
1238 count
+= strlen (end
);
1239 end
= temp_buf
.data () + count
;
1242 for (i
= 0; i
< m_aexprs
.size (); i
++)
1244 QUIT
; /* Allow user to bail out with ^C. */
1245 if ((count
+ 10 + 2 * m_aexprs
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1247 str_list
.emplace_back (temp_buf
.data (), count
);
1249 end
= temp_buf
.data ();
1251 sprintf (end
, "X%08X,", m_aexprs
[i
]->len
);
1252 end
+= 10; /* 'X' + 8 hex digits + ',' */
1255 end
= mem2hex (m_aexprs
[i
]->buf
, end
, m_aexprs
[i
]->len
);
1256 count
+= 2 * m_aexprs
[i
]->len
;
1261 str_list
.emplace_back (temp_buf
.data (), count
);
1263 end
= temp_buf
.data ();
1269 /* Add the printed expression EXP to *LIST. */
1272 collection_list::append_exp (struct expression
*exp
)
1274 string_file tmp_stream
;
1276 print_expression (exp
, &tmp_stream
);
1278 m_computed
.push_back (std::move (tmp_stream
.string ()));
1282 collection_list::finish ()
1284 memrange_sortmerge (m_memranges
);
1288 encode_actions_1 (struct command_line
*action
,
1289 struct bp_location
*tloc
,
1291 LONGEST frame_offset
,
1292 struct collection_list
*collect
,
1293 struct collection_list
*stepping_list
)
1295 const char *action_exp
;
1297 struct value
*tempval
;
1298 struct cmd_list_element
*cmd
;
1300 for (; action
; action
= action
->next
)
1302 QUIT
; /* Allow user to bail out with ^C. */
1303 action_exp
= action
->line
;
1304 action_exp
= skip_spaces (action_exp
);
1306 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1308 error (_("Bad action list item: %s"), action_exp
);
1310 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1312 int trace_string
= 0;
1314 if (*action_exp
== '/')
1315 action_exp
= decode_agent_options (action_exp
, &trace_string
);
1318 { /* Repeat over a comma-separated list. */
1319 QUIT
; /* Allow user to bail out with ^C. */
1320 action_exp
= skip_spaces (action_exp
);
1322 if (0 == strncasecmp ("$reg", action_exp
, 4))
1324 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ());
1327 int remote_regno
= (gdbarch_remote_register_number
1328 (target_gdbarch (), i
));
1330 /* Ignore arch regnos without a corresponding
1331 remote regno. This can happen for regnos not
1333 if (remote_regno
>= 0)
1334 collect
->add_remote_register (remote_regno
);
1336 action_exp
= strchr (action_exp
, ','); /* more? */
1338 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1340 collect
->add_local_symbols (target_gdbarch (),
1346 action_exp
= strchr (action_exp
, ','); /* more? */
1348 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1350 collect
->add_local_symbols (target_gdbarch (),
1356 action_exp
= strchr (action_exp
, ','); /* more? */
1358 else if (0 == strncasecmp ("$_ret", action_exp
, 5))
1361 = gen_trace_for_return_address (tloc
->address
,
1365 finalize_tracepoint_aexpr (aexpr
.get ());
1367 /* take care of the registers */
1368 collect
->add_ax_registers (aexpr
.get ());
1370 collect
->add_aexpr (std::move (aexpr
));
1371 action_exp
= strchr (action_exp
, ','); /* more? */
1373 else if (0 == strncasecmp ("$_sdata", action_exp
, 7))
1375 collect
->add_static_trace_data ();
1376 action_exp
= strchr (action_exp
, ','); /* more? */
1382 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1383 block_for_pc (tloc
->address
),
1386 switch (exp
->elts
[0].opcode
)
1390 const char *name
= &exp
->elts
[2].string
;
1392 i
= user_reg_map_name_to_regnum (target_gdbarch (),
1393 name
, strlen (name
));
1395 internal_error (__FILE__
, __LINE__
,
1396 _("Register $%s not available"),
1399 printf_filtered ("OP_REGISTER: ");
1400 collect
->add_local_register (target_gdbarch (),
1406 /* Safe because we know it's a simple expression. */
1407 tempval
= evaluate_expression (exp
.get ());
1408 addr
= value_address (tempval
);
1409 /* Initialize the TYPE_LENGTH if it is a typedef. */
1410 check_typedef (exp
->elts
[1].type
);
1411 collect
->add_memrange (target_gdbarch (),
1412 memrange_absolute
, addr
,
1413 TYPE_LENGTH (exp
->elts
[1].type
),
1415 collect
->append_exp (exp
.get ());
1420 struct symbol
*sym
= exp
->elts
[2].symbol
;
1421 const char *name
= sym
->natural_name ();
1423 collect
->collect_symbol (exp
->elts
[2].symbol
,
1429 collect
->add_wholly_collected (name
);
1433 default: /* Full-fledged expression. */
1434 agent_expr_up aexpr
= gen_trace_for_expr (tloc
->address
,
1438 finalize_tracepoint_aexpr (aexpr
.get ());
1440 /* Take care of the registers. */
1441 collect
->add_ax_registers (aexpr
.get ());
1443 collect
->add_aexpr (std::move (aexpr
));
1444 collect
->append_exp (exp
.get ());
1449 while (action_exp
&& *action_exp
++ == ',');
1451 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1454 { /* Repeat over a comma-separated list. */
1455 QUIT
; /* Allow user to bail out with ^C. */
1456 action_exp
= skip_spaces (action_exp
);
1459 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1460 block_for_pc (tloc
->address
),
1463 agent_expr_up aexpr
= gen_eval_for_expr (tloc
->address
,
1466 finalize_tracepoint_aexpr (aexpr
.get ());
1468 /* Even though we're not officially collecting, add
1469 to the collect list anyway. */
1470 collect
->add_aexpr (std::move (aexpr
));
1473 while (action_exp
&& *action_exp
++ == ',');
1475 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1477 /* We check against nested while-stepping when setting
1478 breakpoint action, so no way to run into nested
1480 gdb_assert (stepping_list
);
1482 encode_actions_1 (action
->body_list_0
.get (), tloc
, frame_reg
,
1483 frame_offset
, stepping_list
, NULL
);
1486 error (_("Invalid tracepoint command '%s'"), action
->line
);
1490 /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST
1491 and STEPPING_LIST. */
1494 encode_actions (struct bp_location
*tloc
,
1495 struct collection_list
*tracepoint_list
,
1496 struct collection_list
*stepping_list
)
1499 LONGEST frame_offset
;
1501 gdbarch_virtual_frame_pointer (tloc
->gdbarch
,
1502 tloc
->address
, &frame_reg
, &frame_offset
);
1504 counted_command_line actions
= all_tracepoint_actions (tloc
->owner
);
1505 encode_actions_1 (actions
.get (), tloc
, frame_reg
, frame_offset
,
1506 tracepoint_list
, stepping_list
);
1507 encode_actions_1 (breakpoint_commands (tloc
->owner
), tloc
,
1508 frame_reg
, frame_offset
, tracepoint_list
, stepping_list
);
1510 tracepoint_list
->finish ();
1511 stepping_list
->finish ();
1514 /* Render all actions into gdb protocol. */
1517 encode_actions_rsp (struct bp_location
*tloc
,
1518 std::vector
<std::string
> *tdp_actions
,
1519 std::vector
<std::string
> *stepping_actions
)
1521 struct collection_list tracepoint_list
, stepping_list
;
1523 encode_actions (tloc
, &tracepoint_list
, &stepping_list
);
1525 *tdp_actions
= tracepoint_list
.stringify ();
1526 *stepping_actions
= stepping_list
.stringify ();
1530 collection_list::add_aexpr (agent_expr_up aexpr
)
1532 m_aexprs
.push_back (std::move (aexpr
));
1536 process_tracepoint_on_disconnect (void)
1538 int has_pending_p
= 0;
1540 /* Check whether we still have pending tracepoint. If we have, warn the
1541 user that pending tracepoint will no longer work. */
1542 for (breakpoint
*b
: all_tracepoints ())
1551 struct bp_location
*loc1
;
1553 for (loc1
= b
->loc
; loc1
; loc1
= loc1
->next
)
1555 if (loc1
->shlib_disabled
)
1568 warning (_("Pending tracepoints will not be resolved while"
1569 " GDB is disconnected\n"));
1572 /* Reset local state of tracing. */
1575 trace_reset_local_state (void)
1577 set_traceframe_num (-1);
1578 set_tracepoint_num (-1);
1579 set_traceframe_context (NULL
);
1580 clear_traceframe_info ();
1584 start_tracing (const char *notes
)
1586 int any_enabled
= 0, num_to_download
= 0;
1589 std::vector
<breakpoint
*> tp_vec
= all_tracepoints ();
1591 /* No point in tracing without any tracepoints... */
1592 if (tp_vec
.empty ())
1593 error (_("No tracepoints defined, not starting trace"));
1595 for (breakpoint
*b
: tp_vec
)
1597 if (b
->enable_state
== bp_enabled
)
1600 if ((b
->type
== bp_fast_tracepoint
1601 ? may_insert_fast_tracepoints
1602 : may_insert_tracepoints
))
1605 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1606 (b
->type
== bp_fast_tracepoint
? "fast " : ""), b
->number
);
1611 if (target_supports_enable_disable_tracepoint ())
1612 warning (_("No tracepoints enabled"));
1615 /* No point in tracing with only disabled tracepoints that
1616 cannot be re-enabled. */
1617 error (_("No tracepoints enabled, not starting trace"));
1621 if (num_to_download
<= 0)
1622 error (_("No tracepoints that may be downloaded, not starting trace"));
1624 target_trace_init ();
1626 for (breakpoint
*b
: tp_vec
)
1628 struct tracepoint
*t
= (struct tracepoint
*) b
;
1629 struct bp_location
*loc
;
1630 int bp_location_downloaded
= 0;
1632 /* Clear `inserted' flag. */
1633 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1636 if ((b
->type
== bp_fast_tracepoint
1637 ? !may_insert_fast_tracepoints
1638 : !may_insert_tracepoints
))
1641 t
->number_on_target
= 0;
1643 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1645 /* Since tracepoint locations are never duplicated, `inserted'
1646 flag should be zero. */
1647 gdb_assert (!loc
->inserted
);
1649 target_download_tracepoint (loc
);
1652 bp_location_downloaded
= 1;
1655 t
->number_on_target
= b
->number
;
1657 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1658 if (loc
->probe
.prob
!= NULL
)
1659 loc
->probe
.prob
->set_semaphore (loc
->probe
.objfile
,
1662 if (bp_location_downloaded
)
1663 gdb::observers::breakpoint_modified
.notify (b
);
1666 /* Send down all the trace state variables too. */
1667 for (const trace_state_variable
&tsv
: tvariables
)
1668 target_download_trace_state_variable (tsv
);
1670 /* Tell target to treat text-like sections as transparent. */
1671 target_trace_set_readonly_regions ();
1672 /* Set some mode flags. */
1673 target_set_disconnected_tracing (disconnected_tracing
);
1674 target_set_circular_trace_buffer (circular_trace_buffer
);
1675 target_set_trace_buffer_size (trace_buffer_size
);
1678 notes
= trace_notes
;
1679 ret
= target_set_trace_notes (trace_user
, notes
, NULL
);
1681 if (!ret
&& (trace_user
|| notes
))
1682 warning (_("Target does not support trace user/notes, info ignored"));
1684 /* Now insert traps and begin collecting data. */
1685 target_trace_start ();
1687 /* Reset our local state. */
1688 trace_reset_local_state ();
1689 current_trace_status()->running
= 1;
1692 /* The tstart command requests the target to start a new trace run.
1693 The command passes any arguments it has to the target verbatim, as
1694 an optional "trace note". This is useful as for instance a warning
1695 to other users if the trace runs disconnected, and you don't want
1696 anybody else messing with the target. */
1699 tstart_command (const char *args
, int from_tty
)
1701 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1703 if (current_trace_status ()->running
)
1706 && !query (_("A trace is running already. Start a new run? ")))
1707 error (_("New trace run not started."));
1710 start_tracing (args
);
1713 /* The tstop command stops the tracing run. The command passes any
1714 supplied arguments to the target verbatim as a "stop note"; if the
1715 target supports trace notes, then it will be reported back as part
1716 of the trace run's status. */
1719 tstop_command (const char *args
, int from_tty
)
1721 if (!current_trace_status ()->running
)
1722 error (_("Trace is not running."));
1724 stop_tracing (args
);
1728 stop_tracing (const char *note
)
1732 target_trace_stop ();
1734 for (breakpoint
*t
: all_tracepoints ())
1736 struct bp_location
*loc
;
1738 if ((t
->type
== bp_fast_tracepoint
1739 ? !may_insert_fast_tracepoints
1740 : !may_insert_tracepoints
))
1743 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
1745 /* GDB can be totally absent in some disconnected trace scenarios,
1746 but we don't really care if this semaphore goes out of sync.
1747 That's why we are decrementing it here, but not taking care
1749 if (loc
->probe
.prob
!= NULL
)
1750 loc
->probe
.prob
->clear_semaphore (loc
->probe
.objfile
,
1756 note
= trace_stop_notes
;
1757 ret
= target_set_trace_notes (NULL
, NULL
, note
);
1760 warning (_("Target does not support trace notes, note ignored"));
1762 /* Should change in response to reply? */
1763 current_trace_status ()->running
= 0;
1766 /* tstatus command */
1768 tstatus_command (const char *args
, int from_tty
)
1770 struct trace_status
*ts
= current_trace_status ();
1773 status
= target_get_trace_status (ts
);
1777 if (ts
->filename
!= NULL
)
1778 printf_filtered (_("Using a trace file.\n"));
1781 printf_filtered (_("Trace can not be run on this target.\n"));
1786 if (!ts
->running_known
)
1788 printf_filtered (_("Run/stop status is unknown.\n"));
1790 else if (ts
->running
)
1792 printf_filtered (_("Trace is running on the target.\n"));
1796 switch (ts
->stop_reason
)
1798 case trace_never_run
:
1799 printf_filtered (_("No trace has been run on the target.\n"));
1801 case trace_stop_command
:
1803 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1806 printf_filtered (_("Trace stopped by a tstop command.\n"));
1808 case trace_buffer_full
:
1809 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1811 case trace_disconnected
:
1812 printf_filtered (_("Trace stopped because of disconnection.\n"));
1814 case tracepoint_passcount
:
1815 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1816 ts
->stopping_tracepoint
);
1818 case tracepoint_error
:
1819 if (ts
->stopping_tracepoint
)
1820 printf_filtered (_("Trace stopped by an "
1821 "error (%s, tracepoint %d).\n"),
1822 ts
->stop_desc
, ts
->stopping_tracepoint
);
1824 printf_filtered (_("Trace stopped by an error (%s).\n"),
1827 case trace_stop_reason_unknown
:
1828 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1831 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1837 if (ts
->traceframes_created
>= 0
1838 && ts
->traceframe_count
!= ts
->traceframes_created
)
1840 printf_filtered (_("Buffer contains %d trace "
1841 "frames (of %d created total).\n"),
1842 ts
->traceframe_count
, ts
->traceframes_created
);
1844 else if (ts
->traceframe_count
>= 0)
1846 printf_filtered (_("Collected %d trace frames.\n"),
1847 ts
->traceframe_count
);
1850 if (ts
->buffer_free
>= 0)
1852 if (ts
->buffer_size
>= 0)
1854 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1855 ts
->buffer_free
, ts
->buffer_size
);
1856 if (ts
->buffer_size
> 0)
1857 printf_filtered (_(" (%d%% full)"),
1858 ((int) ((((long long) (ts
->buffer_size
1859 - ts
->buffer_free
)) * 100)
1860 / ts
->buffer_size
)));
1861 printf_filtered (_(".\n"));
1864 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1868 if (ts
->disconnected_tracing
)
1869 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1871 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1873 if (ts
->circular_buffer
)
1874 printf_filtered (_("Trace buffer is circular.\n"));
1876 if (ts
->user_name
&& strlen (ts
->user_name
) > 0)
1877 printf_filtered (_("Trace user is %s.\n"), ts
->user_name
);
1879 if (ts
->notes
&& strlen (ts
->notes
) > 0)
1880 printf_filtered (_("Trace notes: %s.\n"), ts
->notes
);
1882 /* Now report on what we're doing with tfind. */
1883 if (traceframe_number
>= 0)
1884 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1885 traceframe_number
, tracepoint_number
);
1887 printf_filtered (_("Not looking at any trace frame.\n"));
1889 /* Report start/stop times if supplied. */
1894 LONGEST run_time
= ts
->stop_time
- ts
->start_time
;
1896 /* Reporting a run time is more readable than two long numbers. */
1897 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
1898 (long int) (ts
->start_time
/ 1000000),
1899 (long int) (ts
->start_time
% 1000000),
1900 (long int) (run_time
/ 1000000),
1901 (long int) (run_time
% 1000000));
1904 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
1905 (long int) (ts
->start_time
/ 1000000),
1906 (long int) (ts
->start_time
% 1000000));
1908 else if (ts
->stop_time
)
1909 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
1910 (long int) (ts
->stop_time
/ 1000000),
1911 (long int) (ts
->stop_time
% 1000000));
1913 /* Now report any per-tracepoint status available. */
1914 for (breakpoint
*t
: all_tracepoints ())
1915 target_get_tracepoint_status (t
, NULL
);
1918 /* Report the trace status to uiout, in a way suitable for MI, and not
1919 suitable for CLI. If ON_STOP is true, suppress a few fields that
1920 are not meaningful in the -trace-stop response.
1922 The implementation is essentially parallel to trace_status_command, but
1923 merging them will result in unreadable code. */
1925 trace_status_mi (int on_stop
)
1927 struct ui_out
*uiout
= current_uiout
;
1928 struct trace_status
*ts
= current_trace_status ();
1931 status
= target_get_trace_status (ts
);
1933 if (status
== -1 && ts
->filename
== NULL
)
1935 uiout
->field_string ("supported", "0");
1939 if (ts
->filename
!= NULL
)
1940 uiout
->field_string ("supported", "file");
1942 uiout
->field_string ("supported", "1");
1944 if (ts
->filename
!= NULL
)
1945 uiout
->field_string ("trace-file", ts
->filename
);
1947 gdb_assert (ts
->running_known
);
1951 uiout
->field_string ("running", "1");
1953 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
1954 Given that the frontend gets the status either on -trace-stop, or from
1955 -trace-status after re-connection, it does not seem like this
1956 information is necessary for anything. It is not necessary for either
1957 figuring the vital state of the target nor for navigation of trace
1958 frames. If the frontend wants to show the current state is some
1959 configure dialog, it can request the value when such dialog is
1960 invoked by the user. */
1964 const char *stop_reason
= NULL
;
1965 int stopping_tracepoint
= -1;
1968 uiout
->field_string ("running", "0");
1970 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
1972 switch (ts
->stop_reason
)
1974 case trace_stop_command
:
1975 stop_reason
= "request";
1977 case trace_buffer_full
:
1978 stop_reason
= "overflow";
1980 case trace_disconnected
:
1981 stop_reason
= "disconnection";
1983 case tracepoint_passcount
:
1984 stop_reason
= "passcount";
1985 stopping_tracepoint
= ts
->stopping_tracepoint
;
1987 case tracepoint_error
:
1988 stop_reason
= "error";
1989 stopping_tracepoint
= ts
->stopping_tracepoint
;
1995 uiout
->field_string ("stop-reason", stop_reason
);
1996 if (stopping_tracepoint
!= -1)
1997 uiout
->field_signed ("stopping-tracepoint",
1998 stopping_tracepoint
);
1999 if (ts
->stop_reason
== tracepoint_error
)
2000 uiout
->field_string ("error-description",
2006 if (ts
->traceframe_count
!= -1)
2007 uiout
->field_signed ("frames", ts
->traceframe_count
);
2008 if (ts
->traceframes_created
!= -1)
2009 uiout
->field_signed ("frames-created", ts
->traceframes_created
);
2010 if (ts
->buffer_size
!= -1)
2011 uiout
->field_signed ("buffer-size", ts
->buffer_size
);
2012 if (ts
->buffer_free
!= -1)
2013 uiout
->field_signed ("buffer-free", ts
->buffer_free
);
2015 uiout
->field_signed ("disconnected", ts
->disconnected_tracing
);
2016 uiout
->field_signed ("circular", ts
->circular_buffer
);
2018 uiout
->field_string ("user-name", ts
->user_name
);
2019 uiout
->field_string ("notes", ts
->notes
);
2024 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2025 (long int) (ts
->start_time
/ 1000000),
2026 (long int) (ts
->start_time
% 1000000));
2027 uiout
->field_string ("start-time", buf
);
2028 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2029 (long int) (ts
->stop_time
/ 1000000),
2030 (long int) (ts
->stop_time
% 1000000));
2031 uiout
->field_string ("stop-time", buf
);
2035 /* Check if a trace run is ongoing. If so, and FROM_TTY, query the
2036 user if she really wants to detach. */
2039 query_if_trace_running (int from_tty
)
2044 /* It can happen that the target that was tracing went away on its
2045 own, and we didn't notice. Get a status update, and if the
2046 current target doesn't even do tracing, then assume it's not
2048 if (target_get_trace_status (current_trace_status ()) < 0)
2049 current_trace_status ()->running
= 0;
2051 /* If running interactively, give the user the option to cancel and
2052 then decide what to do differently with the run. Scripts are
2053 just going to disconnect and let the target deal with it,
2054 according to how it's been instructed previously via
2055 disconnected-tracing. */
2056 if (current_trace_status ()->running
)
2058 process_tracepoint_on_disconnect ();
2060 if (current_trace_status ()->disconnected_tracing
)
2062 if (!query (_("Trace is running and will "
2063 "continue after detach; detach anyway? ")))
2064 error (_("Not confirmed."));
2068 if (!query (_("Trace is running but will "
2069 "stop on detach; detach anyway? ")))
2070 error (_("Not confirmed."));
2075 /* This function handles the details of what to do about an ongoing
2076 tracing run if the user has asked to detach or otherwise disconnect
2080 disconnect_tracing (void)
2082 /* Also we want to be out of tfind mode, otherwise things can get
2083 confusing upon reconnection. Just use these calls instead of
2084 full tfind_1 behavior because we're in the middle of detaching,
2085 and there's no point to updating current stack frame etc. */
2086 trace_reset_local_state ();
2089 /* Worker function for the various flavors of the tfind command. */
2091 tfind_1 (enum trace_find_type type
, int num
,
2092 CORE_ADDR addr1
, CORE_ADDR addr2
,
2095 int target_frameno
= -1, target_tracept
= -1;
2096 struct frame_id old_frame_id
= null_frame_id
;
2097 struct tracepoint
*tp
;
2098 struct ui_out
*uiout
= current_uiout
;
2100 /* Only try to get the current stack frame if we have a chance of
2101 succeeding. In particular, if we're trying to get a first trace
2102 frame while all threads are running, it's not going to succeed,
2103 so leave it with a default value and let the frame comparison
2104 below (correctly) decide to print out the source location of the
2106 if (!(type
== tfind_number
&& num
== -1)
2107 && (has_stack_frames () || traceframe_number
>= 0))
2108 old_frame_id
= get_frame_id (get_current_frame ());
2110 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
2113 if (type
== tfind_number
2115 && target_frameno
== -1)
2117 /* We told the target to get out of tfind mode, and it did. */
2119 else if (target_frameno
== -1)
2121 /* A request for a non-existent trace frame has failed.
2122 Our response will be different, depending on FROM_TTY:
2124 If FROM_TTY is true, meaning that this command was
2125 typed interactively by the user, then give an error
2126 and DO NOT change the state of traceframe_number etc.
2128 However if FROM_TTY is false, meaning that we're either
2129 in a script, a loop, or a user-defined command, then
2130 DON'T give an error, but DO change the state of
2131 traceframe_number etc. to invalid.
2133 The rationale is that if you typed the command, you
2134 might just have committed a typo or something, and you'd
2135 like to NOT lose your current debugging state. However
2136 if you're in a user-defined command or especially in a
2137 loop, then you need a way to detect that the command
2138 failed WITHOUT aborting. This allows you to write
2139 scripts that search thru the trace buffer until the end,
2140 and then continue on to do something else. */
2143 error (_("Target failed to find requested trace frame."));
2147 printf_filtered ("End of trace buffer.\n");
2148 #if 0 /* dubious now? */
2149 /* The following will not recurse, since it's
2151 tfind_command ("-1", from_tty
);
2156 tp
= get_tracepoint_by_number_on_target (target_tracept
);
2158 reinit_frame_cache ();
2159 target_dcache_invalidate ();
2161 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
2163 if (target_frameno
!= get_traceframe_number ())
2164 gdb::observers::traceframe_changed
.notify (target_frameno
, tracepoint_number
);
2166 set_current_traceframe (target_frameno
);
2168 if (target_frameno
== -1)
2169 set_traceframe_context (NULL
);
2171 set_traceframe_context (get_current_frame ());
2173 if (traceframe_number
>= 0)
2175 /* Use different branches for MI and CLI to make CLI messages
2177 if (uiout
->is_mi_like_p ())
2179 uiout
->field_string ("found", "1");
2180 uiout
->field_signed ("tracepoint", tracepoint_number
);
2181 uiout
->field_signed ("traceframe", traceframe_number
);
2185 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2186 traceframe_number
, tracepoint_number
);
2191 if (uiout
->is_mi_like_p ())
2192 uiout
->field_string ("found", "0");
2193 else if (type
== tfind_number
&& num
== -1)
2194 printf_unfiltered (_("No longer looking at any trace frame\n"));
2195 else /* This case may never occur, check. */
2196 printf_unfiltered (_("No trace frame found\n"));
2199 /* If we're in nonstop mode and getting out of looking at trace
2200 frames, there won't be any current frame to go back to and
2203 && (has_stack_frames () || traceframe_number
>= 0))
2205 enum print_what print_what
;
2207 /* NOTE: in imitation of the step command, try to determine
2208 whether we have made a transition from one function to
2209 another. If so, we'll print the "stack frame" (ie. the new
2210 function and it's arguments) -- otherwise we'll just show the
2213 if (frame_id_eq (old_frame_id
,
2214 get_frame_id (get_current_frame ())))
2215 print_what
= SRC_LINE
;
2217 print_what
= SRC_AND_LOC
;
2219 print_stack_frame (get_selected_frame (NULL
), 1, print_what
, 1);
2224 /* Error on looking at traceframes while trace is running. */
2227 check_trace_running (struct trace_status
*status
)
2229 if (status
->running
&& status
->filename
== NULL
)
2230 error (_("May not look at trace frames while trace is running."));
2233 /* trace_find_command takes a trace frame number n,
2234 sends "QTFrame:<n>" to the target,
2235 and accepts a reply that may contain several optional pieces
2236 of information: a frame number, a tracepoint number, and an
2237 indication of whether this is a trap frame or a stepping frame.
2239 The minimal response is just "OK" (which indicates that the
2240 target does not give us a frame number or a tracepoint number).
2241 Instead of that, the target may send us a string containing
2243 F<hexnum> (gives the selected frame number)
2244 T<hexnum> (gives the selected tracepoint number)
2249 tfind_command_1 (const char *args
, int from_tty
)
2250 { /* This should only be called with a numeric argument. */
2253 check_trace_running (current_trace_status ());
2255 if (args
== 0 || *args
== 0)
2256 { /* TFIND with no args means find NEXT trace frame. */
2257 if (traceframe_number
== -1)
2258 frameno
= 0; /* "next" is first one. */
2260 frameno
= traceframe_number
+ 1;
2262 else if (0 == strcmp (args
, "-"))
2264 if (traceframe_number
== -1)
2265 error (_("not debugging trace buffer"));
2266 else if (from_tty
&& traceframe_number
== 0)
2267 error (_("already at start of trace buffer"));
2269 frameno
= traceframe_number
- 1;
2271 /* A hack to work around eval's need for fp to have been collected. */
2272 else if (0 == strcmp (args
, "-1"))
2275 frameno
= parse_and_eval_long (args
);
2278 error (_("invalid input (%d is less than zero)"), frameno
);
2280 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
2284 tfind_command (const char *args
, int from_tty
)
2286 tfind_command_1 (args
, from_tty
);
2291 tfind_end_command (const char *args
, int from_tty
)
2293 tfind_command_1 ("-1", from_tty
);
2298 tfind_start_command (const char *args
, int from_tty
)
2300 tfind_command_1 ("0", from_tty
);
2303 /* tfind pc command */
2305 tfind_pc_command (const char *args
, int from_tty
)
2309 check_trace_running (current_trace_status ());
2311 if (args
== 0 || *args
== 0)
2312 pc
= regcache_read_pc (get_current_regcache ());
2314 pc
= parse_and_eval_address (args
);
2316 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
2319 /* tfind tracepoint command */
2321 tfind_tracepoint_command (const char *args
, int from_tty
)
2324 struct tracepoint
*tp
;
2326 check_trace_running (current_trace_status ());
2328 if (args
== 0 || *args
== 0)
2330 if (tracepoint_number
== -1)
2331 error (_("No current tracepoint -- please supply an argument."));
2333 tdp
= tracepoint_number
; /* Default is current TDP. */
2336 tdp
= parse_and_eval_long (args
);
2338 /* If we have the tracepoint on hand, use the number that the
2339 target knows about (which may be different if we disconnected
2340 and reconnected). */
2341 tp
= get_tracepoint (tdp
);
2343 tdp
= tp
->number_on_target
;
2345 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
2348 /* TFIND LINE command:
2350 This command will take a sourceline for argument, just like BREAK
2351 or TRACE (ie. anything that "decode_line_1" can handle).
2353 With no argument, this command will find the next trace frame
2354 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2357 tfind_line_command (const char *args
, int from_tty
)
2359 check_trace_running (current_trace_status ());
2361 symtab_and_line sal
;
2362 if (args
== 0 || *args
== 0)
2364 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2368 std::vector
<symtab_and_line
> sals
2369 = decode_line_with_current_source (args
, DECODE_LINE_FUNFIRSTLINE
);
2373 if (sal
.symtab
== 0)
2374 error (_("No line number information available."));
2376 CORE_ADDR start_pc
, end_pc
;
2377 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2379 if (start_pc
== end_pc
)
2381 printf_filtered ("Line %d of \"%s\"",
2383 symtab_to_filename_for_display (sal
.symtab
));
2385 printf_filtered (" is at address ");
2386 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2388 printf_filtered (" but contains no code.\n");
2389 sal
= find_pc_line (start_pc
, 0);
2391 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2392 && start_pc
!= end_pc
)
2393 printf_filtered ("Attempting to find line %d instead.\n",
2396 error (_("Cannot find a good line."));
2400 /* Is there any case in which we get here, and have an address
2401 which the user would want to see? If we have debugging
2402 symbols and no line numbers? */
2403 error (_("Line number %d is out of range for \"%s\"."),
2404 sal
.line
, symtab_to_filename_for_display (sal
.symtab
));
2406 /* Find within range of stated line. */
2408 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2410 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2413 /* tfind range command */
2415 tfind_range_command (const char *args
, int from_tty
)
2417 static CORE_ADDR start
, stop
;
2420 check_trace_running (current_trace_status ());
2422 if (args
== 0 || *args
== 0)
2423 { /* XXX FIXME: what should default behavior be? */
2424 printf_filtered ("Usage: tfind range STARTADDR, ENDADDR\n");
2428 if (0 != (tmp
= strchr (args
, ',')))
2430 std::string
start_addr (args
, tmp
);
2432 tmp
= skip_spaces (tmp
);
2433 start
= parse_and_eval_address (start_addr
.c_str ());
2434 stop
= parse_and_eval_address (tmp
);
2437 { /* No explicit end address? */
2438 start
= parse_and_eval_address (args
);
2439 stop
= start
+ 1; /* ??? */
2442 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2445 /* tfind outside command */
2447 tfind_outside_command (const char *args
, int from_tty
)
2449 CORE_ADDR start
, stop
;
2452 if (current_trace_status ()->running
2453 && current_trace_status ()->filename
== NULL
)
2454 error (_("May not look at trace frames while trace is running."));
2456 if (args
== 0 || *args
== 0)
2457 { /* XXX FIXME: what should default behavior be? */
2458 printf_filtered ("Usage: tfind outside STARTADDR, ENDADDR\n");
2462 if (0 != (tmp
= strchr (args
, ',')))
2464 std::string
start_addr (args
, tmp
);
2466 tmp
= skip_spaces (tmp
);
2467 start
= parse_and_eval_address (start_addr
.c_str ());
2468 stop
= parse_and_eval_address (tmp
);
2471 { /* No explicit end address? */
2472 start
= parse_and_eval_address (args
);
2473 stop
= start
+ 1; /* ??? */
2476 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2479 /* info scope command: list the locals for a scope. */
2481 info_scope_command (const char *args_in
, int from_tty
)
2484 struct bound_minimal_symbol msym
;
2485 const struct block
*block
;
2486 const char *symname
;
2487 const char *save_args
= args_in
;
2488 struct block_iterator iter
;
2490 struct gdbarch
*gdbarch
;
2492 const char *args
= args_in
;
2494 if (args
== 0 || *args
== 0)
2495 error (_("requires an argument (function, "
2496 "line or *addr) to define a scope"));
2498 event_location_up location
= string_to_event_location (&args
,
2500 std::vector
<symtab_and_line
> sals
2501 = decode_line_1 (location
.get (), DECODE_LINE_FUNFIRSTLINE
,
2505 /* Presumably decode_line_1 has already warned. */
2509 /* Resolve line numbers to PC. */
2510 resolve_sal_pc (&sals
[0]);
2511 block
= block_for_pc (sals
[0].pc
);
2515 QUIT
; /* Allow user to bail out with ^C. */
2516 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2518 QUIT
; /* Allow user to bail out with ^C. */
2520 printf_filtered ("Scope for %s:\n", save_args
);
2523 symname
= sym
->print_name ();
2524 if (symname
== NULL
|| *symname
== '\0')
2525 continue; /* Probably botched, certainly useless. */
2527 gdbarch
= symbol_arch (sym
);
2529 printf_filtered ("Symbol %s is ", symname
);
2531 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
2532 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
,
2533 BLOCK_ENTRY_PC (block
),
2537 switch (SYMBOL_CLASS (sym
))
2540 case LOC_UNDEF
: /* Messed up symbol? */
2541 printf_filtered ("a bogus symbol, class %d.\n",
2542 SYMBOL_CLASS (sym
));
2543 count
--; /* Don't count this one. */
2546 printf_filtered ("a constant with value %s (%s)",
2547 plongest (SYMBOL_VALUE (sym
)),
2548 hex_string (SYMBOL_VALUE (sym
)));
2550 case LOC_CONST_BYTES
:
2551 printf_filtered ("constant bytes: ");
2552 if (SYMBOL_TYPE (sym
))
2553 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2554 fprintf_filtered (gdb_stdout
, " %02x",
2555 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2558 printf_filtered ("in static storage at address ");
2559 printf_filtered ("%s", paddress (gdbarch
,
2560 SYMBOL_VALUE_ADDRESS (sym
)));
2563 /* GDBARCH is the architecture associated with the objfile
2564 the symbol is defined in; the target architecture may be
2565 different, and may provide additional registers. However,
2566 we do not know the target architecture at this point.
2567 We assume the objfile architecture will contain all the
2568 standard registers that occur in debug info in that
2570 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2573 if (SYMBOL_IS_ARGUMENT (sym
))
2574 printf_filtered ("an argument in register $%s",
2575 gdbarch_register_name (gdbarch
, regno
));
2577 printf_filtered ("a local variable in register $%s",
2578 gdbarch_register_name (gdbarch
, regno
));
2581 printf_filtered ("an argument at stack/frame offset %s",
2582 plongest (SYMBOL_VALUE (sym
)));
2585 printf_filtered ("a local variable at frame offset %s",
2586 plongest (SYMBOL_VALUE (sym
)));
2589 printf_filtered ("a reference argument at offset %s",
2590 plongest (SYMBOL_VALUE (sym
)));
2592 case LOC_REGPARM_ADDR
:
2593 /* Note comment at LOC_REGISTER. */
2594 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2596 printf_filtered ("the address of an argument, in register $%s",
2597 gdbarch_register_name (gdbarch
, regno
));
2600 printf_filtered ("a typedef.\n");
2603 printf_filtered ("a label at address ");
2604 printf_filtered ("%s", paddress (gdbarch
,
2605 SYMBOL_VALUE_ADDRESS (sym
)));
2608 printf_filtered ("a function at address ");
2609 printf_filtered ("%s",
2610 paddress (gdbarch
, BLOCK_ENTRY_PC (SYMBOL_BLOCK_VALUE (sym
))));
2612 case LOC_UNRESOLVED
:
2613 msym
= lookup_minimal_symbol (sym
->linkage_name (),
2615 if (msym
.minsym
== NULL
)
2616 printf_filtered ("Unresolved Static");
2619 printf_filtered ("static storage at address ");
2620 printf_filtered ("%s",
2622 BMSYMBOL_VALUE_ADDRESS (msym
)));
2625 case LOC_OPTIMIZED_OUT
:
2626 printf_filtered ("optimized out.\n");
2629 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2632 if (SYMBOL_TYPE (sym
))
2634 struct type
*t
= check_typedef (SYMBOL_TYPE (sym
));
2636 printf_filtered (", length %s.\n", pulongest (TYPE_LENGTH (t
)));
2639 if (BLOCK_FUNCTION (block
))
2642 block
= BLOCK_SUPERBLOCK (block
);
2645 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2649 /* Helper for trace_dump_command. Dump the action list starting at
2650 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2651 actions of the body of a while-stepping action. STEPPING_FRAME is
2652 set if the current traceframe was determined to be a while-stepping
2656 trace_dump_actions (struct command_line
*action
,
2657 int stepping_actions
, int stepping_frame
,
2660 const char *action_exp
, *next_comma
;
2662 for (; action
!= NULL
; action
= action
->next
)
2664 struct cmd_list_element
*cmd
;
2666 QUIT
; /* Allow user to bail out with ^C. */
2667 action_exp
= action
->line
;
2668 action_exp
= skip_spaces (action_exp
);
2670 /* The collection actions to be done while stepping are
2671 bracketed by the commands "while-stepping" and "end". */
2673 if (*action_exp
== '#') /* comment line */
2676 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2678 error (_("Bad action list item: %s"), action_exp
);
2680 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2682 gdb_assert (action
->body_list_1
== nullptr);
2683 trace_dump_actions (action
->body_list_0
.get (),
2684 1, stepping_frame
, from_tty
);
2686 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2688 /* Display the collected data.
2689 For the trap frame, display only what was collected at
2690 the trap. Likewise for stepping frames, display only
2691 what was collected while stepping. This means that the
2692 two boolean variables, STEPPING_FRAME and
2693 STEPPING_ACTIONS should be equal. */
2694 if (stepping_frame
== stepping_actions
)
2696 int trace_string
= 0;
2698 if (*action_exp
== '/')
2699 action_exp
= decode_agent_options (action_exp
, &trace_string
);
2702 { /* Repeat over a comma-separated list. */
2703 QUIT
; /* Allow user to bail out with ^C. */
2704 if (*action_exp
== ',')
2706 action_exp
= skip_spaces (action_exp
);
2708 next_comma
= strchr (action_exp
, ',');
2710 if (0 == strncasecmp (action_exp
, "$reg", 4))
2711 registers_info (NULL
, from_tty
);
2712 else if (0 == strncasecmp (action_exp
, "$_ret", 5))
2714 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2715 info_locals_command (NULL
, from_tty
);
2716 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2717 info_args_command (NULL
, from_tty
);
2720 std::string contents
;
2721 const char *exp
= action_exp
;
2722 if (next_comma
!= NULL
)
2724 size_t len
= next_comma
- action_exp
;
2725 contents
= std::string (action_exp
, len
);
2726 exp
= contents
.c_str ();
2729 printf_filtered ("%s = ", exp
);
2730 output_command (exp
, from_tty
);
2731 printf_filtered ("\n");
2733 action_exp
= next_comma
;
2735 while (action_exp
&& *action_exp
== ',');
2741 /* Return bp_location of the tracepoint associated with the current
2742 traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe
2743 is a stepping traceframe. */
2745 struct bp_location
*
2746 get_traceframe_location (int *stepping_frame_p
)
2748 struct tracepoint
*t
;
2749 struct bp_location
*tloc
;
2750 struct regcache
*regcache
;
2752 if (tracepoint_number
== -1)
2753 error (_("No current trace frame."));
2755 t
= get_tracepoint (tracepoint_number
);
2758 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2761 /* The current frame is a trap frame if the frame PC is equal to the
2762 tracepoint PC. If not, then the current frame was collected
2763 during single-stepping. */
2764 regcache
= get_current_regcache ();
2766 /* If the traceframe's address matches any of the tracepoint's
2767 locations, assume it is a direct hit rather than a while-stepping
2768 frame. (FIXME this is not reliable, should record each frame's
2770 for (tloc
= t
->loc
; tloc
; tloc
= tloc
->next
)
2771 if (tloc
->address
== regcache_read_pc (regcache
))
2773 *stepping_frame_p
= 0;
2777 /* If this is a stepping frame, we don't know which location
2778 triggered. The first is as good (or bad) a guess as any... */
2779 *stepping_frame_p
= 1;
2783 /* Return the default collect actions of a tracepoint T. */
2785 static counted_command_line
2786 all_tracepoint_actions (struct breakpoint
*t
)
2788 counted_command_line
actions (nullptr, command_lines_deleter ());
2790 /* If there are default expressions to collect, make up a collect
2791 action and prepend to the action list to encode. Note that since
2792 validation is per-tracepoint (local var "xyz" might be valid for
2793 one tracepoint and not another, etc), we make up the action on
2794 the fly, and don't cache it. */
2795 if (*default_collect
)
2797 gdb::unique_xmalloc_ptr
<char> default_collect_line
2798 (xstrprintf ("collect %s", default_collect
));
2800 validate_actionline (default_collect_line
.get (), t
);
2801 actions
.reset (new struct command_line (simple_control
,
2802 default_collect_line
.release ()),
2803 command_lines_deleter ());
2809 /* The tdump command. */
2812 tdump_command (const char *args
, int from_tty
)
2814 int stepping_frame
= 0;
2815 struct bp_location
*loc
;
2817 /* This throws an error is not inspecting a trace frame. */
2818 loc
= get_traceframe_location (&stepping_frame
);
2820 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2821 tracepoint_number
, traceframe_number
);
2823 /* This command only makes sense for the current frame, not the
2825 scoped_restore_current_thread restore_thread
;
2827 select_frame (get_current_frame ());
2829 counted_command_line actions
= all_tracepoint_actions (loc
->owner
);
2831 trace_dump_actions (actions
.get (), 0, stepping_frame
, from_tty
);
2832 trace_dump_actions (breakpoint_commands (loc
->owner
), 0, stepping_frame
,
2836 /* Encode a piece of a tracepoint's source-level definition in a form
2837 that is suitable for both protocol and saving in files. */
2838 /* This version does not do multiple encodes for long strings; it should
2839 return an offset to the next piece to encode. FIXME */
2842 encode_source_string (int tpnum
, ULONGEST addr
,
2843 const char *srctype
, const char *src
,
2844 char *buf
, int buf_size
)
2846 if (80 + strlen (srctype
) > buf_size
)
2847 error (_("Buffer too small for source encoding"));
2848 sprintf (buf
, "%x:%s:%s:%x:%x:",
2849 tpnum
, phex_nz (addr
, sizeof (addr
)),
2850 srctype
, 0, (int) strlen (src
));
2851 if (strlen (buf
) + strlen (src
) * 2 >= buf_size
)
2852 error (_("Source string too long for buffer"));
2853 bin2hex ((gdb_byte
*) src
, buf
+ strlen (buf
), strlen (src
));
2857 /* Tell the target what to do with an ongoing tracing run if GDB
2858 disconnects for some reason. */
2861 set_disconnected_tracing (const char *args
, int from_tty
,
2862 struct cmd_list_element
*c
)
2864 target_set_disconnected_tracing (disconnected_tracing
);
2868 set_circular_trace_buffer (const char *args
, int from_tty
,
2869 struct cmd_list_element
*c
)
2871 target_set_circular_trace_buffer (circular_trace_buffer
);
2875 set_trace_buffer_size (const char *args
, int from_tty
,
2876 struct cmd_list_element
*c
)
2878 target_set_trace_buffer_size (trace_buffer_size
);
2882 set_trace_user (const char *args
, int from_tty
,
2883 struct cmd_list_element
*c
)
2887 ret
= target_set_trace_notes (trace_user
, NULL
, NULL
);
2890 warning (_("Target does not support trace notes, user ignored"));
2894 set_trace_notes (const char *args
, int from_tty
,
2895 struct cmd_list_element
*c
)
2899 ret
= target_set_trace_notes (NULL
, trace_notes
, NULL
);
2902 warning (_("Target does not support trace notes, note ignored"));
2906 set_trace_stop_notes (const char *args
, int from_tty
,
2907 struct cmd_list_element
*c
)
2911 ret
= target_set_trace_notes (NULL
, NULL
, trace_stop_notes
);
2914 warning (_("Target does not support trace notes, stop note ignored"));
2917 /* Convert the memory pointed to by mem into hex, placing result in buf.
2918 * Return a pointer to the last char put in buf (null)
2919 * "stolen" from sparc-stub.c
2922 static const char hexchars
[] = "0123456789abcdef";
2925 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2933 *buf
++ = hexchars
[ch
>> 4];
2934 *buf
++ = hexchars
[ch
& 0xf];
2943 get_traceframe_number (void)
2945 return traceframe_number
;
2949 get_tracepoint_number (void)
2951 return tracepoint_number
;
2954 /* Make the traceframe NUM be the current trace frame. Does nothing
2955 if NUM is already current. */
2958 set_current_traceframe (int num
)
2962 if (traceframe_number
== num
)
2964 /* Nothing to do. */
2968 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
2971 warning (_("could not change traceframe"));
2973 set_traceframe_num (newnum
);
2975 /* Changing the traceframe changes our view of registers and of the
2977 registers_changed ();
2979 clear_traceframe_info ();
2982 scoped_restore_current_traceframe::scoped_restore_current_traceframe ()
2983 : m_traceframe_number (traceframe_number
)
2986 /* Given a number and address, return an uploaded tracepoint with that
2987 number, creating if necessary. */
2989 struct uploaded_tp
*
2990 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
2992 struct uploaded_tp
*utp
;
2994 for (utp
= *utpp
; utp
; utp
= utp
->next
)
2995 if (utp
->number
== num
&& utp
->addr
== addr
)
2998 utp
= new uploaded_tp
;
3008 free_uploaded_tps (struct uploaded_tp
**utpp
)
3010 struct uploaded_tp
*next_one
;
3014 next_one
= (*utpp
)->next
;
3020 /* Given a number and address, return an uploaded tracepoint with that
3021 number, creating if necessary. */
3023 struct uploaded_tsv
*
3024 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
3026 struct uploaded_tsv
*utsv
;
3028 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
3029 if (utsv
->number
== num
)
3032 utsv
= XCNEW (struct uploaded_tsv
);
3034 utsv
->next
= *utsvp
;
3041 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
3043 struct uploaded_tsv
*next_one
;
3047 next_one
= (*utsvp
)->next
;
3053 /* FIXME this function is heuristic and will miss the cases where the
3054 conditional is semantically identical but differs in whitespace,
3055 such as "x == 0" vs "x==0". */
3058 cond_string_is_same (char *str1
, char *str2
)
3060 if (str1
== NULL
|| str2
== NULL
)
3061 return (str1
== str2
);
3063 return (strcmp (str1
, str2
) == 0);
3066 /* Look for an existing tracepoint that seems similar enough to the
3067 uploaded one. Enablement isn't compared, because the user can
3068 toggle that freely, and may have done so in anticipation of the
3069 next trace run. Return the location of matched tracepoint. */
3071 static struct bp_location
*
3072 find_matching_tracepoint_location (struct uploaded_tp
*utp
)
3074 struct bp_location
*loc
;
3076 for (breakpoint
*b
: all_tracepoints ())
3078 struct tracepoint
*t
= (struct tracepoint
*) b
;
3080 if (b
->type
== utp
->type
3081 && t
->step_count
== utp
->step
3082 && t
->pass_count
== utp
->pass
3083 && cond_string_is_same (t
->cond_string
,
3084 utp
->cond_string
.get ())
3085 /* FIXME also test actions. */
3088 /* Scan the locations for an address match. */
3089 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3091 if (loc
->address
== utp
->addr
)
3099 /* Given a list of tracepoints uploaded from a target, attempt to
3100 match them up with existing tracepoints, and create new ones if not
3104 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
3106 struct uploaded_tp
*utp
;
3107 /* A set of tracepoints which are modified. */
3108 std::vector
<breakpoint
*> modified_tp
;
3110 /* Look for GDB tracepoints that match up with our uploaded versions. */
3111 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
3113 struct bp_location
*loc
;
3114 struct tracepoint
*t
;
3116 loc
= find_matching_tracepoint_location (utp
);
3121 /* Mark this location as already inserted. */
3123 t
= (struct tracepoint
*) loc
->owner
;
3124 printf_filtered (_("Assuming tracepoint %d is same "
3125 "as target's tracepoint %d at %s.\n"),
3126 loc
->owner
->number
, utp
->number
,
3127 paddress (loc
->gdbarch
, utp
->addr
));
3129 /* The tracepoint LOC->owner was modified (the location LOC
3130 was marked as inserted in the target). Save it in
3131 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3132 observers will be notified later once for each tracepoint
3133 saved in MODIFIED_TP. */
3134 for (breakpoint
*b
: modified_tp
)
3135 if (b
== loc
->owner
)
3141 modified_tp
.push_back (loc
->owner
);
3145 t
= create_tracepoint_from_upload (utp
);
3147 printf_filtered (_("Created tracepoint %d for "
3148 "target's tracepoint %d at %s.\n"),
3149 t
->number
, utp
->number
,
3150 paddress (get_current_arch (), utp
->addr
));
3152 printf_filtered (_("Failed to create tracepoint for target's "
3153 "tracepoint %d at %s, skipping it.\n"),
3155 paddress (get_current_arch (), utp
->addr
));
3157 /* Whether found or created, record the number used by the
3158 target, to help with mapping target tracepoints back to their
3159 counterparts here. */
3161 t
->number_on_target
= utp
->number
;
3164 /* Notify 'breakpoint-modified' observer that at least one of B's
3165 locations was changed. */
3166 for (breakpoint
*b
: modified_tp
)
3167 gdb::observers::breakpoint_modified
.notify (b
);
3169 free_uploaded_tps (uploaded_tps
);
3172 /* Trace state variables don't have much to identify them beyond their
3173 name, so just use that to detect matches. */
3175 static struct trace_state_variable
*
3176 find_matching_tsv (struct uploaded_tsv
*utsv
)
3181 return find_trace_state_variable (utsv
->name
);
3184 static struct trace_state_variable
*
3185 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
3187 const char *namebase
;
3190 struct trace_state_variable
*tsv
;
3194 namebase
= utsv
->name
;
3200 buf
= string_printf ("%s_%d", namebase
, try_num
++);
3203 /* Fish for a name that is not in use. */
3204 /* (should check against all internal vars?) */
3205 while (find_trace_state_variable (buf
.c_str ()))
3206 buf
= string_printf ("%s_%d", namebase
, try_num
++);
3208 /* We have an available name, create the variable. */
3209 tsv
= create_trace_state_variable (buf
.c_str ());
3210 tsv
->initial_value
= utsv
->initial_value
;
3211 tsv
->builtin
= utsv
->builtin
;
3213 gdb::observers::tsv_created
.notify (tsv
);
3218 /* Given a list of uploaded trace state variables, try to match them
3219 up with existing variables, or create additional ones. */
3222 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
3224 struct uploaded_tsv
*utsv
;
3227 /* Most likely some numbers will have to be reassigned as part of
3228 the merge, so clear them all in anticipation. */
3229 for (trace_state_variable
&tsv
: tvariables
)
3232 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
3234 struct trace_state_variable
*tsv
= find_matching_tsv (utsv
);
3238 printf_filtered (_("Assuming trace state variable $%s "
3239 "is same as target's variable %d.\n"),
3240 tsv
->name
.c_str (), utsv
->number
);
3244 tsv
= create_tsv_from_upload (utsv
);
3246 printf_filtered (_("Created trace state variable "
3247 "$%s for target's variable %d.\n"),
3248 tsv
->name
.c_str (), utsv
->number
);
3250 /* Give precedence to numberings that come from the target. */
3252 tsv
->number
= utsv
->number
;
3255 /* Renumber everything that didn't get a target-assigned number. */
3257 for (const trace_state_variable
&tsv
: tvariables
)
3258 highest
= std::max (tsv
.number
, highest
);
3261 for (trace_state_variable
&tsv
: tvariables
)
3262 if (tsv
.number
== 0)
3263 tsv
.number
= highest
++;
3265 free_uploaded_tsvs (uploaded_tsvs
);
3268 /* Parse the part of trace status syntax that is shared between
3269 the remote protocol and the trace file reader. */
3272 parse_trace_status (const char *line
, struct trace_status
*ts
)
3274 const char *p
= line
, *p1
, *p2
, *p3
, *p_temp
;
3278 ts
->running_known
= 1;
3279 ts
->running
= (*p
++ == '1');
3280 ts
->stop_reason
= trace_stop_reason_unknown
;
3281 xfree (ts
->stop_desc
);
3282 ts
->stop_desc
= NULL
;
3283 ts
->traceframe_count
= -1;
3284 ts
->traceframes_created
= -1;
3285 ts
->buffer_free
= -1;
3286 ts
->buffer_size
= -1;
3287 ts
->disconnected_tracing
= 0;
3288 ts
->circular_buffer
= 0;
3289 xfree (ts
->user_name
);
3290 ts
->user_name
= NULL
;
3293 ts
->start_time
= ts
->stop_time
= 0;
3297 p1
= strchr (p
, ':');
3299 error (_("Malformed trace status, at %s\n\
3300 Status line: '%s'\n"), p
, line
);
3301 p3
= strchr (p
, ';');
3303 p3
= p
+ strlen (p
);
3304 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
3306 p
= unpack_varlen_hex (++p1
, &val
);
3307 ts
->stop_reason
= trace_buffer_full
;
3309 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
3311 p
= unpack_varlen_hex (++p1
, &val
);
3312 ts
->stop_reason
= trace_never_run
;
3314 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
],
3317 p
= unpack_varlen_hex (++p1
, &val
);
3318 ts
->stop_reason
= tracepoint_passcount
;
3319 ts
->stopping_tracepoint
= val
;
3321 else if (strncmp (p
, stop_reason_names
[trace_stop_command
], p1
- p
) == 0)
3323 p2
= strchr (++p1
, ':');
3331 ts
->stop_desc
= (char *) xmalloc (strlen (line
));
3332 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3333 ts
->stop_desc
[end
] = '\0';
3336 ts
->stop_desc
= xstrdup ("");
3338 p
= unpack_varlen_hex (++p2
, &val
);
3339 ts
->stop_reason
= trace_stop_command
;
3341 else if (strncmp (p
, stop_reason_names
[trace_disconnected
], p1
- p
) == 0)
3343 p
= unpack_varlen_hex (++p1
, &val
);
3344 ts
->stop_reason
= trace_disconnected
;
3346 else if (strncmp (p
, stop_reason_names
[tracepoint_error
], p1
- p
) == 0)
3348 p2
= strchr (++p1
, ':');
3351 ts
->stop_desc
= (char *) xmalloc ((p2
- p1
) / 2 + 1);
3352 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3353 ts
->stop_desc
[end
] = '\0';
3356 ts
->stop_desc
= xstrdup ("");
3358 p
= unpack_varlen_hex (++p2
, &val
);
3359 ts
->stopping_tracepoint
= val
;
3360 ts
->stop_reason
= tracepoint_error
;
3362 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3364 p
= unpack_varlen_hex (++p1
, &val
);
3365 ts
->traceframe_count
= val
;
3367 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3369 p
= unpack_varlen_hex (++p1
, &val
);
3370 ts
->traceframes_created
= val
;
3372 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3374 p
= unpack_varlen_hex (++p1
, &val
);
3375 ts
->buffer_free
= val
;
3377 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3379 p
= unpack_varlen_hex (++p1
, &val
);
3380 ts
->buffer_size
= val
;
3382 else if (strncmp (p
, "disconn", p1
- p
) == 0)
3384 p
= unpack_varlen_hex (++p1
, &val
);
3385 ts
->disconnected_tracing
= val
;
3387 else if (strncmp (p
, "circular", p1
- p
) == 0)
3389 p
= unpack_varlen_hex (++p1
, &val
);
3390 ts
->circular_buffer
= val
;
3392 else if (strncmp (p
, "starttime", p1
- p
) == 0)
3394 p
= unpack_varlen_hex (++p1
, &val
);
3395 ts
->start_time
= val
;
3397 else if (strncmp (p
, "stoptime", p1
- p
) == 0)
3399 p
= unpack_varlen_hex (++p1
, &val
);
3400 ts
->stop_time
= val
;
3402 else if (strncmp (p
, "username", p1
- p
) == 0)
3405 ts
->user_name
= (char *) xmalloc (strlen (p
) / 2);
3406 end
= hex2bin (p1
, (gdb_byte
*) ts
->user_name
, (p3
- p1
) / 2);
3407 ts
->user_name
[end
] = '\0';
3410 else if (strncmp (p
, "notes", p1
- p
) == 0)
3413 ts
->notes
= (char *) xmalloc (strlen (p
) / 2);
3414 end
= hex2bin (p1
, (gdb_byte
*) ts
->notes
, (p3
- p1
) / 2);
3415 ts
->notes
[end
] = '\0';
3420 /* Silently skip unknown optional info. */
3421 p_temp
= strchr (p1
+ 1, ';');
3425 /* Must be at the end. */
3432 parse_tracepoint_status (const char *p
, struct breakpoint
*bp
,
3433 struct uploaded_tp
*utp
)
3436 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
3438 p
= unpack_varlen_hex (p
, &uval
);
3440 tp
->hit_count
+= uval
;
3442 utp
->hit_count
+= uval
;
3443 p
= unpack_varlen_hex (p
+ 1, &uval
);
3445 tp
->traceframe_usage
+= uval
;
3447 utp
->traceframe_usage
+= uval
;
3448 /* Ignore any extra, allowing for future extensions. */
3451 /* Given a line of text defining a part of a tracepoint, parse it into
3452 an "uploaded tracepoint". */
3455 parse_tracepoint_definition (const char *line
, struct uploaded_tp
**utpp
)
3459 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
, start
;
3462 const char *srctype
;
3464 struct uploaded_tp
*utp
= NULL
;
3467 /* Both tracepoint and action definitions start with the same number
3468 and address sequence. */
3470 p
= unpack_varlen_hex (p
, &num
);
3471 p
++; /* skip a colon */
3472 p
= unpack_varlen_hex (p
, &addr
);
3473 p
++; /* skip a colon */
3476 gdb::unique_xmalloc_ptr
<char[]> cond
;
3478 enabled
= (*p
++ == 'E');
3479 p
++; /* skip a colon */
3480 p
= unpack_varlen_hex (p
, &step
);
3481 p
++; /* skip a colon */
3482 p
= unpack_varlen_hex (p
, &pass
);
3483 type
= bp_tracepoint
;
3484 /* Thumb through optional fields. */
3487 p
++; /* skip a colon */
3490 type
= bp_fast_tracepoint
;
3492 p
= unpack_varlen_hex (p
, &orig_size
);
3496 type
= bp_static_tracepoint
;
3502 p
= unpack_varlen_hex (p
, &xlen
);
3503 p
++; /* skip a comma */
3504 cond
.reset ((char *) xmalloc (2 * xlen
+ 1));
3505 strncpy (&cond
[0], p
, 2 * xlen
);
3506 cond
[2 * xlen
] = '\0';
3510 warning (_("Unrecognized char '%c' in tracepoint "
3511 "definition, skipping rest"), *p
);
3513 utp
= get_uploaded_tp (num
, addr
, utpp
);
3515 utp
->enabled
= enabled
;
3518 utp
->cond
= std::move (cond
);
3520 else if (piece
== 'A')
3522 utp
= get_uploaded_tp (num
, addr
, utpp
);
3523 utp
->actions
.emplace_back (xstrdup (p
));
3525 else if (piece
== 'S')
3527 utp
= get_uploaded_tp (num
, addr
, utpp
);
3528 utp
->step_actions
.emplace_back (xstrdup (p
));
3530 else if (piece
== 'Z')
3532 /* Parse a chunk of source form definition. */
3533 utp
= get_uploaded_tp (num
, addr
, utpp
);
3535 p
= strchr (p
, ':');
3536 p
++; /* skip a colon */
3537 p
= unpack_varlen_hex (p
, &start
);
3538 p
++; /* skip a colon */
3539 p
= unpack_varlen_hex (p
, &xlen
);
3540 p
++; /* skip a colon */
3542 buf
= (char *) alloca (strlen (line
));
3544 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3547 if (startswith (srctype
, "at:"))
3548 utp
->at_string
.reset (xstrdup (buf
));
3549 else if (startswith (srctype
, "cond:"))
3550 utp
->cond_string
.reset (xstrdup (buf
));
3551 else if (startswith (srctype
, "cmd:"))
3552 utp
->cmd_strings
.emplace_back (xstrdup (buf
));
3554 else if (piece
== 'V')
3556 utp
= get_uploaded_tp (num
, addr
, utpp
);
3558 parse_tracepoint_status (p
, NULL
, utp
);
3562 /* Don't error out, the target might be sending us optional
3563 info that we don't care about. */
3564 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece
);
3568 /* Convert a textual description of a trace state variable into an
3572 parse_tsv_definition (const char *line
, struct uploaded_tsv
**utsvp
)
3576 ULONGEST num
, initval
, builtin
;
3578 struct uploaded_tsv
*utsv
= NULL
;
3580 buf
= (char *) alloca (strlen (line
));
3583 p
= unpack_varlen_hex (p
, &num
);
3584 p
++; /* skip a colon */
3585 p
= unpack_varlen_hex (p
, &initval
);
3586 p
++; /* skip a colon */
3587 p
= unpack_varlen_hex (p
, &builtin
);
3588 p
++; /* skip a colon */
3589 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3592 utsv
= get_uploaded_tsv (num
, utsvp
);
3593 utsv
->initial_value
= initval
;
3594 utsv
->builtin
= builtin
;
3595 utsv
->name
= xstrdup (buf
);
3598 /* Given a line of text defining a static tracepoint marker, parse it
3599 into a "static tracepoint marker" object. Throws an error is
3600 parsing fails. If PP is non-null, it points to one past the end of
3601 the parsed marker definition. */
3604 parse_static_tracepoint_marker_definition (const char *line
, const char **pp
,
3605 static_tracepoint_marker
*marker
)
3607 const char *p
, *endp
;
3611 p
= unpack_varlen_hex (p
, &addr
);
3612 p
++; /* skip a colon */
3614 marker
->gdbarch
= target_gdbarch ();
3615 marker
->address
= (CORE_ADDR
) addr
;
3617 endp
= strchr (p
, ':');
3619 error (_("bad marker definition: %s"), line
);
3621 marker
->str_id
= hex2str (p
, (endp
- p
) / 2);
3624 p
++; /* skip a colon */
3626 /* This definition may be followed by another one, separated by a comma. */
3628 endp
= strchr (p
, ',');
3629 if (endp
!= nullptr)
3632 hex_len
= strlen (p
);
3634 marker
->extra
= hex2str (p
, hex_len
/ 2);
3640 /* Print MARKER to gdb_stdout. */
3643 print_one_static_tracepoint_marker (int count
,
3644 const static_tracepoint_marker
&marker
)
3648 char wrap_indent
[80];
3649 char extra_field_indent
[80];
3650 struct ui_out
*uiout
= current_uiout
;
3652 symtab_and_line sal
;
3653 sal
.pc
= marker
.address
;
3655 std::vector
<breakpoint
*> tracepoints
3656 = static_tracepoints_here (marker
.address
);
3658 ui_out_emit_tuple
tuple_emitter (uiout
, "marker");
3660 /* A counter field to help readability. This is not a stable
3662 uiout
->field_signed ("count", count
);
3664 uiout
->field_string ("marker-id", marker
.str_id
.c_str ());
3666 uiout
->field_fmt ("enabled", "%c",
3667 !tracepoints
.empty () ? 'y' : 'n');
3670 strcpy (wrap_indent
, " ");
3672 if (gdbarch_addr_bit (marker
.gdbarch
) <= 32)
3673 strcat (wrap_indent
, " ");
3675 strcat (wrap_indent
, " ");
3677 strcpy (extra_field_indent
, " ");
3679 uiout
->field_core_addr ("addr", marker
.gdbarch
, marker
.address
);
3681 sal
= find_pc_line (marker
.address
, 0);
3682 sym
= find_pc_sect_function (marker
.address
, NULL
);
3685 uiout
->text ("in ");
3686 uiout
->field_string ("func", sym
->print_name (),
3687 function_name_style
.style ());
3688 uiout
->wrap_hint (wrap_indent
);
3689 uiout
->text (" at ");
3692 uiout
->field_skip ("func");
3694 if (sal
.symtab
!= NULL
)
3696 uiout
->field_string ("file",
3697 symtab_to_filename_for_display (sal
.symtab
),
3698 file_name_style
.style ());
3701 if (uiout
->is_mi_like_p ())
3703 const char *fullname
= symtab_to_fullname (sal
.symtab
);
3705 uiout
->field_string ("fullname", fullname
);
3708 uiout
->field_skip ("fullname");
3710 uiout
->field_signed ("line", sal
.line
);
3714 uiout
->field_skip ("fullname");
3715 uiout
->field_skip ("line");
3719 uiout
->text (extra_field_indent
);
3720 uiout
->text (_("Data: \""));
3721 uiout
->field_string ("extra-data", marker
.extra
.c_str ());
3722 uiout
->text ("\"\n");
3724 if (!tracepoints
.empty ())
3729 ui_out_emit_tuple
inner_tuple_emitter (uiout
, "tracepoints-at");
3731 uiout
->text (extra_field_indent
);
3732 uiout
->text (_("Probed by static tracepoints: "));
3733 for (ix
= 0; ix
< tracepoints
.size (); ix
++)
3738 uiout
->field_signed ("tracepoint-id", tracepoints
[ix
]->number
);
3742 if (uiout
->is_mi_like_p ())
3743 uiout
->field_signed ("number-of-tracepoints", tracepoints
.size ());
3750 info_static_tracepoint_markers_command (const char *arg
, int from_tty
)
3752 struct ui_out
*uiout
= current_uiout
;
3753 std::vector
<static_tracepoint_marker
> markers
3754 = target_static_tracepoint_markers_by_strid (NULL
);
3756 /* We don't have to check target_can_use_agent and agent's capability on
3757 static tracepoint here, in order to be compatible with older GDBserver.
3758 We don't check USE_AGENT is true or not, because static tracepoints
3759 don't work without in-process agent, so we don't bother users to type
3760 `set agent on' when to use static tracepoint. */
3762 ui_out_emit_table
table_emitter (uiout
, 5, -1,
3763 "StaticTracepointMarkersTable");
3765 uiout
->table_header (7, ui_left
, "counter", "Cnt");
3767 uiout
->table_header (40, ui_left
, "marker-id", "ID");
3769 uiout
->table_header (3, ui_left
, "enabled", "Enb");
3770 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
3771 uiout
->table_header (10, ui_left
, "addr", "Address");
3773 uiout
->table_header (18, ui_left
, "addr", "Address");
3774 uiout
->table_header (40, ui_noalign
, "what", "What");
3776 uiout
->table_body ();
3778 for (int i
= 0; i
< markers
.size (); i
++)
3779 print_one_static_tracepoint_marker (i
+ 1, markers
[i
]);
3782 /* The $_sdata convenience variable is a bit special. We don't know
3783 for sure type of the value until we actually have a chance to fetch
3784 the data --- the size of the object depends on what has been
3785 collected. We solve this by making $_sdata be an internalvar that
3786 creates a new value on access. */
3788 /* Return a new value with the correct type for the sdata object of
3789 the current trace frame. Return a void value if there's no object
3792 static struct value
*
3793 sdata_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
3796 /* We need to read the whole object before we know its size. */
3797 gdb::optional
<gdb::byte_vector
> buf
3798 = target_read_alloc (current_top_target (), TARGET_OBJECT_STATIC_TRACE_DATA
,
3805 type
= init_vector_type (builtin_type (gdbarch
)->builtin_true_char
,
3807 v
= allocate_value (type
);
3808 memcpy (value_contents_raw (v
), buf
->data (), buf
->size ());
3812 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
3815 #if !defined(HAVE_LIBEXPAT)
3817 struct std::unique_ptr
<traceframe_info
>
3818 parse_traceframe_info (const char *tframe_info
)
3820 static int have_warned
;
3825 warning (_("Can not parse XML trace frame info; XML support "
3826 "was disabled at compile time"));
3832 #else /* HAVE_LIBEXPAT */
3834 #include "xml-support.h"
3836 /* Handle the start of a <memory> element. */
3839 traceframe_info_start_memory (struct gdb_xml_parser
*parser
,
3840 const struct gdb_xml_element
*element
,
3842 std::vector
<gdb_xml_value
> &attributes
)
3844 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
3845 ULONGEST
*start_p
, *length_p
;
3848 = (ULONGEST
*) xml_find_attribute (attributes
, "start")->value
.get ();
3850 = (ULONGEST
*) xml_find_attribute (attributes
, "length")->value
.get ();
3852 info
->memory
.emplace_back (*start_p
, *length_p
);
3855 /* Handle the start of a <tvar> element. */
3858 traceframe_info_start_tvar (struct gdb_xml_parser
*parser
,
3859 const struct gdb_xml_element
*element
,
3861 std::vector
<gdb_xml_value
> &attributes
)
3863 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
3864 const char *id_attrib
3865 = (const char *) xml_find_attribute (attributes
, "id")->value
.get ();
3866 int id
= gdb_xml_parse_ulongest (parser
, id_attrib
);
3868 info
->tvars
.push_back (id
);
3871 /* The allowed elements and attributes for an XML memory map. */
3873 static const struct gdb_xml_attribute memory_attributes
[] = {
3874 { "start", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
3875 { "length", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
3876 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3879 static const struct gdb_xml_attribute tvar_attributes
[] = {
3880 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
3881 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
3884 static const struct gdb_xml_element traceframe_info_children
[] = {
3885 { "memory", memory_attributes
, NULL
,
3886 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3887 traceframe_info_start_memory
, NULL
},
3888 { "tvar", tvar_attributes
, NULL
,
3889 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
3890 traceframe_info_start_tvar
, NULL
},
3891 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3894 static const struct gdb_xml_element traceframe_info_elements
[] = {
3895 { "traceframe-info", NULL
, traceframe_info_children
, GDB_XML_EF_NONE
,
3897 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
3900 /* Parse a traceframe-info XML document. */
3903 parse_traceframe_info (const char *tframe_info
)
3905 traceframe_info_up
result (new traceframe_info
);
3907 if (gdb_xml_parse_quick (_("trace frame info"),
3908 "traceframe-info.dtd", traceframe_info_elements
,
3909 tframe_info
, result
.get ()) == 0)
3915 #endif /* HAVE_LIBEXPAT */
3917 /* Returns the traceframe_info object for the current traceframe.
3918 This is where we avoid re-fetching the object from the target if we
3919 already have it cached. */
3921 struct traceframe_info
*
3922 get_traceframe_info (void)
3924 if (current_traceframe_info
== NULL
)
3925 current_traceframe_info
= target_traceframe_info ();
3927 return current_traceframe_info
.get ();
3930 /* If the target supports the query, return in RESULT the set of
3931 collected memory in the current traceframe, found within the LEN
3932 bytes range starting at MEMADDR. Returns true if the target
3933 supports the query, otherwise returns false, and RESULT is left
3937 traceframe_available_memory (std::vector
<mem_range
> *result
,
3938 CORE_ADDR memaddr
, ULONGEST len
)
3940 struct traceframe_info
*info
= get_traceframe_info ();
3946 for (mem_range
&r
: info
->memory
)
3947 if (mem_ranges_overlap (r
.start
, r
.length
, memaddr
, len
))
3949 ULONGEST lo1
, hi1
, lo2
, hi2
;
3952 hi1
= memaddr
+ len
;
3955 hi2
= r
.start
+ r
.length
;
3957 CORE_ADDR start
= std::max (lo1
, lo2
);
3958 int length
= std::min (hi1
, hi2
) - start
;
3960 result
->emplace_back (start
, length
);
3963 normalize_mem_ranges (result
);
3970 /* Implementation of `sdata' variable. */
3972 static const struct internalvar_funcs sdata_funcs
=
3979 /* See tracepoint.h. */
3980 cmd_list_element
*while_stepping_cmd_element
= nullptr;
3982 /* module initialization */
3984 _initialize_tracepoint (void)
3986 struct cmd_list_element
*c
;
3988 /* Explicitly create without lookup, since that tries to create a
3989 value with a void typed value, and when we get here, gdbarch
3990 isn't initialized yet. At this point, we're quite sure there
3991 isn't another convenience variable of the same name. */
3992 create_internalvar_type_lazy ("_sdata", &sdata_funcs
, NULL
);
3994 traceframe_number
= -1;
3995 tracepoint_number
= -1;
3997 add_info ("scope", info_scope_command
,
3998 _("List the variables local to a scope."));
4000 add_cmd ("tracepoints", class_trace
,
4001 _("Tracing of program execution without stopping the program."),
4004 add_com ("tdump", class_trace
, tdump_command
,
4005 _("Print everything collected at the current tracepoint."));
4007 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
4008 Define a trace state variable.\n\
4009 Argument is a $-prefixed name, optionally followed\n\
4010 by '=' and an expression that sets the initial value\n\
4011 at the start of tracing."));
4012 set_cmd_completer (c
, expression_completer
);
4014 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
4015 Delete one or more trace state variables.\n\
4016 Arguments are the names of the variables to delete.\n\
4017 If no arguments are supplied, delete all variables."), &deletelist
);
4018 /* FIXME add a trace variable completer. */
4020 add_info ("tvariables", info_tvariables_command
, _("\
4021 Status of trace state variables and their values."));
4023 add_info ("static-tracepoint-markers",
4024 info_static_tracepoint_markers_command
, _("\
4025 List target static tracepoints markers."));
4027 add_prefix_cmd ("tfind", class_trace
, tfind_command
, _("\
4028 Select a trace frame.\n\
4029 No argument means forward by one frame; '-' means backward by one frame."),
4030 &tfindlist
, "tfind ", 1, &cmdlist
);
4032 add_cmd ("outside", class_trace
, tfind_outside_command
, _("\
4033 Select a trace frame whose PC is outside the given range (exclusive).\n\
4034 Usage: tfind outside ADDR1, ADDR2"),
4037 add_cmd ("range", class_trace
, tfind_range_command
, _("\
4038 Select a trace frame whose PC is in the given range (inclusive).\n\
4039 Usage: tfind range ADDR1, ADDR2"),
4042 add_cmd ("line", class_trace
, tfind_line_command
, _("\
4043 Select a trace frame by source line.\n\
4044 Argument can be a line number (with optional source file),\n\
4045 a function name, or '*' followed by an address.\n\
4046 Default argument is 'the next source line that was traced'."),
4049 add_cmd ("tracepoint", class_trace
, tfind_tracepoint_command
, _("\
4050 Select a trace frame by tracepoint number.\n\
4051 Default is the tracepoint for the current trace frame."),
4054 add_cmd ("pc", class_trace
, tfind_pc_command
, _("\
4055 Select a trace frame by PC.\n\
4056 Default is the current PC, or the PC of the current trace frame."),
4059 add_cmd ("end", class_trace
, tfind_end_command
, _("\
4060 De-select any trace frame and resume 'live' debugging."),
4063 add_alias_cmd ("none", "end", class_trace
, 0, &tfindlist
);
4065 add_cmd ("start", class_trace
, tfind_start_command
,
4066 _("Select the first trace frame in the trace buffer."),
4069 add_com ("tstatus", class_trace
, tstatus_command
,
4070 _("Display the status of the current trace data collection."));
4072 add_com ("tstop", class_trace
, tstop_command
, _("\
4073 Stop trace data collection.\n\
4074 Usage: tstop [NOTES]...\n\
4075 Any arguments supplied are recorded with the trace as a stop reason and\n\
4076 reported by tstatus (if the target supports trace notes)."));
4078 add_com ("tstart", class_trace
, tstart_command
, _("\
4079 Start trace data collection.\n\
4080 Usage: tstart [NOTES]...\n\
4081 Any arguments supplied are recorded with the trace as a note and\n\
4082 reported by tstatus (if the target supports trace notes)."));
4084 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
4085 Ends a list of commands or actions.\n\
4086 Several GDB commands allow you to enter a list of commands or actions.\n\
4087 Entering \"end\" on a line by itself is the normal way to terminate\n\
4089 Note: the \"end\" command cannot be used at the gdb prompt."));
4091 while_stepping_cmd_element
= add_com ("while-stepping", class_trace
,
4092 while_stepping_pseudocommand
, _("\
4093 Specify single-stepping behavior at a tracepoint.\n\
4094 Argument is number of instructions to trace in single-step mode\n\
4095 following the tracepoint. This command is normally followed by\n\
4096 one or more \"collect\" commands, to specify what to collect\n\
4097 while single-stepping.\n\n\
4098 Note: this command can only be used in a tracepoint \"actions\" list."));
4100 add_com_alias ("ws", "while-stepping", class_alias
, 0);
4101 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
4103 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
4104 Specify one or more data items to be collected at a tracepoint.\n\
4105 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4106 collect all data (variables, registers) referenced by that expression.\n\
4107 Also accepts the following special arguments:\n\
4108 $regs -- all registers.\n\
4109 $args -- all function arguments.\n\
4110 $locals -- all variables local to the block/function scope.\n\
4111 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
4112 Note: this command can only be used in a tracepoint \"actions\" list."));
4114 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
4115 Specify one or more expressions to be evaluated at a tracepoint.\n\
4116 Accepts a comma-separated list of (one or more) expressions.\n\
4117 The result of each evaluation will be discarded.\n\
4118 Note: this command can only be used in a tracepoint \"actions\" list."));
4120 add_com ("actions", class_trace
, actions_command
, _("\
4121 Specify the actions to be taken at a tracepoint.\n\
4122 Tracepoint actions may include collecting of specified data,\n\
4123 single-stepping, or enabling/disabling other tracepoints,\n\
4124 depending on target's capabilities."));
4126 default_collect
= xstrdup ("");
4127 add_setshow_string_cmd ("default-collect", class_trace
,
4128 &default_collect
, _("\
4129 Set the list of expressions to collect by default."), _("\
4130 Show the list of expressions to collect by default."), NULL
,
4132 &setlist
, &showlist
);
4134 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
4135 &disconnected_tracing
, _("\
4136 Set whether tracing continues after GDB disconnects."), _("\
4137 Show whether tracing continues after GDB disconnects."), _("\
4138 Use this to continue a tracing run even if GDB disconnects\n\
4139 or detaches from the target. You can reconnect later and look at\n\
4140 trace data collected in the meantime."),
4141 set_disconnected_tracing
,
4146 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
4147 &circular_trace_buffer
, _("\
4148 Set target's use of circular trace buffer."), _("\
4149 Show target's use of circular trace buffer."), _("\
4150 Use this to make the trace buffer into a circular buffer,\n\
4151 which will discard traceframes (oldest first) instead of filling\n\
4152 up and stopping the trace run."),
4153 set_circular_trace_buffer
,
4158 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class
,
4159 &trace_buffer_size
, _("\
4160 Set requested size of trace buffer."), _("\
4161 Show requested size of trace buffer."), _("\
4162 Use this to choose a size for the trace buffer. Some targets\n\
4163 may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
4164 disables any attempt to set the buffer size and lets the target choose."),
4165 set_trace_buffer_size
, NULL
,
4166 &setlist
, &showlist
);
4168 add_setshow_string_cmd ("trace-user", class_trace
,
4170 Set the user name to use for current and future trace runs."), _("\
4171 Show the user name to use for current and future trace runs."), NULL
,
4172 set_trace_user
, NULL
,
4173 &setlist
, &showlist
);
4175 add_setshow_string_cmd ("trace-notes", class_trace
,
4177 Set notes string to use for current and future trace runs."), _("\
4178 Show the notes string to use for current and future trace runs."), NULL
,
4179 set_trace_notes
, NULL
,
4180 &setlist
, &showlist
);
4182 add_setshow_string_cmd ("trace-stop-notes", class_trace
,
4183 &trace_stop_notes
, _("\
4184 Set notes string to use for future tstop commands."), _("\
4185 Show the notes string to use for future tstop commands."), NULL
,
4186 set_trace_stop_notes
, NULL
,
4187 &setlist
, &showlist
);