1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997-2013 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"
30 #include "gdb_string.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"
53 #include "exceptions.h"
54 #include "cli/cli-utils.h"
57 #include "completer.h"
58 #include "filestuff.h"
60 /* readline include files */
61 #include "readline/readline.h"
62 #include "readline/history.h"
64 /* readline defines this. */
75 /* Maximum length of an agent aexpression.
76 This accounts for the fact that packets are limited to 400 bytes
77 (which includes everything -- including the checksum), and assumes
78 the worst case of maximum length for each of the pieces of a
81 NOTE: expressions get mem2hex'ed otherwise this would be twice as
82 large. (400 - 31)/2 == 184 */
83 #define MAX_AGENT_EXPR_LEN 184
85 /* A hook used to notify the UI of tracepoint operations. */
87 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
88 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
90 extern void (*deprecated_readline_begin_hook
) (char *, ...);
91 extern char *(*deprecated_readline_hook
) (char *);
92 extern void (*deprecated_readline_end_hook
) (void);
97 This module defines the following debugger commands:
98 trace : set a tracepoint on a function, line, or address.
99 info trace : list all debugger-defined tracepoints.
100 delete trace : delete one or more tracepoints.
101 enable trace : enable one or more tracepoints.
102 disable trace : disable one or more tracepoints.
103 actions : specify actions to be taken at a tracepoint.
104 passcount : specify a pass count for a tracepoint.
105 tstart : start a trace experiment.
106 tstop : stop a trace experiment.
107 tstatus : query the status of a trace experiment.
108 tfind : find a trace frame in the trace buffer.
109 tdump : print everything collected at the current tracepoint.
110 save-tracepoints : write tracepoint setup into a file.
112 This module defines the following user-visible debugger variables:
113 $trace_frame : sequence number of trace frame currently being debugged.
114 $trace_line : source line of trace frame currently being debugged.
115 $trace_file : source file of trace frame currently being debugged.
116 $tracepoint : tracepoint number of trace frame currently being debugged.
120 /* ======= Important global variables: ======= */
122 /* The list of all trace state variables. We don't retain pointers to
123 any of these for any reason - API is by name or number only - so it
124 works to have a vector of objects. */
126 typedef struct trace_state_variable tsv_s
;
129 static VEC(tsv_s
) *tvariables
;
131 /* The next integer to assign to a variable. */
133 static int next_tsv_number
= 1;
135 /* Number of last traceframe collected. */
136 static int traceframe_number
;
138 /* Tracepoint for last traceframe collected. */
139 static int tracepoint_number
;
141 /* Symbol for function for last traceframe collected. */
142 static struct symbol
*traceframe_fun
;
144 /* Symtab and line for last traceframe collected. */
145 static struct symtab_and_line traceframe_sal
;
147 /* The traceframe info of the current traceframe. NULL if we haven't
148 yet attempted to fetch it, or if the target does not support
149 fetching this object, or if we're not inspecting a traceframe
151 static struct traceframe_info
*traceframe_info
;
153 /* Tracing command lists. */
154 static struct cmd_list_element
*tfindlist
;
156 /* List of expressions to collect by default at each tracepoint hit. */
157 char *default_collect
= "";
159 static int disconnected_tracing
;
161 /* This variable controls whether we ask the target for a linear or
162 circular trace buffer. */
164 static int circular_trace_buffer
;
166 /* This variable is the requested trace buffer size, or -1 to indicate
167 that we don't care and leave it up to the target to set a size. */
169 static int trace_buffer_size
= -1;
171 /* Textual notes applying to the current and/or future trace runs. */
173 char *trace_user
= NULL
;
175 /* Textual notes applying to the current and/or future trace runs. */
177 char *trace_notes
= NULL
;
179 /* Textual notes applying to the stopping of a trace. */
181 char *trace_stop_notes
= NULL
;
183 /* ======= Important command functions: ======= */
184 static void trace_actions_command (char *, int);
185 static void trace_start_command (char *, int);
186 static void trace_stop_command (char *, int);
187 static void trace_status_command (char *, int);
188 static void trace_find_command (char *, int);
189 static void trace_find_pc_command (char *, int);
190 static void trace_find_tracepoint_command (char *, int);
191 static void trace_find_line_command (char *, int);
192 static void trace_find_range_command (char *, int);
193 static void trace_find_outside_command (char *, int);
194 static void trace_dump_command (char *, int);
196 /* support routines */
198 struct collection_list
;
199 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
200 static char *mem2hex (gdb_byte
*, char *, int);
201 static void add_register (struct collection_list
*collection
,
204 static void free_uploaded_tps (struct uploaded_tp
**utpp
);
205 static void free_uploaded_tsvs (struct uploaded_tsv
**utsvp
);
208 extern void _initialize_tracepoint (void);
210 static struct trace_status trace_status
;
212 char *stop_reason_names
[] = {
222 struct trace_status
*
223 current_trace_status (void)
225 return &trace_status
;
231 free_traceframe_info (struct traceframe_info
*info
)
235 VEC_free (mem_range_s
, info
->memory
);
241 /* Free and clear the traceframe info cache of the current
245 clear_traceframe_info (void)
247 free_traceframe_info (traceframe_info
);
248 traceframe_info
= NULL
;
251 /* Set traceframe number to NUM. */
253 set_traceframe_num (int num
)
255 traceframe_number
= num
;
256 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
259 /* Set tracepoint number to NUM. */
261 set_tracepoint_num (int num
)
263 tracepoint_number
= num
;
264 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
267 /* Set externally visible debug variables for querying/printing
268 the traceframe context (line, function, file). */
271 set_traceframe_context (struct frame_info
*trace_frame
)
275 /* Save as globals for internal use. */
276 if (trace_frame
!= NULL
277 && get_frame_pc_if_available (trace_frame
, &trace_pc
))
279 traceframe_sal
= find_pc_line (trace_pc
, 0);
280 traceframe_fun
= find_pc_function (trace_pc
);
282 /* Save linenumber as "$trace_line", a debugger variable visible to
284 set_internalvar_integer (lookup_internalvar ("trace_line"),
285 traceframe_sal
.line
);
289 init_sal (&traceframe_sal
);
290 traceframe_fun
= NULL
;
291 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
294 /* Save func name as "$trace_func", a debugger variable visible to
296 if (traceframe_fun
== NULL
297 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
298 clear_internalvar (lookup_internalvar ("trace_func"));
300 set_internalvar_string (lookup_internalvar ("trace_func"),
301 SYMBOL_LINKAGE_NAME (traceframe_fun
));
303 /* Save file name as "$trace_file", a debugger variable visible to
305 if (traceframe_sal
.symtab
== NULL
)
306 clear_internalvar (lookup_internalvar ("trace_file"));
308 set_internalvar_string (lookup_internalvar ("trace_file"),
309 symtab_to_filename_for_display (traceframe_sal
.symtab
));
312 /* Create a new trace state variable with the given name. */
314 struct trace_state_variable
*
315 create_trace_state_variable (const char *name
)
317 struct trace_state_variable tsv
;
319 memset (&tsv
, 0, sizeof (tsv
));
320 tsv
.name
= xstrdup (name
);
321 tsv
.number
= next_tsv_number
++;
322 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
325 /* Look for a trace state variable of the given name. */
327 struct trace_state_variable
*
328 find_trace_state_variable (const char *name
)
330 struct trace_state_variable
*tsv
;
333 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
334 if (strcmp (name
, tsv
->name
) == 0)
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
, 1);
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 expression
*exp
= NULL
;
702 struct cleanup
*old_chain
= NULL
;
705 struct bp_location
*loc
;
706 struct agent_expr
*aexpr
;
707 struct tracepoint
*t
= (struct tracepoint
*) b
;
709 /* If EOF is typed, *line is NULL. */
713 p
= skip_spaces_const (line
);
715 /* Symbol lookup etc. */
716 if (*p
== '\0') /* empty line: just prompt for another line. */
719 if (*p
== '#') /* comment line */
722 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
724 error (_("`%s' is not a tracepoint action, or is ambiguous."), p
);
726 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
728 int trace_string
= 0;
731 p
= decode_agent_options (p
, &trace_string
);
734 { /* Repeat over a comma-separated list. */
735 QUIT
; /* Allow user to bail out with ^C. */
736 p
= skip_spaces_const (p
);
738 if (*p
== '$') /* Look for special pseudo-symbols. */
740 if (0 == strncasecmp ("reg", p
+ 1, 3)
741 || 0 == strncasecmp ("arg", p
+ 1, 3)
742 || 0 == strncasecmp ("loc", p
+ 1, 3)
743 || 0 == strncasecmp ("_ret", p
+ 1, 4)
744 || 0 == strncasecmp ("_sdata", p
+ 1, 6))
749 /* else fall thru, treat p as an expression and parse it! */
752 for (loc
= t
->base
.loc
; loc
; loc
= loc
->next
)
755 exp
= parse_exp_1 (&p
, loc
->address
,
756 block_for_pc (loc
->address
), 1);
757 old_chain
= make_cleanup (free_current_contents
, &exp
);
759 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
761 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
763 error (_("constant `%s' (value %s) "
764 "will not be collected."),
765 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
766 plongest (SYMBOL_VALUE (exp
->elts
[2].symbol
)));
768 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
)
769 == LOC_OPTIMIZED_OUT
)
771 error (_("`%s' is optimized away "
772 "and cannot be collected."),
773 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
777 /* We have something to collect, make sure that the expr to
778 bytecode translator can handle it and that it's not too
780 aexpr
= gen_trace_for_expr (loc
->address
, exp
, trace_string
);
781 make_cleanup_free_agent_expr (aexpr
);
783 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
784 error (_("Expression is too complicated."));
788 report_agent_reqs_errors (aexpr
);
790 do_cleanups (old_chain
);
793 while (p
&& *p
++ == ',');
796 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
799 { /* Repeat over a comma-separated list. */
800 QUIT
; /* Allow user to bail out with ^C. */
801 p
= skip_spaces_const (p
);
804 for (loc
= t
->base
.loc
; loc
; loc
= loc
->next
)
808 /* Only expressions are allowed for this action. */
809 exp
= parse_exp_1 (&p
, loc
->address
,
810 block_for_pc (loc
->address
), 1);
811 old_chain
= make_cleanup (free_current_contents
, &exp
);
813 /* We have something to evaluate, make sure that the expr to
814 bytecode translator can handle it and that it's not too
816 aexpr
= gen_eval_for_expr (loc
->address
, exp
);
817 make_cleanup_free_agent_expr (aexpr
);
819 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
820 error (_("Expression is too complicated."));
823 report_agent_reqs_errors (aexpr
);
825 do_cleanups (old_chain
);
828 while (p
&& *p
++ == ',');
831 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
835 p
= skip_spaces_const (p
);
836 t
->step_count
= strtol (p
, &endp
, 0);
837 if (endp
== p
|| t
->step_count
== 0)
838 error (_("while-stepping step count `%s' is malformed."), line
);
842 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
846 error (_("`%s' is not a supported tracepoint action."), line
);
850 memrange_absolute
= -1
855 int type
; /* memrange_absolute for absolute memory range,
856 else basereg number. */
857 bfd_signed_vma start
;
861 struct collection_list
863 unsigned char regs_mask
[32]; /* room for up to 256 regs */
866 struct memrange
*list
;
867 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
869 struct agent_expr
**aexpr_list
;
871 /* True is the user requested a collection of "$_sdata", "static
875 tracepoint_list
, stepping_list
;
877 /* MEMRANGE functions: */
879 static int memrange_cmp (const void *, const void *);
881 /* Compare memranges for qsort. */
883 memrange_cmp (const void *va
, const void *vb
)
885 const struct memrange
*a
= va
, *b
= vb
;
887 if (a
->type
< b
->type
)
889 if (a
->type
> b
->type
)
891 if (a
->type
== memrange_absolute
)
893 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
895 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
900 if (a
->start
< b
->start
)
902 if (a
->start
> b
->start
)
908 /* Sort the memrange list using qsort, and merge adjacent memranges. */
910 memrange_sortmerge (struct collection_list
*memranges
)
914 qsort (memranges
->list
, memranges
->next_memrange
,
915 sizeof (struct memrange
), memrange_cmp
);
916 if (memranges
->next_memrange
> 0)
918 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
920 /* If memrange b overlaps or is adjacent to memrange a,
922 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
923 && memranges
->list
[b
].start
<= memranges
->list
[a
].end
)
925 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
926 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
927 continue; /* next b, same a */
931 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
932 sizeof (struct memrange
));
934 memranges
->next_memrange
= a
+ 1;
938 /* Add a register to a collection list. */
940 add_register (struct collection_list
*collection
, unsigned int regno
)
943 printf_filtered ("collect register %d\n", regno
);
944 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
945 error (_("Internal: register number %d too large for tracepoint"),
947 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
950 /* Add a memrange to a collection list. */
952 add_memrange (struct collection_list
*memranges
,
953 int type
, bfd_signed_vma base
,
958 printf_filtered ("(%d,", type
);
960 printf_filtered (",%ld)\n", len
);
963 /* type: memrange_absolute == memory, other n == basereg */
964 memranges
->list
[memranges
->next_memrange
].type
= type
;
965 /* base: addr if memory, offset if reg relative. */
966 memranges
->list
[memranges
->next_memrange
].start
= base
;
967 /* len: we actually save end (base + len) for convenience */
968 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
969 memranges
->next_memrange
++;
970 if (memranges
->next_memrange
>= memranges
->listsize
)
972 memranges
->listsize
*= 2;
973 memranges
->list
= xrealloc (memranges
->list
,
974 memranges
->listsize
);
977 if (type
!= memrange_absolute
) /* Better collect the base register! */
978 add_register (memranges
, type
);
981 /* Add a symbol to a collection list. */
983 collect_symbol (struct collection_list
*collect
,
985 struct gdbarch
*gdbarch
,
986 long frame_regno
, long frame_offset
,
992 bfd_signed_vma offset
;
993 int treat_as_expr
= 0;
995 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
996 switch (SYMBOL_CLASS (sym
))
999 printf_filtered ("%s: don't know symbol class %d\n",
1000 SYMBOL_PRINT_NAME (sym
),
1001 SYMBOL_CLASS (sym
));
1004 printf_filtered ("constant %s (value %s) will not be collected.\n",
1005 SYMBOL_PRINT_NAME (sym
), plongest (SYMBOL_VALUE (sym
)));
1008 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1013 sprintf_vma (tmp
, offset
);
1014 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1015 SYMBOL_PRINT_NAME (sym
), len
,
1018 /* A struct may be a C++ class with static fields, go to general
1019 expression handling. */
1020 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1023 add_memrange (collect
, memrange_absolute
, offset
, len
);
1026 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1028 printf_filtered ("LOC_REG[parm] %s: ",
1029 SYMBOL_PRINT_NAME (sym
));
1030 add_register (collect
, reg
);
1031 /* Check for doubles stored in two registers. */
1032 /* FIXME: how about larger types stored in 3 or more regs? */
1033 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
1034 len
> register_size (gdbarch
, reg
))
1035 add_register (collect
, reg
+ 1);
1038 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1039 printf_filtered (" (will not collect %s)\n",
1040 SYMBOL_PRINT_NAME (sym
));
1044 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1047 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1048 SYMBOL_PRINT_NAME (sym
), len
);
1049 printf_vma (offset
);
1050 printf_filtered (" from frame ptr reg %d\n", reg
);
1052 add_memrange (collect
, reg
, offset
, len
);
1054 case LOC_REGPARM_ADDR
:
1055 reg
= SYMBOL_VALUE (sym
);
1059 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1060 SYMBOL_PRINT_NAME (sym
), len
);
1061 printf_vma (offset
);
1062 printf_filtered (" from reg %d\n", reg
);
1064 add_memrange (collect
, reg
, offset
, len
);
1068 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1071 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1072 SYMBOL_PRINT_NAME (sym
), len
);
1073 printf_vma (offset
);
1074 printf_filtered (" from frame ptr reg %d\n", reg
);
1076 add_memrange (collect
, reg
, offset
, len
);
1079 case LOC_UNRESOLVED
:
1083 case LOC_OPTIMIZED_OUT
:
1084 printf_filtered ("%s has been optimized out of existence.\n",
1085 SYMBOL_PRINT_NAME (sym
));
1093 /* Expressions are the most general case. */
1096 struct agent_expr
*aexpr
;
1097 struct cleanup
*old_chain1
= NULL
;
1099 aexpr
= gen_trace_for_var (scope
, gdbarch
, sym
, trace_string
);
1101 /* It can happen that the symbol is recorded as a computed
1102 location, but it's been optimized away and doesn't actually
1103 have a location expression. */
1106 printf_filtered ("%s has been optimized out of existence.\n",
1107 SYMBOL_PRINT_NAME (sym
));
1111 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1115 report_agent_reqs_errors (aexpr
);
1117 discard_cleanups (old_chain1
);
1118 add_aexpr (collect
, aexpr
);
1120 /* Take care of the registers. */
1121 if (aexpr
->reg_mask_len
> 0)
1125 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1127 QUIT
; /* Allow user to bail out with ^C. */
1128 if (aexpr
->reg_mask
[ndx1
] != 0)
1130 /* Assume chars have 8 bits. */
1131 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1132 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1133 /* It's used -- record it. */
1134 add_register (collect
, ndx1
* 8 + ndx2
);
1141 /* Data to be passed around in the calls to the locals and args
1144 struct add_local_symbols_data
1146 struct collection_list
*collect
;
1147 struct gdbarch
*gdbarch
;
1155 /* The callback for the locals and args iterators. */
1158 do_collect_symbol (const char *print_name
,
1162 struct add_local_symbols_data
*p
= cb_data
;
1164 collect_symbol (p
->collect
, sym
, p
->gdbarch
, p
->frame_regno
,
1165 p
->frame_offset
, p
->pc
, p
->trace_string
);
1169 /* Add all locals (or args) symbols to collection list. */
1171 add_local_symbols (struct collection_list
*collect
,
1172 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1173 long frame_regno
, long frame_offset
, int type
,
1176 struct block
*block
;
1177 struct add_local_symbols_data cb_data
;
1179 cb_data
.collect
= collect
;
1180 cb_data
.gdbarch
= gdbarch
;
1182 cb_data
.frame_regno
= frame_regno
;
1183 cb_data
.frame_offset
= frame_offset
;
1185 cb_data
.trace_string
= trace_string
;
1189 block
= block_for_pc (pc
);
1192 warning (_("Can't collect locals; "
1193 "no symbol table info available.\n"));
1197 iterate_over_block_local_vars (block
, do_collect_symbol
, &cb_data
);
1198 if (cb_data
.count
== 0)
1199 warning (_("No locals found in scope."));
1203 pc
= get_pc_function_start (pc
);
1204 block
= block_for_pc (pc
);
1207 warning (_("Can't collect args; no symbol table info available."));
1211 iterate_over_block_arg_vars (block
, do_collect_symbol
, &cb_data
);
1212 if (cb_data
.count
== 0)
1213 warning (_("No args found in scope."));
1218 add_static_trace_data (struct collection_list
*collection
)
1221 printf_filtered ("collect static trace data\n");
1222 collection
->strace_data
= 1;
1225 /* worker function */
1227 clear_collection_list (struct collection_list
*list
)
1231 list
->next_memrange
= 0;
1232 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1234 free_agent_expr (list
->aexpr_list
[ndx
]);
1235 list
->aexpr_list
[ndx
] = NULL
;
1237 list
->next_aexpr_elt
= 0;
1238 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1239 list
->strace_data
= 0;
1242 /* Reduce a collection list to string form (for gdb protocol). */
1244 stringify_collection_list (struct collection_list
*list
)
1246 char temp_buf
[2048];
1250 char *(*str_list
)[];
1254 count
= 1 + 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1255 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1257 if (list
->strace_data
)
1260 printf_filtered ("\nCollecting static trace data\n");
1263 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1267 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1268 if (list
->regs_mask
[i
] != 0) /* Skip leading zeroes in regs_mask. */
1270 if (list
->regs_mask
[i
] != 0) /* Prepare to send regs_mask to the stub. */
1273 printf_filtered ("\nCollecting registers (mask): 0x");
1278 QUIT
; /* Allow user to bail out with ^C. */
1280 printf_filtered ("%02X", list
->regs_mask
[i
]);
1281 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1284 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1288 printf_filtered ("\n");
1289 if (list
->next_memrange
> 0 && info_verbose
)
1290 printf_filtered ("Collecting memranges: \n");
1291 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1293 QUIT
; /* Allow user to bail out with ^C. */
1294 sprintf_vma (tmp2
, list
->list
[i
].start
);
1297 printf_filtered ("(%d, %s, %ld)\n",
1300 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1302 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1304 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1311 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
1313 /* The "%X" conversion specifier expects an unsigned argument,
1314 so passing -1 (memrange_absolute) to it directly gives you
1315 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1317 if (list
->list
[i
].type
== memrange_absolute
)
1318 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1320 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
1323 count
+= strlen (end
);
1324 end
= temp_buf
+ count
;
1327 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1329 QUIT
; /* Allow user to bail out with ^C. */
1330 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1332 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1337 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1338 end
+= 10; /* 'X' + 8 hex digits + ',' */
1341 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1342 end
, list
->aexpr_list
[i
]->len
);
1343 count
+= 2 * list
->aexpr_list
[i
]->len
;
1348 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1353 (*str_list
)[ndx
] = NULL
;
1366 encode_actions_1 (struct command_line
*action
,
1367 struct bp_location
*tloc
,
1369 LONGEST frame_offset
,
1370 struct collection_list
*collect
,
1371 struct collection_list
*stepping_list
)
1373 const char *action_exp
;
1374 struct expression
*exp
= NULL
;
1376 struct value
*tempval
;
1377 struct cmd_list_element
*cmd
;
1378 struct agent_expr
*aexpr
;
1380 for (; action
; action
= action
->next
)
1382 QUIT
; /* Allow user to bail out with ^C. */
1383 action_exp
= action
->line
;
1384 action_exp
= skip_spaces_const (action_exp
);
1386 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1388 error (_("Bad action list item: %s"), action_exp
);
1390 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1392 int trace_string
= 0;
1394 if (*action_exp
== '/')
1395 action_exp
= decode_agent_options (action_exp
, &trace_string
);
1398 { /* Repeat over a comma-separated list. */
1399 QUIT
; /* Allow user to bail out with ^C. */
1400 action_exp
= skip_spaces_const (action_exp
);
1402 if (0 == strncasecmp ("$reg", action_exp
, 4))
1404 for (i
= 0; i
< gdbarch_num_regs (tloc
->gdbarch
); i
++)
1405 add_register (collect
, i
);
1406 action_exp
= strchr (action_exp
, ','); /* more? */
1408 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1410 add_local_symbols (collect
,
1417 action_exp
= strchr (action_exp
, ','); /* more? */
1419 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1421 add_local_symbols (collect
,
1428 action_exp
= strchr (action_exp
, ','); /* more? */
1430 else if (0 == strncasecmp ("$_ret", action_exp
, 5))
1432 struct cleanup
*old_chain1
= NULL
;
1434 aexpr
= gen_trace_for_return_address (tloc
->address
,
1438 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1441 report_agent_reqs_errors (aexpr
);
1443 discard_cleanups (old_chain1
);
1444 add_aexpr (collect
, aexpr
);
1446 /* take care of the registers */
1447 if (aexpr
->reg_mask_len
> 0)
1451 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1453 QUIT
; /* allow user to bail out with ^C */
1454 if (aexpr
->reg_mask
[ndx1
] != 0)
1456 /* assume chars have 8 bits */
1457 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1458 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1459 /* it's used -- record it */
1460 add_register (collect
,
1466 action_exp
= strchr (action_exp
, ','); /* more? */
1468 else if (0 == strncasecmp ("$_sdata", action_exp
, 7))
1470 add_static_trace_data (collect
);
1471 action_exp
= strchr (action_exp
, ','); /* more? */
1476 struct cleanup
*old_chain
= NULL
;
1477 struct cleanup
*old_chain1
= NULL
;
1479 exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1480 block_for_pc (tloc
->address
), 1);
1481 old_chain
= make_cleanup (free_current_contents
, &exp
);
1483 switch (exp
->elts
[0].opcode
)
1487 const char *name
= &exp
->elts
[2].string
;
1489 i
= user_reg_map_name_to_regnum (tloc
->gdbarch
,
1490 name
, strlen (name
));
1492 internal_error (__FILE__
, __LINE__
,
1493 _("Register $%s not available"),
1496 printf_filtered ("OP_REGISTER: ");
1497 add_register (collect
, i
);
1502 /* Safe because we know it's a simple expression. */
1503 tempval
= evaluate_expression (exp
);
1504 addr
= value_address (tempval
);
1505 /* Initialize the TYPE_LENGTH if it is a typedef. */
1506 check_typedef (exp
->elts
[1].type
);
1507 add_memrange (collect
, memrange_absolute
, addr
,
1508 TYPE_LENGTH (exp
->elts
[1].type
));
1512 collect_symbol (collect
,
1513 exp
->elts
[2].symbol
,
1521 default: /* Full-fledged expression. */
1522 aexpr
= gen_trace_for_expr (tloc
->address
, exp
,
1525 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1529 report_agent_reqs_errors (aexpr
);
1531 discard_cleanups (old_chain1
);
1532 add_aexpr (collect
, aexpr
);
1534 /* Take care of the registers. */
1535 if (aexpr
->reg_mask_len
> 0)
1540 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1542 QUIT
; /* Allow user to bail out with ^C. */
1543 if (aexpr
->reg_mask
[ndx1
] != 0)
1545 /* Assume chars have 8 bits. */
1546 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1547 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1548 /* It's used -- record it. */
1549 add_register (collect
,
1556 do_cleanups (old_chain
);
1559 while (action_exp
&& *action_exp
++ == ',');
1561 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1564 { /* Repeat over a comma-separated list. */
1565 QUIT
; /* Allow user to bail out with ^C. */
1566 action_exp
= skip_spaces_const (action_exp
);
1569 struct cleanup
*old_chain
= NULL
;
1570 struct cleanup
*old_chain1
= NULL
;
1572 exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1573 block_for_pc (tloc
->address
), 1);
1574 old_chain
= make_cleanup (free_current_contents
, &exp
);
1576 aexpr
= gen_eval_for_expr (tloc
->address
, exp
);
1577 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1580 report_agent_reqs_errors (aexpr
);
1582 discard_cleanups (old_chain1
);
1583 /* Even though we're not officially collecting, add
1584 to the collect list anyway. */
1585 add_aexpr (collect
, aexpr
);
1587 do_cleanups (old_chain
);
1590 while (action_exp
&& *action_exp
++ == ',');
1592 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1594 /* We check against nested while-stepping when setting
1595 breakpoint action, so no way to run into nested
1597 gdb_assert (stepping_list
);
1599 encode_actions_1 (action
->body_list
[0], tloc
, frame_reg
,
1600 frame_offset
, stepping_list
, NULL
);
1603 error (_("Invalid tracepoint command '%s'"), action
->line
);
1607 /* Render all actions into gdb protocol. */
1610 encode_actions (struct bp_location
*tloc
, char ***tdp_actions
,
1611 char ***stepping_actions
)
1613 char *default_collect_line
= NULL
;
1614 struct command_line
*actions
;
1615 struct command_line
*default_collect_action
= NULL
;
1617 LONGEST frame_offset
;
1618 struct cleanup
*back_to
;
1620 back_to
= make_cleanup (null_cleanup
, NULL
);
1622 clear_collection_list (&tracepoint_list
);
1623 clear_collection_list (&stepping_list
);
1625 *tdp_actions
= NULL
;
1626 *stepping_actions
= NULL
;
1628 gdbarch_virtual_frame_pointer (tloc
->gdbarch
,
1629 tloc
->address
, &frame_reg
, &frame_offset
);
1631 actions
= breakpoint_commands (tloc
->owner
);
1633 /* If there are default expressions to collect, make up a collect
1634 action and prepend to the action list to encode. Note that since
1635 validation is per-tracepoint (local var "xyz" might be valid for
1636 one tracepoint and not another, etc), we make up the action on
1637 the fly, and don't cache it. */
1638 if (*default_collect
)
1640 default_collect_line
= xstrprintf ("collect %s", default_collect
);
1641 make_cleanup (xfree
, default_collect_line
);
1643 validate_actionline (default_collect_line
, tloc
->owner
);
1645 default_collect_action
= xmalloc (sizeof (struct command_line
));
1646 make_cleanup (xfree
, default_collect_action
);
1647 default_collect_action
->next
= actions
;
1648 default_collect_action
->line
= default_collect_line
;
1649 actions
= default_collect_action
;
1651 encode_actions_1 (actions
, tloc
, frame_reg
, frame_offset
,
1652 &tracepoint_list
, &stepping_list
);
1654 memrange_sortmerge (&tracepoint_list
);
1655 memrange_sortmerge (&stepping_list
);
1657 *tdp_actions
= stringify_collection_list (&tracepoint_list
);
1658 *stepping_actions
= stringify_collection_list (&stepping_list
);
1660 do_cleanups (back_to
);
1664 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1666 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1668 collect
->aexpr_list
=
1669 xrealloc (collect
->aexpr_list
,
1670 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1671 collect
->aexpr_listsize
*= 2;
1673 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1674 collect
->next_aexpr_elt
++;
1678 process_tracepoint_on_disconnect (void)
1680 VEC(breakpoint_p
) *tp_vec
= NULL
;
1682 struct breakpoint
*b
;
1683 int has_pending_p
= 0;
1685 /* Check whether we still have pending tracepoint. If we have, warn the
1686 user that pending tracepoint will no longer work. */
1687 tp_vec
= all_tracepoints ();
1688 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1697 struct bp_location
*loc1
;
1699 for (loc1
= b
->loc
; loc1
; loc1
= loc1
->next
)
1701 if (loc1
->shlib_disabled
)
1712 VEC_free (breakpoint_p
, tp_vec
);
1715 warning (_("Pending tracepoints will not be resolved while"
1716 " GDB is disconnected\n"));
1721 start_tracing (char *notes
)
1723 VEC(breakpoint_p
) *tp_vec
= NULL
;
1725 struct breakpoint
*b
;
1726 struct trace_state_variable
*tsv
;
1727 int any_enabled
= 0, num_to_download
= 0;
1730 tp_vec
= all_tracepoints ();
1732 /* No point in tracing without any tracepoints... */
1733 if (VEC_length (breakpoint_p
, tp_vec
) == 0)
1735 VEC_free (breakpoint_p
, tp_vec
);
1736 error (_("No tracepoints defined, not starting trace"));
1739 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1741 struct tracepoint
*t
= (struct tracepoint
*) b
;
1742 struct bp_location
*loc
;
1744 if (b
->enable_state
== bp_enabled
)
1747 if ((b
->type
== bp_fast_tracepoint
1748 ? may_insert_fast_tracepoints
1749 : may_insert_tracepoints
))
1752 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1753 (b
->type
== bp_fast_tracepoint
? "fast " : ""), b
->number
);
1758 if (target_supports_enable_disable_tracepoint ())
1759 warning (_("No tracepoints enabled"));
1762 /* No point in tracing with only disabled tracepoints that
1763 cannot be re-enabled. */
1764 VEC_free (breakpoint_p
, tp_vec
);
1765 error (_("No tracepoints enabled, not starting trace"));
1769 if (num_to_download
<= 0)
1771 VEC_free (breakpoint_p
, tp_vec
);
1772 error (_("No tracepoints that may be downloaded, not starting trace"));
1775 target_trace_init ();
1777 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1779 struct tracepoint
*t
= (struct tracepoint
*) b
;
1780 struct bp_location
*loc
;
1781 int bp_location_downloaded
= 0;
1783 /* Clear `inserted' flag. */
1784 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1787 if ((b
->type
== bp_fast_tracepoint
1788 ? !may_insert_fast_tracepoints
1789 : !may_insert_tracepoints
))
1792 t
->number_on_target
= 0;
1794 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1796 /* Since tracepoint locations are never duplicated, `inserted'
1797 flag should be zero. */
1798 gdb_assert (!loc
->inserted
);
1800 target_download_tracepoint (loc
);
1803 bp_location_downloaded
= 1;
1806 t
->number_on_target
= b
->number
;
1808 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1809 if (loc
->probe
!= NULL
)
1810 loc
->probe
->pops
->set_semaphore (loc
->probe
, loc
->gdbarch
);
1812 if (bp_location_downloaded
)
1813 observer_notify_breakpoint_modified (b
);
1815 VEC_free (breakpoint_p
, tp_vec
);
1817 /* Send down all the trace state variables too. */
1818 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1820 target_download_trace_state_variable (tsv
);
1823 /* Tell target to treat text-like sections as transparent. */
1824 target_trace_set_readonly_regions ();
1825 /* Set some mode flags. */
1826 target_set_disconnected_tracing (disconnected_tracing
);
1827 target_set_circular_trace_buffer (circular_trace_buffer
);
1828 target_set_trace_buffer_size (trace_buffer_size
);
1831 notes
= trace_notes
;
1832 ret
= target_set_trace_notes (trace_user
, notes
, NULL
);
1834 if (!ret
&& (trace_user
|| notes
))
1835 warning (_("Target does not support trace user/notes, info ignored"));
1837 /* Now insert traps and begin collecting data. */
1838 target_trace_start ();
1840 /* Reset our local state. */
1841 set_traceframe_num (-1);
1842 set_tracepoint_num (-1);
1843 set_traceframe_context (NULL
);
1844 current_trace_status()->running
= 1;
1845 clear_traceframe_info ();
1848 /* The tstart command requests the target to start a new trace run.
1849 The command passes any arguments it has to the target verbatim, as
1850 an optional "trace note". This is useful as for instance a warning
1851 to other users if the trace runs disconnected, and you don't want
1852 anybody else messing with the target. */
1855 trace_start_command (char *args
, int from_tty
)
1857 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1859 if (current_trace_status ()->running
)
1862 && !query (_("A trace is running already. Start a new run? ")))
1863 error (_("New trace run not started."));
1866 start_tracing (args
);
1869 /* The tstop command stops the tracing run. The command passes any
1870 supplied arguments to the target verbatim as a "stop note"; if the
1871 target supports trace notes, then it will be reported back as part
1872 of the trace run's status. */
1875 trace_stop_command (char *args
, int from_tty
)
1877 if (!current_trace_status ()->running
)
1878 error (_("Trace is not running."));
1880 stop_tracing (args
);
1884 stop_tracing (char *note
)
1887 VEC(breakpoint_p
) *tp_vec
= NULL
;
1889 struct breakpoint
*t
;
1891 target_trace_stop ();
1893 tp_vec
= all_tracepoints ();
1894 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1896 struct bp_location
*loc
;
1898 if ((t
->type
== bp_fast_tracepoint
1899 ? !may_insert_fast_tracepoints
1900 : !may_insert_tracepoints
))
1903 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
1905 /* GDB can be totally absent in some disconnected trace scenarios,
1906 but we don't really care if this semaphore goes out of sync.
1907 That's why we are decrementing it here, but not taking care
1909 if (loc
->probe
!= NULL
)
1910 loc
->probe
->pops
->clear_semaphore (loc
->probe
, loc
->gdbarch
);
1914 VEC_free (breakpoint_p
, tp_vec
);
1917 note
= trace_stop_notes
;
1918 ret
= target_set_trace_notes (NULL
, NULL
, note
);
1921 warning (_("Target does not support trace notes, note ignored"));
1923 /* Should change in response to reply? */
1924 current_trace_status ()->running
= 0;
1927 /* tstatus command */
1929 trace_status_command (char *args
, int from_tty
)
1931 struct trace_status
*ts
= current_trace_status ();
1933 VEC(breakpoint_p
) *tp_vec
= NULL
;
1934 struct breakpoint
*t
;
1936 status
= target_get_trace_status (ts
);
1940 if (ts
->filename
!= NULL
)
1941 printf_filtered (_("Using a trace file.\n"));
1944 printf_filtered (_("Trace can not be run on this target.\n"));
1949 if (!ts
->running_known
)
1951 printf_filtered (_("Run/stop status is unknown.\n"));
1953 else if (ts
->running
)
1955 printf_filtered (_("Trace is running on the target.\n"));
1959 switch (ts
->stop_reason
)
1961 case trace_never_run
:
1962 printf_filtered (_("No trace has been run on the target.\n"));
1966 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1969 printf_filtered (_("Trace stopped by a tstop command.\n"));
1971 case trace_buffer_full
:
1972 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1974 case trace_disconnected
:
1975 printf_filtered (_("Trace stopped because of disconnection.\n"));
1977 case tracepoint_passcount
:
1978 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1979 ts
->stopping_tracepoint
);
1981 case tracepoint_error
:
1982 if (ts
->stopping_tracepoint
)
1983 printf_filtered (_("Trace stopped by an "
1984 "error (%s, tracepoint %d).\n"),
1985 ts
->stop_desc
, ts
->stopping_tracepoint
);
1987 printf_filtered (_("Trace stopped by an error (%s).\n"),
1990 case trace_stop_reason_unknown
:
1991 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1994 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
2000 if (ts
->traceframes_created
>= 0
2001 && ts
->traceframe_count
!= ts
->traceframes_created
)
2003 printf_filtered (_("Buffer contains %d trace "
2004 "frames (of %d created total).\n"),
2005 ts
->traceframe_count
, ts
->traceframes_created
);
2007 else if (ts
->traceframe_count
>= 0)
2009 printf_filtered (_("Collected %d trace frames.\n"),
2010 ts
->traceframe_count
);
2013 if (ts
->buffer_free
>= 0)
2015 if (ts
->buffer_size
>= 0)
2017 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
2018 ts
->buffer_free
, ts
->buffer_size
);
2019 if (ts
->buffer_size
> 0)
2020 printf_filtered (_(" (%d%% full)"),
2021 ((int) ((((long long) (ts
->buffer_size
2022 - ts
->buffer_free
)) * 100)
2023 / ts
->buffer_size
)));
2024 printf_filtered (_(".\n"));
2027 printf_filtered (_("Trace buffer has %d bytes free.\n"),
2031 if (ts
->disconnected_tracing
)
2032 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
2034 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
2036 if (ts
->circular_buffer
)
2037 printf_filtered (_("Trace buffer is circular.\n"));
2039 if (ts
->user_name
&& strlen (ts
->user_name
) > 0)
2040 printf_filtered (_("Trace user is %s.\n"), ts
->user_name
);
2042 if (ts
->notes
&& strlen (ts
->notes
) > 0)
2043 printf_filtered (_("Trace notes: %s.\n"), ts
->notes
);
2045 /* Now report on what we're doing with tfind. */
2046 if (traceframe_number
>= 0)
2047 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
2048 traceframe_number
, tracepoint_number
);
2050 printf_filtered (_("Not looking at any trace frame.\n"));
2052 /* Report start/stop times if supplied. */
2057 LONGEST run_time
= ts
->stop_time
- ts
->start_time
;
2059 /* Reporting a run time is more readable than two long numbers. */
2060 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
2061 (long int) ts
->start_time
/ 1000000,
2062 (long int) ts
->start_time
% 1000000,
2063 (long int) run_time
/ 1000000,
2064 (long int) run_time
% 1000000);
2067 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
2068 (long int) ts
->start_time
/ 1000000,
2069 (long int) ts
->start_time
% 1000000);
2071 else if (ts
->stop_time
)
2072 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
2073 (long int) ts
->stop_time
/ 1000000,
2074 (long int) ts
->stop_time
% 1000000);
2076 /* Now report any per-tracepoint status available. */
2077 tp_vec
= all_tracepoints ();
2079 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
2080 target_get_tracepoint_status (t
, NULL
);
2082 VEC_free (breakpoint_p
, tp_vec
);
2085 /* Report the trace status to uiout, in a way suitable for MI, and not
2086 suitable for CLI. If ON_STOP is true, suppress a few fields that
2087 are not meaningful in the -trace-stop response.
2089 The implementation is essentially parallel to trace_status_command, but
2090 merging them will result in unreadable code. */
2092 trace_status_mi (int on_stop
)
2094 struct ui_out
*uiout
= current_uiout
;
2095 struct trace_status
*ts
= current_trace_status ();
2098 status
= target_get_trace_status (ts
);
2100 if (status
== -1 && ts
->filename
== NULL
)
2102 ui_out_field_string (uiout
, "supported", "0");
2106 if (ts
->filename
!= NULL
)
2107 ui_out_field_string (uiout
, "supported", "file");
2109 ui_out_field_string (uiout
, "supported", "1");
2111 if (ts
->filename
!= NULL
)
2112 ui_out_field_string (uiout
, "trace-file", ts
->filename
);
2114 gdb_assert (ts
->running_known
);
2118 ui_out_field_string (uiout
, "running", "1");
2120 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
2121 Given that the frontend gets the status either on -trace-stop, or from
2122 -trace-status after re-connection, it does not seem like this
2123 information is necessary for anything. It is not necessary for either
2124 figuring the vital state of the target nor for navigation of trace
2125 frames. If the frontend wants to show the current state is some
2126 configure dialog, it can request the value when such dialog is
2127 invoked by the user. */
2131 char *stop_reason
= NULL
;
2132 int stopping_tracepoint
= -1;
2135 ui_out_field_string (uiout
, "running", "0");
2137 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
2139 switch (ts
->stop_reason
)
2142 stop_reason
= "request";
2144 case trace_buffer_full
:
2145 stop_reason
= "overflow";
2147 case trace_disconnected
:
2148 stop_reason
= "disconnection";
2150 case tracepoint_passcount
:
2151 stop_reason
= "passcount";
2152 stopping_tracepoint
= ts
->stopping_tracepoint
;
2154 case tracepoint_error
:
2155 stop_reason
= "error";
2156 stopping_tracepoint
= ts
->stopping_tracepoint
;
2162 ui_out_field_string (uiout
, "stop-reason", stop_reason
);
2163 if (stopping_tracepoint
!= -1)
2164 ui_out_field_int (uiout
, "stopping-tracepoint",
2165 stopping_tracepoint
);
2166 if (ts
->stop_reason
== tracepoint_error
)
2167 ui_out_field_string (uiout
, "error-description",
2173 if (ts
->traceframe_count
!= -1)
2174 ui_out_field_int (uiout
, "frames", ts
->traceframe_count
);
2175 if (ts
->traceframes_created
!= -1)
2176 ui_out_field_int (uiout
, "frames-created", ts
->traceframes_created
);
2177 if (ts
->buffer_size
!= -1)
2178 ui_out_field_int (uiout
, "buffer-size", ts
->buffer_size
);
2179 if (ts
->buffer_free
!= -1)
2180 ui_out_field_int (uiout
, "buffer-free", ts
->buffer_free
);
2182 ui_out_field_int (uiout
, "disconnected", ts
->disconnected_tracing
);
2183 ui_out_field_int (uiout
, "circular", ts
->circular_buffer
);
2185 ui_out_field_string (uiout
, "user-name", ts
->user_name
);
2186 ui_out_field_string (uiout
, "notes", ts
->notes
);
2191 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2192 (long int) ts
->start_time
/ 1000000,
2193 (long int) ts
->start_time
% 1000000);
2194 ui_out_field_string (uiout
, "start-time", buf
);
2195 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2196 (long int) ts
->stop_time
/ 1000000,
2197 (long int) ts
->stop_time
% 1000000);
2198 ui_out_field_string (uiout
, "stop-time", buf
);
2202 /* Check if a trace run is ongoing. If so, and FROM_TTY, query the
2203 user if she really wants to detach. */
2206 query_if_trace_running (int from_tty
)
2211 /* It can happen that the target that was tracing went away on its
2212 own, and we didn't notice. Get a status update, and if the
2213 current target doesn't even do tracing, then assume it's not
2215 if (target_get_trace_status (current_trace_status ()) < 0)
2216 current_trace_status ()->running
= 0;
2218 /* If running interactively, give the user the option to cancel and
2219 then decide what to do differently with the run. Scripts are
2220 just going to disconnect and let the target deal with it,
2221 according to how it's been instructed previously via
2222 disconnected-tracing. */
2223 if (current_trace_status ()->running
)
2225 process_tracepoint_on_disconnect ();
2227 if (current_trace_status ()->disconnected_tracing
)
2229 if (!query (_("Trace is running and will "
2230 "continue after detach; detach anyway? ")))
2231 error (_("Not confirmed."));
2235 if (!query (_("Trace is running but will "
2236 "stop on detach; detach anyway? ")))
2237 error (_("Not confirmed."));
2242 /* This function handles the details of what to do about an ongoing
2243 tracing run if the user has asked to detach or otherwise disconnect
2247 disconnect_tracing (void)
2249 /* Also we want to be out of tfind mode, otherwise things can get
2250 confusing upon reconnection. Just use these calls instead of
2251 full tfind_1 behavior because we're in the middle of detaching,
2252 and there's no point to updating current stack frame etc. */
2253 set_current_traceframe (-1);
2254 set_tracepoint_num (-1);
2255 set_traceframe_context (NULL
);
2258 /* Worker function for the various flavors of the tfind command. */
2260 tfind_1 (enum trace_find_type type
, int num
,
2261 CORE_ADDR addr1
, CORE_ADDR addr2
,
2264 int target_frameno
= -1, target_tracept
= -1;
2265 struct frame_id old_frame_id
= null_frame_id
;
2266 struct tracepoint
*tp
;
2267 struct ui_out
*uiout
= current_uiout
;
2269 /* Only try to get the current stack frame if we have a chance of
2270 succeeding. In particular, if we're trying to get a first trace
2271 frame while all threads are running, it's not going to succeed,
2272 so leave it with a default value and let the frame comparison
2273 below (correctly) decide to print out the source location of the
2275 if (!(type
== tfind_number
&& num
== -1)
2276 && (has_stack_frames () || traceframe_number
>= 0))
2277 old_frame_id
= get_frame_id (get_current_frame ());
2279 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
2282 if (type
== tfind_number
2284 && target_frameno
== -1)
2286 /* We told the target to get out of tfind mode, and it did. */
2288 else if (target_frameno
== -1)
2290 /* A request for a non-existent trace frame has failed.
2291 Our response will be different, depending on FROM_TTY:
2293 If FROM_TTY is true, meaning that this command was
2294 typed interactively by the user, then give an error
2295 and DO NOT change the state of traceframe_number etc.
2297 However if FROM_TTY is false, meaning that we're either
2298 in a script, a loop, or a user-defined command, then
2299 DON'T give an error, but DO change the state of
2300 traceframe_number etc. to invalid.
2302 The rationalle is that if you typed the command, you
2303 might just have committed a typo or something, and you'd
2304 like to NOT lose your current debugging state. However
2305 if you're in a user-defined command or especially in a
2306 loop, then you need a way to detect that the command
2307 failed WITHOUT aborting. This allows you to write
2308 scripts that search thru the trace buffer until the end,
2309 and then continue on to do something else. */
2312 error (_("Target failed to find requested trace frame."));
2316 printf_filtered ("End of trace buffer.\n");
2317 #if 0 /* dubious now? */
2318 /* The following will not recurse, since it's
2320 trace_find_command ("-1", from_tty
);
2325 tp
= get_tracepoint_by_number_on_target (target_tracept
);
2327 reinit_frame_cache ();
2328 target_dcache_invalidate ();
2330 set_tracepoint_num (tp
? tp
->base
.number
: target_tracept
);
2332 if (target_frameno
!= get_traceframe_number ())
2333 observer_notify_traceframe_changed (target_frameno
, tracepoint_number
);
2335 set_current_traceframe (target_frameno
);
2337 if (target_frameno
== -1)
2338 set_traceframe_context (NULL
);
2340 set_traceframe_context (get_current_frame ());
2342 if (traceframe_number
>= 0)
2344 /* Use different branches for MI and CLI to make CLI messages
2346 if (ui_out_is_mi_like_p (uiout
))
2348 ui_out_field_string (uiout
, "found", "1");
2349 ui_out_field_int (uiout
, "tracepoint", tracepoint_number
);
2350 ui_out_field_int (uiout
, "traceframe", traceframe_number
);
2354 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2355 traceframe_number
, tracepoint_number
);
2360 if (ui_out_is_mi_like_p (uiout
))
2361 ui_out_field_string (uiout
, "found", "0");
2362 else if (type
== tfind_number
&& num
== -1)
2363 printf_unfiltered (_("No longer looking at any trace frame\n"));
2364 else /* This case may never occur, check. */
2365 printf_unfiltered (_("No trace frame found\n"));
2368 /* If we're in nonstop mode and getting out of looking at trace
2369 frames, there won't be any current frame to go back to and
2372 && (has_stack_frames () || traceframe_number
>= 0))
2374 enum print_what print_what
;
2376 /* NOTE: in imitation of the step command, try to determine
2377 whether we have made a transition from one function to
2378 another. If so, we'll print the "stack frame" (ie. the new
2379 function and it's arguments) -- otherwise we'll just show the
2382 if (frame_id_eq (old_frame_id
,
2383 get_frame_id (get_current_frame ())))
2384 print_what
= SRC_LINE
;
2386 print_what
= SRC_AND_LOC
;
2388 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
2393 /* trace_find_command takes a trace frame number n,
2394 sends "QTFrame:<n>" to the target,
2395 and accepts a reply that may contain several optional pieces
2396 of information: a frame number, a tracepoint number, and an
2397 indication of whether this is a trap frame or a stepping frame.
2399 The minimal response is just "OK" (which indicates that the
2400 target does not give us a frame number or a tracepoint number).
2401 Instead of that, the target may send us a string containing
2403 F<hexnum> (gives the selected frame number)
2404 T<hexnum> (gives the selected tracepoint number)
2409 trace_find_command (char *args
, int from_tty
)
2410 { /* This should only be called with a numeric argument. */
2413 if (current_trace_status ()->running
2414 && current_trace_status ()->filename
== NULL
)
2415 error (_("May not look at trace frames while trace is running."));
2417 if (args
== 0 || *args
== 0)
2418 { /* TFIND with no args means find NEXT trace frame. */
2419 if (traceframe_number
== -1)
2420 frameno
= 0; /* "next" is first one. */
2422 frameno
= traceframe_number
+ 1;
2424 else if (0 == strcmp (args
, "-"))
2426 if (traceframe_number
== -1)
2427 error (_("not debugging trace buffer"));
2428 else if (from_tty
&& traceframe_number
== 0)
2429 error (_("already at start of trace buffer"));
2431 frameno
= traceframe_number
- 1;
2433 /* A hack to work around eval's need for fp to have been collected. */
2434 else if (0 == strcmp (args
, "-1"))
2437 frameno
= parse_and_eval_long (args
);
2440 error (_("invalid input (%d is less than zero)"), frameno
);
2442 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
2447 trace_find_end_command (char *args
, int from_tty
)
2449 trace_find_command ("-1", from_tty
);
2454 trace_find_start_command (char *args
, int from_tty
)
2456 trace_find_command ("0", from_tty
);
2459 /* tfind pc command */
2461 trace_find_pc_command (char *args
, int from_tty
)
2465 if (current_trace_status ()->running
2466 && current_trace_status ()->filename
== NULL
)
2467 error (_("May not look at trace frames while trace is running."));
2469 if (args
== 0 || *args
== 0)
2470 pc
= regcache_read_pc (get_current_regcache ());
2472 pc
= parse_and_eval_address (args
);
2474 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
2477 /* tfind tracepoint command */
2479 trace_find_tracepoint_command (char *args
, int from_tty
)
2482 struct tracepoint
*tp
;
2484 if (current_trace_status ()->running
2485 && current_trace_status ()->filename
== NULL
)
2486 error (_("May not look at trace frames while trace is running."));
2488 if (args
== 0 || *args
== 0)
2490 if (tracepoint_number
== -1)
2491 error (_("No current tracepoint -- please supply an argument."));
2493 tdp
= tracepoint_number
; /* Default is current TDP. */
2496 tdp
= parse_and_eval_long (args
);
2498 /* If we have the tracepoint on hand, use the number that the
2499 target knows about (which may be different if we disconnected
2500 and reconnected). */
2501 tp
= get_tracepoint (tdp
);
2503 tdp
= tp
->number_on_target
;
2505 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
2508 /* TFIND LINE command:
2510 This command will take a sourceline for argument, just like BREAK
2511 or TRACE (ie. anything that "decode_line_1" can handle).
2513 With no argument, this command will find the next trace frame
2514 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2517 trace_find_line_command (char *args
, int from_tty
)
2519 static CORE_ADDR start_pc
, end_pc
;
2520 struct symtabs_and_lines sals
;
2521 struct symtab_and_line sal
;
2522 struct cleanup
*old_chain
;
2524 if (current_trace_status ()->running
2525 && current_trace_status ()->filename
== NULL
)
2526 error (_("May not look at trace frames while trace is running."));
2528 if (args
== 0 || *args
== 0)
2530 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2532 sals
.sals
= (struct symtab_and_line
*)
2533 xmalloc (sizeof (struct symtab_and_line
));
2538 sals
= decode_line_with_current_source (args
, DECODE_LINE_FUNFIRSTLINE
);
2542 old_chain
= make_cleanup (xfree
, sals
.sals
);
2543 if (sal
.symtab
== 0)
2544 error (_("No line number information available."));
2546 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2548 if (start_pc
== end_pc
)
2550 printf_filtered ("Line %d of \"%s\"",
2552 symtab_to_filename_for_display (sal
.symtab
));
2554 printf_filtered (" is at address ");
2555 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2557 printf_filtered (" but contains no code.\n");
2558 sal
= find_pc_line (start_pc
, 0);
2560 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2561 && start_pc
!= end_pc
)
2562 printf_filtered ("Attempting to find line %d instead.\n",
2565 error (_("Cannot find a good line."));
2569 /* Is there any case in which we get here, and have an address
2570 which the user would want to see? If we have debugging
2571 symbols and no line numbers? */
2572 error (_("Line number %d is out of range for \"%s\"."),
2573 sal
.line
, symtab_to_filename_for_display (sal
.symtab
));
2575 /* Find within range of stated line. */
2577 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2579 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2580 do_cleanups (old_chain
);
2583 /* tfind range command */
2585 trace_find_range_command (char *args
, int from_tty
)
2587 static CORE_ADDR start
, stop
;
2590 if (current_trace_status ()->running
2591 && current_trace_status ()->filename
== NULL
)
2592 error (_("May not look at trace frames while trace is running."));
2594 if (args
== 0 || *args
== 0)
2595 { /* XXX FIXME: what should default behavior be? */
2596 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2600 if (0 != (tmp
= strchr (args
, ',')))
2602 *tmp
++ = '\0'; /* Terminate start address. */
2603 tmp
= skip_spaces (tmp
);
2604 start
= parse_and_eval_address (args
);
2605 stop
= parse_and_eval_address (tmp
);
2608 { /* No explicit end address? */
2609 start
= parse_and_eval_address (args
);
2610 stop
= start
+ 1; /* ??? */
2613 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2616 /* tfind outside command */
2618 trace_find_outside_command (char *args
, int from_tty
)
2620 CORE_ADDR start
, stop
;
2623 if (current_trace_status ()->running
2624 && current_trace_status ()->filename
== NULL
)
2625 error (_("May not look at trace frames while trace is running."));
2627 if (args
== 0 || *args
== 0)
2628 { /* XXX FIXME: what should default behavior be? */
2629 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2633 if (0 != (tmp
= strchr (args
, ',')))
2635 *tmp
++ = '\0'; /* Terminate start address. */
2636 tmp
= skip_spaces (tmp
);
2637 start
= parse_and_eval_address (args
);
2638 stop
= parse_and_eval_address (tmp
);
2641 { /* No explicit end address? */
2642 start
= parse_and_eval_address (args
);
2643 stop
= start
+ 1; /* ??? */
2646 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2649 /* info scope command: list the locals for a scope. */
2651 scope_info (char *args
, int from_tty
)
2653 struct symtabs_and_lines sals
;
2655 struct minimal_symbol
*msym
;
2656 struct block
*block
;
2657 const char *symname
;
2658 char *save_args
= args
;
2659 struct block_iterator iter
;
2661 struct gdbarch
*gdbarch
;
2664 if (args
== 0 || *args
== 0)
2665 error (_("requires an argument (function, "
2666 "line or *addr) to define a scope"));
2668 sals
= decode_line_1 (&args
, DECODE_LINE_FUNFIRSTLINE
, NULL
, 0);
2669 if (sals
.nelts
== 0)
2670 return; /* Presumably decode_line_1 has already warned. */
2672 /* Resolve line numbers to PC. */
2673 resolve_sal_pc (&sals
.sals
[0]);
2674 block
= block_for_pc (sals
.sals
[0].pc
);
2678 QUIT
; /* Allow user to bail out with ^C. */
2679 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2681 QUIT
; /* Allow user to bail out with ^C. */
2683 printf_filtered ("Scope for %s:\n", save_args
);
2686 symname
= SYMBOL_PRINT_NAME (sym
);
2687 if (symname
== NULL
|| *symname
== '\0')
2688 continue; /* Probably botched, certainly useless. */
2690 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
2692 printf_filtered ("Symbol %s is ", symname
);
2694 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
2695 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
,
2696 BLOCK_START (block
),
2700 switch (SYMBOL_CLASS (sym
))
2703 case LOC_UNDEF
: /* Messed up symbol? */
2704 printf_filtered ("a bogus symbol, class %d.\n",
2705 SYMBOL_CLASS (sym
));
2706 count
--; /* Don't count this one. */
2709 printf_filtered ("a constant with value %s (%s)",
2710 plongest (SYMBOL_VALUE (sym
)),
2711 hex_string (SYMBOL_VALUE (sym
)));
2713 case LOC_CONST_BYTES
:
2714 printf_filtered ("constant bytes: ");
2715 if (SYMBOL_TYPE (sym
))
2716 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2717 fprintf_filtered (gdb_stdout
, " %02x",
2718 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2721 printf_filtered ("in static storage at address ");
2722 printf_filtered ("%s", paddress (gdbarch
,
2723 SYMBOL_VALUE_ADDRESS (sym
)));
2726 /* GDBARCH is the architecture associated with the objfile
2727 the symbol is defined in; the target architecture may be
2728 different, and may provide additional registers. However,
2729 we do not know the target architecture at this point.
2730 We assume the objfile architecture will contain all the
2731 standard registers that occur in debug info in that
2733 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2736 if (SYMBOL_IS_ARGUMENT (sym
))
2737 printf_filtered ("an argument in register $%s",
2738 gdbarch_register_name (gdbarch
, regno
));
2740 printf_filtered ("a local variable in register $%s",
2741 gdbarch_register_name (gdbarch
, regno
));
2744 printf_filtered ("an argument at stack/frame offset %s",
2745 plongest (SYMBOL_VALUE (sym
)));
2748 printf_filtered ("a local variable at frame offset %s",
2749 plongest (SYMBOL_VALUE (sym
)));
2752 printf_filtered ("a reference argument at offset %s",
2753 plongest (SYMBOL_VALUE (sym
)));
2755 case LOC_REGPARM_ADDR
:
2756 /* Note comment at LOC_REGISTER. */
2757 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2759 printf_filtered ("the address of an argument, in register $%s",
2760 gdbarch_register_name (gdbarch
, regno
));
2763 printf_filtered ("a typedef.\n");
2766 printf_filtered ("a label at address ");
2767 printf_filtered ("%s", paddress (gdbarch
,
2768 SYMBOL_VALUE_ADDRESS (sym
)));
2771 printf_filtered ("a function at address ");
2772 printf_filtered ("%s",
2773 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2775 case LOC_UNRESOLVED
:
2776 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2779 printf_filtered ("Unresolved Static");
2782 printf_filtered ("static storage at address ");
2783 printf_filtered ("%s",
2785 SYMBOL_VALUE_ADDRESS (msym
)));
2788 case LOC_OPTIMIZED_OUT
:
2789 printf_filtered ("optimized out.\n");
2792 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2795 if (SYMBOL_TYPE (sym
))
2796 printf_filtered (", length %d.\n",
2797 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2799 if (BLOCK_FUNCTION (block
))
2802 block
= BLOCK_SUPERBLOCK (block
);
2805 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2809 /* Helper for trace_dump_command. Dump the action list starting at
2810 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2811 actions of the body of a while-stepping action. STEPPING_FRAME is
2812 set if the current traceframe was determined to be a while-stepping
2816 trace_dump_actions (struct command_line
*action
,
2817 int stepping_actions
, int stepping_frame
,
2820 const char *action_exp
, *next_comma
;
2822 for (; action
!= NULL
; action
= action
->next
)
2824 struct cmd_list_element
*cmd
;
2826 QUIT
; /* Allow user to bail out with ^C. */
2827 action_exp
= action
->line
;
2828 action_exp
= skip_spaces_const (action_exp
);
2830 /* The collection actions to be done while stepping are
2831 bracketed by the commands "while-stepping" and "end". */
2833 if (*action_exp
== '#') /* comment line */
2836 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2838 error (_("Bad action list item: %s"), action_exp
);
2840 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2844 for (i
= 0; i
< action
->body_count
; ++i
)
2845 trace_dump_actions (action
->body_list
[i
],
2846 1, stepping_frame
, from_tty
);
2848 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2850 /* Display the collected data.
2851 For the trap frame, display only what was collected at
2852 the trap. Likewise for stepping frames, display only
2853 what was collected while stepping. This means that the
2854 two boolean variables, STEPPING_FRAME and
2855 STEPPING_ACTIONS should be equal. */
2856 if (stepping_frame
== stepping_actions
)
2859 struct cleanup
*old_chain
2860 = make_cleanup (free_current_contents
, &cmd
);
2861 int trace_string
= 0;
2863 if (*action_exp
== '/')
2864 action_exp
= decode_agent_options (action_exp
, &trace_string
);
2867 { /* Repeat over a comma-separated list. */
2868 QUIT
; /* Allow user to bail out with ^C. */
2869 if (*action_exp
== ',')
2871 action_exp
= skip_spaces_const (action_exp
);
2873 next_comma
= strchr (action_exp
, ',');
2875 if (0 == strncasecmp (action_exp
, "$reg", 4))
2876 registers_info (NULL
, from_tty
);
2877 else if (0 == strncasecmp (action_exp
, "$_ret", 5))
2879 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2880 locals_info (NULL
, from_tty
);
2881 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2882 args_info (NULL
, from_tty
);
2885 if (next_comma
!= NULL
)
2887 size_t len
= next_comma
- action_exp
;
2889 cmd
= xrealloc (cmd
, len
+ 1);
2890 memcpy (cmd
, action_exp
, len
);
2895 size_t len
= strlen (action_exp
);
2897 cmd
= xrealloc (cmd
, len
+ 1);
2898 memcpy (cmd
, action_exp
, len
+ 1);
2901 printf_filtered ("%s = ", cmd
);
2902 output_command_const (cmd
, from_tty
);
2903 printf_filtered ("\n");
2905 action_exp
= next_comma
;
2907 while (action_exp
&& *action_exp
== ',');
2909 do_cleanups (old_chain
);
2915 /* The tdump command. */
2918 trace_dump_command (char *args
, int from_tty
)
2920 struct regcache
*regcache
;
2921 struct tracepoint
*t
;
2922 int stepping_frame
= 0;
2923 struct bp_location
*loc
;
2924 char *default_collect_line
= NULL
;
2925 struct command_line
*actions
, *default_collect_action
= NULL
;
2926 struct cleanup
*old_chain
= NULL
;
2928 if (tracepoint_number
== -1)
2930 warning (_("No current trace frame."));
2934 t
= get_tracepoint (tracepoint_number
);
2937 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2940 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2941 tracepoint_number
, traceframe_number
);
2943 /* The current frame is a trap frame if the frame PC is equal
2944 to the tracepoint PC. If not, then the current frame was
2945 collected during single-stepping. */
2947 regcache
= get_current_regcache ();
2949 /* If the traceframe's address matches any of the tracepoint's
2950 locations, assume it is a direct hit rather than a while-stepping
2951 frame. (FIXME this is not reliable, should record each frame's
2954 for (loc
= t
->base
.loc
; loc
; loc
= loc
->next
)
2955 if (loc
->address
== regcache_read_pc (regcache
))
2958 actions
= breakpoint_commands (&t
->base
);
2960 /* If there is a default-collect list, make up a collect command,
2961 prepend to the tracepoint's commands, and pass the whole mess to
2962 the trace dump scanner. We need to validate because
2963 default-collect might have been junked since the trace run. */
2964 if (*default_collect
)
2966 default_collect_line
= xstrprintf ("collect %s", default_collect
);
2967 old_chain
= make_cleanup (xfree
, default_collect_line
);
2968 validate_actionline (default_collect_line
, &t
->base
);
2969 default_collect_action
= xmalloc (sizeof (struct command_line
));
2970 make_cleanup (xfree
, default_collect_action
);
2971 default_collect_action
->next
= actions
;
2972 default_collect_action
->line
= default_collect_line
;
2973 actions
= default_collect_action
;
2976 trace_dump_actions (actions
, 0, stepping_frame
, from_tty
);
2978 if (*default_collect
)
2979 do_cleanups (old_chain
);
2982 /* Encode a piece of a tracepoint's source-level definition in a form
2983 that is suitable for both protocol and saving in files. */
2984 /* This version does not do multiple encodes for long strings; it should
2985 return an offset to the next piece to encode. FIXME */
2988 encode_source_string (int tpnum
, ULONGEST addr
,
2989 char *srctype
, char *src
, char *buf
, int buf_size
)
2991 if (80 + strlen (srctype
) > buf_size
)
2992 error (_("Buffer too small for source encoding"));
2993 sprintf (buf
, "%x:%s:%s:%x:%x:",
2994 tpnum
, phex_nz (addr
, sizeof (addr
)),
2995 srctype
, 0, (int) strlen (src
));
2996 if (strlen (buf
) + strlen (src
) * 2 >= buf_size
)
2997 error (_("Source string too long for buffer"));
2998 bin2hex ((gdb_byte
*) src
, buf
+ strlen (buf
), 0);
3002 /* Free trace file writer. */
3005 trace_file_writer_xfree (void *arg
)
3007 struct trace_file_writer
*writer
= arg
;
3009 writer
->ops
->dtor (writer
);
3013 /* TFILE trace writer. */
3015 struct tfile_trace_file_writer
3017 struct trace_file_writer base
;
3019 /* File pointer to tfile trace file. */
3021 /* Path name of the tfile trace file. */
3025 /* This is the implementation of trace_file_write_ops method
3026 target_save. We just call the generic target
3027 target_save_trace_data to do target-side saving. */
3030 tfile_target_save (struct trace_file_writer
*self
,
3031 const char *filename
)
3033 int err
= target_save_trace_data (filename
);
3038 /* This is the implementation of trace_file_write_ops method
3042 tfile_dtor (struct trace_file_writer
*self
)
3044 struct tfile_trace_file_writer
*writer
3045 = (struct tfile_trace_file_writer
*) self
;
3047 xfree (writer
->pathname
);
3049 if (writer
->fp
!= NULL
)
3050 fclose (writer
->fp
);
3053 /* This is the implementation of trace_file_write_ops method
3054 start. It creates the trace file FILENAME and registers some
3058 tfile_start (struct trace_file_writer
*self
, const char *filename
)
3060 struct tfile_trace_file_writer
*writer
3061 = (struct tfile_trace_file_writer
*) self
;
3063 writer
->pathname
= tilde_expand (filename
);
3064 writer
->fp
= gdb_fopen_cloexec (writer
->pathname
, "wb");
3065 if (writer
->fp
== NULL
)
3066 error (_("Unable to open file '%s' for saving trace data (%s)"),
3067 filename
, safe_strerror (errno
));
3070 /* This is the implementation of trace_file_write_ops method
3071 write_header. Write the TFILE header. */
3074 tfile_write_header (struct trace_file_writer
*self
)
3076 struct tfile_trace_file_writer
*writer
3077 = (struct tfile_trace_file_writer
*) self
;
3080 /* Write a file header, with a high-bit-set char to indicate a
3081 binary file, plus a hint as what this file is, and a version
3082 number in case of future needs. */
3083 written
= fwrite ("\x7fTRACE0\n", 8, 1, writer
->fp
);
3085 perror_with_name (writer
->pathname
);
3088 /* This is the implementation of trace_file_write_ops method
3089 write_regblock_type. Write the size of register block. */
3092 tfile_write_regblock_type (struct trace_file_writer
*self
, int size
)
3094 struct tfile_trace_file_writer
*writer
3095 = (struct tfile_trace_file_writer
*) self
;
3097 fprintf (writer
->fp
, "R %x\n", size
);
3100 /* This is the implementation of trace_file_write_ops method
3104 tfile_write_status (struct trace_file_writer
*self
,
3105 struct trace_status
*ts
)
3107 struct tfile_trace_file_writer
*writer
3108 = (struct tfile_trace_file_writer
*) self
;
3110 fprintf (writer
->fp
, "status %c;%s",
3111 (ts
->running
? '1' : '0'), stop_reason_names
[ts
->stop_reason
]);
3112 if (ts
->stop_reason
== tracepoint_error
3113 || ts
->stop_reason
== tstop_command
)
3115 char *buf
= (char *) alloca (strlen (ts
->stop_desc
) * 2 + 1);
3117 bin2hex ((gdb_byte
*) ts
->stop_desc
, buf
, 0);
3118 fprintf (writer
->fp
, ":%s", buf
);
3120 fprintf (writer
->fp
, ":%x", ts
->stopping_tracepoint
);
3121 if (ts
->traceframe_count
>= 0)
3122 fprintf (writer
->fp
, ";tframes:%x", ts
->traceframe_count
);
3123 if (ts
->traceframes_created
>= 0)
3124 fprintf (writer
->fp
, ";tcreated:%x", ts
->traceframes_created
);
3125 if (ts
->buffer_free
>= 0)
3126 fprintf (writer
->fp
, ";tfree:%x", ts
->buffer_free
);
3127 if (ts
->buffer_size
>= 0)
3128 fprintf (writer
->fp
, ";tsize:%x", ts
->buffer_size
);
3129 if (ts
->disconnected_tracing
)
3130 fprintf (writer
->fp
, ";disconn:%x", ts
->disconnected_tracing
);
3131 if (ts
->circular_buffer
)
3132 fprintf (writer
->fp
, ";circular:%x", ts
->circular_buffer
);
3133 if (ts
->notes
!= NULL
)
3135 char *buf
= (char *) alloca (strlen (ts
->notes
) * 2 + 1);
3137 bin2hex ((gdb_byte
*) ts
->notes
, buf
, 0);
3138 fprintf (writer
->fp
, ";notes:%s", buf
);
3140 if (ts
->user_name
!= NULL
)
3142 char *buf
= (char *) alloca (strlen (ts
->user_name
) * 2 + 1);
3144 bin2hex ((gdb_byte
*) ts
->user_name
, buf
, 0);
3145 fprintf (writer
->fp
, ";username:%s", buf
);
3147 fprintf (writer
->fp
, "\n");
3150 /* This is the implementation of trace_file_write_ops method
3151 write_uploaded_tsv. */
3154 tfile_write_uploaded_tsv (struct trace_file_writer
*self
,
3155 struct uploaded_tsv
*utsv
)
3158 struct tfile_trace_file_writer
*writer
3159 = (struct tfile_trace_file_writer
*) self
;
3163 buf
= (char *) xmalloc (strlen (utsv
->name
) * 2 + 1);
3164 bin2hex ((gdb_byte
*) (utsv
->name
), buf
, 0);
3167 fprintf (writer
->fp
, "tsv %x:%s:%x:%s\n",
3168 utsv
->number
, phex_nz (utsv
->initial_value
, 8),
3169 utsv
->builtin
, buf
);
3175 #define MAX_TRACE_UPLOAD 2000
3177 /* This is the implementation of trace_file_write_ops method
3178 write_uploaded_tp. */
3181 tfile_write_uploaded_tp (struct trace_file_writer
*self
,
3182 struct uploaded_tp
*utp
)
3184 struct tfile_trace_file_writer
*writer
3185 = (struct tfile_trace_file_writer
*) self
;
3188 char buf
[MAX_TRACE_UPLOAD
];
3190 fprintf (writer
->fp
, "tp T%x:%s:%c:%x:%x",
3191 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
3192 (utp
->enabled
? 'E' : 'D'), utp
->step
, utp
->pass
);
3193 if (utp
->type
== bp_fast_tracepoint
)
3194 fprintf (writer
->fp
, ":F%x", utp
->orig_size
);
3196 fprintf (writer
->fp
,
3197 ":X%x,%s", (unsigned int) strlen (utp
->cond
) / 2,
3199 fprintf (writer
->fp
, "\n");
3200 for (a
= 0; VEC_iterate (char_ptr
, utp
->actions
, a
, act
); ++a
)
3201 fprintf (writer
->fp
, "tp A%x:%s:%s\n",
3202 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)), act
);
3203 for (a
= 0; VEC_iterate (char_ptr
, utp
->step_actions
, a
, act
); ++a
)
3204 fprintf (writer
->fp
, "tp S%x:%s:%s\n",
3205 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)), act
);
3208 encode_source_string (utp
->number
, utp
->addr
,
3209 "at", utp
->at_string
, buf
, MAX_TRACE_UPLOAD
);
3210 fprintf (writer
->fp
, "tp Z%s\n", buf
);
3212 if (utp
->cond_string
)
3214 encode_source_string (utp
->number
, utp
->addr
,
3215 "cond", utp
->cond_string
,
3216 buf
, MAX_TRACE_UPLOAD
);
3217 fprintf (writer
->fp
, "tp Z%s\n", buf
);
3219 for (a
= 0; VEC_iterate (char_ptr
, utp
->cmd_strings
, a
, act
); ++a
)
3221 encode_source_string (utp
->number
, utp
->addr
, "cmd", act
,
3222 buf
, MAX_TRACE_UPLOAD
);
3223 fprintf (writer
->fp
, "tp Z%s\n", buf
);
3225 fprintf (writer
->fp
, "tp V%x:%s:%x:%s\n",
3226 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
3228 phex_nz (utp
->traceframe_usage
,
3229 sizeof (utp
->traceframe_usage
)));
3232 /* This is the implementation of trace_file_write_ops method
3233 write_definition_end. */
3236 tfile_write_definition_end (struct trace_file_writer
*self
)
3238 struct tfile_trace_file_writer
*writer
3239 = (struct tfile_trace_file_writer
*) self
;
3241 fprintf (writer
->fp
, "\n");
3244 /* This is the implementation of trace_file_write_ops method
3248 tfile_write_raw_data (struct trace_file_writer
*self
, gdb_byte
*buf
,
3251 struct tfile_trace_file_writer
*writer
3252 = (struct tfile_trace_file_writer
*) self
;
3254 if (fwrite (buf
, len
, 1, writer
->fp
) < 1)
3255 perror_with_name (writer
->pathname
);
3258 /* This is the implementation of trace_file_write_ops method
3262 tfile_end (struct trace_file_writer
*self
)
3264 struct tfile_trace_file_writer
*writer
3265 = (struct tfile_trace_file_writer
*) self
;
3266 uint32_t gotten
= 0;
3268 /* Mark the end of trace data. */
3269 if (fwrite (&gotten
, 4, 1, writer
->fp
) < 1)
3270 perror_with_name (writer
->pathname
);
3273 /* Operations to write trace buffers into TFILE format. */
3275 static const struct trace_file_write_ops tfile_write_ops
=
3281 tfile_write_regblock_type
,
3283 tfile_write_uploaded_tsv
,
3284 tfile_write_uploaded_tp
,
3285 tfile_write_definition_end
,
3286 tfile_write_raw_data
,
3291 /* Helper macros. */
3293 #define TRACE_WRITE_R_BLOCK(writer, buf, size) \
3294 writer->ops->frame_ops->write_r_block ((writer), (buf), (size))
3295 #define TRACE_WRITE_M_BLOCK_HEADER(writer, addr, size) \
3296 writer->ops->frame_ops->write_m_block_header ((writer), (addr), \
3298 #define TRACE_WRITE_M_BLOCK_MEMORY(writer, buf, size) \
3299 writer->ops->frame_ops->write_m_block_memory ((writer), (buf), \
3301 #define TRACE_WRITE_V_BLOCK(writer, num, val) \
3302 writer->ops->frame_ops->write_v_block ((writer), (num), (val))
3304 /* Save tracepoint data to file named FILENAME through WRITER. WRITER
3305 determines the trace file format. If TARGET_DOES_SAVE is non-zero,
3306 the save is performed on the target, otherwise GDB obtains all trace
3307 data and saves it locally. */
3310 trace_save (const char *filename
, struct trace_file_writer
*writer
,
3311 int target_does_save
)
3313 struct trace_status
*ts
= current_trace_status ();
3315 struct uploaded_tp
*uploaded_tps
= NULL
, *utp
;
3316 struct uploaded_tsv
*uploaded_tsvs
= NULL
, *utsv
;
3318 ULONGEST offset
= 0;
3319 gdb_byte buf
[MAX_TRACE_UPLOAD
];
3320 #define MAX_TRACE_UPLOAD 2000
3322 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
3324 /* If the target is to save the data to a file on its own, then just
3325 send the command and be done with it. */
3326 if (target_does_save
)
3328 if (!writer
->ops
->target_save (writer
, filename
))
3329 error (_("Target failed to save trace data to '%s'."),
3334 /* Get the trace status first before opening the file, so if the
3335 target is losing, we can get out without touching files. */
3336 status
= target_get_trace_status (ts
);
3338 writer
->ops
->start (writer
, filename
);
3340 writer
->ops
->write_header (writer
);
3342 /* Write descriptive info. */
3344 /* Write out the size of a register block. */
3345 writer
->ops
->write_regblock_type (writer
, trace_regblock_size
);
3347 /* Write out status of the tracing run (aka "tstatus" info). */
3348 writer
->ops
->write_status (writer
, ts
);
3350 /* Note that we want to upload tracepoints and save those, rather
3351 than simply writing out the local ones, because the user may have
3352 changed tracepoints in GDB in preparation for a future tracing
3353 run, or maybe just mass-deleted all types of breakpoints as part
3354 of cleaning up. So as not to contaminate the session, leave the
3355 data in its uploaded form, don't make into real tracepoints. */
3357 /* Get trace state variables first, they may be checked when parsing
3358 uploaded commands. */
3360 target_upload_trace_state_variables (&uploaded_tsvs
);
3362 for (utsv
= uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
3363 writer
->ops
->write_uploaded_tsv (writer
, utsv
);
3365 free_uploaded_tsvs (&uploaded_tsvs
);
3367 target_upload_tracepoints (&uploaded_tps
);
3369 for (utp
= uploaded_tps
; utp
; utp
= utp
->next
)
3370 target_get_tracepoint_status (NULL
, utp
);
3372 for (utp
= uploaded_tps
; utp
; utp
= utp
->next
)
3373 writer
->ops
->write_uploaded_tp (writer
, utp
);
3375 free_uploaded_tps (&uploaded_tps
);
3377 /* Mark the end of the definition section. */
3378 writer
->ops
->write_definition_end (writer
);
3380 /* Get and write the trace data proper. */
3385 /* The writer supports writing the contents of trace buffer
3386 directly to trace file. Don't parse the contents of trace
3388 if (writer
->ops
->write_trace_buffer
!= NULL
)
3390 /* We ask for big blocks, in the hopes of efficiency, but
3391 will take less if the target has packet size limitations
3393 gotten
= target_get_raw_trace_data (buf
, offset
,
3396 error (_("Failure to get requested trace buffer data"));
3397 /* No more data is forthcoming, we're done. */
3401 writer
->ops
->write_trace_buffer (writer
, buf
, gotten
);
3409 /* Parse the trace buffers according to how data are stored
3410 in trace buffer in GDBserver. */
3412 gotten
= target_get_raw_trace_data (buf
, offset
, 6);
3417 /* Read the first six bytes in, which is the tracepoint
3418 number and trace frame size. */
3420 extract_unsigned_integer (&buf
[0], 2, byte_order
);
3422 tf_size
= (uint32_t)
3423 extract_unsigned_integer (&buf
[2], 4, byte_order
);
3425 writer
->ops
->frame_ops
->start (writer
, tp_num
);
3434 for (block
= 0; block
< tf_size
; )
3436 gdb_byte block_type
;
3438 /* We'll fetch one block each time, in order to
3439 handle the extremely large 'M' block. We first
3440 fetch one byte to get the type of the block. */
3441 gotten
= target_get_raw_trace_data (buf
, offset
, 1);
3443 error (_("Failure to get requested trace buffer data"));
3449 block_type
= buf
[0];
3454 = target_get_raw_trace_data (buf
, offset
,
3455 trace_regblock_size
);
3456 if (gotten
< trace_regblock_size
)
3457 error (_("Failure to get requested trace"
3460 TRACE_WRITE_R_BLOCK (writer
, buf
,
3461 trace_regblock_size
);
3465 unsigned short mlen
;
3470 t
= target_get_raw_trace_data (buf
,offset
, 10);
3472 error (_("Failure to get requested trace"
3480 extract_unsigned_integer (buf
, 8,
3482 mlen
= (unsigned short)
3483 extract_unsigned_integer (&buf
[8], 2,
3486 TRACE_WRITE_M_BLOCK_HEADER (writer
, addr
,
3489 /* The memory contents in 'M' block may be
3490 very large. Fetch the data from the target
3491 and write them into file one by one. */
3492 for (j
= 0; j
< mlen
; )
3494 unsigned int read_length
;
3496 if (mlen
- j
> MAX_TRACE_UPLOAD
)
3497 read_length
= MAX_TRACE_UPLOAD
;
3499 read_length
= mlen
- j
;
3501 t
= target_get_raw_trace_data (buf
,
3504 if (t
< read_length
)
3505 error (_("Failure to get requested"
3506 " trace buffer data"));
3508 TRACE_WRITE_M_BLOCK_MEMORY (writer
, buf
,
3512 gotten
+= read_length
;
3523 = target_get_raw_trace_data (buf
, offset
,
3526 error (_("Failure to get requested"
3527 " trace buffer data"));
3529 vnum
= (int) extract_signed_integer (buf
,
3533 = extract_signed_integer (&buf
[4], 8,
3536 TRACE_WRITE_V_BLOCK (writer
, vnum
, val
);
3540 error (_("Unknown block type '%c' (0x%x) in"
3542 block_type
, block_type
);
3552 writer
->ops
->frame_ops
->end (writer
);
3556 writer
->ops
->end (writer
);
3559 /* Return a trace writer for TFILE format. */
3561 static struct trace_file_writer
*
3562 tfile_trace_file_writer_new (void)
3564 struct tfile_trace_file_writer
*writer
3565 = xmalloc (sizeof (struct tfile_trace_file_writer
));
3567 writer
->base
.ops
= &tfile_write_ops
;
3569 writer
->pathname
= NULL
;
3571 return (struct trace_file_writer
*) writer
;
3575 trace_save_command (char *args
, int from_tty
)
3577 int target_does_save
= 0;
3579 char *filename
= NULL
;
3580 struct cleanup
*back_to
;
3581 int generate_ctf
= 0;
3582 struct trace_file_writer
*writer
= NULL
;
3585 error_no_arg (_("file in which to save trace data"));
3587 argv
= gdb_buildargv (args
);
3588 back_to
= make_cleanup_freeargv (argv
);
3590 for (; *argv
; ++argv
)
3592 if (strcmp (*argv
, "-r") == 0)
3593 target_does_save
= 1;
3594 if (strcmp (*argv
, "-ctf") == 0)
3596 else if (**argv
== '-')
3597 error (_("unknown option `%s'"), *argv
);
3603 error_no_arg (_("file in which to save trace data"));
3606 writer
= ctf_trace_file_writer_new ();
3608 writer
= tfile_trace_file_writer_new ();
3610 make_cleanup (trace_file_writer_xfree
, writer
);
3612 trace_save (filename
, writer
, target_does_save
);
3615 printf_filtered (_("Trace data saved to %s '%s'.\n"),
3616 generate_ctf
? "directory" : "file", filename
);
3618 do_cleanups (back_to
);
3621 /* Save the trace data to file FILENAME of tfile format. */
3624 trace_save_tfile (const char *filename
, int target_does_save
)
3626 struct trace_file_writer
*writer
;
3627 struct cleanup
*back_to
;
3629 writer
= tfile_trace_file_writer_new ();
3630 back_to
= make_cleanup (trace_file_writer_xfree
, writer
);
3631 trace_save (filename
, writer
, target_does_save
);
3632 do_cleanups (back_to
);
3635 /* Save the trace data to dir DIRNAME of ctf format. */
3638 trace_save_ctf (const char *dirname
, int target_does_save
)
3640 struct trace_file_writer
*writer
;
3641 struct cleanup
*back_to
;
3643 writer
= ctf_trace_file_writer_new ();
3644 back_to
= make_cleanup (trace_file_writer_xfree
, writer
);
3646 trace_save (dirname
, writer
, target_does_save
);
3647 do_cleanups (back_to
);
3650 /* Tell the target what to do with an ongoing tracing run if GDB
3651 disconnects for some reason. */
3654 set_disconnected_tracing (char *args
, int from_tty
,
3655 struct cmd_list_element
*c
)
3657 target_set_disconnected_tracing (disconnected_tracing
);
3661 set_circular_trace_buffer (char *args
, int from_tty
,
3662 struct cmd_list_element
*c
)
3664 target_set_circular_trace_buffer (circular_trace_buffer
);
3668 set_trace_buffer_size (char *args
, int from_tty
,
3669 struct cmd_list_element
*c
)
3671 target_set_trace_buffer_size (trace_buffer_size
);
3675 set_trace_user (char *args
, int from_tty
,
3676 struct cmd_list_element
*c
)
3680 ret
= target_set_trace_notes (trace_user
, NULL
, NULL
);
3683 warning (_("Target does not support trace notes, user ignored"));
3687 set_trace_notes (char *args
, int from_tty
,
3688 struct cmd_list_element
*c
)
3692 ret
= target_set_trace_notes (NULL
, trace_notes
, NULL
);
3695 warning (_("Target does not support trace notes, note ignored"));
3699 set_trace_stop_notes (char *args
, int from_tty
,
3700 struct cmd_list_element
*c
)
3704 ret
= target_set_trace_notes (NULL
, NULL
, trace_stop_notes
);
3707 warning (_("Target does not support trace notes, stop note ignored"));
3710 /* Convert the memory pointed to by mem into hex, placing result in buf.
3711 * Return a pointer to the last char put in buf (null)
3712 * "stolen" from sparc-stub.c
3715 static const char hexchars
[] = "0123456789abcdef";
3718 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
3726 *buf
++ = hexchars
[ch
>> 4];
3727 *buf
++ = hexchars
[ch
& 0xf];
3736 get_traceframe_number (void)
3738 return traceframe_number
;
3742 get_tracepoint_number (void)
3744 return tracepoint_number
;
3747 /* Make the traceframe NUM be the current trace frame. Does nothing
3748 if NUM is already current. */
3751 set_current_traceframe (int num
)
3755 if (traceframe_number
== num
)
3757 /* Nothing to do. */
3761 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
3764 warning (_("could not change traceframe"));
3766 set_traceframe_num (newnum
);
3768 /* Changing the traceframe changes our view of registers and of the
3770 registers_changed ();
3772 clear_traceframe_info ();
3775 /* Make the traceframe NUM be the current trace frame, and do nothing
3779 set_traceframe_number (int num
)
3781 traceframe_number
= num
;
3784 /* A cleanup used when switching away and back from tfind mode. */
3786 struct current_traceframe_cleanup
3788 /* The traceframe we were inspecting. */
3789 int traceframe_number
;
3793 do_restore_current_traceframe_cleanup (void *arg
)
3795 struct current_traceframe_cleanup
*old
= arg
;
3797 set_current_traceframe (old
->traceframe_number
);
3801 restore_current_traceframe_cleanup_dtor (void *arg
)
3803 struct current_traceframe_cleanup
*old
= arg
;
3809 make_cleanup_restore_current_traceframe (void)
3811 struct current_traceframe_cleanup
*old
;
3813 old
= xmalloc (sizeof (struct current_traceframe_cleanup
));
3814 old
->traceframe_number
= traceframe_number
;
3816 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
3817 restore_current_traceframe_cleanup_dtor
);
3821 make_cleanup_restore_traceframe_number (void)
3823 return make_cleanup_restore_integer (&traceframe_number
);
3826 /* Given a number and address, return an uploaded tracepoint with that
3827 number, creating if necessary. */
3829 struct uploaded_tp
*
3830 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
3832 struct uploaded_tp
*utp
;
3834 for (utp
= *utpp
; utp
; utp
= utp
->next
)
3835 if (utp
->number
== num
&& utp
->addr
== addr
)
3837 utp
= (struct uploaded_tp
*) xmalloc (sizeof (struct uploaded_tp
));
3838 memset (utp
, 0, sizeof (struct uploaded_tp
));
3841 utp
->actions
= NULL
;
3842 utp
->step_actions
= NULL
;
3843 utp
->cmd_strings
= NULL
;
3850 free_uploaded_tps (struct uploaded_tp
**utpp
)
3852 struct uploaded_tp
*next_one
;
3856 next_one
= (*utpp
)->next
;
3862 /* Given a number and address, return an uploaded tracepoint with that
3863 number, creating if necessary. */
3865 struct uploaded_tsv
*
3866 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
3868 struct uploaded_tsv
*utsv
;
3870 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
3871 if (utsv
->number
== num
)
3873 utsv
= (struct uploaded_tsv
*) xmalloc (sizeof (struct uploaded_tsv
));
3874 memset (utsv
, 0, sizeof (struct uploaded_tsv
));
3876 utsv
->next
= *utsvp
;
3882 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
3884 struct uploaded_tsv
*next_one
;
3888 next_one
= (*utsvp
)->next
;
3894 /* FIXME this function is heuristic and will miss the cases where the
3895 conditional is semantically identical but differs in whitespace,
3896 such as "x == 0" vs "x==0". */
3899 cond_string_is_same (char *str1
, char *str2
)
3901 if (str1
== NULL
|| str2
== NULL
)
3902 return (str1
== str2
);
3904 return (strcmp (str1
, str2
) == 0);
3907 /* Look for an existing tracepoint that seems similar enough to the
3908 uploaded one. Enablement isn't compared, because the user can
3909 toggle that freely, and may have done so in anticipation of the
3910 next trace run. Return the location of matched tracepoint. */
3912 static struct bp_location
*
3913 find_matching_tracepoint_location (struct uploaded_tp
*utp
)
3915 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
3917 struct breakpoint
*b
;
3918 struct bp_location
*loc
;
3920 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
3922 struct tracepoint
*t
= (struct tracepoint
*) b
;
3924 if (b
->type
== utp
->type
3925 && t
->step_count
== utp
->step
3926 && t
->pass_count
== utp
->pass
3927 && cond_string_is_same (t
->base
.cond_string
, utp
->cond_string
)
3928 /* FIXME also test actions. */
3931 /* Scan the locations for an address match. */
3932 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3934 if (loc
->address
== utp
->addr
)
3942 /* Given a list of tracepoints uploaded from a target, attempt to
3943 match them up with existing tracepoints, and create new ones if not
3947 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
3949 struct uploaded_tp
*utp
;
3950 /* A set of tracepoints which are modified. */
3951 VEC(breakpoint_p
) *modified_tp
= NULL
;
3953 struct breakpoint
*b
;
3955 /* Look for GDB tracepoints that match up with our uploaded versions. */
3956 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
3958 struct bp_location
*loc
;
3959 struct tracepoint
*t
;
3961 loc
= find_matching_tracepoint_location (utp
);
3966 /* Mark this location as already inserted. */
3968 t
= (struct tracepoint
*) loc
->owner
;
3969 printf_filtered (_("Assuming tracepoint %d is same "
3970 "as target's tracepoint %d at %s.\n"),
3971 loc
->owner
->number
, utp
->number
,
3972 paddress (loc
->gdbarch
, utp
->addr
));
3974 /* The tracepoint LOC->owner was modified (the location LOC
3975 was marked as inserted in the target). Save it in
3976 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3977 observers will be notified later once for each tracepoint
3978 saved in MODIFIED_TP. */
3980 VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
);
3982 if (b
== loc
->owner
)
3988 VEC_safe_push (breakpoint_p
, modified_tp
, loc
->owner
);
3992 t
= create_tracepoint_from_upload (utp
);
3994 printf_filtered (_("Created tracepoint %d for "
3995 "target's tracepoint %d at %s.\n"),
3996 t
->base
.number
, utp
->number
,
3997 paddress (get_current_arch (), utp
->addr
));
3999 printf_filtered (_("Failed to create tracepoint for target's "
4000 "tracepoint %d at %s, skipping it.\n"),
4002 paddress (get_current_arch (), utp
->addr
));
4004 /* Whether found or created, record the number used by the
4005 target, to help with mapping target tracepoints back to their
4006 counterparts here. */
4008 t
->number_on_target
= utp
->number
;
4011 /* Notify 'breakpoint-modified' observer that at least one of B's
4012 locations was changed. */
4013 for (ix
= 0; VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
); ix
++)
4014 observer_notify_breakpoint_modified (b
);
4016 VEC_free (breakpoint_p
, modified_tp
);
4017 free_uploaded_tps (uploaded_tps
);
4020 /* Trace state variables don't have much to identify them beyond their
4021 name, so just use that to detect matches. */
4023 static struct trace_state_variable
*
4024 find_matching_tsv (struct uploaded_tsv
*utsv
)
4029 return find_trace_state_variable (utsv
->name
);
4032 static struct trace_state_variable
*
4033 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
4035 const char *namebase
;
4038 struct trace_state_variable
*tsv
;
4039 struct cleanup
*old_chain
;
4043 namebase
= utsv
->name
;
4044 buf
= xstrprintf ("%s", namebase
);
4049 buf
= xstrprintf ("%s_%d", namebase
, try_num
++);
4052 /* Fish for a name that is not in use. */
4053 /* (should check against all internal vars?) */
4054 while (find_trace_state_variable (buf
))
4057 buf
= xstrprintf ("%s_%d", namebase
, try_num
++);
4060 old_chain
= make_cleanup (xfree
, buf
);
4062 /* We have an available name, create the variable. */
4063 tsv
= create_trace_state_variable (buf
);
4064 tsv
->initial_value
= utsv
->initial_value
;
4065 tsv
->builtin
= utsv
->builtin
;
4067 observer_notify_tsv_created (tsv
);
4069 do_cleanups (old_chain
);
4074 /* Given a list of uploaded trace state variables, try to match them
4075 up with existing variables, or create additional ones. */
4078 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
4081 struct uploaded_tsv
*utsv
;
4082 struct trace_state_variable
*tsv
;
4085 /* Most likely some numbers will have to be reassigned as part of
4086 the merge, so clear them all in anticipation. */
4087 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
4090 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
4092 tsv
= find_matching_tsv (utsv
);
4096 printf_filtered (_("Assuming trace state variable $%s "
4097 "is same as target's variable %d.\n"),
4098 tsv
->name
, utsv
->number
);
4102 tsv
= create_tsv_from_upload (utsv
);
4104 printf_filtered (_("Created trace state variable "
4105 "$%s for target's variable %d.\n"),
4106 tsv
->name
, utsv
->number
);
4108 /* Give precedence to numberings that come from the target. */
4110 tsv
->number
= utsv
->number
;
4113 /* Renumber everything that didn't get a target-assigned number. */
4115 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
4116 if (tsv
->number
> highest
)
4117 highest
= tsv
->number
;
4120 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
4121 if (tsv
->number
== 0)
4122 tsv
->number
= highest
++;
4124 free_uploaded_tsvs (uploaded_tsvs
);
4127 /* target tfile command */
4129 static struct target_ops tfile_ops
;
4131 /* Fill in tfile_ops with its defined operations and properties. */
4133 #define TRACE_HEADER_SIZE 8
4135 static char *trace_filename
;
4136 static int trace_fd
= -1;
4137 static off_t trace_frames_offset
;
4138 static off_t cur_offset
;
4139 static int cur_data_size
;
4140 int trace_regblock_size
;
4142 static void tfile_interp_line (char *line
,
4143 struct uploaded_tp
**utpp
,
4144 struct uploaded_tsv
**utsvp
);
4146 /* Read SIZE bytes into READBUF from the trace frame, starting at
4147 TRACE_FD's current position. Note that this call `read'
4148 underneath, hence it advances the file's seek position. Throws an
4149 error if the `read' syscall fails, or less than SIZE bytes are
4153 tfile_read (gdb_byte
*readbuf
, int size
)
4157 gotten
= read (trace_fd
, readbuf
, size
);
4159 perror_with_name (trace_filename
);
4160 else if (gotten
< size
)
4161 error (_("Premature end of file while reading trace file"));
4165 tfile_open (char *filename
, int from_tty
)
4167 volatile struct gdb_exception ex
;
4169 struct cleanup
*old_chain
;
4172 char header
[TRACE_HEADER_SIZE
];
4173 char linebuf
[1000]; /* Should be max remote packet size or so. */
4176 struct trace_status
*ts
;
4177 struct uploaded_tp
*uploaded_tps
= NULL
;
4178 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4180 target_preopen (from_tty
);
4182 error (_("No trace file specified."));
4184 filename
= tilde_expand (filename
);
4185 if (!IS_ABSOLUTE_PATH(filename
))
4187 temp
= concat (current_directory
, "/", filename
, (char *) NULL
);
4192 old_chain
= make_cleanup (xfree
, filename
);
4194 flags
= O_BINARY
| O_LARGEFILE
;
4196 scratch_chan
= gdb_open_cloexec (filename
, flags
, 0);
4197 if (scratch_chan
< 0)
4198 perror_with_name (filename
);
4200 /* Looks semi-reasonable. Toss the old trace file and work on the new. */
4202 discard_cleanups (old_chain
); /* Don't free filename any more. */
4203 unpush_target (&tfile_ops
);
4205 trace_filename
= xstrdup (filename
);
4206 trace_fd
= scratch_chan
;
4209 /* Read the file header and test for validity. */
4210 tfile_read ((gdb_byte
*) &header
, TRACE_HEADER_SIZE
);
4212 bytes
+= TRACE_HEADER_SIZE
;
4213 if (!(header
[0] == 0x7f
4214 && (strncmp (header
+ 1, "TRACE0\n", 7) == 0)))
4215 error (_("File is not a valid trace file."));
4217 push_target (&tfile_ops
);
4219 trace_regblock_size
= 0;
4220 ts
= current_trace_status ();
4221 /* We know we're working with a file. Record its name. */
4222 ts
->filename
= trace_filename
;
4223 /* Set defaults in case there is no status line. */
4224 ts
->running_known
= 0;
4225 ts
->stop_reason
= trace_stop_reason_unknown
;
4226 ts
->traceframe_count
= -1;
4227 ts
->buffer_free
= 0;
4228 ts
->disconnected_tracing
= 0;
4229 ts
->circular_buffer
= 0;
4231 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4233 /* Read through a section of newline-terminated lines that
4234 define things like tracepoints. */
4238 tfile_read (&byte
, 1);
4243 /* Empty line marks end of the definition section. */
4248 tfile_interp_line (linebuf
, &uploaded_tps
, &uploaded_tsvs
);
4251 linebuf
[i
++] = byte
;
4253 error (_("Excessively long lines in trace file"));
4256 /* Record the starting offset of the binary trace data. */
4257 trace_frames_offset
= bytes
;
4259 /* If we don't have a blocksize, we can't interpret the
4261 if (trace_regblock_size
== 0)
4262 error (_("No register block size recorded in trace file"));
4266 /* Pop the partially set up target. */
4268 throw_exception (ex
);
4271 if (ts
->traceframe_count
<= 0)
4272 warning (_("No traceframes present in this file."));
4274 /* Add the file's tracepoints and variables into the current mix. */
4276 /* Get trace state variables first, they may be checked when parsing
4277 uploaded commands. */
4278 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
4280 merge_uploaded_tracepoints (&uploaded_tps
);
4283 /* Interpret the given line from the definitions part of the trace
4287 tfile_interp_line (char *line
, struct uploaded_tp
**utpp
,
4288 struct uploaded_tsv
**utsvp
)
4292 if (strncmp (p
, "R ", strlen ("R ")) == 0)
4295 trace_regblock_size
= strtol (p
, &p
, 16);
4297 else if (strncmp (p
, "status ", strlen ("status ")) == 0)
4299 p
+= strlen ("status ");
4300 parse_trace_status (p
, current_trace_status ());
4302 else if (strncmp (p
, "tp ", strlen ("tp ")) == 0)
4304 p
+= strlen ("tp ");
4305 parse_tracepoint_definition (p
, utpp
);
4307 else if (strncmp (p
, "tsv ", strlen ("tsv ")) == 0)
4309 p
+= strlen ("tsv ");
4310 parse_tsv_definition (p
, utsvp
);
4313 warning (_("Ignoring trace file definition \"%s\""), line
);
4316 /* Parse the part of trace status syntax that is shared between
4317 the remote protocol and the trace file reader. */
4320 parse_trace_status (char *line
, struct trace_status
*ts
)
4322 char *p
= line
, *p1
, *p2
, *p3
, *p_temp
;
4326 ts
->running_known
= 1;
4327 ts
->running
= (*p
++ == '1');
4328 ts
->stop_reason
= trace_stop_reason_unknown
;
4329 xfree (ts
->stop_desc
);
4330 ts
->stop_desc
= NULL
;
4331 ts
->traceframe_count
= -1;
4332 ts
->traceframes_created
= -1;
4333 ts
->buffer_free
= -1;
4334 ts
->buffer_size
= -1;
4335 ts
->disconnected_tracing
= 0;
4336 ts
->circular_buffer
= 0;
4337 xfree (ts
->user_name
);
4338 ts
->user_name
= NULL
;
4341 ts
->start_time
= ts
->stop_time
= 0;
4345 p1
= strchr (p
, ':');
4347 error (_("Malformed trace status, at %s\n\
4348 Status line: '%s'\n"), p
, line
);
4349 p3
= strchr (p
, ';');
4351 p3
= p
+ strlen (p
);
4352 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
4354 p
= unpack_varlen_hex (++p1
, &val
);
4355 ts
->stop_reason
= trace_buffer_full
;
4357 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
4359 p
= unpack_varlen_hex (++p1
, &val
);
4360 ts
->stop_reason
= trace_never_run
;
4362 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
],
4365 p
= unpack_varlen_hex (++p1
, &val
);
4366 ts
->stop_reason
= tracepoint_passcount
;
4367 ts
->stopping_tracepoint
= val
;
4369 else if (strncmp (p
, stop_reason_names
[tstop_command
], p1
- p
) == 0)
4371 p2
= strchr (++p1
, ':');
4379 ts
->stop_desc
= xmalloc (strlen (line
));
4380 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
4381 ts
->stop_desc
[end
] = '\0';
4384 ts
->stop_desc
= xstrdup ("");
4386 p
= unpack_varlen_hex (++p2
, &val
);
4387 ts
->stop_reason
= tstop_command
;
4389 else if (strncmp (p
, stop_reason_names
[trace_disconnected
], p1
- p
) == 0)
4391 p
= unpack_varlen_hex (++p1
, &val
);
4392 ts
->stop_reason
= trace_disconnected
;
4394 else if (strncmp (p
, stop_reason_names
[tracepoint_error
], p1
- p
) == 0)
4396 p2
= strchr (++p1
, ':');
4399 ts
->stop_desc
= xmalloc ((p2
- p1
) / 2 + 1);
4400 end
= hex2bin (p1
, (gdb_byte
*) ts
->stop_desc
, (p2
- p1
) / 2);
4401 ts
->stop_desc
[end
] = '\0';
4404 ts
->stop_desc
= xstrdup ("");
4406 p
= unpack_varlen_hex (++p2
, &val
);
4407 ts
->stopping_tracepoint
= val
;
4408 ts
->stop_reason
= tracepoint_error
;
4410 else if (strncmp (p
, "tframes", p1
- p
) == 0)
4412 p
= unpack_varlen_hex (++p1
, &val
);
4413 ts
->traceframe_count
= val
;
4415 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
4417 p
= unpack_varlen_hex (++p1
, &val
);
4418 ts
->traceframes_created
= val
;
4420 else if (strncmp (p
, "tfree", p1
- p
) == 0)
4422 p
= unpack_varlen_hex (++p1
, &val
);
4423 ts
->buffer_free
= val
;
4425 else if (strncmp (p
, "tsize", p1
- p
) == 0)
4427 p
= unpack_varlen_hex (++p1
, &val
);
4428 ts
->buffer_size
= val
;
4430 else if (strncmp (p
, "disconn", p1
- p
) == 0)
4432 p
= unpack_varlen_hex (++p1
, &val
);
4433 ts
->disconnected_tracing
= val
;
4435 else if (strncmp (p
, "circular", p1
- p
) == 0)
4437 p
= unpack_varlen_hex (++p1
, &val
);
4438 ts
->circular_buffer
= val
;
4440 else if (strncmp (p
, "starttime", p1
- p
) == 0)
4442 p
= unpack_varlen_hex (++p1
, &val
);
4443 ts
->start_time
= val
;
4445 else if (strncmp (p
, "stoptime", p1
- p
) == 0)
4447 p
= unpack_varlen_hex (++p1
, &val
);
4448 ts
->stop_time
= val
;
4450 else if (strncmp (p
, "username", p1
- p
) == 0)
4453 ts
->user_name
= xmalloc (strlen (p
) / 2);
4454 end
= hex2bin (p1
, (gdb_byte
*) ts
->user_name
, (p3
- p1
) / 2);
4455 ts
->user_name
[end
] = '\0';
4458 else if (strncmp (p
, "notes", p1
- p
) == 0)
4461 ts
->notes
= xmalloc (strlen (p
) / 2);
4462 end
= hex2bin (p1
, (gdb_byte
*) ts
->notes
, (p3
- p1
) / 2);
4463 ts
->notes
[end
] = '\0';
4468 /* Silently skip unknown optional info. */
4469 p_temp
= strchr (p1
+ 1, ';');
4473 /* Must be at the end. */
4480 parse_tracepoint_status (char *p
, struct breakpoint
*bp
,
4481 struct uploaded_tp
*utp
)
4484 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
4486 p
= unpack_varlen_hex (p
, &uval
);
4488 tp
->base
.hit_count
+= uval
;
4490 utp
->hit_count
+= uval
;
4491 p
= unpack_varlen_hex (p
+ 1, &uval
);
4493 tp
->traceframe_usage
+= uval
;
4495 utp
->traceframe_usage
+= uval
;
4496 /* Ignore any extra, allowing for future extensions. */
4499 /* Given a line of text defining a part of a tracepoint, parse it into
4500 an "uploaded tracepoint". */
4503 parse_tracepoint_definition (char *line
, struct uploaded_tp
**utpp
)
4507 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
, start
;
4510 char *cond
, *srctype
, *buf
;
4511 struct uploaded_tp
*utp
= NULL
;
4514 /* Both tracepoint and action definitions start with the same number
4515 and address sequence. */
4517 p
= unpack_varlen_hex (p
, &num
);
4518 p
++; /* skip a colon */
4519 p
= unpack_varlen_hex (p
, &addr
);
4520 p
++; /* skip a colon */
4523 enabled
= (*p
++ == 'E');
4524 p
++; /* skip a colon */
4525 p
= unpack_varlen_hex (p
, &step
);
4526 p
++; /* skip a colon */
4527 p
= unpack_varlen_hex (p
, &pass
);
4528 type
= bp_tracepoint
;
4530 /* Thumb through optional fields. */
4533 p
++; /* skip a colon */
4536 type
= bp_fast_tracepoint
;
4538 p
= unpack_varlen_hex (p
, &orig_size
);
4542 type
= bp_static_tracepoint
;
4548 p
= unpack_varlen_hex (p
, &xlen
);
4549 p
++; /* skip a comma */
4550 cond
= (char *) xmalloc (2 * xlen
+ 1);
4551 strncpy (cond
, p
, 2 * xlen
);
4552 cond
[2 * xlen
] = '\0';
4556 warning (_("Unrecognized char '%c' in tracepoint "
4557 "definition, skipping rest"), *p
);
4559 utp
= get_uploaded_tp (num
, addr
, utpp
);
4561 utp
->enabled
= enabled
;
4566 else if (piece
== 'A')
4568 utp
= get_uploaded_tp (num
, addr
, utpp
);
4569 VEC_safe_push (char_ptr
, utp
->actions
, xstrdup (p
));
4571 else if (piece
== 'S')
4573 utp
= get_uploaded_tp (num
, addr
, utpp
);
4574 VEC_safe_push (char_ptr
, utp
->step_actions
, xstrdup (p
));
4576 else if (piece
== 'Z')
4578 /* Parse a chunk of source form definition. */
4579 utp
= get_uploaded_tp (num
, addr
, utpp
);
4581 p
= strchr (p
, ':');
4582 p
++; /* skip a colon */
4583 p
= unpack_varlen_hex (p
, &start
);
4584 p
++; /* skip a colon */
4585 p
= unpack_varlen_hex (p
, &xlen
);
4586 p
++; /* skip a colon */
4588 buf
= alloca (strlen (line
));
4590 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
4593 if (strncmp (srctype
, "at:", strlen ("at:")) == 0)
4594 utp
->at_string
= xstrdup (buf
);
4595 else if (strncmp (srctype
, "cond:", strlen ("cond:")) == 0)
4596 utp
->cond_string
= xstrdup (buf
);
4597 else if (strncmp (srctype
, "cmd:", strlen ("cmd:")) == 0)
4598 VEC_safe_push (char_ptr
, utp
->cmd_strings
, xstrdup (buf
));
4600 else if (piece
== 'V')
4602 utp
= get_uploaded_tp (num
, addr
, utpp
);
4604 parse_tracepoint_status (p
, NULL
, utp
);
4608 /* Don't error out, the target might be sending us optional
4609 info that we don't care about. */
4610 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece
);
4614 /* Convert a textual description of a trace state variable into an
4618 parse_tsv_definition (char *line
, struct uploaded_tsv
**utsvp
)
4621 ULONGEST num
, initval
, builtin
;
4623 struct uploaded_tsv
*utsv
= NULL
;
4625 buf
= alloca (strlen (line
));
4628 p
= unpack_varlen_hex (p
, &num
);
4629 p
++; /* skip a colon */
4630 p
= unpack_varlen_hex (p
, &initval
);
4631 p
++; /* skip a colon */
4632 p
= unpack_varlen_hex (p
, &builtin
);
4633 p
++; /* skip a colon */
4634 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
4637 utsv
= get_uploaded_tsv (num
, utsvp
);
4638 utsv
->initial_value
= initval
;
4639 utsv
->builtin
= builtin
;
4640 utsv
->name
= xstrdup (buf
);
4643 /* Close the trace file and generally clean up. */
4655 xfree (trace_filename
);
4656 trace_filename
= NULL
;
4660 tfile_files_info (struct target_ops
*t
)
4662 printf_filtered ("\t`%s'\n", trace_filename
);
4665 /* The trace status for a file is that tracing can never be run. */
4668 tfile_get_trace_status (struct trace_status
*ts
)
4670 /* Other bits of trace status were collected as part of opening the
4671 trace files, so nothing to do here. */
4677 tfile_get_tracepoint_status (struct breakpoint
*tp
, struct uploaded_tp
*utp
)
4679 /* Other bits of trace status were collected as part of opening the
4680 trace files, so nothing to do here. */
4683 /* Given the position of a traceframe in the file, figure out what
4684 address the frame was collected at. This would normally be the
4685 value of a collected PC register, but if not available, we
4689 tfile_get_traceframe_address (off_t tframe_offset
)
4693 struct tracepoint
*tp
;
4694 off_t saved_offset
= cur_offset
;
4696 /* FIXME dig pc out of collected registers. */
4698 /* Fall back to using tracepoint address. */
4699 lseek (trace_fd
, tframe_offset
, SEEK_SET
);
4700 tfile_read ((gdb_byte
*) &tpnum
, 2);
4701 tpnum
= (short) extract_signed_integer ((gdb_byte
*) &tpnum
, 2,
4703 (target_gdbarch ()));
4705 tp
= get_tracepoint_by_number_on_target (tpnum
);
4706 /* FIXME this is a poor heuristic if multiple locations. */
4707 if (tp
&& tp
->base
.loc
)
4708 addr
= tp
->base
.loc
->address
;
4710 /* Restore our seek position. */
4711 cur_offset
= saved_offset
;
4712 lseek (trace_fd
, cur_offset
, SEEK_SET
);
4716 /* Given a type of search and some parameters, scan the collection of
4717 traceframes in the file looking for a match. When found, return
4718 both the traceframe and tracepoint number, otherwise -1 for
4722 tfile_trace_find (enum trace_find_type type
, int num
,
4723 CORE_ADDR addr1
, CORE_ADDR addr2
, int *tpp
)
4726 int tfnum
= 0, found
= 0;
4727 unsigned int data_size
;
4728 struct tracepoint
*tp
;
4729 off_t offset
, tframe_offset
;
4739 lseek (trace_fd
, trace_frames_offset
, SEEK_SET
);
4740 offset
= trace_frames_offset
;
4743 tframe_offset
= offset
;
4744 tfile_read ((gdb_byte
*) &tpnum
, 2);
4745 tpnum
= (short) extract_signed_integer ((gdb_byte
*) &tpnum
, 2,
4747 (target_gdbarch ()));
4751 tfile_read ((gdb_byte
*) &data_size
, 4);
4752 data_size
= (unsigned int) extract_unsigned_integer
4753 ((gdb_byte
*) &data_size
, 4,
4754 gdbarch_byte_order (target_gdbarch ()));
4757 if (type
== tfind_number
)
4759 /* Looking for a specific trace frame. */
4765 /* Start from the _next_ trace frame. */
4766 if (tfnum
> traceframe_number
)
4771 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
4772 if (tfaddr
== addr1
)
4776 tp
= get_tracepoint (num
);
4777 if (tp
&& tpnum
== tp
->number_on_target
)
4781 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
4782 if (addr1
<= tfaddr
&& tfaddr
<= addr2
)
4786 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
4787 if (!(addr1
<= tfaddr
&& tfaddr
<= addr2
))
4791 internal_error (__FILE__
, __LINE__
, _("unknown tfind type"));
4800 cur_offset
= offset
;
4801 cur_data_size
= data_size
;
4805 /* Skip past the traceframe's data. */
4806 lseek (trace_fd
, data_size
, SEEK_CUR
);
4807 offset
+= data_size
;
4808 /* Update our own count of traceframes. */
4811 /* Did not find what we were looking for. */
4817 /* Prototype of the callback passed to tframe_walk_blocks. */
4818 typedef int (*walk_blocks_callback_func
) (char blocktype
, void *data
);
4820 /* Callback for traceframe_walk_blocks, used to find a given block
4821 type in a traceframe. */
4824 match_blocktype (char blocktype
, void *data
)
4826 char *wantedp
= data
;
4828 if (*wantedp
== blocktype
)
4834 /* Walk over all traceframe block starting at POS offset from
4835 CUR_OFFSET, and call CALLBACK for each block found, passing in DATA
4836 unmodified. If CALLBACK returns true, this returns the position in
4837 the traceframe where the block is found, relative to the start of
4838 the traceframe (cur_offset). Returns -1 if no callback call
4839 returned true, indicating that all blocks have been walked. */
4842 traceframe_walk_blocks (walk_blocks_callback_func callback
,
4843 int pos
, void *data
)
4845 /* Iterate through a traceframe's blocks, looking for a block of the
4848 lseek (trace_fd
, cur_offset
+ pos
, SEEK_SET
);
4849 while (pos
< cur_data_size
)
4851 unsigned short mlen
;
4854 tfile_read ((gdb_byte
*) &block_type
, 1);
4858 if ((*callback
) (block_type
, data
))
4864 lseek (trace_fd
, cur_offset
+ pos
+ trace_regblock_size
, SEEK_SET
);
4865 pos
+= trace_regblock_size
;
4868 lseek (trace_fd
, cur_offset
+ pos
+ 8, SEEK_SET
);
4869 tfile_read ((gdb_byte
*) &mlen
, 2);
4870 mlen
= (unsigned short)
4871 extract_unsigned_integer ((gdb_byte
*) &mlen
, 2,
4873 (target_gdbarch ()));
4874 lseek (trace_fd
, mlen
, SEEK_CUR
);
4875 pos
+= (8 + 2 + mlen
);
4878 lseek (trace_fd
, cur_offset
+ pos
+ 4 + 8, SEEK_SET
);
4882 error (_("Unknown block type '%c' (0x%x) in trace frame"),
4883 block_type
, block_type
);
4891 /* Convenience wrapper around traceframe_walk_blocks. Looks for the
4892 position offset of a block of type TYPE_WANTED in the current trace
4893 frame, starting at POS. Returns -1 if no such block was found. */
4896 traceframe_find_block_type (char type_wanted
, int pos
)
4898 return traceframe_walk_blocks (match_blocktype
, pos
, &type_wanted
);
4901 /* Look for a block of saved registers in the traceframe, and get the
4902 requested register from it. */
4905 tfile_fetch_registers (struct target_ops
*ops
,
4906 struct regcache
*regcache
, int regno
)
4908 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4909 int offset
, regn
, regsize
, pc_regno
;
4912 /* An uninitialized reg size says we're not going to be
4913 successful at getting register blocks. */
4914 if (!trace_regblock_size
)
4917 regs
= alloca (trace_regblock_size
);
4919 if (traceframe_find_block_type ('R', 0) >= 0)
4921 tfile_read (regs
, trace_regblock_size
);
4923 /* Assume the block is laid out in GDB register number order,
4924 each register with the size that it has in GDB. */
4926 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
4928 regsize
= register_size (gdbarch
, regn
);
4929 /* Make sure we stay within block bounds. */
4930 if (offset
+ regsize
>= trace_regblock_size
)
4932 if (regcache_register_status (regcache
, regn
) == REG_UNKNOWN
)
4936 regcache_raw_supply (regcache
, regno
, regs
+ offset
);
4939 else if (regno
== -1)
4941 regcache_raw_supply (regcache
, regn
, regs
+ offset
);
4949 /* We get here if no register data has been found. Mark registers
4951 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
4952 regcache_raw_supply (regcache
, regn
, NULL
);
4954 /* We can often usefully guess that the PC is going to be the same
4955 as the address of the tracepoint. */
4956 pc_regno
= gdbarch_pc_regnum (gdbarch
);
4957 if (pc_regno
>= 0 && (regno
== -1 || regno
== pc_regno
))
4959 struct tracepoint
*tp
= get_tracepoint (tracepoint_number
);
4961 if (tp
&& tp
->base
.loc
)
4963 /* But don't try to guess if tracepoint is multi-location... */
4964 if (tp
->base
.loc
->next
)
4966 warning (_("Tracepoint %d has multiple "
4967 "locations, cannot infer $pc"),
4971 /* ... or does while-stepping. */
4972 if (tp
->step_count
> 0)
4974 warning (_("Tracepoint %d does while-stepping, "
4975 "cannot infer $pc"),
4980 store_unsigned_integer (regs
, register_size (gdbarch
, pc_regno
),
4981 gdbarch_byte_order (gdbarch
),
4982 tp
->base
.loc
->address
);
4983 regcache_raw_supply (regcache
, pc_regno
, regs
);
4989 tfile_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4990 const char *annex
, gdb_byte
*readbuf
,
4991 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
4993 /* We're only doing regular memory for now. */
4994 if (object
!= TARGET_OBJECT_MEMORY
)
4997 if (readbuf
== NULL
)
4998 error (_("tfile_xfer_partial: trace file is read-only"));
5000 if (traceframe_number
!= -1)
5004 /* Iterate through the traceframe's blocks, looking for
5006 while ((pos
= traceframe_find_block_type ('M', pos
)) >= 0)
5008 ULONGEST maddr
, amt
;
5009 unsigned short mlen
;
5010 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
5012 tfile_read ((gdb_byte
*) &maddr
, 8);
5013 maddr
= extract_unsigned_integer ((gdb_byte
*) &maddr
, 8,
5015 tfile_read ((gdb_byte
*) &mlen
, 2);
5016 mlen
= (unsigned short)
5017 extract_unsigned_integer ((gdb_byte
*) &mlen
, 2, byte_order
);
5019 /* If the block includes the first part of the desired
5020 range, return as much it has; GDB will re-request the
5021 remainder, which might be in a different block of this
5023 if (maddr
<= offset
&& offset
< (maddr
+ mlen
))
5025 amt
= (maddr
+ mlen
) - offset
;
5029 if (maddr
!= offset
)
5030 lseek (trace_fd
, offset
- maddr
, SEEK_CUR
);
5031 tfile_read (readbuf
, amt
);
5035 /* Skip over this block. */
5036 pos
+= (8 + 2 + mlen
);
5040 /* It's unduly pedantic to refuse to look at the executable for
5041 read-only pieces; so do the equivalent of readonly regions aka
5043 /* FIXME account for relocation at some point. */
5050 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5052 if ((s
->flags
& SEC_LOAD
) == 0
5053 || (s
->flags
& SEC_READONLY
) == 0)
5057 size
= bfd_get_section_size (s
);
5058 if (vma
<= offset
&& offset
< (vma
+ size
))
5062 amt
= (vma
+ size
) - offset
;
5066 amt
= bfd_get_section_contents (exec_bfd
, s
,
5067 readbuf
, offset
- vma
, amt
);
5073 /* Indicate failure to find the requested memory block. */
5077 /* Iterate through the blocks of a trace frame, looking for a 'V'
5078 block with a matching tsv number. */
5081 tfile_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
5086 /* Iterate over blocks in current frame and find the last 'V'
5087 block in which tsv number is TSVNUM. In one trace frame, there
5088 may be multiple 'V' blocks created for a given trace variable,
5089 and the last matched 'V' block contains the updated value. */
5091 while ((pos
= traceframe_find_block_type ('V', pos
)) >= 0)
5095 tfile_read ((gdb_byte
*) &vnum
, 4);
5096 vnum
= (int) extract_signed_integer ((gdb_byte
*) &vnum
, 4,
5098 (target_gdbarch ()));
5101 tfile_read ((gdb_byte
*) val
, 8);
5102 *val
= extract_signed_integer ((gdb_byte
*) val
, 8,
5104 (target_gdbarch ()));
5114 tfile_has_all_memory (struct target_ops
*ops
)
5120 tfile_has_memory (struct target_ops
*ops
)
5126 tfile_has_stack (struct target_ops
*ops
)
5128 return traceframe_number
!= -1;
5132 tfile_has_registers (struct target_ops
*ops
)
5134 return traceframe_number
!= -1;
5137 /* Callback for traceframe_walk_blocks. Builds a traceframe_info
5138 object for the tfile target's current traceframe. */
5141 build_traceframe_info (char blocktype
, void *data
)
5143 struct traceframe_info
*info
= data
;
5149 struct mem_range
*r
;
5151 unsigned short mlen
;
5153 tfile_read ((gdb_byte
*) &maddr
, 8);
5154 maddr
= extract_unsigned_integer ((gdb_byte
*) &maddr
, 8,
5156 (target_gdbarch ()));
5157 tfile_read ((gdb_byte
*) &mlen
, 2);
5158 mlen
= (unsigned short)
5159 extract_unsigned_integer ((gdb_byte
*) &mlen
,
5160 2, gdbarch_byte_order
5161 (target_gdbarch ()));
5163 r
= VEC_safe_push (mem_range_s
, info
->memory
, NULL
);
5176 warning (_("Unhandled trace block type (%d) '%c ' "
5177 "while building trace frame info."),
5178 blocktype
, blocktype
);
5185 static struct traceframe_info
*
5186 tfile_traceframe_info (void)
5188 struct traceframe_info
*info
= XCNEW (struct traceframe_info
);
5190 traceframe_walk_blocks (build_traceframe_info
, 0, info
);
5195 init_tfile_ops (void)
5197 tfile_ops
.to_shortname
= "tfile";
5198 tfile_ops
.to_longname
= "Local trace dump file";
5200 = "Use a trace file as a target. Specify the filename of the trace file.";
5201 tfile_ops
.to_open
= tfile_open
;
5202 tfile_ops
.to_close
= tfile_close
;
5203 tfile_ops
.to_fetch_registers
= tfile_fetch_registers
;
5204 tfile_ops
.to_xfer_partial
= tfile_xfer_partial
;
5205 tfile_ops
.to_files_info
= tfile_files_info
;
5206 tfile_ops
.to_get_trace_status
= tfile_get_trace_status
;
5207 tfile_ops
.to_get_tracepoint_status
= tfile_get_tracepoint_status
;
5208 tfile_ops
.to_trace_find
= tfile_trace_find
;
5209 tfile_ops
.to_get_trace_state_variable_value
5210 = tfile_get_trace_state_variable_value
;
5211 tfile_ops
.to_stratum
= process_stratum
;
5212 tfile_ops
.to_has_all_memory
= tfile_has_all_memory
;
5213 tfile_ops
.to_has_memory
= tfile_has_memory
;
5214 tfile_ops
.to_has_stack
= tfile_has_stack
;
5215 tfile_ops
.to_has_registers
= tfile_has_registers
;
5216 tfile_ops
.to_traceframe_info
= tfile_traceframe_info
;
5217 tfile_ops
.to_magic
= OPS_MAGIC
;
5221 free_current_marker (void *arg
)
5223 struct static_tracepoint_marker
**marker_p
= arg
;
5225 if (*marker_p
!= NULL
)
5227 release_static_tracepoint_marker (*marker_p
);
5234 /* Given a line of text defining a static tracepoint marker, parse it
5235 into a "static tracepoint marker" object. Throws an error is
5236 parsing fails. If PP is non-null, it points to one past the end of
5237 the parsed marker definition. */
5240 parse_static_tracepoint_marker_definition (char *line
, char **pp
,
5241 struct static_tracepoint_marker
*marker
)
5248 p
= unpack_varlen_hex (p
, &addr
);
5249 p
++; /* skip a colon */
5251 marker
->gdbarch
= target_gdbarch ();
5252 marker
->address
= (CORE_ADDR
) addr
;
5254 endp
= strchr (p
, ':');
5256 error (_("bad marker definition: %s"), line
);
5258 marker
->str_id
= xmalloc (endp
- p
+ 1);
5259 end
= hex2bin (p
, (gdb_byte
*) marker
->str_id
, (endp
- p
+ 1) / 2);
5260 marker
->str_id
[end
] = '\0';
5263 p
++; /* skip a colon */
5265 marker
->extra
= xmalloc (strlen (p
) + 1);
5266 end
= hex2bin (p
, (gdb_byte
*) marker
->extra
, strlen (p
) / 2);
5267 marker
->extra
[end
] = '\0';
5273 /* Release a static tracepoint marker's contents. Note that the
5274 object itself isn't released here. There objects are usually on
5278 release_static_tracepoint_marker (struct static_tracepoint_marker
*marker
)
5280 xfree (marker
->str_id
);
5281 marker
->str_id
= NULL
;
5284 /* Print MARKER to gdb_stdout. */
5287 print_one_static_tracepoint_marker (int count
,
5288 struct static_tracepoint_marker
*marker
)
5290 struct command_line
*l
;
5293 char wrap_indent
[80];
5294 char extra_field_indent
[80];
5295 struct ui_out
*uiout
= current_uiout
;
5296 struct cleanup
*bkpt_chain
;
5297 VEC(breakpoint_p
) *tracepoints
;
5299 struct symtab_and_line sal
;
5303 sal
.pc
= marker
->address
;
5305 tracepoints
= static_tracepoints_here (marker
->address
);
5307 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "marker");
5309 /* A counter field to help readability. This is not a stable
5311 ui_out_field_int (uiout
, "count", count
);
5313 ui_out_field_string (uiout
, "marker-id", marker
->str_id
);
5315 ui_out_field_fmt (uiout
, "enabled", "%c",
5316 !VEC_empty (breakpoint_p
, tracepoints
) ? 'y' : 'n');
5317 ui_out_spaces (uiout
, 2);
5319 strcpy (wrap_indent
, " ");
5321 if (gdbarch_addr_bit (marker
->gdbarch
) <= 32)
5322 strcat (wrap_indent
, " ");
5324 strcat (wrap_indent
, " ");
5326 strcpy (extra_field_indent
, " ");
5328 ui_out_field_core_addr (uiout
, "addr", marker
->gdbarch
, marker
->address
);
5330 sal
= find_pc_line (marker
->address
, 0);
5331 sym
= find_pc_sect_function (marker
->address
, NULL
);
5334 ui_out_text (uiout
, "in ");
5335 ui_out_field_string (uiout
, "func",
5336 SYMBOL_PRINT_NAME (sym
));
5337 ui_out_wrap_hint (uiout
, wrap_indent
);
5338 ui_out_text (uiout
, " at ");
5341 ui_out_field_skip (uiout
, "func");
5343 if (sal
.symtab
!= NULL
)
5345 ui_out_field_string (uiout
, "file",
5346 symtab_to_filename_for_display (sal
.symtab
));
5347 ui_out_text (uiout
, ":");
5349 if (ui_out_is_mi_like_p (uiout
))
5351 const char *fullname
= symtab_to_fullname (sal
.symtab
);
5353 ui_out_field_string (uiout
, "fullname", fullname
);
5356 ui_out_field_skip (uiout
, "fullname");
5358 ui_out_field_int (uiout
, "line", sal
.line
);
5362 ui_out_field_skip (uiout
, "fullname");
5363 ui_out_field_skip (uiout
, "line");
5366 ui_out_text (uiout
, "\n");
5367 ui_out_text (uiout
, extra_field_indent
);
5368 ui_out_text (uiout
, _("Data: \""));
5369 ui_out_field_string (uiout
, "extra-data", marker
->extra
);
5370 ui_out_text (uiout
, "\"\n");
5372 if (!VEC_empty (breakpoint_p
, tracepoints
))
5374 struct cleanup
*cleanup_chain
;
5376 struct breakpoint
*b
;
5378 cleanup_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
,
5381 ui_out_text (uiout
, extra_field_indent
);
5382 ui_out_text (uiout
, _("Probed by static tracepoints: "));
5383 for (ix
= 0; VEC_iterate(breakpoint_p
, tracepoints
, ix
, b
); ix
++)
5386 ui_out_text (uiout
, ", ");
5387 ui_out_text (uiout
, "#");
5388 ui_out_field_int (uiout
, "tracepoint-id", b
->number
);
5391 do_cleanups (cleanup_chain
);
5393 if (ui_out_is_mi_like_p (uiout
))
5394 ui_out_field_int (uiout
, "number-of-tracepoints",
5395 VEC_length(breakpoint_p
, tracepoints
));
5397 ui_out_text (uiout
, "\n");
5399 VEC_free (breakpoint_p
, tracepoints
);
5401 do_cleanups (bkpt_chain
);
5405 info_static_tracepoint_markers_command (char *arg
, int from_tty
)
5407 VEC(static_tracepoint_marker_p
) *markers
;
5408 struct cleanup
*old_chain
;
5409 struct static_tracepoint_marker
*marker
;
5410 struct ui_out
*uiout
= current_uiout
;
5413 /* We don't have to check target_can_use_agent and agent's capability on
5414 static tracepoint here, in order to be compatible with older GDBserver.
5415 We don't check USE_AGENT is true or not, because static tracepoints
5416 don't work without in-process agent, so we don't bother users to type
5417 `set agent on' when to use static tracepoint. */
5420 = make_cleanup_ui_out_table_begin_end (uiout
, 5, -1,
5421 "StaticTracepointMarkersTable");
5423 ui_out_table_header (uiout
, 7, ui_left
, "counter", "Cnt");
5425 ui_out_table_header (uiout
, 40, ui_left
, "marker-id", "ID");
5427 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb");
5428 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
5429 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");
5431 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");
5432 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What");
5434 ui_out_table_body (uiout
);
5436 markers
= target_static_tracepoint_markers_by_strid (NULL
);
5437 make_cleanup (VEC_cleanup (static_tracepoint_marker_p
), &markers
);
5440 VEC_iterate (static_tracepoint_marker_p
,
5441 markers
, i
, marker
);
5444 print_one_static_tracepoint_marker (i
+ 1, marker
);
5445 release_static_tracepoint_marker (marker
);
5448 do_cleanups (old_chain
);
5451 /* The $_sdata convenience variable is a bit special. We don't know
5452 for sure type of the value until we actually have a chance to fetch
5453 the data --- the size of the object depends on what has been
5454 collected. We solve this by making $_sdata be an internalvar that
5455 creates a new value on access. */
5457 /* Return a new value with the correct type for the sdata object of
5458 the current trace frame. Return a void value if there's no object
5461 static struct value
*
5462 sdata_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
5468 /* We need to read the whole object before we know its size. */
5469 size
= target_read_alloc (¤t_target
,
5470 TARGET_OBJECT_STATIC_TRACE_DATA
,
5477 type
= init_vector_type (builtin_type (gdbarch
)->builtin_true_char
,
5479 v
= allocate_value (type
);
5480 memcpy (value_contents_raw (v
), buf
, size
);
5485 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
5488 #if !defined(HAVE_LIBEXPAT)
5490 struct traceframe_info
*
5491 parse_traceframe_info (const char *tframe_info
)
5493 static int have_warned
;
5498 warning (_("Can not parse XML trace frame info; XML support "
5499 "was disabled at compile time"));
5505 #else /* HAVE_LIBEXPAT */
5507 #include "xml-support.h"
5509 /* Handle the start of a <memory> element. */
5512 traceframe_info_start_memory (struct gdb_xml_parser
*parser
,
5513 const struct gdb_xml_element
*element
,
5514 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
5516 struct traceframe_info
*info
= user_data
;
5517 struct mem_range
*r
= VEC_safe_push (mem_range_s
, info
->memory
, NULL
);
5518 ULONGEST
*start_p
, *length_p
;
5520 start_p
= xml_find_attribute (attributes
, "start")->value
;
5521 length_p
= xml_find_attribute (attributes
, "length")->value
;
5523 r
->start
= *start_p
;
5524 r
->length
= *length_p
;
5527 /* Discard the constructed trace frame info (if an error occurs). */
5530 free_result (void *p
)
5532 struct traceframe_info
*result
= p
;
5534 free_traceframe_info (result
);
5537 /* The allowed elements and attributes for an XML memory map. */
5539 static const struct gdb_xml_attribute memory_attributes
[] = {
5540 { "start", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
5541 { "length", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
5542 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
5545 static const struct gdb_xml_element traceframe_info_children
[] = {
5546 { "memory", memory_attributes
, NULL
,
5547 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
5548 traceframe_info_start_memory
, NULL
},
5549 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
5552 static const struct gdb_xml_element traceframe_info_elements
[] = {
5553 { "traceframe-info", NULL
, traceframe_info_children
, GDB_XML_EF_NONE
,
5555 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
5558 /* Parse a traceframe-info XML document. */
5560 struct traceframe_info
*
5561 parse_traceframe_info (const char *tframe_info
)
5563 struct traceframe_info
*result
;
5564 struct cleanup
*back_to
;
5566 result
= XCNEW (struct traceframe_info
);
5567 back_to
= make_cleanup (free_result
, result
);
5569 if (gdb_xml_parse_quick (_("trace frame info"),
5570 "traceframe-info.dtd", traceframe_info_elements
,
5571 tframe_info
, result
) == 0)
5573 /* Parsed successfully, keep the result. */
5574 discard_cleanups (back_to
);
5579 do_cleanups (back_to
);
5583 #endif /* HAVE_LIBEXPAT */
5585 /* Returns the traceframe_info object for the current traceframe.
5586 This is where we avoid re-fetching the object from the target if we
5587 already have it cached. */
5589 static struct traceframe_info
*
5590 get_traceframe_info (void)
5592 if (traceframe_info
== NULL
)
5593 traceframe_info
= target_traceframe_info ();
5595 return traceframe_info
;
5598 /* If the target supports the query, return in RESULT the set of
5599 collected memory in the current traceframe, found within the LEN
5600 bytes range starting at MEMADDR. Returns true if the target
5601 supports the query, otherwise returns false, and RESULT is left
5605 traceframe_available_memory (VEC(mem_range_s
) **result
,
5606 CORE_ADDR memaddr
, ULONGEST len
)
5608 struct traceframe_info
*info
= get_traceframe_info ();
5612 struct mem_range
*r
;
5617 for (i
= 0; VEC_iterate (mem_range_s
, info
->memory
, i
, r
); i
++)
5618 if (mem_ranges_overlap (r
->start
, r
->length
, memaddr
, len
))
5620 ULONGEST lo1
, hi1
, lo2
, hi2
;
5621 struct mem_range
*nr
;
5624 hi1
= memaddr
+ len
;
5627 hi2
= r
->start
+ r
->length
;
5629 nr
= VEC_safe_push (mem_range_s
, *result
, NULL
);
5631 nr
->start
= max (lo1
, lo2
);
5632 nr
->length
= min (hi1
, hi2
) - nr
->start
;
5635 normalize_mem_ranges (*result
);
5642 /* Implementation of `sdata' variable. */
5644 static const struct internalvar_funcs sdata_funcs
=
5651 /* module initialization */
5653 _initialize_tracepoint (void)
5655 struct cmd_list_element
*c
;
5657 /* Explicitly create without lookup, since that tries to create a
5658 value with a void typed value, and when we get here, gdbarch
5659 isn't initialized yet. At this point, we're quite sure there
5660 isn't another convenience variable of the same name. */
5661 create_internalvar_type_lazy ("_sdata", &sdata_funcs
, NULL
);
5663 traceframe_number
= -1;
5664 tracepoint_number
= -1;
5666 if (tracepoint_list
.list
== NULL
)
5668 tracepoint_list
.listsize
= 128;
5669 tracepoint_list
.list
= xmalloc
5670 (tracepoint_list
.listsize
* sizeof (struct memrange
));
5672 if (tracepoint_list
.aexpr_list
== NULL
)
5674 tracepoint_list
.aexpr_listsize
= 128;
5675 tracepoint_list
.aexpr_list
= xmalloc
5676 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
5679 if (stepping_list
.list
== NULL
)
5681 stepping_list
.listsize
= 128;
5682 stepping_list
.list
= xmalloc
5683 (stepping_list
.listsize
* sizeof (struct memrange
));
5686 if (stepping_list
.aexpr_list
== NULL
)
5688 stepping_list
.aexpr_listsize
= 128;
5689 stepping_list
.aexpr_list
= xmalloc
5690 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
5693 add_info ("scope", scope_info
,
5694 _("List the variables local to a scope"));
5696 add_cmd ("tracepoints", class_trace
, NULL
,
5697 _("Tracing of program execution without stopping the program."),
5700 add_com ("tdump", class_trace
, trace_dump_command
,
5701 _("Print everything collected at the current tracepoint."));
5703 add_com ("tsave", class_trace
, trace_save_command
, _("\
5704 Save the trace data to a file.\n\
5705 Use the '-ctf' option to save the data to CTF format.\n\
5706 Use the '-r' option to direct the target to save directly to the file,\n\
5707 using its own filesystem."));
5709 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
5710 Define a trace state variable.\n\
5711 Argument is a $-prefixed name, optionally followed\n\
5712 by '=' and an expression that sets the initial value\n\
5713 at the start of tracing."));
5714 set_cmd_completer (c
, expression_completer
);
5716 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
5717 Delete one or more trace state variables.\n\
5718 Arguments are the names of the variables to delete.\n\
5719 If no arguments are supplied, delete all variables."), &deletelist
);
5720 /* FIXME add a trace variable completer. */
5722 add_info ("tvariables", tvariables_info
, _("\
5723 Status of trace state variables and their values.\n\
5726 add_info ("static-tracepoint-markers",
5727 info_static_tracepoint_markers_command
, _("\
5728 List target static tracepoints markers.\n\
5731 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
5732 Select a trace frame;\n\
5733 No argument means forward by one frame; '-' means backward by one frame."),
5734 &tfindlist
, "tfind ", 1, &cmdlist
);
5736 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
5737 Select a trace frame whose PC is outside the given range (exclusive).\n\
5738 Usage: tfind outside addr1, addr2"),
5741 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
5742 Select a trace frame whose PC is in the given range (inclusive).\n\
5743 Usage: tfind range addr1,addr2"),
5746 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
5747 Select a trace frame by source line.\n\
5748 Argument can be a line number (with optional source file),\n\
5749 a function name, or '*' followed by an address.\n\
5750 Default argument is 'the next source line that was traced'."),
5753 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
5754 Select a trace frame by tracepoint number.\n\
5755 Default is the tracepoint for the current trace frame."),
5758 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
5759 Select a trace frame by PC.\n\
5760 Default is the current PC, or the PC of the current trace frame."),
5763 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
5764 De-select any trace frame and resume 'live' debugging."),
5767 add_alias_cmd ("none", "end", class_trace
, 0, &tfindlist
);
5769 add_cmd ("start", class_trace
, trace_find_start_command
,
5770 _("Select the first trace frame in the trace buffer."),
5773 add_com ("tstatus", class_trace
, trace_status_command
,
5774 _("Display the status of the current trace data collection."));
5776 add_com ("tstop", class_trace
, trace_stop_command
, _("\
5777 Stop trace data collection.\n\
5778 Usage: tstop [ <notes> ... ]\n\
5779 Any arguments supplied are recorded with the trace as a stop reason and\n\
5780 reported by tstatus (if the target supports trace notes)."));
5782 add_com ("tstart", class_trace
, trace_start_command
, _("\
5783 Start trace data collection.\n\
5784 Usage: tstart [ <notes> ... ]\n\
5785 Any arguments supplied are recorded with the trace as a note and\n\
5786 reported by tstatus (if the target supports trace notes)."));
5788 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
5789 Ends a list of commands or actions.\n\
5790 Several GDB commands allow you to enter a list of commands or actions.\n\
5791 Entering \"end\" on a line by itself is the normal way to terminate\n\
5793 Note: the \"end\" command cannot be used at the gdb prompt."));
5795 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
5796 Specify single-stepping behavior at a tracepoint.\n\
5797 Argument is number of instructions to trace in single-step mode\n\
5798 following the tracepoint. This command is normally followed by\n\
5799 one or more \"collect\" commands, to specify what to collect\n\
5800 while single-stepping.\n\n\
5801 Note: this command can only be used in a tracepoint \"actions\" list."));
5803 add_com_alias ("ws", "while-stepping", class_alias
, 0);
5804 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
5806 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
5807 Specify one or more data items to be collected at a tracepoint.\n\
5808 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
5809 collect all data (variables, registers) referenced by that expression.\n\
5810 Also accepts the following special arguments:\n\
5811 $regs -- all registers.\n\
5812 $args -- all function arguments.\n\
5813 $locals -- all variables local to the block/function scope.\n\
5814 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
5815 Note: this command can only be used in a tracepoint \"actions\" list."));
5817 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
5818 Specify one or more expressions to be evaluated at a tracepoint.\n\
5819 Accepts a comma-separated list of (one or more) expressions.\n\
5820 The result of each evaluation will be discarded.\n\
5821 Note: this command can only be used in a tracepoint \"actions\" list."));
5823 add_com ("actions", class_trace
, trace_actions_command
, _("\
5824 Specify the actions to be taken at a tracepoint.\n\
5825 Tracepoint actions may include collecting of specified data,\n\
5826 single-stepping, or enabling/disabling other tracepoints,\n\
5827 depending on target's capabilities."));
5829 default_collect
= xstrdup ("");
5830 add_setshow_string_cmd ("default-collect", class_trace
,
5831 &default_collect
, _("\
5832 Set the list of expressions to collect by default"), _("\
5833 Show the list of expressions to collect by default"), NULL
,
5835 &setlist
, &showlist
);
5837 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
5838 &disconnected_tracing
, _("\
5839 Set whether tracing continues after GDB disconnects."), _("\
5840 Show whether tracing continues after GDB disconnects."), _("\
5841 Use this to continue a tracing run even if GDB disconnects\n\
5842 or detaches from the target. You can reconnect later and look at\n\
5843 trace data collected in the meantime."),
5844 set_disconnected_tracing
,
5849 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
5850 &circular_trace_buffer
, _("\
5851 Set target's use of circular trace buffer."), _("\
5852 Show target's use of circular trace buffer."), _("\
5853 Use this to make the trace buffer into a circular buffer,\n\
5854 which will discard traceframes (oldest first) instead of filling\n\
5855 up and stopping the trace run."),
5856 set_circular_trace_buffer
,
5861 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class
,
5862 &trace_buffer_size
, _("\
5863 Set requested size of trace buffer."), _("\
5864 Show requested size of trace buffer."), _("\
5865 Use this to choose a size for the trace buffer. Some targets\n\
5866 may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
5867 disables any attempt to set the buffer size and lets the target choose."),
5868 set_trace_buffer_size
, NULL
,
5869 &setlist
, &showlist
);
5871 add_setshow_string_cmd ("trace-user", class_trace
,
5873 Set the user name to use for current and future trace runs"), _("\
5874 Show the user name to use for current and future trace runs"), NULL
,
5875 set_trace_user
, NULL
,
5876 &setlist
, &showlist
);
5878 add_setshow_string_cmd ("trace-notes", class_trace
,
5880 Set notes string to use for current and future trace runs"), _("\
5881 Show the notes string to use for current and future trace runs"), NULL
,
5882 set_trace_notes
, NULL
,
5883 &setlist
, &showlist
);
5885 add_setshow_string_cmd ("trace-stop-notes", class_trace
,
5886 &trace_stop_notes
, _("\
5887 Set notes string to use for future tstop commands"), _("\
5888 Show the notes string to use for future tstop commands"), NULL
,
5889 set_trace_stop_notes
, NULL
,
5890 &setlist
, &showlist
);
5894 add_target_with_completer (&tfile_ops
, filename_completer
);