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 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"
51 /* readline include files */
52 #include "readline/readline.h"
53 #include "readline/history.h"
55 /* readline defines this. */
66 extern int hex2bin (const char *hex
, gdb_byte
*bin
, int count
);
67 extern int bin2hex (const gdb_byte
*bin
, char *hex
, int count
);
69 extern void stop_tracing ();
71 /* Maximum length of an agent aexpression.
72 This accounts for the fact that packets are limited to 400 bytes
73 (which includes everything -- including the checksum), and assumes
74 the worst case of maximum length for each of the pieces of a
77 NOTE: expressions get mem2hex'ed otherwise this would be twice as
78 large. (400 - 31)/2 == 184 */
79 #define MAX_AGENT_EXPR_LEN 184
81 /* A hook used to notify the UI of tracepoint operations. */
83 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
84 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
86 extern void (*deprecated_readline_begin_hook
) (char *, ...);
87 extern char *(*deprecated_readline_hook
) (char *);
88 extern void (*deprecated_readline_end_hook
) (void);
90 /* GDB commands implemented in other modules:
93 extern void output_command (char *, int);
98 This module defines the following debugger commands:
99 trace : set a tracepoint on a function, line, or address.
100 info trace : list all debugger-defined tracepoints.
101 delete trace : delete one or more tracepoints.
102 enable trace : enable one or more tracepoints.
103 disable trace : disable one or more tracepoints.
104 actions : specify actions to be taken at a tracepoint.
105 passcount : specify a pass count for a tracepoint.
106 tstart : start a trace experiment.
107 tstop : stop a trace experiment.
108 tstatus : query the status of a trace experiment.
109 tfind : find a trace frame in the trace buffer.
110 tdump : print everything collected at the current tracepoint.
111 save-tracepoints : write tracepoint setup into a file.
113 This module defines the following user-visible debugger variables:
114 $trace_frame : sequence number of trace frame currently being debugged.
115 $trace_line : source line of trace frame currently being debugged.
116 $trace_file : source file of trace frame currently being debugged.
117 $tracepoint : tracepoint number of trace frame currently being debugged.
121 /* ======= Important global variables: ======= */
123 /* The list of all trace state variables. We don't retain pointers to
124 any of these for any reason - API is by name or number only - so it
125 works to have a vector of objects. */
127 typedef struct trace_state_variable tsv_s
;
130 static VEC(tsv_s
) *tvariables
;
132 /* The next integer to assign to a variable. */
134 static int next_tsv_number
= 1;
136 /* Number of last traceframe collected. */
137 static int traceframe_number
;
139 /* Tracepoint for last traceframe collected. */
140 static int tracepoint_number
;
142 /* Symbol for function for last traceframe collected */
143 static struct symbol
*traceframe_fun
;
145 /* Symtab and line for last traceframe collected */
146 static struct symtab_and_line traceframe_sal
;
148 /* Tracing command lists */
149 static struct cmd_list_element
*tfindlist
;
151 /* List of expressions to collect by default at each tracepoint hit. */
152 char *default_collect
= "";
154 static int disconnected_tracing
;
156 /* This variable controls whether we ask the target for a linear or
157 circular trace buffer. */
159 static int circular_trace_buffer
;
161 /* ======= Important command functions: ======= */
162 static void trace_actions_command (char *, int);
163 static void trace_start_command (char *, int);
164 static void trace_stop_command (char *, int);
165 static void trace_status_command (char *, int);
166 static void trace_find_command (char *, int);
167 static void trace_find_pc_command (char *, int);
168 static void trace_find_tracepoint_command (char *, int);
169 static void trace_find_line_command (char *, int);
170 static void trace_find_range_command (char *, int);
171 static void trace_find_outside_command (char *, int);
172 static void trace_dump_command (char *, int);
174 /* support routines */
176 struct collection_list
;
177 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
178 static char *mem2hex (gdb_byte
*, char *, int);
179 static void add_register (struct collection_list
*collection
,
182 extern void send_disconnected_tracing_value (int value
);
184 static void free_uploaded_tps (struct uploaded_tp
**utpp
);
185 static void free_uploaded_tsvs (struct uploaded_tsv
**utsvp
);
188 extern void _initialize_tracepoint (void);
190 static struct trace_status trace_status
;
192 char *stop_reason_names
[] = {
201 struct trace_status
*
202 current_trace_status ()
204 return &trace_status
;
207 /* Set traceframe number to NUM. */
209 set_traceframe_num (int num
)
211 traceframe_number
= num
;
212 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
215 /* Set tracepoint number to NUM. */
217 set_tracepoint_num (int num
)
219 tracepoint_number
= num
;
220 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
223 /* Set externally visible debug variables for querying/printing
224 the traceframe context (line, function, file) */
227 set_traceframe_context (struct frame_info
*trace_frame
)
231 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
234 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
235 traceframe_sal
.symtab
= NULL
;
236 clear_internalvar (lookup_internalvar ("trace_func"));
237 clear_internalvar (lookup_internalvar ("trace_file"));
238 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
242 /* Save as globals for internal use. */
243 trace_pc
= get_frame_pc (trace_frame
);
244 traceframe_sal
= find_pc_line (trace_pc
, 0);
245 traceframe_fun
= find_pc_function (trace_pc
);
247 /* Save linenumber as "$trace_line", a debugger variable visible to
249 set_internalvar_integer (lookup_internalvar ("trace_line"),
250 traceframe_sal
.line
);
252 /* Save func name as "$trace_func", a debugger variable visible to
254 if (traceframe_fun
== NULL
255 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
256 clear_internalvar (lookup_internalvar ("trace_func"));
258 set_internalvar_string (lookup_internalvar ("trace_func"),
259 SYMBOL_LINKAGE_NAME (traceframe_fun
));
261 /* Save file name as "$trace_file", a debugger variable visible to
263 if (traceframe_sal
.symtab
== NULL
264 || traceframe_sal
.symtab
->filename
== NULL
)
265 clear_internalvar (lookup_internalvar ("trace_file"));
267 set_internalvar_string (lookup_internalvar ("trace_file"),
268 traceframe_sal
.symtab
->filename
);
271 /* Create a new trace state variable with the given name. */
273 struct trace_state_variable
*
274 create_trace_state_variable (const char *name
)
276 struct trace_state_variable tsv
;
278 memset (&tsv
, 0, sizeof (tsv
));
279 tsv
.name
= xstrdup (name
);
280 tsv
.number
= next_tsv_number
++;
281 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
284 /* Look for a trace state variable of the given name. */
286 struct trace_state_variable
*
287 find_trace_state_variable (const char *name
)
289 struct trace_state_variable
*tsv
;
292 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
293 if (strcmp (name
, tsv
->name
) == 0)
300 delete_trace_state_variable (const char *name
)
302 struct trace_state_variable
*tsv
;
305 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
306 if (strcmp (name
, tsv
->name
) == 0)
308 xfree ((void *)tsv
->name
);
309 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
313 warning (_("No trace variable named \"$%s\", not deleting"), name
);
316 /* The 'tvariable' command collects a name and optional expression to
317 evaluate into an initial value. */
320 trace_variable_command (char *args
, int from_tty
)
322 struct expression
*expr
;
323 struct cleanup
*old_chain
;
324 struct internalvar
*intvar
= NULL
;
326 struct trace_state_variable
*tsv
;
329 error_no_arg (_("trace state variable name"));
331 /* All the possible valid arguments are expressions. */
332 expr
= parse_expression (args
);
333 old_chain
= make_cleanup (free_current_contents
, &expr
);
335 if (expr
->nelts
== 0)
336 error (_("No expression?"));
338 /* Only allow two syntaxes; "$name" and "$name=value". */
339 if (expr
->elts
[0].opcode
== OP_INTERNALVAR
)
341 intvar
= expr
->elts
[1].internalvar
;
343 else if (expr
->elts
[0].opcode
== BINOP_ASSIGN
344 && expr
->elts
[1].opcode
== OP_INTERNALVAR
)
346 intvar
= expr
->elts
[2].internalvar
;
347 initval
= value_as_long (evaluate_subexpression_type (expr
, 4));
350 error (_("Syntax must be $NAME [ = EXPR ]"));
353 error (_("No name given"));
355 if (strlen (internalvar_name (intvar
)) <= 0)
356 error (_("Must supply a non-empty variable name"));
358 /* If the variable already exists, just change its initial value. */
359 tsv
= find_trace_state_variable (internalvar_name (intvar
));
362 tsv
->initial_value
= initval
;
363 printf_filtered (_("Trace state variable $%s now has initial value %s.\n"),
364 tsv
->name
, plongest (tsv
->initial_value
));
368 /* Create a new variable. */
369 tsv
= create_trace_state_variable (internalvar_name (intvar
));
370 tsv
->initial_value
= initval
;
372 printf_filtered (_("Trace state variable $%s created, with initial value %s.\n"),
373 tsv
->name
, plongest (tsv
->initial_value
));
375 do_cleanups (old_chain
);
379 delete_trace_variable_command (char *args
, int from_tty
)
383 struct cleanup
*back_to
;
384 struct trace_state_variable
*tsv
;
388 if (query (_("Delete all trace state variables? ")))
389 VEC_free (tsv_s
, tvariables
);
394 argv
= gdb_buildargv (args
);
395 back_to
= make_cleanup_freeargv (argv
);
397 for (i
= 0; argv
[i
] != NULL
; i
++)
400 delete_trace_state_variable (argv
[i
] + 1);
402 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv
[i
]);
405 do_cleanups (back_to
);
411 tvariables_info_1 (void)
413 struct trace_state_variable
*tsv
;
416 struct cleanup
*back_to
;
418 if (VEC_length (tsv_s
, tvariables
) == 0 && !ui_out_is_mi_like_p (uiout
))
420 printf_filtered (_("No trace state variables.\n"));
424 /* Try to acquire values from the target. */
425 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
426 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
429 back_to
= make_cleanup_ui_out_table_begin_end (uiout
, 3,
430 count
, "trace-variables");
431 ui_out_table_header (uiout
, 15, ui_left
, "name", "Name");
432 ui_out_table_header (uiout
, 11, ui_left
, "initial", "Initial");
433 ui_out_table_header (uiout
, 11, ui_left
, "current", "Current");
435 ui_out_table_body (uiout
);
437 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
439 struct cleanup
*back_to2
;
443 back_to2
= make_cleanup_ui_out_tuple_begin_end (uiout
, "variable");
445 name
= concat ("$", tsv
->name
, NULL
);
446 make_cleanup (xfree
, name
);
447 ui_out_field_string (uiout
, "name", name
);
448 ui_out_field_string (uiout
, "initial", plongest (tsv
->initial_value
));
450 if (tsv
->value_known
)
451 c
= plongest (tsv
->value
);
452 else if (ui_out_is_mi_like_p (uiout
))
453 /* For MI, we prefer not to use magic string constants, but rather
454 omit the field completely. The difference between unknown and
455 undefined does not seem important enough to represent. */
457 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
458 /* The value is/was defined, but we don't have it. */
461 /* It is not meaningful to ask about the value. */
464 ui_out_field_string (uiout
, "current", c
);
465 ui_out_text (uiout
, "\n");
467 do_cleanups (back_to2
);
470 do_cleanups (back_to
);
473 /* List all the trace state variables. */
476 tvariables_info (char *args
, int from_tty
)
478 tvariables_info_1 ();
481 /* ACTIONS functions: */
483 /* The three functions:
484 collect_pseudocommand,
485 while_stepping_pseudocommand, and
486 end_actions_pseudocommand
487 are placeholders for "commands" that are actually ONLY to be used
488 within a tracepoint action list. If the actual function is ever called,
489 it means that somebody issued the "command" at the top level,
490 which is always an error. */
493 end_actions_pseudocommand (char *args
, int from_tty
)
495 error (_("This command cannot be used at the top level."));
499 while_stepping_pseudocommand (char *args
, int from_tty
)
501 error (_("This command can only be used in a tracepoint actions list."));
505 collect_pseudocommand (char *args
, int from_tty
)
507 error (_("This command can only be used in a tracepoint actions list."));
511 teval_pseudocommand (char *args
, int from_tty
)
513 error (_("This command can only be used in a tracepoint actions list."));
516 /* Enter a list of actions for a tracepoint. */
518 trace_actions_command (char *args
, int from_tty
)
520 struct breakpoint
*t
;
521 struct command_line
*l
;
523 t
= get_tracepoint_by_number (&args
, 0, 1);
527 xstrprintf ("Enter actions for tracepoint %d, one per line.",
529 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
531 l
= read_command_lines (tmpbuf
, from_tty
, 1, check_tracepoint_command
, t
);
532 do_cleanups (cleanups
);
533 breakpoint_set_commands (t
, l
);
535 /* else just return */
538 /* worker function */
540 validate_actionline (char **line
, struct breakpoint
*t
)
542 struct cmd_list_element
*c
;
543 struct expression
*exp
= NULL
;
544 struct cleanup
*old_chain
= NULL
;
546 struct bp_location
*loc
;
548 /* if EOF is typed, *line is NULL */
552 for (p
= *line
; isspace ((int) *p
);)
555 /* Symbol lookup etc. */
556 if (*p
== '\0') /* empty line: just prompt for another line. */
559 if (*p
== '#') /* comment line */
562 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
565 warning (_("'%s' is not an action that I know, or is ambiguous."),
570 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
572 struct agent_expr
*aexpr
;
573 struct agent_reqs areqs
;
576 { /* repeat over a comma-separated list */
577 QUIT
; /* allow user to bail out with ^C */
578 while (isspace ((int) *p
))
581 if (*p
== '$') /* look for special pseudo-symbols */
583 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
584 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
585 (0 == strncasecmp ("loc", p
+ 1, 3)))
590 /* else fall thru, treat p as an expression and parse it! */
593 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
596 exp
= parse_exp_1 (&p
, block_for_pc (loc
->address
), 1);
597 old_chain
= make_cleanup (free_current_contents
, &exp
);
599 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
601 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
603 warning (_("constant %s (value %ld) will not be collected."),
604 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
605 SYMBOL_VALUE (exp
->elts
[2].symbol
));
608 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
610 warning (_("%s is optimized away and cannot be collected."),
611 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
616 /* We have something to collect, make sure that the expr to
617 bytecode translator can handle it and that it's not too
619 aexpr
= gen_trace_for_expr (loc
->address
, exp
);
620 make_cleanup_free_agent_expr (aexpr
);
622 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
623 error (_("expression too complicated, try simplifying"));
625 ax_reqs (aexpr
, &areqs
);
626 (void) make_cleanup (xfree
, areqs
.reg_mask
);
628 if (areqs
.flaw
!= agent_flaw_none
)
629 error (_("malformed expression"));
631 if (areqs
.min_height
< 0)
632 error (_("gdb: Internal error: expression has min height < 0"));
634 if (areqs
.max_height
> 20)
635 error (_("expression too complicated, try simplifying"));
637 do_cleanups (old_chain
);
640 while (p
&& *p
++ == ',');
643 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
645 struct agent_expr
*aexpr
;
648 { /* repeat over a comma-separated list */
649 QUIT
; /* allow user to bail out with ^C */
650 while (isspace ((int) *p
))
654 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
657 /* Only expressions are allowed for this action. */
658 exp
= parse_exp_1 (&p
, block_for_pc (loc
->address
), 1);
659 old_chain
= make_cleanup (free_current_contents
, &exp
);
661 /* We have something to evaluate, make sure that the expr to
662 bytecode translator can handle it and that it's not too
664 aexpr
= gen_eval_for_expr (loc
->address
, exp
);
665 make_cleanup_free_agent_expr (aexpr
);
667 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
668 error (_("expression too complicated, try simplifying"));
670 do_cleanups (old_chain
);
673 while (p
&& *p
++ == ',');
676 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
678 char *steparg
; /* in case warning is necessary */
680 while (isspace ((int) *p
))
685 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
687 error (_("'%s': bad step-count."), *line
);
691 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
695 error (_("'%s' is not a supported tracepoint action."), *line
);
700 memrange_absolute
= -1
705 int type
; /* memrange_absolute for absolute memory range,
706 else basereg number */
707 bfd_signed_vma start
;
711 struct collection_list
713 unsigned char regs_mask
[32]; /* room for up to 256 regs */
716 struct memrange
*list
;
717 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
719 struct agent_expr
**aexpr_list
;
722 tracepoint_list
, stepping_list
;
724 /* MEMRANGE functions: */
726 static int memrange_cmp (const void *, const void *);
728 /* compare memranges for qsort */
730 memrange_cmp (const void *va
, const void *vb
)
732 const struct memrange
*a
= va
, *b
= vb
;
734 if (a
->type
< b
->type
)
736 if (a
->type
> b
->type
)
738 if (a
->type
== memrange_absolute
)
740 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
742 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
747 if (a
->start
< b
->start
)
749 if (a
->start
> b
->start
)
755 /* Sort the memrange list using qsort, and merge adjacent memranges. */
757 memrange_sortmerge (struct collection_list
*memranges
)
761 qsort (memranges
->list
, memranges
->next_memrange
,
762 sizeof (struct memrange
), memrange_cmp
);
763 if (memranges
->next_memrange
> 0)
765 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
767 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
768 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
771 /* memrange b starts before memrange a ends; merge them. */
772 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
773 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
774 continue; /* next b, same a */
778 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
779 sizeof (struct memrange
));
781 memranges
->next_memrange
= a
+ 1;
785 /* Add a register to a collection list. */
787 add_register (struct collection_list
*collection
, unsigned int regno
)
790 printf_filtered ("collect register %d\n", regno
);
791 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
792 error (_("Internal: register number %d too large for tracepoint"),
794 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
797 /* Add a memrange to a collection list */
799 add_memrange (struct collection_list
*memranges
,
800 int type
, bfd_signed_vma base
,
805 printf_filtered ("(%d,", type
);
807 printf_filtered (",%ld)\n", len
);
810 /* type: memrange_absolute == memory, other n == basereg */
811 memranges
->list
[memranges
->next_memrange
].type
= type
;
812 /* base: addr if memory, offset if reg relative. */
813 memranges
->list
[memranges
->next_memrange
].start
= base
;
814 /* len: we actually save end (base + len) for convenience */
815 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
816 memranges
->next_memrange
++;
817 if (memranges
->next_memrange
>= memranges
->listsize
)
819 memranges
->listsize
*= 2;
820 memranges
->list
= xrealloc (memranges
->list
,
821 memranges
->listsize
);
824 if (type
!= memrange_absolute
) /* Better collect the base register! */
825 add_register (memranges
, type
);
828 /* Add a symbol to a collection list. */
830 collect_symbol (struct collection_list
*collect
,
832 struct gdbarch
*gdbarch
,
833 long frame_regno
, long frame_offset
,
838 bfd_signed_vma offset
;
839 int treat_as_expr
= 0;
841 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
842 switch (SYMBOL_CLASS (sym
))
845 printf_filtered ("%s: don't know symbol class %d\n",
846 SYMBOL_PRINT_NAME (sym
),
850 printf_filtered ("constant %s (value %ld) will not be collected.\n",
851 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
854 offset
= SYMBOL_VALUE_ADDRESS (sym
);
859 sprintf_vma (tmp
, offset
);
860 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
861 SYMBOL_PRINT_NAME (sym
), len
,
864 /* A struct may be a C++ class with static fields, go to general
865 expression handling. */
866 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
869 add_memrange (collect
, memrange_absolute
, offset
, len
);
872 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
874 printf_filtered ("LOC_REG[parm] %s: ",
875 SYMBOL_PRINT_NAME (sym
));
876 add_register (collect
, reg
);
877 /* Check for doubles stored in two registers. */
878 /* FIXME: how about larger types stored in 3 or more regs? */
879 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
880 len
> register_size (gdbarch
, reg
))
881 add_register (collect
, reg
+ 1);
884 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
885 printf_filtered (" (will not collect %s)\n",
886 SYMBOL_PRINT_NAME (sym
));
890 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
893 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
894 SYMBOL_PRINT_NAME (sym
), len
);
896 printf_filtered (" from frame ptr reg %d\n", reg
);
898 add_memrange (collect
, reg
, offset
, len
);
900 case LOC_REGPARM_ADDR
:
901 reg
= SYMBOL_VALUE (sym
);
905 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
906 SYMBOL_PRINT_NAME (sym
), len
);
908 printf_filtered (" from reg %d\n", reg
);
910 add_memrange (collect
, reg
, offset
, len
);
914 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
917 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
918 SYMBOL_PRINT_NAME (sym
), len
);
920 printf_filtered (" from frame ptr reg %d\n", reg
);
922 add_memrange (collect
, reg
, offset
, len
);
925 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
926 SYMBOL_PRINT_NAME (sym
));
928 case LOC_OPTIMIZED_OUT
:
929 printf_filtered ("%s has been optimized out of existence.\n",
930 SYMBOL_PRINT_NAME (sym
));
938 /* Expressions are the most general case. */
941 struct agent_expr
*aexpr
;
942 struct cleanup
*old_chain1
= NULL
;
943 struct agent_reqs areqs
;
945 aexpr
= gen_trace_for_var (scope
, gdbarch
, sym
);
947 /* It can happen that the symbol is recorded as a computed
948 location, but it's been optimized away and doesn't actually
949 have a location expression. */
952 printf_filtered ("%s has been optimized out of existence.\n",
953 SYMBOL_PRINT_NAME (sym
));
957 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
959 ax_reqs (aexpr
, &areqs
);
960 if (areqs
.flaw
!= agent_flaw_none
)
961 error (_("malformed expression"));
963 if (areqs
.min_height
< 0)
964 error (_("gdb: Internal error: expression has min height < 0"));
965 if (areqs
.max_height
> 20)
966 error (_("expression too complicated, try simplifying"));
968 discard_cleanups (old_chain1
);
969 add_aexpr (collect
, aexpr
);
971 /* take care of the registers */
972 if (areqs
.reg_mask_len
> 0)
976 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
978 QUIT
; /* allow user to bail out with ^C */
979 if (areqs
.reg_mask
[ndx1
] != 0)
981 /* assume chars have 8 bits */
982 for (ndx2
= 0; ndx2
< 8; ndx2
++)
983 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
984 /* it's used -- record it */
985 add_register (collect
, ndx1
* 8 + ndx2
);
992 /* Add all locals (or args) symbols to collection list */
994 add_local_symbols (struct collection_list
*collect
,
995 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
996 long frame_regno
, long frame_offset
, int type
)
1000 struct dict_iterator iter
;
1003 block
= block_for_pc (pc
);
1006 QUIT
; /* allow user to bail out with ^C */
1007 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1009 if (SYMBOL_IS_ARGUMENT (sym
)
1010 ? type
== 'A' /* collecting Arguments */
1011 : type
== 'L') /* collecting Locals */
1014 collect_symbol (collect
, sym
, gdbarch
,
1015 frame_regno
, frame_offset
, pc
);
1018 if (BLOCK_FUNCTION (block
))
1021 block
= BLOCK_SUPERBLOCK (block
);
1024 warning (_("No %s found in scope."),
1025 type
== 'L' ? "locals" : "args");
1028 /* worker function */
1030 clear_collection_list (struct collection_list
*list
)
1034 list
->next_memrange
= 0;
1035 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1037 free_agent_expr (list
->aexpr_list
[ndx
]);
1038 list
->aexpr_list
[ndx
] = NULL
;
1040 list
->next_aexpr_elt
= 0;
1041 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1044 /* reduce a collection list to string form (for gdb protocol) */
1046 stringify_collection_list (struct collection_list
*list
, char *string
)
1048 char temp_buf
[2048];
1052 char *(*str_list
)[];
1056 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1057 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1059 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1060 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1062 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1065 printf_filtered ("\nCollecting registers (mask): 0x");
1070 QUIT
; /* allow user to bail out with ^C */
1072 printf_filtered ("%02X", list
->regs_mask
[i
]);
1073 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1076 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1080 printf_filtered ("\n");
1081 if (list
->next_memrange
> 0 && info_verbose
)
1082 printf_filtered ("Collecting memranges: \n");
1083 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1085 QUIT
; /* allow user to bail out with ^C */
1086 sprintf_vma (tmp2
, list
->list
[i
].start
);
1089 printf_filtered ("(%d, %s, %ld)\n",
1092 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1094 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1096 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1103 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
1105 /* The "%X" conversion specifier expects an unsigned argument,
1106 so passing -1 (memrange_absolute) to it directly gives you
1107 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1109 if (list
->list
[i
].type
== memrange_absolute
)
1110 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1112 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
1115 count
+= strlen (end
);
1116 end
= temp_buf
+ count
;
1119 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1121 QUIT
; /* allow user to bail out with ^C */
1122 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1124 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1129 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1130 end
+= 10; /* 'X' + 8 hex digits + ',' */
1133 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1134 end
, list
->aexpr_list
[i
]->len
);
1135 count
+= 2 * list
->aexpr_list
[i
]->len
;
1140 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1145 (*str_list
)[ndx
] = NULL
;
1158 encode_actions_1 (struct command_line
*action
,
1159 struct breakpoint
*t
,
1160 struct bp_location
*tloc
,
1162 LONGEST frame_offset
,
1163 struct collection_list
*collect
,
1164 struct collection_list
*stepping_list
)
1167 struct expression
*exp
= NULL
;
1168 struct command_line
*actions
;
1170 struct value
*tempval
;
1171 struct cmd_list_element
*cmd
;
1172 struct agent_expr
*aexpr
;
1174 for (; action
; action
= action
->next
)
1176 QUIT
; /* allow user to bail out with ^C */
1177 action_exp
= action
->line
;
1178 while (isspace ((int) *action_exp
))
1181 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1183 error (_("Bad action list item: %s"), action_exp
);
1185 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1188 { /* repeat over a comma-separated list */
1189 QUIT
; /* allow user to bail out with ^C */
1190 while (isspace ((int) *action_exp
))
1193 if (0 == strncasecmp ("$reg", action_exp
, 4))
1195 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1196 add_register (collect
, i
);
1197 action_exp
= strchr (action_exp
, ','); /* more? */
1199 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1201 add_local_symbols (collect
,
1207 action_exp
= strchr (action_exp
, ','); /* more? */
1209 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1211 add_local_symbols (collect
,
1217 action_exp
= strchr (action_exp
, ','); /* more? */
1221 unsigned long addr
, len
;
1222 struct cleanup
*old_chain
= NULL
;
1223 struct cleanup
*old_chain1
= NULL
;
1224 struct agent_reqs areqs
;
1226 exp
= parse_exp_1 (&action_exp
,
1227 block_for_pc (tloc
->address
), 1);
1228 old_chain
= make_cleanup (free_current_contents
, &exp
);
1230 switch (exp
->elts
[0].opcode
)
1234 const char *name
= &exp
->elts
[2].string
;
1236 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1237 name
, strlen (name
));
1239 internal_error (__FILE__
, __LINE__
,
1240 _("Register $%s not available"),
1243 printf_filtered ("OP_REGISTER: ");
1244 add_register (collect
, i
);
1249 /* safe because we know it's a simple expression */
1250 tempval
= evaluate_expression (exp
);
1251 addr
= value_address (tempval
);
1252 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1253 add_memrange (collect
, memrange_absolute
, addr
, len
);
1257 collect_symbol (collect
,
1258 exp
->elts
[2].symbol
,
1265 default: /* full-fledged expression */
1266 aexpr
= gen_trace_for_expr (tloc
->address
, exp
);
1268 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1270 ax_reqs (aexpr
, &areqs
);
1271 if (areqs
.flaw
!= agent_flaw_none
)
1272 error (_("malformed expression"));
1274 if (areqs
.min_height
< 0)
1275 error (_("gdb: Internal error: expression has min height < 0"));
1276 if (areqs
.max_height
> 20)
1277 error (_("expression too complicated, try simplifying"));
1279 discard_cleanups (old_chain1
);
1280 add_aexpr (collect
, aexpr
);
1282 /* take care of the registers */
1283 if (areqs
.reg_mask_len
> 0)
1288 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1290 QUIT
; /* allow user to bail out with ^C */
1291 if (areqs
.reg_mask
[ndx1
] != 0)
1293 /* assume chars have 8 bits */
1294 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1295 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1296 /* it's used -- record it */
1297 add_register (collect
,
1304 do_cleanups (old_chain
);
1307 while (action_exp
&& *action_exp
++ == ',');
1309 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1312 { /* repeat over a comma-separated list */
1313 QUIT
; /* allow user to bail out with ^C */
1314 while (isspace ((int) *action_exp
))
1318 unsigned long addr
, len
;
1319 struct cleanup
*old_chain
= NULL
;
1320 struct cleanup
*old_chain1
= NULL
;
1321 struct agent_reqs areqs
;
1323 exp
= parse_exp_1 (&action_exp
,
1324 block_for_pc (tloc
->address
), 1);
1325 old_chain
= make_cleanup (free_current_contents
, &exp
);
1327 aexpr
= gen_eval_for_expr (tloc
->address
, exp
);
1328 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1330 ax_reqs (aexpr
, &areqs
);
1331 if (areqs
.flaw
!= agent_flaw_none
)
1332 error (_("malformed expression"));
1334 if (areqs
.min_height
< 0)
1335 error (_("gdb: Internal error: expression has min height < 0"));
1336 if (areqs
.max_height
> 20)
1337 error (_("expression too complicated, try simplifying"));
1339 discard_cleanups (old_chain1
);
1340 /* Even though we're not officially collecting, add
1341 to the collect list anyway. */
1342 add_aexpr (collect
, aexpr
);
1344 do_cleanups (old_chain
);
1347 while (action_exp
&& *action_exp
++ == ',');
1349 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1351 /* We check against nested while-stepping when setting
1352 breakpoint action, so no way to run into nested
1354 gdb_assert (stepping_list
);
1356 encode_actions_1 (action
->body_list
[0], t
, tloc
, frame_reg
, frame_offset
,
1357 stepping_list
, NULL
);
1360 error (_("Invalid tracepoint command '%s'"), action
->line
);
1364 /* Render all actions into gdb protocol. */
1366 encode_actions (struct breakpoint
*t
, struct bp_location
*tloc
,
1367 char ***tdp_actions
, char ***stepping_actions
)
1369 static char tdp_buff
[2048], step_buff
[2048];
1370 char *default_collect_line
= NULL
;
1371 struct command_line
*actions
;
1372 struct command_line
*default_collect_action
= NULL
;
1374 LONGEST frame_offset
;
1375 struct cleanup
*back_to
;
1377 back_to
= make_cleanup (null_cleanup
, NULL
);
1379 clear_collection_list (&tracepoint_list
);
1380 clear_collection_list (&stepping_list
);
1382 *tdp_actions
= NULL
;
1383 *stepping_actions
= NULL
;
1385 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1386 t
->loc
->address
, &frame_reg
, &frame_offset
);
1388 actions
= t
->commands
;
1390 /* If there are default expressions to collect, make up a collect
1391 action and prepend to the action list to encode. Note that since
1392 validation is per-tracepoint (local var "xyz" might be valid for
1393 one tracepoint and not another, etc), we make up the action on
1394 the fly, and don't cache it. */
1395 if (*default_collect
)
1398 enum actionline_type linetype
;
1400 default_collect_line
= xstrprintf ("collect %s", default_collect
);
1401 make_cleanup (xfree
, default_collect_line
);
1403 line
= default_collect_line
;
1404 linetype
= validate_actionline (&line
, t
);
1405 if (linetype
!= BADLINE
)
1407 default_collect_action
= xmalloc (sizeof (struct command_line
));
1408 make_cleanup (xfree
, default_collect_action
);
1409 default_collect_action
->next
= t
->commands
;
1410 default_collect_action
->line
= line
;
1411 actions
= default_collect_action
;
1414 encode_actions_1 (actions
, t
, tloc
, frame_reg
, frame_offset
,
1415 &tracepoint_list
, &stepping_list
);
1417 memrange_sortmerge (&tracepoint_list
);
1418 memrange_sortmerge (&stepping_list
);
1420 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1422 *stepping_actions
= stringify_collection_list (&stepping_list
,
1425 do_cleanups (back_to
);
1429 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1431 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1433 collect
->aexpr_list
=
1434 xrealloc (collect
->aexpr_list
,
1435 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1436 collect
->aexpr_listsize
*= 2;
1438 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1439 collect
->next_aexpr_elt
++;
1444 start_tracing (void)
1447 VEC(breakpoint_p
) *tp_vec
= NULL
;
1449 struct breakpoint
*t
;
1450 struct trace_state_variable
*tsv
;
1451 int any_downloaded
= 0;
1453 target_trace_init ();
1455 tp_vec
= all_tracepoints ();
1456 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1458 t
->number_on_target
= 0;
1459 target_download_tracepoint (t
);
1460 t
->number_on_target
= t
->number
;
1463 VEC_free (breakpoint_p
, tp_vec
);
1465 /* No point in tracing without any tracepoints... */
1466 if (!any_downloaded
)
1467 error ("No tracepoints downloaded, not starting trace");
1469 /* Send down all the trace state variables too. */
1470 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1472 target_download_trace_state_variable (tsv
);
1475 /* Tell target to treat text-like sections as transparent. */
1476 target_trace_set_readonly_regions ();
1477 /* Set some mode flags. */
1478 target_set_disconnected_tracing (disconnected_tracing
);
1479 target_set_circular_trace_buffer (circular_trace_buffer
);
1481 /* Now insert traps and begin collecting data. */
1482 target_trace_start ();
1484 /* Reset our local state. */
1485 set_traceframe_num (-1);
1486 set_tracepoint_num (-1);
1487 set_traceframe_context (NULL
);
1488 current_trace_status()->running
= 1;
1493 Tell target to clear any previous trace experiment.
1494 Walk the list of tracepoints, and send them (and their actions)
1495 to the target. If no errors,
1496 Tell target to start a new trace experiment. */
1499 trace_start_command (char *args
, int from_tty
)
1501 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1508 trace_stop_command (char *args
, int from_tty
)
1516 target_trace_stop ();
1517 /* should change in response to reply? */
1518 current_trace_status ()->running
= 0;
1521 /* tstatus command */
1523 trace_status_command (char *args
, int from_tty
)
1525 struct trace_status
*ts
= current_trace_status ();
1528 status
= target_get_trace_status (ts
);
1533 printf_filtered (_("Using a trace file.\n"));
1536 printf_filtered (_("Trace can not be run on this target.\n"));
1541 if (!ts
->running_known
)
1543 printf_filtered (_("Run/stop status is unknown.\n"));
1545 else if (ts
->running
)
1547 printf_filtered (_("Trace is running on the target.\n"));
1548 if (disconnected_tracing
)
1549 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1551 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1555 switch (ts
->stop_reason
)
1557 case trace_never_run
:
1558 printf_filtered (_("No trace has been run on the target.\n"));
1561 printf_filtered (_("Trace stopped by a tstop command.\n"));
1563 case trace_buffer_full
:
1564 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1566 case trace_disconnected
:
1567 printf_filtered (_("Trace stopped because of disconnection.\n"));
1569 case tracepoint_passcount
:
1570 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1571 ts
->stopping_tracepoint
);
1573 case trace_stop_reason_unknown
:
1574 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1577 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1583 if (ts
->traceframes_created
>= 0
1584 && ts
->traceframe_count
!= ts
->traceframes_created
)
1586 printf_filtered (_("Buffer contains %d trace frames (of %d created total).\n"),
1587 ts
->traceframe_count
, ts
->traceframes_created
);
1589 else if (ts
->traceframe_count
>= 0)
1591 printf_filtered (_("Collected %d trace frames.\n"),
1592 ts
->traceframe_count
);
1595 if (ts
->buffer_free
>= 0)
1597 if (ts
->buffer_size
>= 0)
1599 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1600 ts
->buffer_free
, ts
->buffer_size
);
1601 if (ts
->buffer_size
> 0)
1602 printf_filtered (_(" (%d%% full)"),
1603 ((int) ((((long long) (ts
->buffer_size
1604 - ts
->buffer_free
)) * 100)
1605 / ts
->buffer_size
)));
1606 printf_filtered (_(".\n"));
1609 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1613 /* Now report on what we're doing with tfind. */
1614 if (traceframe_number
>= 0)
1615 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1616 traceframe_number
, tracepoint_number
);
1618 printf_filtered (_("Not looking at any trace frame.\n"));
1621 /* Report the trace status to uiout, in a way suitable for MI, and not
1622 suitable for CLI. If ON_STOP is true, suppress a few fields that
1623 are not meaningful in the -trace-stop response.
1625 The implementation is essentially parallel to trace_status_command, but
1626 merging them will result in unreadable code. */
1628 trace_status_mi (int on_stop
)
1630 struct trace_status
*ts
= current_trace_status ();
1632 char *string_status
;
1634 status
= target_get_trace_status (ts
);
1636 if (status
== -1 && !ts
->from_file
)
1638 ui_out_field_string (uiout
, "supported", "0");
1643 ui_out_field_string (uiout
, "supported", "file");
1645 ui_out_field_string (uiout
, "supported", "1");
1647 gdb_assert (ts
->running_known
);
1651 ui_out_field_string (uiout
, "running", "1");
1653 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
1654 Given that the frontend gets the status either on -trace-stop, or from
1655 -trace-status after re-connection, it does not seem like this
1656 information is necessary for anything. It is not necessary for either
1657 figuring the vital state of the target nor for navigation of trace
1658 frames. If the frontend wants to show the current state is some
1659 configure dialog, it can request the value when such dialog is
1660 invoked by the user. */
1664 char *stop_reason
= NULL
;
1665 int stopping_tracepoint
= -1;
1668 ui_out_field_string (uiout
, "running", "0");
1670 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
1672 switch (ts
->stop_reason
)
1675 stop_reason
= "request";
1677 case trace_buffer_full
:
1678 stop_reason
= "overflow";
1680 case trace_disconnected
:
1681 stop_reason
= "disconnection";
1683 case tracepoint_passcount
:
1684 stop_reason
= "passcount";
1685 stopping_tracepoint
= ts
->stopping_tracepoint
;
1691 ui_out_field_string (uiout
, "stop-reason", stop_reason
);
1692 if (stopping_tracepoint
!= -1)
1693 ui_out_field_int (uiout
, "stopping-tracepoint",
1694 stopping_tracepoint
);
1700 if ((int) ts
->traceframe_count
!= -1)
1701 ui_out_field_int (uiout
, "frames", ts
->traceframe_count
);
1702 if ((int) ts
->buffer_size
!= -1)
1703 ui_out_field_int (uiout
, "buffer-size", (int) ts
->buffer_size
);
1704 if ((int) ts
->buffer_free
!= -1)
1705 ui_out_field_int (uiout
, "buffer-free", (int) ts
->buffer_free
);
1710 disconnect_or_stop_tracing (int from_tty
)
1712 /* It can happen that the target that was tracing went away on its
1713 own, and we didn't notice. Get a status update, and if the
1714 current target doesn't even do tracing, then assume it's not
1716 if (target_get_trace_status (current_trace_status ()) < 0)
1717 current_trace_status ()->running
= 0;
1719 if (current_trace_status ()->running
&& from_tty
)
1721 int cont
= query (_("Trace is running. Continue tracing after detach? "));
1722 /* Note that we send the query result without affecting the
1723 user's setting of disconnected_tracing, so that the answer is
1725 send_disconnected_tracing_value (cont
);
1727 /* Also ensure that we do the equivalent of a tstop command if
1728 tracing is not to continue after the detach. */
1734 /* Worker function for the various flavors of the tfind command. */
1736 tfind_1 (enum trace_find_type type
, int num
,
1737 ULONGEST addr1
, ULONGEST addr2
,
1740 int target_frameno
= -1, target_tracept
= -1;
1741 struct frame_id old_frame_id
;
1743 struct breakpoint
*tp
;
1745 old_frame_id
= get_frame_id (get_current_frame ());
1747 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
1750 if (type
== tfind_number
1752 && target_frameno
== -1)
1754 /* We told the target to get out of tfind mode, and it did. */
1756 else if (target_frameno
== -1)
1758 /* A request for a non-existant trace frame has failed.
1759 Our response will be different, depending on FROM_TTY:
1761 If FROM_TTY is true, meaning that this command was
1762 typed interactively by the user, then give an error
1763 and DO NOT change the state of traceframe_number etc.
1765 However if FROM_TTY is false, meaning that we're either
1766 in a script, a loop, or a user-defined command, then
1767 DON'T give an error, but DO change the state of
1768 traceframe_number etc. to invalid.
1770 The rationalle is that if you typed the command, you
1771 might just have committed a typo or something, and you'd
1772 like to NOT lose your current debugging state. However
1773 if you're in a user-defined command or especially in a
1774 loop, then you need a way to detect that the command
1775 failed WITHOUT aborting. This allows you to write
1776 scripts that search thru the trace buffer until the end,
1777 and then continue on to do something else. */
1780 error (_("Target failed to find requested trace frame."));
1784 printf_filtered ("End of trace buffer.\n");
1785 #if 0 /* dubious now? */
1786 /* The following will not recurse, since it's
1788 trace_find_command ("-1", from_tty
);
1793 tp
= get_tracepoint_by_number_on_target (target_tracept
);
1795 reinit_frame_cache ();
1796 registers_changed ();
1797 target_dcache_invalidate ();
1798 set_traceframe_num (target_frameno
);
1799 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
1800 if (target_frameno
== -1)
1801 set_traceframe_context (NULL
);
1803 set_traceframe_context (get_current_frame ());
1805 if (traceframe_number
>= 0)
1807 /* Use different branches for MI and CLI to make CLI messages
1809 if (ui_out_is_mi_like_p (uiout
))
1811 ui_out_field_string (uiout
, "found", "1");
1812 ui_out_field_int (uiout
, "tracepoint", tracepoint_number
);
1813 ui_out_field_int (uiout
, "traceframe", traceframe_number
);
1817 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
1818 traceframe_number
, tracepoint_number
);
1823 if (ui_out_is_mi_like_p (uiout
))
1824 ui_out_field_string (uiout
, "found", "0");
1826 printf_unfiltered (_("No trace frame found"));
1829 /* If we're in nonstop mode and getting out of looking at trace
1830 frames, there won't be any current frame to go back to and
1833 && (has_stack_frames () || traceframe_number
>= 0))
1835 enum print_what print_what
;
1837 /* NOTE: in immitation of the step command, try to determine
1838 whether we have made a transition from one function to
1839 another. If so, we'll print the "stack frame" (ie. the new
1840 function and it's arguments) -- otherwise we'll just show the
1843 if (frame_id_eq (old_frame_id
,
1844 get_frame_id (get_current_frame ())))
1845 print_what
= SRC_LINE
;
1847 print_what
= SRC_AND_LOC
;
1849 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1854 /* trace_find_command takes a trace frame number n,
1855 sends "QTFrame:<n>" to the target,
1856 and accepts a reply that may contain several optional pieces
1857 of information: a frame number, a tracepoint number, and an
1858 indication of whether this is a trap frame or a stepping frame.
1860 The minimal response is just "OK" (which indicates that the
1861 target does not give us a frame number or a tracepoint number).
1862 Instead of that, the target may send us a string containing
1864 F<hexnum> (gives the selected frame number)
1865 T<hexnum> (gives the selected tracepoint number)
1870 trace_find_command (char *args
, int from_tty
)
1871 { /* this should only be called with a numeric argument */
1874 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1875 error ("May not look at trace frames while trace is running.");
1877 if (args
== 0 || *args
== 0)
1878 { /* TFIND with no args means find NEXT trace frame. */
1879 if (traceframe_number
== -1)
1880 frameno
= 0; /* "next" is first one */
1882 frameno
= traceframe_number
+ 1;
1884 else if (0 == strcmp (args
, "-"))
1886 if (traceframe_number
== -1)
1887 error (_("not debugging trace buffer"));
1888 else if (from_tty
&& traceframe_number
== 0)
1889 error (_("already at start of trace buffer"));
1891 frameno
= traceframe_number
- 1;
1893 /* A hack to work around eval's need for fp to have been collected. */
1894 else if (0 == strcmp (args
, "-1"))
1897 frameno
= parse_and_eval_long (args
);
1900 error (_("invalid input (%d is less than zero)"), frameno
);
1902 tfind_1 (tfind_number
, frameno
, 0, 0, from_tty
);
1907 trace_find_end_command (char *args
, int from_tty
)
1909 trace_find_command ("-1", from_tty
);
1914 trace_find_none_command (char *args
, int from_tty
)
1916 trace_find_command ("-1", from_tty
);
1921 trace_find_start_command (char *args
, int from_tty
)
1923 trace_find_command ("0", from_tty
);
1926 /* tfind pc command */
1928 trace_find_pc_command (char *args
, int from_tty
)
1933 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1934 error ("May not look at trace frames while trace is running.");
1936 if (args
== 0 || *args
== 0)
1937 pc
= regcache_read_pc (get_current_regcache ());
1939 pc
= parse_and_eval_address (args
);
1941 tfind_1 (tfind_pc
, 0, pc
, 0, from_tty
);
1944 /* tfind tracepoint command */
1946 trace_find_tracepoint_command (char *args
, int from_tty
)
1949 struct breakpoint
*tp
;
1951 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1952 error ("May not look at trace frames while trace is running.");
1954 if (args
== 0 || *args
== 0)
1956 if (tracepoint_number
== -1)
1957 error (_("No current tracepoint -- please supply an argument."));
1959 tdp
= tracepoint_number
; /* default is current TDP */
1962 tdp
= parse_and_eval_long (args
);
1964 /* If we have the tracepoint on hand, use the number that the
1965 target knows about (which may be different if we disconnected
1966 and reconnected). */
1967 tp
= get_tracepoint (tdp
);
1969 tdp
= tp
->number_on_target
;
1971 tfind_1 (tfind_tp
, tdp
, 0, 0, from_tty
);
1974 /* TFIND LINE command:
1976 This command will take a sourceline for argument, just like BREAK
1977 or TRACE (ie. anything that "decode_line_1" can handle).
1979 With no argument, this command will find the next trace frame
1980 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1983 trace_find_line_command (char *args
, int from_tty
)
1985 static CORE_ADDR start_pc
, end_pc
;
1986 struct symtabs_and_lines sals
;
1987 struct symtab_and_line sal
;
1988 struct cleanup
*old_chain
;
1989 char startpc_str
[40], endpc_str
[40];
1991 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1992 error ("May not look at trace frames while trace is running.");
1994 if (args
== 0 || *args
== 0)
1996 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1998 sals
.sals
= (struct symtab_and_line
*)
1999 xmalloc (sizeof (struct symtab_and_line
));
2004 sals
= decode_line_spec (args
, 1);
2008 old_chain
= make_cleanup (xfree
, sals
.sals
);
2009 if (sal
.symtab
== 0)
2011 printf_filtered ("TFIND: No line number information available");
2014 /* This is useful for "info line *0x7f34". If we can't
2015 tell the user about a source line, at least let them
2016 have the symbolic address. */
2017 printf_filtered (" for address ");
2019 print_address (get_current_arch (), sal
.pc
, gdb_stdout
);
2020 printf_filtered (";\n -- will attempt to find by PC. \n");
2024 printf_filtered (".\n");
2025 return; /* No line, no PC; what can we do? */
2028 else if (sal
.line
> 0
2029 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2031 if (start_pc
== end_pc
)
2033 printf_filtered ("Line %d of \"%s\"",
2034 sal
.line
, sal
.symtab
->filename
);
2036 printf_filtered (" is at address ");
2037 print_address (get_current_arch (), start_pc
, gdb_stdout
);
2039 printf_filtered (" but contains no code.\n");
2040 sal
= find_pc_line (start_pc
, 0);
2042 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
2043 && start_pc
!= end_pc
)
2044 printf_filtered ("Attempting to find line %d instead.\n",
2047 error (_("Cannot find a good line."));
2051 /* Is there any case in which we get here, and have an address
2052 which the user would want to see? If we have debugging
2053 symbols and no line numbers? */
2054 error (_("Line number %d is out of range for \"%s\"."),
2055 sal
.line
, sal
.symtab
->filename
);
2057 /* Find within range of stated line. */
2059 tfind_1 (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2061 tfind_1 (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2062 do_cleanups (old_chain
);
2065 /* tfind range command */
2067 trace_find_range_command (char *args
, int from_tty
)
2069 static CORE_ADDR start
, stop
;
2070 char start_str
[40], stop_str
[40];
2073 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2074 error ("May not look at trace frames while trace is running.");
2076 if (args
== 0 || *args
== 0)
2077 { /* XXX FIXME: what should default behavior be? */
2078 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2082 if (0 != (tmp
= strchr (args
, ',')))
2084 *tmp
++ = '\0'; /* terminate start address */
2085 while (isspace ((int) *tmp
))
2087 start
= parse_and_eval_address (args
);
2088 stop
= parse_and_eval_address (tmp
);
2091 { /* no explicit end address? */
2092 start
= parse_and_eval_address (args
);
2093 stop
= start
+ 1; /* ??? */
2096 tfind_1 (tfind_range
, 0, start
, stop
, from_tty
);
2099 /* tfind outside command */
2101 trace_find_outside_command (char *args
, int from_tty
)
2103 CORE_ADDR start
, stop
;
2104 char start_str
[40], stop_str
[40];
2107 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2108 error ("May not look at trace frames while trace is running.");
2110 if (args
== 0 || *args
== 0)
2111 { /* XXX FIXME: what should default behavior be? */
2112 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2116 if (0 != (tmp
= strchr (args
, ',')))
2118 *tmp
++ = '\0'; /* terminate start address */
2119 while (isspace ((int) *tmp
))
2121 start
= parse_and_eval_address (args
);
2122 stop
= parse_and_eval_address (tmp
);
2125 { /* no explicit end address? */
2126 start
= parse_and_eval_address (args
);
2127 stop
= start
+ 1; /* ??? */
2130 tfind_1 (tfind_outside
, 0, start
, stop
, from_tty
);
2133 /* info scope command: list the locals for a scope. */
2135 scope_info (char *args
, int from_tty
)
2137 struct symtabs_and_lines sals
;
2139 struct minimal_symbol
*msym
;
2140 struct block
*block
;
2141 char **canonical
, *symname
, *save_args
= args
;
2142 struct dict_iterator iter
;
2144 struct gdbarch
*gdbarch
;
2147 if (args
== 0 || *args
== 0)
2148 error (_("requires an argument (function, line or *addr) to define a scope"));
2150 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
2151 if (sals
.nelts
== 0)
2152 return; /* presumably decode_line_1 has already warned */
2154 /* Resolve line numbers to PC */
2155 resolve_sal_pc (&sals
.sals
[0]);
2156 block
= block_for_pc (sals
.sals
[0].pc
);
2160 QUIT
; /* allow user to bail out with ^C */
2161 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2163 QUIT
; /* allow user to bail out with ^C */
2165 printf_filtered ("Scope for %s:\n", save_args
);
2168 symname
= SYMBOL_PRINT_NAME (sym
);
2169 if (symname
== NULL
|| *symname
== '\0')
2170 continue; /* probably botched, certainly useless */
2172 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
2174 printf_filtered ("Symbol %s is ", symname
);
2175 switch (SYMBOL_CLASS (sym
))
2178 case LOC_UNDEF
: /* messed up symbol? */
2179 printf_filtered ("a bogus symbol, class %d.\n",
2180 SYMBOL_CLASS (sym
));
2181 count
--; /* don't count this one */
2184 printf_filtered ("a constant with value %ld (0x%lx)",
2185 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2187 case LOC_CONST_BYTES
:
2188 printf_filtered ("constant bytes: ");
2189 if (SYMBOL_TYPE (sym
))
2190 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2191 fprintf_filtered (gdb_stdout
, " %02x",
2192 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2195 printf_filtered ("in static storage at address ");
2196 printf_filtered ("%s", paddress (gdbarch
,
2197 SYMBOL_VALUE_ADDRESS (sym
)));
2200 /* GDBARCH is the architecture associated with the objfile
2201 the symbol is defined in; the target architecture may be
2202 different, and may provide additional registers. However,
2203 we do not know the target architecture at this point.
2204 We assume the objfile architecture will contain all the
2205 standard registers that occur in debug info in that
2207 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2209 if (SYMBOL_IS_ARGUMENT (sym
))
2210 printf_filtered ("an argument in register $%s",
2211 gdbarch_register_name (gdbarch
, regno
));
2213 printf_filtered ("a local variable in register $%s",
2214 gdbarch_register_name (gdbarch
, regno
));
2217 printf_filtered ("an argument at stack/frame offset %ld",
2218 SYMBOL_VALUE (sym
));
2221 printf_filtered ("a local variable at frame offset %ld",
2222 SYMBOL_VALUE (sym
));
2225 printf_filtered ("a reference argument at offset %ld",
2226 SYMBOL_VALUE (sym
));
2228 case LOC_REGPARM_ADDR
:
2229 /* Note comment at LOC_REGISTER. */
2230 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2231 printf_filtered ("the address of an argument, in register $%s",
2232 gdbarch_register_name (gdbarch
, regno
));
2235 printf_filtered ("a typedef.\n");
2238 printf_filtered ("a label at address ");
2239 printf_filtered ("%s", paddress (gdbarch
,
2240 SYMBOL_VALUE_ADDRESS (sym
)));
2243 printf_filtered ("a function at address ");
2244 printf_filtered ("%s",
2245 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2247 case LOC_UNRESOLVED
:
2248 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2251 printf_filtered ("Unresolved Static");
2254 printf_filtered ("static storage at address ");
2255 printf_filtered ("%s",
2256 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
2259 case LOC_OPTIMIZED_OUT
:
2260 printf_filtered ("optimized out.\n");
2263 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
2266 if (SYMBOL_TYPE (sym
))
2267 printf_filtered (", length %d.\n",
2268 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2270 if (BLOCK_FUNCTION (block
))
2273 block
= BLOCK_SUPERBLOCK (block
);
2276 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2280 /* worker function (cleanup) */
2282 replace_comma (void *data
)
2290 trace_dump_command (char *args
, int from_tty
)
2292 struct regcache
*regcache
;
2293 struct gdbarch
*gdbarch
;
2294 struct breakpoint
*t
;
2295 struct command_line
*action
;
2296 char *action_exp
, *next_comma
;
2297 struct cleanup
*old_cleanups
;
2298 int stepping_actions
= 0;
2299 int stepping_frame
= 0;
2300 struct bp_location
*loc
;
2302 if (tracepoint_number
== -1)
2304 warning (_("No current trace frame."));
2308 t
= get_tracepoint (tracepoint_number
);
2311 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2314 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2316 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2317 tracepoint_number
, traceframe_number
);
2319 /* The current frame is a trap frame if the frame PC is equal
2320 to the tracepoint PC. If not, then the current frame was
2321 collected during single-stepping. */
2323 regcache
= get_current_regcache ();
2324 gdbarch
= get_regcache_arch (regcache
);
2326 /* If the traceframe's address matches any of the tracepoint's
2327 locations, assume it is a direct hit rather than a while-stepping
2328 frame. (FIXME this is not reliable, should record each frame's
2331 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
2332 if (loc
->address
== regcache_read_pc (regcache
))
2335 for (action
= t
->commands
; action
; action
= action
->next
)
2337 struct cmd_list_element
*cmd
;
2339 QUIT
; /* allow user to bail out with ^C */
2340 action_exp
= action
->line
;
2341 while (isspace ((int) *action_exp
))
2344 /* The collection actions to be done while stepping are
2345 bracketed by the commands "while-stepping" and "end". */
2347 if (*action_exp
== '#') /* comment line */
2350 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2352 error (_("Bad action list item: %s"), action_exp
);
2354 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2355 stepping_actions
= 1;
2356 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2357 stepping_actions
= 0;
2358 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2360 /* Display the collected data.
2361 For the trap frame, display only what was collected at
2362 the trap. Likewise for stepping frames, display only
2363 what was collected while stepping. This means that the
2364 two boolean variables, STEPPING_FRAME and
2365 STEPPING_ACTIONS should be equal. */
2366 if (stepping_frame
== stepping_actions
)
2369 { /* repeat over a comma-separated list */
2370 QUIT
; /* allow user to bail out with ^C */
2371 if (*action_exp
== ',')
2373 while (isspace ((int) *action_exp
))
2376 next_comma
= strchr (action_exp
, ',');
2378 if (0 == strncasecmp (action_exp
, "$reg", 4))
2379 registers_info (NULL
, from_tty
);
2380 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2381 locals_info (NULL
, from_tty
);
2382 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2383 args_info (NULL
, from_tty
);
2388 make_cleanup (replace_comma
, next_comma
);
2391 printf_filtered ("%s = ", action_exp
);
2392 output_command (action_exp
, from_tty
);
2393 printf_filtered ("\n");
2397 action_exp
= next_comma
;
2399 while (action_exp
&& *action_exp
== ',');
2403 discard_cleanups (old_cleanups
);
2406 extern int trace_regblock_size
;
2409 trace_save_command (char *args
, int from_tty
)
2412 char *filename
= NULL
, *pathname
;
2413 int target_does_save
= 0;
2414 struct cleanup
*cleanup
;
2415 struct trace_status
*ts
= current_trace_status ();
2418 struct uploaded_tp
*uploaded_tps
= NULL
, *utp
;
2419 struct uploaded_tsv
*uploaded_tsvs
= NULL
, *utsv
;
2422 ULONGEST offset
= 0;
2423 #define MAX_TRACE_UPLOAD 2000
2424 gdb_byte buf
[MAX_TRACE_UPLOAD
];
2428 error_no_arg (_("file in which to save trace data"));
2430 argv
= gdb_buildargv (args
);
2431 make_cleanup_freeargv (argv
);
2433 for (; *argv
; ++argv
)
2435 if (strcmp (*argv
, "-r") == 0)
2436 target_does_save
= 1;
2437 else if (**argv
== '-')
2438 error (_("unknown option `%s'"), *argv
);
2444 error_no_arg (_("file in which to save trace data"));
2446 /* If the target is to save the data to a file on its own, then just
2447 send the command and be done with it. */
2448 if (target_does_save
)
2450 err
= target_save_trace_data (filename
);
2452 error (_("Target failed to save trace data to '%s'."),
2457 /* Get the trace status first before opening the file, so if the
2458 target is losing, we can get out without touching files. */
2459 status
= target_get_trace_status (ts
);
2461 pathname
= tilde_expand (args
);
2462 cleanup
= make_cleanup (xfree
, pathname
);
2464 fp
= fopen (pathname
, "w");
2466 error (_("Unable to open file '%s' for saving trace data (%s)"),
2467 args
, safe_strerror (errno
));
2468 make_cleanup_fclose (fp
);
2470 /* Write a file header, with a high-bit-set char to indicate a
2471 binary file, plus a hint as what this file is, and a version
2472 number in case of future needs. */
2473 written
= fwrite ("\x7fTRACE0\n", 8, 1, fp
);
2475 perror_with_name (pathname
);
2477 /* Write descriptive info. */
2479 /* Write out the size of a register block. */
2480 fprintf (fp
, "R %x\n", trace_regblock_size
);
2482 /* Write out status of the tracing run (aka "tstatus" info). */
2483 fprintf (fp
, "status %c;%s:%x",
2484 (ts
->running
? '1' : '0'),
2485 stop_reason_names
[ts
->stop_reason
], ts
->stopping_tracepoint
);
2486 if (ts
->traceframe_count
>= 0)
2487 fprintf (fp
, ";tframes:%x", ts
->traceframe_count
);
2488 if (ts
->traceframes_created
>= 0)
2489 fprintf (fp
, ";tcreated:%x", ts
->traceframes_created
);
2490 if (ts
->buffer_free
>= 0)
2491 fprintf (fp
, ";tfree:%x", ts
->buffer_free
);
2492 if (ts
->buffer_size
>= 0)
2493 fprintf (fp
, ";tsize:%x", ts
->buffer_size
);
2496 /* Note that we want to upload tracepoints and save those, rather
2497 than simply writing out the local ones, because the user may have
2498 changed tracepoints in GDB in preparation for a future tracing
2499 run, or maybe just mass-deleted all types of breakpoints as part
2500 of cleaning up. So as not to contaminate the session, leave the
2501 data in its uploaded form, don't make into real tracepoints. */
2503 /* Get trace state variables first, they may be checked when parsing
2504 uploaded commands. */
2506 target_upload_trace_state_variables (&uploaded_tsvs
);
2508 for (utsv
= uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
2514 buf
= (char *) xmalloc (strlen (utsv
->name
) * 2 + 1);
2515 bin2hex ((gdb_byte
*) (utsv
->name
), buf
, 0);
2518 fprintf (fp
, "tsv %x:%s:%x:%s\n",
2519 utsv
->number
, phex_nz (utsv
->initial_value
, 8),
2520 utsv
->builtin
, buf
);
2526 free_uploaded_tsvs (&uploaded_tsvs
);
2528 target_upload_tracepoints (&uploaded_tps
);
2530 for (utp
= uploaded_tps
; utp
; utp
= utp
->next
)
2532 fprintf (fp
, "tp T%x:%s:%c:%x:%x",
2533 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2534 (utp
->enabled
? 'E' : 'D'), utp
->step
, utp
->pass
);
2535 if (utp
->type
== bp_fast_tracepoint
)
2536 fprintf (fp
, ":F%x", utp
->orig_size
);
2538 fprintf (fp
, ":X%x,%s", (unsigned int) strlen (utp
->cond
) / 2,
2541 for (a
= 0; a
< utp
->numactions
; ++a
)
2542 fprintf (fp
, "tp A%x:%s:%s\n",
2543 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2545 for (a
= 0; a
< utp
->num_step_actions
; ++a
)
2546 fprintf (fp
, "tp S%x:%s:%s\n",
2547 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2548 utp
->step_actions
[a
]);
2551 free_uploaded_tps (&uploaded_tps
);
2553 /* Mark the end of the definition section. */
2556 /* Get and write the trace data proper. We ask for big blocks, in
2557 the hopes of efficiency, but will take less if the target has
2558 packet size limitations or some such. */
2561 gotten
= target_get_raw_trace_data (buf
, offset
, MAX_TRACE_UPLOAD
);
2563 error (_("Failure to get requested trace buffer data"));
2564 /* No more data is forthcoming, we're done. */
2567 written
= fwrite (buf
, gotten
, 1, fp
);
2568 if (written
< gotten
)
2569 perror_with_name (pathname
);
2573 /* Mark the end of trace data. */
2574 written
= fwrite (&gotten
, 4, 1, fp
);
2576 perror_with_name (pathname
);
2578 do_cleanups (cleanup
);
2580 printf_filtered (_("Trace data saved to file '%s'.\n"), args
);
2583 /* Tell the target what to do with an ongoing tracing run if GDB
2584 disconnects for some reason. */
2587 send_disconnected_tracing_value (int value
)
2589 target_set_disconnected_tracing (value
);
2593 set_disconnected_tracing (char *args
, int from_tty
,
2594 struct cmd_list_element
*c
)
2596 send_disconnected_tracing_value (disconnected_tracing
);
2600 set_circular_trace_buffer (char *args
, int from_tty
,
2601 struct cmd_list_element
*c
)
2603 target_set_circular_trace_buffer (circular_trace_buffer
);
2606 /* Convert the memory pointed to by mem into hex, placing result in buf.
2607 * Return a pointer to the last char put in buf (null)
2608 * "stolen" from sparc-stub.c
2611 static const char hexchars
[] = "0123456789abcdef";
2614 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2622 *buf
++ = hexchars
[ch
>> 4];
2623 *buf
++ = hexchars
[ch
& 0xf];
2632 get_traceframe_number (void)
2634 return traceframe_number
;
2637 /* Make the traceframe NUM be the current trace frame. Does nothing
2638 if NUM is already current. */
2641 set_traceframe_number (int num
)
2645 if (traceframe_number
== num
)
2647 /* Nothing to do. */
2651 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
2654 warning (_("could not change traceframe"));
2656 traceframe_number
= newnum
;
2658 /* Changing the traceframe changes our view of registers and of the
2660 registers_changed ();
2663 /* A cleanup used when switching away and back from tfind mode. */
2665 struct current_traceframe_cleanup
2667 /* The traceframe we were inspecting. */
2668 int traceframe_number
;
2672 do_restore_current_traceframe_cleanup (void *arg
)
2674 struct current_traceframe_cleanup
*old
= arg
;
2676 set_traceframe_number (old
->traceframe_number
);
2680 restore_current_traceframe_cleanup_dtor (void *arg
)
2682 struct current_traceframe_cleanup
*old
= arg
;
2688 make_cleanup_restore_current_traceframe (void)
2690 struct current_traceframe_cleanup
*old
;
2692 old
= xmalloc (sizeof (struct current_traceframe_cleanup
));
2693 old
->traceframe_number
= traceframe_number
;
2695 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
2696 restore_current_traceframe_cleanup_dtor
);
2699 /* Given a number and address, return an uploaded tracepoint with that
2700 number, creating if necessary. */
2702 struct uploaded_tp
*
2703 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
2705 struct uploaded_tp
*utp
;
2707 for (utp
= *utpp
; utp
; utp
= utp
->next
)
2708 if (utp
->number
== num
&& utp
->addr
== addr
)
2710 utp
= (struct uploaded_tp
*) xmalloc (sizeof (struct uploaded_tp
));
2711 memset (utp
, 0, sizeof (struct uploaded_tp
));
2720 free_uploaded_tps (struct uploaded_tp
**utpp
)
2722 struct uploaded_tp
*next_one
;
2726 next_one
= (*utpp
)->next
;
2732 /* Given a number and address, return an uploaded tracepoint with that
2733 number, creating if necessary. */
2735 struct uploaded_tsv
*
2736 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
2738 struct uploaded_tsv
*utsv
;
2740 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
2741 if (utsv
->number
== num
)
2743 utsv
= (struct uploaded_tsv
*) xmalloc (sizeof (struct uploaded_tsv
));
2744 memset (utsv
, 0, sizeof (struct uploaded_tsv
));
2746 utsv
->next
= *utsvp
;
2752 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
2754 struct uploaded_tsv
*next_one
;
2758 next_one
= (*utsvp
)->next
;
2764 /* Look for an existing tracepoint that seems similar enough to the
2765 uploaded one. Enablement isn't compared, because the user can
2766 toggle that freely, and may have done so in anticipation of the
2770 find_matching_tracepoint (struct uploaded_tp
*utp
)
2772 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
2774 struct breakpoint
*t
;
2775 struct bp_location
*loc
;
2777 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
2779 if (t
->type
== utp
->type
2780 && t
->step_count
== utp
->step
2781 && t
->pass_count
== utp
->pass
2782 /* FIXME also test conditionals and actions */
2785 /* Scan the locations for an address match. */
2786 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
2788 if (loc
->address
== utp
->addr
)
2796 /* Given a list of tracepoints uploaded from a target, attempt to
2797 match them up with existing tracepoints, and create new ones if not
2801 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
2803 struct uploaded_tp
*utp
;
2804 struct breakpoint
*t
;
2806 /* Look for GDB tracepoints that match up with our uploaded versions. */
2807 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
2809 t
= find_matching_tracepoint (utp
);
2811 printf_filtered (_("Assuming tracepoint %d is same as target's tracepoint %d at %s.\n"),
2812 t
->number
, utp
->number
, paddress (get_current_arch (), utp
->addr
));
2815 t
= create_tracepoint_from_upload (utp
);
2817 printf_filtered (_("Created tracepoint %d for target's tracepoint %d at %s.\n"),
2818 t
->number
, utp
->number
, paddress (get_current_arch (), utp
->addr
));
2820 printf_filtered (_("Failed to create tracepoint for target's tracepoint %d at %s, skipping it.\n"),
2821 utp
->number
, paddress (get_current_arch (), utp
->addr
));
2823 /* Whether found or created, record the number used by the
2824 target, to help with mapping target tracepoints back to their
2825 counterparts here. */
2827 t
->number_on_target
= utp
->number
;
2830 free_uploaded_tps (uploaded_tps
);
2833 /* Trace state variables don't have much to identify them beyond their
2834 name, so just use that to detect matches. */
2836 struct trace_state_variable
*
2837 find_matching_tsv (struct uploaded_tsv
*utsv
)
2842 return find_trace_state_variable (utsv
->name
);
2845 struct trace_state_variable
*
2846 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
2848 const char *namebase
;
2851 struct trace_state_variable
*tsv
;
2855 namebase
= utsv
->name
;
2856 sprintf (buf
, "%s", namebase
);
2861 sprintf (buf
, "%s_%d", namebase
, try_num
++);
2864 /* Fish for a name that is not in use. */
2865 /* (should check against all internal vars?) */
2866 while (find_trace_state_variable (buf
))
2867 sprintf (buf
, "%s_%d", namebase
, try_num
++);
2869 /* We have an available name, create the variable. */
2870 tsv
= create_trace_state_variable (xstrdup (buf
));
2871 tsv
->initial_value
= utsv
->initial_value
;
2872 tsv
->builtin
= utsv
->builtin
;
2877 /* Given a list of uploaded trace state variables, try to match them
2878 up with existing variables, or create additional ones. */
2881 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
2884 struct uploaded_tsv
*utsv
;
2885 struct trace_state_variable
*tsv
;
2888 /* Most likely some numbers will have to be reassigned as part of
2889 the merge, so clear them all in anticipation. */
2890 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2893 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
2895 tsv
= find_matching_tsv (utsv
);
2897 printf_filtered (_("Assuming trace state variable $%s is same as target's variable %d.\n"),
2898 tsv
->name
, utsv
->number
);
2901 tsv
= create_tsv_from_upload (utsv
);
2902 printf_filtered (_("Created trace state variable $%s for target's variable %d.\n"),
2903 tsv
->name
, utsv
->number
);
2905 /* Give precedence to numberings that come from the target. */
2907 tsv
->number
= utsv
->number
;
2910 /* Renumber everything that didn't get a target-assigned number. */
2912 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2913 if (tsv
->number
> highest
)
2914 highest
= tsv
->number
;
2917 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2918 if (tsv
->number
== 0)
2919 tsv
->number
= highest
++;
2921 free_uploaded_tsvs (uploaded_tsvs
);
2924 /* target tfile command */
2926 struct target_ops tfile_ops
;
2928 /* Fill in tfile_ops with its defined operations and properties. */
2930 #define TRACE_HEADER_SIZE 8
2932 char *trace_filename
;
2934 off_t trace_frames_offset
;
2937 int trace_regblock_size
;
2939 static void tfile_interp_line (char *line
,
2940 struct uploaded_tp
**utpp
,
2941 struct uploaded_tsv
**utsvp
);
2944 tfile_open (char *filename
, int from_tty
)
2947 struct cleanup
*old_chain
;
2950 char header
[TRACE_HEADER_SIZE
];
2951 char linebuf
[1000]; /* should be max remote packet size or so */
2953 int bytes
, i
, gotten
;
2954 struct trace_status
*ts
;
2955 struct uploaded_tp
*uploaded_tps
= NULL
;
2956 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
2958 target_preopen (from_tty
);
2960 error (_("No trace file specified."));
2962 filename
= tilde_expand (filename
);
2963 if (!IS_ABSOLUTE_PATH(filename
))
2965 temp
= concat (current_directory
, "/", filename
, (char *)NULL
);
2970 old_chain
= make_cleanup (xfree
, filename
);
2972 flags
= O_BINARY
| O_LARGEFILE
;
2974 scratch_chan
= open (filename
, flags
, 0);
2975 if (scratch_chan
< 0)
2976 perror_with_name (filename
);
2978 /* Looks semi-reasonable. Toss the old trace file and work on the new. */
2980 discard_cleanups (old_chain
); /* Don't free filename any more */
2981 unpush_target (&tfile_ops
);
2983 push_target (&tfile_ops
);
2985 trace_filename
= xstrdup (filename
);
2986 trace_fd
= scratch_chan
;
2989 /* Read the file header and test for validity. */
2990 gotten
= read (trace_fd
, &header
, TRACE_HEADER_SIZE
);
2992 perror_with_name (trace_filename
);
2993 else if (gotten
< TRACE_HEADER_SIZE
)
2994 error (_("Premature end of file while reading trace file"));
2996 bytes
+= TRACE_HEADER_SIZE
;
2997 if (!(header
[0] == 0x7f
2998 && (strncmp (header
+ 1, "TRACE0\n", 7) == 0)))
2999 error (_("File is not a valid trace file."));
3001 trace_regblock_size
= 0;
3002 ts
= current_trace_status ();
3003 /* We know we're working with a file. */
3005 /* Set defaults in case there is no status line. */
3006 ts
->running_known
= 0;
3007 ts
->stop_reason
= trace_stop_reason_unknown
;
3008 ts
->traceframe_count
= -1;
3009 ts
->buffer_free
= 0;
3011 /* Read through a section of newline-terminated lines that
3012 define things like tracepoints. */
3016 gotten
= read (trace_fd
, &byte
, 1);
3018 perror_with_name (trace_filename
);
3019 else if (gotten
< 1)
3020 error (_("Premature end of file while reading trace file"));
3025 /* Empty line marks end of the definition section. */
3030 tfile_interp_line (linebuf
, &uploaded_tps
, &uploaded_tsvs
);
3033 linebuf
[i
++] = byte
;
3035 error (_("Excessively long lines in trace file"));
3038 /* Add the file's tracepoints and variables into the current mix. */
3040 /* Get trace state variables first, they may be checked when parsing
3041 uploaded commands. */
3042 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
3044 merge_uploaded_tracepoints (&uploaded_tps
);
3046 /* Record the starting offset of the binary trace data. */
3047 trace_frames_offset
= bytes
;
3049 /* If we don't have a blocksize, we can't interpret the
3051 if (trace_regblock_size
== 0)
3052 error (_("No register block size recorded in trace file"));
3053 if (ts
->traceframe_count
<= 0)
3055 warning ("No traceframes present in this file.");
3059 #define TFILE_PID (1)
3060 inferior_appeared (current_inferior (), TFILE_PID
);
3061 inferior_ptid
= pid_to_ptid (TFILE_PID
);
3062 add_thread_silent (inferior_ptid
);
3064 post_create_inferior (&tfile_ops
, from_tty
);
3067 /* FIXME this will get defined in MI patch submission */
3068 tfind_1 (tfind_number
, 0, 0, 0, 0);
3072 /* Interpret the given line from the definitions part of the trace
3076 tfile_interp_line (char *line
,
3077 struct uploaded_tp
**utpp
, struct uploaded_tsv
**utsvp
)
3081 if (strncmp (p
, "R ", strlen ("R ")) == 0)
3084 trace_regblock_size
= strtol (p
, &p
, 16);
3086 else if (strncmp (p
, "status ", strlen ("status ")) == 0)
3088 p
+= strlen ("status ");
3089 parse_trace_status (p
, current_trace_status ());
3091 else if (strncmp (p
, "tp ", strlen ("tp ")) == 0)
3093 p
+= strlen ("tp ");
3094 parse_tracepoint_definition (p
, utpp
);
3096 else if (strncmp (p
, "tsv ", strlen ("tsv ")) == 0)
3098 p
+= strlen ("tsv ");
3099 parse_tsv_definition (p
, utsvp
);
3102 warning ("Ignoring trace file definition \"%s\"", line
);
3105 /* Parse the part of trace status syntax that is shared between
3106 the remote protocol and the trace file reader. */
3108 extern char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
3111 parse_trace_status (char *line
, struct trace_status
*ts
)
3113 char *p
= line
, *p1
, *p_temp
;
3116 ts
->running_known
= 1;
3117 ts
->running
= (*p
++ == '1');
3118 ts
->stop_reason
= trace_stop_reason_unknown
;
3119 ts
->traceframe_count
= -1;
3120 ts
->traceframes_created
= -1;
3121 ts
->buffer_free
= -1;
3122 ts
->buffer_size
= -1;
3126 p1
= strchr (p
, ':');
3128 error (_("Malformed trace status, at %s\n\
3129 Status line: '%s'\n"), p
, line
);
3130 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
3132 p
= unpack_varlen_hex (++p1
, &val
);
3133 ts
->stop_reason
= trace_buffer_full
;
3135 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
3137 p
= unpack_varlen_hex (++p1
, &val
);
3138 ts
->stop_reason
= trace_never_run
;
3140 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
], p1
- p
) == 0)
3142 p
= unpack_varlen_hex (++p1
, &val
);
3143 ts
->stop_reason
= tracepoint_passcount
;
3144 ts
->stopping_tracepoint
= val
;
3146 else if (strncmp (p
, stop_reason_names
[tstop_command
], p1
- p
) == 0)
3148 p
= unpack_varlen_hex (++p1
, &val
);
3149 ts
->stop_reason
= tstop_command
;
3151 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3153 p
= unpack_varlen_hex (++p1
, &val
);
3154 ts
->traceframe_count
= val
;
3156 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3158 p
= unpack_varlen_hex (++p1
, &val
);
3159 ts
->traceframes_created
= val
;
3161 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3163 p
= unpack_varlen_hex (++p1
, &val
);
3164 ts
->buffer_free
= val
;
3166 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3168 p
= unpack_varlen_hex (++p1
, &val
);
3169 ts
->buffer_size
= val
;
3173 /* Silently skip unknown optional info. */
3174 p_temp
= strchr (p1
+ 1, ';');
3178 /* Must be at the end. */
3184 /* Given a line of text defining a tracepoint or tracepoint action, parse
3185 it into an "uploaded tracepoint". */
3188 parse_tracepoint_definition (char *line
, struct uploaded_tp
**utpp
)
3192 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
;
3196 struct uploaded_tp
*utp
= NULL
;
3199 /* Both tracepoint and action definitions start with the same number
3200 and address sequence. */
3202 p
= unpack_varlen_hex (p
, &num
);
3203 p
++; /* skip a colon */
3204 p
= unpack_varlen_hex (p
, &addr
);
3205 p
++; /* skip a colon */
3208 enabled
= (*p
++ == 'E');
3209 p
++; /* skip a colon */
3210 p
= unpack_varlen_hex (p
, &step
);
3211 p
++; /* skip a colon */
3212 p
= unpack_varlen_hex (p
, &pass
);
3213 type
= bp_tracepoint
;
3215 /* Thumb through optional fields. */
3218 p
++; /* skip a colon */
3221 type
= bp_fast_tracepoint
;
3223 p
= unpack_varlen_hex (p
, &orig_size
);
3228 p
= unpack_varlen_hex (p
, &xlen
);
3229 p
++; /* skip a comma */
3230 cond
= (char *) xmalloc (2 * xlen
+ 1);
3231 strncpy (cond
, p
, 2 * xlen
);
3232 cond
[2 * xlen
] = '\0';
3236 warning ("Unrecognized char '%c' in tracepoint definition, skipping rest", *p
);
3238 utp
= get_uploaded_tp (num
, addr
, utpp
);
3240 utp
->enabled
= enabled
;
3245 else if (piece
== 'A')
3247 utp
= get_uploaded_tp (num
, addr
, utpp
);
3248 utp
->actions
[utp
->numactions
++] = xstrdup (p
);
3250 else if (piece
== 'S')
3252 utp
= get_uploaded_tp (num
, addr
, utpp
);
3253 utp
->step_actions
[utp
->num_step_actions
++] = xstrdup (p
);
3257 error ("Invalid tracepoint piece");
3261 /* Convert a textual description of a trace state variable into an
3265 parse_tsv_definition (char *line
, struct uploaded_tsv
**utsvp
)
3268 ULONGEST num
, initval
, builtin
;
3270 struct uploaded_tsv
*utsv
= NULL
;
3272 buf
= alloca (strlen (line
));
3275 p
= unpack_varlen_hex (p
, &num
);
3276 p
++; /* skip a colon */
3277 p
= unpack_varlen_hex (p
, &initval
);
3278 p
++; /* skip a colon */
3279 p
= unpack_varlen_hex (p
, &builtin
);
3280 p
++; /* skip a colon */
3281 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3284 utsv
= get_uploaded_tsv (num
, utsvp
);
3285 utsv
->initial_value
= initval
;
3286 utsv
->builtin
= builtin
;
3287 utsv
->name
= xstrdup (buf
);
3290 /* Close the trace file and generally clean up. */
3293 tfile_close (int quitting
)
3300 pid
= ptid_get_pid (inferior_ptid
);
3301 inferior_ptid
= null_ptid
; /* Avoid confusion from thread stuff */
3302 exit_inferior_silent (pid
);
3307 xfree (trace_filename
);
3311 tfile_files_info (struct target_ops
*t
)
3313 /* (it would be useful to mention the name of the file) */
3314 printf_filtered ("Looking at a trace file.\n");
3317 /* The trace status for a file is that tracing can never be run. */
3320 tfile_get_trace_status (struct trace_status
*ts
)
3322 /* Other bits of trace status were collected as part of opening the
3323 trace files, so nothing to do here. */
3328 /* Given the position of a traceframe in the file, figure out what
3329 address the frame was collected at. This would normally be the
3330 value of a collected PC register, but if not available, we
3334 tfile_get_traceframe_address (off_t tframe_offset
)
3338 struct breakpoint
*tp
;
3339 off_t saved_offset
= cur_offset
;
3342 /* FIXME dig pc out of collected registers */
3344 /* Fall back to using tracepoint address. */
3345 lseek (trace_fd
, tframe_offset
, SEEK_SET
);
3346 gotten
= read (trace_fd
, &tpnum
, 2);
3348 perror_with_name (trace_filename
);
3349 else if (gotten
< 2)
3350 error (_("Premature end of file while reading trace file"));
3352 tp
= get_tracepoint_by_number_on_target (tpnum
);
3353 /* FIXME this is a poor heuristic if multiple locations */
3355 addr
= tp
->loc
->address
;
3357 /* Restore our seek position. */
3358 cur_offset
= saved_offset
;
3359 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3363 /* Given a type of search and some parameters, scan the collection of
3364 traceframes in the file looking for a match. When found, return
3365 both the traceframe and tracepoint number, otherwise -1 for
3369 tfile_trace_find (enum trace_find_type type
, int num
,
3370 ULONGEST addr1
, ULONGEST addr2
, int *tpp
)
3373 int tfnum
= 0, found
= 0, gotten
;
3375 struct breakpoint
*tp
;
3376 off_t offset
, tframe_offset
;
3379 lseek (trace_fd
, trace_frames_offset
, SEEK_SET
);
3380 offset
= trace_frames_offset
;
3383 tframe_offset
= offset
;
3384 gotten
= read (trace_fd
, &tpnum
, 2);
3386 perror_with_name (trace_filename
);
3387 else if (gotten
< 2)
3388 error (_("Premature end of file while reading trace file"));
3392 gotten
= read (trace_fd
, &data_size
, 4);
3394 perror_with_name (trace_filename
);
3395 else if (gotten
< 4)
3396 error (_("Premature end of file while reading trace file"));
3405 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3406 if (tfaddr
== addr1
)
3410 tp
= get_tracepoint (num
);
3411 if (tp
&& tpnum
== tp
->number_on_target
)
3415 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3416 if (addr1
<= tfaddr
&& tfaddr
<= addr2
)
3420 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3421 if (!(addr1
<= tfaddr
&& tfaddr
<= addr2
))
3425 internal_error (__FILE__
, __LINE__
, _("unknown tfind type"));
3429 printf_filtered ("Found traceframe %d.\n", tfnum
);
3432 cur_offset
= offset
;
3433 cur_data_size
= data_size
;
3436 /* Skip past the traceframe's data. */
3437 lseek (trace_fd
, data_size
, SEEK_CUR
);
3438 offset
+= data_size
;
3439 /* Update our own count of traceframes. */
3442 /* Did not find what we were looking for. */
3448 /* Look for a block of saved registers in the traceframe, and get the
3449 requested register from it. */
3452 tfile_fetch_registers (struct target_ops
*ops
,
3453 struct regcache
*regcache
, int regno
)
3455 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3457 int i
, pos
, offset
, regn
, regsize
, gotten
;
3458 unsigned short mlen
;
3461 /* An uninitialized reg size says we're not going to be
3462 successful at getting register blocks. */
3463 if (!trace_regblock_size
)
3466 regs
= alloca (trace_regblock_size
);
3468 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3470 while (pos
< cur_data_size
)
3472 gotten
= read (trace_fd
, &block_type
, 1);
3474 perror_with_name (trace_filename
);
3475 else if (gotten
< 1)
3476 error (_("Premature end of file while reading trace file"));
3482 gotten
= read (trace_fd
, regs
, trace_regblock_size
);
3484 perror_with_name (trace_filename
);
3485 else if (gotten
< trace_regblock_size
)
3486 error (_("Premature end of file while reading trace file"));
3488 /* Assume the block is laid out in GDB register number order,
3489 each register with the size that it has in GDB. */
3491 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
3493 regsize
= register_size (gdbarch
, regn
);
3494 /* Make sure we stay within block bounds. */
3495 if (offset
+ regsize
>= trace_regblock_size
)
3497 if (!regcache_valid_p (regcache
, regn
))
3501 regcache_raw_supply (regcache
, regno
, regs
+ offset
);
3504 else if (regno
== -1)
3506 regcache_raw_supply (regcache
, regn
, regs
+ offset
);
3513 lseek (trace_fd
, 8, SEEK_CUR
);
3514 gotten
= read (trace_fd
, &mlen
, 2);
3516 perror_with_name (trace_filename
);
3517 else if (gotten
< 2)
3518 error (_("Premature end of file while reading trace file"));
3519 lseek (trace_fd
, mlen
, SEEK_CUR
);
3520 pos
+= (8 + 2 + mlen
);
3523 lseek (trace_fd
, 4 + 8, SEEK_CUR
);
3527 error ("Unknown block type '%c' (0x%x) in trace frame",
3528 block_type
, block_type
);
3535 tfile_xfer_partial (struct target_ops
*ops
, enum target_object object
,
3536 const char *annex
, gdb_byte
*readbuf
,
3537 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
3542 unsigned short mlen
;
3544 /* We're only doing regular memory for now. */
3545 if (object
!= TARGET_OBJECT_MEMORY
)
3548 if (readbuf
== NULL
)
3549 error ("tfile_xfer_partial: trace file is read-only");
3551 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3553 while (pos
< cur_data_size
)
3555 gotten
= read (trace_fd
, &block_type
, 1);
3557 perror_with_name (trace_filename
);
3558 else if (gotten
< 1)
3559 error (_("Premature end of file while reading trace file"));
3564 lseek (trace_fd
, trace_regblock_size
, SEEK_CUR
);
3565 pos
+= trace_regblock_size
;
3568 gotten
= read (trace_fd
, &maddr
, 8);
3570 perror_with_name (trace_filename
);
3571 else if (gotten
< 8)
3572 error (_("Premature end of file while reading trace file"));
3574 gotten
= read (trace_fd
, &mlen
, 2);
3576 perror_with_name (trace_filename
);
3577 else if (gotten
< 2)
3578 error (_("Premature end of file while reading trace file"));
3579 if (maddr
<= offset
&& (offset
+ len
) <= (maddr
+ mlen
))
3581 gotten
= read (trace_fd
, readbuf
, mlen
);
3583 perror_with_name (trace_filename
);
3584 else if (gotten
< mlen
)
3585 error (_("Premature end of file qwhile reading trace file"));
3589 lseek (trace_fd
, mlen
, SEEK_CUR
);
3590 pos
+= (8 + 2 + mlen
);
3593 lseek (trace_fd
, 4 + 8, SEEK_CUR
);
3597 error ("Unknown block type '%c' (0x%x) in traceframe",
3598 block_type
, block_type
);
3602 /* Indicate failure to find the requested memory block. */
3606 /* Iterate through the blocks of a trace frame, looking for a 'V'
3607 block with a matching tsv number. */
3610 tfile_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
3613 int pos
, vnum
, gotten
;
3614 unsigned short mlen
;
3616 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3618 while (pos
< cur_data_size
)
3620 gotten
= read (trace_fd
, &block_type
, 1);
3622 perror_with_name (trace_filename
);
3623 else if (gotten
< 1)
3624 error (_("Premature end of file while reading trace file"));
3629 lseek (trace_fd
, trace_regblock_size
, SEEK_CUR
);
3630 pos
+= trace_regblock_size
;
3633 lseek (trace_fd
, 8, SEEK_CUR
);
3634 gotten
= read (trace_fd
, &mlen
, 2);
3636 perror_with_name (trace_filename
);
3637 else if (gotten
< 2)
3638 error (_("Premature end of file while reading trace file"));
3639 lseek (trace_fd
, mlen
, SEEK_CUR
);
3640 pos
+= (8 + 2 + mlen
);
3643 gotten
= read (trace_fd
, &vnum
, 4);
3645 perror_with_name (trace_filename
);
3646 else if (gotten
< 4)
3647 error (_("Premature end of file while reading trace file"));
3650 gotten
= read (trace_fd
, val
, 8);
3652 perror_with_name (trace_filename
);
3653 else if (gotten
< 8)
3654 error (_("Premature end of file while reading trace file"));
3657 lseek (trace_fd
, 8, SEEK_CUR
);
3661 error ("Unknown block type '%c' (0x%x) in traceframe",
3662 block_type
, block_type
);
3666 /* Didn't find anything. */
3671 tfile_has_memory (struct target_ops
*ops
)
3677 tfile_has_stack (struct target_ops
*ops
)
3683 tfile_has_registers (struct target_ops
*ops
)
3689 init_tfile_ops (void)
3691 tfile_ops
.to_shortname
= "tfile";
3692 tfile_ops
.to_longname
= "Local trace dump file";
3694 "Use a trace file as a target. Specify the filename of the trace file.";
3695 tfile_ops
.to_open
= tfile_open
;
3696 tfile_ops
.to_close
= tfile_close
;
3697 tfile_ops
.to_fetch_registers
= tfile_fetch_registers
;
3698 tfile_ops
.to_xfer_partial
= tfile_xfer_partial
;
3699 tfile_ops
.to_files_info
= tfile_files_info
;
3700 tfile_ops
.to_get_trace_status
= tfile_get_trace_status
;
3701 tfile_ops
.to_trace_find
= tfile_trace_find
;
3702 tfile_ops
.to_get_trace_state_variable_value
= tfile_get_trace_state_variable_value
;
3703 /* core_stratum might seem more logical, but GDB doesn't like having
3704 more than one core_stratum vector. */
3705 tfile_ops
.to_stratum
= process_stratum
;
3706 tfile_ops
.to_has_memory
= tfile_has_memory
;
3707 tfile_ops
.to_has_stack
= tfile_has_stack
;
3708 tfile_ops
.to_has_registers
= tfile_has_registers
;
3709 tfile_ops
.to_magic
= OPS_MAGIC
;
3712 /* module initialization */
3714 _initialize_tracepoint (void)
3716 struct cmd_list_element
*c
;
3718 traceframe_number
= -1;
3719 tracepoint_number
= -1;
3721 if (tracepoint_list
.list
== NULL
)
3723 tracepoint_list
.listsize
= 128;
3724 tracepoint_list
.list
= xmalloc
3725 (tracepoint_list
.listsize
* sizeof (struct memrange
));
3727 if (tracepoint_list
.aexpr_list
== NULL
)
3729 tracepoint_list
.aexpr_listsize
= 128;
3730 tracepoint_list
.aexpr_list
= xmalloc
3731 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
3734 if (stepping_list
.list
== NULL
)
3736 stepping_list
.listsize
= 128;
3737 stepping_list
.list
= xmalloc
3738 (stepping_list
.listsize
* sizeof (struct memrange
));
3741 if (stepping_list
.aexpr_list
== NULL
)
3743 stepping_list
.aexpr_listsize
= 128;
3744 stepping_list
.aexpr_list
= xmalloc
3745 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
3748 add_info ("scope", scope_info
,
3749 _("List the variables local to a scope"));
3751 add_cmd ("tracepoints", class_trace
, NULL
,
3752 _("Tracing of program execution without stopping the program."),
3755 add_com ("tdump", class_trace
, trace_dump_command
,
3756 _("Print everything collected at the current tracepoint."));
3758 add_com ("tsave", class_trace
, trace_save_command
, _("\
3759 Save the trace data to a file.\n\
3760 Use the '-r' option to direct the target to save directly to the file,\n\
3761 using its own filesystem."));
3763 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
3764 Define a trace state variable.\n\
3765 Argument is a $-prefixed name, optionally followed\n\
3766 by '=' and an expression that sets the initial value\n\
3767 at the start of tracing."));
3768 set_cmd_completer (c
, expression_completer
);
3770 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
3771 Delete one or more trace state variables.\n\
3772 Arguments are the names of the variables to delete.\n\
3773 If no arguments are supplied, delete all variables."), &deletelist
);
3774 /* FIXME add a trace variable completer */
3776 add_info ("tvariables", tvariables_info
, _("\
3777 Status of trace state variables and their values.\n\
3780 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
3781 Select a trace frame;\n\
3782 No argument means forward by one frame; '-' means backward by one frame."),
3783 &tfindlist
, "tfind ", 1, &cmdlist
);
3785 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
3786 Select a trace frame whose PC is outside the given range (exclusive).\n\
3787 Usage: tfind outside addr1, addr2"),
3790 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
3791 Select a trace frame whose PC is in the given range (inclusive).\n\
3792 Usage: tfind range addr1,addr2"),
3795 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
3796 Select a trace frame by source line.\n\
3797 Argument can be a line number (with optional source file), \n\
3798 a function name, or '*' followed by an address.\n\
3799 Default argument is 'the next source line that was traced'."),
3802 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
3803 Select a trace frame by tracepoint number.\n\
3804 Default is the tracepoint for the current trace frame."),
3807 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
3808 Select a trace frame by PC.\n\
3809 Default is the current PC, or the PC of the current trace frame."),
3812 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
3813 Synonym for 'none'.\n\
3814 De-select any trace frame and resume 'live' debugging."),
3817 add_cmd ("none", class_trace
, trace_find_none_command
,
3818 _("De-select any trace frame and resume 'live' debugging."),
3821 add_cmd ("start", class_trace
, trace_find_start_command
,
3822 _("Select the first trace frame in the trace buffer."),
3825 add_com ("tstatus", class_trace
, trace_status_command
,
3826 _("Display the status of the current trace data collection."));
3828 add_com ("tstop", class_trace
, trace_stop_command
,
3829 _("Stop trace data collection."));
3831 add_com ("tstart", class_trace
, trace_start_command
,
3832 _("Start trace data collection."));
3834 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
3835 Ends a list of commands or actions.\n\
3836 Several GDB commands allow you to enter a list of commands or actions.\n\
3837 Entering \"end\" on a line by itself is the normal way to terminate\n\
3839 Note: the \"end\" command cannot be used at the gdb prompt."));
3841 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
3842 Specify single-stepping behavior at a tracepoint.\n\
3843 Argument is number of instructions to trace in single-step mode\n\
3844 following the tracepoint. This command is normally followed by\n\
3845 one or more \"collect\" commands, to specify what to collect\n\
3846 while single-stepping.\n\n\
3847 Note: this command can only be used in a tracepoint \"actions\" list."));
3849 add_com_alias ("ws", "while-stepping", class_alias
, 0);
3850 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
3852 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
3853 Specify one or more data items to be collected at a tracepoint.\n\
3854 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
3855 collect all data (variables, registers) referenced by that expression.\n\
3856 Also accepts the following special arguments:\n\
3857 $regs -- all registers.\n\
3858 $args -- all function arguments.\n\
3859 $locals -- all variables local to the block/function scope.\n\
3860 Note: this command can only be used in a tracepoint \"actions\" list."));
3862 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
3863 Specify one or more expressions to be evaluated at a tracepoint.\n\
3864 Accepts a comma-separated list of (one or more) expressions.\n\
3865 The result of each evaluation will be discarded.\n\
3866 Note: this command can only be used in a tracepoint \"actions\" list."));
3868 add_com ("actions", class_trace
, trace_actions_command
, _("\
3869 Specify the actions to be taken at a tracepoint.\n\
3870 Tracepoint actions may include collecting of specified data, \n\
3871 single-stepping, or enabling/disabling other tracepoints, \n\
3872 depending on target's capabilities."));
3874 default_collect
= xstrdup ("");
3875 add_setshow_string_cmd ("default-collect", class_trace
,
3876 &default_collect
, _("\
3877 Set the list of expressions to collect by default"), _("\
3878 Show the list of expressions to collect by default"), NULL
,
3880 &setlist
, &showlist
);
3882 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
3883 &disconnected_tracing
, _("\
3884 Set whether tracing continues after GDB disconnects."), _("\
3885 Show whether tracing continues after GDB disconnects."), _("\
3886 Use this to continue a tracing run even if GDB disconnects\n\
3887 or detaches from the target. You can reconnect later and look at\n\
3888 trace data collected in the meantime."),
3889 set_disconnected_tracing
,
3894 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
3895 &circular_trace_buffer
, _("\
3896 Set target's use of circular trace buffer."), _("\
3897 Show target's use of circular trace buffer."), _("\
3898 Use this to make the trace buffer into a circular buffer,\n\
3899 which will discard traceframes (oldest first) instead of filling\n\
3900 up and stopping the trace run."),
3901 set_circular_trace_buffer
,
3908 add_target (&tfile_ops
);