1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
26 #include "expression.h"
31 #include "gdb_string.h"
33 #include "breakpoint.h"
34 #include "tracepoint.h"
37 #include "completer.h"
39 #include "dictionary.h"
41 #include "user-regs.h"
45 #include "filenames.h"
46 #include "gdbthread.h"
56 /* readline include files */
57 #include "readline/readline.h"
58 #include "readline/history.h"
60 /* readline defines this. */
71 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
72 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
74 extern void stop_tracing ();
76 /* Maximum length of an agent aexpression.
77 This accounts for the fact that packets are limited to 400 bytes
78 (which includes everything -- including the checksum), and assumes
79 the worst case of maximum length for each of the pieces of a
82 NOTE: expressions get mem2hex'ed otherwise this would be twice as
83 large. (400 - 31)/2 == 184 */
84 #define MAX_AGENT_EXPR_LEN 184
86 /* A hook used to notify the UI of tracepoint operations. */
88 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
89 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
91 extern void (*deprecated_readline_begin_hook
) (char *, ...);
92 extern char *(*deprecated_readline_hook
) (char *);
93 extern void (*deprecated_readline_end_hook
) (void);
95 /* GDB commands implemented in other modules:
98 extern void output_command (char *, int);
103 This module defines the following debugger commands:
104 trace : set a tracepoint on a function, line, or address.
105 info trace : list all debugger-defined tracepoints.
106 delete trace : delete one or more tracepoints.
107 enable trace : enable one or more tracepoints.
108 disable trace : disable one or more tracepoints.
109 actions : specify actions to be taken at a tracepoint.
110 passcount : specify a pass count for a tracepoint.
111 tstart : start a trace experiment.
112 tstop : stop a trace experiment.
113 tstatus : query the status of a trace experiment.
114 tfind : find a trace frame in the trace buffer.
115 tdump : print everything collected at the current tracepoint.
116 save-tracepoints : write tracepoint setup into a file.
118 This module defines the following user-visible debugger variables:
119 $trace_frame : sequence number of trace frame currently being debugged.
120 $trace_line : source line of trace frame currently being debugged.
121 $trace_file : source file of trace frame currently being debugged.
122 $tracepoint : tracepoint number of trace frame currently being debugged.
126 /* ======= Important global variables: ======= */
128 /* The list of all trace state variables. We don't retain pointers to
129 any of these for any reason - API is by name or number only - so it
130 works to have a vector of objects. */
132 typedef struct trace_state_variable tsv_s
;
135 /* An object describing the contents of a traceframe. */
137 struct traceframe_info
139 /* Collected memory. */
140 VEC(mem_range_s
) *memory
;
143 static VEC(tsv_s
) *tvariables
;
145 /* The next integer to assign to a variable. */
147 static int next_tsv_number
= 1;
149 /* Number of last traceframe collected. */
150 static int traceframe_number
;
152 /* Tracepoint for last traceframe collected. */
153 static int tracepoint_number
;
155 /* Symbol for function for last traceframe collected. */
156 static struct symbol
*traceframe_fun
;
158 /* Symtab and line for last traceframe collected. */
159 static struct symtab_and_line traceframe_sal
;
161 /* The traceframe info of the current traceframe. NULL if we haven't
162 yet attempted to fetch it, or if the target does not support
163 fetching this object, or if we're not inspecting a traceframe
165 static struct traceframe_info
*traceframe_info
;
167 /* Tracing command lists. */
168 static struct cmd_list_element
*tfindlist
;
170 /* List of expressions to collect by default at each tracepoint hit. */
171 char *default_collect
= "";
173 static int disconnected_tracing
;
175 /* This variable controls whether we ask the target for a linear or
176 circular trace buffer. */
178 static int circular_trace_buffer
;
180 /* ======= Important command functions: ======= */
181 static void trace_actions_command (char *, int);
182 static void trace_start_command (char *, int);
183 static void trace_stop_command (char *, int);
184 static void trace_status_command (char *, int);
185 static void trace_find_command (char *, int);
186 static void trace_find_pc_command (char *, int);
187 static void trace_find_tracepoint_command (char *, int);
188 static void trace_find_line_command (char *, int);
189 static void trace_find_range_command (char *, int);
190 static void trace_find_outside_command (char *, int);
191 static void trace_dump_command (char *, int);
193 /* support routines */
195 struct collection_list
;
196 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
197 static char *mem2hex (gdb_byte
*, char *, int);
198 static void add_register (struct collection_list
*collection
,
201 extern void send_disconnected_tracing_value (int value
);
203 static void free_uploaded_tps (struct uploaded_tp
**utpp
);
204 static void free_uploaded_tsvs (struct uploaded_tsv
**utsvp
);
207 extern void _initialize_tracepoint (void);
209 static struct trace_status trace_status
;
211 char *stop_reason_names
[] = {
221 struct trace_status
*
222 current_trace_status ()
224 return &trace_status
;
230 free_traceframe_info (struct traceframe_info
*info
)
234 VEC_free (mem_range_s
, info
->memory
);
240 /* Free and and clear the traceframe info cache of the current
244 clear_traceframe_info (void)
246 free_traceframe_info (traceframe_info
);
247 traceframe_info
= NULL
;
250 /* Set traceframe number to NUM. */
252 set_traceframe_num (int num
)
254 traceframe_number
= num
;
255 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
258 /* Set tracepoint number to NUM. */
260 set_tracepoint_num (int num
)
262 tracepoint_number
= num
;
263 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
266 /* Set externally visible debug variables for querying/printing
267 the traceframe context (line, function, file). */
270 set_traceframe_context (struct frame_info
*trace_frame
)
274 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
277 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
278 traceframe_sal
.symtab
= NULL
;
279 clear_internalvar (lookup_internalvar ("trace_func"));
280 clear_internalvar (lookup_internalvar ("trace_file"));
281 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
285 /* Save as globals for internal use. */
286 trace_pc
= get_frame_pc (trace_frame
);
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
);
295 /* Save func name as "$trace_func", a debugger variable visible to
297 if (traceframe_fun
== NULL
298 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
299 clear_internalvar (lookup_internalvar ("trace_func"));
301 set_internalvar_string (lookup_internalvar ("trace_func"),
302 SYMBOL_LINKAGE_NAME (traceframe_fun
));
304 /* Save file name as "$trace_file", a debugger variable visible to
306 if (traceframe_sal
.symtab
== NULL
307 || traceframe_sal
.symtab
->filename
== NULL
)
308 clear_internalvar (lookup_internalvar ("trace_file"));
310 set_internalvar_string (lookup_internalvar ("trace_file"),
311 traceframe_sal
.symtab
->filename
);
314 /* Create a new trace state variable with the given name. */
316 struct trace_state_variable
*
317 create_trace_state_variable (const char *name
)
319 struct trace_state_variable tsv
;
321 memset (&tsv
, 0, sizeof (tsv
));
322 tsv
.name
= xstrdup (name
);
323 tsv
.number
= next_tsv_number
++;
324 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
327 /* Look for a trace state variable of the given name. */
329 struct trace_state_variable
*
330 find_trace_state_variable (const char *name
)
332 struct trace_state_variable
*tsv
;
335 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
336 if (strcmp (name
, tsv
->name
) == 0)
343 delete_trace_state_variable (const char *name
)
345 struct trace_state_variable
*tsv
;
348 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
349 if (strcmp (name
, tsv
->name
) == 0)
351 xfree ((void *)tsv
->name
);
352 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
356 warning (_("No trace variable named \"$%s\", not deleting"), name
);
359 /* The 'tvariable' command collects a name and optional expression to
360 evaluate into an initial value. */
363 trace_variable_command (char *args
, int from_tty
)
365 struct expression
*expr
;
366 struct cleanup
*old_chain
;
367 struct internalvar
*intvar
= NULL
;
369 struct trace_state_variable
*tsv
;
372 error_no_arg (_("trace state variable name"));
374 /* All the possible valid arguments are expressions. */
375 expr
= parse_expression (args
);
376 old_chain
= make_cleanup (free_current_contents
, &expr
);
378 if (expr
->nelts
== 0)
379 error (_("No expression?"));
381 /* Only allow two syntaxes; "$name" and "$name=value". */
382 if (expr
->elts
[0].opcode
== OP_INTERNALVAR
)
384 intvar
= expr
->elts
[1].internalvar
;
386 else if (expr
->elts
[0].opcode
== BINOP_ASSIGN
387 && expr
->elts
[1].opcode
== OP_INTERNALVAR
)
389 intvar
= expr
->elts
[2].internalvar
;
390 initval
= value_as_long (evaluate_subexpression_type (expr
, 4));
393 error (_("Syntax must be $NAME [ = EXPR ]"));
396 error (_("No name given"));
398 if (strlen (internalvar_name (intvar
)) <= 0)
399 error (_("Must supply a non-empty variable name"));
401 /* If the variable already exists, just change its initial value. */
402 tsv
= find_trace_state_variable (internalvar_name (intvar
));
405 tsv
->initial_value
= initval
;
406 printf_filtered (_("Trace state variable $%s "
407 "now has initial value %s.\n"),
408 tsv
->name
, plongest (tsv
->initial_value
));
409 do_cleanups (old_chain
);
413 /* Create a new variable. */
414 tsv
= create_trace_state_variable (internalvar_name (intvar
));
415 tsv
->initial_value
= initval
;
417 printf_filtered (_("Trace state variable $%s "
418 "created, with initial value %s.\n"),
419 tsv
->name
, plongest (tsv
->initial_value
));
421 do_cleanups (old_chain
);
425 delete_trace_variable_command (char *args
, int from_tty
)
429 struct cleanup
*back_to
;
433 if (query (_("Delete all trace state variables? ")))
434 VEC_free (tsv_s
, tvariables
);
439 argv
= gdb_buildargv (args
);
440 back_to
= make_cleanup_freeargv (argv
);
442 for (ix
= 0; argv
[ix
] != NULL
; ix
++)
444 if (*argv
[ix
] == '$')
445 delete_trace_state_variable (argv
[ix
] + 1);
447 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv
[ix
]);
450 do_cleanups (back_to
);
456 tvariables_info_1 (void)
458 struct trace_state_variable
*tsv
;
461 struct cleanup
*back_to
;
463 if (VEC_length (tsv_s
, tvariables
) == 0 && !ui_out_is_mi_like_p (uiout
))
465 printf_filtered (_("No trace state variables.\n"));
469 /* Try to acquire values from the target. */
470 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
, ++count
)
471 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
474 back_to
= make_cleanup_ui_out_table_begin_end (uiout
, 3,
475 count
, "trace-variables");
476 ui_out_table_header (uiout
, 15, ui_left
, "name", "Name");
477 ui_out_table_header (uiout
, 11, ui_left
, "initial", "Initial");
478 ui_out_table_header (uiout
, 11, ui_left
, "current", "Current");
480 ui_out_table_body (uiout
);
482 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
484 struct cleanup
*back_to2
;
488 back_to2
= make_cleanup_ui_out_tuple_begin_end (uiout
, "variable");
490 name
= concat ("$", tsv
->name
, (char *) NULL
);
491 make_cleanup (xfree
, name
);
492 ui_out_field_string (uiout
, "name", name
);
493 ui_out_field_string (uiout
, "initial", plongest (tsv
->initial_value
));
495 if (tsv
->value_known
)
496 c
= plongest (tsv
->value
);
497 else if (ui_out_is_mi_like_p (uiout
))
498 /* For MI, we prefer not to use magic string constants, but rather
499 omit the field completely. The difference between unknown and
500 undefined does not seem important enough to represent. */
502 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
503 /* The value is/was defined, but we don't have it. */
506 /* It is not meaningful to ask about the value. */
509 ui_out_field_string (uiout
, "current", c
);
510 ui_out_text (uiout
, "\n");
512 do_cleanups (back_to2
);
515 do_cleanups (back_to
);
518 /* List all the trace state variables. */
521 tvariables_info (char *args
, int from_tty
)
523 tvariables_info_1 ();
526 /* Stash definitions of tsvs into the given file. */
529 save_trace_state_variables (struct ui_file
*fp
)
531 struct trace_state_variable
*tsv
;
534 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
536 fprintf_unfiltered (fp
, "tvariable $%s", tsv
->name
);
537 if (tsv
->initial_value
)
538 fprintf_unfiltered (fp
, " = %s", plongest (tsv
->initial_value
));
539 fprintf_unfiltered (fp
, "\n");
543 /* ACTIONS functions: */
545 /* The three functions:
546 collect_pseudocommand,
547 while_stepping_pseudocommand, and
548 end_actions_pseudocommand
549 are placeholders for "commands" that are actually ONLY to be used
550 within a tracepoint action list. If the actual function is ever called,
551 it means that somebody issued the "command" at the top level,
552 which is always an error. */
555 end_actions_pseudocommand (char *args
, int from_tty
)
557 error (_("This command cannot be used at the top level."));
561 while_stepping_pseudocommand (char *args
, int from_tty
)
563 error (_("This command can only be used in a tracepoint actions list."));
567 collect_pseudocommand (char *args
, int from_tty
)
569 error (_("This command can only be used in a tracepoint actions list."));
573 teval_pseudocommand (char *args
, int from_tty
)
575 error (_("This command can only be used in a tracepoint actions list."));
578 /* Enter a list of actions for a tracepoint. */
580 trace_actions_command (char *args
, int from_tty
)
582 struct breakpoint
*t
;
583 struct command_line
*l
;
585 t
= get_tracepoint_by_number (&args
, 0, 1);
589 xstrprintf ("Enter actions for tracepoint %d, one per line.",
591 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
593 l
= read_command_lines (tmpbuf
, from_tty
, 1,
594 check_tracepoint_command
, t
);
595 do_cleanups (cleanups
);
596 breakpoint_set_commands (t
, l
);
598 /* else just return */
601 /* Report the results of checking the agent expression, as errors or
605 report_agent_reqs_errors (struct agent_expr
*aexpr
)
607 /* All of the "flaws" are serious bytecode generation issues that
608 should never occur. */
609 if (aexpr
->flaw
!= agent_flaw_none
)
610 internal_error (__FILE__
, __LINE__
, _("expression is malformed"));
612 /* If analysis shows a stack underflow, GDB must have done something
613 badly wrong in its bytecode generation. */
614 if (aexpr
->min_height
< 0)
615 internal_error (__FILE__
, __LINE__
,
616 _("expression has min height < 0"));
618 /* Issue this error if the stack is predicted to get too deep. The
619 limit is rather arbitrary; a better scheme might be for the
620 target to report how much stack it will have available. The
621 depth roughly corresponds to parenthesization, so a limit of 20
622 amounts to 20 levels of expression nesting, which is actually
623 a pretty big hairy expression. */
624 if (aexpr
->max_height
> 20)
625 error (_("Expression is too complicated."));
628 /* worker function */
630 validate_actionline (char **line
, struct breakpoint
*t
)
632 struct cmd_list_element
*c
;
633 struct expression
*exp
= NULL
;
634 struct cleanup
*old_chain
= NULL
;
636 struct bp_location
*loc
;
637 struct agent_expr
*aexpr
;
639 /* If EOF is typed, *line is NULL. */
643 for (p
= *line
; isspace ((int) *p
);)
646 /* Symbol lookup etc. */
647 if (*p
== '\0') /* empty line: just prompt for another line. */
650 if (*p
== '#') /* comment line */
653 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
655 error (_("`%s' is not a tracepoint action, or is ambiguous."), p
);
657 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
660 { /* Repeat over a comma-separated list. */
661 QUIT
; /* Allow user to bail out with ^C. */
662 while (isspace ((int) *p
))
665 if (*p
== '$') /* Look for special pseudo-symbols. */
667 if (0 == strncasecmp ("reg", p
+ 1, 3)
668 || 0 == strncasecmp ("arg", p
+ 1, 3)
669 || 0 == strncasecmp ("loc", p
+ 1, 3)
670 || 0 == strncasecmp ("_sdata", p
+ 1, 6))
675 /* else fall thru, treat p as an expression and parse it! */
678 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
681 exp
= parse_exp_1 (&p
, block_for_pc (loc
->address
), 1);
682 old_chain
= make_cleanup (free_current_contents
, &exp
);
684 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
686 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
688 error (_("constant `%s' (value %ld) "
689 "will not be collected."),
690 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
691 SYMBOL_VALUE (exp
->elts
[2].symbol
));
693 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
)
694 == LOC_OPTIMIZED_OUT
)
696 error (_("`%s' is optimized away "
697 "and cannot be collected."),
698 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
702 /* We have something to collect, make sure that the expr to
703 bytecode translator can handle it and that it's not too
705 aexpr
= gen_trace_for_expr (loc
->address
, exp
);
706 make_cleanup_free_agent_expr (aexpr
);
708 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
709 error (_("Expression is too complicated."));
713 report_agent_reqs_errors (aexpr
);
715 do_cleanups (old_chain
);
718 while (p
&& *p
++ == ',');
721 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
724 { /* Repeat over a comma-separated list. */
725 QUIT
; /* Allow user to bail out with ^C. */
726 while (isspace ((int) *p
))
730 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
733 /* Only expressions are allowed for this action. */
734 exp
= parse_exp_1 (&p
, block_for_pc (loc
->address
), 1);
735 old_chain
= make_cleanup (free_current_contents
, &exp
);
737 /* We have something to evaluate, make sure that the expr to
738 bytecode translator can handle it and that it's not too
740 aexpr
= gen_eval_for_expr (loc
->address
, exp
);
741 make_cleanup_free_agent_expr (aexpr
);
743 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
744 error (_("Expression is too complicated."));
747 report_agent_reqs_errors (aexpr
);
749 do_cleanups (old_chain
);
752 while (p
&& *p
++ == ',');
755 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
757 char *steparg
; /* In case warning is necessary. */
759 while (isspace ((int) *p
))
763 if (*p
== '\0' || (t
->step_count
= strtol (p
, &p
, 0)) == 0)
764 error (_("while-stepping step count `%s' is malformed."), *line
);
767 else if (cmd_cfunc_eq (c
, printf_command
))
771 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
774 aexpr
= new_agent_expr (loc
->gdbarch
, loc
->address
);
775 old_chain
= make_cleanup_free_agent_expr (aexpr
);
776 string_printf (p
, NULL
, gen_printf_expr_callback
,
778 ax_simple (aexpr
, aop_end
);
779 /* The agent expr include expr for arguments, format string, 1 byte
780 for aop_printf, 1 byte for the number of arguments, 1 byte for
781 size of format string, 1 byte for blank after format string
782 and 1 byte for aop_end. */
783 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
784 error (_("Expression is too complicated."));
785 do_cleanups (old_chain
);
789 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
793 error (_("`%s' is not a supported tracepoint action."), *line
);
797 memrange_absolute
= -1
802 int type
; /* memrange_absolute for absolute memory range,
803 else basereg number. */
804 bfd_signed_vma start
;
808 struct collection_list
810 unsigned char regs_mask
[32]; /* room for up to 256 regs */
813 struct memrange
*list
;
814 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
816 struct agent_expr
**aexpr_list
;
818 /* True is the user requested a collection of "$_sdata", "static
822 tracepoint_list
, stepping_list
;
824 /* MEMRANGE functions: */
826 static int memrange_cmp (const void *, const void *);
828 /* Compare memranges for qsort. */
830 memrange_cmp (const void *va
, const void *vb
)
832 const struct memrange
*a
= va
, *b
= vb
;
834 if (a
->type
< b
->type
)
836 if (a
->type
> b
->type
)
838 if (a
->type
== memrange_absolute
)
840 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
842 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
847 if (a
->start
< b
->start
)
849 if (a
->start
> b
->start
)
855 /* Sort the memrange list using qsort, and merge adjacent memranges. */
857 memrange_sortmerge (struct collection_list
*memranges
)
861 qsort (memranges
->list
, memranges
->next_memrange
,
862 sizeof (struct memrange
), memrange_cmp
);
863 if (memranges
->next_memrange
> 0)
865 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
867 /* If memrange b overlaps or is adjacent to memrange a,
869 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
870 && memranges
->list
[b
].start
<= memranges
->list
[a
].end
)
872 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
873 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
874 continue; /* next b, same a */
878 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
879 sizeof (struct memrange
));
881 memranges
->next_memrange
= a
+ 1;
885 /* Add a register to a collection list. */
887 add_register (struct collection_list
*collection
, unsigned int regno
)
890 printf_filtered ("collect register %d\n", regno
);
891 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
892 error (_("Internal: register number %d too large for tracepoint"),
894 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
897 /* Add a memrange to a collection list. */
899 add_memrange (struct collection_list
*memranges
,
900 int type
, bfd_signed_vma base
,
905 printf_filtered ("(%d,", type
);
907 printf_filtered (",%ld)\n", len
);
910 /* type: memrange_absolute == memory, other n == basereg */
911 memranges
->list
[memranges
->next_memrange
].type
= type
;
912 /* base: addr if memory, offset if reg relative. */
913 memranges
->list
[memranges
->next_memrange
].start
= base
;
914 /* len: we actually save end (base + len) for convenience */
915 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
916 memranges
->next_memrange
++;
917 if (memranges
->next_memrange
>= memranges
->listsize
)
919 memranges
->listsize
*= 2;
920 memranges
->list
= xrealloc (memranges
->list
,
921 memranges
->listsize
);
924 if (type
!= memrange_absolute
) /* Better collect the base register! */
925 add_register (memranges
, type
);
928 /* Add a symbol to a collection list. */
930 collect_symbol (struct collection_list
*collect
,
932 struct gdbarch
*gdbarch
,
933 long frame_regno
, long frame_offset
,
938 bfd_signed_vma offset
;
939 int treat_as_expr
= 0;
941 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
942 switch (SYMBOL_CLASS (sym
))
945 printf_filtered ("%s: don't know symbol class %d\n",
946 SYMBOL_PRINT_NAME (sym
),
950 printf_filtered ("constant %s (value %ld) will not be collected.\n",
951 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
954 offset
= SYMBOL_VALUE_ADDRESS (sym
);
959 sprintf_vma (tmp
, offset
);
960 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
961 SYMBOL_PRINT_NAME (sym
), len
,
964 /* A struct may be a C++ class with static fields, go to general
965 expression handling. */
966 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
969 add_memrange (collect
, memrange_absolute
, offset
, len
);
972 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
974 printf_filtered ("LOC_REG[parm] %s: ",
975 SYMBOL_PRINT_NAME (sym
));
976 add_register (collect
, reg
);
977 /* Check for doubles stored in two registers. */
978 /* FIXME: how about larger types stored in 3 or more regs? */
979 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
980 len
> register_size (gdbarch
, reg
))
981 add_register (collect
, reg
+ 1);
984 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
985 printf_filtered (" (will not collect %s)\n",
986 SYMBOL_PRINT_NAME (sym
));
990 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
993 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
994 SYMBOL_PRINT_NAME (sym
), len
);
996 printf_filtered (" from frame ptr reg %d\n", reg
);
998 add_memrange (collect
, reg
, offset
, len
);
1000 case LOC_REGPARM_ADDR
:
1001 reg
= SYMBOL_VALUE (sym
);
1005 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1006 SYMBOL_PRINT_NAME (sym
), len
);
1007 printf_vma (offset
);
1008 printf_filtered (" from reg %d\n", reg
);
1010 add_memrange (collect
, reg
, offset
, len
);
1014 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1017 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1018 SYMBOL_PRINT_NAME (sym
), len
);
1019 printf_vma (offset
);
1020 printf_filtered (" from frame ptr reg %d\n", reg
);
1022 add_memrange (collect
, reg
, offset
, len
);
1025 case LOC_UNRESOLVED
:
1029 case LOC_OPTIMIZED_OUT
:
1030 printf_filtered ("%s has been optimized out of existence.\n",
1031 SYMBOL_PRINT_NAME (sym
));
1039 /* Expressions are the most general case. */
1042 struct agent_expr
*aexpr
;
1043 struct cleanup
*old_chain1
= NULL
;
1045 aexpr
= gen_trace_for_var (scope
, gdbarch
, sym
);
1047 /* It can happen that the symbol is recorded as a computed
1048 location, but it's been optimized away and doesn't actually
1049 have a location expression. */
1052 printf_filtered ("%s has been optimized out of existence.\n",
1053 SYMBOL_PRINT_NAME (sym
));
1057 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1061 report_agent_reqs_errors (aexpr
);
1063 discard_cleanups (old_chain1
);
1064 add_aexpr (collect
, aexpr
);
1066 /* Take care of the registers. */
1067 if (aexpr
->reg_mask_len
> 0)
1071 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1073 QUIT
; /* Allow user to bail out with ^C. */
1074 if (aexpr
->reg_mask
[ndx1
] != 0)
1076 /* Assume chars have 8 bits. */
1077 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1078 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1079 /* It's used -- record it. */
1080 add_register (collect
, ndx1
* 8 + ndx2
);
1087 /* Data to be passed around in the calls to the locals and args
1090 struct add_local_symbols_data
1092 struct collection_list
*collect
;
1093 struct gdbarch
*gdbarch
;
1100 /* The callback for the locals and args iterators. */
1103 do_collect_symbol (const char *print_name
,
1107 struct add_local_symbols_data
*p
= cb_data
;
1109 collect_symbol (p
->collect
, sym
, p
->gdbarch
, p
->frame_regno
,
1110 p
->frame_offset
, p
->pc
);
1114 /* Add all locals (or args) symbols to collection list. */
1116 add_local_symbols (struct collection_list
*collect
,
1117 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1118 long frame_regno
, long frame_offset
, int type
)
1120 struct block
*block
;
1121 struct add_local_symbols_data cb_data
;
1123 cb_data
.collect
= collect
;
1124 cb_data
.gdbarch
= gdbarch
;
1126 cb_data
.frame_regno
= frame_regno
;
1127 cb_data
.frame_offset
= frame_offset
;
1132 block
= block_for_pc (pc
);
1135 warning (_("Can't collect locals; "
1136 "no symbol table info available.\n"));
1140 iterate_over_block_local_vars (block
, do_collect_symbol
, &cb_data
);
1141 if (cb_data
.count
== 0)
1142 warning (_("No locals found in scope."));
1146 pc
= get_pc_function_start (pc
);
1147 block
= block_for_pc (pc
);
1150 warning (_("Can't collect args; no symbol table info available.\n"));
1154 iterate_over_block_arg_vars (block
, do_collect_symbol
, &cb_data
);
1155 if (cb_data
.count
== 0)
1156 warning (_("No args found in scope."));
1161 add_static_trace_data (struct collection_list
*collection
)
1164 printf_filtered ("collect static trace data\n");
1165 collection
->strace_data
= 1;
1168 /* worker function */
1170 clear_collection_list (struct collection_list
*list
)
1174 list
->next_memrange
= 0;
1175 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1177 free_agent_expr (list
->aexpr_list
[ndx
]);
1178 list
->aexpr_list
[ndx
] = NULL
;
1180 list
->next_aexpr_elt
= 0;
1181 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1182 list
->strace_data
= 0;
1185 /* Reduce a collection list to string form (for gdb protocol). */
1187 stringify_collection_list (struct collection_list
*list
, char *string
)
1189 char temp_buf
[2048];
1193 char *(*str_list
)[];
1197 count
= 1 + 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1198 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1200 if (list
->strace_data
)
1203 printf_filtered ("\nCollecting static trace data\n");
1206 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1210 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1211 if (list
->regs_mask
[i
] != 0) /* Skip leading zeroes in regs_mask. */
1213 if (list
->regs_mask
[i
] != 0) /* Prepare to send regs_mask to the stub. */
1216 printf_filtered ("\nCollecting registers (mask): 0x");
1221 QUIT
; /* Allow user to bail out with ^C. */
1223 printf_filtered ("%02X", list
->regs_mask
[i
]);
1224 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1227 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1231 printf_filtered ("\n");
1232 if (list
->next_memrange
> 0 && info_verbose
)
1233 printf_filtered ("Collecting memranges: \n");
1234 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1236 QUIT
; /* Allow user to bail out with ^C. */
1237 sprintf_vma (tmp2
, list
->list
[i
].start
);
1240 printf_filtered ("(%d, %s, %ld)\n",
1243 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1245 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1247 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1254 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
1256 /* The "%X" conversion specifier expects an unsigned argument,
1257 so passing -1 (memrange_absolute) to it directly gives you
1258 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1260 if (list
->list
[i
].type
== memrange_absolute
)
1261 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1263 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
1266 count
+= strlen (end
);
1267 end
= temp_buf
+ count
;
1270 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1272 QUIT
; /* Allow user to bail out with ^C. */
1273 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1275 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1280 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1281 end
+= 10; /* 'X' + 8 hex digits + ',' */
1284 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1285 end
, list
->aexpr_list
[i
]->len
);
1286 count
+= 2 * list
->aexpr_list
[i
]->len
;
1291 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1296 (*str_list
)[ndx
] = NULL
;
1309 encode_actions_1 (struct command_line
*action
,
1310 struct breakpoint
*t
,
1311 struct bp_location
*tloc
,
1313 LONGEST frame_offset
,
1314 struct collection_list
*collect
,
1315 struct collection_list
*stepping_list
)
1318 struct expression
*exp
= NULL
;
1320 struct value
*tempval
;
1321 struct cmd_list_element
*cmd
;
1322 struct agent_expr
*aexpr
;
1324 for (; action
; action
= action
->next
)
1326 QUIT
; /* Allow user to bail out with ^C. */
1327 action_exp
= action
->line
;
1328 while (isspace ((int) *action_exp
))
1331 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1333 error (_("Bad action list item: %s"), action_exp
);
1335 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1338 { /* Repeat over a comma-separated list. */
1339 QUIT
; /* Allow user to bail out with ^C. */
1340 while (isspace ((int) *action_exp
))
1343 if (0 == strncasecmp ("$reg", action_exp
, 4))
1345 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1346 add_register (collect
, i
);
1347 action_exp
= strchr (action_exp
, ','); /* more? */
1349 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1351 add_local_symbols (collect
,
1357 action_exp
= strchr (action_exp
, ','); /* more? */
1359 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1361 add_local_symbols (collect
,
1367 action_exp
= strchr (action_exp
, ','); /* more? */
1369 else if (0 == strncasecmp ("$_sdata", action_exp
, 7))
1371 add_static_trace_data (collect
);
1372 action_exp
= strchr (action_exp
, ','); /* more? */
1376 unsigned long addr
, len
;
1377 struct cleanup
*old_chain
= NULL
;
1378 struct cleanup
*old_chain1
= NULL
;
1380 exp
= parse_exp_1 (&action_exp
,
1381 block_for_pc (tloc
->address
), 1);
1382 old_chain
= make_cleanup (free_current_contents
, &exp
);
1384 switch (exp
->elts
[0].opcode
)
1388 const char *name
= &exp
->elts
[2].string
;
1390 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1391 name
, strlen (name
));
1393 internal_error (__FILE__
, __LINE__
,
1394 _("Register $%s not available"),
1397 printf_filtered ("OP_REGISTER: ");
1398 add_register (collect
, i
);
1403 /* Safe because we know it's a simple expression. */
1404 tempval
= evaluate_expression (exp
);
1405 addr
= value_address (tempval
);
1406 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1407 add_memrange (collect
, memrange_absolute
, addr
, len
);
1411 collect_symbol (collect
,
1412 exp
->elts
[2].symbol
,
1419 default: /* Full-fledged expression. */
1420 aexpr
= gen_trace_for_expr (tloc
->address
, exp
);
1422 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1426 report_agent_reqs_errors (aexpr
);
1428 discard_cleanups (old_chain1
);
1429 add_aexpr (collect
, aexpr
);
1431 /* Take care of the registers. */
1432 if (aexpr
->reg_mask_len
> 0)
1437 for (ndx1
= 0; ndx1
< aexpr
->reg_mask_len
; ndx1
++)
1439 QUIT
; /* Allow user to bail out with ^C. */
1440 if (aexpr
->reg_mask
[ndx1
] != 0)
1442 /* Assume chars have 8 bits. */
1443 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1444 if (aexpr
->reg_mask
[ndx1
] & (1 << ndx2
))
1445 /* It's used -- record it. */
1446 add_register (collect
,
1453 do_cleanups (old_chain
);
1456 while (action_exp
&& *action_exp
++ == ',');
1458 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1461 { /* Repeat over a comma-separated list. */
1462 QUIT
; /* Allow user to bail out with ^C. */
1463 while (isspace ((int) *action_exp
))
1467 struct cleanup
*old_chain
= NULL
;
1468 struct cleanup
*old_chain1
= NULL
;
1470 exp
= parse_exp_1 (&action_exp
,
1471 block_for_pc (tloc
->address
), 1);
1472 old_chain
= make_cleanup (free_current_contents
, &exp
);
1474 aexpr
= gen_eval_for_expr (tloc
->address
, exp
);
1475 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1478 report_agent_reqs_errors (aexpr
);
1480 discard_cleanups (old_chain1
);
1481 /* Even though we're not officially collecting, add
1482 to the collect list anyway. */
1483 add_aexpr (collect
, aexpr
);
1485 do_cleanups (old_chain
);
1488 while (action_exp
&& *action_exp
++ == ',');
1490 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1492 /* We check against nested while-stepping when setting
1493 breakpoint action, so no way to run into nested
1495 gdb_assert (stepping_list
);
1497 encode_actions_1 (action
->body_list
[0], t
, tloc
, frame_reg
,
1498 frame_offset
, stepping_list
, NULL
);
1500 else if (cmd_cfunc_eq (cmd
, printf_command
))
1503 struct cleanup
*old_chain
= NULL
;
1505 aexpr
= new_agent_expr (tloc
->gdbarch
, tloc
->address
);
1506 old_chain
= make_cleanup_free_agent_expr (aexpr
);
1507 string_printf (action_exp
, NULL
, gen_printf_expr_callback
,
1509 ax_simple (aexpr
, aop_end
);
1512 report_agent_reqs_errors (aexpr
);
1513 discard_cleanups (old_chain
);
1514 add_aexpr (collect
, aexpr
);
1517 error (_("Invalid tracepoint command '%s'"), action
->line
);
1521 /* Render all actions into gdb protocol. */
1523 encode_actions (struct breakpoint
*t
, struct bp_location
*tloc
,
1524 char ***tdp_actions
, char ***stepping_actions
)
1526 static char tdp_buff
[2048], step_buff
[2048];
1527 char *default_collect_line
= NULL
;
1528 struct command_line
*actions
;
1529 struct command_line
*default_collect_action
= NULL
;
1531 LONGEST frame_offset
;
1532 struct cleanup
*back_to
;
1534 back_to
= make_cleanup (null_cleanup
, NULL
);
1536 clear_collection_list (&tracepoint_list
);
1537 clear_collection_list (&stepping_list
);
1539 *tdp_actions
= NULL
;
1540 *stepping_actions
= NULL
;
1542 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1543 t
->loc
->address
, &frame_reg
, &frame_offset
);
1545 actions
= breakpoint_commands (t
);
1547 /* If there are default expressions to collect, make up a collect
1548 action and prepend to the action list to encode. Note that since
1549 validation is per-tracepoint (local var "xyz" might be valid for
1550 one tracepoint and not another, etc), we make up the action on
1551 the fly, and don't cache it. */
1552 if (*default_collect
)
1556 default_collect_line
= xstrprintf ("collect %s", default_collect
);
1557 make_cleanup (xfree
, default_collect_line
);
1559 line
= default_collect_line
;
1560 validate_actionline (&line
, t
);
1562 default_collect_action
= xmalloc (sizeof (struct command_line
));
1563 make_cleanup (xfree
, default_collect_action
);
1564 default_collect_action
->next
= actions
;
1565 default_collect_action
->line
= line
;
1566 actions
= default_collect_action
;
1568 encode_actions_1 (actions
, t
, tloc
, frame_reg
, frame_offset
,
1569 &tracepoint_list
, &stepping_list
);
1571 memrange_sortmerge (&tracepoint_list
);
1572 memrange_sortmerge (&stepping_list
);
1574 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1576 *stepping_actions
= stringify_collection_list (&stepping_list
,
1579 do_cleanups (back_to
);
1583 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1585 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1587 collect
->aexpr_list
=
1588 xrealloc (collect
->aexpr_list
,
1589 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1590 collect
->aexpr_listsize
*= 2;
1592 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1593 collect
->next_aexpr_elt
++;
1598 start_tracing (void)
1600 VEC(breakpoint_p
) *tp_vec
= NULL
;
1602 struct breakpoint
*t
;
1603 struct trace_state_variable
*tsv
;
1604 int any_enabled
= 0, num_to_download
= 0;
1606 tp_vec
= all_tracepoints ();
1608 /* No point in tracing without any tracepoints... */
1609 if (VEC_length (breakpoint_p
, tp_vec
) == 0)
1611 VEC_free (breakpoint_p
, tp_vec
);
1612 error (_("No tracepoints defined, not starting trace"));
1615 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1617 if (t
->enable_state
== bp_enabled
)
1620 if ((t
->type
== bp_fast_tracepoint
1621 ? may_insert_fast_tracepoints
1622 : may_insert_tracepoints
))
1625 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1626 (t
->type
== bp_fast_tracepoint
? "fast " : ""), t
->number
);
1629 /* No point in tracing with only disabled tracepoints. */
1632 VEC_free (breakpoint_p
, tp_vec
);
1633 error (_("No tracepoints enabled, not starting trace"));
1636 if (num_to_download
<= 0)
1638 VEC_free (breakpoint_p
, tp_vec
);
1639 error (_("No tracepoints that may be downloaded, not starting trace"));
1642 target_trace_init ();
1644 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1646 if ((t
->type
== bp_fast_tracepoint
1647 ? !may_insert_fast_tracepoints
1648 : !may_insert_tracepoints
))
1651 t
->number_on_target
= 0;
1652 target_download_tracepoint (t
);
1653 t
->number_on_target
= t
->number
;
1655 VEC_free (breakpoint_p
, tp_vec
);
1657 /* Send down all the trace state variables too. */
1658 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1660 target_download_trace_state_variable (tsv
);
1663 /* Tell target to treat text-like sections as transparent. */
1664 target_trace_set_readonly_regions ();
1665 /* Set some mode flags. */
1666 target_set_disconnected_tracing (disconnected_tracing
);
1667 target_set_circular_trace_buffer (circular_trace_buffer
);
1669 /* Now insert traps and begin collecting data. */
1670 target_trace_start ();
1672 /* Reset our local state. */
1673 set_traceframe_num (-1);
1674 set_tracepoint_num (-1);
1675 set_traceframe_context (NULL
);
1676 current_trace_status()->running
= 1;
1677 clear_traceframe_info ();
1682 Tell target to clear any previous trace experiment.
1683 Walk the list of tracepoints, and send them (and their actions)
1684 to the target. If no errors,
1685 Tell target to start a new trace experiment. */
1688 trace_start_command (char *args
, int from_tty
)
1690 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1692 if (current_trace_status ()->running
)
1695 && !query (_("A trace is running already. Start a new run? ")))
1696 error (_("New trace run not started."));
1704 trace_stop_command (char *args
, int from_tty
)
1706 if (!current_trace_status ()->running
)
1707 error (_("Trace is not running."));
1715 target_trace_stop ();
1716 /* Should change in response to reply? */
1717 current_trace_status ()->running
= 0;
1720 /* tstatus command */
1722 trace_status_command (char *args
, int from_tty
)
1724 struct trace_status
*ts
= current_trace_status ();
1727 status
= target_get_trace_status (ts
);
1732 printf_filtered (_("Using a trace file.\n"));
1735 printf_filtered (_("Trace can not be run on this target.\n"));
1740 if (!ts
->running_known
)
1742 printf_filtered (_("Run/stop status is unknown.\n"));
1744 else if (ts
->running
)
1746 printf_filtered (_("Trace is running on the target.\n"));
1750 switch (ts
->stop_reason
)
1752 case trace_never_run
:
1753 printf_filtered (_("No trace has been run on the target.\n"));
1756 printf_filtered (_("Trace stopped by a tstop command.\n"));
1758 case trace_buffer_full
:
1759 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1761 case trace_disconnected
:
1762 printf_filtered (_("Trace stopped because of disconnection.\n"));
1764 case tracepoint_passcount
:
1765 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1766 ts
->stopping_tracepoint
);
1768 case tracepoint_error
:
1769 if (ts
->stopping_tracepoint
)
1770 printf_filtered (_("Trace stopped by an "
1771 "error (%s, tracepoint %d).\n"),
1772 ts
->error_desc
, ts
->stopping_tracepoint
);
1774 printf_filtered (_("Trace stopped by an error (%s).\n"),
1777 case trace_stop_reason_unknown
:
1778 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1781 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1787 if (ts
->traceframes_created
>= 0
1788 && ts
->traceframe_count
!= ts
->traceframes_created
)
1790 printf_filtered (_("Buffer contains %d trace "
1791 "frames (of %d created total).\n"),
1792 ts
->traceframe_count
, ts
->traceframes_created
);
1794 else if (ts
->traceframe_count
>= 0)
1796 printf_filtered (_("Collected %d trace frames.\n"),
1797 ts
->traceframe_count
);
1800 if (ts
->buffer_free
>= 0)
1802 if (ts
->buffer_size
>= 0)
1804 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1805 ts
->buffer_free
, ts
->buffer_size
);
1806 if (ts
->buffer_size
> 0)
1807 printf_filtered (_(" (%d%% full)"),
1808 ((int) ((((long long) (ts
->buffer_size
1809 - ts
->buffer_free
)) * 100)
1810 / ts
->buffer_size
)));
1811 printf_filtered (_(".\n"));
1814 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1818 if (ts
->disconnected_tracing
)
1819 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1821 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1823 if (ts
->circular_buffer
)
1824 printf_filtered (_("Trace buffer is circular.\n"));
1826 /* Now report on what we're doing with tfind. */
1827 if (traceframe_number
>= 0)
1828 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1829 traceframe_number
, tracepoint_number
);
1831 printf_filtered (_("Not looking at any trace frame.\n"));
1834 /* Report the trace status to uiout, in a way suitable for MI, and not
1835 suitable for CLI. If ON_STOP is true, suppress a few fields that
1836 are not meaningful in the -trace-stop response.
1838 The implementation is essentially parallel to trace_status_command, but
1839 merging them will result in unreadable code. */
1841 trace_status_mi (int on_stop
)
1843 struct trace_status
*ts
= current_trace_status ();
1846 status
= target_get_trace_status (ts
);
1848 if (status
== -1 && !ts
->from_file
)
1850 ui_out_field_string (uiout
, "supported", "0");
1855 ui_out_field_string (uiout
, "supported", "file");
1857 ui_out_field_string (uiout
, "supported", "1");
1859 gdb_assert (ts
->running_known
);
1863 ui_out_field_string (uiout
, "running", "1");
1865 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
1866 Given that the frontend gets the status either on -trace-stop, or from
1867 -trace-status after re-connection, it does not seem like this
1868 information is necessary for anything. It is not necessary for either
1869 figuring the vital state of the target nor for navigation of trace
1870 frames. If the frontend wants to show the current state is some
1871 configure dialog, it can request the value when such dialog is
1872 invoked by the user. */
1876 char *stop_reason
= NULL
;
1877 int stopping_tracepoint
= -1;
1880 ui_out_field_string (uiout
, "running", "0");
1882 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
1884 switch (ts
->stop_reason
)
1887 stop_reason
= "request";
1889 case trace_buffer_full
:
1890 stop_reason
= "overflow";
1892 case trace_disconnected
:
1893 stop_reason
= "disconnection";
1895 case tracepoint_passcount
:
1896 stop_reason
= "passcount";
1897 stopping_tracepoint
= ts
->stopping_tracepoint
;
1899 case tracepoint_error
:
1900 stop_reason
= "error";
1901 stopping_tracepoint
= ts
->stopping_tracepoint
;
1907 ui_out_field_string (uiout
, "stop-reason", stop_reason
);
1908 if (stopping_tracepoint
!= -1)
1909 ui_out_field_int (uiout
, "stopping-tracepoint",
1910 stopping_tracepoint
);
1911 if (ts
->stop_reason
== tracepoint_error
)
1912 ui_out_field_string (uiout
, "error-description",
1918 if (ts
->traceframe_count
!= -1)
1919 ui_out_field_int (uiout
, "frames", ts
->traceframe_count
);
1920 if (ts
->traceframes_created
!= -1)
1921 ui_out_field_int (uiout
, "frames-created", ts
->traceframes_created
);
1922 if (ts
->buffer_size
!= -1)
1923 ui_out_field_int (uiout
, "buffer-size", ts
->buffer_size
);
1924 if (ts
->buffer_free
!= -1)
1925 ui_out_field_int (uiout
, "buffer-free", ts
->buffer_free
);
1927 ui_out_field_int (uiout
, "disconnected", ts
->disconnected_tracing
);
1928 ui_out_field_int (uiout
, "circular", ts
->circular_buffer
);
1931 /* This function handles the details of what to do about an ongoing
1932 tracing run if the user has asked to detach or otherwise disconnect
1935 disconnect_tracing (int from_tty
)
1937 /* It can happen that the target that was tracing went away on its
1938 own, and we didn't notice. Get a status update, and if the
1939 current target doesn't even do tracing, then assume it's not
1941 if (target_get_trace_status (current_trace_status ()) < 0)
1942 current_trace_status ()->running
= 0;
1944 /* If running interactively, give the user the option to cancel and
1945 then decide what to do differently with the run. Scripts are
1946 just going to disconnect and let the target deal with it,
1947 according to how it's been instructed previously via
1948 disconnected-tracing. */
1949 if (current_trace_status ()->running
&& from_tty
)
1951 if (current_trace_status ()->disconnected_tracing
)
1953 if (!query (_("Trace is running and will "
1954 "continue after detach; detach anyway? ")))
1955 error (_("Not confirmed."));
1959 if (!query (_("Trace is running but will "
1960 "stop on detach; detach anyway? ")))
1961 error (_("Not confirmed."));
1965 /* Also we want to be out of tfind mode, otherwise things can get
1966 confusing upon reconnection. Just use these calls instead of
1967 full tfind_1 behavior because we're in the middle of detaching,
1968 and there's no point to updating current stack frame etc. */
1969 set_current_traceframe (-1);
1970 set_traceframe_context (NULL
);
1973 /* Worker function for the various flavors of the tfind command. */
1975 tfind_1 (enum trace_find_type type
, int num
,
1976 ULONGEST addr1
, ULONGEST addr2
,
1979 int target_frameno
= -1, target_tracept
= -1;
1980 struct frame_id old_frame_id
= null_frame_id
;
1981 struct breakpoint
*tp
;
1983 /* Only try to get the current stack frame if we have a chance of
1984 succeeding. In particular, if we're trying to get a first trace
1985 frame while all threads are running, it's not going to succeed,
1986 so leave it with a default value and let the frame comparison
1987 below (correctly) decide to print out the source location of the
1989 if (!(type
== tfind_number
&& num
== -1)
1990 && (has_stack_frames () || traceframe_number
>= 0))
1991 old_frame_id
= get_frame_id (get_current_frame ());
1993 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
1996 if (type
== tfind_number
1998 && target_frameno
== -1)
2000 /* We told the target to get out of tfind mode, and it did. */
2002 else if (target_frameno
== -1)
2004 /* A request for a non-existent trace frame has failed.
2005 Our response will be different, depending on FROM_TTY:
2007 If FROM_TTY is true, meaning that this command was
2008 typed interactively by the user, then give an error
2009 and DO NOT change the state of traceframe_number etc.
2011 However if FROM_TTY is false, meaning that we're either
2012 in a script, a loop, or a user-defined command, then
2013 DON'T give an error, but DO change the state of
2014 traceframe_number etc. to invalid.
2016 The rationalle is that if you typed the command, you
2017 might just have committed a typo or something, and you'd
2018 like to NOT lose your current debugging state. However
2019 if you're in a user-defined command or especially in a
2020 loop, then you need a way to detect that the command
2021 failed WITHOUT aborting. This allows you to write
2022 scripts that search thru the trace buffer until the end,
2023 and then continue on to do something else. */
2026 error (_("Target failed to find requested trace frame."));
2030 printf_filtered ("End of trace buffer.\n");
2031 #if 0 /* dubious now? */
2032 /* The following will not recurse, since it's
2034 trace_find_command ("-1", from_tty
);
2039 tp
= get_tracepoint_by_number_on_target (target_tracept
);
2041 reinit_frame_cache ();
2042 registers_changed ();
2043 target_dcache_invalidate ();
2044 set_traceframe_num (target_frameno
);
2045 clear_traceframe_info ();
2046 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
2047 if (target_frameno
== -1)
2048 set_traceframe_context (NULL
);
2050 set_traceframe_context (get_current_frame ());
2052 if (traceframe_number
>= 0)
2054 /* Use different branches for MI and CLI to make CLI messages
2056 if (ui_out_is_mi_like_p (uiout
))
2058 ui_out_field_string (uiout
, "found", "1");
2059 ui_out_field_int (uiout
, "tracepoint", tracepoint_number
);
2060 ui_out_field_int (uiout
, "traceframe", traceframe_number
);
2064 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2065 traceframe_number
, tracepoint_number
);
2070 if (ui_out_is_mi_like_p (uiout
))
2071 ui_out_field_string (uiout
, "found", "0");
2072 else if (type
== tfind_number
&& num
== -1)
2073 printf_unfiltered (_("No longer looking at any trace frame\n"));
2074 else /* This case may never occur, check. */
2075 printf_unfiltered (_("No trace frame found\n"));
2078 /* If we're in nonstop mode and getting out of looking at trace
2079 frames, there won't be any current frame to go back to and
2082 && (has_stack_frames () || traceframe_number
>= 0))
2084 enum print_what print_what
;
2086 /* NOTE: in imitation of the step command, try to determine
2087 whether we have made a transition from one function to
2088 another. If so, we'll print the "stack frame" (ie. the new
2089 function and it's arguments) -- otherwise we'll just show the
2092 if (frame_id_eq (old_frame_id
,
2093 get_frame_id (get_current_frame ())))
2094 print_what
= SRC_LINE
;
2096 print_what
= SRC_AND_LOC
;
2098 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
2103 /* trace_find_command takes a trace frame number n,
2104 sends "QTFrame:<n>" to the target,
2105 and accepts a reply that may contain several optional pieces
2106 of information: a frame number, a tracepoint number, and an
2107 indication of whether this is a trap frame or a stepping frame.
2109 The minimal response is just "OK" (which indicates that the
2110 target does not give us a frame number or a tracepoint number).
2111 Instead of that, the target may send us a string containing
2113 F<hexnum> (gives the selected frame number)
2114 T<hexnum> (gives the selected tracepoint number)
2119 trace_find_command (char *args
, int from_tty
)
2120 { /* This should only be called with a numeric argument. */
2123 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2124 error (_("May not look at trace frames while trace is running."));
2126 if (args
== 0 || *args
== 0)
2127 { /* TFIND with no args means find NEXT trace frame. */
2128 if (traceframe_number
== -1)
2129 frameno
= 0; /* "next" is first one. */
2131 frameno
= traceframe_number
+ 1;
2133 else if (0 == strcmp (args
, "-"))
2135 if (traceframe_number
== -1)
2136 error (_("not debugging trace buffer"));
2137 else if (from_tty
&& traceframe_number
== 0)
2138 error (_("already at start of trace buffer"));
2140 frameno
= traceframe_number
- 1;
2142 /* A hack to work around eval's need for fp to have been collected. */
2143 else if (0 == strcmp (args
, "-1"))
2146 frameno
= parse_and_eval_long (args
);
2149 error (_("invalid input (%d is less than zero)"), frameno
);
2151 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
2156 trace_find_end_command (char *args
, int from_tty
)
2158 trace_find_command ("-1", from_tty
);
2163 trace_find_none_command (char *args
, int from_tty
)
2165 trace_find_command ("-1", from_tty
);
2170 trace_find_start_command (char *args
, int from_tty
)
2172 trace_find_command ("0", from_tty
);
2175 /* tfind pc command */
2177 trace_find_pc_command (char *args
, int from_tty
)
2181 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2182 error (_("May not look at trace frames while trace is running."));
2184 if (args
== 0 || *args
== 0)
2185 pc
= regcache_read_pc (get_current_regcache ());
2187 pc
= parse_and_eval_address (args
);
2189 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
2192 /* tfind tracepoint command */
2194 trace_find_tracepoint_command (char *args
, int from_tty
)
2197 struct breakpoint
*tp
;
2199 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2200 error (_("May not look at trace frames while trace is running."));
2202 if (args
== 0 || *args
== 0)
2204 if (tracepoint_number
== -1)
2205 error (_("No current tracepoint -- please supply an argument."));
2207 tdp
= tracepoint_number
; /* Default is current TDP. */
2210 tdp
= parse_and_eval_long (args
);
2212 /* If we have the tracepoint on hand, use the number that the
2213 target knows about (which may be different if we disconnected
2214 and reconnected). */
2215 tp
= get_tracepoint (tdp
);
2217 tdp
= tp
->number_on_target
;
2219 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
2222 /* TFIND LINE command:
2224 This command will take a sourceline for argument, just like BREAK
2225 or TRACE (ie. anything that "decode_line_1" can handle).
2227 With no argument, this command will find the next trace frame
2228 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2231 trace_find_line_command (char *args
, int from_tty
)
2233 static CORE_ADDR start_pc
, end_pc
;
2234 struct symtabs_and_lines sals
;
2235 struct symtab_and_line sal
;
2236 struct cleanup
*old_chain
;
2238 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2239 error (_("May not look at trace frames while trace is running."));
2241 if (args
== 0 || *args
== 0)
2243 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2245 sals
.sals
= (struct symtab_and_line
*)
2246 xmalloc (sizeof (struct symtab_and_line
));
2251 sals
= decode_line_spec (args
, 1);
2255 old_chain
= make_cleanup (xfree
, sals
.sals
);
2256 if (sal
.symtab
== 0)
2257 error (_("No line number information available."));
2259 if (sal
.line
> 0 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2261 if (start_pc
== end_pc
)
2263 printf_filtered ("Line %d of \"%s\"",
2264 sal
.line
, sal
.symtab
->filename
);
2266 printf_filtered (" is at address ");
2267 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2269 printf_filtered (" but contains no code.\n");
2270 sal
= find_pc_line (start_pc
, 0);
2272 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2273 && start_pc
!= end_pc
)
2274 printf_filtered ("Attempting to find line %d instead.\n",
2277 error (_("Cannot find a good line."));
2281 /* Is there any case in which we get here, and have an address
2282 which the user would want to see? If we have debugging
2283 symbols and no line numbers? */
2284 error (_("Line number %d is out of range for \"%s\"."),
2285 sal
.line
, sal
.symtab
->filename
);
2287 /* Find within range of stated line. */
2289 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2291 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2292 do_cleanups (old_chain
);
2295 /* tfind range command */
2297 trace_find_range_command (char *args
, int from_tty
)
2299 static CORE_ADDR start
, stop
;
2302 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2303 error (_("May not look at trace frames while trace is running."));
2305 if (args
== 0 || *args
== 0)
2306 { /* XXX FIXME: what should default behavior be? */
2307 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2311 if (0 != (tmp
= strchr (args
, ',')))
2313 *tmp
++ = '\0'; /* Terminate start address. */
2314 while (isspace ((int) *tmp
))
2316 start
= parse_and_eval_address (args
);
2317 stop
= parse_and_eval_address (tmp
);
2320 { /* No explicit end address? */
2321 start
= parse_and_eval_address (args
);
2322 stop
= start
+ 1; /* ??? */
2325 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2328 /* tfind outside command */
2330 trace_find_outside_command (char *args
, int from_tty
)
2332 CORE_ADDR start
, stop
;
2335 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2336 error (_("May not look at trace frames while trace is running."));
2338 if (args
== 0 || *args
== 0)
2339 { /* XXX FIXME: what should default behavior be? */
2340 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2344 if (0 != (tmp
= strchr (args
, ',')))
2346 *tmp
++ = '\0'; /* Terminate start address. */
2347 while (isspace ((int) *tmp
))
2349 start
= parse_and_eval_address (args
);
2350 stop
= parse_and_eval_address (tmp
);
2353 { /* No explicit end address? */
2354 start
= parse_and_eval_address (args
);
2355 stop
= start
+ 1; /* ??? */
2358 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2361 /* info scope command: list the locals for a scope. */
2363 scope_info (char *args
, int from_tty
)
2365 struct symtabs_and_lines sals
;
2367 struct minimal_symbol
*msym
;
2368 struct block
*block
;
2369 char **canonical
, *symname
, *save_args
= args
;
2370 struct dict_iterator iter
;
2372 struct gdbarch
*gdbarch
;
2375 if (args
== 0 || *args
== 0)
2376 error (_("requires an argument (function, "
2377 "line or *addr) to define a scope"));
2379 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
2380 if (sals
.nelts
== 0)
2381 return; /* Presumably decode_line_1 has already warned. */
2383 /* Resolve line numbers to PC. */
2384 resolve_sal_pc (&sals
.sals
[0]);
2385 block
= block_for_pc (sals
.sals
[0].pc
);
2389 QUIT
; /* Allow user to bail out with ^C. */
2390 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2392 QUIT
; /* Allow user to bail out with ^C. */
2394 printf_filtered ("Scope for %s:\n", save_args
);
2397 symname
= SYMBOL_PRINT_NAME (sym
);
2398 if (symname
== NULL
|| *symname
== '\0')
2399 continue; /* Probably botched, certainly useless. */
2401 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
2403 printf_filtered ("Symbol %s is ", symname
);
2404 switch (SYMBOL_CLASS (sym
))
2407 case LOC_UNDEF
: /* Messed up symbol? */
2408 printf_filtered ("a bogus symbol, class %d.\n",
2409 SYMBOL_CLASS (sym
));
2410 count
--; /* Don't count this one. */
2413 printf_filtered ("a constant with value %ld (0x%lx)",
2414 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2416 case LOC_CONST_BYTES
:
2417 printf_filtered ("constant bytes: ");
2418 if (SYMBOL_TYPE (sym
))
2419 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2420 fprintf_filtered (gdb_stdout
, " %02x",
2421 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2424 printf_filtered ("in static storage at address ");
2425 printf_filtered ("%s", paddress (gdbarch
,
2426 SYMBOL_VALUE_ADDRESS (sym
)));
2429 /* GDBARCH is the architecture associated with the objfile
2430 the symbol is defined in; the target architecture may be
2431 different, and may provide additional registers. However,
2432 we do not know the target architecture at this point.
2433 We assume the objfile architecture will contain all the
2434 standard registers that occur in debug info in that
2436 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2439 if (SYMBOL_IS_ARGUMENT (sym
))
2440 printf_filtered ("an argument in register $%s",
2441 gdbarch_register_name (gdbarch
, regno
));
2443 printf_filtered ("a local variable in register $%s",
2444 gdbarch_register_name (gdbarch
, regno
));
2447 printf_filtered ("an argument at stack/frame offset %ld",
2448 SYMBOL_VALUE (sym
));
2451 printf_filtered ("a local variable at frame offset %ld",
2452 SYMBOL_VALUE (sym
));
2455 printf_filtered ("a reference argument at offset %ld",
2456 SYMBOL_VALUE (sym
));
2458 case LOC_REGPARM_ADDR
:
2459 /* Note comment at LOC_REGISTER. */
2460 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
,
2462 printf_filtered ("the address of an argument, in register $%s",
2463 gdbarch_register_name (gdbarch
, regno
));
2466 printf_filtered ("a typedef.\n");
2469 printf_filtered ("a label at address ");
2470 printf_filtered ("%s", paddress (gdbarch
,
2471 SYMBOL_VALUE_ADDRESS (sym
)));
2474 printf_filtered ("a function at address ");
2475 printf_filtered ("%s",
2476 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2478 case LOC_UNRESOLVED
:
2479 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2482 printf_filtered ("Unresolved Static");
2485 printf_filtered ("static storage at address ");
2486 printf_filtered ("%s",
2487 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
2490 case LOC_OPTIMIZED_OUT
:
2491 printf_filtered ("optimized out.\n");
2494 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
,
2495 BLOCK_START (block
),
2499 if (SYMBOL_TYPE (sym
))
2500 printf_filtered (", length %d.\n",
2501 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2503 if (BLOCK_FUNCTION (block
))
2506 block
= BLOCK_SUPERBLOCK (block
);
2509 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2513 /* worker function (cleanup) */
2515 replace_comma (void *data
)
2522 /* Helper for trace_dump_command. Dump the action list starting at
2523 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2524 actions of the body of a while-stepping action. STEPPING_FRAME is
2525 set if the current traceframe was determined to be a while-stepping
2529 trace_dump_actions (struct command_line
*action
,
2530 int stepping_actions
, int stepping_frame
,
2533 char *action_exp
, *next_comma
;
2535 for (; action
!= NULL
; action
= action
->next
)
2537 struct cmd_list_element
*cmd
;
2539 QUIT
; /* Allow user to bail out with ^C. */
2540 action_exp
= action
->line
;
2541 while (isspace ((int) *action_exp
))
2544 /* The collection actions to be done while stepping are
2545 bracketed by the commands "while-stepping" and "end". */
2547 if (*action_exp
== '#') /* comment line */
2550 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2552 error (_("Bad action list item: %s"), action_exp
);
2554 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2558 for (i
= 0; i
< action
->body_count
; ++i
)
2559 trace_dump_actions (action
->body_list
[i
],
2560 1, stepping_frame
, from_tty
);
2562 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2564 /* Display the collected data.
2565 For the trap frame, display only what was collected at
2566 the trap. Likewise for stepping frames, display only
2567 what was collected while stepping. This means that the
2568 two boolean variables, STEPPING_FRAME and
2569 STEPPING_ACTIONS should be equal. */
2570 if (stepping_frame
== stepping_actions
)
2573 { /* Repeat over a comma-separated list. */
2574 QUIT
; /* Allow user to bail out with ^C. */
2575 if (*action_exp
== ',')
2577 while (isspace ((int) *action_exp
))
2580 next_comma
= strchr (action_exp
, ',');
2582 if (0 == strncasecmp (action_exp
, "$reg", 4))
2583 registers_info (NULL
, from_tty
);
2584 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2585 locals_info (NULL
, from_tty
);
2586 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2587 args_info (NULL
, from_tty
);
2592 make_cleanup (replace_comma
, next_comma
);
2595 printf_filtered ("%s = ", action_exp
);
2596 output_command (action_exp
, from_tty
);
2597 printf_filtered ("\n");
2601 action_exp
= next_comma
;
2603 while (action_exp
&& *action_exp
== ',');
2609 /* The tdump command. */
2612 trace_dump_command (char *args
, int from_tty
)
2614 struct regcache
*regcache
;
2615 struct breakpoint
*t
;
2616 int stepping_frame
= 0;
2617 struct bp_location
*loc
;
2618 char *line
, *default_collect_line
= NULL
;
2619 struct command_line
*actions
, *default_collect_action
= NULL
;
2620 struct cleanup
*old_chain
= NULL
;
2622 if (tracepoint_number
== -1)
2624 warning (_("No current trace frame."));
2628 t
= get_tracepoint (tracepoint_number
);
2631 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2634 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2635 tracepoint_number
, traceframe_number
);
2637 /* The current frame is a trap frame if the frame PC is equal
2638 to the tracepoint PC. If not, then the current frame was
2639 collected during single-stepping. */
2641 regcache
= get_current_regcache ();
2643 /* If the traceframe's address matches any of the tracepoint's
2644 locations, assume it is a direct hit rather than a while-stepping
2645 frame. (FIXME this is not reliable, should record each frame's
2648 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
2649 if (loc
->address
== regcache_read_pc (regcache
))
2652 actions
= breakpoint_commands (t
);
2654 /* If there is a default-collect list, make up a collect command,
2655 prepend to the tracepoint's commands, and pass the whole mess to
2656 the trace dump scanner. We need to validate because
2657 default-collect might have been junked since the trace run. */
2658 if (*default_collect
)
2660 default_collect_line
= xstrprintf ("collect %s", default_collect
);
2661 old_chain
= make_cleanup (xfree
, default_collect_line
);
2662 line
= default_collect_line
;
2663 validate_actionline (&line
, t
);
2664 default_collect_action
= xmalloc (sizeof (struct command_line
));
2665 make_cleanup (xfree
, default_collect_action
);
2666 default_collect_action
->next
= actions
;
2667 default_collect_action
->line
= line
;
2668 actions
= default_collect_action
;
2671 trace_dump_actions (actions
, 0, stepping_frame
, from_tty
);
2673 if (*default_collect
)
2674 do_cleanups (old_chain
);
2677 /* Encode a piece of a tracepoint's source-level definition in a form
2678 that is suitable for both protocol and saving in files. */
2679 /* This version does not do multiple encodes for long strings; it should
2680 return an offset to the next piece to encode. FIXME */
2683 encode_source_string (int tpnum
, ULONGEST addr
,
2684 char *srctype
, char *src
, char *buf
, int buf_size
)
2686 if (80 + strlen (srctype
) > buf_size
)
2687 error (_("Buffer too small for source encoding"));
2688 sprintf (buf
, "%x:%s:%s:%x:%x:",
2689 tpnum
, phex_nz (addr
, sizeof (addr
)),
2690 srctype
, 0, (int) strlen (src
));
2691 if (strlen (buf
) + strlen (src
) * 2 >= buf_size
)
2692 error (_("Source string too long for buffer"));
2693 bin2hex (src
, buf
+ strlen (buf
), 0);
2697 extern int trace_regblock_size
;
2699 /* Save tracepoint data to file named FILENAME. If TARGET_DOES_SAVE is
2700 non-zero, the save is performed on the target, otherwise GDB obtains all
2701 trace data and saves it locally. */
2704 trace_save (const char *filename
, int target_does_save
)
2706 struct cleanup
*cleanup
;
2708 struct trace_status
*ts
= current_trace_status ();
2711 struct uploaded_tp
*uploaded_tps
= NULL
, *utp
;
2712 struct uploaded_tsv
*uploaded_tsvs
= NULL
, *utsv
;
2716 ULONGEST offset
= 0;
2717 #define MAX_TRACE_UPLOAD 2000
2718 gdb_byte buf
[MAX_TRACE_UPLOAD
];
2721 /* If the target is to save the data to a file on its own, then just
2722 send the command and be done with it. */
2723 if (target_does_save
)
2725 err
= target_save_trace_data (filename
);
2727 error (_("Target failed to save trace data to '%s'."),
2732 /* Get the trace status first before opening the file, so if the
2733 target is losing, we can get out without touching files. */
2734 status
= target_get_trace_status (ts
);
2736 pathname
= tilde_expand (filename
);
2737 cleanup
= make_cleanup (xfree
, pathname
);
2739 fp
= fopen (pathname
, "wb");
2741 error (_("Unable to open file '%s' for saving trace data (%s)"),
2742 filename
, safe_strerror (errno
));
2743 make_cleanup_fclose (fp
);
2745 /* Write a file header, with a high-bit-set char to indicate a
2746 binary file, plus a hint as what this file is, and a version
2747 number in case of future needs. */
2748 written
= fwrite ("\x7fTRACE0\n", 8, 1, fp
);
2750 perror_with_name (pathname
);
2752 /* Write descriptive info. */
2754 /* Write out the size of a register block. */
2755 fprintf (fp
, "R %x\n", trace_regblock_size
);
2757 /* Write out status of the tracing run (aka "tstatus" info). */
2758 fprintf (fp
, "status %c;%s",
2759 (ts
->running
? '1' : '0'), stop_reason_names
[ts
->stop_reason
]);
2760 if (ts
->stop_reason
== tracepoint_error
)
2762 char *buf
= (char *) alloca (strlen (ts
->error_desc
) * 2 + 1);
2764 bin2hex ((gdb_byte
*) ts
->error_desc
, buf
, 0);
2765 fprintf (fp
, ":%s", buf
);
2767 fprintf (fp
, ":%x", ts
->stopping_tracepoint
);
2768 if (ts
->traceframe_count
>= 0)
2769 fprintf (fp
, ";tframes:%x", ts
->traceframe_count
);
2770 if (ts
->traceframes_created
>= 0)
2771 fprintf (fp
, ";tcreated:%x", ts
->traceframes_created
);
2772 if (ts
->buffer_free
>= 0)
2773 fprintf (fp
, ";tfree:%x", ts
->buffer_free
);
2774 if (ts
->buffer_size
>= 0)
2775 fprintf (fp
, ";tsize:%x", ts
->buffer_size
);
2776 if (ts
->disconnected_tracing
)
2777 fprintf (fp
, ";disconn:%x", ts
->disconnected_tracing
);
2778 if (ts
->circular_buffer
)
2779 fprintf (fp
, ";circular:%x", ts
->circular_buffer
);
2782 /* Note that we want to upload tracepoints and save those, rather
2783 than simply writing out the local ones, because the user may have
2784 changed tracepoints in GDB in preparation for a future tracing
2785 run, or maybe just mass-deleted all types of breakpoints as part
2786 of cleaning up. So as not to contaminate the session, leave the
2787 data in its uploaded form, don't make into real tracepoints. */
2789 /* Get trace state variables first, they may be checked when parsing
2790 uploaded commands. */
2792 target_upload_trace_state_variables (&uploaded_tsvs
);
2794 for (utsv
= uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
2800 buf
= (char *) xmalloc (strlen (utsv
->name
) * 2 + 1);
2801 bin2hex ((gdb_byte
*) (utsv
->name
), buf
, 0);
2804 fprintf (fp
, "tsv %x:%s:%x:%s\n",
2805 utsv
->number
, phex_nz (utsv
->initial_value
, 8),
2806 utsv
->builtin
, buf
);
2812 free_uploaded_tsvs (&uploaded_tsvs
);
2814 target_upload_tracepoints (&uploaded_tps
);
2816 for (utp
= uploaded_tps
; utp
; utp
= utp
->next
)
2818 fprintf (fp
, "tp T%x:%s:%c:%x:%x",
2819 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2820 (utp
->enabled
? 'E' : 'D'), utp
->step
, utp
->pass
);
2821 if (utp
->type
== bp_fast_tracepoint
)
2822 fprintf (fp
, ":F%x", utp
->orig_size
);
2824 fprintf (fp
, ":X%x,%s", (unsigned int) strlen (utp
->cond
) / 2,
2827 for (a
= 0; VEC_iterate (char_ptr
, utp
->actions
, a
, act
); ++a
)
2828 fprintf (fp
, "tp A%x:%s:%s\n",
2829 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)), act
);
2830 for (a
= 0; VEC_iterate (char_ptr
, utp
->step_actions
, a
, act
); ++a
)
2831 fprintf (fp
, "tp S%x:%s:%s\n",
2832 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)), act
);
2835 encode_source_string (utp
->number
, utp
->addr
,
2836 "at", utp
->at_string
, buf
, MAX_TRACE_UPLOAD
);
2837 fprintf (fp
, "tp Z%s\n", buf
);
2839 if (utp
->cond_string
)
2841 encode_source_string (utp
->number
, utp
->addr
,
2842 "cond", utp
->cond_string
,
2843 buf
, MAX_TRACE_UPLOAD
);
2844 fprintf (fp
, "tp Z%s\n", buf
);
2846 for (a
= 0; VEC_iterate (char_ptr
, utp
->cmd_strings
, a
, act
); ++a
)
2848 encode_source_string (utp
->number
, utp
->addr
, "cmd", act
,
2849 buf
, MAX_TRACE_UPLOAD
);
2850 fprintf (fp
, "tp Z%s\n", buf
);
2854 free_uploaded_tps (&uploaded_tps
);
2856 /* Mark the end of the definition section. */
2859 /* Get and write the trace data proper. We ask for big blocks, in
2860 the hopes of efficiency, but will take less if the target has
2861 packet size limitations or some such. */
2864 gotten
= target_get_raw_trace_data (buf
, offset
, MAX_TRACE_UPLOAD
);
2866 error (_("Failure to get requested trace buffer data"));
2867 /* No more data is forthcoming, we're done. */
2870 written
= fwrite (buf
, gotten
, 1, fp
);
2872 perror_with_name (pathname
);
2876 /* Mark the end of trace data. (We know that gotten is 0 at this point.) */
2877 written
= fwrite (&gotten
, 4, 1, fp
);
2879 perror_with_name (pathname
);
2881 do_cleanups (cleanup
);
2885 trace_save_command (char *args
, int from_tty
)
2887 int target_does_save
= 0;
2889 char *filename
= NULL
;
2890 struct cleanup
*back_to
;
2893 error_no_arg (_("file in which to save trace data"));
2895 argv
= gdb_buildargv (args
);
2896 back_to
= make_cleanup_freeargv (argv
);
2898 for (; *argv
; ++argv
)
2900 if (strcmp (*argv
, "-r") == 0)
2901 target_does_save
= 1;
2902 else if (**argv
== '-')
2903 error (_("unknown option `%s'"), *argv
);
2909 error_no_arg (_("file in which to save trace data"));
2911 trace_save (filename
, target_does_save
);
2914 printf_filtered (_("Trace data saved to file '%s'.\n"), args
);
2916 do_cleanups (back_to
);
2919 /* Tell the target what to do with an ongoing tracing run if GDB
2920 disconnects for some reason. */
2923 send_disconnected_tracing_value (int value
)
2925 target_set_disconnected_tracing (value
);
2929 set_disconnected_tracing (char *args
, int from_tty
,
2930 struct cmd_list_element
*c
)
2932 send_disconnected_tracing_value (disconnected_tracing
);
2936 set_circular_trace_buffer (char *args
, int from_tty
,
2937 struct cmd_list_element
*c
)
2939 target_set_circular_trace_buffer (circular_trace_buffer
);
2942 /* Convert the memory pointed to by mem into hex, placing result in buf.
2943 * Return a pointer to the last char put in buf (null)
2944 * "stolen" from sparc-stub.c
2947 static const char hexchars
[] = "0123456789abcdef";
2950 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2958 *buf
++ = hexchars
[ch
>> 4];
2959 *buf
++ = hexchars
[ch
& 0xf];
2968 get_traceframe_number (void)
2970 return traceframe_number
;
2973 /* Make the traceframe NUM be the current trace frame. Does nothing
2974 if NUM is already current. */
2977 set_current_traceframe (int num
)
2981 if (traceframe_number
== num
)
2983 /* Nothing to do. */
2987 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
2990 warning (_("could not change traceframe"));
2992 traceframe_number
= newnum
;
2994 /* Changing the traceframe changes our view of registers and of the
2996 registers_changed ();
2998 clear_traceframe_info ();
3001 /* Make the traceframe NUM be the current trace frame, and do nothing
3005 set_traceframe_number (int num
)
3007 traceframe_number
= num
;
3010 /* A cleanup used when switching away and back from tfind mode. */
3012 struct current_traceframe_cleanup
3014 /* The traceframe we were inspecting. */
3015 int traceframe_number
;
3019 do_restore_current_traceframe_cleanup (void *arg
)
3021 struct current_traceframe_cleanup
*old
= arg
;
3023 set_current_traceframe (old
->traceframe_number
);
3027 restore_current_traceframe_cleanup_dtor (void *arg
)
3029 struct current_traceframe_cleanup
*old
= arg
;
3035 make_cleanup_restore_current_traceframe (void)
3037 struct current_traceframe_cleanup
*old
;
3039 old
= xmalloc (sizeof (struct current_traceframe_cleanup
));
3040 old
->traceframe_number
= traceframe_number
;
3042 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
3043 restore_current_traceframe_cleanup_dtor
);
3047 make_cleanup_restore_traceframe_number (void)
3049 return make_cleanup_restore_integer (&traceframe_number
);
3052 /* Given a number and address, return an uploaded tracepoint with that
3053 number, creating if necessary. */
3055 struct uploaded_tp
*
3056 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
3058 struct uploaded_tp
*utp
;
3060 for (utp
= *utpp
; utp
; utp
= utp
->next
)
3061 if (utp
->number
== num
&& utp
->addr
== addr
)
3063 utp
= (struct uploaded_tp
*) xmalloc (sizeof (struct uploaded_tp
));
3064 memset (utp
, 0, sizeof (struct uploaded_tp
));
3067 utp
->actions
= NULL
;
3068 utp
->step_actions
= NULL
;
3069 utp
->cmd_strings
= NULL
;
3076 free_uploaded_tps (struct uploaded_tp
**utpp
)
3078 struct uploaded_tp
*next_one
;
3082 next_one
= (*utpp
)->next
;
3088 /* Given a number and address, return an uploaded tracepoint with that
3089 number, creating if necessary. */
3091 struct uploaded_tsv
*
3092 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
3094 struct uploaded_tsv
*utsv
;
3096 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
3097 if (utsv
->number
== num
)
3099 utsv
= (struct uploaded_tsv
*) xmalloc (sizeof (struct uploaded_tsv
));
3100 memset (utsv
, 0, sizeof (struct uploaded_tsv
));
3102 utsv
->next
= *utsvp
;
3108 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
3110 struct uploaded_tsv
*next_one
;
3114 next_one
= (*utsvp
)->next
;
3120 /* Look for an existing tracepoint that seems similar enough to the
3121 uploaded one. Enablement isn't compared, because the user can
3122 toggle that freely, and may have done so in anticipation of the
3126 find_matching_tracepoint (struct uploaded_tp
*utp
)
3128 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
3130 struct breakpoint
*t
;
3131 struct bp_location
*loc
;
3133 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
3135 if (t
->type
== utp
->type
3136 && t
->step_count
== utp
->step
3137 && t
->pass_count
== utp
->pass
3138 /* FIXME also test conditionals and actions. */
3141 /* Scan the locations for an address match. */
3142 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
3144 if (loc
->address
== utp
->addr
)
3152 /* Given a list of tracepoints uploaded from a target, attempt to
3153 match them up with existing tracepoints, and create new ones if not
3157 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
3159 struct uploaded_tp
*utp
;
3160 struct breakpoint
*t
;
3162 /* Look for GDB tracepoints that match up with our uploaded versions. */
3163 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
3165 t
= find_matching_tracepoint (utp
);
3167 printf_filtered (_("Assuming tracepoint %d is same "
3168 "as target's tracepoint %d at %s.\n"),
3169 t
->number
, utp
->number
,
3170 paddress (get_current_arch (), utp
->addr
));
3173 t
= create_tracepoint_from_upload (utp
);
3175 printf_filtered (_("Created tracepoint %d for "
3176 "target's tracepoint %d at %s.\n"),
3177 t
->number
, utp
->number
,
3178 paddress (get_current_arch (), utp
->addr
));
3180 printf_filtered (_("Failed to create tracepoint for target's "
3181 "tracepoint %d at %s, skipping it.\n"),
3183 paddress (get_current_arch (), utp
->addr
));
3185 /* Whether found or created, record the number used by the
3186 target, to help with mapping target tracepoints back to their
3187 counterparts here. */
3189 t
->number_on_target
= utp
->number
;
3192 free_uploaded_tps (uploaded_tps
);
3195 /* Trace state variables don't have much to identify them beyond their
3196 name, so just use that to detect matches. */
3198 struct trace_state_variable
*
3199 find_matching_tsv (struct uploaded_tsv
*utsv
)
3204 return find_trace_state_variable (utsv
->name
);
3207 struct trace_state_variable
*
3208 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
3210 const char *namebase
;
3213 struct trace_state_variable
*tsv
;
3217 namebase
= utsv
->name
;
3218 sprintf (buf
, "%s", namebase
);
3223 sprintf (buf
, "%s_%d", namebase
, try_num
++);
3226 /* Fish for a name that is not in use. */
3227 /* (should check against all internal vars?) */
3228 while (find_trace_state_variable (buf
))
3229 sprintf (buf
, "%s_%d", namebase
, try_num
++);
3231 /* We have an available name, create the variable. */
3232 tsv
= create_trace_state_variable (xstrdup (buf
));
3233 tsv
->initial_value
= utsv
->initial_value
;
3234 tsv
->builtin
= utsv
->builtin
;
3239 /* Given a list of uploaded trace state variables, try to match them
3240 up with existing variables, or create additional ones. */
3243 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
3246 struct uploaded_tsv
*utsv
;
3247 struct trace_state_variable
*tsv
;
3250 /* Most likely some numbers will have to be reassigned as part of
3251 the merge, so clear them all in anticipation. */
3252 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3255 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
3257 tsv
= find_matching_tsv (utsv
);
3261 printf_filtered (_("Assuming trace state variable $%s "
3262 "is same as target's variable %d.\n"),
3263 tsv
->name
, utsv
->number
);
3267 tsv
= create_tsv_from_upload (utsv
);
3269 printf_filtered (_("Created trace state variable "
3270 "$%s for target's variable %d.\n"),
3271 tsv
->name
, utsv
->number
);
3273 /* Give precedence to numberings that come from the target. */
3275 tsv
->number
= utsv
->number
;
3278 /* Renumber everything that didn't get a target-assigned number. */
3280 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3281 if (tsv
->number
> highest
)
3282 highest
= tsv
->number
;
3285 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
3286 if (tsv
->number
== 0)
3287 tsv
->number
= highest
++;
3289 free_uploaded_tsvs (uploaded_tsvs
);
3292 /* target tfile command */
3294 struct target_ops tfile_ops
;
3296 /* Fill in tfile_ops with its defined operations and properties. */
3298 #define TRACE_HEADER_SIZE 8
3300 char *trace_filename
;
3302 off_t trace_frames_offset
;
3304 int cur_traceframe_number
;
3306 int trace_regblock_size
;
3308 static void tfile_interp_line (char *line
,
3309 struct uploaded_tp
**utpp
,
3310 struct uploaded_tsv
**utsvp
);
3312 /* Read SIZE bytes into READBUF from the trace frame, starting at
3313 TRACE_FD's current position. Note that this call `read'
3314 underneath, hence it advances the file's seek position. Throws an
3315 error if the `read' syscall fails, or less than SIZE bytes are
3319 tfile_read (gdb_byte
*readbuf
, int size
)
3323 gotten
= read (trace_fd
, readbuf
, size
);
3325 perror_with_name (trace_filename
);
3326 else if (gotten
< size
)
3327 error (_("Premature end of file while reading trace file"));
3331 tfile_open (char *filename
, int from_tty
)
3334 struct cleanup
*old_chain
;
3337 char header
[TRACE_HEADER_SIZE
];
3338 char linebuf
[1000]; /* Should be max remote packet size or so. */
3341 struct trace_status
*ts
;
3342 struct uploaded_tp
*uploaded_tps
= NULL
;
3343 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
3345 target_preopen (from_tty
);
3347 error (_("No trace file specified."));
3349 filename
= tilde_expand (filename
);
3350 if (!IS_ABSOLUTE_PATH(filename
))
3352 temp
= concat (current_directory
, "/", filename
, (char *) NULL
);
3357 old_chain
= make_cleanup (xfree
, filename
);
3359 flags
= O_BINARY
| O_LARGEFILE
;
3361 scratch_chan
= open (filename
, flags
, 0);
3362 if (scratch_chan
< 0)
3363 perror_with_name (filename
);
3365 /* Looks semi-reasonable. Toss the old trace file and work on the new. */
3367 discard_cleanups (old_chain
); /* Don't free filename any more. */
3368 unpush_target (&tfile_ops
);
3370 push_target (&tfile_ops
);
3372 trace_filename
= xstrdup (filename
);
3373 trace_fd
= scratch_chan
;
3376 /* Read the file header and test for validity. */
3377 tfile_read ((gdb_byte
*) &header
, TRACE_HEADER_SIZE
);
3379 bytes
+= TRACE_HEADER_SIZE
;
3380 if (!(header
[0] == 0x7f
3381 && (strncmp (header
+ 1, "TRACE0\n", 7) == 0)))
3382 error (_("File is not a valid trace file."));
3384 trace_regblock_size
= 0;
3385 ts
= current_trace_status ();
3386 /* We know we're working with a file. */
3388 /* Set defaults in case there is no status line. */
3389 ts
->running_known
= 0;
3390 ts
->stop_reason
= trace_stop_reason_unknown
;
3391 ts
->traceframe_count
= -1;
3392 ts
->buffer_free
= 0;
3393 ts
->disconnected_tracing
= 0;
3394 ts
->circular_buffer
= 0;
3396 cur_traceframe_number
= -1;
3398 /* Read through a section of newline-terminated lines that
3399 define things like tracepoints. */
3403 tfile_read (&byte
, 1);
3408 /* Empty line marks end of the definition section. */
3413 tfile_interp_line (linebuf
, &uploaded_tps
, &uploaded_tsvs
);
3416 linebuf
[i
++] = byte
;
3418 error (_("Excessively long lines in trace file"));
3421 /* Add the file's tracepoints and variables into the current mix. */
3423 /* Get trace state variables first, they may be checked when parsing
3424 uploaded commands. */
3425 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3427 merge_uploaded_tracepoints (&uploaded_tps
);
3429 /* Record the starting offset of the binary trace data. */
3430 trace_frames_offset
= bytes
;
3432 /* If we don't have a blocksize, we can't interpret the
3434 if (trace_regblock_size
== 0)
3435 error (_("No register block size recorded in trace file"));
3436 if (ts
->traceframe_count
<= 0)
3438 warning (_("No traceframes present in this file."));
3442 #define TFILE_PID (1)
3443 inferior_appeared (current_inferior (), TFILE_PID
);
3444 inferior_ptid
= pid_to_ptid (TFILE_PID
);
3445 add_thread_silent (inferior_ptid
);
3447 post_create_inferior (&tfile_ops
, from_tty
);
3450 /* FIXME this will get defined in MI patch submission. */
3451 tfind_1 (tfind_number
, 0, 0, 0, 0);
3455 /* Interpret the given line from the definitions part of the trace
3459 tfile_interp_line (char *line
,
3460 struct uploaded_tp
**utpp
, struct uploaded_tsv
**utsvp
)
3464 if (strncmp (p
, "R ", strlen ("R ")) == 0)
3467 trace_regblock_size
= strtol (p
, &p
, 16);
3469 else if (strncmp (p
, "status ", strlen ("status ")) == 0)
3471 p
+= strlen ("status ");
3472 parse_trace_status (p
, current_trace_status ());
3474 else if (strncmp (p
, "tp ", strlen ("tp ")) == 0)
3476 p
+= strlen ("tp ");
3477 parse_tracepoint_definition (p
, utpp
);
3479 else if (strncmp (p
, "tsv ", strlen ("tsv ")) == 0)
3481 p
+= strlen ("tsv ");
3482 parse_tsv_definition (p
, utsvp
);
3485 warning (_("Ignoring trace file definition \"%s\""), line
);
3488 /* Parse the part of trace status syntax that is shared between
3489 the remote protocol and the trace file reader. */
3492 parse_trace_status (char *line
, struct trace_status
*ts
)
3494 char *p
= line
, *p1
, *p2
, *p_temp
;
3497 ts
->running_known
= 1;
3498 ts
->running
= (*p
++ == '1');
3499 ts
->stop_reason
= trace_stop_reason_unknown
;
3500 xfree (ts
->error_desc
);
3501 ts
->error_desc
= NULL
;
3502 ts
->traceframe_count
= -1;
3503 ts
->traceframes_created
= -1;
3504 ts
->buffer_free
= -1;
3505 ts
->buffer_size
= -1;
3506 ts
->disconnected_tracing
= 0;
3507 ts
->circular_buffer
= 0;
3511 p1
= strchr (p
, ':');
3513 error (_("Malformed trace status, at %s\n\
3514 Status line: '%s'\n"), p
, line
);
3515 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
3517 p
= unpack_varlen_hex (++p1
, &val
);
3518 ts
->stop_reason
= trace_buffer_full
;
3520 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
3522 p
= unpack_varlen_hex (++p1
, &val
);
3523 ts
->stop_reason
= trace_never_run
;
3525 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
],
3528 p
= unpack_varlen_hex (++p1
, &val
);
3529 ts
->stop_reason
= tracepoint_passcount
;
3530 ts
->stopping_tracepoint
= val
;
3532 else if (strncmp (p
, stop_reason_names
[tstop_command
], p1
- p
) == 0)
3534 p
= unpack_varlen_hex (++p1
, &val
);
3535 ts
->stop_reason
= tstop_command
;
3537 else if (strncmp (p
, stop_reason_names
[trace_disconnected
], p1
- p
) == 0)
3539 p
= unpack_varlen_hex (++p1
, &val
);
3540 ts
->stop_reason
= trace_disconnected
;
3542 else if (strncmp (p
, stop_reason_names
[tracepoint_error
], p1
- p
) == 0)
3544 p2
= strchr (++p1
, ':');
3549 ts
->error_desc
= xmalloc ((p2
- p1
) / 2 + 1);
3550 end
= hex2bin (p1
, ts
->error_desc
, (p2
- p1
) / 2);
3551 ts
->error_desc
[end
] = '\0';
3554 ts
->error_desc
= xstrdup ("");
3556 p
= unpack_varlen_hex (++p2
, &val
);
3557 ts
->stopping_tracepoint
= val
;
3558 ts
->stop_reason
= tracepoint_error
;
3560 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3562 p
= unpack_varlen_hex (++p1
, &val
);
3563 ts
->traceframe_count
= val
;
3565 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3567 p
= unpack_varlen_hex (++p1
, &val
);
3568 ts
->traceframes_created
= val
;
3570 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3572 p
= unpack_varlen_hex (++p1
, &val
);
3573 ts
->buffer_free
= val
;
3575 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3577 p
= unpack_varlen_hex (++p1
, &val
);
3578 ts
->buffer_size
= val
;
3580 else if (strncmp (p
, "disconn", p1
- p
) == 0)
3582 p
= unpack_varlen_hex (++p1
, &val
);
3583 ts
->disconnected_tracing
= val
;
3585 else if (strncmp (p
, "circular", p1
- p
) == 0)
3587 p
= unpack_varlen_hex (++p1
, &val
);
3588 ts
->circular_buffer
= val
;
3592 /* Silently skip unknown optional info. */
3593 p_temp
= strchr (p1
+ 1, ';');
3597 /* Must be at the end. */
3603 /* Given a line of text defining a part of a tracepoint, parse it into
3604 an "uploaded tracepoint". */
3607 parse_tracepoint_definition (char *line
, struct uploaded_tp
**utpp
)
3611 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
, start
;
3614 char *cond
, *srctype
, *buf
;
3615 struct uploaded_tp
*utp
= NULL
;
3618 /* Both tracepoint and action definitions start with the same number
3619 and address sequence. */
3621 p
= unpack_varlen_hex (p
, &num
);
3622 p
++; /* skip a colon */
3623 p
= unpack_varlen_hex (p
, &addr
);
3624 p
++; /* skip a colon */
3627 enabled
= (*p
++ == 'E');
3628 p
++; /* skip a colon */
3629 p
= unpack_varlen_hex (p
, &step
);
3630 p
++; /* skip a colon */
3631 p
= unpack_varlen_hex (p
, &pass
);
3632 type
= bp_tracepoint
;
3634 /* Thumb through optional fields. */
3637 p
++; /* skip a colon */
3640 type
= bp_fast_tracepoint
;
3642 p
= unpack_varlen_hex (p
, &orig_size
);
3646 type
= bp_static_tracepoint
;
3652 p
= unpack_varlen_hex (p
, &xlen
);
3653 p
++; /* skip a comma */
3654 cond
= (char *) xmalloc (2 * xlen
+ 1);
3655 strncpy (cond
, p
, 2 * xlen
);
3656 cond
[2 * xlen
] = '\0';
3660 warning (_("Unrecognized char '%c' in tracepoint "
3661 "definition, skipping rest"), *p
);
3663 utp
= get_uploaded_tp (num
, addr
, utpp
);
3665 utp
->enabled
= enabled
;
3670 else if (piece
== 'A')
3672 utp
= get_uploaded_tp (num
, addr
, utpp
);
3673 VEC_safe_push (char_ptr
, utp
->actions
, xstrdup (p
));
3675 else if (piece
== 'S')
3677 utp
= get_uploaded_tp (num
, addr
, utpp
);
3678 VEC_safe_push (char_ptr
, utp
->step_actions
, xstrdup (p
));
3680 else if (piece
== 'Z')
3682 /* Parse a chunk of source form definition. */
3683 utp
= get_uploaded_tp (num
, addr
, utpp
);
3685 p
= strchr (p
, ':');
3686 p
++; /* skip a colon */
3687 p
= unpack_varlen_hex (p
, &start
);
3688 p
++; /* skip a colon */
3689 p
= unpack_varlen_hex (p
, &xlen
);
3690 p
++; /* skip a colon */
3692 buf
= alloca (strlen (line
));
3694 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3697 if (strncmp (srctype
, "at:", strlen ("at:")) == 0)
3698 utp
->at_string
= xstrdup (buf
);
3699 else if (strncmp (srctype
, "cond:", strlen ("cond:")) == 0)
3700 utp
->cond_string
= xstrdup (buf
);
3701 else if (strncmp (srctype
, "cmd:", strlen ("cmd:")) == 0)
3702 VEC_safe_push (char_ptr
, utp
->cmd_strings
, xstrdup (buf
));
3706 /* Don't error out, the target might be sending us optional
3707 info that we don't care about. */
3708 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece
);
3712 /* Convert a textual description of a trace state variable into an
3716 parse_tsv_definition (char *line
, struct uploaded_tsv
**utsvp
)
3719 ULONGEST num
, initval
, builtin
;
3721 struct uploaded_tsv
*utsv
= NULL
;
3723 buf
= alloca (strlen (line
));
3726 p
= unpack_varlen_hex (p
, &num
);
3727 p
++; /* skip a colon */
3728 p
= unpack_varlen_hex (p
, &initval
);
3729 p
++; /* skip a colon */
3730 p
= unpack_varlen_hex (p
, &builtin
);
3731 p
++; /* skip a colon */
3732 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3735 utsv
= get_uploaded_tsv (num
, utsvp
);
3736 utsv
->initial_value
= initval
;
3737 utsv
->builtin
= builtin
;
3738 utsv
->name
= xstrdup (buf
);
3741 /* Close the trace file and generally clean up. */
3744 tfile_close (int quitting
)
3751 pid
= ptid_get_pid (inferior_ptid
);
3752 inferior_ptid
= null_ptid
; /* Avoid confusion from thread stuff. */
3753 exit_inferior_silent (pid
);
3758 xfree (trace_filename
);
3762 tfile_files_info (struct target_ops
*t
)
3764 /* (it would be useful to mention the name of the file). */
3765 printf_filtered ("Looking at a trace file.\n");
3768 /* The trace status for a file is that tracing can never be run. */
3771 tfile_get_trace_status (struct trace_status
*ts
)
3773 /* Other bits of trace status were collected as part of opening the
3774 trace files, so nothing to do here. */
3779 /* Given the position of a traceframe in the file, figure out what
3780 address the frame was collected at. This would normally be the
3781 value of a collected PC register, but if not available, we
3785 tfile_get_traceframe_address (off_t tframe_offset
)
3789 struct breakpoint
*tp
;
3790 off_t saved_offset
= cur_offset
;
3792 /* FIXME dig pc out of collected registers. */
3794 /* Fall back to using tracepoint address. */
3795 lseek (trace_fd
, tframe_offset
, SEEK_SET
);
3796 tfile_read ((gdb_byte
*) &tpnum
, 2);
3797 tpnum
= (short) extract_signed_integer ((gdb_byte
*) &tpnum
, 2,
3801 tp
= get_tracepoint_by_number_on_target (tpnum
);
3802 /* FIXME this is a poor heuristic if multiple locations. */
3804 addr
= tp
->loc
->address
;
3806 /* Restore our seek position. */
3807 cur_offset
= saved_offset
;
3808 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3812 /* Make tfile's selected traceframe match GDB's selected
3816 set_tfile_traceframe (void)
3820 if (cur_traceframe_number
== get_traceframe_number ())
3823 /* Avoid recursion, tfile_trace_find calls us again. */
3824 cur_traceframe_number
= get_traceframe_number ();
3826 newnum
= target_trace_find (tfind_number
,
3827 get_traceframe_number (), 0, 0, NULL
);
3829 /* Should not happen. If it does, all bets are off. */
3830 if (newnum
!= get_traceframe_number ())
3831 warning (_("could not set tfile's traceframe"));
3834 /* Given a type of search and some parameters, scan the collection of
3835 traceframes in the file looking for a match. When found, return
3836 both the traceframe and tracepoint number, otherwise -1 for
3840 tfile_trace_find (enum trace_find_type type
, int num
,
3841 ULONGEST addr1
, ULONGEST addr2
, int *tpp
)
3844 int tfnum
= 0, found
= 0;
3845 unsigned int data_size
;
3846 struct breakpoint
*tp
;
3847 off_t offset
, tframe_offset
;
3850 /* Lookups other than by absolute frame number depend on the current
3851 trace selected, so make sure it is correct on the tfile end
3853 if (type
!= tfind_number
)
3854 set_tfile_traceframe ();
3856 lseek (trace_fd
, trace_frames_offset
, SEEK_SET
);
3857 offset
= trace_frames_offset
;
3860 tframe_offset
= offset
;
3861 tfile_read ((gdb_byte
*) &tpnum
, 2);
3862 tpnum
= (short) extract_signed_integer ((gdb_byte
*) &tpnum
, 2,
3868 tfile_read ((gdb_byte
*) &data_size
, 4);
3869 data_size
= (unsigned int) extract_unsigned_integer
3870 ((gdb_byte
*) &data_size
, 4,
3871 gdbarch_byte_order (target_gdbarch
));
3880 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3881 if (tfaddr
== addr1
)
3885 tp
= get_tracepoint (num
);
3886 if (tp
&& tpnum
== tp
->number_on_target
)
3890 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3891 if (addr1
<= tfaddr
&& tfaddr
<= addr2
)
3895 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3896 if (!(addr1
<= tfaddr
&& tfaddr
<= addr2
))
3900 internal_error (__FILE__
, __LINE__
, _("unknown tfind type"));
3906 cur_offset
= offset
;
3907 cur_data_size
= data_size
;
3908 cur_traceframe_number
= tfnum
;
3911 /* Skip past the traceframe's data. */
3912 lseek (trace_fd
, data_size
, SEEK_CUR
);
3913 offset
+= data_size
;
3914 /* Update our own count of traceframes. */
3917 /* Did not find what we were looking for. */
3923 /* Prototype of the callback passed to tframe_walk_blocks. */
3924 typedef int (*walk_blocks_callback_func
) (char blocktype
, void *data
);
3926 /* Callback for traceframe_walk_blocks, used to find a given block
3927 type in a traceframe. */
3930 match_blocktype (char blocktype
, void *data
)
3932 char *wantedp
= data
;
3934 if (*wantedp
== blocktype
)
3940 /* Walk over all traceframe block starting at POS offset from
3941 CUR_OFFSET, and call CALLBACK for each block found, passing in DATA
3942 unmodified. If CALLBACK returns true, this returns the position in
3943 the traceframe where the block is found, relative to the start of
3944 the traceframe (cur_offset). Returns -1 if no callback call
3945 returned true, indicating that all blocks have been walked. */
3948 traceframe_walk_blocks (walk_blocks_callback_func callback
,
3949 int pos
, void *data
)
3951 /* Iterate through a traceframe's blocks, looking for a block of the
3954 lseek (trace_fd
, cur_offset
+ pos
, SEEK_SET
);
3955 while (pos
< cur_data_size
)
3957 unsigned short mlen
;
3960 tfile_read (&block_type
, 1);
3964 if ((*callback
) (block_type
, data
))
3970 lseek (trace_fd
, cur_offset
+ pos
+ trace_regblock_size
, SEEK_SET
);
3971 pos
+= trace_regblock_size
;
3974 lseek (trace_fd
, cur_offset
+ pos
+ 8, SEEK_SET
);
3975 tfile_read ((gdb_byte
*) &mlen
, 2);
3976 mlen
= (unsigned short)
3977 extract_unsigned_integer ((gdb_byte
*) &mlen
, 2,
3980 lseek (trace_fd
, mlen
, SEEK_CUR
);
3981 pos
+= (8 + 2 + mlen
);
3984 lseek (trace_fd
, cur_offset
+ pos
+ 4 + 8, SEEK_SET
);
3988 error (_("Unknown block type '%c' (0x%x) in trace frame"),
3989 block_type
, block_type
);
3997 /* Convenience wrapper around traceframe_walk_blocks. Looks for the
3998 position offset of a block of type TYPE_WANTED in the current trace
3999 frame, starting at POS. Returns -1 if no such block was found. */
4002 traceframe_find_block_type (char type_wanted
, int pos
)
4004 return traceframe_walk_blocks (match_blocktype
, pos
, &type_wanted
);
4007 /* Look for a block of saved registers in the traceframe, and get the
4008 requested register from it. */
4011 tfile_fetch_registers (struct target_ops
*ops
,
4012 struct regcache
*regcache
, int regno
)
4014 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4016 int pos
, offset
, regn
, regsize
, pc_regno
;
4017 unsigned short mlen
;
4020 /* An uninitialized reg size says we're not going to be
4021 successful at getting register blocks. */
4022 if (!trace_regblock_size
)
4025 set_tfile_traceframe ();
4027 regs
= alloca (trace_regblock_size
);
4029 if (traceframe_find_block_type ('R', 0) >= 0)
4031 tfile_read (regs
, trace_regblock_size
);
4033 /* Assume the block is laid out in GDB register number order,
4034 each register with the size that it has in GDB. */
4036 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
4038 regsize
= register_size (gdbarch
, regn
);
4039 /* Make sure we stay within block bounds. */
4040 if (offset
+ regsize
>= trace_regblock_size
)
4042 if (regcache_register_status (regcache
, regn
) == REG_UNKNOWN
)
4046 regcache_raw_supply (regcache
, regno
, regs
+ offset
);
4049 else if (regno
== -1)
4051 regcache_raw_supply (regcache
, regn
, regs
+ offset
);
4059 /* We get here if no register data has been found. Mark registers
4061 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
4062 regcache_raw_supply (regcache
, regn
, NULL
);
4064 /* We can often usefully guess that the PC is going to be the same
4065 as the address of the tracepoint. */
4066 pc_regno
= gdbarch_pc_regnum (gdbarch
);
4067 if (pc_regno
>= 0 && (regno
== -1 || regno
== pc_regno
))
4069 struct breakpoint
*tp
= get_tracepoint (tracepoint_number
);
4073 /* But don't try to guess if tracepoint is multi-location... */
4076 warning (_("Tracepoint %d has multiple "
4077 "locations, cannot infer $pc"),
4081 /* ... or does while-stepping. */
4082 if (tp
->step_count
> 0)
4084 warning (_("Tracepoint %d does while-stepping, "
4085 "cannot infer $pc"),
4090 store_unsigned_integer (regs
, register_size (gdbarch
, pc_regno
),
4091 gdbarch_byte_order (gdbarch
),
4093 regcache_raw_supply (regcache
, pc_regno
, regs
);
4099 tfile_xfer_partial (struct target_ops
*ops
, enum target_object object
,
4100 const char *annex
, gdb_byte
*readbuf
,
4101 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
4103 /* We're only doing regular memory for now. */
4104 if (object
!= TARGET_OBJECT_MEMORY
)
4107 if (readbuf
== NULL
)
4108 error (_("tfile_xfer_partial: trace file is read-only"));
4110 set_tfile_traceframe ();
4112 if (traceframe_number
!= -1)
4116 /* Iterate through the traceframe's blocks, looking for
4118 while ((pos
= traceframe_find_block_type ('M', pos
)) >= 0)
4120 ULONGEST maddr
, amt
;
4121 unsigned short mlen
;
4122 enum bfd_endian byte_order
= gdbarch_byte_order (target_gdbarch
);
4124 tfile_read ((gdb_byte
*) &maddr
, 8);
4125 maddr
= extract_unsigned_integer ((gdb_byte
*) &maddr
, 8,
4127 tfile_read ((gdb_byte
*) &mlen
, 2);
4128 mlen
= (unsigned short)
4129 extract_unsigned_integer ((gdb_byte
*) &mlen
, 2, byte_order
);
4131 /* If the block includes the first part of the desired
4132 range, return as much it has; GDB will re-request the
4133 remainder, which might be in a different block of this
4135 if (maddr
<= offset
&& offset
< (maddr
+ mlen
))
4137 amt
= (maddr
+ mlen
) - offset
;
4141 tfile_read (readbuf
, amt
);
4145 /* Skip over this block. */
4146 pos
+= (8 + 2 + mlen
);
4150 /* It's unduly pedantic to refuse to look at the executable for
4151 read-only pieces; so do the equivalent of readonly regions aka
4153 /* FIXME account for relocation at some point. */
4160 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
4162 if ((s
->flags
& SEC_LOAD
) == 0
4163 || (s
->flags
& SEC_READONLY
) == 0)
4167 size
= bfd_get_section_size (s
);
4168 if (vma
<= offset
&& offset
< (vma
+ size
))
4172 amt
= (vma
+ size
) - offset
;
4176 amt
= bfd_get_section_contents (exec_bfd
, s
,
4177 readbuf
, offset
- vma
, amt
);
4183 /* Indicate failure to find the requested memory block. */
4187 /* Iterate through the blocks of a trace frame, looking for a 'V'
4188 block with a matching tsv number. */
4191 tfile_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
4195 set_tfile_traceframe ();
4198 while ((pos
= traceframe_find_block_type ('V', pos
)) >= 0)
4202 tfile_read ((gdb_byte
*) &vnum
, 4);
4203 vnum
= (int) extract_signed_integer ((gdb_byte
*) &vnum
, 4,
4208 tfile_read ((gdb_byte
*) val
, 8);
4209 *val
= extract_signed_integer ((gdb_byte
*) val
, 8,
4217 /* Didn't find anything. */
4222 tfile_has_all_memory (struct target_ops
*ops
)
4228 tfile_has_memory (struct target_ops
*ops
)
4234 tfile_has_stack (struct target_ops
*ops
)
4236 return traceframe_number
!= -1;
4240 tfile_has_registers (struct target_ops
*ops
)
4242 return traceframe_number
!= -1;
4245 /* Callback for traceframe_walk_blocks. Builds a traceframe_info
4246 object for the tfile target's current traceframe. */
4249 build_traceframe_info (char blocktype
, void *data
)
4251 struct traceframe_info
*info
= data
;
4257 struct mem_range
*r
;
4259 unsigned short mlen
;
4261 tfile_read ((gdb_byte
*) &maddr
, 8);
4262 tfile_read ((gdb_byte
*) &mlen
, 2);
4264 r
= VEC_safe_push (mem_range_s
, info
->memory
, NULL
);
4277 warning (_("Unhandled trace block type (%d) '%c ' "
4278 "while building trace frame info."),
4279 blocktype
, blocktype
);
4286 static struct traceframe_info
*
4287 tfile_traceframe_info (void)
4289 struct traceframe_info
*info
= XCNEW (struct traceframe_info
);
4291 traceframe_walk_blocks (build_traceframe_info
, 0, info
);
4296 init_tfile_ops (void)
4298 tfile_ops
.to_shortname
= "tfile";
4299 tfile_ops
.to_longname
= "Local trace dump file";
4301 = "Use a trace file as a target. Specify the filename of the trace file.";
4302 tfile_ops
.to_open
= tfile_open
;
4303 tfile_ops
.to_close
= tfile_close
;
4304 tfile_ops
.to_fetch_registers
= tfile_fetch_registers
;
4305 tfile_ops
.to_xfer_partial
= tfile_xfer_partial
;
4306 tfile_ops
.to_files_info
= tfile_files_info
;
4307 tfile_ops
.to_get_trace_status
= tfile_get_trace_status
;
4308 tfile_ops
.to_trace_find
= tfile_trace_find
;
4309 tfile_ops
.to_get_trace_state_variable_value
4310 = tfile_get_trace_state_variable_value
;
4311 tfile_ops
.to_stratum
= process_stratum
;
4312 tfile_ops
.to_has_all_memory
= tfile_has_all_memory
;
4313 tfile_ops
.to_has_memory
= tfile_has_memory
;
4314 tfile_ops
.to_has_stack
= tfile_has_stack
;
4315 tfile_ops
.to_has_registers
= tfile_has_registers
;
4316 tfile_ops
.to_traceframe_info
= tfile_traceframe_info
;
4317 tfile_ops
.to_magic
= OPS_MAGIC
;
4320 /* Given a line of text defining a static tracepoint marker, parse it
4321 into a "static tracepoint marker" object. Throws an error is
4322 parsing fails. If PP is non-null, it points to one past the end of
4323 the parsed marker definition. */
4326 parse_static_tracepoint_marker_definition (char *line
, char **pp
,
4327 struct static_tracepoint_marker
*marker
)
4334 p
= unpack_varlen_hex (p
, &addr
);
4335 p
++; /* skip a colon */
4337 marker
->gdbarch
= target_gdbarch
;
4338 marker
->address
= (CORE_ADDR
) addr
;
4340 endp
= strchr (p
, ':');
4342 error (_("bad marker definition: %s"), line
);
4344 marker
->str_id
= xmalloc (endp
- p
+ 1);
4345 end
= hex2bin (p
, (gdb_byte
*) marker
->str_id
, (endp
- p
+ 1) / 2);
4346 marker
->str_id
[end
] = '\0';
4349 p
++; /* skip a colon */
4351 marker
->extra
= xmalloc (strlen (p
) + 1);
4352 end
= hex2bin (p
, (gdb_byte
*) marker
->extra
, strlen (p
) / 2);
4353 marker
->extra
[end
] = '\0';
4359 /* Release a static tracepoint marker's contents. Note that the
4360 object itself isn't released here. There objects are usually on
4364 release_static_tracepoint_marker (struct static_tracepoint_marker
*marker
)
4366 xfree (marker
->str_id
);
4367 marker
->str_id
= NULL
;
4370 /* Print MARKER to gdb_stdout. */
4373 print_one_static_tracepoint_marker (int count
,
4374 struct static_tracepoint_marker
*marker
)
4376 struct command_line
*l
;
4379 char wrap_indent
[80];
4380 char extra_field_indent
[80];
4381 struct ui_stream
*stb
= ui_out_stream_new (uiout
);
4382 struct cleanup
*old_chain
= make_cleanup_ui_out_stream_delete (stb
);
4383 struct cleanup
*bkpt_chain
;
4384 VEC(breakpoint_p
) *tracepoints
;
4386 struct symtab_and_line sal
;
4390 sal
.pc
= marker
->address
;
4392 tracepoints
= static_tracepoints_here (marker
->address
);
4394 bkpt_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "marker");
4396 /* A counter field to help readability. This is not a stable
4398 ui_out_field_int (uiout
, "count", count
);
4400 ui_out_field_string (uiout
, "marker-id", marker
->str_id
);
4402 ui_out_field_fmt (uiout
, "enabled", "%c",
4403 !VEC_empty (breakpoint_p
, tracepoints
) ? 'y' : 'n');
4404 ui_out_spaces (uiout
, 2);
4406 strcpy (wrap_indent
, " ");
4408 if (gdbarch_addr_bit (marker
->gdbarch
) <= 32)
4409 strcat (wrap_indent
, " ");
4411 strcat (wrap_indent
, " ");
4413 strcpy (extra_field_indent
, " ");
4415 ui_out_field_core_addr (uiout
, "addr", marker
->gdbarch
, marker
->address
);
4417 sal
= find_pc_line (marker
->address
, 0);
4418 sym
= find_pc_sect_function (marker
->address
, NULL
);
4421 ui_out_text (uiout
, "in ");
4422 ui_out_field_string (uiout
, "func",
4423 SYMBOL_PRINT_NAME (sym
));
4424 ui_out_wrap_hint (uiout
, wrap_indent
);
4425 ui_out_text (uiout
, " at ");
4428 ui_out_field_skip (uiout
, "func");
4430 if (sal
.symtab
!= NULL
)
4432 ui_out_field_string (uiout
, "file", sal
.symtab
->filename
);
4433 ui_out_text (uiout
, ":");
4435 if (ui_out_is_mi_like_p (uiout
))
4437 char *fullname
= symtab_to_fullname (sal
.symtab
);
4440 ui_out_field_string (uiout
, "fullname", fullname
);
4443 ui_out_field_skip (uiout
, "fullname");
4445 ui_out_field_int (uiout
, "line", sal
.line
);
4449 ui_out_field_skip (uiout
, "fullname");
4450 ui_out_field_skip (uiout
, "line");
4453 ui_out_text (uiout
, "\n");
4454 ui_out_text (uiout
, extra_field_indent
);
4455 ui_out_text (uiout
, _("Data: \""));
4456 ui_out_field_string (uiout
, "extra-data", marker
->extra
);
4457 ui_out_text (uiout
, "\"\n");
4459 if (!VEC_empty (breakpoint_p
, tracepoints
))
4461 struct cleanup
*cleanup_chain
;
4463 struct breakpoint
*b
;
4465 cleanup_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
,
4468 ui_out_text (uiout
, extra_field_indent
);
4469 ui_out_text (uiout
, _("Probed by static tracepoints: "));
4470 for (ix
= 0; VEC_iterate(breakpoint_p
, tracepoints
, ix
, b
); ix
++)
4473 ui_out_text (uiout
, ", ");
4474 ui_out_text (uiout
, "#");
4475 ui_out_field_int (uiout
, "tracepoint-id", b
->number
);
4478 do_cleanups (cleanup_chain
);
4480 if (ui_out_is_mi_like_p (uiout
))
4481 ui_out_field_int (uiout
, "number-of-tracepoints",
4482 VEC_length(breakpoint_p
, tracepoints
));
4484 ui_out_text (uiout
, "\n");
4486 VEC_free (breakpoint_p
, tracepoints
);
4488 do_cleanups (bkpt_chain
);
4489 do_cleanups (old_chain
);
4493 info_static_tracepoint_markers_command (char *arg
, int from_tty
)
4495 VEC(static_tracepoint_marker_p
) *markers
;
4496 struct cleanup
*old_chain
;
4497 struct static_tracepoint_marker
*marker
;
4501 = make_cleanup_ui_out_table_begin_end (uiout
, 5, -1,
4502 "StaticTracepointMarkersTable");
4504 ui_out_table_header (uiout
, 7, ui_left
, "counter", "Cnt");
4506 ui_out_table_header (uiout
, 40, ui_left
, "marker-id", "ID");
4508 ui_out_table_header (uiout
, 3, ui_left
, "enabled", "Enb");
4509 if (gdbarch_addr_bit (target_gdbarch
) <= 32)
4510 ui_out_table_header (uiout
, 10, ui_left
, "addr", "Address");
4512 ui_out_table_header (uiout
, 18, ui_left
, "addr", "Address");
4513 ui_out_table_header (uiout
, 40, ui_noalign
, "what", "What");
4515 ui_out_table_body (uiout
);
4517 markers
= target_static_tracepoint_markers_by_strid (NULL
);
4518 make_cleanup (VEC_cleanup (static_tracepoint_marker_p
), &markers
);
4521 VEC_iterate (static_tracepoint_marker_p
,
4522 markers
, i
, marker
);
4525 print_one_static_tracepoint_marker (i
+ 1, marker
);
4526 release_static_tracepoint_marker (marker
);
4529 do_cleanups (old_chain
);
4532 /* The $_sdata convenience variable is a bit special. We don't know
4533 for sure type of the value until we actually have a chance to fetch
4534 the data --- the size of the object depends on what has been
4535 collected. We solve this by making $_sdata be an internalvar that
4536 creates a new value on access. */
4538 /* Return a new value with the correct type for the sdata object of
4539 the current trace frame. Return a void value if there's no object
4542 static struct value
*
4543 sdata_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
)
4548 /* We need to read the whole object before we know its size. */
4549 size
= target_read_alloc (¤t_target
,
4550 TARGET_OBJECT_STATIC_TRACE_DATA
,
4557 type
= init_vector_type (builtin_type (gdbarch
)->builtin_true_char
,
4559 v
= allocate_value (type
);
4560 memcpy (value_contents_raw (v
), buf
, size
);
4565 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
4568 #if !defined(HAVE_LIBEXPAT)
4570 struct traceframe_info
*
4571 parse_traceframe_info (const char *tframe_info
)
4573 static int have_warned
;
4578 warning (_("Can not parse XML trace frame info; XML support "
4579 "was disabled at compile time"));
4585 #else /* HAVE_LIBEXPAT */
4587 #include "xml-support.h"
4589 /* Handle the start of a <memory> element. */
4592 traceframe_info_start_memory (struct gdb_xml_parser
*parser
,
4593 const struct gdb_xml_element
*element
,
4594 void *user_data
, VEC(gdb_xml_value_s
) *attributes
)
4596 struct traceframe_info
*info
= user_data
;
4597 struct mem_range
*r
= VEC_safe_push (mem_range_s
, info
->memory
, NULL
);
4598 ULONGEST
*start_p
, *length_p
;
4600 start_p
= xml_find_attribute (attributes
, "start")->value
;
4601 length_p
= xml_find_attribute (attributes
, "length")->value
;
4603 r
->start
= *start_p
;
4604 r
->length
= *length_p
;
4607 /* Discard the constructed trace frame info (if an error occurs). */
4610 free_result (void *p
)
4612 struct traceframe_info
*result
= p
;
4614 free_traceframe_info (result
);
4617 /* The allowed elements and attributes for an XML memory map. */
4619 static const struct gdb_xml_attribute memory_attributes
[] = {
4620 { "start", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
4621 { "length", GDB_XML_AF_NONE
, gdb_xml_parse_attr_ulongest
, NULL
},
4622 { NULL
, GDB_XML_AF_NONE
, NULL
, NULL
}
4625 static const struct gdb_xml_element traceframe_info_children
[] = {
4626 { "memory", memory_attributes
, NULL
,
4627 GDB_XML_EF_REPEATABLE
| GDB_XML_EF_OPTIONAL
,
4628 traceframe_info_start_memory
, NULL
},
4629 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
4632 static const struct gdb_xml_element traceframe_info_elements
[] = {
4633 { "traceframe-info", NULL
, traceframe_info_children
, GDB_XML_EF_NONE
,
4635 { NULL
, NULL
, NULL
, GDB_XML_EF_NONE
, NULL
, NULL
}
4638 /* Parse a traceframe-info XML document. */
4640 struct traceframe_info
*
4641 parse_traceframe_info (const char *tframe_info
)
4643 struct traceframe_info
*result
;
4644 struct cleanup
*back_to
;
4646 result
= XCNEW (struct traceframe_info
);
4647 back_to
= make_cleanup (free_result
, result
);
4649 if (gdb_xml_parse_quick (_("trace frame info"),
4650 "traceframe-info.dtd", traceframe_info_elements
,
4651 tframe_info
, result
) == 0)
4653 /* Parsed successfully, keep the result. */
4654 discard_cleanups (back_to
);
4659 do_cleanups (back_to
);
4663 #endif /* HAVE_LIBEXPAT */
4665 /* Returns the traceframe_info object for the current traceframe.
4666 This is where we avoid re-fetching the object from the target if we
4667 already have it cached. */
4669 struct traceframe_info
*
4670 get_traceframe_info (void)
4672 if (traceframe_info
== NULL
)
4673 traceframe_info
= target_traceframe_info ();
4675 return traceframe_info
;
4678 /* If the target supports the query, return in RESULT the set of
4679 collected memory in the current traceframe, found within the LEN
4680 bytes range starting at MEMADDR. Returns true if the target
4681 supports the query, otherwise returns false, and RESULT is left
4685 traceframe_available_memory (VEC(mem_range_s
) **result
,
4686 CORE_ADDR memaddr
, ULONGEST len
)
4688 struct traceframe_info
*info
= get_traceframe_info ();
4692 struct mem_range
*r
;
4697 for (i
= 0; VEC_iterate (mem_range_s
, info
->memory
, i
, r
); i
++)
4698 if (mem_ranges_overlap (r
->start
, r
->length
, memaddr
, len
))
4700 ULONGEST lo1
, hi1
, lo2
, hi2
;
4701 struct mem_range
*nr
;
4704 hi1
= memaddr
+ len
;
4707 hi2
= r
->start
+ r
->length
;
4709 nr
= VEC_safe_push (mem_range_s
, *result
, NULL
);
4711 nr
->start
= max (lo1
, lo2
);
4712 nr
->length
= min (hi1
, hi2
) - nr
->start
;
4715 normalize_mem_ranges (*result
);
4722 /* module initialization */
4724 _initialize_tracepoint (void)
4726 struct cmd_list_element
*c
;
4728 /* Explicitly create without lookup, since that tries to create a
4729 value with a void typed value, and when we get here, gdbarch
4730 isn't initialized yet. At this point, we're quite sure there
4731 isn't another convenience variable of the same name. */
4732 create_internalvar_type_lazy ("_sdata", sdata_make_value
);
4734 traceframe_number
= -1;
4735 tracepoint_number
= -1;
4737 if (tracepoint_list
.list
== NULL
)
4739 tracepoint_list
.listsize
= 128;
4740 tracepoint_list
.list
= xmalloc
4741 (tracepoint_list
.listsize
* sizeof (struct memrange
));
4743 if (tracepoint_list
.aexpr_list
== NULL
)
4745 tracepoint_list
.aexpr_listsize
= 128;
4746 tracepoint_list
.aexpr_list
= xmalloc
4747 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
4750 if (stepping_list
.list
== NULL
)
4752 stepping_list
.listsize
= 128;
4753 stepping_list
.list
= xmalloc
4754 (stepping_list
.listsize
* sizeof (struct memrange
));
4757 if (stepping_list
.aexpr_list
== NULL
)
4759 stepping_list
.aexpr_listsize
= 128;
4760 stepping_list
.aexpr_list
= xmalloc
4761 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
4764 add_info ("scope", scope_info
,
4765 _("List the variables local to a scope"));
4767 add_cmd ("tracepoints", class_trace
, NULL
,
4768 _("Tracing of program execution without stopping the program."),
4771 add_com ("tdump", class_trace
, trace_dump_command
,
4772 _("Print everything collected at the current tracepoint."));
4774 add_com ("tsave", class_trace
, trace_save_command
, _("\
4775 Save the trace data to a file.\n\
4776 Use the '-r' option to direct the target to save directly to the file,\n\
4777 using its own filesystem."));
4779 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
4780 Define a trace state variable.\n\
4781 Argument is a $-prefixed name, optionally followed\n\
4782 by '=' and an expression that sets the initial value\n\
4783 at the start of tracing."));
4784 set_cmd_completer (c
, expression_completer
);
4786 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
4787 Delete one or more trace state variables.\n\
4788 Arguments are the names of the variables to delete.\n\
4789 If no arguments are supplied, delete all variables."), &deletelist
);
4790 /* FIXME add a trace variable completer. */
4792 add_info ("tvariables", tvariables_info
, _("\
4793 Status of trace state variables and their values.\n\
4796 add_info ("static-tracepoint-markers",
4797 info_static_tracepoint_markers_command
, _("\
4798 List target static tracepoints markers.\n\
4801 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
4802 Select a trace frame;\n\
4803 No argument means forward by one frame; '-' means backward by one frame."),
4804 &tfindlist
, "tfind ", 1, &cmdlist
);
4806 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
4807 Select a trace frame whose PC is outside the given range (exclusive).\n\
4808 Usage: tfind outside addr1, addr2"),
4811 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
4812 Select a trace frame whose PC is in the given range (inclusive).\n\
4813 Usage: tfind range addr1,addr2"),
4816 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
4817 Select a trace frame by source line.\n\
4818 Argument can be a line number (with optional source file),\n\
4819 a function name, or '*' followed by an address.\n\
4820 Default argument is 'the next source line that was traced'."),
4823 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
4824 Select a trace frame by tracepoint number.\n\
4825 Default is the tracepoint for the current trace frame."),
4828 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
4829 Select a trace frame by PC.\n\
4830 Default is the current PC, or the PC of the current trace frame."),
4833 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
4834 Synonym for 'none'.\n\
4835 De-select any trace frame and resume 'live' debugging."),
4838 add_cmd ("none", class_trace
, trace_find_none_command
,
4839 _("De-select any trace frame and resume 'live' debugging."),
4842 add_cmd ("start", class_trace
, trace_find_start_command
,
4843 _("Select the first trace frame in the trace buffer."),
4846 add_com ("tstatus", class_trace
, trace_status_command
,
4847 _("Display the status of the current trace data collection."));
4849 add_com ("tstop", class_trace
, trace_stop_command
,
4850 _("Stop trace data collection."));
4852 add_com ("tstart", class_trace
, trace_start_command
,
4853 _("Start trace data collection."));
4855 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
4856 Ends a list of commands or actions.\n\
4857 Several GDB commands allow you to enter a list of commands or actions.\n\
4858 Entering \"end\" on a line by itself is the normal way to terminate\n\
4860 Note: the \"end\" command cannot be used at the gdb prompt."));
4862 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
4863 Specify single-stepping behavior at a tracepoint.\n\
4864 Argument is number of instructions to trace in single-step mode\n\
4865 following the tracepoint. This command is normally followed by\n\
4866 one or more \"collect\" commands, to specify what to collect\n\
4867 while single-stepping.\n\n\
4868 Note: this command can only be used in a tracepoint \"actions\" list."));
4870 add_com_alias ("ws", "while-stepping", class_alias
, 0);
4871 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
4873 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
4874 Specify one or more data items to be collected at a tracepoint.\n\
4875 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4876 collect all data (variables, registers) referenced by that expression.\n\
4877 Also accepts the following special arguments:\n\
4878 $regs -- all registers.\n\
4879 $args -- all function arguments.\n\
4880 $locals -- all variables local to the block/function scope.\n\
4881 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
4882 Note: this command can only be used in a tracepoint \"actions\" list."));
4884 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
4885 Specify one or more expressions to be evaluated at a tracepoint.\n\
4886 Accepts a comma-separated list of (one or more) expressions.\n\
4887 The result of each evaluation will be discarded.\n\
4888 Note: this command can only be used in a tracepoint \"actions\" list."));
4890 add_com ("actions", class_trace
, trace_actions_command
, _("\
4891 Specify the actions to be taken at a tracepoint.\n\
4892 Tracepoint actions may include collecting of specified data,\n\
4893 single-stepping, or enabling/disabling other tracepoints,\n\
4894 depending on target's capabilities."));
4896 default_collect
= xstrdup ("");
4897 add_setshow_string_cmd ("default-collect", class_trace
,
4898 &default_collect
, _("\
4899 Set the list of expressions to collect by default"), _("\
4900 Show the list of expressions to collect by default"), NULL
,
4902 &setlist
, &showlist
);
4904 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
4905 &disconnected_tracing
, _("\
4906 Set whether tracing continues after GDB disconnects."), _("\
4907 Show whether tracing continues after GDB disconnects."), _("\
4908 Use this to continue a tracing run even if GDB disconnects\n\
4909 or detaches from the target. You can reconnect later and look at\n\
4910 trace data collected in the meantime."),
4911 set_disconnected_tracing
,
4916 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
4917 &circular_trace_buffer
, _("\
4918 Set target's use of circular trace buffer."), _("\
4919 Show target's use of circular trace buffer."), _("\
4920 Use this to make the trace buffer into a circular buffer,\n\
4921 which will discard traceframes (oldest first) instead of filling\n\
4922 up and stopping the trace run."),
4923 set_circular_trace_buffer
,
4930 add_target (&tfile_ops
);