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"
58 /* readline include files */
59 #include "readline/readline.h"
60 #include "readline/history.h"
62 /* readline defines this. */
73 /* Maximum length of an agent aexpression.
74 This accounts for the fact that packets are limited to 400 bytes
75 (which includes everything -- including the checksum), and assumes
76 the worst case of maximum length for each of the pieces of a
79 NOTE: expressions get mem2hex'ed otherwise this would be twice as
80 large. (400 - 31)/2 == 184 */
81 #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 /* An object describing the contents of a traceframe. */
131 struct traceframe_info
133 /* Collected memory. */
134 VEC(mem_range_s
) *memory
;
137 static VEC(tsv_s
) *tvariables
;
139 /* The next integer to assign to a variable. */
141 static int next_tsv_number
= 1;
143 /* Number of last traceframe collected. */
144 static int traceframe_number
;
146 /* Tracepoint for last traceframe collected. */
147 static int tracepoint_number
;
149 /* Symbol for function for last traceframe collected. */
150 static struct symbol
*traceframe_fun
;
152 /* Symtab and line for last traceframe collected. */
153 static struct symtab_and_line traceframe_sal
;
155 /* The traceframe info of the current traceframe. NULL if we haven't
156 yet attempted to fetch it, or if the target does not support
157 fetching this object, or if we're not inspecting a traceframe
159 static struct traceframe_info
*traceframe_info
;
161 /* Tracing command lists. */
162 static struct cmd_list_element
*tfindlist
;
164 /* List of expressions to collect by default at each tracepoint hit. */
165 char *default_collect
= "";
167 static int disconnected_tracing
;
169 /* This variable controls whether we ask the target for a linear or
170 circular trace buffer. */
172 static int circular_trace_buffer
;
174 /* This variable is the requested trace buffer size, or -1 to indicate
175 that we don't care and leave it up to the target to set a size. */
177 static int trace_buffer_size
= -1;
179 /* Textual notes applying to the current and/or future trace runs. */
181 char *trace_user
= NULL
;
183 /* Textual notes applying to the current and/or future trace runs. */
185 char *trace_notes
= NULL
;
187 /* Textual notes applying to the stopping of a trace. */
189 char *trace_stop_notes
= NULL
;
191 /* ======= Important command functions: ======= */
192 static void trace_actions_command (char *, int);
193 static void trace_start_command (char *, int);
194 static void trace_stop_command (char *, int);
195 static void trace_status_command (char *, int);
196 static void trace_find_command (char *, int);
197 static void trace_find_pc_command (char *, int);
198 static void trace_find_tracepoint_command (char *, int);
199 static void trace_find_line_command (char *, int);
200 static void trace_find_range_command (char *, int);
201 static void trace_find_outside_command (char *, int);
202 static void trace_dump_command (char *, int);
204 /* support routines */
206 struct collection_list
;
207 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
208 static char *mem2hex (gdb_byte
*, char *, int);
209 static void add_register (struct collection_list
*collection
,
212 static void free_uploaded_tps (struct uploaded_tp
**utpp
);
213 static void free_uploaded_tsvs (struct uploaded_tsv
**utsvp
);
216 extern void _initialize_tracepoint (void);
218 static struct trace_status trace_status
;
220 char *stop_reason_names
[] = {
230 struct trace_status
*
231 current_trace_status (void)
233 return &trace_status
;
239 free_traceframe_info (struct traceframe_info
*info
)
243 VEC_free (mem_range_s
, info
->memory
);
249 /* Free and clear the traceframe info cache of the current
253 clear_traceframe_info (void)
255 free_traceframe_info (traceframe_info
);
256 traceframe_info
= NULL
;
259 /* Set traceframe number to NUM. */
261 set_traceframe_num (int num
)
263 traceframe_number
= num
;
264 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
267 /* Set tracepoint number to NUM. */
269 set_tracepoint_num (int num
)
271 tracepoint_number
= num
;
272 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
275 /* Set externally visible debug variables for querying/printing
276 the traceframe context (line, function, file). */
279 set_traceframe_context (struct frame_info
*trace_frame
)
283 /* Save as globals for internal use. */
284 if (trace_frame
!= NULL
285 && get_frame_pc_if_available (trace_frame
, &trace_pc
))
287 traceframe_sal
= find_pc_line (trace_pc
, 0);
288 traceframe_fun
= find_pc_function (trace_pc
);
290 /* Save linenumber as "$trace_line", a debugger variable visible to
292 set_internalvar_integer (lookup_internalvar ("trace_line"),
293 traceframe_sal
.line
);
297 init_sal (&traceframe_sal
);
298 traceframe_fun
= NULL
;
299 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
302 /* Save func name as "$trace_func", a debugger variable visible to
304 if (traceframe_fun
== NULL
305 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
306 clear_internalvar (lookup_internalvar ("trace_func"));
308 set_internalvar_string (lookup_internalvar ("trace_func"),
309 SYMBOL_LINKAGE_NAME (traceframe_fun
));
311 /* Save file name as "$trace_file", a debugger variable visible to
313 if (traceframe_sal
.symtab
== NULL
)
314 clear_internalvar (lookup_internalvar ("trace_file"));
316 set_internalvar_string (lookup_internalvar ("trace_file"),
317 symtab_to_filename_for_display (traceframe_sal
.symtab
));
320 /* Create a new trace state variable with the given name. */
322 struct trace_state_variable
*
323 create_trace_state_variable (const char *name
)
325 struct trace_state_variable tsv
;
327 memset (&tsv
, 0, sizeof (tsv
));
328 tsv
.name
= xstrdup (name
);
329 tsv
.number
= next_tsv_number
++;
330 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
333 /* Look for a trace state variable of the given name. */
335 struct trace_state_variable
*
336 find_trace_state_variable (const char *name
)
338 struct trace_state_variable
*tsv
;
341 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
342 if (strcmp (name
, tsv
->name
) == 0)
349 delete_trace_state_variable (const char *name
)
351 struct trace_state_variable
*tsv
;
354 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
355 if (strcmp (name
, tsv
->name
) == 0)
357 observer_notify_tsv_deleted (tsv
);
359 xfree ((void *)tsv
->name
);
360 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
365 warning (_("No trace variable named \"$%s\", not deleting"), name
);
368 /* Throws an error if NAME is not valid syntax for a trace state
372 validate_trace_state_variable_name (const char *name
)
377 error (_("Must supply a non-empty variable name"));
379 /* All digits in the name is reserved for value history
381 for (p
= name
; isdigit (*p
); p
++)
384 error (_("$%s is not a valid trace state variable name"), name
);
386 for (p
= name
; isalnum (*p
) || *p
== '_'; p
++)
389 error (_("$%s is not a valid trace state variable name"), name
);
392 /* The 'tvariable' command collects a name and optional expression to
393 evaluate into an initial value. */
396 trace_variable_command (char *args
, int from_tty
)
398 struct cleanup
*old_chain
;
400 struct trace_state_variable
*tsv
;
404 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
406 /* Only allow two syntaxes; "$name" and "$name=value". */
407 p
= skip_spaces (args
);
410 error (_("Name of trace variable should start with '$'"));
413 while (isalnum (*p
) || *p
== '_')
415 name
= savestring (name
, p
- name
);
416 old_chain
= make_cleanup (xfree
, name
);
419 if (*p
!= '=' && *p
!= '\0')
420 error (_("Syntax must be $NAME [ = EXPR ]"));
422 validate_trace_state_variable_name (name
);
425 initval
= value_as_long (parse_and_eval (++p
));
427 /* If the variable already exists, just change its initial value. */
428 tsv
= find_trace_state_variable (name
);
431 if (tsv
->initial_value
!= initval
)
433 tsv
->initial_value
= initval
;
434 observer_notify_tsv_modified (tsv
);
436 printf_filtered (_("Trace state variable $%s "
437 "now has initial value %s.\n"),
438 tsv
->name
, plongest (tsv
->initial_value
));
439 do_cleanups (old_chain
);
443 /* Create a new variable. */
444 tsv
= create_trace_state_variable (name
);
445 tsv
->initial_value
= initval
;
447 observer_notify_tsv_created (tsv
);
449 printf_filtered (_("Trace state variable $%s "
450 "created, with initial value %s.\n"),
451 tsv
->name
, plongest (tsv
->initial_value
));
453 do_cleanups (old_chain
);
457 delete_trace_variable_command (char *args
, int from_tty
)
461 struct cleanup
*back_to
;
465 if (query (_("Delete all trace state variables? ")))
466 VEC_free (tsv_s
, tvariables
);
468 observer_notify_tsv_deleted (NULL
);
472 argv
= gdb_buildargv (args
);
473 back_to
= make_cleanup_freeargv (argv
);
475 for (ix
= 0; argv
[ix
] != NULL
; ix
++)
477 if (*argv
[ix
] == '$')
478 delete_trace_state_variable (argv
[ix
] + 1);
480 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv
[ix
]);
483 do_cleanups (back_to
);
489 tvariables_info_1 (void)
491 struct trace_state_variable
*tsv
;
494 struct cleanup
*back_to
;
495 struct ui_out
*uiout
= current_uiout
;
497 if (VEC_length (tsv_s
, tvariables
) == 0 && !ui_out_is_mi_like_p (uiout
))
499 printf_filtered (_("No trace state variables.\n"));
503 /* Try to acquire values from the target. */
504 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
, ++count
)
505 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
508 back_to
= make_cleanup_ui_out_table_begin_end (uiout
, 3,
509 count
, "trace-variables");
510 ui_out_table_header (uiout
, 15, ui_left
, "name", "Name");
511 ui_out_table_header (uiout
, 11, ui_left
, "initial", "Initial");
512 ui_out_table_header (uiout
, 11, ui_left
, "current", "Current");
514 ui_out_table_body (uiout
);
516 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
518 struct cleanup
*back_to2
;
522 back_to2
= make_cleanup_ui_out_tuple_begin_end (uiout
, "variable");
524 name
= concat ("$", tsv
->name
, (char *) NULL
);
525 make_cleanup (xfree
, name
);
526 ui_out_field_string (uiout
, "name", name
);
527 ui_out_field_string (uiout
, "initial", plongest (tsv
->initial_value
));
529 if (tsv
->value_known
)
530 c
= plongest (tsv
->value
);
531 else if (ui_out_is_mi_like_p (uiout
))
532 /* For MI, we prefer not to use magic string constants, but rather
533 omit the field completely. The difference between unknown and
534 undefined does not seem important enough to represent. */
536 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
537 /* The value is/was defined, but we don't have it. */
540 /* It is not meaningful to ask about the value. */
543 ui_out_field_string (uiout
, "current", c
);
544 ui_out_text (uiout
, "\n");
546 do_cleanups (back_to2
);
549 do_cleanups (back_to
);
552 /* List all the trace state variables. */
555 tvariables_info (char *args
, int from_tty
)
557 tvariables_info_1 ();
560 /* Stash definitions of tsvs into the given file. */
563 save_trace_state_variables (struct ui_file
*fp
)
565 struct trace_state_variable
*tsv
;
568 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
570 fprintf_unfiltered (fp
, "tvariable $%s", tsv
->name
);
571 if (tsv
->initial_value
)
572 fprintf_unfiltered (fp
, " = %s", plongest (tsv
->initial_value
));
573 fprintf_unfiltered (fp
, "\n");
577 /* ACTIONS functions: */
579 /* The three functions:
580 collect_pseudocommand,
581 while_stepping_pseudocommand, and
582 end_actions_pseudocommand
583 are placeholders for "commands" that are actually ONLY to be used
584 within a tracepoint action list. If the actual function is ever called,
585 it means that somebody issued the "command" at the top level,
586 which is always an error. */
589 end_actions_pseudocommand (char *args
, int from_tty
)
591 error (_("This command cannot be used at the top level."));
595 while_stepping_pseudocommand (char *args
, int from_tty
)
597 error (_("This command can only be used in a tracepoint actions list."));
601 collect_pseudocommand (char *args
, int from_tty
)
603 error (_("This command can only be used in a tracepoint actions list."));
607 teval_pseudocommand (char *args
, int from_tty
)
609 error (_("This command can only be used in a tracepoint actions list."));
612 /* Parse any collection options, such as /s for strings. */
615 decode_agent_options (const char *exp
, int *trace_string
)
617 struct value_print_options opts
;
624 /* Call this to borrow the print elements default for collection
626 get_user_print_options (&opts
);
631 if (target_supports_string_tracing ())
633 /* Allow an optional decimal number giving an explicit maximum
634 string length, defaulting it to the "print elements" value;
635 so "collect/s80 mystr" gets at most 80 bytes of string. */
636 *trace_string
= opts
.print_max
;
638 if (*exp
>= '0' && *exp
<= '9')
639 *trace_string
= atoi (exp
);
640 while (*exp
>= '0' && *exp
<= '9')
644 error (_("Target does not support \"/s\" option for string tracing."));
647 error (_("Undefined collection format \"%c\"."), *exp
);
649 exp
= skip_spaces_const (exp
);
654 /* Enter a list of actions for a tracepoint. */
656 trace_actions_command (char *args
, int from_tty
)
658 struct tracepoint
*t
;
659 struct command_line
*l
;
661 t
= get_tracepoint_by_number (&args
, NULL
, 1);
665 xstrprintf ("Enter actions for tracepoint %d, one per line.",
667 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
669 l
= read_command_lines (tmpbuf
, from_tty
, 1,
670 check_tracepoint_command
, t
);
671 do_cleanups (cleanups
);
672 breakpoint_set_commands (&t
->base
, l
);
674 /* else just return */
677 /* Report the results of checking the agent expression, as errors or
681 report_agent_reqs_errors (struct agent_expr
*aexpr
)
683 /* All of the "flaws" are serious bytecode generation issues that
684 should never occur. */
685 if (aexpr
->flaw
!= agent_flaw_none
)
686 internal_error (__FILE__
, __LINE__
, _("expression is malformed"));
688 /* If analysis shows a stack underflow, GDB must have done something
689 badly wrong in its bytecode generation. */
690 if (aexpr
->min_height
< 0)
691 internal_error (__FILE__
, __LINE__
,
692 _("expression has min height < 0"));
694 /* Issue this error if the stack is predicted to get too deep. The
695 limit is rather arbitrary; a better scheme might be for the
696 target to report how much stack it will have available. The
697 depth roughly corresponds to parenthesization, so a limit of 20
698 amounts to 20 levels of expression nesting, which is actually
699 a pretty big hairy expression. */
700 if (aexpr
->max_height
> 20)
701 error (_("Expression is too complicated."));
704 /* worker function */
706 validate_actionline (const char *line
, struct breakpoint
*b
)
708 struct cmd_list_element
*c
;
709 struct expression
*exp
= NULL
;
710 struct cleanup
*old_chain
= NULL
;
713 struct bp_location
*loc
;
714 struct agent_expr
*aexpr
;
715 struct tracepoint
*t
= (struct tracepoint
*) b
;
717 /* If EOF is typed, *line is NULL. */
721 p
= skip_spaces_const (line
);
723 /* Symbol lookup etc. */
724 if (*p
== '\0') /* empty line: just prompt for another line. */
727 if (*p
== '#') /* comment line */
730 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
732 error (_("`%s' is not a tracepoint action, or is ambiguous."), p
);
734 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
736 int trace_string
= 0;
739 p
= decode_agent_options (p
, &trace_string
);
742 { /* Repeat over a comma-separated list. */
743 QUIT
; /* Allow user to bail out with ^C. */
744 p
= skip_spaces_const (p
);
746 if (*p
== '$') /* Look for special pseudo-symbols. */
748 if (0 == strncasecmp ("reg", p
+ 1, 3)
749 || 0 == strncasecmp ("arg", p
+ 1, 3)
750 || 0 == strncasecmp ("loc", p
+ 1, 3)
751 || 0 == strncasecmp ("_ret", p
+ 1, 4)
752 || 0 == strncasecmp ("_sdata", p
+ 1, 6))
757 /* else fall thru, treat p as an expression and parse it! */
760 for (loc
= t
->base
.loc
; loc
; loc
= loc
->next
)
763 exp
= parse_exp_1 (&p
, loc
->address
,
764 block_for_pc (loc
->address
), 1);
765 old_chain
= make_cleanup (free_current_contents
, &exp
);
767 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
769 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
771 error (_("constant `%s' (value %s) "
772 "will not be collected."),
773 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
774 plongest (SYMBOL_VALUE (exp
->elts
[2].symbol
)));
776 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
)
777 == LOC_OPTIMIZED_OUT
)
779 error (_("`%s' is optimized away "
780 "and cannot be collected."),
781 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
785 /* We have something to collect, make sure that the expr to
786 bytecode translator can handle it and that it's not too
788 aexpr
= gen_trace_for_expr (loc
->address
, exp
, trace_string
);
789 make_cleanup_free_agent_expr (aexpr
);
791 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
792 error (_("Expression is too complicated."));
796 report_agent_reqs_errors (aexpr
);
798 do_cleanups (old_chain
);
801 while (p
&& *p
++ == ',');
804 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
807 { /* Repeat over a comma-separated list. */
808 QUIT
; /* Allow user to bail out with ^C. */
809 p
= skip_spaces_const (p
);
812 for (loc
= t
->base
.loc
; loc
; loc
= loc
->next
)
816 /* Only expressions are allowed for this action. */
817 exp
= parse_exp_1 (&p
, loc
->address
,
818 block_for_pc (loc
->address
), 1);
819 old_chain
= make_cleanup (free_current_contents
, &exp
);
821 /* We have something to evaluate, make sure that the expr to
822 bytecode translator can handle it and that it's not too
824 aexpr
= gen_eval_for_expr (loc
->address
, exp
);
825 make_cleanup_free_agent_expr (aexpr
);
827 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
828 error (_("Expression is too complicated."));
831 report_agent_reqs_errors (aexpr
);
833 do_cleanups (old_chain
);
836 while (p
&& *p
++ == ',');
839 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
843 p
= skip_spaces_const (p
);
844 t
->step_count
= strtol (p
, &endp
, 0);
845 if (endp
== p
|| t
->step_count
== 0)
846 error (_("while-stepping step count `%s' is malformed."), line
);
850 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
854 error (_("`%s' is not a supported tracepoint action."), line
);
858 memrange_absolute
= -1
863 int type
; /* memrange_absolute for absolute memory range,
864 else basereg number. */
865 bfd_signed_vma start
;
869 struct collection_list
871 unsigned char regs_mask
[32]; /* room for up to 256 regs */
874 struct memrange
*list
;
875 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
877 struct agent_expr
**aexpr_list
;
879 /* True is the user requested a collection of "$_sdata", "static
883 tracepoint_list
, stepping_list
;
885 /* MEMRANGE functions: */
887 static int memrange_cmp (const void *, const void *);
889 /* Compare memranges for qsort. */
891 memrange_cmp (const void *va
, const void *vb
)
893 const struct memrange
*a
= va
, *b
= vb
;
895 if (a
->type
< b
->type
)
897 if (a
->type
> b
->type
)
899 if (a
->type
== memrange_absolute
)
901 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
903 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
908 if (a
->start
< b
->start
)
910 if (a
->start
> b
->start
)
916 /* Sort the memrange list using qsort, and merge adjacent memranges. */
918 memrange_sortmerge (struct collection_list
*memranges
)
922 qsort (memranges
->list
, memranges
->next_memrange
,
923 sizeof (struct memrange
), memrange_cmp
);
924 if (memranges
->next_memrange
> 0)
926 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
928 /* If memrange b overlaps or is adjacent to memrange a,
930 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
931 && memranges
->list
[b
].start
<= memranges
->list
[a
].end
)
933 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
934 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
935 continue; /* next b, same a */
939 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
940 sizeof (struct memrange
));
942 memranges
->next_memrange
= a
+ 1;
946 /* Add a register to a collection list. */
948 add_register (struct collection_list
*collection
, unsigned int regno
)
951 printf_filtered ("collect register %d\n", regno
);
952 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
953 error (_("Internal: register number %d too large for tracepoint"),
955 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
958 /* Add a memrange to a collection list. */
960 add_memrange (struct collection_list
*memranges
,
961 int type
, bfd_signed_vma base
,
966 printf_filtered ("(%d,", type
);
968 printf_filtered (",%ld)\n", len
);
971 /* type: memrange_absolute == memory, other n == basereg */
972 memranges
->list
[memranges
->next_memrange
].type
= type
;
973 /* base: addr if memory, offset if reg relative. */
974 memranges
->list
[memranges
->next_memrange
].start
= base
;
975 /* len: we actually save end (base + len) for convenience */
976 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
977 memranges
->next_memrange
++;
978 if (memranges
->next_memrange
>= memranges
->listsize
)
980 memranges
->listsize
*= 2;
981 memranges
->list
= xrealloc (memranges
->list
,
982 memranges
->listsize
);
985 if (type
!= memrange_absolute
) /* Better collect the base register! */
986 add_register (memranges
, type
);
989 /* Add a symbol to a collection list. */
991 collect_symbol (struct collection_list
*collect
,
993 struct gdbarch
*gdbarch
,
994 long frame_regno
, long frame_offset
,
1000 bfd_signed_vma offset
;
1001 int treat_as_expr
= 0;
1003 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
1004 switch (SYMBOL_CLASS (sym
))
1007 printf_filtered ("%s: don't know symbol class %d\n",
1008 SYMBOL_PRINT_NAME (sym
),
1009 SYMBOL_CLASS (sym
));
1012 printf_filtered ("constant %s (value %s) will not be collected.\n",
1013 SYMBOL_PRINT_NAME (sym
), plongest (SYMBOL_VALUE (sym
)));
1016 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1021 sprintf_vma (tmp
, offset
);
1022 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1023 SYMBOL_PRINT_NAME (sym
), len
,
1026 /* A struct may be a C++ class with static fields, go to general
1027 expression handling. */
1028 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1031 add_memrange (collect
, memrange_absolute
, offset
, len
);
1034 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1036 printf_filtered ("LOC_REG[parm] %s: ",
1037 SYMBOL_PRINT_NAME (sym
));
1038 add_register (collect
, reg
);
1039 /* Check for doubles stored in two registers. */
1040 /* FIXME: how about larger types stored in 3 or more regs? */
1041 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
1042 len
> register_size (gdbarch
, reg
))
1043 add_register (collect
, reg
+ 1);
1046 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1047 printf_filtered (" (will not collect %s)\n",
1048 SYMBOL_PRINT_NAME (sym
));
1052 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1055 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1056 SYMBOL_PRINT_NAME (sym
), len
);
1057 printf_vma (offset
);
1058 printf_filtered (" from frame ptr reg %d\n", reg
);
1060 add_memrange (collect
, reg
, offset
, len
);
1062 case LOC_REGPARM_ADDR
:
1063 reg
= SYMBOL_VALUE (sym
);
1067 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1068 SYMBOL_PRINT_NAME (sym
), len
);
1069 printf_vma (offset
);
1070 printf_filtered (" from reg %d\n", reg
);
1072 add_memrange (collect
, reg
, offset
, len
);
1076 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1079 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1080 SYMBOL_PRINT_NAME (sym
), len
);
1081 printf_vma (offset
);
1082 printf_filtered (" from frame ptr reg %d\n", reg
);
1084 add_memrange (collect
, reg
, offset
, len
);
1087 case LOC_UNRESOLVED
:
1091 case LOC_OPTIMIZED_OUT
:
1092 printf_filtered ("%s has been optimized out of existence.\n",
1093 SYMBOL_PRINT_NAME (sym
));
1101 /* Expressions are the most general case. */
1104 struct agent_expr
*aexpr
;
1105 struct cleanup
*old_chain1
= NULL
;
1107 aexpr
= gen_trace_for_var (scope
, gdbarch
, sym
, trace_string
);
1109 /* It can happen that the symbol is recorded as a computed
1110 location, but it's been optimized away and doesn't actually
1111 have a location expression. */
1114 printf_filtered ("%s has been optimized out of existence.\n",
1115 SYMBOL_PRINT_NAME (sym
));
1119 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1123 report_agent_reqs_errors (aexpr
);
1125 discard_cleanups (old_chain1
);
1126 add_aexpr (collect
, aexpr
);
1128 /* Take care of the registers. */
1129 if (aexpr
->reg_mask_len
> 0)
1133 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1135 QUIT
; /* Allow user to bail out with ^C. */
1136 if (aexpr
->reg_mask
[ndx1
] != 0)
1138 /* Assume chars have 8 bits. */
1139 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1140 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1141 /* It's used -- record it. */
1142 add_register (collect
, ndx1
* 8 + ndx2
);
1149 /* Data to be passed around in the calls to the locals and args
1152 struct add_local_symbols_data
1154 struct collection_list
*collect
;
1155 struct gdbarch
*gdbarch
;
1163 /* The callback for the locals and args iterators. */
1166 do_collect_symbol (const char *print_name
,
1170 struct add_local_symbols_data
*p
= cb_data
;
1172 collect_symbol (p
->collect
, sym
, p
->gdbarch
, p
->frame_regno
,
1173 p
->frame_offset
, p
->pc
, p
->trace_string
);
1177 /* Add all locals (or args) symbols to collection list. */
1179 add_local_symbols (struct collection_list
*collect
,
1180 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1181 long frame_regno
, long frame_offset
, int type
,
1184 struct block
*block
;
1185 struct add_local_symbols_data cb_data
;
1187 cb_data
.collect
= collect
;
1188 cb_data
.gdbarch
= gdbarch
;
1190 cb_data
.frame_regno
= frame_regno
;
1191 cb_data
.frame_offset
= frame_offset
;
1193 cb_data
.trace_string
= trace_string
;
1197 block
= block_for_pc (pc
);
1200 warning (_("Can't collect locals; "
1201 "no symbol table info available.\n"));
1205 iterate_over_block_local_vars (block
, do_collect_symbol
, &cb_data
);
1206 if (cb_data
.count
== 0)
1207 warning (_("No locals found in scope."));
1211 pc
= get_pc_function_start (pc
);
1212 block
= block_for_pc (pc
);
1215 warning (_("Can't collect args; no symbol table info available."));
1219 iterate_over_block_arg_vars (block
, do_collect_symbol
, &cb_data
);
1220 if (cb_data
.count
== 0)
1221 warning (_("No args found in scope."));
1226 add_static_trace_data (struct collection_list
*collection
)
1229 printf_filtered ("collect static trace data\n");
1230 collection
->strace_data
= 1;
1233 /* worker function */
1235 clear_collection_list (struct collection_list
*list
)
1239 list
->next_memrange
= 0;
1240 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1242 free_agent_expr (list
->aexpr_list
[ndx
]);
1243 list
->aexpr_list
[ndx
] = NULL
;
1245 list
->next_aexpr_elt
= 0;
1246 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1247 list
->strace_data
= 0;
1250 /* Reduce a collection list to string form (for gdb protocol). */
1252 stringify_collection_list (struct collection_list
*list
, char *string
)
1254 char temp_buf
[2048];
1258 char *(*str_list
)[];
1262 count
= 1 + 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1263 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1265 if (list
->strace_data
)
1268 printf_filtered ("\nCollecting static trace data\n");
1271 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1275 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1276 if (list
->regs_mask
[i
] != 0) /* Skip leading zeroes in regs_mask. */
1278 if (list
->regs_mask
[i
] != 0) /* Prepare to send regs_mask to the stub. */
1281 printf_filtered ("\nCollecting registers (mask): 0x");
1286 QUIT
; /* Allow user to bail out with ^C. */
1288 printf_filtered ("%02X", list
->regs_mask
[i
]);
1289 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1292 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1296 printf_filtered ("\n");
1297 if (list
->next_memrange
> 0 && info_verbose
)
1298 printf_filtered ("Collecting memranges: \n");
1299 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1301 QUIT
; /* Allow user to bail out with ^C. */
1302 sprintf_vma (tmp2
, list
->list
[i
].start
);
1305 printf_filtered ("(%d, %s, %ld)\n",
1308 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1310 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1312 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1319 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
1321 /* The "%X" conversion specifier expects an unsigned argument,
1322 so passing -1 (memrange_absolute) to it directly gives you
1323 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1325 if (list
->list
[i
].type
== memrange_absolute
)
1326 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1328 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
1331 count
+= strlen (end
);
1332 end
= temp_buf
+ count
;
1335 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1337 QUIT
; /* Allow user to bail out with ^C. */
1338 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1340 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1345 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1346 end
+= 10; /* 'X' + 8 hex digits + ',' */
1349 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1350 end
, list
->aexpr_list
[i
]->len
);
1351 count
+= 2 * list
->aexpr_list
[i
]->len
;
1356 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1361 (*str_list
)[ndx
] = NULL
;
1374 encode_actions_1 (struct command_line
*action
,
1375 struct breakpoint
*t
,
1376 struct bp_location
*tloc
,
1378 LONGEST frame_offset
,
1379 struct collection_list
*collect
,
1380 struct collection_list
*stepping_list
)
1382 const char *action_exp
;
1383 struct expression
*exp
= NULL
;
1385 struct value
*tempval
;
1386 struct cmd_list_element
*cmd
;
1387 struct agent_expr
*aexpr
;
1389 for (; action
; action
= action
->next
)
1391 QUIT
; /* Allow user to bail out with ^C. */
1392 action_exp
= action
->line
;
1393 action_exp
= skip_spaces_const (action_exp
);
1395 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1397 error (_("Bad action list item: %s"), action_exp
);
1399 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1401 int trace_string
= 0;
1403 if (*action_exp
== '/')
1404 action_exp
= decode_agent_options (action_exp
, &trace_string
);
1407 { /* Repeat over a comma-separated list. */
1408 QUIT
; /* Allow user to bail out with ^C. */
1409 action_exp
= skip_spaces_const (action_exp
);
1411 if (0 == strncasecmp ("$reg", action_exp
, 4))
1413 for (i
= 0; i
< gdbarch_num_regs (tloc
->gdbarch
); i
++)
1414 add_register (collect
, i
);
1415 action_exp
= strchr (action_exp
, ','); /* more? */
1417 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1419 add_local_symbols (collect
,
1426 action_exp
= strchr (action_exp
, ','); /* more? */
1428 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1430 add_local_symbols (collect
,
1437 action_exp
= strchr (action_exp
, ','); /* more? */
1439 else if (0 == strncasecmp ("$_ret", action_exp
, 5))
1441 struct cleanup
*old_chain1
= NULL
;
1443 aexpr
= gen_trace_for_return_address (tloc
->address
,
1447 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1450 report_agent_reqs_errors (aexpr
);
1452 discard_cleanups (old_chain1
);
1453 add_aexpr (collect
, aexpr
);
1455 /* take care of the registers */
1456 if (aexpr
->reg_mask_len
> 0)
1460 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1462 QUIT
; /* allow user to bail out with ^C */
1463 if (aexpr
->reg_mask
[ndx1
] != 0)
1465 /* assume chars have 8 bits */
1466 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1467 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1468 /* it's used -- record it */
1469 add_register (collect
,
1475 action_exp
= strchr (action_exp
, ','); /* more? */
1477 else if (0 == strncasecmp ("$_sdata", action_exp
, 7))
1479 add_static_trace_data (collect
);
1480 action_exp
= strchr (action_exp
, ','); /* more? */
1485 struct cleanup
*old_chain
= NULL
;
1486 struct cleanup
*old_chain1
= NULL
;
1488 exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1489 block_for_pc (tloc
->address
), 1);
1490 old_chain
= make_cleanup (free_current_contents
, &exp
);
1492 switch (exp
->elts
[0].opcode
)
1496 const char *name
= &exp
->elts
[2].string
;
1498 i
= user_reg_map_name_to_regnum (tloc
->gdbarch
,
1499 name
, strlen (name
));
1501 internal_error (__FILE__
, __LINE__
,
1502 _("Register $%s not available"),
1505 printf_filtered ("OP_REGISTER: ");
1506 add_register (collect
, i
);
1511 /* Safe because we know it's a simple expression. */
1512 tempval
= evaluate_expression (exp
);
1513 addr
= value_address (tempval
);
1514 /* Initialize the TYPE_LENGTH if it is a typedef. */
1515 check_typedef (exp
->elts
[1].type
);
1516 add_memrange (collect
, memrange_absolute
, addr
,
1517 TYPE_LENGTH (exp
->elts
[1].type
));
1521 collect_symbol (collect
,
1522 exp
->elts
[2].symbol
,
1530 default: /* Full-fledged expression. */
1531 aexpr
= gen_trace_for_expr (tloc
->address
, exp
,
1534 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1538 report_agent_reqs_errors (aexpr
);
1540 discard_cleanups (old_chain1
);
1541 add_aexpr (collect
, aexpr
);
1543 /* Take care of the registers. */
1544 if (aexpr
->reg_mask_len
> 0)
1549 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1551 QUIT
; /* Allow user to bail out with ^C. */
1552 if (aexpr
->reg_mask
[ndx1
] != 0)
1554 /* Assume chars have 8 bits. */
1555 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1556 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1557 /* It's used -- record it. */
1558 add_register (collect
,
1565 do_cleanups (old_chain
);
1568 while (action_exp
&& *action_exp
++ == ',');
1570 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1573 { /* Repeat over a comma-separated list. */
1574 QUIT
; /* Allow user to bail out with ^C. */
1575 action_exp
= skip_spaces_const (action_exp
);
1578 struct cleanup
*old_chain
= NULL
;
1579 struct cleanup
*old_chain1
= NULL
;
1581 exp
= parse_exp_1 (&action_exp
, tloc
->address
,
1582 block_for_pc (tloc
->address
), 1);
1583 old_chain
= make_cleanup (free_current_contents
, &exp
);
1585 aexpr
= gen_eval_for_expr (tloc
->address
, exp
);
1586 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1589 report_agent_reqs_errors (aexpr
);
1591 discard_cleanups (old_chain1
);
1592 /* Even though we're not officially collecting, add
1593 to the collect list anyway. */
1594 add_aexpr (collect
, aexpr
);
1596 do_cleanups (old_chain
);
1599 while (action_exp
&& *action_exp
++ == ',');
1601 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1603 /* We check against nested while-stepping when setting
1604 breakpoint action, so no way to run into nested
1606 gdb_assert (stepping_list
);
1608 encode_actions_1 (action
->body_list
[0], t
, tloc
, frame_reg
,
1609 frame_offset
, stepping_list
, NULL
);
1612 error (_("Invalid tracepoint command '%s'"), action
->line
);
1616 /* Render all actions into gdb protocol. */
1619 encode_actions (struct breakpoint
*t
, struct bp_location
*tloc
,
1620 char ***tdp_actions
, char ***stepping_actions
)
1622 static char tdp_buff
[2048], step_buff
[2048];
1623 char *default_collect_line
= NULL
;
1624 struct command_line
*actions
;
1625 struct command_line
*default_collect_action
= NULL
;
1627 LONGEST frame_offset
;
1628 struct cleanup
*back_to
;
1630 back_to
= make_cleanup (null_cleanup
, NULL
);
1632 clear_collection_list (&tracepoint_list
);
1633 clear_collection_list (&stepping_list
);
1635 *tdp_actions
= NULL
;
1636 *stepping_actions
= NULL
;
1638 gdbarch_virtual_frame_pointer (tloc
->gdbarch
,
1639 tloc
->address
, &frame_reg
, &frame_offset
);
1641 actions
= breakpoint_commands (t
);
1643 /* If there are default expressions to collect, make up a collect
1644 action and prepend to the action list to encode. Note that since
1645 validation is per-tracepoint (local var "xyz" might be valid for
1646 one tracepoint and not another, etc), we make up the action on
1647 the fly, and don't cache it. */
1648 if (*default_collect
)
1650 default_collect_line
= xstrprintf ("collect %s", default_collect
);
1651 make_cleanup (xfree
, default_collect_line
);
1653 validate_actionline (default_collect_line
, t
);
1655 default_collect_action
= xmalloc (sizeof (struct command_line
));
1656 make_cleanup (xfree
, default_collect_action
);
1657 default_collect_action
->next
= actions
;
1658 default_collect_action
->line
= default_collect_line
;
1659 actions
= default_collect_action
;
1661 encode_actions_1 (actions
, t
, tloc
, frame_reg
, frame_offset
,
1662 &tracepoint_list
, &stepping_list
);
1664 memrange_sortmerge (&tracepoint_list
);
1665 memrange_sortmerge (&stepping_list
);
1667 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1669 *stepping_actions
= stringify_collection_list (&stepping_list
,
1672 do_cleanups (back_to
);
1676 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1678 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1680 collect
->aexpr_list
=
1681 xrealloc (collect
->aexpr_list
,
1682 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1683 collect
->aexpr_listsize
*= 2;
1685 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1686 collect
->next_aexpr_elt
++;
1690 process_tracepoint_on_disconnect (void)
1692 VEC(breakpoint_p
) *tp_vec
= NULL
;
1694 struct breakpoint
*b
;
1695 int has_pending_p
= 0;
1697 /* Check whether we still have pending tracepoint. If we have, warn the
1698 user that pending tracepoint will no longer work. */
1699 tp_vec
= all_tracepoints ();
1700 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1709 struct bp_location
*loc1
;
1711 for (loc1
= b
->loc
; loc1
; loc1
= loc1
->next
)
1713 if (loc1
->shlib_disabled
)
1724 VEC_free (breakpoint_p
, tp_vec
);
1727 warning (_("Pending tracepoints will not be resolved while"
1728 " GDB is disconnected\n"));
1733 start_tracing (char *notes
)
1735 VEC(breakpoint_p
) *tp_vec
= NULL
;
1737 struct breakpoint
*b
;
1738 struct trace_state_variable
*tsv
;
1739 int any_enabled
= 0, num_to_download
= 0;
1742 tp_vec
= all_tracepoints ();
1744 /* No point in tracing without any tracepoints... */
1745 if (VEC_length (breakpoint_p
, tp_vec
) == 0)
1747 VEC_free (breakpoint_p
, tp_vec
);
1748 error (_("No tracepoints defined, not starting trace"));
1751 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1753 struct tracepoint
*t
= (struct tracepoint
*) b
;
1754 struct bp_location
*loc
;
1756 if (b
->enable_state
== bp_enabled
)
1759 if ((b
->type
== bp_fast_tracepoint
1760 ? may_insert_fast_tracepoints
1761 : may_insert_tracepoints
))
1764 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1765 (b
->type
== bp_fast_tracepoint
? "fast " : ""), b
->number
);
1770 if (target_supports_enable_disable_tracepoint ())
1771 warning (_("No tracepoints enabled"));
1774 /* No point in tracing with only disabled tracepoints that
1775 cannot be re-enabled. */
1776 VEC_free (breakpoint_p
, tp_vec
);
1777 error (_("No tracepoints enabled, not starting trace"));
1781 if (num_to_download
<= 0)
1783 VEC_free (breakpoint_p
, tp_vec
);
1784 error (_("No tracepoints that may be downloaded, not starting trace"));
1787 target_trace_init ();
1789 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
1791 struct tracepoint
*t
= (struct tracepoint
*) b
;
1792 struct bp_location
*loc
;
1793 int bp_location_downloaded
= 0;
1795 /* Clear `inserted' flag. */
1796 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1799 if ((b
->type
== bp_fast_tracepoint
1800 ? !may_insert_fast_tracepoints
1801 : !may_insert_tracepoints
))
1804 t
->number_on_target
= 0;
1806 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1808 /* Since tracepoint locations are never duplicated, `inserted'
1809 flag should be zero. */
1810 gdb_assert (!loc
->inserted
);
1812 target_download_tracepoint (loc
);
1815 bp_location_downloaded
= 1;
1818 t
->number_on_target
= b
->number
;
1820 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
1821 if (loc
->probe
!= NULL
)
1822 loc
->probe
->pops
->set_semaphore (loc
->probe
, loc
->gdbarch
);
1824 if (bp_location_downloaded
)
1825 observer_notify_breakpoint_modified (b
);
1827 VEC_free (breakpoint_p
, tp_vec
);
1829 /* Send down all the trace state variables too. */
1830 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1832 target_download_trace_state_variable (tsv
);
1835 /* Tell target to treat text-like sections as transparent. */
1836 target_trace_set_readonly_regions ();
1837 /* Set some mode flags. */
1838 target_set_disconnected_tracing (disconnected_tracing
);
1839 target_set_circular_trace_buffer (circular_trace_buffer
);
1840 target_set_trace_buffer_size (trace_buffer_size
);
1843 notes
= trace_notes
;
1844 ret
= target_set_trace_notes (trace_user
, notes
, NULL
);
1846 if (!ret
&& (trace_user
|| notes
))
1847 warning (_("Target does not support trace user/notes, info ignored"));
1849 /* Now insert traps and begin collecting data. */
1850 target_trace_start ();
1852 /* Reset our local state. */
1853 set_traceframe_num (-1);
1854 set_tracepoint_num (-1);
1855 set_traceframe_context (NULL
);
1856 current_trace_status()->running
= 1;
1857 clear_traceframe_info ();
1860 /* The tstart command requests the target to start a new trace run.
1861 The command passes any arguments it has to the target verbatim, as
1862 an optional "trace note". This is useful as for instance a warning
1863 to other users if the trace runs disconnected, and you don't want
1864 anybody else messing with the target. */
1867 trace_start_command (char *args
, int from_tty
)
1869 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1871 if (current_trace_status ()->running
)
1874 && !query (_("A trace is running already. Start a new run? ")))
1875 error (_("New trace run not started."));
1878 start_tracing (args
);
1881 /* The tstop command stops the tracing run. The command passes any
1882 supplied arguments to the target verbatim as a "stop note"; if the
1883 target supports trace notes, then it will be reported back as part
1884 of the trace run's status. */
1887 trace_stop_command (char *args
, int from_tty
)
1889 if (!current_trace_status ()->running
)
1890 error (_("Trace is not running."));
1892 stop_tracing (args
);
1896 stop_tracing (char *note
)
1899 VEC(breakpoint_p
) *tp_vec
= NULL
;
1901 struct breakpoint
*t
;
1903 target_trace_stop ();
1905 tp_vec
= all_tracepoints ();
1906 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1908 struct bp_location
*loc
;
1910 if ((t
->type
== bp_fast_tracepoint
1911 ? !may_insert_fast_tracepoints
1912 : !may_insert_tracepoints
))
1915 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
1917 /* GDB can be totally absent in some disconnected trace scenarios,
1918 but we don't really care if this semaphore goes out of sync.
1919 That's why we are decrementing it here, but not taking care
1921 if (loc
->probe
!= NULL
)
1922 loc
->probe
->pops
->clear_semaphore (loc
->probe
, loc
->gdbarch
);
1926 VEC_free (breakpoint_p
, tp_vec
);
1929 note
= trace_stop_notes
;
1930 ret
= target_set_trace_notes (NULL
, NULL
, note
);
1933 warning (_("Target does not support trace notes, note ignored"));
1935 /* Should change in response to reply? */
1936 current_trace_status ()->running
= 0;
1939 /* tstatus command */
1941 trace_status_command (char *args
, int from_tty
)
1943 struct trace_status
*ts
= current_trace_status ();
1945 VEC(breakpoint_p
) *tp_vec
= NULL
;
1946 struct breakpoint
*t
;
1948 status
= target_get_trace_status (ts
);
1952 if (ts
->filename
!= NULL
)
1953 printf_filtered (_("Using a trace file.\n"));
1956 printf_filtered (_("Trace can not be run on this target.\n"));
1961 if (!ts
->running_known
)
1963 printf_filtered (_("Run/stop status is unknown.\n"));
1965 else if (ts
->running
)
1967 printf_filtered (_("Trace is running on the target.\n"));
1971 switch (ts
->stop_reason
)
1973 case trace_never_run
:
1974 printf_filtered (_("No trace has been run on the target.\n"));
1978 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1981 printf_filtered (_("Trace stopped by a tstop command.\n"));
1983 case trace_buffer_full
:
1984 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1986 case trace_disconnected
:
1987 printf_filtered (_("Trace stopped because of disconnection.\n"));
1989 case tracepoint_passcount
:
1990 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1991 ts
->stopping_tracepoint
);
1993 case tracepoint_error
:
1994 if (ts
->stopping_tracepoint
)
1995 printf_filtered (_("Trace stopped by an "
1996 "error (%s, tracepoint %d).\n"),
1997 ts
->stop_desc
, ts
->stopping_tracepoint
);
1999 printf_filtered (_("Trace stopped by an error (%s).\n"),
2002 case trace_stop_reason_unknown
:
2003 printf_filtered (_("Trace stopped for an unknown reason.\n"));
2006 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
2012 if (ts
->traceframes_created
>= 0
2013 && ts
->traceframe_count
!= ts
->traceframes_created
)
2015 printf_filtered (_("Buffer contains %d trace "
2016 "frames (of %d created total).\n"),
2017 ts
->traceframe_count
, ts
->traceframes_created
);
2019 else if (ts
->traceframe_count
>= 0)
2021 printf_filtered (_("Collected %d trace frames.\n"),
2022 ts
->traceframe_count
);
2025 if (ts
->buffer_free
>= 0)
2027 if (ts
->buffer_size
>= 0)
2029 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
2030 ts
->buffer_free
, ts
->buffer_size
);
2031 if (ts
->buffer_size
> 0)
2032 printf_filtered (_(" (%d%% full)"),
2033 ((int) ((((long long) (ts
->buffer_size
2034 - ts
->buffer_free
)) * 100)
2035 / ts
->buffer_size
)));
2036 printf_filtered (_(".\n"));
2039 printf_filtered (_("Trace buffer has %d bytes free.\n"),
2043 if (ts
->disconnected_tracing
)
2044 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
2046 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
2048 if (ts
->circular_buffer
)
2049 printf_filtered (_("Trace buffer is circular.\n"));
2051 if (ts
->user_name
&& strlen (ts
->user_name
) > 0)
2052 printf_filtered (_("Trace user is %s.\n"), ts
->user_name
);
2054 if (ts
->notes
&& strlen (ts
->notes
) > 0)
2055 printf_filtered (_("Trace notes: %s.\n"), ts
->notes
);
2057 /* Now report on what we're doing with tfind. */
2058 if (traceframe_number
>= 0)
2059 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
2060 traceframe_number
, tracepoint_number
);
2062 printf_filtered (_("Not looking at any trace frame.\n"));
2064 /* Report start/stop times if supplied. */
2069 LONGEST run_time
= ts
->stop_time
- ts
->start_time
;
2071 /* Reporting a run time is more readable than two long numbers. */
2072 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
2073 (long int) ts
->start_time
/ 1000000,
2074 (long int) ts
->start_time
% 1000000,
2075 (long int) run_time
/ 1000000,
2076 (long int) run_time
% 1000000);
2079 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
2080 (long int) ts
->start_time
/ 1000000,
2081 (long int) ts
->start_time
% 1000000);
2083 else if (ts
->stop_time
)
2084 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
2085 (long int) ts
->stop_time
/ 1000000,
2086 (long int) ts
->stop_time
% 1000000);
2088 /* Now report any per-tracepoint status available. */
2089 tp_vec
= all_tracepoints ();
2091 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
2092 target_get_tracepoint_status (t
, NULL
);
2094 VEC_free (breakpoint_p
, tp_vec
);
2097 /* Report the trace status to uiout, in a way suitable for MI, and not
2098 suitable for CLI. If ON_STOP is true, suppress a few fields that
2099 are not meaningful in the -trace-stop response.
2101 The implementation is essentially parallel to trace_status_command, but
2102 merging them will result in unreadable code. */
2104 trace_status_mi (int on_stop
)
2106 struct ui_out
*uiout
= current_uiout
;
2107 struct trace_status
*ts
= current_trace_status ();
2110 status
= target_get_trace_status (ts
);
2112 if (status
== -1 && ts
->filename
== NULL
)
2114 ui_out_field_string (uiout
, "supported", "0");
2118 if (ts
->filename
!= NULL
)
2119 ui_out_field_string (uiout
, "supported", "file");
2121 ui_out_field_string (uiout
, "supported", "1");
2123 if (ts
->filename
!= NULL
)
2124 ui_out_field_string (uiout
, "trace-file", ts
->filename
);
2126 gdb_assert (ts
->running_known
);
2130 ui_out_field_string (uiout
, "running", "1");
2132 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
2133 Given that the frontend gets the status either on -trace-stop, or from
2134 -trace-status after re-connection, it does not seem like this
2135 information is necessary for anything. It is not necessary for either
2136 figuring the vital state of the target nor for navigation of trace
2137 frames. If the frontend wants to show the current state is some
2138 configure dialog, it can request the value when such dialog is
2139 invoked by the user. */
2143 char *stop_reason
= NULL
;
2144 int stopping_tracepoint
= -1;
2147 ui_out_field_string (uiout
, "running", "0");
2149 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
2151 switch (ts
->stop_reason
)
2154 stop_reason
= "request";
2156 case trace_buffer_full
:
2157 stop_reason
= "overflow";
2159 case trace_disconnected
:
2160 stop_reason
= "disconnection";
2162 case tracepoint_passcount
:
2163 stop_reason
= "passcount";
2164 stopping_tracepoint
= ts
->stopping_tracepoint
;
2166 case tracepoint_error
:
2167 stop_reason
= "error";
2168 stopping_tracepoint
= ts
->stopping_tracepoint
;
2174 ui_out_field_string (uiout
, "stop-reason", stop_reason
);
2175 if (stopping_tracepoint
!= -1)
2176 ui_out_field_int (uiout
, "stopping-tracepoint",
2177 stopping_tracepoint
);
2178 if (ts
->stop_reason
== tracepoint_error
)
2179 ui_out_field_string (uiout
, "error-description",
2185 if (ts
->traceframe_count
!= -1)
2186 ui_out_field_int (uiout
, "frames", ts
->traceframe_count
);
2187 if (ts
->traceframes_created
!= -1)
2188 ui_out_field_int (uiout
, "frames-created", ts
->traceframes_created
);
2189 if (ts
->buffer_size
!= -1)
2190 ui_out_field_int (uiout
, "buffer-size", ts
->buffer_size
);
2191 if (ts
->buffer_free
!= -1)
2192 ui_out_field_int (uiout
, "buffer-free", ts
->buffer_free
);
2194 ui_out_field_int (uiout
, "disconnected", ts
->disconnected_tracing
);
2195 ui_out_field_int (uiout
, "circular", ts
->circular_buffer
);
2197 ui_out_field_string (uiout
, "user-name", ts
->user_name
);
2198 ui_out_field_string (uiout
, "notes", ts
->notes
);
2203 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2204 (long int) ts
->start_time
/ 1000000,
2205 (long int) ts
->start_time
% 1000000);
2206 ui_out_field_string (uiout
, "start-time", buf
);
2207 xsnprintf (buf
, sizeof buf
, "%ld.%06ld",
2208 (long int) ts
->stop_time
/ 1000000,
2209 (long int) ts
->stop_time
% 1000000);
2210 ui_out_field_string (uiout
, "stop-time", buf
);
2214 /* This function handles the details of what to do about an ongoing
2215 tracing run if the user has asked to detach or otherwise disconnect
2218 disconnect_tracing (int from_tty
)
2220 /* It can happen that the target that was tracing went away on its
2221 own, and we didn't notice. Get a status update, and if the
2222 current target doesn't even do tracing, then assume it's not
2224 if (target_get_trace_status (current_trace_status ()) < 0)
2225 current_trace_status ()->running
= 0;
2227 /* If running interactively, give the user the option to cancel and
2228 then decide what to do differently with the run. Scripts are
2229 just going to disconnect and let the target deal with it,
2230 according to how it's been instructed previously via
2231 disconnected-tracing. */
2232 if (current_trace_status ()->running
&& from_tty
)
2234 process_tracepoint_on_disconnect ();
2236 if (current_trace_status ()->disconnected_tracing
)
2238 if (!query (_("Trace is running and will "
2239 "continue after detach; detach anyway? ")))
2240 error (_("Not confirmed."));
2244 if (!query (_("Trace is running but will "
2245 "stop on detach; detach anyway? ")))
2246 error (_("Not confirmed."));
2250 /* Also we want to be out of tfind mode, otherwise things can get
2251 confusing upon reconnection. Just use these calls instead of
2252 full tfind_1 behavior because we're in the middle of detaching,
2253 and there's no point to updating current stack frame etc. */
2254 set_current_traceframe (-1);
2255 set_tracepoint_num (-1);
2256 set_traceframe_context (NULL
);
2259 /* Worker function for the various flavors of the tfind command. */
2261 tfind_1 (enum trace_find_type type
, int num
,
2262 ULONGEST addr1
, ULONGEST addr2
,
2265 int target_frameno
= -1, target_tracept
= -1;
2266 struct frame_id old_frame_id
= null_frame_id
;
2267 struct tracepoint
*tp
;
2268 struct ui_out
*uiout
= current_uiout
;
2270 /* Only try to get the current stack frame if we have a chance of
2271 succeeding. In particular, if we're trying to get a first trace
2272 frame while all threads are running, it's not going to succeed,
2273 so leave it with a default value and let the frame comparison
2274 below (correctly) decide to print out the source location of the
2276 if (!(type
== tfind_number
&& num
== -1)
2277 && (has_stack_frames () || traceframe_number
>= 0))
2278 old_frame_id
= get_frame_id (get_current_frame ());
2280 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
2283 if (type
== tfind_number
2285 && target_frameno
== -1)
2287 /* We told the target to get out of tfind mode, and it did. */
2289 else if (target_frameno
== -1)
2291 /* A request for a non-existent trace frame has failed.
2292 Our response will be different, depending on FROM_TTY:
2294 If FROM_TTY is true, meaning that this command was
2295 typed interactively by the user, then give an error
2296 and DO NOT change the state of traceframe_number etc.
2298 However if FROM_TTY is false, meaning that we're either
2299 in a script, a loop, or a user-defined command, then
2300 DON'T give an error, but DO change the state of
2301 traceframe_number etc. to invalid.
2303 The rationalle is that if you typed the command, you
2304 might just have committed a typo or something, and you'd
2305 like to NOT lose your current debugging state. However
2306 if you're in a user-defined command or especially in a
2307 loop, then you need a way to detect that the command
2308 failed WITHOUT aborting. This allows you to write
2309 scripts that search thru the trace buffer until the end,
2310 and then continue on to do something else. */
2313 error (_("Target failed to find requested trace frame."));
2317 printf_filtered ("End of trace buffer.\n");
2318 #if 0 /* dubious now? */
2319 /* The following will not recurse, since it's
2321 trace_find_command ("-1", from_tty
);
2326 tp
= get_tracepoint_by_number_on_target (target_tracept
);
2328 reinit_frame_cache ();
2329 target_dcache_invalidate ();
2331 set_tracepoint_num (tp
? tp
->base
.number
: target_tracept
);
2333 if (target_frameno
!= get_traceframe_number ())
2334 observer_notify_traceframe_changed (target_frameno
, tracepoint_number
);
2336 set_current_traceframe (target_frameno
);
2338 if (target_frameno
== -1)
2339 set_traceframe_context (NULL
);
2341 set_traceframe_context (get_current_frame ());
2343 if (traceframe_number
>= 0)
2345 /* Use different branches for MI and CLI to make CLI messages
2347 if (ui_out_is_mi_like_p (uiout
))
2349 ui_out_field_string (uiout
, "found", "1");
2350 ui_out_field_int (uiout
, "tracepoint", tracepoint_number
);
2351 ui_out_field_int (uiout
, "traceframe", traceframe_number
);
2355 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2356 traceframe_number
, tracepoint_number
);
2361 if (ui_out_is_mi_like_p (uiout
))
2362 ui_out_field_string (uiout
, "found", "0");
2363 else if (type
== tfind_number
&& num
== -1)
2364 printf_unfiltered (_("No longer looking at any trace frame\n"));
2365 else /* This case may never occur, check. */
2366 printf_unfiltered (_("No trace frame found\n"));
2369 /* If we're in nonstop mode and getting out of looking at trace
2370 frames, there won't be any current frame to go back to and
2373 && (has_stack_frames () || traceframe_number
>= 0))
2375 enum print_what print_what
;
2377 /* NOTE: in imitation of the step command, try to determine
2378 whether we have made a transition from one function to
2379 another. If so, we'll print the "stack frame" (ie. the new
2380 function and it's arguments) -- otherwise we'll just show the
2383 if (frame_id_eq (old_frame_id
,
2384 get_frame_id (get_current_frame ())))
2385 print_what
= SRC_LINE
;
2387 print_what
= SRC_AND_LOC
;
2389 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
2394 /* trace_find_command takes a trace frame number n,
2395 sends "QTFrame:<n>" to the target,
2396 and accepts a reply that may contain several optional pieces
2397 of information: a frame number, a tracepoint number, and an
2398 indication of whether this is a trap frame or a stepping frame.
2400 The minimal response is just "OK" (which indicates that the
2401 target does not give us a frame number or a tracepoint number).
2402 Instead of that, the target may send us a string containing
2404 F<hexnum> (gives the selected frame number)
2405 T<hexnum> (gives the selected tracepoint number)
2410 trace_find_command (char *args
, int from_tty
)
2411 { /* This should only be called with a numeric argument. */
2414 if (current_trace_status ()->running
2415 && current_trace_status ()->filename
== NULL
)
2416 error (_("May not look at trace frames while trace is running."));
2418 if (args
== 0 || *args
== 0)
2419 { /* TFIND with no args means find NEXT trace frame. */
2420 if (traceframe_number
== -1)
2421 frameno
= 0; /* "next" is first one. */
2423 frameno
= traceframe_number
+ 1;
2425 else if (0 == strcmp (args
, "-"))
2427 if (traceframe_number
== -1)
2428 error (_("not debugging trace buffer"));
2429 else if (from_tty
&& traceframe_number
== 0)
2430 error (_("already at start of trace buffer"));
2432 frameno
= traceframe_number
- 1;
2434 /* A hack to work around eval's need for fp to have been collected. */
2435 else if (0 == strcmp (args
, "-1"))
2438 frameno
= parse_and_eval_long (args
);
2441 error (_("invalid input (%d is less than zero)"), frameno
);
2443 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
2448 trace_find_end_command (char *args
, int from_tty
)
2450 trace_find_command ("-1", from_tty
);
2455 trace_find_start_command (char *args
, int from_tty
)
2457 trace_find_command ("0", from_tty
);
2460 /* tfind pc command */
2462 trace_find_pc_command (char *args
, int from_tty
)
2466 if (current_trace_status ()->running
2467 && current_trace_status ()->filename
== NULL
)
2468 error (_("May not look at trace frames while trace is running."));
2470 if (args
== 0 || *args
== 0)
2471 pc
= regcache_read_pc (get_current_regcache ());
2473 pc
= parse_and_eval_address (args
);
2475 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
2478 /* tfind tracepoint command */
2480 trace_find_tracepoint_command (char *args
, int from_tty
)
2483 struct tracepoint
*tp
;
2485 if (current_trace_status ()->running
2486 && current_trace_status ()->filename
== NULL
)
2487 error (_("May not look at trace frames while trace is running."));
2489 if (args
== 0 || *args
== 0)
2491 if (tracepoint_number
== -1)
2492 error (_("No current tracepoint -- please supply an argument."));
2494 tdp
= tracepoint_number
; /* Default is current TDP. */
2497 tdp
= parse_and_eval_long (args
);
2499 /* If we have the tracepoint on hand, use the number that the
2500 target knows about (which may be different if we disconnected
2501 and reconnected). */
2502 tp
= get_tracepoint (tdp
);
2504 tdp
= tp
->number_on_target
;
2506 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
2509 /* TFIND LINE command:
2511 This command will take a sourceline for argument, just like BREAK
2512 or TRACE (ie. anything that "decode_line_1" can handle).
2514 With no argument, this command will find the next trace frame
2515 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2518 trace_find_line_command (char *args
, int from_tty
)
2520 static CORE_ADDR start_pc
, end_pc
;
2521 struct symtabs_and_lines sals
;
2522 struct symtab_and_line sal
;
2523 struct cleanup
*old_chain
;
2525 if (current_trace_status ()->running
2526 && current_trace_status ()->filename
== NULL
)
2527 error (_("May not look at trace frames while trace is running."));
2529 if (args
== 0 || *args
== 0)
2531 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2533 sals
.sals
= (struct symtab_and_line
*)
2534 xmalloc (sizeof (struct symtab_and_line
));
2539 sals
= decode_line_with_current_source (args
, DECODE_LINE_FUNFIRSTLINE
);
2543 old_chain
= make_cleanup (xfree
, sals
.sals
);
2544 if (sal
.symtab
== 0)
2545 error (_("No line number information available."));
2547 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2549 if (start_pc
== end_pc
)
2551 printf_filtered ("Line %d of \"%s\"",
2553 symtab_to_filename_for_display (sal
.symtab
));
2555 printf_filtered (" is at address ");
2556 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2558 printf_filtered (" but contains no code.\n");
2559 sal
= find_pc_line (start_pc
, 0);
2561 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2562 && start_pc
!= end_pc
)
2563 printf_filtered ("Attempting to find line %d instead.\n",
2566 error (_("Cannot find a good line."));
2570 /* Is there any case in which we get here, and have an address
2571 which the user would want to see? If we have debugging
2572 symbols and no line numbers? */
2573 error (_("Line number %d is out of range for \"%s\"."),
2574 sal
.line
, symtab_to_filename_for_display (sal
.symtab
));
2576 /* Find within range of stated line. */
2578 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2580 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2581 do_cleanups (old_chain
);
2584 /* tfind range command */
2586 trace_find_range_command (char *args
, int from_tty
)
2588 static CORE_ADDR start
, stop
;
2591 if (current_trace_status ()->running
2592 && current_trace_status ()->filename
== NULL
)
2593 error (_("May not look at trace frames while trace is running."));
2595 if (args
== 0 || *args
== 0)
2596 { /* XXX FIXME: what should default behavior be? */
2597 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2601 if (0 != (tmp
= strchr (args
, ',')))
2603 *tmp
++ = '\0'; /* Terminate start address. */
2604 tmp
= skip_spaces (tmp
);
2605 start
= parse_and_eval_address (args
);
2606 stop
= parse_and_eval_address (tmp
);
2609 { /* No explicit end address? */
2610 start
= parse_and_eval_address (args
);
2611 stop
= start
+ 1; /* ??? */
2614 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2617 /* tfind outside command */
2619 trace_find_outside_command (char *args
, int from_tty
)
2621 CORE_ADDR start
, stop
;
2624 if (current_trace_status ()->running
2625 && current_trace_status ()->filename
== NULL
)
2626 error (_("May not look at trace frames while trace is running."));
2628 if (args
== 0 || *args
== 0)
2629 { /* XXX FIXME: what should default behavior be? */
2630 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2634 if (0 != (tmp
= strchr (args
, ',')))
2636 *tmp
++ = '\0'; /* Terminate start address. */
2637 tmp
= skip_spaces (tmp
);
2638 start
= parse_and_eval_address (args
);
2639 stop
= parse_and_eval_address (tmp
);
2642 { /* No explicit end address? */
2643 start
= parse_and_eval_address (args
);
2644 stop
= start
+ 1; /* ??? */
2647 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2650 /* info scope command: list the locals for a scope. */
2652 scope_info (char *args
, int from_tty
)
2654 struct symtabs_and_lines sals
;
2656 struct minimal_symbol
*msym
;
2657 struct block
*block
;
2658 const char *symname
;
2659 char *save_args
= args
;
2660 struct block_iterator iter
;
2662 struct gdbarch
*gdbarch
;
2665 if (args
== 0 || *args
== 0)
2666 error (_("requires an argument (function, "
2667 "line or *addr) to define a scope"));
2669 sals
= decode_line_1 (&args
, DECODE_LINE_FUNFIRSTLINE
, NULL
, 0);
2670 if (sals
.nelts
== 0)
2671 return; /* Presumably decode_line_1 has already warned. */
2673 /* Resolve line numbers to PC. */
2674 resolve_sal_pc (&sals
.sals
[0]);
2675 block
= block_for_pc (sals
.sals
[0].pc
);
2679 QUIT
; /* Allow user to bail out with ^C. */
2680 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2682 QUIT
; /* Allow user to bail out with ^C. */
2684 printf_filtered ("Scope for %s:\n", save_args
);
2687 symname
= SYMBOL_PRINT_NAME (sym
);
2688 if (symname
== NULL
|| *symname
== '\0')
2689 continue; /* Probably botched, certainly useless. */
2691 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
2693 printf_filtered ("Symbol %s is ", symname
);
2695 if (SYMBOL_COMPUTED_OPS (sym
) != NULL
)
2696 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
,
2697 BLOCK_START (block
),
2701 switch (SYMBOL_CLASS (sym
))
2704 case LOC_UNDEF
: /* Messed up symbol? */
2705 printf_filtered ("a bogus symbol, class %d.\n",
2706 SYMBOL_CLASS (sym
));
2707 count
--; /* Don't count this one. */
2710 printf_filtered ("a constant with value %s (%s)",
2711 plongest (SYMBOL_VALUE (sym
)),
2712 hex_string (SYMBOL_VALUE (sym
)));
2714 case LOC_CONST_BYTES
:
2715 printf_filtered ("constant bytes: ");
2716 if (SYMBOL_TYPE (sym
))
2717 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2718 fprintf_filtered (gdb_stdout
, " %02x",
2719 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2722 printf_filtered ("in static storage at address ");
2723 printf_filtered ("%s", paddress (gdbarch
,
2724 SYMBOL_VALUE_ADDRESS (sym
)));
2727 /* GDBARCH is the architecture associated with the objfile
2728 the symbol is defined in; the target architecture may be
2729 different, and may provide additional registers. However,
2730 we do not know the target architecture at this point.
2731 We assume the objfile architecture will contain all the
2732 standard registers that occur in debug info in that
2734 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2737 if (SYMBOL_IS_ARGUMENT (sym
))
2738 printf_filtered ("an argument in register $%s",
2739 gdbarch_register_name (gdbarch
, regno
));
2741 printf_filtered ("a local variable in register $%s",
2742 gdbarch_register_name (gdbarch
, regno
));
2745 printf_filtered ("an argument at stack/frame offset %s",
2746 plongest (SYMBOL_VALUE (sym
)));
2749 printf_filtered ("a local variable at frame offset %s",
2750 plongest (SYMBOL_VALUE (sym
)));
2753 printf_filtered ("a reference argument at offset %s",
2754 plongest (SYMBOL_VALUE (sym
)));
2756 case LOC_REGPARM_ADDR
:
2757 /* Note comment at LOC_REGISTER. */
2758 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2760 printf_filtered ("the address of an argument, in register $%s",
2761 gdbarch_register_name (gdbarch
, regno
));
2764 printf_filtered ("a typedef.\n");
2767 printf_filtered ("a label at address ");
2768 printf_filtered ("%s", paddress (gdbarch
,
2769 SYMBOL_VALUE_ADDRESS (sym
)));
2772 printf_filtered ("a function at address ");
2773 printf_filtered ("%s",
2774 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2776 case LOC_UNRESOLVED
:
2777 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2780 printf_filtered ("Unresolved Static");
2783 printf_filtered ("static storage at address ");
2784 printf_filtered ("%s",
2786 SYMBOL_VALUE_ADDRESS (msym
)));
2789 case LOC_OPTIMIZED_OUT
:
2790 printf_filtered ("optimized out.\n");
2793 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2796 if (SYMBOL_TYPE (sym
))
2797 printf_filtered (", length %d.\n",
2798 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2800 if (BLOCK_FUNCTION (block
))
2803 block
= BLOCK_SUPERBLOCK (block
);
2806 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2810 /* Helper for trace_dump_command. Dump the action list starting at
2811 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2812 actions of the body of a while-stepping action. STEPPING_FRAME is
2813 set if the current traceframe was determined to be a while-stepping
2817 trace_dump_actions (struct command_line
*action
,
2818 int stepping_actions
, int stepping_frame
,
2821 const char *action_exp
, *next_comma
;
2823 for (; action
!= NULL
; action
= action
->next
)
2825 struct cmd_list_element
*cmd
;
2827 QUIT
; /* Allow user to bail out with ^C. */
2828 action_exp
= action
->line
;
2829 action_exp
= skip_spaces_const (action_exp
);
2831 /* The collection actions to be done while stepping are
2832 bracketed by the commands "while-stepping" and "end". */
2834 if (*action_exp
== '#') /* comment line */
2837 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2839 error (_("Bad action list item: %s"), action_exp
);
2841 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2845 for (i
= 0; i
< action
->body_count
; ++i
)
2846 trace_dump_actions (action
->body_list
[i
],
2847 1, stepping_frame
, from_tty
);
2849 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2851 /* Display the collected data.
2852 For the trap frame, display only what was collected at
2853 the trap. Likewise for stepping frames, display only
2854 what was collected while stepping. This means that the
2855 two boolean variables, STEPPING_FRAME and
2856 STEPPING_ACTIONS should be equal. */
2857 if (stepping_frame
== stepping_actions
)
2860 struct cleanup
*old_chain
2861 = make_cleanup (free_current_contents
, &cmd
);
2862 int trace_string
= 0;
2864 if (*action_exp
== '/')
2865 action_exp
= decode_agent_options (action_exp
, &trace_string
);
2868 { /* Repeat over a comma-separated list. */
2869 QUIT
; /* Allow user to bail out with ^C. */
2870 if (*action_exp
== ',')
2872 action_exp
= skip_spaces_const (action_exp
);
2874 next_comma
= strchr (action_exp
, ',');
2876 if (0 == strncasecmp (action_exp
, "$reg", 4))
2877 registers_info (NULL
, from_tty
);
2878 else if (0 == strncasecmp (action_exp
, "$_ret", 5))
2880 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2881 locals_info (NULL
, from_tty
);
2882 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2883 args_info (NULL
, from_tty
);
2886 if (next_comma
!= NULL
)
2888 size_t len
= next_comma
- action_exp
;
2890 cmd
= xrealloc (cmd
, len
+ 1);
2891 memcpy (cmd
, action_exp
, len
);
2896 size_t len
= strlen (action_exp
);
2898 cmd
= xrealloc (cmd
, len
+ 1);
2899 memcpy (cmd
, action_exp
, len
+ 1);
2902 printf_filtered ("%s = ", cmd
);
2903 output_command_const (cmd
, from_tty
);
2904 printf_filtered ("\n");
2906 action_exp
= next_comma
;
2908 while (action_exp
&& *action_exp
== ',');
2910 do_cleanups (old_chain
);
2916 /* The tdump command. */
2919 trace_dump_command (char *args
, int from_tty
)
2921 struct regcache
*regcache
;
2922 struct tracepoint
*t
;
2923 int stepping_frame
= 0;
2924 struct bp_location
*loc
;
2925 char *default_collect_line
= NULL
;
2926 struct command_line
*actions
, *default_collect_action
= NULL
;
2927 struct cleanup
*old_chain
= NULL
;
2929 if (tracepoint_number
== -1)
2931 warning (_("No current trace frame."));
2935 t
= get_tracepoint (tracepoint_number
);
2938 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2941 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2942 tracepoint_number
, traceframe_number
);
2944 /* The current frame is a trap frame if the frame PC is equal
2945 to the tracepoint PC. If not, then the current frame was
2946 collected during single-stepping. */
2948 regcache
= get_current_regcache ();
2950 /* If the traceframe's address matches any of the tracepoint's
2951 locations, assume it is a direct hit rather than a while-stepping
2952 frame. (FIXME this is not reliable, should record each frame's
2955 for (loc
= t
->base
.loc
; loc
; loc
= loc
->next
)
2956 if (loc
->address
== regcache_read_pc (regcache
))
2959 actions
= breakpoint_commands (&t
->base
);
2961 /* If there is a default-collect list, make up a collect command,
2962 prepend to the tracepoint's commands, and pass the whole mess to
2963 the trace dump scanner. We need to validate because
2964 default-collect might have been junked since the trace run. */
2965 if (*default_collect
)
2967 default_collect_line
= xstrprintf ("collect %s", default_collect
);
2968 old_chain
= make_cleanup (xfree
, default_collect_line
);
2969 validate_actionline (default_collect_line
, &t
->base
);
2970 default_collect_action
= xmalloc (sizeof (struct command_line
));
2971 make_cleanup (xfree
, default_collect_action
);
2972 default_collect_action
->next
= actions
;
2973 default_collect_action
->line
= default_collect_line
;
2974 actions
= default_collect_action
;
2977 trace_dump_actions (actions
, 0, stepping_frame
, from_tty
);
2979 if (*default_collect
)
2980 do_cleanups (old_chain
);
2983 /* Encode a piece of a tracepoint's source-level definition in a form
2984 that is suitable for both protocol and saving in files. */
2985 /* This version does not do multiple encodes for long strings; it should
2986 return an offset to the next piece to encode. FIXME */
2989 encode_source_string (int tpnum
, ULONGEST addr
,
2990 char *srctype
, char *src
, char *buf
, int buf_size
)
2992 if (80 + strlen (srctype
) > buf_size
)
2993 error (_("Buffer too small for source encoding"));
2994 sprintf (buf
, "%x:%s:%s:%x:%x:",
2995 tpnum
, phex_nz (addr
, sizeof (addr
)),
2996 srctype
, 0, (int) strlen (src
));
2997 if (strlen (buf
) + strlen (src
) * 2 >= buf_size
)
2998 error (_("Source string too long for buffer"));
2999 bin2hex (src
, buf
+ strlen (buf
), 0);
3003 /* Free trace file writer. */
3006 trace_file_writer_xfree (void *arg
)
3008 struct trace_file_writer
*writer
= arg
;
3010 writer
->ops
->dtor (writer
);
3014 /* TFILE trace writer. */
3016 struct tfile_trace_file_writer
3018 struct trace_file_writer base
;
3020 /* File pointer to tfile trace file. */
3022 /* Path name of the tfile trace file. */
3026 /* This is the implementation of trace_file_write_ops method
3027 target_save. We just call the generic target
3028 target_save_trace_data to do target-side saving. */
3031 tfile_target_save (struct trace_file_writer
*self
,
3032 const char *filename
)
3034 int err
= target_save_trace_data (filename
);
3039 /* This is the implementation of trace_file_write_ops method
3043 tfile_dtor (struct trace_file_writer
*self
)
3045 struct tfile_trace_file_writer
*writer
3046 = (struct tfile_trace_file_writer
*) self
;
3048 xfree (writer
->pathname
);
3050 if (writer
->fp
!= NULL
)
3051 fclose (writer
->fp
);
3054 /* This is the implementation of trace_file_write_ops method
3055 start. It creates the trace file FILENAME and registers some
3059 tfile_start (struct trace_file_writer
*self
, const char *filename
)
3061 struct tfile_trace_file_writer
*writer
3062 = (struct tfile_trace_file_writer
*) self
;
3064 writer
->pathname
= tilde_expand (filename
);
3065 writer
->fp
= fopen (writer
->pathname
, "wb");
3066 if (writer
->fp
== NULL
)
3067 error (_("Unable to open file '%s' for saving trace data (%s)"),
3068 filename
, safe_strerror (errno
));
3071 /* This is the implementation of trace_file_write_ops method
3072 write_header. Write the TFILE header. */
3075 tfile_write_header (struct trace_file_writer
*self
)
3077 struct tfile_trace_file_writer
*writer
3078 = (struct tfile_trace_file_writer
*) self
;
3081 /* Write a file header, with a high-bit-set char to indicate a
3082 binary file, plus a hint as what this file is, and a version
3083 number in case of future needs. */
3084 written
= fwrite ("\x7fTRACE0\n", 8, 1, writer
->fp
);
3086 perror_with_name (writer
->pathname
);
3089 /* This is the implementation of trace_file_write_ops method
3090 write_regblock_type. Write the size of register block. */
3093 tfile_write_regblock_type (struct trace_file_writer
*self
, int size
)
3095 struct tfile_trace_file_writer
*writer
3096 = (struct tfile_trace_file_writer
*) self
;
3098 fprintf (writer
->fp
, "R %x\n", size
);
3101 /* This is the implementation of trace_file_write_ops method
3105 tfile_write_status (struct trace_file_writer
*self
,
3106 struct trace_status
*ts
)
3108 struct tfile_trace_file_writer
*writer
3109 = (struct tfile_trace_file_writer
*) self
;
3111 fprintf (writer
->fp
, "status %c;%s",
3112 (ts
->running
? '1' : '0'), stop_reason_names
[ts
->stop_reason
]);
3113 if (ts
->stop_reason
== tracepoint_error
3114 || ts
->stop_reason
== tstop_command
)
3116 char *buf
= (char *) alloca (strlen (ts
->stop_desc
) * 2 + 1);
3118 bin2hex ((gdb_byte
*) ts
->stop_desc
, buf
, 0);
3119 fprintf (writer
->fp
, ":%s", buf
);
3121 fprintf (writer
->fp
, ":%x", ts
->stopping_tracepoint
);
3122 if (ts
->traceframe_count
>= 0)
3123 fprintf (writer
->fp
, ";tframes:%x", ts
->traceframe_count
);
3124 if (ts
->traceframes_created
>= 0)
3125 fprintf (writer
->fp
, ";tcreated:%x", ts
->traceframes_created
);
3126 if (ts
->buffer_free
>= 0)
3127 fprintf (writer
->fp
, ";tfree:%x", ts
->buffer_free
);
3128 if (ts
->buffer_size
>= 0)
3129 fprintf (writer
->fp
, ";tsize:%x", ts
->buffer_size
);
3130 if (ts
->disconnected_tracing
)
3131 fprintf (writer
->fp
, ";disconn:%x", ts
->disconnected_tracing
);
3132 if (ts
->circular_buffer
)
3133 fprintf (writer
->fp
, ";circular:%x", ts
->circular_buffer
);
3134 if (ts
->notes
!= NULL
)
3136 char *buf
= (char *) alloca (strlen (ts
->notes
) * 2 + 1);
3138 bin2hex ((gdb_byte
*) ts
->notes
, buf
, 0);
3139 fprintf (writer
->fp
, ";notes:%s", buf
);
3141 if (ts
->user_name
!= NULL
)
3143 char *buf
= (char *) alloca (strlen (ts
->user_name
) * 2 + 1);
3145 bin2hex ((gdb_byte
*) ts
->user_name
, buf
, 0);
3146 fprintf (writer
->fp
, ";username:%s", buf
);
3148 fprintf (writer
->fp
, "\n");
3151 /* This is the implementation of trace_file_write_ops method
3152 write_uploaded_tsv. */
3155 tfile_write_uploaded_tsv (struct trace_file_writer
*self
,
3156 struct uploaded_tsv
*utsv
)
3159 struct tfile_trace_file_writer
*writer
3160 = (struct tfile_trace_file_writer
*) self
;
3164 buf
= (char *) xmalloc (strlen (utsv
->name
) * 2 + 1);
3165 bin2hex ((gdb_byte
*) (utsv
->name
), buf
, 0);
3168 fprintf (writer
->fp
, "tsv %x:%s:%x:%s\n",
3169 utsv
->number
, phex_nz (utsv
->initial_value
, 8),
3170 utsv
->builtin
, buf
);
3176 #define MAX_TRACE_UPLOAD 2000
3178 /* This is the implementation of trace_file_write_ops method
3179 write_uploaded_tp. */
3182 tfile_write_uploaded_tp (struct trace_file_writer
*self
,
3183 struct uploaded_tp
*utp
)
3185 struct tfile_trace_file_writer
*writer
3186 = (struct tfile_trace_file_writer
*) self
;
3189 gdb_byte buf
[MAX_TRACE_UPLOAD
];
3191 fprintf (writer
->fp
, "tp T%x:%s:%c:%x:%x",
3192 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
3193 (utp
->enabled
? 'E' : 'D'), utp
->step
, utp
->pass
);
3194 if (utp
->type
== bp_fast_tracepoint
)
3195 fprintf (writer
->fp
, ":F%x", utp
->orig_size
);
3197 fprintf (writer
->fp
,
3198 ":X%x,%s", (unsigned int) strlen (utp
->cond
) / 2,
3200 fprintf (writer
->fp
, "\n");
3201 for (a
= 0; VEC_iterate (char_ptr
, utp
->actions
, a
, act
); ++a
)
3202 fprintf (writer
->fp
, "tp A%x:%s:%s\n",
3203 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)), act
);
3204 for (a
= 0; VEC_iterate (char_ptr
, utp
->step_actions
, a
, act
); ++a
)
3205 fprintf (writer
->fp
, "tp S%x:%s:%s\n",
3206 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)), act
);
3209 encode_source_string (utp
->number
, utp
->addr
,
3210 "at", utp
->at_string
, buf
, MAX_TRACE_UPLOAD
);
3211 fprintf (writer
->fp
, "tp Z%s\n", buf
);
3213 if (utp
->cond_string
)
3215 encode_source_string (utp
->number
, utp
->addr
,
3216 "cond", utp
->cond_string
,
3217 buf
, MAX_TRACE_UPLOAD
);
3218 fprintf (writer
->fp
, "tp Z%s\n", buf
);
3220 for (a
= 0; VEC_iterate (char_ptr
, utp
->cmd_strings
, a
, act
); ++a
)
3222 encode_source_string (utp
->number
, utp
->addr
, "cmd", act
,
3223 buf
, MAX_TRACE_UPLOAD
);
3224 fprintf (writer
->fp
, "tp Z%s\n", buf
);
3226 fprintf (writer
->fp
, "tp V%x:%s:%x:%s\n",
3227 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
3229 phex_nz (utp
->traceframe_usage
,
3230 sizeof (utp
->traceframe_usage
)));
3233 /* This is the implementation of trace_file_write_ops method
3234 write_definition_end. */
3237 tfile_write_definition_end (struct trace_file_writer
*self
)
3239 struct tfile_trace_file_writer
*writer
3240 = (struct tfile_trace_file_writer
*) self
;
3242 fprintf (writer
->fp
, "\n");
3245 /* This is the implementation of trace_file_write_ops method
3249 tfile_write_raw_data (struct trace_file_writer
*self
, gdb_byte
*buf
,
3252 struct tfile_trace_file_writer
*writer
3253 = (struct tfile_trace_file_writer
*) self
;
3255 if (fwrite (buf
, len
, 1, writer
->fp
) < 1)
3256 perror_with_name (writer
->pathname
);
3259 /* This is the implementation of trace_file_write_ops method
3263 tfile_end (struct trace_file_writer
*self
)
3265 struct tfile_trace_file_writer
*writer
3266 = (struct tfile_trace_file_writer
*) self
;
3267 uint32_t gotten
= 0;
3269 /* Mark the end of trace data. */
3270 if (fwrite (&gotten
, 4, 1, writer
->fp
) < 1)
3271 perror_with_name (writer
->pathname
);
3274 /* Operations to write trace buffers into TFILE format. */
3276 static const struct trace_file_write_ops tfile_write_ops
=
3282 tfile_write_regblock_type
,
3284 tfile_write_uploaded_tsv
,
3285 tfile_write_uploaded_tp
,
3286 tfile_write_definition_end
,
3287 tfile_write_raw_data
,
3292 /* Helper macros. */
3294 #define TRACE_WRITE_R_BLOCK(writer, buf, size) \
3295 writer->ops->frame_ops->write_r_block ((writer), (buf), (size))
3296 #define TRACE_WRITE_M_BLOCK_HEADER(writer, addr, size) \
3297 writer->ops->frame_ops->write_m_block_header ((writer), (addr), \
3299 #define TRACE_WRITE_M_BLOCK_MEMORY(writer, buf, size) \
3300 writer->ops->frame_ops->write_m_block_memory ((writer), (buf), \
3302 #define TRACE_WRITE_V_BLOCK(writer, num, val) \
3303 writer->ops->frame_ops->write_v_block ((writer), (num), (val))
3305 extern int trace_regblock_size
;
3307 /* Save tracepoint data to file named FILENAME through WRITER. WRITER
3308 determines the trace file format. If TARGET_DOES_SAVE is non-zero,
3309 the save is performed on the target, otherwise GDB obtains all trace
3310 data and saves it locally. */
3313 trace_save (const char *filename
, struct trace_file_writer
*writer
,
3314 int target_does_save
)
3316 struct trace_status
*ts
= current_trace_status ();
3318 struct uploaded_tp
*uploaded_tps
= NULL
, *utp
;
3319 struct uploaded_tsv
*uploaded_tsvs
= NULL
, *utsv
;
3321 ULONGEST offset
= 0;
3322 gdb_byte buf
[MAX_TRACE_UPLOAD
];
3324 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
3326 /* If the target is to save the data to a file on its own, then just
3327 send the command and be done with it. */
3328 if (target_does_save
)
3330 if (!writer
->ops
->target_save (writer
, filename
))
3331 error (_("Target failed to save trace data to '%s'."),
3336 /* Get the trace status first before opening the file, so if the
3337 target is losing, we can get out without touching files. */
3338 status
= target_get_trace_status (ts
);
3340 writer
->ops
->start (writer
, filename
);
3342 writer
->ops
->write_header (writer
);
3344 /* Write descriptive info. */
3346 /* Write out the size of a register block. */
3347 writer
->ops
->write_regblock_type (writer
, trace_regblock_size
);
3349 /* Write out status of the tracing run (aka "tstatus" info). */
3350 writer
->ops
->write_status (writer
, ts
);
3352 /* Note that we want to upload tracepoints and save those, rather
3353 than simply writing out the local ones, because the user may have
3354 changed tracepoints in GDB in preparation for a future tracing
3355 run, or maybe just mass-deleted all types of breakpoints as part
3356 of cleaning up. So as not to contaminate the session, leave the
3357 data in its uploaded form, don't make into real tracepoints. */
3359 /* Get trace state variables first, they may be checked when parsing
3360 uploaded commands. */
3362 target_upload_trace_state_variables (&uploaded_tsvs
);
3364 for (utsv
= uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
3365 writer
->ops
->write_uploaded_tsv (writer
, utsv
);
3367 free_uploaded_tsvs (&uploaded_tsvs
);
3369 target_upload_tracepoints (&uploaded_tps
);
3371 for (utp
= uploaded_tps
; utp
; utp
= utp
->next
)
3372 target_get_tracepoint_status (NULL
, utp
);
3374 for (utp
= uploaded_tps
; utp
; utp
= utp
->next
)
3375 writer
->ops
->write_uploaded_tp (writer
, utp
);
3377 free_uploaded_tps (&uploaded_tps
);
3379 /* Mark the end of the definition section. */
3380 writer
->ops
->write_definition_end (writer
);
3382 /* Get and write the trace data proper. */
3387 /* The writer supports writing the contents of trace buffer
3388 directly to trace file. Don't parse the contents of trace
3390 if (writer
->ops
->write_trace_buffer
!= NULL
)
3392 /* We ask for big blocks, in the hopes of efficiency, but
3393 will take less if the target has packet size limitations
3395 gotten
= target_get_raw_trace_data (buf
, offset
,
3398 error (_("Failure to get requested trace buffer data"));
3399 /* No more data is forthcoming, we're done. */
3403 writer
->ops
->write_trace_buffer (writer
, buf
, gotten
);
3411 /* Parse the trace buffers according to how data are stored
3412 in trace buffer in GDBserver. */
3414 gotten
= target_get_raw_trace_data (buf
, offset
, 6);
3419 /* Read the first six bytes in, which is the tracepoint
3420 number and trace frame size. */
3422 extract_unsigned_integer (&buf
[0], 2, byte_order
);
3424 tf_size
= (uint32_t)
3425 extract_unsigned_integer (&buf
[2], 4, byte_order
);
3427 writer
->ops
->frame_ops
->start (writer
, tp_num
);
3436 for (block
= 0; block
< tf_size
; )
3438 gdb_byte block_type
;
3440 /* We'll fetch one block each time, in order to
3441 handle the extremely large 'M' block. We first
3442 fetch one byte to get the type of the block. */
3443 gotten
= target_get_raw_trace_data (buf
, offset
, 1);
3445 error (_("Failure to get requested trace buffer data"));
3451 block_type
= buf
[0];
3456 = target_get_raw_trace_data (buf
, offset
,
3457 trace_regblock_size
);
3458 if (gotten
< trace_regblock_size
)
3459 error (_("Failure to get requested trace"
3462 TRACE_WRITE_R_BLOCK (writer
, buf
,
3463 trace_regblock_size
);
3467 unsigned short mlen
;
3472 t
= target_get_raw_trace_data (buf
,offset
, 10);
3474 error (_("Failure to get requested trace"
3482 extract_unsigned_integer (buf
, 8,
3484 mlen
= (unsigned short)
3485 extract_unsigned_integer (&buf
[8], 2,
3488 TRACE_WRITE_M_BLOCK_HEADER (writer
, addr
,
3491 /* The memory contents in 'M' block may be
3492 very large. Fetch the data from the target
3493 and write them into file one by one. */
3494 for (j
= 0; j
< mlen
; )
3496 unsigned int read_length
;
3498 if (mlen
- j
> MAX_TRACE_UPLOAD
)
3499 read_length
= MAX_TRACE_UPLOAD
;
3501 read_length
= mlen
- j
;
3503 t
= target_get_raw_trace_data (buf
,
3506 if (t
< read_length
)
3507 error (_("Failure to get requested"
3508 " trace buffer data"));
3510 TRACE_WRITE_M_BLOCK_MEMORY (writer
, buf
,
3514 gotten
+= read_length
;
3525 = target_get_raw_trace_data (buf
, offset
,
3528 error (_("Failure to get requested"
3529 " trace buffer data"));
3531 vnum
= (int) extract_signed_integer (buf
,
3535 = extract_signed_integer (&buf
[4], 8,
3538 TRACE_WRITE_V_BLOCK (writer
, vnum
, val
);
3542 error (_("Unknown block type '%c' (0x%x) in"
3544 block_type
, block_type
);
3554 writer
->ops
->frame_ops
->end (writer
);
3558 writer
->ops
->end (writer
);
3561 /* Return a trace writer for TFILE format. */
3563 static struct trace_file_writer
*
3564 tfile_trace_file_writer_new (void)
3566 struct tfile_trace_file_writer
*writer
3567 = xmalloc (sizeof (struct tfile_trace_file_writer
));
3569 writer
->base
.ops
= &tfile_write_ops
;
3571 writer
->pathname
= NULL
;
3573 return (struct trace_file_writer
*) writer
;
3577 trace_save_command (char *args
, int from_tty
)
3579 int target_does_save
= 0;
3581 char *filename
= NULL
;
3582 struct cleanup
*back_to
;
3583 int generate_ctf
= 0;
3584 struct trace_file_writer
*writer
= NULL
;
3587 error_no_arg (_("file in which to save trace data"));
3589 argv
= gdb_buildargv (args
);
3590 back_to
= make_cleanup_freeargv (argv
);
3592 for (; *argv
; ++argv
)
3594 if (strcmp (*argv
, "-r") == 0)
3595 target_does_save
= 1;
3596 if (strcmp (*argv
, "-ctf") == 0)
3598 else if (**argv
== '-')
3599 error (_("unknown option `%s'"), *argv
);
3605 error_no_arg (_("file in which to save trace data"));
3608 writer
= ctf_trace_file_writer_new ();
3610 writer
= tfile_trace_file_writer_new ();
3612 make_cleanup (trace_file_writer_xfree
, writer
);
3614 trace_save (filename
, writer
, target_does_save
);
3617 printf_filtered (_("Trace data saved to %s '%s'.\n"),
3618 generate_ctf
? "directory" : "file", filename
);
3620 do_cleanups (back_to
);
3623 /* Save the trace data to file FILENAME of tfile format. */
3626 trace_save_tfile (const char *filename
, int target_does_save
)
3628 struct trace_file_writer
*writer
;
3629 struct cleanup
*back_to
;
3631 writer
= tfile_trace_file_writer_new ();
3632 back_to
= make_cleanup (trace_file_writer_xfree
, writer
);
3633 trace_save (filename
, writer
, target_does_save
);
3634 do_cleanups (back_to
);
3637 /* Save the trace data to dir DIRNAME of ctf format. */
3640 trace_save_ctf (const char *dirname
, int target_does_save
)
3642 struct trace_file_writer
*writer
;
3643 struct cleanup
*back_to
;
3645 writer
= ctf_trace_file_writer_new ();
3646 back_to
= make_cleanup (trace_file_writer_xfree
, writer
);
3648 trace_save (dirname
, writer
, target_does_save
);
3649 do_cleanups (back_to
);
3652 /* Tell the target what to do with an ongoing tracing run if GDB
3653 disconnects for some reason. */
3656 set_disconnected_tracing (char *args
, int from_tty
,
3657 struct cmd_list_element
*c
)
3659 target_set_disconnected_tracing (disconnected_tracing
);
3663 set_circular_trace_buffer (char *args
, int from_tty
,
3664 struct cmd_list_element
*c
)
3666 target_set_circular_trace_buffer (circular_trace_buffer
);
3670 set_trace_buffer_size (char *args
, int from_tty
,
3671 struct cmd_list_element
*c
)
3673 target_set_trace_buffer_size (trace_buffer_size
);
3677 set_trace_user (char *args
, int from_tty
,
3678 struct cmd_list_element
*c
)
3682 ret
= target_set_trace_notes (trace_user
, NULL
, NULL
);
3685 warning (_("Target does not support trace notes, user ignored"));
3689 set_trace_notes (char *args
, int from_tty
,
3690 struct cmd_list_element
*c
)
3694 ret
= target_set_trace_notes (NULL
, trace_notes
, NULL
);
3697 warning (_("Target does not support trace notes, note ignored"));
3701 set_trace_stop_notes (char *args
, int from_tty
,
3702 struct cmd_list_element
*c
)
3706 ret
= target_set_trace_notes (NULL
, NULL
, trace_stop_notes
);
3709 warning (_("Target does not support trace notes, stop note ignored"));
3712 /* Convert the memory pointed to by mem into hex, placing result in buf.
3713 * Return a pointer to the last char put in buf (null)
3714 * "stolen" from sparc-stub.c
3717 static const char hexchars
[] = "0123456789abcdef";
3720 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
3728 *buf
++ = hexchars
[ch
>> 4];
3729 *buf
++ = hexchars
[ch
& 0xf];
3738 get_traceframe_number (void)
3740 return traceframe_number
;
3743 /* Make the traceframe NUM be the current trace frame. Does nothing
3744 if NUM is already current. */
3747 set_current_traceframe (int num
)
3751 if (traceframe_number
== num
)
3753 /* Nothing to do. */
3757 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
3760 warning (_("could not change traceframe"));
3762 set_traceframe_num (newnum
);
3764 /* Changing the traceframe changes our view of registers and of the
3766 registers_changed ();
3768 clear_traceframe_info ();
3771 /* Make the traceframe NUM be the current trace frame, and do nothing
3775 set_traceframe_number (int num
)
3777 traceframe_number
= num
;
3780 /* A cleanup used when switching away and back from tfind mode. */
3782 struct current_traceframe_cleanup
3784 /* The traceframe we were inspecting. */
3785 int traceframe_number
;
3789 do_restore_current_traceframe_cleanup (void *arg
)
3791 struct current_traceframe_cleanup
*old
= arg
;
3793 set_current_traceframe (old
->traceframe_number
);
3797 restore_current_traceframe_cleanup_dtor (void *arg
)
3799 struct current_traceframe_cleanup
*old
= arg
;
3805 make_cleanup_restore_current_traceframe (void)
3807 struct current_traceframe_cleanup
*old
;
3809 old
= xmalloc (sizeof (struct current_traceframe_cleanup
));
3810 old
->traceframe_number
= traceframe_number
;
3812 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
3813 restore_current_traceframe_cleanup_dtor
);
3817 make_cleanup_restore_traceframe_number (void)
3819 return make_cleanup_restore_integer (&traceframe_number
);
3822 /* Given a number and address, return an uploaded tracepoint with that
3823 number, creating if necessary. */
3825 struct uploaded_tp
*
3826 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
3828 struct uploaded_tp
*utp
;
3830 for (utp
= *utpp
; utp
; utp
= utp
->next
)
3831 if (utp
->number
== num
&& utp
->addr
== addr
)
3833 utp
= (struct uploaded_tp
*) xmalloc (sizeof (struct uploaded_tp
));
3834 memset (utp
, 0, sizeof (struct uploaded_tp
));
3837 utp
->actions
= NULL
;
3838 utp
->step_actions
= NULL
;
3839 utp
->cmd_strings
= NULL
;
3846 free_uploaded_tps (struct uploaded_tp
**utpp
)
3848 struct uploaded_tp
*next_one
;
3852 next_one
= (*utpp
)->next
;
3858 /* Given a number and address, return an uploaded tracepoint with that
3859 number, creating if necessary. */
3861 static struct uploaded_tsv
*
3862 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
3864 struct uploaded_tsv
*utsv
;
3866 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
3867 if (utsv
->number
== num
)
3869 utsv
= (struct uploaded_tsv
*) xmalloc (sizeof (struct uploaded_tsv
));
3870 memset (utsv
, 0, sizeof (struct uploaded_tsv
));
3872 utsv
->next
= *utsvp
;
3878 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
3880 struct uploaded_tsv
*next_one
;
3884 next_one
= (*utsvp
)->next
;
3890 /* FIXME this function is heuristic and will miss the cases where the
3891 conditional is semantically identical but differs in whitespace,
3892 such as "x == 0" vs "x==0". */
3895 cond_string_is_same (char *str1
, char *str2
)
3897 if (str1
== NULL
|| str2
== NULL
)
3898 return (str1
== str2
);
3900 return (strcmp (str1
, str2
) == 0);
3903 /* Look for an existing tracepoint that seems similar enough to the
3904 uploaded one. Enablement isn't compared, because the user can
3905 toggle that freely, and may have done so in anticipation of the
3906 next trace run. Return the location of matched tracepoint. */
3908 static struct bp_location
*
3909 find_matching_tracepoint_location (struct uploaded_tp
*utp
)
3911 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
3913 struct breakpoint
*b
;
3914 struct bp_location
*loc
;
3916 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, b
); ix
++)
3918 struct tracepoint
*t
= (struct tracepoint
*) b
;
3920 if (b
->type
== utp
->type
3921 && t
->step_count
== utp
->step
3922 && t
->pass_count
== utp
->pass
3923 && cond_string_is_same (t
->base
.cond_string
, utp
->cond_string
)
3924 /* FIXME also test actions. */
3927 /* Scan the locations for an address match. */
3928 for (loc
= b
->loc
; loc
; loc
= loc
->next
)
3930 if (loc
->address
== utp
->addr
)
3938 /* Given a list of tracepoints uploaded from a target, attempt to
3939 match them up with existing tracepoints, and create new ones if not
3943 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
3945 struct uploaded_tp
*utp
;
3946 /* A set of tracepoints which are modified. */
3947 VEC(breakpoint_p
) *modified_tp
= NULL
;
3949 struct breakpoint
*b
;
3951 /* Look for GDB tracepoints that match up with our uploaded versions. */
3952 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
3954 struct bp_location
*loc
;
3955 struct tracepoint
*t
;
3957 loc
= find_matching_tracepoint_location (utp
);
3962 /* Mark this location as already inserted. */
3964 t
= (struct tracepoint
*) loc
->owner
;
3965 printf_filtered (_("Assuming tracepoint %d is same "
3966 "as target's tracepoint %d at %s.\n"),
3967 loc
->owner
->number
, utp
->number
,
3968 paddress (loc
->gdbarch
, utp
->addr
));
3970 /* The tracepoint LOC->owner was modified (the location LOC
3971 was marked as inserted in the target). Save it in
3972 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3973 observers will be notified later once for each tracepoint
3974 saved in MODIFIED_TP. */
3976 VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
);
3978 if (b
== loc
->owner
)
3984 VEC_safe_push (breakpoint_p
, modified_tp
, loc
->owner
);
3988 t
= create_tracepoint_from_upload (utp
);
3990 printf_filtered (_("Created tracepoint %d for "
3991 "target's tracepoint %d at %s.\n"),
3992 t
->base
.number
, utp
->number
,
3993 paddress (get_current_arch (), utp
->addr
));
3995 printf_filtered (_("Failed to create tracepoint for target's "
3996 "tracepoint %d at %s, skipping it.\n"),
3998 paddress (get_current_arch (), utp
->addr
));
4000 /* Whether found or created, record the number used by the
4001 target, to help with mapping target tracepoints back to their
4002 counterparts here. */
4004 t
->number_on_target
= utp
->number
;
4007 /* Notify 'breakpoint-modified' observer that at least one of B's
4008 locations was changed. */
4009 for (ix
= 0; VEC_iterate (breakpoint_p
, modified_tp
, ix
, b
); ix
++)
4010 observer_notify_breakpoint_modified (b
);
4012 VEC_free (breakpoint_p
, modified_tp
);
4013 free_uploaded_tps (uploaded_tps
);
4016 /* Trace state variables don't have much to identify them beyond their
4017 name, so just use that to detect matches. */
4019 static struct trace_state_variable
*
4020 find_matching_tsv (struct uploaded_tsv
*utsv
)
4025 return find_trace_state_variable (utsv
->name
);
4028 static struct trace_state_variable
*
4029 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
4031 const char *namebase
;
4034 struct trace_state_variable
*tsv
;
4035 struct cleanup
*old_chain
;
4039 namebase
= utsv
->name
;
4040 buf
= xstrprintf ("%s", namebase
);
4045 buf
= xstrprintf ("%s_%d", namebase
, try_num
++);
4048 /* Fish for a name that is not in use. */
4049 /* (should check against all internal vars?) */
4050 while (find_trace_state_variable (buf
))
4053 buf
= xstrprintf ("%s_%d", namebase
, try_num
++);
4056 old_chain
= make_cleanup (xfree
, buf
);
4058 /* We have an available name, create the variable. */
4059 tsv
= create_trace_state_variable (buf
);
4060 tsv
->initial_value
= utsv
->initial_value
;
4061 tsv
->builtin
= utsv
->builtin
;
4063 observer_notify_tsv_created (tsv
);
4065 do_cleanups (old_chain
);
4070 /* Given a list of uploaded trace state variables, try to match them
4071 up with existing variables, or create additional ones. */
4074 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
4077 struct uploaded_tsv
*utsv
;
4078 struct trace_state_variable
*tsv
;
4081 /* Most likely some numbers will have to be reassigned as part of
4082 the merge, so clear them all in anticipation. */
4083 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
4086 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
4088 tsv
= find_matching_tsv (utsv
);
4092 printf_filtered (_("Assuming trace state variable $%s "
4093 "is same as target's variable %d.\n"),
4094 tsv
->name
, utsv
->number
);
4098 tsv
= create_tsv_from_upload (utsv
);
4100 printf_filtered (_("Created trace state variable "
4101 "$%s for target's variable %d.\n"),
4102 tsv
->name
, utsv
->number
);
4104 /* Give precedence to numberings that come from the target. */
4106 tsv
->number
= utsv
->number
;
4109 /* Renumber everything that didn't get a target-assigned number. */
4111 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
4112 if (tsv
->number
> highest
)
4113 highest
= tsv
->number
;
4116 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
4117 if (tsv
->number
== 0)
4118 tsv
->number
= highest
++;
4120 free_uploaded_tsvs (uploaded_tsvs
);
4123 /* target tfile command */
4125 static struct target_ops tfile_ops
;
4127 /* Fill in tfile_ops with its defined operations and properties. */
4129 #define TRACE_HEADER_SIZE 8
4131 static char *trace_filename
;
4132 static int trace_fd
= -1;
4133 static off_t trace_frames_offset
;
4134 static off_t cur_offset
;
4135 static int cur_data_size
;
4136 int trace_regblock_size
;
4138 static void tfile_interp_line (char *line
,
4139 struct uploaded_tp
**utpp
,
4140 struct uploaded_tsv
**utsvp
);
4142 /* Read SIZE bytes into READBUF from the trace frame, starting at
4143 TRACE_FD's current position. Note that this call `read'
4144 underneath, hence it advances the file's seek position. Throws an
4145 error if the `read' syscall fails, or less than SIZE bytes are
4149 tfile_read (gdb_byte
*readbuf
, int size
)
4153 gotten
= read (trace_fd
, readbuf
, size
);
4155 perror_with_name (trace_filename
);
4156 else if (gotten
< size
)
4157 error (_("Premature end of file while reading trace file"));
4161 tfile_open (char *filename
, int from_tty
)
4163 volatile struct gdb_exception ex
;
4165 struct cleanup
*old_chain
;
4168 char header
[TRACE_HEADER_SIZE
];
4169 char linebuf
[1000]; /* Should be max remote packet size or so. */
4172 struct trace_status
*ts
;
4173 struct uploaded_tp
*uploaded_tps
= NULL
;
4174 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
4176 target_preopen (from_tty
);
4178 error (_("No trace file specified."));
4180 filename
= tilde_expand (filename
);
4181 if (!IS_ABSOLUTE_PATH(filename
))
4183 temp
= concat (current_directory
, "/", filename
, (char *) NULL
);
4188 old_chain
= make_cleanup (xfree
, filename
);
4190 flags
= O_BINARY
| O_LARGEFILE
;
4192 scratch_chan
= open (filename
, flags
, 0);
4193 if (scratch_chan
< 0)
4194 perror_with_name (filename
);
4196 /* Looks semi-reasonable. Toss the old trace file and work on the new. */
4198 discard_cleanups (old_chain
); /* Don't free filename any more. */
4199 unpush_target (&tfile_ops
);
4201 trace_filename
= xstrdup (filename
);
4202 trace_fd
= scratch_chan
;
4205 /* Read the file header and test for validity. */
4206 tfile_read ((gdb_byte
*) &header
, TRACE_HEADER_SIZE
);
4208 bytes
+= TRACE_HEADER_SIZE
;
4209 if (!(header
[0] == 0x7f
4210 && (strncmp (header
+ 1, "TRACE0\n", 7) == 0)))
4211 error (_("File is not a valid trace file."));
4213 push_target (&tfile_ops
);
4215 trace_regblock_size
= 0;
4216 ts
= current_trace_status ();
4217 /* We know we're working with a file. Record its name. */
4218 ts
->filename
= trace_filename
;
4219 /* Set defaults in case there is no status line. */
4220 ts
->running_known
= 0;
4221 ts
->stop_reason
= trace_stop_reason_unknown
;
4222 ts
->traceframe_count
= -1;
4223 ts
->buffer_free
= 0;
4224 ts
->disconnected_tracing
= 0;
4225 ts
->circular_buffer
= 0;
4227 TRY_CATCH (ex
, RETURN_MASK_ALL
)
4229 /* Read through a section of newline-terminated lines that
4230 define things like tracepoints. */
4234 tfile_read (&byte
, 1);
4239 /* Empty line marks end of the definition section. */
4244 tfile_interp_line (linebuf
, &uploaded_tps
, &uploaded_tsvs
);
4247 linebuf
[i
++] = byte
;
4249 error (_("Excessively long lines in trace file"));
4252 /* Record the starting offset of the binary trace data. */
4253 trace_frames_offset
= bytes
;
4255 /* If we don't have a blocksize, we can't interpret the
4257 if (trace_regblock_size
== 0)
4258 error (_("No register block size recorded in trace file"));
4262 /* Pop the partially set up target. */
4264 throw_exception (ex
);
4267 inferior_appeared (current_inferior (), TFILE_PID
);
4268 inferior_ptid
= pid_to_ptid (TFILE_PID
);
4269 add_thread_silent (inferior_ptid
);
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
);
4282 post_create_inferior (&tfile_ops
, from_tty
);
4285 /* Interpret the given line from the definitions part of the trace
4289 tfile_interp_line (char *line
,
4290 struct uploaded_tp
**utpp
, struct uploaded_tsv
**utsvp
)
4294 if (strncmp (p
, "R ", strlen ("R ")) == 0)
4297 trace_regblock_size
= strtol (p
, &p
, 16);
4299 else if (strncmp (p
, "status ", strlen ("status ")) == 0)
4301 p
+= strlen ("status ");
4302 parse_trace_status (p
, current_trace_status ());
4304 else if (strncmp (p
, "tp ", strlen ("tp ")) == 0)
4306 p
+= strlen ("tp ");
4307 parse_tracepoint_definition (p
, utpp
);
4309 else if (strncmp (p
, "tsv ", strlen ("tsv ")) == 0)
4311 p
+= strlen ("tsv ");
4312 parse_tsv_definition (p
, utsvp
);
4315 warning (_("Ignoring trace file definition \"%s\""), line
);
4318 /* Parse the part of trace status syntax that is shared between
4319 the remote protocol and the trace file reader. */
4322 parse_trace_status (char *line
, struct trace_status
*ts
)
4324 char *p
= line
, *p1
, *p2
, *p3
, *p_temp
;
4328 ts
->running_known
= 1;
4329 ts
->running
= (*p
++ == '1');
4330 ts
->stop_reason
= trace_stop_reason_unknown
;
4331 xfree (ts
->stop_desc
);
4332 ts
->stop_desc
= NULL
;
4333 ts
->traceframe_count
= -1;
4334 ts
->traceframes_created
= -1;
4335 ts
->buffer_free
= -1;
4336 ts
->buffer_size
= -1;
4337 ts
->disconnected_tracing
= 0;
4338 ts
->circular_buffer
= 0;
4339 xfree (ts
->user_name
);
4340 ts
->user_name
= NULL
;
4343 ts
->start_time
= ts
->stop_time
= 0;
4347 p1
= strchr (p
, ':');
4349 error (_("Malformed trace status, at %s\n\
4350 Status line: '%s'\n"), p
, line
);
4351 p3
= strchr (p
, ';');
4353 p3
= p
+ strlen (p
);
4354 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
4356 p
= unpack_varlen_hex (++p1
, &val
);
4357 ts
->stop_reason
= trace_buffer_full
;
4359 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
4361 p
= unpack_varlen_hex (++p1
, &val
);
4362 ts
->stop_reason
= trace_never_run
;
4364 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
],
4367 p
= unpack_varlen_hex (++p1
, &val
);
4368 ts
->stop_reason
= tracepoint_passcount
;
4369 ts
->stopping_tracepoint
= val
;
4371 else if (strncmp (p
, stop_reason_names
[tstop_command
], p1
- p
) == 0)
4373 p2
= strchr (++p1
, ':');
4381 ts
->stop_desc
= xmalloc (strlen (line
));
4382 end
= hex2bin (p1
, ts
->stop_desc
, (p2
- p1
) / 2);
4383 ts
->stop_desc
[end
] = '\0';
4386 ts
->stop_desc
= xstrdup ("");
4388 p
= unpack_varlen_hex (++p2
, &val
);
4389 ts
->stop_reason
= tstop_command
;
4391 else if (strncmp (p
, stop_reason_names
[trace_disconnected
], p1
- p
) == 0)
4393 p
= unpack_varlen_hex (++p1
, &val
);
4394 ts
->stop_reason
= trace_disconnected
;
4396 else if (strncmp (p
, stop_reason_names
[tracepoint_error
], p1
- p
) == 0)
4398 p2
= strchr (++p1
, ':');
4401 ts
->stop_desc
= xmalloc ((p2
- p1
) / 2 + 1);
4402 end
= hex2bin (p1
, ts
->stop_desc
, (p2
- p1
) / 2);
4403 ts
->stop_desc
[end
] = '\0';
4406 ts
->stop_desc
= xstrdup ("");
4408 p
= unpack_varlen_hex (++p2
, &val
);
4409 ts
->stopping_tracepoint
= val
;
4410 ts
->stop_reason
= tracepoint_error
;
4412 else if (strncmp (p
, "tframes", p1
- p
) == 0)
4414 p
= unpack_varlen_hex (++p1
, &val
);
4415 ts
->traceframe_count
= val
;
4417 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
4419 p
= unpack_varlen_hex (++p1
, &val
);
4420 ts
->traceframes_created
= val
;
4422 else if (strncmp (p
, "tfree", p1
- p
) == 0)
4424 p
= unpack_varlen_hex (++p1
, &val
);
4425 ts
->buffer_free
= val
;
4427 else if (strncmp (p
, "tsize", p1
- p
) == 0)
4429 p
= unpack_varlen_hex (++p1
, &val
);
4430 ts
->buffer_size
= val
;
4432 else if (strncmp (p
, "disconn", p1
- p
) == 0)
4434 p
= unpack_varlen_hex (++p1
, &val
);
4435 ts
->disconnected_tracing
= val
;
4437 else if (strncmp (p
, "circular", p1
- p
) == 0)
4439 p
= unpack_varlen_hex (++p1
, &val
);
4440 ts
->circular_buffer
= val
;
4442 else if (strncmp (p
, "starttime", p1
- p
) == 0)
4444 p
= unpack_varlen_hex (++p1
, &val
);
4445 ts
->start_time
= val
;
4447 else if (strncmp (p
, "stoptime", p1
- p
) == 0)
4449 p
= unpack_varlen_hex (++p1
, &val
);
4450 ts
->stop_time
= val
;
4452 else if (strncmp (p
, "username", p1
- p
) == 0)
4455 ts
->user_name
= xmalloc (strlen (p
) / 2);
4456 end
= hex2bin (p1
, ts
->user_name
, (p3
- p1
) / 2);
4457 ts
->user_name
[end
] = '\0';
4460 else if (strncmp (p
, "notes", p1
- p
) == 0)
4463 ts
->notes
= xmalloc (strlen (p
) / 2);
4464 end
= hex2bin (p1
, ts
->notes
, (p3
- p1
) / 2);
4465 ts
->notes
[end
] = '\0';
4470 /* Silently skip unknown optional info. */
4471 p_temp
= strchr (p1
+ 1, ';');
4475 /* Must be at the end. */
4482 parse_tracepoint_status (char *p
, struct breakpoint
*bp
,
4483 struct uploaded_tp
*utp
)
4486 struct tracepoint
*tp
= (struct tracepoint
*) bp
;
4488 p
= unpack_varlen_hex (p
, &uval
);
4490 tp
->base
.hit_count
+= uval
;
4492 utp
->hit_count
+= uval
;
4493 p
= unpack_varlen_hex (p
+ 1, &uval
);
4495 tp
->traceframe_usage
+= uval
;
4497 utp
->traceframe_usage
+= uval
;
4498 /* Ignore any extra, allowing for future extensions. */
4501 /* Given a line of text defining a part of a tracepoint, parse it into
4502 an "uploaded tracepoint". */
4505 parse_tracepoint_definition (char *line
, struct uploaded_tp
**utpp
)
4509 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
, start
;
4512 char *cond
, *srctype
, *buf
;
4513 struct uploaded_tp
*utp
= NULL
;
4516 /* Both tracepoint and action definitions start with the same number
4517 and address sequence. */
4519 p
= unpack_varlen_hex (p
, &num
);
4520 p
++; /* skip a colon */
4521 p
= unpack_varlen_hex (p
, &addr
);
4522 p
++; /* skip a colon */
4525 enabled
= (*p
++ == 'E');
4526 p
++; /* skip a colon */
4527 p
= unpack_varlen_hex (p
, &step
);
4528 p
++; /* skip a colon */
4529 p
= unpack_varlen_hex (p
, &pass
);
4530 type
= bp_tracepoint
;
4532 /* Thumb through optional fields. */
4535 p
++; /* skip a colon */
4538 type
= bp_fast_tracepoint
;
4540 p
= unpack_varlen_hex (p
, &orig_size
);
4544 type
= bp_static_tracepoint
;
4550 p
= unpack_varlen_hex (p
, &xlen
);
4551 p
++; /* skip a comma */
4552 cond
= (char *) xmalloc (2 * xlen
+ 1);
4553 strncpy (cond
, p
, 2 * xlen
);
4554 cond
[2 * xlen
] = '\0';
4558 warning (_("Unrecognized char '%c' in tracepoint "
4559 "definition, skipping rest"), *p
);
4561 utp
= get_uploaded_tp (num
, addr
, utpp
);
4563 utp
->enabled
= enabled
;
4568 else if (piece
== 'A')
4570 utp
= get_uploaded_tp (num
, addr
, utpp
);
4571 VEC_safe_push (char_ptr
, utp
->actions
, xstrdup (p
));
4573 else if (piece
== 'S')
4575 utp
= get_uploaded_tp (num
, addr
, utpp
);
4576 VEC_safe_push (char_ptr
, utp
->step_actions
, xstrdup (p
));
4578 else if (piece
== 'Z')
4580 /* Parse a chunk of source form definition. */
4581 utp
= get_uploaded_tp (num
, addr
, utpp
);
4583 p
= strchr (p
, ':');
4584 p
++; /* skip a colon */
4585 p
= unpack_varlen_hex (p
, &start
);
4586 p
++; /* skip a colon */
4587 p
= unpack_varlen_hex (p
, &xlen
);
4588 p
++; /* skip a colon */
4590 buf
= alloca (strlen (line
));
4592 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
4595 if (strncmp (srctype
, "at:", strlen ("at:")) == 0)
4596 utp
->at_string
= xstrdup (buf
);
4597 else if (strncmp (srctype
, "cond:", strlen ("cond:")) == 0)
4598 utp
->cond_string
= xstrdup (buf
);
4599 else if (strncmp (srctype
, "cmd:", strlen ("cmd:")) == 0)
4600 VEC_safe_push (char_ptr
, utp
->cmd_strings
, xstrdup (buf
));
4602 else if (piece
== 'V')
4604 utp
= get_uploaded_tp (num
, addr
, utpp
);
4606 parse_tracepoint_status (p
, NULL
, utp
);
4610 /* Don't error out, the target might be sending us optional
4611 info that we don't care about. */
4612 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece
);
4616 /* Convert a textual description of a trace state variable into an
4620 parse_tsv_definition (char *line
, struct uploaded_tsv
**utsvp
)
4623 ULONGEST num
, initval
, builtin
;
4625 struct uploaded_tsv
*utsv
= NULL
;
4627 buf
= alloca (strlen (line
));
4630 p
= unpack_varlen_hex (p
, &num
);
4631 p
++; /* skip a colon */
4632 p
= unpack_varlen_hex (p
, &initval
);
4633 p
++; /* skip a colon */
4634 p
= unpack_varlen_hex (p
, &builtin
);
4635 p
++; /* skip a colon */
4636 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
4639 utsv
= get_uploaded_tsv (num
, utsvp
);
4640 utsv
->initial_value
= initval
;
4641 utsv
->builtin
= builtin
;
4642 utsv
->name
= xstrdup (buf
);
4645 /* Close the trace file and generally clean up. */
4655 pid
= ptid_get_pid (inferior_ptid
);
4656 inferior_ptid
= null_ptid
; /* Avoid confusion from thread stuff. */
4657 exit_inferior_silent (pid
);
4661 xfree (trace_filename
);
4662 trace_filename
= NULL
;
4666 tfile_files_info (struct target_ops
*t
)
4668 printf_filtered ("\t`%s'\n", trace_filename
);
4671 /* The trace status for a file is that tracing can never be run. */
4674 tfile_get_trace_status (struct trace_status
*ts
)
4676 /* Other bits of trace status were collected as part of opening the
4677 trace files, so nothing to do here. */
4683 tfile_get_tracepoint_status (struct breakpoint
*tp
, struct uploaded_tp
*utp
)
4685 /* Other bits of trace status were collected as part of opening the
4686 trace files, so nothing to do here. */
4689 /* Given the position of a traceframe in the file, figure out what
4690 address the frame was collected at. This would normally be the
4691 value of a collected PC register, but if not available, we
4695 tfile_get_traceframe_address (off_t tframe_offset
)
4699 struct tracepoint
*tp
;
4700 off_t saved_offset
= cur_offset
;
4702 /* FIXME dig pc out of collected registers. */
4704 /* Fall back to using tracepoint address. */
4705 lseek (trace_fd
, tframe_offset
, SEEK_SET
);
4706 tfile_read ((gdb_byte
*) &tpnum
, 2);
4707 tpnum
= (short) extract_signed_integer ((gdb_byte
*) &tpnum
, 2,
4709 (target_gdbarch ()));
4711 tp
= get_tracepoint_by_number_on_target (tpnum
);
4712 /* FIXME this is a poor heuristic if multiple locations. */
4713 if (tp
&& tp
->base
.loc
)
4714 addr
= tp
->base
.loc
->address
;
4716 /* Restore our seek position. */
4717 cur_offset
= saved_offset
;
4718 lseek (trace_fd
, cur_offset
, SEEK_SET
);
4722 /* Given a type of search and some parameters, scan the collection of
4723 traceframes in the file looking for a match. When found, return
4724 both the traceframe and tracepoint number, otherwise -1 for
4728 tfile_trace_find (enum trace_find_type type
, int num
,
4729 ULONGEST addr1
, ULONGEST addr2
, int *tpp
)
4732 int tfnum
= 0, found
= 0;
4733 unsigned int data_size
;
4734 struct tracepoint
*tp
;
4735 off_t offset
, tframe_offset
;
4745 lseek (trace_fd
, trace_frames_offset
, SEEK_SET
);
4746 offset
= trace_frames_offset
;
4749 tframe_offset
= offset
;
4750 tfile_read ((gdb_byte
*) &tpnum
, 2);
4751 tpnum
= (short) extract_signed_integer ((gdb_byte
*) &tpnum
, 2,
4753 (target_gdbarch ()));
4757 tfile_read ((gdb_byte
*) &data_size
, 4);
4758 data_size
= (unsigned int) extract_unsigned_integer
4759 ((gdb_byte
*) &data_size
, 4,
4760 gdbarch_byte_order (target_gdbarch ()));
4763 if (type
== tfind_number
)
4765 /* Looking for a specific trace frame. */
4771 /* Start from the _next_ trace frame. */
4772 if (tfnum
> traceframe_number
)
4777 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
4778 if (tfaddr
== addr1
)
4782 tp
= get_tracepoint (num
);
4783 if (tp
&& tpnum
== tp
->number_on_target
)
4787 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
4788 if (addr1
<= tfaddr
&& tfaddr
<= addr2
)
4792 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
4793 if (!(addr1
<= tfaddr
&& tfaddr
<= addr2
))
4797 internal_error (__FILE__
, __LINE__
, _("unknown tfind type"));
4806 cur_offset
= offset
;
4807 cur_data_size
= data_size
;
4811 /* Skip past the traceframe's data. */
4812 lseek (trace_fd
, data_size
, SEEK_CUR
);
4813 offset
+= data_size
;
4814 /* Update our own count of traceframes. */
4817 /* Did not find what we were looking for. */
4823 /* Prototype of the callback passed to tframe_walk_blocks. */
4824 typedef int (*walk_blocks_callback_func
) (char blocktype
, void *data
);
4826 /* Callback for traceframe_walk_blocks, used to find a given block
4827 type in a traceframe. */
4830 match_blocktype (char blocktype
, void *data
)
4832 char *wantedp
= data
;
4834 if (*wantedp
== blocktype
)
4840 /* Walk over all traceframe block starting at POS offset from
4841 CUR_OFFSET, and call CALLBACK for each block found, passing in DATA
4842 unmodified. If CALLBACK returns true, this returns the position in
4843 the traceframe where the block is found, relative to the start of
4844 the traceframe (cur_offset). Returns -1 if no callback call
4845 returned true, indicating that all blocks have been walked. */
4848 traceframe_walk_blocks (walk_blocks_callback_func callback
,
4849 int pos
, void *data
)
4851 /* Iterate through a traceframe's blocks, looking for a block of the
4854 lseek (trace_fd
, cur_offset
+ pos
, SEEK_SET
);
4855 while (pos
< cur_data_size
)
4857 unsigned short mlen
;
4860 tfile_read (&block_type
, 1);
4864 if ((*callback
) (block_type
, data
))
4870 lseek (trace_fd
, cur_offset
+ pos
+ trace_regblock_size
, SEEK_SET
);
4871 pos
+= trace_regblock_size
;
4874 lseek (trace_fd
, cur_offset
+ pos
+ 8, SEEK_SET
);
4875 tfile_read ((gdb_byte
*) &mlen
, 2);
4876 mlen
= (unsigned short)
4877 extract_unsigned_integer ((gdb_byte
*) &mlen
, 2,
4879 (target_gdbarch ()));
4880 lseek (trace_fd
, mlen
, SEEK_CUR
);
4881 pos
+= (8 + 2 + mlen
);
4884 lseek (trace_fd
, cur_offset
+ pos
+ 4 + 8, SEEK_SET
);
4888 error (_("Unknown block type '%c' (0x%x) in trace frame"),
4889 block_type
, block_type
);
4897 /* Convenience wrapper around traceframe_walk_blocks. Looks for the
4898 position offset of a block of type TYPE_WANTED in the current trace
4899 frame, starting at POS. Returns -1 if no such block was found. */
4902 traceframe_find_block_type (char type_wanted
, int pos
)
4904 return traceframe_walk_blocks (match_blocktype
, pos
, &type_wanted
);
4907 /* Look for a block of saved registers in the traceframe, and get the
4908 requested register from it. */
4911 tfile_fetch_registers (struct target_ops
*ops
,
4912 struct regcache
*regcache
, int regno
)
4914 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4915 int offset
, regn
, regsize
, pc_regno
;
4918 /* An uninitialized reg size says we're not going to be
4919 successful at getting register blocks. */
4920 if (!trace_regblock_size
)
4923 regs
= alloca (trace_regblock_size
);
4925 if (traceframe_find_block_type ('R', 0) >= 0)
4927 tfile_read (regs
, trace_regblock_size
);
4929 /* Assume the block is laid out in GDB register number order,
4930 each register with the size that it has in GDB. */
4932 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
4934 regsize
= register_size (gdbarch
, regn
);
4935 /* Make sure we stay within block bounds. */
4936 if (offset
+ regsize
>= trace_regblock_size
)
4938 if (regcache_register_status (regcache
, regn
) == REG_UNKNOWN
)
4942 regcache_raw_supply (regcache
, regno
, regs
+ offset
);
4945 else if (regno
== -1)
4947 regcache_raw_supply (regcache
, regn
, regs
+ offset
);
4955 /* We get here if no register data has been found. Mark registers
4957 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
4958 regcache_raw_supply (regcache
, regn
, NULL
);
4960 /* We can often usefully guess that the PC is going to be the same
4961 as the address of the tracepoint. */
4962 pc_regno
= gdbarch_pc_regnum (gdbarch
);
4963 if (pc_regno
>= 0 && (regno
== -1 || regno
== pc_regno
))
4965 struct tracepoint
*tp
= get_tracepoint (tracepoint_number
);
4967 if (tp
&& tp
->base
.loc
)
4969 /* But don't try to guess if tracepoint is multi-location... */
4970 if (tp
->base
.loc
->next
)
4972 warning (_("Tracepoint %d has multiple "
4973 "locations, cannot infer $pc"),
4977 /* ... or does while-stepping. */
4978 if (tp
->step_count
> 0)
4980 warning (_("Tracepoint %d does while-stepping, "
4981 "cannot infer $pc"),
4986 store_unsigned_integer (regs
, register_size (gdbarch
, pc_regno
),
4987 gdbarch_byte_order (gdbarch
),
4988 tp
->base
.loc
->address
);
4989 regcache_raw_supply (regcache
, pc_regno
, regs
);
4995 tfile_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4996 const char *annex
, gdb_byte
*readbuf
,
4997 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
4999 /* We're only doing regular memory for now. */
5000 if (object
!= TARGET_OBJECT_MEMORY
)
5003 if (readbuf
== NULL
)
5004 error (_("tfile_xfer_partial: trace file is read-only"));
5006 if (traceframe_number
!= -1)
5010 /* Iterate through the traceframe's blocks, looking for
5012 while ((pos
= traceframe_find_block_type ('M', pos
)) >= 0)
5014 ULONGEST maddr
, amt
;
5015 unsigned short mlen
;
5016 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch ());
5018 tfile_read ((gdb_byte
*) &maddr
, 8);
5019 maddr
= extract_unsigned_integer ((gdb_byte
*) &maddr
, 8,
5021 tfile_read ((gdb_byte
*) &mlen
, 2);
5022 mlen
= (unsigned short)
5023 extract_unsigned_integer ((gdb_byte
*) &mlen
, 2, byte_order
);
5025 /* If the block includes the first part of the desired
5026 range, return as much it has; GDB will re-request the
5027 remainder, which might be in a different block of this
5029 if (maddr
<= offset
&& offset
< (maddr
+ mlen
))
5031 amt
= (maddr
+ mlen
) - offset
;
5035 if (maddr
!= offset
)
5036 lseek (trace_fd
, offset
- maddr
, SEEK_CUR
);
5037 tfile_read (readbuf
, amt
);
5041 /* Skip over this block. */
5042 pos
+= (8 + 2 + mlen
);
5046 /* It's unduly pedantic to refuse to look at the executable for
5047 read-only pieces; so do the equivalent of readonly regions aka
5049 /* FIXME account for relocation at some point. */
5056 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
5058 if ((s
->flags
& SEC_LOAD
) == 0
5059 || (s
->flags
& SEC_READONLY
) == 0)
5063 size
= bfd_get_section_size (s
);
5064 if (vma
<= offset
&& offset
< (vma
+ size
))
5068 amt
= (vma
+ size
) - offset
;
5072 amt
= bfd_get_section_contents (exec_bfd
, s
,
5073 readbuf
, offset
- vma
, amt
);
5079 /* Indicate failure to find the requested memory block. */
5083 /* Iterate through the blocks of a trace frame, looking for a 'V'
5084 block with a matching tsv number. */
5087 tfile_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
5092 /* Iterate over blocks in current frame and find the last 'V'
5093 block in which tsv number is TSVNUM. In one trace frame, there
5094 may be multiple 'V' blocks created for a given trace variable,
5095 and the last matched 'V' block contains the updated value. */
5097 while ((pos
= traceframe_find_block_type ('V', pos
)) >= 0)
5101 tfile_read ((gdb_byte
*) &vnum
, 4);
5102 vnum
= (int) extract_signed_integer ((gdb_byte
*) &vnum
, 4,
5104 (target_gdbarch ()));
5107 tfile_read ((gdb_byte
*) val
, 8);
5108 *val
= extract_signed_integer ((gdb_byte
*) val
, 8,
5110 (target_gdbarch ()));
5120 tfile_has_all_memory (struct target_ops
*ops
)
5126 tfile_has_memory (struct target_ops
*ops
)
5132 tfile_has_stack (struct target_ops
*ops
)
5134 return traceframe_number
!= -1;
5138 tfile_has_registers (struct target_ops
*ops
)
5140 return traceframe_number
!= -1;
5144 tfile_thread_alive (struct target_ops
*ops
, ptid_t ptid
)
5149 /* Callback for traceframe_walk_blocks. Builds a traceframe_info
5150 object for the tfile target's current traceframe. */
5153 build_traceframe_info (char blocktype
, void *data
)
5155 struct traceframe_info
*info
= data
;
5161 struct mem_range
*r
;
5163 unsigned short mlen
;
5165 tfile_read ((gdb_byte
*) &maddr
, 8);
5166 maddr
= extract_unsigned_integer ((gdb_byte
*) &maddr
, 8,
5168 (target_gdbarch ()));
5169 tfile_read ((gdb_byte
*) &mlen
, 2);
5170 mlen
= (unsigned short)
5171 extract_unsigned_integer ((gdb_byte
*) &mlen
,
5172 2, gdbarch_byte_order
5173 (target_gdbarch ()));
5175 r
= VEC_safe_push (mem_range_s
, info
->memory
, NULL
);
5188 warning (_("Unhandled trace block type (%d) '%c ' "
5189 "while building trace frame info."),
5190 blocktype
, blocktype
);
5197 static struct traceframe_info
*
5198 tfile_traceframe_info (void)
5200 struct traceframe_info
*info
= XCNEW (struct traceframe_info
);
5202 traceframe_walk_blocks (build_traceframe_info
, 0, info
);
5207 init_tfile_ops (void)
5209 tfile_ops
.to_shortname
= "tfile";
5210 tfile_ops
.to_longname
= "Local trace dump file";
5212 = "Use a trace file as a target. Specify the filename of the trace file.";
5213 tfile_ops
.to_open
= tfile_open
;
5214 tfile_ops
.to_close
= tfile_close
;
5215 tfile_ops
.to_fetch_registers
= tfile_fetch_registers
;
5216 tfile_ops
.to_xfer_partial
= tfile_xfer_partial
;
5217 tfile_ops
.to_files_info
= tfile_files_info
;
5218 tfile_ops
.to_get_trace_status
= tfile_get_trace_status
;
5219 tfile_ops
.to_get_tracepoint_status
= tfile_get_tracepoint_status
;
5220 tfile_ops
.to_trace_find
= tfile_trace_find
;
5221 tfile_ops
.to_get_trace_state_variable_value
5222 = tfile_get_trace_state_variable_value
;
5223 tfile_ops
.to_stratum
= process_stratum
;
5224 tfile_ops
.to_has_all_memory
= tfile_has_all_memory
;
5225 tfile_ops
.to_has_memory
= tfile_has_memory
;
5226 tfile_ops
.to_has_stack
= tfile_has_stack
;
5227 tfile_ops
.to_has_registers
= tfile_has_registers
;
5228 tfile_ops
.to_traceframe_info
= tfile_traceframe_info
;
5229 tfile_ops
.to_thread_alive
= tfile_thread_alive
;
5230 tfile_ops
.to_magic
= OPS_MAGIC
;
5234 free_current_marker (void *arg
)
5236 struct static_tracepoint_marker
**marker_p
= arg
;
5238 if (*marker_p
!= NULL
)
5240 release_static_tracepoint_marker (*marker_p
);
5247 /* Given a line of text defining a static tracepoint marker, parse it
5248 into a "static tracepoint marker" object. Throws an error is
5249 parsing fails. If PP is non-null, it points to one past the end of
5250 the parsed marker definition. */
5253 parse_static_tracepoint_marker_definition (char *line
, char **pp
,
5254 struct static_tracepoint_marker
*marker
)
5261 p
= unpack_varlen_hex (p
, &addr
);
5262 p
++; /* skip a colon */
5264 marker
->gdbarch
= target_gdbarch ();
5265 marker
->address
= (CORE_ADDR
) addr
;
5267 endp
= strchr (p
, ':');
5269 error (_("bad marker definition: %s"), line
);
5271 marker
->str_id
= xmalloc (endp
- p
+ 1);
5272 end
= hex2bin (p
, (gdb_byte
*) marker
->str_id
, (endp
- p
+ 1) / 2);
5273 marker
->str_id
[end
] = '\0';
5276 p
++; /* skip a colon */
5278 marker
->extra
= xmalloc (strlen (p
) + 1);
5279 end
= hex2bin (p
, (gdb_byte
*) marker
->extra
, strlen (p
) / 2);
5280 marker
->extra
[end
] = '\0';
5286 /* Release a static tracepoint marker's contents. Note that the
5287 object itself isn't released here. There objects are usually on
5291 release_static_tracepoint_marker (struct static_tracepoint_marker
*marker
)
5293 xfree (marker
->str_id
);
5294 marker
->str_id
= NULL
;
5297 /* Print MARKER to gdb_stdout. */
5300 print_one_static_tracepoint_marker (int count
,
5301 struct static_tracepoint_marker
*marker
)
5303 struct command_line
*l
;
5306 char wrap_indent
[80];
5307 char extra_field_indent
[80];
5308 struct ui_out
*uiout
= current_uiout
;
5309 struct cleanup
*bkpt_chain
;
5310 VEC(breakpoint_p
) *tracepoints
;
5312 struct symtab_and_line sal
;
5316 sal
.pc
= marker
->address
;
5318 tracepoints
= static_tracepoints_here (marker
->address
);
5320 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "marker");
5322 /* A counter field to help readability. This is not a stable
5324 ui_out_field_int (uiout
, "count", count
);
5326 ui_out_field_string (uiout
, "marker-id", marker
->str_id
);
5328 ui_out_field_fmt (uiout
, "enabled", "%c",
5329 !VEC_empty (breakpoint_p
, tracepoints
) ? 'y' : 'n');
5330 ui_out_spaces (uiout
, 2);
5332 strcpy (wrap_indent
, " ");
5334 if (gdbarch_addr_bit (marker
->gdbarch
) <= 32)
5335 strcat (wrap_indent
, " ");
5337 strcat (wrap_indent
, " ");
5339 strcpy (extra_field_indent
, " ");
5341 ui_out_field_core_addr (uiout
, "addr", marker
->gdbarch
, marker
->address
);
5343 sal
= find_pc_line (marker
->address
, 0);
5344 sym
= find_pc_sect_function (marker
->address
, NULL
);
5347 ui_out_text (uiout
, "in ");
5348 ui_out_field_string (uiout
, "func",
5349 SYMBOL_PRINT_NAME (sym
));
5350 ui_out_wrap_hint (uiout
, wrap_indent
);
5351 ui_out_text (uiout
, " at ");
5354 ui_out_field_skip (uiout
, "func");
5356 if (sal
.symtab
!= NULL
)
5358 ui_out_field_string (uiout
, "file",
5359 symtab_to_filename_for_display (sal
.symtab
));
5360 ui_out_text (uiout
, ":");
5362 if (ui_out_is_mi_like_p (uiout
))
5364 const char *fullname
= symtab_to_fullname (sal
.symtab
);
5366 ui_out_field_string (uiout
, "fullname", fullname
);
5369 ui_out_field_skip (uiout
, "fullname");
5371 ui_out_field_int (uiout
, "line", sal
.line
);
5375 ui_out_field_skip (uiout
, "fullname");
5376 ui_out_field_skip (uiout
, "line");
5379 ui_out_text (uiout
, "\n");
5380 ui_out_text (uiout
, extra_field_indent
);
5381 ui_out_text (uiout
, _("Data: \""));
5382 ui_out_field_string (uiout
, "extra-data", marker
->extra
);
5383 ui_out_text (uiout
, "\"\n");
5385 if (!VEC_empty (breakpoint_p
, tracepoints
))
5387 struct cleanup
*cleanup_chain
;
5389 struct breakpoint
*b
;
5391 cleanup_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
,
5394 ui_out_text (uiout
, extra_field_indent
);
5395 ui_out_text (uiout
, _("Probed by static tracepoints: "));
5396 for (ix
= 0; VEC_iterate(breakpoint_p
, tracepoints
, ix
, b
); ix
++)
5399 ui_out_text (uiout
, ", ");
5400 ui_out_text (uiout
, "#");
5401 ui_out_field_int (uiout
, "tracepoint-id", b
->number
);
5404 do_cleanups (cleanup_chain
);
5406 if (ui_out_is_mi_like_p (uiout
))
5407 ui_out_field_int (uiout
, "number-of-tracepoints",
5408 VEC_length(breakpoint_p
, tracepoints
));
5410 ui_out_text (uiout
, "\n");
5412 VEC_free (breakpoint_p
, tracepoints
);
5414 do_cleanups (bkpt_chain
);
5418 info_static_tracepoint_markers_command (char *arg
, int from_tty
)
5420 VEC(static_tracepoint_marker_p
) *markers
;
5421 struct cleanup
*old_chain
;
5422 struct static_tracepoint_marker
*marker
;
5423 struct ui_out
*uiout
= current_uiout
;
5426 /* We don't have to check target_can_use_agent and agent's capability on
5427 static tracepoint here, in order to be compatible with older GDBserver.
5428 We don't check USE_AGENT is true or not, because static tracepoints
5429 don't work without in-process agent, so we don't bother users to type
5430 `set agent on' when to use static tracepoint. */
5433 = make_cleanup_ui_out_table_begin_end (uiout
, 5, -1,
5434 "StaticTracepointMarkersTable");
5436 ui_out_table_header (uiout
, 7, ui_left
, "counter", "Cnt");
5438 ui_out_table_header (uiout
, 40, ui_left
, "marker-id", "ID");
5440 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb");
5441 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
5442 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");
5444 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");
5445 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What");
5447 ui_out_table_body (uiout
);
5449 markers
= target_static_tracepoint_markers_by_strid (NULL
);
5450 make_cleanup (VEC_cleanup (static_tracepoint_marker_p
), &markers
);
5453 VEC_iterate (static_tracepoint_marker_p
,
5454 markers
, i
, marker
);
5457 print_one_static_tracepoint_marker (i
+ 1, marker
);
5458 release_static_tracepoint_marker (marker
);
5461 do_cleanups (old_chain
);
5464 /* The $_sdata convenience variable is a bit special. We don't know
5465 for sure type of the value until we actually have a chance to fetch
5466 the data --- the size of the object depends on what has been
5467 collected. We solve this by making $_sdata be an internalvar that
5468 creates a new value on access. */
5470 /* Return a new value with the correct type for the sdata object of
5471 the current trace frame. Return a void value if there's no object
5474 static struct value
*
5475 sdata_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
5481 /* We need to read the whole object before we know its size. */
5482 size
= target_read_alloc (¤t_target
,
5483 TARGET_OBJECT_STATIC_TRACE_DATA
,
5490 type
= init_vector_type (builtin_type (gdbarch
)->builtin_true_char
,
5492 v
= allocate_value (type
);
5493 memcpy (value_contents_raw (v
), buf
, size
);
5498 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
5501 #if !defined(HAVE_LIBEXPAT)
5503 struct traceframe_info
*
5504 parse_traceframe_info (const char *tframe_info
)
5506 static int have_warned
;
5511 warning (_("Can not parse XML trace frame info; XML support "
5512 "was disabled at compile time"));
5518 #else /* HAVE_LIBEXPAT */
5520 #include "xml-support.h"
5522 /* Handle the start of a <memory> element. */
5525 traceframe_info_start_memory (struct gdb_xml_parser
*parser
,
5526 const struct gdb_xml_element
*element
,
5527 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
5529 struct traceframe_info
*info
= user_data
;
5530 struct mem_range
*r
= VEC_safe_push (mem_range_s
, info
->memory
, NULL
);
5531 ULONGEST
*start_p
, *length_p
;
5533 start_p
= xml_find_attribute (attributes
, "start")->value
;
5534 length_p
= xml_find_attribute (attributes
, "length")->value
;
5536 r
->start
= *start_p
;
5537 r
->length
= *length_p
;
5540 /* Discard the constructed trace frame info (if an error occurs). */
5543 free_result (void *p
)
5545 struct traceframe_info
*result
= p
;
5547 free_traceframe_info (result
);
5550 /* The allowed elements and attributes for an XML memory map. */
5552 static const struct gdb_xml_attribute memory_attributes
[] = {
5553 { "start", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
5554 { "length", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
5555 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
5558 static const struct gdb_xml_element traceframe_info_children
[] = {
5559 { "memory", memory_attributes
, NULL
,
5560 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
5561 traceframe_info_start_memory
, NULL
},
5562 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
5565 static const struct gdb_xml_element traceframe_info_elements
[] = {
5566 { "traceframe-info", NULL
, traceframe_info_children
, GDB_XML_EF_NONE
,
5568 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
5571 /* Parse a traceframe-info XML document. */
5573 struct traceframe_info
*
5574 parse_traceframe_info (const char *tframe_info
)
5576 struct traceframe_info
*result
;
5577 struct cleanup
*back_to
;
5579 result
= XCNEW (struct traceframe_info
);
5580 back_to
= make_cleanup (free_result
, result
);
5582 if (gdb_xml_parse_quick (_("trace frame info"),
5583 "traceframe-info.dtd", traceframe_info_elements
,
5584 tframe_info
, result
) == 0)
5586 /* Parsed successfully, keep the result. */
5587 discard_cleanups (back_to
);
5592 do_cleanups (back_to
);
5596 #endif /* HAVE_LIBEXPAT */
5598 /* Returns the traceframe_info object for the current traceframe.
5599 This is where we avoid re-fetching the object from the target if we
5600 already have it cached. */
5602 static struct traceframe_info
*
5603 get_traceframe_info (void)
5605 if (traceframe_info
== NULL
)
5606 traceframe_info
= target_traceframe_info ();
5608 return traceframe_info
;
5611 /* If the target supports the query, return in RESULT the set of
5612 collected memory in the current traceframe, found within the LEN
5613 bytes range starting at MEMADDR. Returns true if the target
5614 supports the query, otherwise returns false, and RESULT is left
5618 traceframe_available_memory (VEC(mem_range_s
) **result
,
5619 CORE_ADDR memaddr
, ULONGEST len
)
5621 struct traceframe_info
*info
= get_traceframe_info ();
5625 struct mem_range
*r
;
5630 for (i
= 0; VEC_iterate (mem_range_s
, info
->memory
, i
, r
); i
++)
5631 if (mem_ranges_overlap (r
->start
, r
->length
, memaddr
, len
))
5633 ULONGEST lo1
, hi1
, lo2
, hi2
;
5634 struct mem_range
*nr
;
5637 hi1
= memaddr
+ len
;
5640 hi2
= r
->start
+ r
->length
;
5642 nr
= VEC_safe_push (mem_range_s
, *result
, NULL
);
5644 nr
->start
= max (lo1
, lo2
);
5645 nr
->length
= min (hi1
, hi2
) - nr
->start
;
5648 normalize_mem_ranges (*result
);
5655 /* Implementation of `sdata' variable. */
5657 static const struct internalvar_funcs sdata_funcs
=
5664 /* module initialization */
5666 _initialize_tracepoint (void)
5668 struct cmd_list_element
*c
;
5670 /* Explicitly create without lookup, since that tries to create a
5671 value with a void typed value, and when we get here, gdbarch
5672 isn't initialized yet. At this point, we're quite sure there
5673 isn't another convenience variable of the same name. */
5674 create_internalvar_type_lazy ("_sdata", &sdata_funcs
, NULL
);
5676 traceframe_number
= -1;
5677 tracepoint_number
= -1;
5679 if (tracepoint_list
.list
== NULL
)
5681 tracepoint_list
.listsize
= 128;
5682 tracepoint_list
.list
= xmalloc
5683 (tracepoint_list
.listsize
* sizeof (struct memrange
));
5685 if (tracepoint_list
.aexpr_list
== NULL
)
5687 tracepoint_list
.aexpr_listsize
= 128;
5688 tracepoint_list
.aexpr_list
= xmalloc
5689 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
5692 if (stepping_list
.list
== NULL
)
5694 stepping_list
.listsize
= 128;
5695 stepping_list
.list
= xmalloc
5696 (stepping_list
.listsize
* sizeof (struct memrange
));
5699 if (stepping_list
.aexpr_list
== NULL
)
5701 stepping_list
.aexpr_listsize
= 128;
5702 stepping_list
.aexpr_list
= xmalloc
5703 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
5706 add_info ("scope", scope_info
,
5707 _("List the variables local to a scope"));
5709 add_cmd ("tracepoints", class_trace
, NULL
,
5710 _("Tracing of program execution without stopping the program."),
5713 add_com ("tdump", class_trace
, trace_dump_command
,
5714 _("Print everything collected at the current tracepoint."));
5716 add_com ("tsave", class_trace
, trace_save_command
, _("\
5717 Save the trace data to a file.\n\
5718 Use the '-ctf' option to save the data to CTF format.\n\
5719 Use the '-r' option to direct the target to save directly to the file,\n\
5720 using its own filesystem."));
5722 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
5723 Define a trace state variable.\n\
5724 Argument is a $-prefixed name, optionally followed\n\
5725 by '=' and an expression that sets the initial value\n\
5726 at the start of tracing."));
5727 set_cmd_completer (c
, expression_completer
);
5729 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
5730 Delete one or more trace state variables.\n\
5731 Arguments are the names of the variables to delete.\n\
5732 If no arguments are supplied, delete all variables."), &deletelist
);
5733 /* FIXME add a trace variable completer. */
5735 add_info ("tvariables", tvariables_info
, _("\
5736 Status of trace state variables and their values.\n\
5739 add_info ("static-tracepoint-markers",
5740 info_static_tracepoint_markers_command
, _("\
5741 List target static tracepoints markers.\n\
5744 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
5745 Select a trace frame;\n\
5746 No argument means forward by one frame; '-' means backward by one frame."),
5747 &tfindlist
, "tfind ", 1, &cmdlist
);
5749 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
5750 Select a trace frame whose PC is outside the given range (exclusive).\n\
5751 Usage: tfind outside addr1, addr2"),
5754 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
5755 Select a trace frame whose PC is in the given range (inclusive).\n\
5756 Usage: tfind range addr1,addr2"),
5759 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
5760 Select a trace frame by source line.\n\
5761 Argument can be a line number (with optional source file),\n\
5762 a function name, or '*' followed by an address.\n\
5763 Default argument is 'the next source line that was traced'."),
5766 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
5767 Select a trace frame by tracepoint number.\n\
5768 Default is the tracepoint for the current trace frame."),
5771 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
5772 Select a trace frame by PC.\n\
5773 Default is the current PC, or the PC of the current trace frame."),
5776 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
5777 De-select any trace frame and resume 'live' debugging."),
5780 add_alias_cmd ("none", "end", class_trace
, 0, &tfindlist
);
5782 add_cmd ("start", class_trace
, trace_find_start_command
,
5783 _("Select the first trace frame in the trace buffer."),
5786 add_com ("tstatus", class_trace
, trace_status_command
,
5787 _("Display the status of the current trace data collection."));
5789 add_com ("tstop", class_trace
, trace_stop_command
, _("\
5790 Stop trace data collection.\n\
5791 Usage: tstop [ <notes> ... ]\n\
5792 Any arguments supplied are recorded with the trace as a stop reason and\n\
5793 reported by tstatus (if the target supports trace notes)."));
5795 add_com ("tstart", class_trace
, trace_start_command
, _("\
5796 Start trace data collection.\n\
5797 Usage: tstart [ <notes> ... ]\n\
5798 Any arguments supplied are recorded with the trace as a note and\n\
5799 reported by tstatus (if the target supports trace notes)."));
5801 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
5802 Ends a list of commands or actions.\n\
5803 Several GDB commands allow you to enter a list of commands or actions.\n\
5804 Entering \"end\" on a line by itself is the normal way to terminate\n\
5806 Note: the \"end\" command cannot be used at the gdb prompt."));
5808 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
5809 Specify single-stepping behavior at a tracepoint.\n\
5810 Argument is number of instructions to trace in single-step mode\n\
5811 following the tracepoint. This command is normally followed by\n\
5812 one or more \"collect\" commands, to specify what to collect\n\
5813 while single-stepping.\n\n\
5814 Note: this command can only be used in a tracepoint \"actions\" list."));
5816 add_com_alias ("ws", "while-stepping", class_alias
, 0);
5817 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
5819 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
5820 Specify one or more data items to be collected at a tracepoint.\n\
5821 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
5822 collect all data (variables, registers) referenced by that expression.\n\
5823 Also accepts the following special arguments:\n\
5824 $regs -- all registers.\n\
5825 $args -- all function arguments.\n\
5826 $locals -- all variables local to the block/function scope.\n\
5827 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
5828 Note: this command can only be used in a tracepoint \"actions\" list."));
5830 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
5831 Specify one or more expressions to be evaluated at a tracepoint.\n\
5832 Accepts a comma-separated list of (one or more) expressions.\n\
5833 The result of each evaluation will be discarded.\n\
5834 Note: this command can only be used in a tracepoint \"actions\" list."));
5836 add_com ("actions", class_trace
, trace_actions_command
, _("\
5837 Specify the actions to be taken at a tracepoint.\n\
5838 Tracepoint actions may include collecting of specified data,\n\
5839 single-stepping, or enabling/disabling other tracepoints,\n\
5840 depending on target's capabilities."));
5842 default_collect
= xstrdup ("");
5843 add_setshow_string_cmd ("default-collect", class_trace
,
5844 &default_collect
, _("\
5845 Set the list of expressions to collect by default"), _("\
5846 Show the list of expressions to collect by default"), NULL
,
5848 &setlist
, &showlist
);
5850 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
5851 &disconnected_tracing
, _("\
5852 Set whether tracing continues after GDB disconnects."), _("\
5853 Show whether tracing continues after GDB disconnects."), _("\
5854 Use this to continue a tracing run even if GDB disconnects\n\
5855 or detaches from the target. You can reconnect later and look at\n\
5856 trace data collected in the meantime."),
5857 set_disconnected_tracing
,
5862 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
5863 &circular_trace_buffer
, _("\
5864 Set target's use of circular trace buffer."), _("\
5865 Show target's use of circular trace buffer."), _("\
5866 Use this to make the trace buffer into a circular buffer,\n\
5867 which will discard traceframes (oldest first) instead of filling\n\
5868 up and stopping the trace run."),
5869 set_circular_trace_buffer
,
5874 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class
,
5875 &trace_buffer_size
, _("\
5876 Set requested size of trace buffer."), _("\
5877 Show requested size of trace buffer."), _("\
5878 Use this to choose a size for the trace buffer. Some targets\n\
5879 may have fixed or limited buffer sizes. A value of -1 disables\n\
5880 any attempt to set the buffer size and lets the target choose."),
5881 set_trace_buffer_size
, NULL
,
5882 &setlist
, &showlist
);
5884 add_setshow_string_cmd ("trace-user", class_trace
,
5886 Set the user name to use for current and future trace runs"), _("\
5887 Show the user name to use for current and future trace runs"), NULL
,
5888 set_trace_user
, NULL
,
5889 &setlist
, &showlist
);
5891 add_setshow_string_cmd ("trace-notes", class_trace
,
5893 Set notes string to use for current and future trace runs"), _("\
5894 Show the notes string to use for current and future trace runs"), NULL
,
5895 set_trace_notes
, NULL
,
5896 &setlist
, &showlist
);
5898 add_setshow_string_cmd ("trace-stop-notes", class_trace
,
5899 &trace_stop_notes
, _("\
5900 Set notes string to use for future tstop commands"), _("\
5901 Show the notes string to use for future tstop commands"), NULL
,
5902 set_trace_stop_notes
, NULL
,
5903 &setlist
, &showlist
);
5907 add_target (&tfile_ops
);