1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
25 #include "expression.h"
29 #include "target-dcache.h"
32 #include "breakpoint.h"
33 #include "tracepoint.h"
36 #include "completer.h"
38 #include "dictionary.h"
40 #include "user-regs.h"
44 #include "filenames.h"
45 #include "gdbthread.h"
52 #include "cli/cli-utils.h"
55 #include "filestuff.h"
57 #include "tracefile.h"
61 /* readline include files */
62 #include "readline/readline.h"
63 #include "readline/history.h"
65 /* readline defines this. */
70 /* Maximum length of an agent aexpression.
71 This accounts for the fact that packets are limited to 400 bytes
72 (which includes everything -- including the checksum), and assumes
73 the worst case of maximum length for each of the pieces of a
76 NOTE: expressions get mem2hex'ed otherwise this would be twice as
77 large. (400 - 31)/2 == 184 */
78 #define MAX_AGENT_EXPR_LEN 184
80 /* A hook used to notify the UI of tracepoint operations. */
82 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
83 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
88 This module defines the following debugger commands:
89 trace : set a tracepoint on a function, line, or address.
90 info trace : list all debugger-defined tracepoints.
91 delete trace : delete one or more tracepoints.
92 enable trace : enable one or more tracepoints.
93 disable trace : disable one or more tracepoints.
94 actions : specify actions to be taken at a tracepoint.
95 passcount : specify a pass count for a tracepoint.
96 tstart : start a trace experiment.
97 tstop : stop a trace experiment.
98 tstatus : query the status of a trace experiment.
99 tfind : find a trace frame in the trace buffer.
100 tdump : print everything collected at the current tracepoint.
101 save-tracepoints : write tracepoint setup into a file.
103 This module defines the following user-visible debugger variables:
104 $trace_frame : sequence number of trace frame currently being debugged.
105 $trace_line : source line of trace frame currently being debugged.
106 $trace_file : source file of trace frame currently being debugged.
107 $tracepoint : tracepoint number of trace frame currently being debugged.
111 /* ======= Important global variables: ======= */
113 /* The list of all trace state variables. We don't retain pointers to
114 any of these for any reason - API is by name or number only - so it
115 works to have a vector of objects. */
117 typedef struct trace_state_variable tsv_s
;
120 static VEC(tsv_s
) *tvariables
;
122 /* The next integer to assign to a variable. */
124 static int next_tsv_number
= 1;
126 /* Number of last traceframe collected. */
127 static int traceframe_number
;
129 /* Tracepoint for last traceframe collected. */
130 static int tracepoint_number
;
132 /* The traceframe info of the current traceframe. NULL if we haven't
133 yet attempted to fetch it, or if the target does not support
134 fetching this object, or if we're not inspecting a traceframe
136 static struct traceframe_info
*traceframe_info
;
138 /* Tracing command lists. */
139 static struct cmd_list_element
*tfindlist
;
141 /* List of expressions to collect by default at each tracepoint hit. */
142 char *default_collect
= "";
144 static int disconnected_tracing
;
146 /* This variable controls whether we ask the target for a linear or
147 circular trace buffer. */
149 static int circular_trace_buffer
;
151 /* This variable is the requested trace buffer size, or -1 to indicate
152 that we don't care and leave it up to the target to set a size. */
154 static int trace_buffer_size
= -1;
156 /* Textual notes applying to the current and/or future trace runs. */
158 char *trace_user
= NULL
;
160 /* Textual notes applying to the current and/or future trace runs. */
162 char *trace_notes
= NULL
;
164 /* Textual notes applying to the stopping of a trace. */
166 char *trace_stop_notes
= NULL
;
168 /* ======= Important command functions: ======= */
169 static void trace_actions_command (char *, int);
170 static void trace_start_command (char *, int);
171 static void trace_stop_command (char *, int);
172 static void trace_status_command (char *, int);
173 static void trace_find_command (char *, int);
174 static void trace_find_pc_command (char *, int);
175 static void trace_find_tracepoint_command (char *, int);
176 static void trace_find_line_command (char *, int);
177 static void trace_find_range_command (char *, int);
178 static void trace_find_outside_command (char *, int);
179 static void trace_dump_command (char *, int);
181 /* support routines */
183 struct collection_list
;
184 static char *mem2hex (gdb_byte
*, char *, int);
186 static struct command_line
*
187 all_tracepoint_actions_and_cleanup (struct breakpoint
*t
);
189 extern void _initialize_tracepoint (void);
191 static struct trace_status trace_status
;
193 const char *stop_reason_names
[] = {
203 struct trace_status
*
204 current_trace_status (void)
206 return &trace_status
;
212 free_traceframe_info (struct traceframe_info
*info
)
216 VEC_free (mem_range_s
, info
->memory
);
217 VEC_free (int, info
->tvars
);
223 /* Free and clear the traceframe info cache of the current
227 clear_traceframe_info (void)
229 free_traceframe_info (traceframe_info
);
230 traceframe_info
= NULL
;
233 /* Set traceframe number to NUM. */
235 set_traceframe_num (int num
)
237 traceframe_number
= num
;
238 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
241 /* Set tracepoint number to NUM. */
243 set_tracepoint_num (int num
)
245 tracepoint_number
= num
;
246 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
249 /* Set externally visible debug variables for querying/printing
250 the traceframe context (line, function, file). */
253 set_traceframe_context (struct frame_info
*trace_frame
)
256 struct symbol
*traceframe_fun
;
257 struct symtab_and_line traceframe_sal
;
259 /* Save as globals for internal use. */
260 if (trace_frame
!= NULL
261 && get_frame_pc_if_available (trace_frame
, &trace_pc
))
263 traceframe_sal
= find_pc_line (trace_pc
, 0);
264 traceframe_fun
= find_pc_function (trace_pc
);
266 /* Save linenumber as "$trace_line", a debugger variable visible to
268 set_internalvar_integer (lookup_internalvar ("trace_line"),
269 traceframe_sal
.line
);
273 init_sal (&traceframe_sal
);
274 traceframe_fun
= NULL
;
275 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
278 /* Save func name as "$trace_func", a debugger variable visible to
280 if (traceframe_fun
== NULL
281 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
282 clear_internalvar (lookup_internalvar ("trace_func"));
284 set_internalvar_string (lookup_internalvar ("trace_func"),
285 SYMBOL_LINKAGE_NAME (traceframe_fun
));
287 /* Save file name as "$trace_file", a debugger variable visible to
289 if (traceframe_sal
.symtab
== NULL
)
290 clear_internalvar (lookup_internalvar ("trace_file"));
292 set_internalvar_string (lookup_internalvar ("trace_file"),
293 symtab_to_filename_for_display (traceframe_sal
.symtab
));
296 /* Create a new trace state variable with the given name. */
298 struct trace_state_variable
*
299 create_trace_state_variable (const char *name
)
301 struct trace_state_variable tsv
;
303 memset (&tsv
, 0, sizeof (tsv
));
304 tsv
.name
= xstrdup (name
);
305 tsv
.number
= next_tsv_number
++;
306 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
309 /* Look for a trace state variable of the given name. */
311 struct trace_state_variable
*
312 find_trace_state_variable (const char *name
)
314 struct trace_state_variable
*tsv
;
317 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
318 if (strcmp (name
, tsv
->name
) == 0)
324 /* Look for a trace state variable of the given number. Return NULL if
327 struct trace_state_variable
*
328 find_trace_state_variable_by_number (int number
)
330 struct trace_state_variable
*tsv
;
333 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
334 if (tsv
->number
== number
)
341 delete_trace_state_variable (const char *name
)
343 struct trace_state_variable
*tsv
;
346 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
347 if (strcmp (name
, tsv
->name
) == 0)
349 observer_notify_tsv_deleted (tsv
);
351 xfree ((void *)tsv
->name
);
352 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
357 warning (_("No trace variable named \"$%s\", not deleting"), name
);
360 /* Throws an error if NAME is not valid syntax for a trace state
364 validate_trace_state_variable_name (const char *name
)
369 error (_("Must supply a non-empty variable name"));
371 /* All digits in the name is reserved for value history
373 for (p
= name
; isdigit (*p
); p
++)
376 error (_("$%s is not a valid trace state variable name"), name
);
378 for (p
= name
; isalnum (*p
) || *p
== '_'; p
++)
381 error (_("$%s is not a valid trace state variable name"), name
);
384 /* The 'tvariable' command collects a name and optional expression to
385 evaluate into an initial value. */
388 trace_variable_command (char *args
, int from_tty
)
390 struct cleanup
*old_chain
;
392 struct trace_state_variable
*tsv
;
396 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
398 /* Only allow two syntaxes; "$name" and "$name=value". */
399 p
= skip_spaces (args
);
402 error (_("Name of trace variable should start with '$'"));
405 while (isalnum (*p
) || *p
== '_')
407 name
= savestring (name
, p
- name
);
408 old_chain
= make_cleanup (xfree
, name
);
411 if (*p
!= '=' && *p
!= '\0')
412 error (_("Syntax must be $NAME [ = EXPR ]"));
414 validate_trace_state_variable_name (name
);
417 initval
= value_as_long (parse_and_eval (++p
));
419 /* If the variable already exists, just change its initial value. */
420 tsv
= find_trace_state_variable (name
);
423 if (tsv
->initial_value
!= initval
)
425 tsv
->initial_value
= initval
;
426 observer_notify_tsv_modified (tsv
);
428 printf_filtered (_("Trace state variable $%s "
429 "now has initial value %s.\n"),
430 tsv
->name
, plongest (tsv
->initial_value
));
431 do_cleanups (old_chain
);
435 /* Create a new variable. */
436 tsv
= create_trace_state_variable (name
);
437 tsv
->initial_value
= initval
;
439 observer_notify_tsv_created (tsv
);
441 printf_filtered (_("Trace state variable $%s "
442 "created, with initial value %s.\n"),
443 tsv
->name
, plongest (tsv
->initial_value
));
445 do_cleanups (old_chain
);
449 delete_trace_variable_command (char *args
, int from_tty
)
453 struct cleanup
*back_to
;
457 if (query (_("Delete all trace state variables? ")))
458 VEC_free (tsv_s
, tvariables
);
460 observer_notify_tsv_deleted (NULL
);
464 argv
= gdb_buildargv (args
);
465 back_to
= make_cleanup_freeargv (argv
);
467 for (ix
= 0; argv
[ix
] != NULL
; ix
++)
469 if (*argv
[ix
] == '$')
470 delete_trace_state_variable (argv
[ix
] + 1);
472 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv
[ix
]);
475 do_cleanups (back_to
);
481 tvariables_info_1 (void)
483 struct trace_state_variable
*tsv
;
486 struct cleanup
*back_to
;
487 struct ui_out
*uiout
= current_uiout
;
489 if (VEC_length (tsv_s
, tvariables
) == 0 && !ui_out_is_mi_like_p (uiout
))
491 printf_filtered (_("No trace state variables.\n"));
495 /* Try to acquire values from the target. */
496 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
, ++count
)
497 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
500 back_to
= make_cleanup_ui_out_table_begin_end (uiout
, 3,
501 count
, "trace-variables");
502 ui_out_table_header (uiout
, 15, ui_left
, "name", "Name");
503 ui_out_table_header (uiout
, 11, ui_left
, "initial", "Initial");
504 ui_out_table_header (uiout
, 11, ui_left
, "current", "Current");
506 ui_out_table_body (uiout
);
508 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
510 struct cleanup
*back_to2
;
514 back_to2
= make_cleanup_ui_out_tuple_begin_end (uiout
, "variable");
516 name
= concat ("$", tsv
->name
, (char *) NULL
);
517 make_cleanup (xfree
, name
);
518 ui_out_field_string (uiout
, "name", name
);
519 ui_out_field_string (uiout
, "initial", plongest (tsv
->initial_value
));
521 if (tsv
->value_known
)
522 c
= plongest (tsv
->value
);
523 else if (ui_out_is_mi_like_p (uiout
))
524 /* For MI, we prefer not to use magic string constants, but rather
525 omit the field completely. The difference between unknown and
526 undefined does not seem important enough to represent. */
528 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
529 /* The value is/was defined, but we don't have it. */
532 /* It is not meaningful to ask about the value. */
535 ui_out_field_string (uiout
, "current", c
);
536 ui_out_text (uiout
, "\n");
538 do_cleanups (back_to2
);
541 do_cleanups (back_to
);
544 /* List all the trace state variables. */
547 tvariables_info (char *args
, int from_tty
)
549 tvariables_info_1 ();
552 /* Stash definitions of tsvs into the given file. */
555 save_trace_state_variables (struct ui_file
*fp
)
557 struct trace_state_variable
*tsv
;
560 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
562 fprintf_unfiltered (fp
, "tvariable $%s", tsv
->name
);
563 if (tsv
->initial_value
)
564 fprintf_unfiltered (fp
, " = %s", plongest (tsv
->initial_value
));
565 fprintf_unfiltered (fp
, "\n");
569 /* ACTIONS functions: */
571 /* The three functions:
572 collect_pseudocommand,
573 while_stepping_pseudocommand, and
574 end_actions_pseudocommand
575 are placeholders for "commands" that are actually ONLY to be used
576 within a tracepoint action list. If the actual function is ever called,
577 it means that somebody issued the "command" at the top level,
578 which is always an error. */
581 end_actions_pseudocommand (char *args
, int from_tty
)
583 error (_("This command cannot be used at the top level."));
587 while_stepping_pseudocommand (char *args
, int from_tty
)
589 error (_("This command can only be used in a tracepoint actions list."));
593 collect_pseudocommand (char *args
, int from_tty
)
595 error (_("This command can only be used in a tracepoint actions list."));
599 teval_pseudocommand (char *args
, int from_tty
)
601 error (_("This command can only be used in a tracepoint actions list."));
604 /* Parse any collection options, such as /s for strings. */
607 decode_agent_options (const char *exp
, int *trace_string
)
609 struct value_print_options opts
;
616 /* Call this to borrow the print elements default for collection
618 get_user_print_options (&opts
);
623 if (target_supports_string_tracing ())
625 /* Allow an optional decimal number giving an explicit maximum
626 string length, defaulting it to the "print elements" value;
627 so "collect/s80 mystr" gets at most 80 bytes of string. */
628 *trace_string
= opts
.print_max
;
630 if (*exp
>= '0' && *exp
<= '9')
631 *trace_string
= atoi (exp
);
632 while (*exp
>= '0' && *exp
<= '9')
636 error (_("Target does not support \"/s\" option for string tracing."));
639 error (_("Undefined collection format \"%c\"."), *exp
);
641 exp
= skip_spaces_const (exp
);
646 /* Enter a list of actions for a tracepoint. */
648 trace_actions_command (char *args
, int from_tty
)
650 struct tracepoint
*t
;
651 struct command_line
*l
;
653 t
= get_tracepoint_by_number (&args
, NULL
);
657 xstrprintf ("Enter actions for tracepoint %d, one per line.",
659 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
661 l
= read_command_lines (tmpbuf
, from_tty
, 1,
662 check_tracepoint_command
, t
);
663 do_cleanups (cleanups
);
664 breakpoint_set_commands (&t
->base
, l
);
666 /* else just return */
669 /* Report the results of checking the agent expression, as errors or
673 report_agent_reqs_errors (struct agent_expr
*aexpr
)
675 /* All of the "flaws" are serious bytecode generation issues that
676 should never occur. */
677 if (aexpr
->flaw
!= agent_flaw_none
)
678 internal_error (__FILE__
, __LINE__
, _("expression is malformed"));
680 /* If analysis shows a stack underflow, GDB must have done something
681 badly wrong in its bytecode generation. */
682 if (aexpr
->min_height
< 0)
683 internal_error (__FILE__
, __LINE__
,
684 _("expression has min height < 0"));
686 /* Issue this error if the stack is predicted to get too deep. The
687 limit is rather arbitrary; a better scheme might be for the
688 target to report how much stack it will have available. The
689 depth roughly corresponds to parenthesization, so a limit of 20
690 amounts to 20 levels of expression nesting, which is actually
691 a pretty big hairy expression. */
692 if (aexpr
->max_height
> 20)
693 error (_("Expression is too complicated."));
696 /* worker function */
698 validate_actionline (const char *line
, struct breakpoint
*b
)
700 struct cmd_list_element
*c
;
701 struct cleanup
*old_chain
= NULL
;
704 struct bp_location
*loc
;
705 struct agent_expr
*aexpr
;
706 struct tracepoint
*t
= (struct tracepoint
*) b
;
708 /* If EOF is typed, *line is NULL. */
712 p
= skip_spaces_const (line
);
714 /* Symbol lookup etc. */
715 if (*p
== '\0') /* empty line: just prompt for another line. */
718 if (*p
== '#') /* comment line */
721 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
723 error (_("`%s' is not a tracepoint action, or is ambiguous."), p
);
725 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
727 int trace_string
= 0;
730 p
= decode_agent_options (p
, &trace_string
);
733 { /* Repeat over a comma-separated list. */
734 QUIT
; /* Allow user to bail out with ^C. */
735 p
= skip_spaces_const (p
);
737 if (*p
== '$') /* Look for special pseudo-symbols. */
739 if (0 == strncasecmp ("reg", p
+ 1, 3)
740 || 0 == strncasecmp ("arg", p
+ 1, 3)
741 || 0 == strncasecmp ("loc", p
+ 1, 3)
742 || 0 == strncasecmp ("_ret", p
+ 1, 4)
743 || 0 == strncasecmp ("_sdata", p
+ 1, 6))
748 /* else fall thru, treat p as an expression and parse it! */
751 for (loc
= t
->base
.loc
; loc
; loc
= loc
->next
)
754 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
755 block_for_pc (loc
->address
), 1);
757 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
759 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
761 error (_("constant `%s' (value %s) "
762 "will not be collected."),
763 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
764 plongest (SYMBOL_VALUE (exp
->elts
[2].symbol
)));
766 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
)
767 == LOC_OPTIMIZED_OUT
)
769 error (_("`%s' is optimized away "
770 "and cannot be collected."),
771 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
775 /* We have something to collect, make sure that the expr to
776 bytecode translator can handle it and that it's not too
778 aexpr
= gen_trace_for_expr (loc
->address
, exp
.get (), trace_string
);
779 old_chain
= make_cleanup_free_agent_expr (aexpr
);
781 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
782 error (_("Expression is too complicated."));
786 report_agent_reqs_errors (aexpr
);
788 do_cleanups (old_chain
);
791 while (p
&& *p
++ == ',');
794 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
797 { /* Repeat over a comma-separated list. */
798 QUIT
; /* Allow user to bail out with ^C. */
799 p
= skip_spaces_const (p
);
802 for (loc
= t
->base
.loc
; loc
; loc
= loc
->next
)
806 /* Only expressions are allowed for this action. */
807 expression_up exp
= parse_exp_1 (&p
, loc
->address
,
808 block_for_pc (loc
->address
), 1);
810 /* We have something to evaluate, make sure that the expr to
811 bytecode translator can handle it and that it's not too
813 aexpr
= gen_eval_for_expr (loc
->address
, exp
.get ());
814 old_chain
= make_cleanup_free_agent_expr (aexpr
);
816 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
817 error (_("Expression is too complicated."));
820 report_agent_reqs_errors (aexpr
);
822 do_cleanups (old_chain
);
825 while (p
&& *p
++ == ',');
828 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
832 p
= skip_spaces_const (p
);
833 t
->step_count
= strtol (p
, &endp
, 0);
834 if (endp
== p
|| t
->step_count
== 0)
835 error (_("while-stepping step count `%s' is malformed."), line
);
839 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
843 error (_("`%s' is not a supported tracepoint action."), line
);
847 memrange_absolute
= -1
850 /* MEMRANGE functions: */
852 /* Compare memranges for std::sort. */
855 memrange_comp (const memrange
&a
, const memrange
&b
)
857 if (a
.type
== b
.type
)
859 if (a
.type
== memrange_absolute
)
860 return (bfd_vma
) a
.start
< (bfd_vma
) b
.start
;
862 return a
.start
< b
.start
;
865 return a
.type
< b
.type
;
868 /* Sort the memrange list using std::sort, and merge adjacent memranges. */
871 memrange_sortmerge (std::vector
<memrange
> &memranges
)
873 if (!memranges
.empty ())
877 std::sort (memranges
.begin (), memranges
.end (), memrange_comp
);
879 for (a
= 0, b
= 1; b
< memranges
.size (); b
++)
881 /* If memrange b overlaps or is adjacent to memrange a,
883 if (memranges
[a
].type
== memranges
[b
].type
884 && memranges
[b
].start
<= memranges
[a
].end
)
886 if (memranges
[b
].end
> memranges
[a
].end
)
887 memranges
[a
].end
= memranges
[b
].end
;
888 continue; /* next b, same a */
892 memranges
[a
] = memranges
[b
];
894 memranges
.resize (a
+ 1);
898 /* Add a register to a collection list. */
901 collection_list::add_register (unsigned int regno
)
904 printf_filtered ("collect register %d\n", regno
);
905 if (regno
>= (8 * sizeof (m_regs_mask
)))
906 error (_("Internal: register number %d too large for tracepoint"),
908 m_regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
911 /* Add a memrange to a collection list. */
914 collection_list::add_memrange (int type
, bfd_signed_vma base
,
919 printf_filtered ("(%d,", type
);
921 printf_filtered (",%ld)\n", len
);
924 /* type: memrange_absolute == memory, other n == basereg */
925 /* base: addr if memory, offset if reg relative. */
926 /* len: we actually save end (base + len) for convenience */
927 m_memranges
.push_back (memrange (type
, base
, base
+ len
));
929 if (type
!= memrange_absolute
) /* Better collect the base register! */
933 /* Add a symbol to a collection list. */
936 collection_list::collect_symbol (struct symbol
*sym
,
937 struct gdbarch
*gdbarch
,
938 long frame_regno
, long frame_offset
,
944 bfd_signed_vma offset
;
945 int treat_as_expr
= 0;
947 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
948 switch (SYMBOL_CLASS (sym
))
951 printf_filtered ("%s: don't know symbol class %d\n",
952 SYMBOL_PRINT_NAME (sym
),
956 printf_filtered ("constant %s (value %s) will not be collected.\n",
957 SYMBOL_PRINT_NAME (sym
), plongest (SYMBOL_VALUE (sym
)));
960 offset
= SYMBOL_VALUE_ADDRESS (sym
);
965 sprintf_vma (tmp
, offset
);
966 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
967 SYMBOL_PRINT_NAME (sym
), len
,
970 /* A struct may be a C++ class with static fields, go to general
971 expression handling. */
972 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
975 add_memrange (memrange_absolute
, offset
, len
);
978 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
980 printf_filtered ("LOC_REG[parm] %s: ",
981 SYMBOL_PRINT_NAME (sym
));
983 /* Check for doubles stored in two registers. */
984 /* FIXME: how about larger types stored in 3 or more regs? */
985 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
986 len
> register_size (gdbarch
, reg
))
987 add_register (reg
+ 1);
990 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
991 printf_filtered (" (will not collect %s)\n",
992 SYMBOL_PRINT_NAME (sym
));
996 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
999 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1000 SYMBOL_PRINT_NAME (sym
), len
);
1001 printf_vma (offset
);
1002 printf_filtered (" from frame ptr reg %d\n", reg
);
1004 add_memrange (reg
, offset
, len
);
1006 case LOC_REGPARM_ADDR
:
1007 reg
= SYMBOL_VALUE (sym
);
1011 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1012 SYMBOL_PRINT_NAME (sym
), len
);
1013 printf_vma (offset
);
1014 printf_filtered (" from reg %d\n", reg
);
1016 add_memrange (reg
, offset
, len
);
1020 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1023 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1024 SYMBOL_PRINT_NAME (sym
), len
);
1025 printf_vma (offset
);
1026 printf_filtered (" from frame ptr reg %d\n", reg
);
1028 add_memrange (reg
, offset
, len
);
1031 case LOC_UNRESOLVED
:
1035 case LOC_OPTIMIZED_OUT
:
1036 printf_filtered ("%s has been optimized out of existence.\n",
1037 SYMBOL_PRINT_NAME (sym
));
1045 /* Expressions are the most general case. */
1048 struct agent_expr
*aexpr
;
1049 struct cleanup
*old_chain1
= NULL
;
1051 aexpr
= gen_trace_for_var (scope
, gdbarch
, sym
, trace_string
);
1053 /* It can happen that the symbol is recorded as a computed
1054 location, but it's been optimized away and doesn't actually
1055 have a location expression. */
1058 printf_filtered ("%s has been optimized out of existence.\n",
1059 SYMBOL_PRINT_NAME (sym
));
1063 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1067 report_agent_reqs_errors (aexpr
);
1069 discard_cleanups (old_chain1
);
1072 /* Take care of the registers. */
1073 if (aexpr
->reg_mask_len
> 0)
1077 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1079 QUIT
; /* Allow user to bail out with ^C. */
1080 if (aexpr
->reg_mask
[ndx1
] != 0)
1082 /* Assume chars have 8 bits. */
1083 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1084 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1085 /* It's used -- record it. */
1086 add_register (ndx1
* 8 + ndx2
);
1093 /* Data to be passed around in the calls to the locals and args
1096 struct add_local_symbols_data
1098 struct collection_list
*collect
;
1099 struct gdbarch
*gdbarch
;
1107 /* The callback for the locals and args iterators. */
1110 do_collect_symbol (const char *print_name
,
1114 struct add_local_symbols_data
*p
= (struct add_local_symbols_data
*) cb_data
;
1116 p
->collect
->collect_symbol (sym
, p
->gdbarch
, p
->frame_regno
,
1117 p
->frame_offset
, p
->pc
, p
->trace_string
);
1120 p
->collect
->add_wholly_collected (print_name
);
1124 collection_list::add_wholly_collected (const char *print_name
)
1126 m_wholly_collected
.push_back (print_name
);
1129 /* Add all locals (or args) symbols to collection list. */
1132 collection_list::add_local_symbols (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1133 long frame_regno
, long frame_offset
, int type
,
1136 const struct block
*block
;
1137 struct add_local_symbols_data cb_data
;
1139 cb_data
.collect
= this;
1140 cb_data
.gdbarch
= gdbarch
;
1142 cb_data
.frame_regno
= frame_regno
;
1143 cb_data
.frame_offset
= frame_offset
;
1145 cb_data
.trace_string
= trace_string
;
1149 block
= block_for_pc (pc
);
1152 warning (_("Can't collect locals; "
1153 "no symbol table info available.\n"));
1157 iterate_over_block_local_vars (block
, do_collect_symbol
, &cb_data
);
1158 if (cb_data
.count
== 0)
1159 warning (_("No locals found in scope."));
1163 pc
= get_pc_function_start (pc
);
1164 block
= block_for_pc (pc
);
1167 warning (_("Can't collect args; no symbol table info available."));
1171 iterate_over_block_arg_vars (block
, do_collect_symbol
, &cb_data
);
1172 if (cb_data
.count
== 0)
1173 warning (_("No args found in scope."));
1178 collection_list::add_static_trace_data ()
1181 printf_filtered ("collect static trace data\n");
1182 m_strace_data
= true;
1185 collection_list::collection_list ()
1187 m_strace_data (false)
1189 m_memranges
.reserve (128);
1190 m_aexprs
.reserve (128);
1193 collection_list::~collection_list ()
1195 for (int ndx
= 0; ndx
< m_aexprs
.size (); ndx
++)
1196 free_agent_expr (m_aexprs
[ndx
]);
1199 /* Reduce a collection list to string form (for gdb protocol). */
1202 collection_list::stringify ()
1204 char temp_buf
[2048];
1208 char *(*str_list
)[];
1212 count
= 1 + 1 + m_memranges
.size () + m_aexprs
.size () + 1;
1213 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1218 printf_filtered ("\nCollecting static trace data\n");
1221 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1225 for (i
= sizeof (m_regs_mask
) - 1; i
> 0; i
--)
1226 if (m_regs_mask
[i
] != 0) /* Skip leading zeroes in regs_mask. */
1228 if (m_regs_mask
[i
] != 0) /* Prepare to send regs_mask to the stub. */
1231 printf_filtered ("\nCollecting registers (mask): 0x");
1236 QUIT
; /* Allow user to bail out with ^C. */
1238 printf_filtered ("%02X", m_regs_mask
[i
]);
1239 sprintf (end
, "%02X", m_regs_mask
[i
]);
1242 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1246 printf_filtered ("\n");
1247 if (!m_memranges
.empty () && info_verbose
)
1248 printf_filtered ("Collecting memranges: \n");
1249 for (i
= 0, count
= 0, end
= temp_buf
; i
< m_memranges
.size (); i
++)
1251 QUIT
; /* Allow user to bail out with ^C. */
1252 sprintf_vma (tmp2
, m_memranges
[i
].start
);
1255 printf_filtered ("(%d, %s, %ld)\n",
1256 m_memranges
[i
].type
,
1258 (long) (m_memranges
[i
].end
1259 - m_memranges
[i
].start
));
1261 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1263 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1270 bfd_signed_vma length
1271 = m_memranges
[i
].end
- m_memranges
[i
].start
;
1273 /* The "%X" conversion specifier expects an unsigned argument,
1274 so passing -1 (memrange_absolute) to it directly gives you
1275 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1277 if (m_memranges
[i
].type
== memrange_absolute
)
1278 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1280 sprintf (end
, "M%X,%s,%lX", m_memranges
[i
].type
, tmp2
, (long) length
);
1283 count
+= strlen (end
);
1284 end
= temp_buf
+ count
;
1287 for (i
= 0; i
< m_aexprs
.size (); i
++)
1289 QUIT
; /* Allow user to bail out with ^C. */
1290 if ((count
+ 10 + 2 * m_aexprs
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1292 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1297 sprintf (end
, "X%08X,", m_aexprs
[i
]->len
);
1298 end
+= 10; /* 'X' + 8 hex digits + ',' */
1301 end
= mem2hex (m_aexprs
[i
]->buf
, end
, m_aexprs
[i
]->len
);
1302 count
+= 2 * m_aexprs
[i
]->len
;
1307 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1312 (*str_list
)[ndx
] = NULL
;
1323 /* Add the printed expression EXP to *LIST. */
1326 collection_list::append_exp (struct expression
*exp
)
1328 struct ui_file
*tmp_stream
= mem_fileopen ();
1330 print_expression (exp
, tmp_stream
);
1332 m_computed
.push_back (ui_file_as_string (tmp_stream
));
1333 ui_file_delete (tmp_stream
);
1337 collection_list::finish ()
1339 memrange_sortmerge (m_memranges
);
1343 encode_actions_1 (struct command_line
*action
,
1344 struct bp_location
*tloc
,
1346 LONGEST frame_offset
,
1347 struct collection_list
*collect
,
1348 struct collection_list
*stepping_list
)
1350 const char *action_exp
;
1352 struct value
*tempval
;
1353 struct cmd_list_element
*cmd
;
1354 struct agent_expr
*aexpr
;
1356 for (; action
; action
= action
->next
)
1358 QUIT
; /* Allow user to bail out with ^C. */
1359 action_exp
= action
->line
;
1360 action_exp
= skip_spaces_const (action_exp
);
1362 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1364 error (_("Bad action list item: %s"), action_exp
);
1366 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1368 int trace_string
= 0;
1370 if (*action_exp
== '/')
1371 action_exp
= decode_agent_options (action_exp
, &trace_string
);
1374 { /* Repeat over a comma-separated list. */
1375 QUIT
; /* Allow user to bail out with ^C. */
1376 action_exp
= skip_spaces_const (action_exp
);
1378 if (0 == strncasecmp ("$reg", action_exp
, 4))
1380 for (i
= 0; i
< gdbarch_num_regs (target_gdbarch ()); i
++)
1381 collect
->add_register (i
);
1382 action_exp
= strchr (action_exp
, ','); /* more? */
1384 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1386 collect
->add_local_symbols (target_gdbarch (),
1392 action_exp
= strchr (action_exp
, ','); /* more? */
1394 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1396 collect
->add_local_symbols (target_gdbarch (),
1402 action_exp
= strchr (action_exp
, ','); /* more? */
1404 else if (0 == strncasecmp ("$_ret", action_exp
, 5))
1406 struct cleanup
*old_chain1
= NULL
;
1408 aexpr
= gen_trace_for_return_address (tloc
->address
,
1412 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1415 report_agent_reqs_errors (aexpr
);
1417 discard_cleanups (old_chain1
);
1418 collect
->add_aexpr (aexpr
);
1420 /* take care of the registers */
1421 if (aexpr
->reg_mask_len
> 0)
1425 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1427 QUIT
; /* allow user to bail out with ^C */
1428 if (aexpr
->reg_mask
[ndx1
] != 0)
1430 /* assume chars have 8 bits */
1431 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1432 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1434 /* It's used -- record it. */
1435 collect
->add_register (ndx1
* 8 + ndx2
);
1441 action_exp
= strchr (action_exp
, ','); /* more? */
1443 else if (0 == strncasecmp ("$_sdata", action_exp
, 7))
1445 collect
->add_static_trace_data ();
1446 action_exp
= strchr (action_exp
, ','); /* more? */
1451 struct cleanup
*old_chain1
= NULL
;
1453 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1454 block_for_pc (tloc
->address
),
1457 switch (exp
->elts
[0].opcode
)
1461 const char *name
= &exp
->elts
[2].string
;
1463 i
= user_reg_map_name_to_regnum (target_gdbarch (),
1464 name
, strlen (name
));
1466 internal_error (__FILE__
, __LINE__
,
1467 _("Register $%s not available"),
1470 printf_filtered ("OP_REGISTER: ");
1471 collect
->add_register (i
);
1476 /* Safe because we know it's a simple expression. */
1477 tempval
= evaluate_expression (exp
.get ());
1478 addr
= value_address (tempval
);
1479 /* Initialize the TYPE_LENGTH if it is a typedef. */
1480 check_typedef (exp
->elts
[1].type
);
1481 collect
->add_memrange (memrange_absolute
, addr
,
1482 TYPE_LENGTH (exp
->elts
[1].type
));
1483 collect
->append_exp (exp
.get ());
1488 struct symbol
*sym
= exp
->elts
[2].symbol
;
1489 char_ptr name
= (char_ptr
) SYMBOL_NATURAL_NAME (sym
);
1491 collect
->collect_symbol (exp
->elts
[2].symbol
,
1497 collect
->add_wholly_collected (name
);
1501 default: /* Full-fledged expression. */
1502 aexpr
= gen_trace_for_expr (tloc
->address
, exp
.get (),
1505 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1509 report_agent_reqs_errors (aexpr
);
1511 discard_cleanups (old_chain1
);
1512 collect
->add_aexpr (aexpr
);
1514 /* Take care of the registers. */
1515 if (aexpr
->reg_mask_len
> 0)
1520 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1522 QUIT
; /* Allow user to bail out with ^C. */
1523 if (aexpr
->reg_mask
[ndx1
] != 0)
1525 /* Assume chars have 8 bits. */
1526 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1527 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1529 /* It's used -- record it. */
1530 collect
->add_register (ndx1
* 8 + ndx2
);
1536 collect
->append_exp (exp
.get ());
1541 while (action_exp
&& *action_exp
++ == ',');
1543 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1546 { /* Repeat over a comma-separated list. */
1547 QUIT
; /* Allow user to bail out with ^C. */
1548 action_exp
= skip_spaces_const (action_exp
);
1551 struct cleanup
*old_chain1
= NULL
;
1553 expression_up exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1554 block_for_pc (tloc
->address
),
1557 aexpr
= gen_eval_for_expr (tloc
->address
, exp
.get ());
1558 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1561 report_agent_reqs_errors (aexpr
);
1563 discard_cleanups (old_chain1
);
1564 /* Even though we're not officially collecting, add
1565 to the collect list anyway. */
1566 collect
->add_aexpr (aexpr
);
1569 while (action_exp
&& *action_exp
++ == ',');
1571 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1573 /* We check against nested while-stepping when setting
1574 breakpoint action, so no way to run into nested
1576 gdb_assert (stepping_list
);
1578 encode_actions_1 (action
->body_list
[0], tloc
, frame_reg
,
1579 frame_offset
, stepping_list
, NULL
);
1582 error (_("Invalid tracepoint command '%s'"), action
->line
);
1586 /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST
1587 and STEPPING_LIST. */
1590 encode_actions (struct bp_location
*tloc
,
1591 struct collection_list
*tracepoint_list
,
1592 struct collection_list
*stepping_list
)
1594 struct command_line
*actions
;
1596 LONGEST frame_offset
;
1598 gdbarch_virtual_frame_pointer (tloc
->gdbarch
,
1599 tloc
->address
, &frame_reg
, &frame_offset
);
1601 actions
= all_tracepoint_actions_and_cleanup (tloc
->owner
);
1603 encode_actions_1 (actions
, tloc
, frame_reg
, frame_offset
,
1604 tracepoint_list
, stepping_list
);
1606 tracepoint_list
->finish ();
1607 stepping_list
->finish ();
1610 /* Render all actions into gdb protocol. */
1613 encode_actions_rsp (struct bp_location
*tloc
, char ***tdp_actions
,
1614 char ***stepping_actions
)
1616 struct collection_list tracepoint_list
, stepping_list
;
1618 *tdp_actions
= NULL
;
1619 *stepping_actions
= NULL
;
1621 encode_actions (tloc
, &tracepoint_list
, &stepping_list
);
1623 *tdp_actions
= tracepoint_list
.stringify ();
1624 *stepping_actions
= stepping_list
.stringify ();
1628 collection_list::add_aexpr (struct agent_expr
*aexpr
)
1630 m_aexprs
.push_back (aexpr
);
1634 process_tracepoint_on_disconnect (void)
1636 VEC(breakpoint_p
) *tp_vec
= NULL
;
1638 struct breakpoint
*b
;
1639 int has_pending_p
= 0;
1641 /* Check whether we still have pending tracepoint. If we have, warn the
1642 user that pending tracepoint will no longer work. */
1643 tp_vec
= all_tracepoints ();
1644 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1653 struct bp_location
*loc1
;
1655 for (loc1
= b
->loc
; loc1
; loc1
= loc1
->next
)
1657 if (loc1
->shlib_disabled
)
1668 VEC_free (breakpoint_p
, tp_vec
);
1671 warning (_("Pending tracepoints will not be resolved while"
1672 " GDB is disconnected\n"));
1675 /* Reset local state of tracing. */
1678 trace_reset_local_state (void)
1680 set_traceframe_num (-1);
1681 set_tracepoint_num (-1);
1682 set_traceframe_context (NULL
);
1683 clear_traceframe_info ();
1687 start_tracing (char *notes
)
1689 VEC(breakpoint_p
) *tp_vec
= NULL
;
1691 struct breakpoint
*b
;
1692 struct trace_state_variable
*tsv
;
1693 int any_enabled
= 0, num_to_download
= 0;
1696 tp_vec
= all_tracepoints ();
1698 /* No point in tracing without any tracepoints... */
1699 if (VEC_length (breakpoint_p
, tp_vec
) == 0)
1701 VEC_free (breakpoint_p
, tp_vec
);
1702 error (_("No tracepoints defined, not starting trace"));
1705 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1707 if (b
->enable_state
== bp_enabled
)
1710 if ((b
->type
== bp_fast_tracepoint
1711 ? may_insert_fast_tracepoints
1712 : may_insert_tracepoints
))
1715 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1716 (b
->type
== bp_fast_tracepoint
? "fast " : ""), b
->number
);
1721 if (target_supports_enable_disable_tracepoint ())
1722 warning (_("No tracepoints enabled"));
1725 /* No point in tracing with only disabled tracepoints that
1726 cannot be re-enabled. */
1727 VEC_free (breakpoint_p
, tp_vec
);
1728 error (_("No tracepoints enabled, not starting trace"));
1732 if (num_to_download
<= 0)
1734 VEC_free (breakpoint_p
, tp_vec
);
1735 error (_("No tracepoints that may be downloaded, not starting trace"));
1738 target_trace_init ();
1740 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1742 struct tracepoint
*t
= (struct tracepoint
*) b
;
1743 struct bp_location
*loc
;
1744 int bp_location_downloaded
= 0;
1746 /* Clear `inserted' flag. */
1747 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1750 if ((b
->type
== bp_fast_tracepoint
1751 ? !may_insert_fast_tracepoints
1752 : !may_insert_tracepoints
))
1755 t
->number_on_target
= 0;
1757 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1759 /* Since tracepoint locations are never duplicated, `inserted'
1760 flag should be zero. */
1761 gdb_assert (!loc
->inserted
);
1763 target_download_tracepoint (loc
);
1766 bp_location_downloaded
= 1;
1769 t
->number_on_target
= b
->number
;
1771 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1772 if (loc
->probe
.probe
!= NULL
1773 && loc
->probe
.probe
->pops
->set_semaphore
!= NULL
)
1774 loc
->probe
.probe
->pops
->set_semaphore (loc
->probe
.probe
,
1778 if (bp_location_downloaded
)
1779 observer_notify_breakpoint_modified (b
);
1781 VEC_free (breakpoint_p
, tp_vec
);
1783 /* Send down all the trace state variables too. */
1784 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1786 target_download_trace_state_variable (tsv
);
1789 /* Tell target to treat text-like sections as transparent. */
1790 target_trace_set_readonly_regions ();
1791 /* Set some mode flags. */
1792 target_set_disconnected_tracing (disconnected_tracing
);
1793 target_set_circular_trace_buffer (circular_trace_buffer
);
1794 target_set_trace_buffer_size (trace_buffer_size
);
1797 notes
= trace_notes
;
1798 ret
= target_set_trace_notes (trace_user
, notes
, NULL
);
1800 if (!ret
&& (trace_user
|| notes
))
1801 warning (_("Target does not support trace user/notes, info ignored"));
1803 /* Now insert traps and begin collecting data. */
1804 target_trace_start ();
1806 /* Reset our local state. */
1807 trace_reset_local_state ();
1808 current_trace_status()->running
= 1;
1811 /* The tstart command requests the target to start a new trace run.
1812 The command passes any arguments it has to the target verbatim, as
1813 an optional "trace note". This is useful as for instance a warning
1814 to other users if the trace runs disconnected, and you don't want
1815 anybody else messing with the target. */
1818 trace_start_command (char *args
, int from_tty
)
1820 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1822 if (current_trace_status ()->running
)
1825 && !query (_("A trace is running already. Start a new run? ")))
1826 error (_("New trace run not started."));
1829 start_tracing (args
);
1832 /* The tstop command stops the tracing run. The command passes any
1833 supplied arguments to the target verbatim as a "stop note"; if the
1834 target supports trace notes, then it will be reported back as part
1835 of the trace run's status. */
1838 trace_stop_command (char *args
, int from_tty
)
1840 if (!current_trace_status ()->running
)
1841 error (_("Trace is not running."));
1843 stop_tracing (args
);
1847 stop_tracing (char *note
)
1850 VEC(breakpoint_p
) *tp_vec
= NULL
;
1852 struct breakpoint
*t
;
1854 target_trace_stop ();
1856 tp_vec
= all_tracepoints ();
1857 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1859 struct bp_location
*loc
;
1861 if ((t
->type
== bp_fast_tracepoint
1862 ? !may_insert_fast_tracepoints
1863 : !may_insert_tracepoints
))
1866 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
1868 /* GDB can be totally absent in some disconnected trace scenarios,
1869 but we don't really care if this semaphore goes out of sync.
1870 That's why we are decrementing it here, but not taking care
1872 if (loc
->probe
.probe
!= NULL
1873 && loc
->probe
.probe
->pops
->clear_semaphore
!= NULL
)
1874 loc
->probe
.probe
->pops
->clear_semaphore (loc
->probe
.probe
,
1880 VEC_free (breakpoint_p
, tp_vec
);
1883 note
= trace_stop_notes
;
1884 ret
= target_set_trace_notes (NULL
, NULL
, note
);
1887 warning (_("Target does not support trace notes, note ignored"));
1889 /* Should change in response to reply? */
1890 current_trace_status ()->running
= 0;
1893 /* tstatus command */
1895 trace_status_command (char *args
, int from_tty
)
1897 struct trace_status
*ts
= current_trace_status ();
1899 VEC(breakpoint_p
) *tp_vec
= NULL
;
1900 struct breakpoint
*t
;
1902 status
= target_get_trace_status (ts
);
1906 if (ts
->filename
!= NULL
)
1907 printf_filtered (_("Using a trace file.\n"));
1910 printf_filtered (_("Trace can not be run on this target.\n"));
1915 if (!ts
->running_known
)
1917 printf_filtered (_("Run/stop status is unknown.\n"));
1919 else if (ts
->running
)
1921 printf_filtered (_("Trace is running on the target.\n"));
1925 switch (ts
->stop_reason
)
1927 case trace_never_run
:
1928 printf_filtered (_("No trace has been run on the target.\n"));
1932 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1935 printf_filtered (_("Trace stopped by a tstop command.\n"));
1937 case trace_buffer_full
:
1938 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1940 case trace_disconnected
:
1941 printf_filtered (_("Trace stopped because of disconnection.\n"));
1943 case tracepoint_passcount
:
1944 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1945 ts
->stopping_tracepoint
);
1947 case tracepoint_error
:
1948 if (ts
->stopping_tracepoint
)
1949 printf_filtered (_("Trace stopped by an "
1950 "error (%s, tracepoint %d).\n"),
1951 ts
->stop_desc
, ts
->stopping_tracepoint
);
1953 printf_filtered (_("Trace stopped by an error (%s).\n"),
1956 case trace_stop_reason_unknown
:
1957 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1960 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1966 if (ts
->traceframes_created
>= 0
1967 && ts
->traceframe_count
!= ts
->traceframes_created
)
1969 printf_filtered (_("Buffer contains %d trace "
1970 "frames (of %d created total).\n"),
1971 ts
->traceframe_count
, ts
->traceframes_created
);
1973 else if (ts
->traceframe_count
>= 0)
1975 printf_filtered (_("Collected %d trace frames.\n"),
1976 ts
->traceframe_count
);
1979 if (ts
->buffer_free
>= 0)
1981 if (ts
->buffer_size
>= 0)
1983 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1984 ts
->buffer_free
, ts
->buffer_size
);
1985 if (ts
->buffer_size
> 0)
1986 printf_filtered (_(" (%d%% full)"),
1987 ((int) ((((long long) (ts
->buffer_size
1988 - ts
->buffer_free
)) * 100)
1989 / ts
->buffer_size
)));
1990 printf_filtered (_(".\n"));
1993 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1997 if (ts
->disconnected_tracing
)
1998 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
2000 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
2002 if (ts
->circular_buffer
)
2003 printf_filtered (_("Trace buffer is circular.\n"));
2005 if (ts
->user_name
&& strlen (ts
->user_name
) > 0)
2006 printf_filtered (_("Trace user is %s.\n"), ts
->user_name
);
2008 if (ts
->notes
&& strlen (ts
->notes
) > 0)
2009 printf_filtered (_("Trace notes: %s.\n"), ts
->notes
);
2011 /* Now report on what we're doing with tfind. */
2012 if (traceframe_number
>= 0)
2013 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
2014 traceframe_number
, tracepoint_number
);
2016 printf_filtered (_("Not looking at any trace frame.\n"));
2018 /* Report start/stop times if supplied. */
2023 LONGEST run_time
= ts
->stop_time
- ts
->start_time
;
2025 /* Reporting a run time is more readable than two long numbers. */
2026 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
2027 (long int) (ts
->start_time
/ 1000000),
2028 (long int) (ts
->start_time
% 1000000),
2029 (long int) (run_time
/ 1000000),
2030 (long int) (run_time
% 1000000));
2033 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
2034 (long int) (ts
->start_time
/ 1000000),
2035 (long int) (ts
->start_time
% 1000000));
2037 else if (ts
->stop_time
)
2038 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
2039 (long int) (ts
->stop_time
/ 1000000),
2040 (long int) (ts
->stop_time
% 1000000));
2042 /* Now report any per-tracepoint status available. */
2043 tp_vec
= all_tracepoints ();
2045 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
2046 target_get_tracepoint_status (t
, NULL
);
2048 VEC_free (breakpoint_p
, tp_vec
);
2051 /* Report the trace status to uiout, in a way suitable for MI, and not
2052 suitable for CLI. If ON_STOP is true, suppress a few fields that
2053 are not meaningful in the -trace-stop response.
2055 The implementation is essentially parallel to trace_status_command, but
2056 merging them will result in unreadable code. */
2058 trace_status_mi (int on_stop
)
2060 struct ui_out
*uiout
= current_uiout
;
2061 struct trace_status
*ts
= current_trace_status ();
2064 status
= target_get_trace_status (ts
);
2066 if (status
== -1 && ts
->filename
== NULL
)
2068 ui_out_field_string (uiout
, "supported", "0");
2072 if (ts
->filename
!= NULL
)
2073 ui_out_field_string (uiout
, "supported", "file");
2075 ui_out_field_string (uiout
, "supported", "1");
2077 if (ts
->filename
!= NULL
)
2078 ui_out_field_string (uiout
, "trace-file", ts
->filename
);
2080 gdb_assert (ts
->running_known
);
2084 ui_out_field_string (uiout
, "running", "1");
2086 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
2087 Given that the frontend gets the status either on -trace-stop, or from
2088 -trace-status after re-connection, it does not seem like this
2089 information is necessary for anything. It is not necessary for either
2090 figuring the vital state of the target nor for navigation of trace
2091 frames. If the frontend wants to show the current state is some
2092 configure dialog, it can request the value when such dialog is
2093 invoked by the user. */
2097 char *stop_reason
= NULL
;
2098 int stopping_tracepoint
= -1;
2101 ui_out_field_string (uiout
, "running", "0");
2103 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
2105 switch (ts
->stop_reason
)
2108 stop_reason
= "request";
2110 case trace_buffer_full
:
2111 stop_reason
= "overflow";
2113 case trace_disconnected
:
2114 stop_reason
= "disconnection";
2116 case tracepoint_passcount
:
2117 stop_reason
= "passcount";
2118 stopping_tracepoint
= ts
->stopping_tracepoint
;
2120 case tracepoint_error
:
2121 stop_reason
= "error";
2122 stopping_tracepoint
= ts
->stopping_tracepoint
;
2128 ui_out_field_string (uiout
, "stop-reason", stop_reason
);
2129 if (stopping_tracepoint
!= -1)
2130 ui_out_field_int (uiout
, "stopping-tracepoint",
2131 stopping_tracepoint
);
2132 if (ts
->stop_reason
== tracepoint_error
)
2133 ui_out_field_string (uiout
, "error-description",
2139 if (ts
->traceframe_count
!= -1)
2140 ui_out_field_int (uiout
, "frames", ts
->traceframe_count
);
2141 if (ts
->traceframes_created
!= -1)
2142 ui_out_field_int (uiout
, "frames-created", ts
->traceframes_created
);
2143 if (ts
->buffer_size
!= -1)
2144 ui_out_field_int (uiout
, "buffer-size", ts
->buffer_size
);
2145 if (ts
->buffer_free
!= -1)
2146 ui_out_field_int (uiout
, "buffer-free", ts
->buffer_free
);
2148 ui_out_field_int (uiout
, "disconnected", ts
->disconnected_tracing
);
2149 ui_out_field_int (uiout
, "circular", ts
->circular_buffer
);
2151 ui_out_field_string (uiout
, "user-name", ts
->user_name
);
2152 ui_out_field_string (uiout
, "notes", ts
->notes
);
2157 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2158 (long int) (ts
->start_time
/ 1000000),
2159 (long int) (ts
->start_time
% 1000000));
2160 ui_out_field_string (uiout
, "start-time", buf
);
2161 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2162 (long int) (ts
->stop_time
/ 1000000),
2163 (long int) (ts
->stop_time
% 1000000));
2164 ui_out_field_string (uiout
, "stop-time", buf
);
2168 /* Check if a trace run is ongoing. If so, and FROM_TTY, query the
2169 user if she really wants to detach. */
2172 query_if_trace_running (int from_tty
)
2177 /* It can happen that the target that was tracing went away on its
2178 own, and we didn't notice. Get a status update, and if the
2179 current target doesn't even do tracing, then assume it's not
2181 if (target_get_trace_status (current_trace_status ()) < 0)
2182 current_trace_status ()->running
= 0;
2184 /* If running interactively, give the user the option to cancel and
2185 then decide what to do differently with the run. Scripts are
2186 just going to disconnect and let the target deal with it,
2187 according to how it's been instructed previously via
2188 disconnected-tracing. */
2189 if (current_trace_status ()->running
)
2191 process_tracepoint_on_disconnect ();
2193 if (current_trace_status ()->disconnected_tracing
)
2195 if (!query (_("Trace is running and will "
2196 "continue after detach; detach anyway? ")))
2197 error (_("Not confirmed."));
2201 if (!query (_("Trace is running but will "
2202 "stop on detach; detach anyway? ")))
2203 error (_("Not confirmed."));
2208 /* This function handles the details of what to do about an ongoing
2209 tracing run if the user has asked to detach or otherwise disconnect
2213 disconnect_tracing (void)
2215 /* Also we want to be out of tfind mode, otherwise things can get
2216 confusing upon reconnection. Just use these calls instead of
2217 full tfind_1 behavior because we're in the middle of detaching,
2218 and there's no point to updating current stack frame etc. */
2219 trace_reset_local_state ();
2222 /* Worker function for the various flavors of the tfind command. */
2224 tfind_1 (enum trace_find_type type
, int num
,
2225 CORE_ADDR addr1
, CORE_ADDR addr2
,
2228 int target_frameno
= -1, target_tracept
= -1;
2229 struct frame_id old_frame_id
= null_frame_id
;
2230 struct tracepoint
*tp
;
2231 struct ui_out
*uiout
= current_uiout
;
2233 /* Only try to get the current stack frame if we have a chance of
2234 succeeding. In particular, if we're trying to get a first trace
2235 frame while all threads are running, it's not going to succeed,
2236 so leave it with a default value and let the frame comparison
2237 below (correctly) decide to print out the source location of the
2239 if (!(type
== tfind_number
&& num
== -1)
2240 && (has_stack_frames () || traceframe_number
>= 0))
2241 old_frame_id
= get_frame_id (get_current_frame ());
2243 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
2246 if (type
== tfind_number
2248 && target_frameno
== -1)
2250 /* We told the target to get out of tfind mode, and it did. */
2252 else if (target_frameno
== -1)
2254 /* A request for a non-existent trace frame has failed.
2255 Our response will be different, depending on FROM_TTY:
2257 If FROM_TTY is true, meaning that this command was
2258 typed interactively by the user, then give an error
2259 and DO NOT change the state of traceframe_number etc.
2261 However if FROM_TTY is false, meaning that we're either
2262 in a script, a loop, or a user-defined command, then
2263 DON'T give an error, but DO change the state of
2264 traceframe_number etc. to invalid.
2266 The rationalle is that if you typed the command, you
2267 might just have committed a typo or something, and you'd
2268 like to NOT lose your current debugging state. However
2269 if you're in a user-defined command or especially in a
2270 loop, then you need a way to detect that the command
2271 failed WITHOUT aborting. This allows you to write
2272 scripts that search thru the trace buffer until the end,
2273 and then continue on to do something else. */
2276 error (_("Target failed to find requested trace frame."));
2280 printf_filtered ("End of trace buffer.\n");
2281 #if 0 /* dubious now? */
2282 /* The following will not recurse, since it's
2284 trace_find_command ("-1", from_tty
);
2289 tp
= get_tracepoint_by_number_on_target (target_tracept
);
2291 reinit_frame_cache ();
2292 target_dcache_invalidate ();
2294 set_tracepoint_num (tp
? tp
->base
.number
: target_tracept
);
2296 if (target_frameno
!= get_traceframe_number ())
2297 observer_notify_traceframe_changed (target_frameno
, tracepoint_number
);
2299 set_current_traceframe (target_frameno
);
2301 if (target_frameno
== -1)
2302 set_traceframe_context (NULL
);
2304 set_traceframe_context (get_current_frame ());
2306 if (traceframe_number
>= 0)
2308 /* Use different branches for MI and CLI to make CLI messages
2310 if (ui_out_is_mi_like_p (uiout
))
2312 ui_out_field_string (uiout
, "found", "1");
2313 ui_out_field_int (uiout
, "tracepoint", tracepoint_number
);
2314 ui_out_field_int (uiout
, "traceframe", traceframe_number
);
2318 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2319 traceframe_number
, tracepoint_number
);
2324 if (ui_out_is_mi_like_p (uiout
))
2325 ui_out_field_string (uiout
, "found", "0");
2326 else if (type
== tfind_number
&& num
== -1)
2327 printf_unfiltered (_("No longer looking at any trace frame\n"));
2328 else /* This case may never occur, check. */
2329 printf_unfiltered (_("No trace frame found\n"));
2332 /* If we're in nonstop mode and getting out of looking at trace
2333 frames, there won't be any current frame to go back to and
2336 && (has_stack_frames () || traceframe_number
>= 0))
2338 enum print_what print_what
;
2340 /* NOTE: in imitation of the step command, try to determine
2341 whether we have made a transition from one function to
2342 another. If so, we'll print the "stack frame" (ie. the new
2343 function and it's arguments) -- otherwise we'll just show the
2346 if (frame_id_eq (old_frame_id
,
2347 get_frame_id (get_current_frame ())))
2348 print_what
= SRC_LINE
;
2350 print_what
= SRC_AND_LOC
;
2352 print_stack_frame (get_selected_frame (NULL
), 1, print_what
, 1);
2357 /* Error on looking at traceframes while trace is running. */
2360 check_trace_running (struct trace_status
*status
)
2362 if (status
->running
&& status
->filename
== NULL
)
2363 error (_("May not look at trace frames while trace is running."));
2366 /* trace_find_command takes a trace frame number n,
2367 sends "QTFrame:<n>" to the target,
2368 and accepts a reply that may contain several optional pieces
2369 of information: a frame number, a tracepoint number, and an
2370 indication of whether this is a trap frame or a stepping frame.
2372 The minimal response is just "OK" (which indicates that the
2373 target does not give us a frame number or a tracepoint number).
2374 Instead of that, the target may send us a string containing
2376 F<hexnum> (gives the selected frame number)
2377 T<hexnum> (gives the selected tracepoint number)
2382 trace_find_command (char *args
, int from_tty
)
2383 { /* This should only be called with a numeric argument. */
2386 check_trace_running (current_trace_status ());
2388 if (args
== 0 || *args
== 0)
2389 { /* TFIND with no args means find NEXT trace frame. */
2390 if (traceframe_number
== -1)
2391 frameno
= 0; /* "next" is first one. */
2393 frameno
= traceframe_number
+ 1;
2395 else if (0 == strcmp (args
, "-"))
2397 if (traceframe_number
== -1)
2398 error (_("not debugging trace buffer"));
2399 else if (from_tty
&& traceframe_number
== 0)
2400 error (_("already at start of trace buffer"));
2402 frameno
= traceframe_number
- 1;
2404 /* A hack to work around eval's need for fp to have been collected. */
2405 else if (0 == strcmp (args
, "-1"))
2408 frameno
= parse_and_eval_long (args
);
2411 error (_("invalid input (%d is less than zero)"), frameno
);
2413 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
2418 trace_find_end_command (char *args
, int from_tty
)
2420 trace_find_command ("-1", from_tty
);
2425 trace_find_start_command (char *args
, int from_tty
)
2427 trace_find_command ("0", from_tty
);
2430 /* tfind pc command */
2432 trace_find_pc_command (char *args
, int from_tty
)
2436 check_trace_running (current_trace_status ());
2438 if (args
== 0 || *args
== 0)
2439 pc
= regcache_read_pc (get_current_regcache ());
2441 pc
= parse_and_eval_address (args
);
2443 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
2446 /* tfind tracepoint command */
2448 trace_find_tracepoint_command (char *args
, int from_tty
)
2451 struct tracepoint
*tp
;
2453 check_trace_running (current_trace_status ());
2455 if (args
== 0 || *args
== 0)
2457 if (tracepoint_number
== -1)
2458 error (_("No current tracepoint -- please supply an argument."));
2460 tdp
= tracepoint_number
; /* Default is current TDP. */
2463 tdp
= parse_and_eval_long (args
);
2465 /* If we have the tracepoint on hand, use the number that the
2466 target knows about (which may be different if we disconnected
2467 and reconnected). */
2468 tp
= get_tracepoint (tdp
);
2470 tdp
= tp
->number_on_target
;
2472 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
2475 /* TFIND LINE command:
2477 This command will take a sourceline for argument, just like BREAK
2478 or TRACE (ie. anything that "decode_line_1" can handle).
2480 With no argument, this command will find the next trace frame
2481 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2484 trace_find_line_command (char *args
, int from_tty
)
2486 static CORE_ADDR start_pc
, end_pc
;
2487 struct symtabs_and_lines sals
;
2488 struct symtab_and_line sal
;
2489 struct cleanup
*old_chain
;
2491 check_trace_running (current_trace_status ());
2493 if (args
== 0 || *args
== 0)
2495 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2497 sals
.sals
= XNEW (struct symtab_and_line
);
2502 sals
= decode_line_with_current_source (args
, DECODE_LINE_FUNFIRSTLINE
);
2506 old_chain
= make_cleanup (xfree
, sals
.sals
);
2507 if (sal
.symtab
== 0)
2508 error (_("No line number information available."));
2510 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2512 if (start_pc
== end_pc
)
2514 printf_filtered ("Line %d of \"%s\"",
2516 symtab_to_filename_for_display (sal
.symtab
));
2518 printf_filtered (" is at address ");
2519 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2521 printf_filtered (" but contains no code.\n");
2522 sal
= find_pc_line (start_pc
, 0);
2524 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2525 && start_pc
!= end_pc
)
2526 printf_filtered ("Attempting to find line %d instead.\n",
2529 error (_("Cannot find a good line."));
2533 /* Is there any case in which we get here, and have an address
2534 which the user would want to see? If we have debugging
2535 symbols and no line numbers? */
2536 error (_("Line number %d is out of range for \"%s\"."),
2537 sal
.line
, symtab_to_filename_for_display (sal
.symtab
));
2539 /* Find within range of stated line. */
2541 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2543 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2544 do_cleanups (old_chain
);
2547 /* tfind range command */
2549 trace_find_range_command (char *args
, int from_tty
)
2551 static CORE_ADDR start
, stop
;
2554 check_trace_running (current_trace_status ());
2556 if (args
== 0 || *args
== 0)
2557 { /* XXX FIXME: what should default behavior be? */
2558 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2562 if (0 != (tmp
= strchr (args
, ',')))
2564 *tmp
++ = '\0'; /* Terminate start address. */
2565 tmp
= skip_spaces (tmp
);
2566 start
= parse_and_eval_address (args
);
2567 stop
= parse_and_eval_address (tmp
);
2570 { /* No explicit end address? */
2571 start
= parse_and_eval_address (args
);
2572 stop
= start
+ 1; /* ??? */
2575 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2578 /* tfind outside command */
2580 trace_find_outside_command (char *args
, int from_tty
)
2582 CORE_ADDR start
, stop
;
2585 if (current_trace_status ()->running
2586 && current_trace_status ()->filename
== NULL
)
2587 error (_("May not look at trace frames while trace is running."));
2589 if (args
== 0 || *args
== 0)
2590 { /* XXX FIXME: what should default behavior be? */
2591 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2595 if (0 != (tmp
= strchr (args
, ',')))
2597 *tmp
++ = '\0'; /* Terminate start address. */
2598 tmp
= skip_spaces (tmp
);
2599 start
= parse_and_eval_address (args
);
2600 stop
= parse_and_eval_address (tmp
);
2603 { /* No explicit end address? */
2604 start
= parse_and_eval_address (args
);
2605 stop
= start
+ 1; /* ??? */
2608 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2611 /* info scope command: list the locals for a scope. */
2613 scope_info (char *args
, int from_tty
)
2615 struct symtabs_and_lines sals
;
2617 struct bound_minimal_symbol msym
;
2618 const struct block
*block
;
2619 const char *symname
;
2620 char *save_args
= args
;
2621 struct block_iterator iter
;
2623 struct gdbarch
*gdbarch
;
2625 struct event_location
*location
;
2626 struct cleanup
*back_to
;
2628 if (args
== 0 || *args
== 0)
2629 error (_("requires an argument (function, "
2630 "line or *addr) to define a scope"));
2632 location
= string_to_event_location (&args
, current_language
);
2633 back_to
= make_cleanup_delete_event_location (location
);
2634 sals
= decode_line_1 (location
, DECODE_LINE_FUNFIRSTLINE
, NULL
, NULL
, 0);
2635 if (sals
.nelts
== 0)
2637 /* Presumably decode_line_1 has already warned. */
2638 do_cleanups (back_to
);
2642 /* Resolve line numbers to PC. */
2643 resolve_sal_pc (&sals
.sals
[0]);
2644 block
= block_for_pc (sals
.sals
[0].pc
);
2648 QUIT
; /* Allow user to bail out with ^C. */
2649 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2651 QUIT
; /* Allow user to bail out with ^C. */
2653 printf_filtered ("Scope for %s:\n", save_args
);
2656 symname
= SYMBOL_PRINT_NAME (sym
);
2657 if (symname
== NULL
|| *symname
== '\0')
2658 continue; /* Probably botched, certainly useless. */
2660 gdbarch
= symbol_arch (sym
);
2662 printf_filtered ("Symbol %s is ", symname
);
2664 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
2665 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
,
2666 BLOCK_START (block
),
2670 switch (SYMBOL_CLASS (sym
))
2673 case LOC_UNDEF
: /* Messed up symbol? */
2674 printf_filtered ("a bogus symbol, class %d.\n",
2675 SYMBOL_CLASS (sym
));
2676 count
--; /* Don't count this one. */
2679 printf_filtered ("a constant with value %s (%s)",
2680 plongest (SYMBOL_VALUE (sym
)),
2681 hex_string (SYMBOL_VALUE (sym
)));
2683 case LOC_CONST_BYTES
:
2684 printf_filtered ("constant bytes: ");
2685 if (SYMBOL_TYPE (sym
))
2686 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2687 fprintf_filtered (gdb_stdout
, " %02x",
2688 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2691 printf_filtered ("in static storage at address ");
2692 printf_filtered ("%s", paddress (gdbarch
,
2693 SYMBOL_VALUE_ADDRESS (sym
)));
2696 /* GDBARCH is the architecture associated with the objfile
2697 the symbol is defined in; the target architecture may be
2698 different, and may provide additional registers. However,
2699 we do not know the target architecture at this point.
2700 We assume the objfile architecture will contain all the
2701 standard registers that occur in debug info in that
2703 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2706 if (SYMBOL_IS_ARGUMENT (sym
))
2707 printf_filtered ("an argument in register $%s",
2708 gdbarch_register_name (gdbarch
, regno
));
2710 printf_filtered ("a local variable in register $%s",
2711 gdbarch_register_name (gdbarch
, regno
));
2714 printf_filtered ("an argument at stack/frame offset %s",
2715 plongest (SYMBOL_VALUE (sym
)));
2718 printf_filtered ("a local variable at frame offset %s",
2719 plongest (SYMBOL_VALUE (sym
)));
2722 printf_filtered ("a reference argument at offset %s",
2723 plongest (SYMBOL_VALUE (sym
)));
2725 case LOC_REGPARM_ADDR
:
2726 /* Note comment at LOC_REGISTER. */
2727 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2729 printf_filtered ("the address of an argument, in register $%s",
2730 gdbarch_register_name (gdbarch
, regno
));
2733 printf_filtered ("a typedef.\n");
2736 printf_filtered ("a label at address ");
2737 printf_filtered ("%s", paddress (gdbarch
,
2738 SYMBOL_VALUE_ADDRESS (sym
)));
2741 printf_filtered ("a function at address ");
2742 printf_filtered ("%s",
2743 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2745 case LOC_UNRESOLVED
:
2746 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2748 if (msym
.minsym
== NULL
)
2749 printf_filtered ("Unresolved Static");
2752 printf_filtered ("static storage at address ");
2753 printf_filtered ("%s",
2755 BMSYMBOL_VALUE_ADDRESS (msym
)));
2758 case LOC_OPTIMIZED_OUT
:
2759 printf_filtered ("optimized out.\n");
2762 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2765 if (SYMBOL_TYPE (sym
))
2766 printf_filtered (", length %d.\n",
2767 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2769 if (BLOCK_FUNCTION (block
))
2772 block
= BLOCK_SUPERBLOCK (block
);
2775 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2777 do_cleanups (back_to
);
2780 /* Helper for trace_dump_command. Dump the action list starting at
2781 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2782 actions of the body of a while-stepping action. STEPPING_FRAME is
2783 set if the current traceframe was determined to be a while-stepping
2787 trace_dump_actions (struct command_line
*action
,
2788 int stepping_actions
, int stepping_frame
,
2791 const char *action_exp
, *next_comma
;
2793 for (; action
!= NULL
; action
= action
->next
)
2795 struct cmd_list_element
*cmd
;
2797 QUIT
; /* Allow user to bail out with ^C. */
2798 action_exp
= action
->line
;
2799 action_exp
= skip_spaces_const (action_exp
);
2801 /* The collection actions to be done while stepping are
2802 bracketed by the commands "while-stepping" and "end". */
2804 if (*action_exp
== '#') /* comment line */
2807 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2809 error (_("Bad action list item: %s"), action_exp
);
2811 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2815 for (i
= 0; i
< action
->body_count
; ++i
)
2816 trace_dump_actions (action
->body_list
[i
],
2817 1, stepping_frame
, from_tty
);
2819 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2821 /* Display the collected data.
2822 For the trap frame, display only what was collected at
2823 the trap. Likewise for stepping frames, display only
2824 what was collected while stepping. This means that the
2825 two boolean variables, STEPPING_FRAME and
2826 STEPPING_ACTIONS should be equal. */
2827 if (stepping_frame
== stepping_actions
)
2830 struct cleanup
*old_chain
2831 = make_cleanup (free_current_contents
, &cmd
);
2832 int trace_string
= 0;
2834 if (*action_exp
== '/')
2835 action_exp
= decode_agent_options (action_exp
, &trace_string
);
2838 { /* Repeat over a comma-separated list. */
2839 QUIT
; /* Allow user to bail out with ^C. */
2840 if (*action_exp
== ',')
2842 action_exp
= skip_spaces_const (action_exp
);
2844 next_comma
= strchr (action_exp
, ',');
2846 if (0 == strncasecmp (action_exp
, "$reg", 4))
2847 registers_info (NULL
, from_tty
);
2848 else if (0 == strncasecmp (action_exp
, "$_ret", 5))
2850 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2851 locals_info (NULL
, from_tty
);
2852 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2853 args_info (NULL
, from_tty
);
2856 if (next_comma
!= NULL
)
2858 size_t len
= next_comma
- action_exp
;
2860 cmd
= (char *) xrealloc (cmd
, len
+ 1);
2861 memcpy (cmd
, action_exp
, len
);
2866 size_t len
= strlen (action_exp
);
2868 cmd
= (char *) xrealloc (cmd
, len
+ 1);
2869 memcpy (cmd
, action_exp
, len
+ 1);
2872 printf_filtered ("%s = ", cmd
);
2873 output_command_const (cmd
, from_tty
);
2874 printf_filtered ("\n");
2876 action_exp
= next_comma
;
2878 while (action_exp
&& *action_exp
== ',');
2880 do_cleanups (old_chain
);
2886 /* Return bp_location of the tracepoint associated with the current
2887 traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe
2888 is a stepping traceframe. */
2890 struct bp_location
*
2891 get_traceframe_location (int *stepping_frame_p
)
2893 struct tracepoint
*t
;
2894 struct bp_location
*tloc
;
2895 struct regcache
*regcache
;
2897 if (tracepoint_number
== -1)
2898 error (_("No current trace frame."));
2900 t
= get_tracepoint (tracepoint_number
);
2903 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2906 /* The current frame is a trap frame if the frame PC is equal to the
2907 tracepoint PC. If not, then the current frame was collected
2908 during single-stepping. */
2909 regcache
= get_current_regcache ();
2911 /* If the traceframe's address matches any of the tracepoint's
2912 locations, assume it is a direct hit rather than a while-stepping
2913 frame. (FIXME this is not reliable, should record each frame's
2915 for (tloc
= t
->base
.loc
; tloc
; tloc
= tloc
->next
)
2916 if (tloc
->address
== regcache_read_pc (regcache
))
2918 *stepping_frame_p
= 0;
2922 /* If this is a stepping frame, we don't know which location
2923 triggered. The first is as good (or bad) a guess as any... */
2924 *stepping_frame_p
= 1;
2928 /* Return all the actions, including default collect, of a tracepoint
2929 T. It constructs cleanups into the chain, and leaves the caller to
2930 handle them (call do_cleanups). */
2932 static struct command_line
*
2933 all_tracepoint_actions_and_cleanup (struct breakpoint
*t
)
2935 struct command_line
*actions
;
2937 actions
= breakpoint_commands (t
);
2939 /* If there are default expressions to collect, make up a collect
2940 action and prepend to the action list to encode. Note that since
2941 validation is per-tracepoint (local var "xyz" might be valid for
2942 one tracepoint and not another, etc), we make up the action on
2943 the fly, and don't cache it. */
2944 if (*default_collect
)
2946 struct command_line
*default_collect_action
;
2947 char *default_collect_line
;
2949 default_collect_line
= xstrprintf ("collect %s", default_collect
);
2950 make_cleanup (xfree
, default_collect_line
);
2952 validate_actionline (default_collect_line
, t
);
2953 default_collect_action
= XNEW (struct command_line
);
2954 make_cleanup (xfree
, default_collect_action
);
2955 default_collect_action
->next
= actions
;
2956 default_collect_action
->line
= default_collect_line
;
2957 actions
= default_collect_action
;
2963 /* The tdump command. */
2966 trace_dump_command (char *args
, int from_tty
)
2968 int stepping_frame
= 0;
2969 struct bp_location
*loc
;
2970 struct cleanup
*old_chain
;
2971 struct command_line
*actions
;
2973 /* This throws an error is not inspecting a trace frame. */
2974 loc
= get_traceframe_location (&stepping_frame
);
2976 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2977 tracepoint_number
, traceframe_number
);
2979 /* This command only makes sense for the current frame, not the
2981 old_chain
= make_cleanup_restore_current_thread ();
2982 select_frame (get_current_frame ());
2984 actions
= all_tracepoint_actions_and_cleanup (loc
->owner
);
2986 trace_dump_actions (actions
, 0, stepping_frame
, from_tty
);
2988 do_cleanups (old_chain
);
2991 /* Encode a piece of a tracepoint's source-level definition in a form
2992 that is suitable for both protocol and saving in files. */
2993 /* This version does not do multiple encodes for long strings; it should
2994 return an offset to the next piece to encode. FIXME */
2997 encode_source_string (int tpnum
, ULONGEST addr
,
2998 char *srctype
, const char *src
, char *buf
, int buf_size
)
3000 if (80 + strlen (srctype
) > buf_size
)
3001 error (_("Buffer too small for source encoding"));
3002 sprintf (buf
, "%x:%s:%s:%x:%x:",
3003 tpnum
, phex_nz (addr
, sizeof (addr
)),
3004 srctype
, 0, (int) strlen (src
));
3005 if (strlen (buf
) + strlen (src
) * 2 >= buf_size
)
3006 error (_("Source string too long for buffer"));
3007 bin2hex ((gdb_byte
*) src
, buf
+ strlen (buf
), strlen (src
));
3011 /* Tell the target what to do with an ongoing tracing run if GDB
3012 disconnects for some reason. */
3015 set_disconnected_tracing (char *args
, int from_tty
,
3016 struct cmd_list_element
*c
)
3018 target_set_disconnected_tracing (disconnected_tracing
);
3022 set_circular_trace_buffer (char *args
, int from_tty
,
3023 struct cmd_list_element
*c
)
3025 target_set_circular_trace_buffer (circular_trace_buffer
);
3029 set_trace_buffer_size (char *args
, int from_tty
,
3030 struct cmd_list_element
*c
)
3032 target_set_trace_buffer_size (trace_buffer_size
);
3036 set_trace_user (char *args
, int from_tty
,
3037 struct cmd_list_element
*c
)
3041 ret
= target_set_trace_notes (trace_user
, NULL
, NULL
);
3044 warning (_("Target does not support trace notes, user ignored"));
3048 set_trace_notes (char *args
, int from_tty
,
3049 struct cmd_list_element
*c
)
3053 ret
= target_set_trace_notes (NULL
, trace_notes
, NULL
);
3056 warning (_("Target does not support trace notes, note ignored"));
3060 set_trace_stop_notes (char *args
, int from_tty
,
3061 struct cmd_list_element
*c
)
3065 ret
= target_set_trace_notes (NULL
, NULL
, trace_stop_notes
);
3068 warning (_("Target does not support trace notes, stop note ignored"));
3071 /* Convert the memory pointed to by mem into hex, placing result in buf.
3072 * Return a pointer to the last char put in buf (null)
3073 * "stolen" from sparc-stub.c
3076 static const char hexchars
[] = "0123456789abcdef";
3079 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
3087 *buf
++ = hexchars
[ch
>> 4];
3088 *buf
++ = hexchars
[ch
& 0xf];
3097 get_traceframe_number (void)
3099 return traceframe_number
;
3103 get_tracepoint_number (void)
3105 return tracepoint_number
;
3108 /* Make the traceframe NUM be the current trace frame. Does nothing
3109 if NUM is already current. */
3112 set_current_traceframe (int num
)
3116 if (traceframe_number
== num
)
3118 /* Nothing to do. */
3122 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
3125 warning (_("could not change traceframe"));
3127 set_traceframe_num (newnum
);
3129 /* Changing the traceframe changes our view of registers and of the
3131 registers_changed ();
3133 clear_traceframe_info ();
3136 /* A cleanup used when switching away and back from tfind mode. */
3138 struct current_traceframe_cleanup
3140 /* The traceframe we were inspecting. */
3141 int traceframe_number
;
3145 do_restore_current_traceframe_cleanup (void *arg
)
3147 struct current_traceframe_cleanup
*old
3148 = (struct current_traceframe_cleanup
*) arg
;
3150 set_current_traceframe (old
->traceframe_number
);
3154 restore_current_traceframe_cleanup_dtor (void *arg
)
3156 struct current_traceframe_cleanup
*old
3157 = (struct current_traceframe_cleanup
*) arg
;
3163 make_cleanup_restore_current_traceframe (void)
3165 struct current_traceframe_cleanup
*old
=
3166 XNEW (struct current_traceframe_cleanup
);
3168 old
->traceframe_number
= traceframe_number
;
3170 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
3171 restore_current_traceframe_cleanup_dtor
);
3174 /* Given a number and address, return an uploaded tracepoint with that
3175 number, creating if necessary. */
3177 struct uploaded_tp
*
3178 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
3180 struct uploaded_tp
*utp
;
3182 for (utp
= *utpp
; utp
; utp
= utp
->next
)
3183 if (utp
->number
== num
&& utp
->addr
== addr
)
3186 utp
= XCNEW (struct uploaded_tp
);
3189 utp
->actions
= NULL
;
3190 utp
->step_actions
= NULL
;
3191 utp
->cmd_strings
= NULL
;
3199 free_uploaded_tps (struct uploaded_tp
**utpp
)
3201 struct uploaded_tp
*next_one
;
3205 next_one
= (*utpp
)->next
;
3211 /* Given a number and address, return an uploaded tracepoint with that
3212 number, creating if necessary. */
3214 struct uploaded_tsv
*
3215 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
3217 struct uploaded_tsv
*utsv
;
3219 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
3220 if (utsv
->number
== num
)
3223 utsv
= XCNEW (struct uploaded_tsv
);
3225 utsv
->next
= *utsvp
;
3232 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
3234 struct uploaded_tsv
*next_one
;
3238 next_one
= (*utsvp
)->next
;
3244 /* FIXME this function is heuristic and will miss the cases where the
3245 conditional is semantically identical but differs in whitespace,
3246 such as "x == 0" vs "x==0". */
3249 cond_string_is_same (char *str1
, char *str2
)
3251 if (str1
== NULL
|| str2
== NULL
)
3252 return (str1
== str2
);
3254 return (strcmp (str1
, str2
) == 0);
3257 /* Look for an existing tracepoint that seems similar enough to the
3258 uploaded one. Enablement isn't compared, because the user can
3259 toggle that freely, and may have done so in anticipation of the
3260 next trace run. Return the location of matched tracepoint. */
3262 static struct bp_location
*
3263 find_matching_tracepoint_location (struct uploaded_tp
*utp
)
3265 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
3267 struct breakpoint
*b
;
3268 struct bp_location
*loc
;
3270 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
3272 struct tracepoint
*t
= (struct tracepoint
*) b
;
3274 if (b
->type
== utp
->type
3275 && t
->step_count
== utp
->step
3276 && t
->pass_count
== utp
->pass
3277 && cond_string_is_same (t
->base
.cond_string
, utp
->cond_string
)
3278 /* FIXME also test actions. */
3281 /* Scan the locations for an address match. */
3282 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3284 if (loc
->address
== utp
->addr
)
3292 /* Given a list of tracepoints uploaded from a target, attempt to
3293 match them up with existing tracepoints, and create new ones if not
3297 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
3299 struct uploaded_tp
*utp
;
3300 /* A set of tracepoints which are modified. */
3301 VEC(breakpoint_p
) *modified_tp
= NULL
;
3303 struct breakpoint
*b
;
3305 /* Look for GDB tracepoints that match up with our uploaded versions. */
3306 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
3308 struct bp_location
*loc
;
3309 struct tracepoint
*t
;
3311 loc
= find_matching_tracepoint_location (utp
);
3316 /* Mark this location as already inserted. */
3318 t
= (struct tracepoint
*) loc
->owner
;
3319 printf_filtered (_("Assuming tracepoint %d is same "
3320 "as target's tracepoint %d at %s.\n"),
3321 loc
->owner
->number
, utp
->number
,
3322 paddress (loc
->gdbarch
, utp
->addr
));
3324 /* The tracepoint LOC->owner was modified (the location LOC
3325 was marked as inserted in the target). Save it in
3326 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3327 observers will be notified later once for each tracepoint
3328 saved in MODIFIED_TP. */
3330 VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
);
3332 if (b
== loc
->owner
)
3338 VEC_safe_push (breakpoint_p
, modified_tp
, loc
->owner
);
3342 t
= create_tracepoint_from_upload (utp
);
3344 printf_filtered (_("Created tracepoint %d for "
3345 "target's tracepoint %d at %s.\n"),
3346 t
->base
.number
, utp
->number
,
3347 paddress (get_current_arch (), utp
->addr
));
3349 printf_filtered (_("Failed to create tracepoint for target's "
3350 "tracepoint %d at %s, skipping it.\n"),
3352 paddress (get_current_arch (), utp
->addr
));
3354 /* Whether found or created, record the number used by the
3355 target, to help with mapping target tracepoints back to their
3356 counterparts here. */
3358 t
->number_on_target
= utp
->number
;
3361 /* Notify 'breakpoint-modified' observer that at least one of B's
3362 locations was changed. */
3363 for (ix
= 0; VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
); ix
++)
3364 observer_notify_breakpoint_modified (b
);
3366 VEC_free (breakpoint_p
, modified_tp
);
3367 free_uploaded_tps (uploaded_tps
);
3370 /* Trace state variables don't have much to identify them beyond their
3371 name, so just use that to detect matches. */
3373 static struct trace_state_variable
*
3374 find_matching_tsv (struct uploaded_tsv
*utsv
)
3379 return find_trace_state_variable (utsv
->name
);
3382 static struct trace_state_variable
*
3383 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
3385 const char *namebase
;
3388 struct trace_state_variable
*tsv
;
3389 struct cleanup
*old_chain
;
3393 namebase
= utsv
->name
;
3394 buf
= xstrprintf ("%s", namebase
);
3399 buf
= xstrprintf ("%s_%d", namebase
, try_num
++);
3402 /* Fish for a name that is not in use. */
3403 /* (should check against all internal vars?) */
3404 while (find_trace_state_variable (buf
))
3407 buf
= xstrprintf ("%s_%d", namebase
, try_num
++);
3410 old_chain
= make_cleanup (xfree
, buf
);
3412 /* We have an available name, create the variable. */
3413 tsv
= create_trace_state_variable (buf
);
3414 tsv
->initial_value
= utsv
->initial_value
;
3415 tsv
->builtin
= utsv
->builtin
;
3417 observer_notify_tsv_created (tsv
);
3419 do_cleanups (old_chain
);
3424 /* Given a list of uploaded trace state variables, try to match them
3425 up with existing variables, or create additional ones. */
3428 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
3431 struct uploaded_tsv
*utsv
;
3432 struct trace_state_variable
*tsv
;
3435 /* Most likely some numbers will have to be reassigned as part of
3436 the merge, so clear them all in anticipation. */
3437 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3440 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
3442 tsv
= find_matching_tsv (utsv
);
3446 printf_filtered (_("Assuming trace state variable $%s "
3447 "is same as target's variable %d.\n"),
3448 tsv
->name
, utsv
->number
);
3452 tsv
= create_tsv_from_upload (utsv
);
3454 printf_filtered (_("Created trace state variable "
3455 "$%s for target's variable %d.\n"),
3456 tsv
->name
, utsv
->number
);
3458 /* Give precedence to numberings that come from the target. */
3460 tsv
->number
= utsv
->number
;
3463 /* Renumber everything that didn't get a target-assigned number. */
3465 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3466 if (tsv
->number
> highest
)
3467 highest
= tsv
->number
;
3470 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3471 if (tsv
->number
== 0)
3472 tsv
->number
= highest
++;
3474 free_uploaded_tsvs (uploaded_tsvs
);
3477 /* Parse the part of trace status syntax that is shared between
3478 the remote protocol and the trace file reader. */
3481 parse_trace_status (char *line
, struct trace_status
*ts
)
3483 char *p
= line
, *p1
, *p2
, *p3
, *p_temp
;
3487 ts
->running_known
= 1;
3488 ts
->running
= (*p
++ == '1');
3489 ts
->stop_reason
= trace_stop_reason_unknown
;
3490 xfree (ts
->stop_desc
);
3491 ts
->stop_desc
= NULL
;
3492 ts
->traceframe_count
= -1;
3493 ts
->traceframes_created
= -1;
3494 ts
->buffer_free
= -1;
3495 ts
->buffer_size
= -1;
3496 ts
->disconnected_tracing
= 0;
3497 ts
->circular_buffer
= 0;
3498 xfree (ts
->user_name
);
3499 ts
->user_name
= NULL
;
3502 ts
->start_time
= ts
->stop_time
= 0;
3506 p1
= strchr (p
, ':');
3508 error (_("Malformed trace status, at %s\n\
3509 Status line: '%s'\n"), p
, line
);
3510 p3
= strchr (p
, ';');
3512 p3
= p
+ strlen (p
);
3513 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
3515 p
= unpack_varlen_hex (++p1
, &val
);
3516 ts
->stop_reason
= trace_buffer_full
;
3518 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
3520 p
= unpack_varlen_hex (++p1
, &val
);
3521 ts
->stop_reason
= trace_never_run
;
3523 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
],
3526 p
= unpack_varlen_hex (++p1
, &val
);
3527 ts
->stop_reason
= tracepoint_passcount
;
3528 ts
->stopping_tracepoint
= val
;
3530 else if (strncmp (p
, stop_reason_names
[tstop_command
], p1
- p
) == 0)
3532 p2
= strchr (++p1
, ':');
3540 ts
->stop_desc
= (char *) xmalloc (strlen (line
));
3541 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3542 ts
->stop_desc
[end
] = '\0';
3545 ts
->stop_desc
= xstrdup ("");
3547 p
= unpack_varlen_hex (++p2
, &val
);
3548 ts
->stop_reason
= tstop_command
;
3550 else if (strncmp (p
, stop_reason_names
[trace_disconnected
], p1
- p
) == 0)
3552 p
= unpack_varlen_hex (++p1
, &val
);
3553 ts
->stop_reason
= trace_disconnected
;
3555 else if (strncmp (p
, stop_reason_names
[tracepoint_error
], p1
- p
) == 0)
3557 p2
= strchr (++p1
, ':');
3560 ts
->stop_desc
= (char *) xmalloc ((p2
- p1
) / 2 + 1);
3561 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
3562 ts
->stop_desc
[end
] = '\0';
3565 ts
->stop_desc
= xstrdup ("");
3567 p
= unpack_varlen_hex (++p2
, &val
);
3568 ts
->stopping_tracepoint
= val
;
3569 ts
->stop_reason
= tracepoint_error
;
3571 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3573 p
= unpack_varlen_hex (++p1
, &val
);
3574 ts
->traceframe_count
= val
;
3576 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3578 p
= unpack_varlen_hex (++p1
, &val
);
3579 ts
->traceframes_created
= val
;
3581 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3583 p
= unpack_varlen_hex (++p1
, &val
);
3584 ts
->buffer_free
= val
;
3586 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3588 p
= unpack_varlen_hex (++p1
, &val
);
3589 ts
->buffer_size
= val
;
3591 else if (strncmp (p
, "disconn", p1
- p
) == 0)
3593 p
= unpack_varlen_hex (++p1
, &val
);
3594 ts
->disconnected_tracing
= val
;
3596 else if (strncmp (p
, "circular", p1
- p
) == 0)
3598 p
= unpack_varlen_hex (++p1
, &val
);
3599 ts
->circular_buffer
= val
;
3601 else if (strncmp (p
, "starttime", p1
- p
) == 0)
3603 p
= unpack_varlen_hex (++p1
, &val
);
3604 ts
->start_time
= val
;
3606 else if (strncmp (p
, "stoptime", p1
- p
) == 0)
3608 p
= unpack_varlen_hex (++p1
, &val
);
3609 ts
->stop_time
= val
;
3611 else if (strncmp (p
, "username", p1
- p
) == 0)
3614 ts
->user_name
= (char *) xmalloc (strlen (p
) / 2);
3615 end
= hex2bin (p1
, (gdb_byte
*) ts
->user_name
, (p3
- p1
) / 2);
3616 ts
->user_name
[end
] = '\0';
3619 else if (strncmp (p
, "notes", p1
- p
) == 0)
3622 ts
->notes
= (char *) xmalloc (strlen (p
) / 2);
3623 end
= hex2bin (p1
, (gdb_byte
*) ts
->notes
, (p3
- p1
) / 2);
3624 ts
->notes
[end
] = '\0';
3629 /* Silently skip unknown optional info. */
3630 p_temp
= strchr (p1
+ 1, ';');
3634 /* Must be at the end. */
3641 parse_tracepoint_status (char *p
, struct breakpoint
*bp
,
3642 struct uploaded_tp
*utp
)
3645 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
3647 p
= unpack_varlen_hex (p
, &uval
);
3649 tp
->base
.hit_count
+= uval
;
3651 utp
->hit_count
+= uval
;
3652 p
= unpack_varlen_hex (p
+ 1, &uval
);
3654 tp
->traceframe_usage
+= uval
;
3656 utp
->traceframe_usage
+= uval
;
3657 /* Ignore any extra, allowing for future extensions. */
3660 /* Given a line of text defining a part of a tracepoint, parse it into
3661 an "uploaded tracepoint". */
3664 parse_tracepoint_definition (char *line
, struct uploaded_tp
**utpp
)
3668 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
, start
;
3671 char *cond
, *srctype
, *buf
;
3672 struct uploaded_tp
*utp
= NULL
;
3675 /* Both tracepoint and action definitions start with the same number
3676 and address sequence. */
3678 p
= unpack_varlen_hex (p
, &num
);
3679 p
++; /* skip a colon */
3680 p
= unpack_varlen_hex (p
, &addr
);
3681 p
++; /* skip a colon */
3684 enabled
= (*p
++ == 'E');
3685 p
++; /* skip a colon */
3686 p
= unpack_varlen_hex (p
, &step
);
3687 p
++; /* skip a colon */
3688 p
= unpack_varlen_hex (p
, &pass
);
3689 type
= bp_tracepoint
;
3691 /* Thumb through optional fields. */
3694 p
++; /* skip a colon */
3697 type
= bp_fast_tracepoint
;
3699 p
= unpack_varlen_hex (p
, &orig_size
);
3703 type
= bp_static_tracepoint
;
3709 p
= unpack_varlen_hex (p
, &xlen
);
3710 p
++; /* skip a comma */
3711 cond
= (char *) xmalloc (2 * xlen
+ 1);
3712 strncpy (cond
, p
, 2 * xlen
);
3713 cond
[2 * xlen
] = '\0';
3717 warning (_("Unrecognized char '%c' in tracepoint "
3718 "definition, skipping rest"), *p
);
3720 utp
= get_uploaded_tp (num
, addr
, utpp
);
3722 utp
->enabled
= enabled
;
3727 else if (piece
== 'A')
3729 utp
= get_uploaded_tp (num
, addr
, utpp
);
3730 VEC_safe_push (char_ptr
, utp
->actions
, xstrdup (p
));
3732 else if (piece
== 'S')
3734 utp
= get_uploaded_tp (num
, addr
, utpp
);
3735 VEC_safe_push (char_ptr
, utp
->step_actions
, xstrdup (p
));
3737 else if (piece
== 'Z')
3739 /* Parse a chunk of source form definition. */
3740 utp
= get_uploaded_tp (num
, addr
, utpp
);
3742 p
= strchr (p
, ':');
3743 p
++; /* skip a colon */
3744 p
= unpack_varlen_hex (p
, &start
);
3745 p
++; /* skip a colon */
3746 p
= unpack_varlen_hex (p
, &xlen
);
3747 p
++; /* skip a colon */
3749 buf
= (char *) alloca (strlen (line
));
3751 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3754 if (startswith (srctype
, "at:"))
3755 utp
->at_string
= xstrdup (buf
);
3756 else if (startswith (srctype
, "cond:"))
3757 utp
->cond_string
= xstrdup (buf
);
3758 else if (startswith (srctype
, "cmd:"))
3759 VEC_safe_push (char_ptr
, utp
->cmd_strings
, xstrdup (buf
));
3761 else if (piece
== 'V')
3763 utp
= get_uploaded_tp (num
, addr
, utpp
);
3765 parse_tracepoint_status (p
, NULL
, utp
);
3769 /* Don't error out, the target might be sending us optional
3770 info that we don't care about. */
3771 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece
);
3775 /* Convert a textual description of a trace state variable into an
3779 parse_tsv_definition (char *line
, struct uploaded_tsv
**utsvp
)
3782 ULONGEST num
, initval
, builtin
;
3784 struct uploaded_tsv
*utsv
= NULL
;
3786 buf
= (char *) alloca (strlen (line
));
3789 p
= unpack_varlen_hex (p
, &num
);
3790 p
++; /* skip a colon */
3791 p
= unpack_varlen_hex (p
, &initval
);
3792 p
++; /* skip a colon */
3793 p
= unpack_varlen_hex (p
, &builtin
);
3794 p
++; /* skip a colon */
3795 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3798 utsv
= get_uploaded_tsv (num
, utsvp
);
3799 utsv
->initial_value
= initval
;
3800 utsv
->builtin
= builtin
;
3801 utsv
->name
= xstrdup (buf
);
3805 free_current_marker (void *arg
)
3807 struct static_tracepoint_marker
**marker_p
3808 = (struct static_tracepoint_marker
**) arg
;
3810 if (*marker_p
!= NULL
)
3812 release_static_tracepoint_marker (*marker_p
);
3819 /* Given a line of text defining a static tracepoint marker, parse it
3820 into a "static tracepoint marker" object. Throws an error is
3821 parsing fails. If PP is non-null, it points to one past the end of
3822 the parsed marker definition. */
3825 parse_static_tracepoint_marker_definition (char *line
, char **pp
,
3826 struct static_tracepoint_marker
*marker
)
3833 p
= unpack_varlen_hex (p
, &addr
);
3834 p
++; /* skip a colon */
3836 marker
->gdbarch
= target_gdbarch ();
3837 marker
->address
= (CORE_ADDR
) addr
;
3839 endp
= strchr (p
, ':');
3841 error (_("bad marker definition: %s"), line
);
3843 marker
->str_id
= (char *) xmalloc (endp
- p
+ 1);
3844 end
= hex2bin (p
, (gdb_byte
*) marker
->str_id
, (endp
- p
+ 1) / 2);
3845 marker
->str_id
[end
] = '\0';
3848 p
++; /* skip a colon */
3850 marker
->extra
= (char *) xmalloc (strlen (p
) + 1);
3851 end
= hex2bin (p
, (gdb_byte
*) marker
->extra
, strlen (p
) / 2);
3852 marker
->extra
[end
] = '\0';
3858 /* Release a static tracepoint marker's contents. Note that the
3859 object itself isn't released here. There objects are usually on
3863 release_static_tracepoint_marker (struct static_tracepoint_marker
*marker
)
3865 xfree (marker
->str_id
);
3866 marker
->str_id
= NULL
;
3869 /* Print MARKER to gdb_stdout. */
3872 print_one_static_tracepoint_marker (int count
,
3873 struct static_tracepoint_marker
*marker
)
3877 char wrap_indent
[80];
3878 char extra_field_indent
[80];
3879 struct ui_out
*uiout
= current_uiout
;
3880 struct cleanup
*bkpt_chain
;
3881 VEC(breakpoint_p
) *tracepoints
;
3883 struct symtab_and_line sal
;
3887 sal
.pc
= marker
->address
;
3889 tracepoints
= static_tracepoints_here (marker
->address
);
3891 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "marker");
3893 /* A counter field to help readability. This is not a stable
3895 ui_out_field_int (uiout
, "count", count
);
3897 ui_out_field_string (uiout
, "marker-id", marker
->str_id
);
3899 ui_out_field_fmt (uiout
, "enabled", "%c",
3900 !VEC_empty (breakpoint_p
, tracepoints
) ? 'y' : 'n');
3901 ui_out_spaces (uiout
, 2);
3903 strcpy (wrap_indent
, " ");
3905 if (gdbarch_addr_bit (marker
->gdbarch
) <= 32)
3906 strcat (wrap_indent
, " ");
3908 strcat (wrap_indent
, " ");
3910 strcpy (extra_field_indent
, " ");
3912 ui_out_field_core_addr (uiout
, "addr", marker
->gdbarch
, marker
->address
);
3914 sal
= find_pc_line (marker
->address
, 0);
3915 sym
= find_pc_sect_function (marker
->address
, NULL
);
3918 ui_out_text (uiout
, "in ");
3919 ui_out_field_string (uiout
, "func",
3920 SYMBOL_PRINT_NAME (sym
));
3921 ui_out_wrap_hint (uiout
, wrap_indent
);
3922 ui_out_text (uiout
, " at ");
3925 ui_out_field_skip (uiout
, "func");
3927 if (sal
.symtab
!= NULL
)
3929 ui_out_field_string (uiout
, "file",
3930 symtab_to_filename_for_display (sal
.symtab
));
3931 ui_out_text (uiout
, ":");
3933 if (ui_out_is_mi_like_p (uiout
))
3935 const char *fullname
= symtab_to_fullname (sal
.symtab
);
3937 ui_out_field_string (uiout
, "fullname", fullname
);
3940 ui_out_field_skip (uiout
, "fullname");
3942 ui_out_field_int (uiout
, "line", sal
.line
);
3946 ui_out_field_skip (uiout
, "fullname");
3947 ui_out_field_skip (uiout
, "line");
3950 ui_out_text (uiout
, "\n");
3951 ui_out_text (uiout
, extra_field_indent
);
3952 ui_out_text (uiout
, _("Data: \""));
3953 ui_out_field_string (uiout
, "extra-data", marker
->extra
);
3954 ui_out_text (uiout
, "\"\n");
3956 if (!VEC_empty (breakpoint_p
, tracepoints
))
3958 struct cleanup
*cleanup_chain
;
3960 struct breakpoint
*b
;
3962 cleanup_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
,
3965 ui_out_text (uiout
, extra_field_indent
);
3966 ui_out_text (uiout
, _("Probed by static tracepoints: "));
3967 for (ix
= 0; VEC_iterate(breakpoint_p
, tracepoints
, ix
, b
); ix
++)
3970 ui_out_text (uiout
, ", ");
3971 ui_out_text (uiout
, "#");
3972 ui_out_field_int (uiout
, "tracepoint-id", b
->number
);
3975 do_cleanups (cleanup_chain
);
3977 if (ui_out_is_mi_like_p (uiout
))
3978 ui_out_field_int (uiout
, "number-of-tracepoints",
3979 VEC_length(breakpoint_p
, tracepoints
));
3981 ui_out_text (uiout
, "\n");
3983 VEC_free (breakpoint_p
, tracepoints
);
3985 do_cleanups (bkpt_chain
);
3989 info_static_tracepoint_markers_command (char *arg
, int from_tty
)
3991 VEC(static_tracepoint_marker_p
) *markers
;
3992 struct cleanup
*old_chain
;
3993 struct static_tracepoint_marker
*marker
;
3994 struct ui_out
*uiout
= current_uiout
;
3997 /* We don't have to check target_can_use_agent and agent's capability on
3998 static tracepoint here, in order to be compatible with older GDBserver.
3999 We don't check USE_AGENT is true or not, because static tracepoints
4000 don't work without in-process agent, so we don't bother users to type
4001 `set agent on' when to use static tracepoint. */
4004 = make_cleanup_ui_out_table_begin_end (uiout
, 5, -1,
4005 "StaticTracepointMarkersTable");
4007 ui_out_table_header (uiout
, 7, ui_left
, "counter", "Cnt");
4009 ui_out_table_header (uiout
, 40, ui_left
, "marker-id", "ID");
4011 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb");
4012 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
4013 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");
4015 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");
4016 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What");
4018 ui_out_table_body (uiout
);
4020 markers
= target_static_tracepoint_markers_by_strid (NULL
);
4021 make_cleanup (VEC_cleanup (static_tracepoint_marker_p
), &markers
);
4024 VEC_iterate (static_tracepoint_marker_p
,
4025 markers
, i
, marker
);
4028 print_one_static_tracepoint_marker (i
+ 1, marker
);
4029 release_static_tracepoint_marker (marker
);
4032 do_cleanups (old_chain
);
4035 /* The $_sdata convenience variable is a bit special. We don't know
4036 for sure type of the value until we actually have a chance to fetch
4037 the data --- the size of the object depends on what has been
4038 collected. We solve this by making $_sdata be an internalvar that
4039 creates a new value on access. */
4041 /* Return a new value with the correct type for the sdata object of
4042 the current trace frame. Return a void value if there's no object
4045 static struct value
*
4046 sdata_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
4052 /* We need to read the whole object before we know its size. */
4053 size
= target_read_alloc (¤t_target
,
4054 TARGET_OBJECT_STATIC_TRACE_DATA
,
4061 type
= init_vector_type (builtin_type (gdbarch
)->builtin_true_char
,
4063 v
= allocate_value (type
);
4064 memcpy (value_contents_raw (v
), buf
, size
);
4069 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
4072 #if !defined(HAVE_LIBEXPAT)
4074 struct traceframe_info
*
4075 parse_traceframe_info (const char *tframe_info
)
4077 static int have_warned
;
4082 warning (_("Can not parse XML trace frame info; XML support "
4083 "was disabled at compile time"));
4089 #else /* HAVE_LIBEXPAT */
4091 #include "xml-support.h"
4093 /* Handle the start of a <memory> element. */
4096 traceframe_info_start_memory (struct gdb_xml_parser
*parser
,
4097 const struct gdb_xml_element
*element
,
4098 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
4100 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
4101 struct mem_range
*r
= VEC_safe_push (mem_range_s
, info
->memory
, NULL
);
4102 ULONGEST
*start_p
, *length_p
;
4105 = (ULONGEST
*) xml_find_attribute (attributes
, "start")->value
;
4107 = (ULONGEST
*) xml_find_attribute (attributes
, "length")->value
;
4109 r
->start
= *start_p
;
4110 r
->length
= *length_p
;
4113 /* Handle the start of a <tvar> element. */
4116 traceframe_info_start_tvar (struct gdb_xml_parser
*parser
,
4117 const struct gdb_xml_element
*element
,
4119 VEC(gdb_xml_value_s
) *attributes
)
4121 struct traceframe_info
*info
= (struct traceframe_info
*) user_data
;
4122 const char *id_attrib
4123 = (const char *) xml_find_attribute (attributes
, "id")->value
;
4124 int id
= gdb_xml_parse_ulongest (parser
, id_attrib
);
4126 VEC_safe_push (int, info
->tvars
, id
);
4129 /* Discard the constructed trace frame info (if an error occurs). */
4132 free_result (void *p
)
4134 struct traceframe_info
*result
= (struct traceframe_info
*) p
;
4136 free_traceframe_info (result
);
4139 /* The allowed elements and attributes for an XML memory map. */
4141 static const struct gdb_xml_attribute memory_attributes
[] = {
4142 { "start", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
4143 { "length", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
4144 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
4147 static const struct gdb_xml_attribute tvar_attributes
[] = {
4148 { "id", GDB_XML_AF_NONE
, NULL
, NULL
},
4149 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
4152 static const struct gdb_xml_element traceframe_info_children
[] = {
4153 { "memory", memory_attributes
, NULL
,
4154 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
4155 traceframe_info_start_memory
, NULL
},
4156 { "tvar", tvar_attributes
, NULL
,
4157 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
4158 traceframe_info_start_tvar
, NULL
},
4159 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
4162 static const struct gdb_xml_element traceframe_info_elements
[] = {
4163 { "traceframe-info", NULL
, traceframe_info_children
, GDB_XML_EF_NONE
,
4165 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
4168 /* Parse a traceframe-info XML document. */
4170 struct traceframe_info
*
4171 parse_traceframe_info (const char *tframe_info
)
4173 struct traceframe_info
*result
;
4174 struct cleanup
*back_to
;
4176 result
= XCNEW (struct traceframe_info
);
4177 back_to
= make_cleanup (free_result
, result
);
4179 if (gdb_xml_parse_quick (_("trace frame info"),
4180 "traceframe-info.dtd", traceframe_info_elements
,
4181 tframe_info
, result
) == 0)
4183 /* Parsed successfully, keep the result. */
4184 discard_cleanups (back_to
);
4189 do_cleanups (back_to
);
4193 #endif /* HAVE_LIBEXPAT */
4195 /* Returns the traceframe_info object for the current traceframe.
4196 This is where we avoid re-fetching the object from the target if we
4197 already have it cached. */
4199 struct traceframe_info
*
4200 get_traceframe_info (void)
4202 if (traceframe_info
== NULL
)
4203 traceframe_info
= target_traceframe_info ();
4205 return traceframe_info
;
4208 /* If the target supports the query, return in RESULT the set of
4209 collected memory in the current traceframe, found within the LEN
4210 bytes range starting at MEMADDR. Returns true if the target
4211 supports the query, otherwise returns false, and RESULT is left
4215 traceframe_available_memory (VEC(mem_range_s
) **result
,
4216 CORE_ADDR memaddr
, ULONGEST len
)
4218 struct traceframe_info
*info
= get_traceframe_info ();
4222 struct mem_range
*r
;
4227 for (i
= 0; VEC_iterate (mem_range_s
, info
->memory
, i
, r
); i
++)
4228 if (mem_ranges_overlap (r
->start
, r
->length
, memaddr
, len
))
4230 ULONGEST lo1
, hi1
, lo2
, hi2
;
4231 struct mem_range
*nr
;
4234 hi1
= memaddr
+ len
;
4237 hi2
= r
->start
+ r
->length
;
4239 nr
= VEC_safe_push (mem_range_s
, *result
, NULL
);
4241 nr
->start
= std::max (lo1
, lo2
);
4242 nr
->length
= std::min (hi1
, hi2
) - nr
->start
;
4245 normalize_mem_ranges (*result
);
4252 /* Implementation of `sdata' variable. */
4254 static const struct internalvar_funcs sdata_funcs
=
4261 /* module initialization */
4263 _initialize_tracepoint (void)
4265 struct cmd_list_element
*c
;
4267 /* Explicitly create without lookup, since that tries to create a
4268 value with a void typed value, and when we get here, gdbarch
4269 isn't initialized yet. At this point, we're quite sure there
4270 isn't another convenience variable of the same name. */
4271 create_internalvar_type_lazy ("_sdata", &sdata_funcs
, NULL
);
4273 traceframe_number
= -1;
4274 tracepoint_number
= -1;
4276 add_info ("scope", scope_info
,
4277 _("List the variables local to a scope"));
4279 add_cmd ("tracepoints", class_trace
, NULL
,
4280 _("Tracing of program execution without stopping the program."),
4283 add_com ("tdump", class_trace
, trace_dump_command
,
4284 _("Print everything collected at the current tracepoint."));
4286 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
4287 Define a trace state variable.\n\
4288 Argument is a $-prefixed name, optionally followed\n\
4289 by '=' and an expression that sets the initial value\n\
4290 at the start of tracing."));
4291 set_cmd_completer (c
, expression_completer
);
4293 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
4294 Delete one or more trace state variables.\n\
4295 Arguments are the names of the variables to delete.\n\
4296 If no arguments are supplied, delete all variables."), &deletelist
);
4297 /* FIXME add a trace variable completer. */
4299 add_info ("tvariables", tvariables_info
, _("\
4300 Status of trace state variables and their values.\n\
4303 add_info ("static-tracepoint-markers",
4304 info_static_tracepoint_markers_command
, _("\
4305 List target static tracepoints markers.\n\
4308 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
4309 Select a trace frame;\n\
4310 No argument means forward by one frame; '-' means backward by one frame."),
4311 &tfindlist
, "tfind ", 1, &cmdlist
);
4313 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
4314 Select a trace frame whose PC is outside the given range (exclusive).\n\
4315 Usage: tfind outside addr1, addr2"),
4318 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
4319 Select a trace frame whose PC is in the given range (inclusive).\n\
4320 Usage: tfind range addr1,addr2"),
4323 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
4324 Select a trace frame by source line.\n\
4325 Argument can be a line number (with optional source file),\n\
4326 a function name, or '*' followed by an address.\n\
4327 Default argument is 'the next source line that was traced'."),
4330 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
4331 Select a trace frame by tracepoint number.\n\
4332 Default is the tracepoint for the current trace frame."),
4335 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
4336 Select a trace frame by PC.\n\
4337 Default is the current PC, or the PC of the current trace frame."),
4340 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
4341 De-select any trace frame and resume 'live' debugging."),
4344 add_alias_cmd ("none", "end", class_trace
, 0, &tfindlist
);
4346 add_cmd ("start", class_trace
, trace_find_start_command
,
4347 _("Select the first trace frame in the trace buffer."),
4350 add_com ("tstatus", class_trace
, trace_status_command
,
4351 _("Display the status of the current trace data collection."));
4353 add_com ("tstop", class_trace
, trace_stop_command
, _("\
4354 Stop trace data collection.\n\
4355 Usage: tstop [ <notes> ... ]\n\
4356 Any arguments supplied are recorded with the trace as a stop reason and\n\
4357 reported by tstatus (if the target supports trace notes)."));
4359 add_com ("tstart", class_trace
, trace_start_command
, _("\
4360 Start trace data collection.\n\
4361 Usage: tstart [ <notes> ... ]\n\
4362 Any arguments supplied are recorded with the trace as a note and\n\
4363 reported by tstatus (if the target supports trace notes)."));
4365 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
4366 Ends a list of commands or actions.\n\
4367 Several GDB commands allow you to enter a list of commands or actions.\n\
4368 Entering \"end\" on a line by itself is the normal way to terminate\n\
4370 Note: the \"end\" command cannot be used at the gdb prompt."));
4372 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
4373 Specify single-stepping behavior at a tracepoint.\n\
4374 Argument is number of instructions to trace in single-step mode\n\
4375 following the tracepoint. This command is normally followed by\n\
4376 one or more \"collect\" commands, to specify what to collect\n\
4377 while single-stepping.\n\n\
4378 Note: this command can only be used in a tracepoint \"actions\" list."));
4380 add_com_alias ("ws", "while-stepping", class_alias
, 0);
4381 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
4383 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
4384 Specify one or more data items to be collected at a tracepoint.\n\
4385 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4386 collect all data (variables, registers) referenced by that expression.\n\
4387 Also accepts the following special arguments:\n\
4388 $regs -- all registers.\n\
4389 $args -- all function arguments.\n\
4390 $locals -- all variables local to the block/function scope.\n\
4391 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
4392 Note: this command can only be used in a tracepoint \"actions\" list."));
4394 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
4395 Specify one or more expressions to be evaluated at a tracepoint.\n\
4396 Accepts a comma-separated list of (one or more) expressions.\n\
4397 The result of each evaluation will be discarded.\n\
4398 Note: this command can only be used in a tracepoint \"actions\" list."));
4400 add_com ("actions", class_trace
, trace_actions_command
, _("\
4401 Specify the actions to be taken at a tracepoint.\n\
4402 Tracepoint actions may include collecting of specified data,\n\
4403 single-stepping, or enabling/disabling other tracepoints,\n\
4404 depending on target's capabilities."));
4406 default_collect
= xstrdup ("");
4407 add_setshow_string_cmd ("default-collect", class_trace
,
4408 &default_collect
, _("\
4409 Set the list of expressions to collect by default"), _("\
4410 Show the list of expressions to collect by default"), NULL
,
4412 &setlist
, &showlist
);
4414 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
4415 &disconnected_tracing
, _("\
4416 Set whether tracing continues after GDB disconnects."), _("\
4417 Show whether tracing continues after GDB disconnects."), _("\
4418 Use this to continue a tracing run even if GDB disconnects\n\
4419 or detaches from the target. You can reconnect later and look at\n\
4420 trace data collected in the meantime."),
4421 set_disconnected_tracing
,
4426 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
4427 &circular_trace_buffer
, _("\
4428 Set target's use of circular trace buffer."), _("\
4429 Show target's use of circular trace buffer."), _("\
4430 Use this to make the trace buffer into a circular buffer,\n\
4431 which will discard traceframes (oldest first) instead of filling\n\
4432 up and stopping the trace run."),
4433 set_circular_trace_buffer
,
4438 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class
,
4439 &trace_buffer_size
, _("\
4440 Set requested size of trace buffer."), _("\
4441 Show requested size of trace buffer."), _("\
4442 Use this to choose a size for the trace buffer. Some targets\n\
4443 may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
4444 disables any attempt to set the buffer size and lets the target choose."),
4445 set_trace_buffer_size
, NULL
,
4446 &setlist
, &showlist
);
4448 add_setshow_string_cmd ("trace-user", class_trace
,
4450 Set the user name to use for current and future trace runs"), _("\
4451 Show the user name to use for current and future trace runs"), NULL
,
4452 set_trace_user
, NULL
,
4453 &setlist
, &showlist
);
4455 add_setshow_string_cmd ("trace-notes", class_trace
,
4457 Set notes string to use for current and future trace runs"), _("\
4458 Show the notes string to use for current and future trace runs"), NULL
,
4459 set_trace_notes
, NULL
,
4460 &setlist
, &showlist
);
4462 add_setshow_string_cmd ("trace-stop-notes", class_trace
,
4463 &trace_stop_notes
, _("\
4464 Set notes string to use for future tstop commands"), _("\
4465 Show the notes string to use for future tstop commands"), NULL
,
4466 set_trace_stop_notes
, NULL
,
4467 &setlist
, &showlist
);