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
));
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 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
312 warning (_("No trace variable named \"$%s\", not deleting"), name
);
315 /* The 'tvariable' command collects a name and optional expression to
316 evaluate into an initial value. */
319 trace_variable_command (char *args
, int from_tty
)
321 struct expression
*expr
;
322 struct cleanup
*old_chain
;
323 struct internalvar
*intvar
= NULL
;
325 struct trace_state_variable
*tsv
;
328 error_no_arg (_("trace state variable name"));
330 /* All the possible valid arguments are expressions. */
331 expr
= parse_expression (args
);
332 old_chain
= make_cleanup (free_current_contents
, &expr
);
334 if (expr
->nelts
== 0)
335 error (_("No expression?"));
337 /* Only allow two syntaxes; "$name" and "$name=value". */
338 if (expr
->elts
[0].opcode
== OP_INTERNALVAR
)
340 intvar
= expr
->elts
[1].internalvar
;
342 else if (expr
->elts
[0].opcode
== BINOP_ASSIGN
343 && expr
->elts
[1].opcode
== OP_INTERNALVAR
)
345 intvar
= expr
->elts
[2].internalvar
;
346 initval
= value_as_long (evaluate_subexpression_type (expr
, 4));
349 error (_("Syntax must be $NAME [ = EXPR ]"));
352 error (_("No name given"));
354 if (strlen (internalvar_name (intvar
)) <= 0)
355 error (_("Must supply a non-empty variable name"));
357 /* If the variable already exists, just change its initial value. */
358 tsv
= find_trace_state_variable (internalvar_name (intvar
));
361 tsv
->initial_value
= initval
;
362 printf_filtered (_("Trace state variable $%s now has initial value %s.\n"),
363 tsv
->name
, plongest (tsv
->initial_value
));
367 /* Create a new variable. */
368 tsv
= create_trace_state_variable (internalvar_name (intvar
));
369 tsv
->initial_value
= initval
;
371 printf_filtered (_("Trace state variable $%s created, with initial value %s.\n"),
372 tsv
->name
, plongest (tsv
->initial_value
));
374 do_cleanups (old_chain
);
378 delete_trace_variable_command (char *args
, int from_tty
)
382 struct cleanup
*back_to
;
383 struct trace_state_variable
*tsv
;
387 if (query (_("Delete all trace state variables? ")))
388 VEC_free (tsv_s
, tvariables
);
393 argv
= gdb_buildargv (args
);
394 back_to
= make_cleanup_freeargv (argv
);
396 for (i
= 0; argv
[i
] != NULL
; i
++)
399 delete_trace_state_variable (argv
[i
] + 1);
401 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv
[i
]);
404 do_cleanups (back_to
);
409 /* List all the trace state variables. */
412 tvariables_info (char *args
, int from_tty
)
414 struct trace_state_variable
*tsv
;
419 if (VEC_length (tsv_s
, tvariables
) == 0)
421 printf_filtered (_("No trace state variables.\n"));
425 /* Try to acquire values from the target. */
426 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
427 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
430 printf_filtered (_("Name\t\t Initial\tCurrent\n"));
432 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
434 printf_filtered ("$%s", tsv
->name
);
435 print_spaces_filtered (17 - strlen (tsv
->name
), gdb_stdout
);
436 printf_filtered ("%s ", plongest (tsv
->initial_value
));
437 print_spaces_filtered (11 - strlen (plongest (tsv
->initial_value
)), gdb_stdout
);
438 if (tsv
->value_known
)
439 printf_filtered (" %s", plongest (tsv
->value
));
440 else if (current_trace_status ()->running
|| traceframe_number
>= 0)
441 /* The value is/was defined, but we don't have it. */
442 printf_filtered (_(" <unknown>"));
444 /* It is not meaningful to ask about the value. */
445 printf_filtered (_(" <undefined>"));
446 printf_filtered ("\n");
450 /* ACTIONS functions: */
452 /* The three functions:
453 collect_pseudocommand,
454 while_stepping_pseudocommand, and
455 end_actions_pseudocommand
456 are placeholders for "commands" that are actually ONLY to be used
457 within a tracepoint action list. If the actual function is ever called,
458 it means that somebody issued the "command" at the top level,
459 which is always an error. */
462 end_actions_pseudocommand (char *args
, int from_tty
)
464 error (_("This command cannot be used at the top level."));
468 while_stepping_pseudocommand (char *args
, int from_tty
)
470 error (_("This command can only be used in a tracepoint actions list."));
474 collect_pseudocommand (char *args
, int from_tty
)
476 error (_("This command can only be used in a tracepoint actions list."));
480 teval_pseudocommand (char *args
, int from_tty
)
482 error (_("This command can only be used in a tracepoint actions list."));
485 /* Enter a list of actions for a tracepoint. */
487 trace_actions_command (char *args
, int from_tty
)
489 struct breakpoint
*t
;
490 struct command_line
*l
;
492 t
= get_tracepoint_by_number (&args
, 0, 1);
496 xstrprintf ("Enter actions for tracepoint %d, one per line.",
498 struct cleanup
*cleanups
= make_cleanup (xfree
, tmpbuf
);
500 l
= read_command_lines (tmpbuf
, from_tty
, 1, check_tracepoint_command
, t
);
501 do_cleanups (cleanups
);
502 breakpoint_set_commands (t
, l
);
504 /* else just return */
507 /* worker function */
509 validate_actionline (char **line
, struct breakpoint
*t
)
511 struct cmd_list_element
*c
;
512 struct expression
*exp
= NULL
;
513 struct cleanup
*old_chain
= NULL
;
515 struct bp_location
*loc
;
517 /* if EOF is typed, *line is NULL */
521 for (p
= *line
; isspace ((int) *p
);)
524 /* Symbol lookup etc. */
525 if (*p
== '\0') /* empty line: just prompt for another line. */
528 if (*p
== '#') /* comment line */
531 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
534 warning (_("'%s' is not an action that I know, or is ambiguous."),
539 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
541 struct agent_expr
*aexpr
;
542 struct agent_reqs areqs
;
545 { /* repeat over a comma-separated list */
546 QUIT
; /* allow user to bail out with ^C */
547 while (isspace ((int) *p
))
550 if (*p
== '$') /* look for special pseudo-symbols */
552 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
553 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
554 (0 == strncasecmp ("loc", p
+ 1, 3)))
559 /* else fall thru, treat p as an expression and parse it! */
562 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
565 exp
= parse_exp_1 (&p
, block_for_pc (loc
->address
), 1);
566 old_chain
= make_cleanup (free_current_contents
, &exp
);
568 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
570 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
572 warning (_("constant %s (value %ld) will not be collected."),
573 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
574 SYMBOL_VALUE (exp
->elts
[2].symbol
));
577 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
579 warning (_("%s is optimized away and cannot be collected."),
580 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
585 /* We have something to collect, make sure that the expr to
586 bytecode translator can handle it and that it's not too
588 aexpr
= gen_trace_for_expr (loc
->address
, exp
);
589 make_cleanup_free_agent_expr (aexpr
);
591 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
592 error (_("expression too complicated, try simplifying"));
594 ax_reqs (aexpr
, &areqs
);
595 (void) make_cleanup (xfree
, areqs
.reg_mask
);
597 if (areqs
.flaw
!= agent_flaw_none
)
598 error (_("malformed expression"));
600 if (areqs
.min_height
< 0)
601 error (_("gdb: Internal error: expression has min height < 0"));
603 if (areqs
.max_height
> 20)
604 error (_("expression too complicated, try simplifying"));
606 do_cleanups (old_chain
);
609 while (p
&& *p
++ == ',');
612 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
614 struct agent_expr
*aexpr
;
617 { /* repeat over a comma-separated list */
618 QUIT
; /* allow user to bail out with ^C */
619 while (isspace ((int) *p
))
623 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
626 /* Only expressions are allowed for this action. */
627 exp
= parse_exp_1 (&p
, block_for_pc (loc
->address
), 1);
628 old_chain
= make_cleanup (free_current_contents
, &exp
);
630 /* We have something to evaluate, make sure that the expr to
631 bytecode translator can handle it and that it's not too
633 aexpr
= gen_eval_for_expr (loc
->address
, exp
);
634 make_cleanup_free_agent_expr (aexpr
);
636 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
637 error (_("expression too complicated, try simplifying"));
639 do_cleanups (old_chain
);
642 while (p
&& *p
++ == ',');
645 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
647 char *steparg
; /* in case warning is necessary */
649 while (isspace ((int) *p
))
654 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
656 error (_("'%s': bad step-count."), *line
);
660 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
664 error (_("'%s' is not a supported tracepoint action."), *line
);
669 memrange_absolute
= -1
674 int type
; /* memrange_absolute for absolute memory range,
675 else basereg number */
676 bfd_signed_vma start
;
680 struct collection_list
682 unsigned char regs_mask
[32]; /* room for up to 256 regs */
685 struct memrange
*list
;
686 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
688 struct agent_expr
**aexpr_list
;
691 tracepoint_list
, stepping_list
;
693 /* MEMRANGE functions: */
695 static int memrange_cmp (const void *, const void *);
697 /* compare memranges for qsort */
699 memrange_cmp (const void *va
, const void *vb
)
701 const struct memrange
*a
= va
, *b
= vb
;
703 if (a
->type
< b
->type
)
705 if (a
->type
> b
->type
)
707 if (a
->type
== memrange_absolute
)
709 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
711 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
716 if (a
->start
< b
->start
)
718 if (a
->start
> b
->start
)
724 /* Sort the memrange list using qsort, and merge adjacent memranges. */
726 memrange_sortmerge (struct collection_list
*memranges
)
730 qsort (memranges
->list
, memranges
->next_memrange
,
731 sizeof (struct memrange
), memrange_cmp
);
732 if (memranges
->next_memrange
> 0)
734 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
736 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
737 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
740 /* memrange b starts before memrange a ends; merge them. */
741 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
742 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
743 continue; /* next b, same a */
747 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
748 sizeof (struct memrange
));
750 memranges
->next_memrange
= a
+ 1;
754 /* Add a register to a collection list. */
756 add_register (struct collection_list
*collection
, unsigned int regno
)
759 printf_filtered ("collect register %d\n", regno
);
760 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
761 error (_("Internal: register number %d too large for tracepoint"),
763 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
766 /* Add a memrange to a collection list */
768 add_memrange (struct collection_list
*memranges
,
769 int type
, bfd_signed_vma base
,
774 printf_filtered ("(%d,", type
);
776 printf_filtered (",%ld)\n", len
);
779 /* type: memrange_absolute == memory, other n == basereg */
780 memranges
->list
[memranges
->next_memrange
].type
= type
;
781 /* base: addr if memory, offset if reg relative. */
782 memranges
->list
[memranges
->next_memrange
].start
= base
;
783 /* len: we actually save end (base + len) for convenience */
784 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
785 memranges
->next_memrange
++;
786 if (memranges
->next_memrange
>= memranges
->listsize
)
788 memranges
->listsize
*= 2;
789 memranges
->list
= xrealloc (memranges
->list
,
790 memranges
->listsize
);
793 if (type
!= memrange_absolute
) /* Better collect the base register! */
794 add_register (memranges
, type
);
797 /* Add a symbol to a collection list. */
799 collect_symbol (struct collection_list
*collect
,
801 struct gdbarch
*gdbarch
,
802 long frame_regno
, long frame_offset
,
807 bfd_signed_vma offset
;
808 int treat_as_expr
= 0;
810 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
811 switch (SYMBOL_CLASS (sym
))
814 printf_filtered ("%s: don't know symbol class %d\n",
815 SYMBOL_PRINT_NAME (sym
),
819 printf_filtered ("constant %s (value %ld) will not be collected.\n",
820 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
823 offset
= SYMBOL_VALUE_ADDRESS (sym
);
828 sprintf_vma (tmp
, offset
);
829 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
830 SYMBOL_PRINT_NAME (sym
), len
,
833 /* A struct may be a C++ class with static fields, go to general
834 expression handling. */
835 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
838 add_memrange (collect
, memrange_absolute
, offset
, len
);
841 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
843 printf_filtered ("LOC_REG[parm] %s: ",
844 SYMBOL_PRINT_NAME (sym
));
845 add_register (collect
, reg
);
846 /* Check for doubles stored in two registers. */
847 /* FIXME: how about larger types stored in 3 or more regs? */
848 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
849 len
> register_size (gdbarch
, reg
))
850 add_register (collect
, reg
+ 1);
853 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
854 printf_filtered (" (will not collect %s)\n",
855 SYMBOL_PRINT_NAME (sym
));
859 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
862 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
863 SYMBOL_PRINT_NAME (sym
), len
);
865 printf_filtered (" from frame ptr reg %d\n", reg
);
867 add_memrange (collect
, reg
, offset
, len
);
869 case LOC_REGPARM_ADDR
:
870 reg
= SYMBOL_VALUE (sym
);
874 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
875 SYMBOL_PRINT_NAME (sym
), len
);
877 printf_filtered (" from reg %d\n", reg
);
879 add_memrange (collect
, reg
, offset
, len
);
883 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
886 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
887 SYMBOL_PRINT_NAME (sym
), len
);
889 printf_filtered (" from frame ptr reg %d\n", reg
);
891 add_memrange (collect
, reg
, offset
, len
);
894 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
895 SYMBOL_PRINT_NAME (sym
));
897 case LOC_OPTIMIZED_OUT
:
898 printf_filtered ("%s has been optimized out of existence.\n",
899 SYMBOL_PRINT_NAME (sym
));
907 /* Expressions are the most general case. */
910 struct agent_expr
*aexpr
;
911 struct cleanup
*old_chain1
= NULL
;
912 struct agent_reqs areqs
;
914 aexpr
= gen_trace_for_var (scope
, gdbarch
, sym
);
916 /* It can happen that the symbol is recorded as a computed
917 location, but it's been optimized away and doesn't actually
918 have a location expression. */
921 printf_filtered ("%s has been optimized out of existence.\n",
922 SYMBOL_PRINT_NAME (sym
));
926 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
928 ax_reqs (aexpr
, &areqs
);
929 if (areqs
.flaw
!= agent_flaw_none
)
930 error (_("malformed expression"));
932 if (areqs
.min_height
< 0)
933 error (_("gdb: Internal error: expression has min height < 0"));
934 if (areqs
.max_height
> 20)
935 error (_("expression too complicated, try simplifying"));
937 discard_cleanups (old_chain1
);
938 add_aexpr (collect
, aexpr
);
940 /* take care of the registers */
941 if (areqs
.reg_mask_len
> 0)
945 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
947 QUIT
; /* allow user to bail out with ^C */
948 if (areqs
.reg_mask
[ndx1
] != 0)
950 /* assume chars have 8 bits */
951 for (ndx2
= 0; ndx2
< 8; ndx2
++)
952 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
953 /* it's used -- record it */
954 add_register (collect
, ndx1
* 8 + ndx2
);
961 /* Add all locals (or args) symbols to collection list */
963 add_local_symbols (struct collection_list
*collect
,
964 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
965 long frame_regno
, long frame_offset
, int type
)
969 struct dict_iterator iter
;
972 block
= block_for_pc (pc
);
975 QUIT
; /* allow user to bail out with ^C */
976 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
978 if (SYMBOL_IS_ARGUMENT (sym
)
979 ? type
== 'A' /* collecting Arguments */
980 : type
== 'L') /* collecting Locals */
983 collect_symbol (collect
, sym
, gdbarch
,
984 frame_regno
, frame_offset
, pc
);
987 if (BLOCK_FUNCTION (block
))
990 block
= BLOCK_SUPERBLOCK (block
);
993 warning (_("No %s found in scope."),
994 type
== 'L' ? "locals" : "args");
997 /* worker function */
999 clear_collection_list (struct collection_list
*list
)
1003 list
->next_memrange
= 0;
1004 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1006 free_agent_expr (list
->aexpr_list
[ndx
]);
1007 list
->aexpr_list
[ndx
] = NULL
;
1009 list
->next_aexpr_elt
= 0;
1010 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1013 /* reduce a collection list to string form (for gdb protocol) */
1015 stringify_collection_list (struct collection_list
*list
, char *string
)
1017 char temp_buf
[2048];
1021 char *(*str_list
)[];
1025 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1026 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1028 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1029 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1031 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1034 printf_filtered ("\nCollecting registers (mask): 0x");
1039 QUIT
; /* allow user to bail out with ^C */
1041 printf_filtered ("%02X", list
->regs_mask
[i
]);
1042 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1045 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1049 printf_filtered ("\n");
1050 if (list
->next_memrange
> 0 && info_verbose
)
1051 printf_filtered ("Collecting memranges: \n");
1052 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1054 QUIT
; /* allow user to bail out with ^C */
1055 sprintf_vma (tmp2
, list
->list
[i
].start
);
1058 printf_filtered ("(%d, %s, %ld)\n",
1061 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1063 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1065 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1072 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
1074 /* The "%X" conversion specifier expects an unsigned argument,
1075 so passing -1 (memrange_absolute) to it directly gives you
1076 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1078 if (list
->list
[i
].type
== memrange_absolute
)
1079 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1081 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
1084 count
+= strlen (end
);
1085 end
= temp_buf
+ count
;
1088 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1090 QUIT
; /* allow user to bail out with ^C */
1091 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1093 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1098 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1099 end
+= 10; /* 'X' + 8 hex digits + ',' */
1102 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1103 end
, list
->aexpr_list
[i
]->len
);
1104 count
+= 2 * list
->aexpr_list
[i
]->len
;
1109 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1114 (*str_list
)[ndx
] = NULL
;
1127 encode_actions_1 (struct command_line
*action
,
1128 struct breakpoint
*t
,
1129 struct bp_location
*tloc
,
1131 LONGEST frame_offset
,
1132 struct collection_list
*collect
,
1133 struct collection_list
*stepping_list
)
1136 struct expression
*exp
= NULL
;
1137 struct command_line
*actions
;
1139 struct value
*tempval
;
1140 struct cmd_list_element
*cmd
;
1141 struct agent_expr
*aexpr
;
1143 for (; action
; action
= action
->next
)
1145 QUIT
; /* allow user to bail out with ^C */
1146 action_exp
= action
->line
;
1147 while (isspace ((int) *action_exp
))
1150 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1152 error (_("Bad action list item: %s"), action_exp
);
1154 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1157 { /* repeat over a comma-separated list */
1158 QUIT
; /* allow user to bail out with ^C */
1159 while (isspace ((int) *action_exp
))
1162 if (0 == strncasecmp ("$reg", action_exp
, 4))
1164 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1165 add_register (collect
, i
);
1166 action_exp
= strchr (action_exp
, ','); /* more? */
1168 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1170 add_local_symbols (collect
,
1176 action_exp
= strchr (action_exp
, ','); /* more? */
1178 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1180 add_local_symbols (collect
,
1186 action_exp
= strchr (action_exp
, ','); /* more? */
1190 unsigned long addr
, len
;
1191 struct cleanup
*old_chain
= NULL
;
1192 struct cleanup
*old_chain1
= NULL
;
1193 struct agent_reqs areqs
;
1195 exp
= parse_exp_1 (&action_exp
,
1196 block_for_pc (tloc
->address
), 1);
1197 old_chain
= make_cleanup (free_current_contents
, &exp
);
1199 switch (exp
->elts
[0].opcode
)
1203 const char *name
= &exp
->elts
[2].string
;
1205 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1206 name
, strlen (name
));
1208 internal_error (__FILE__
, __LINE__
,
1209 _("Register $%s not available"),
1212 printf_filtered ("OP_REGISTER: ");
1213 add_register (collect
, i
);
1218 /* safe because we know it's a simple expression */
1219 tempval
= evaluate_expression (exp
);
1220 addr
= value_address (tempval
);
1221 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1222 add_memrange (collect
, memrange_absolute
, addr
, len
);
1226 collect_symbol (collect
,
1227 exp
->elts
[2].symbol
,
1234 default: /* full-fledged expression */
1235 aexpr
= gen_trace_for_expr (tloc
->address
, exp
);
1237 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1239 ax_reqs (aexpr
, &areqs
);
1240 if (areqs
.flaw
!= agent_flaw_none
)
1241 error (_("malformed expression"));
1243 if (areqs
.min_height
< 0)
1244 error (_("gdb: Internal error: expression has min height < 0"));
1245 if (areqs
.max_height
> 20)
1246 error (_("expression too complicated, try simplifying"));
1248 discard_cleanups (old_chain1
);
1249 add_aexpr (collect
, aexpr
);
1251 /* take care of the registers */
1252 if (areqs
.reg_mask_len
> 0)
1257 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1259 QUIT
; /* allow user to bail out with ^C */
1260 if (areqs
.reg_mask
[ndx1
] != 0)
1262 /* assume chars have 8 bits */
1263 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1264 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1265 /* it's used -- record it */
1266 add_register (collect
,
1273 do_cleanups (old_chain
);
1276 while (action_exp
&& *action_exp
++ == ',');
1278 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1281 { /* repeat over a comma-separated list */
1282 QUIT
; /* allow user to bail out with ^C */
1283 while (isspace ((int) *action_exp
))
1287 unsigned long addr
, len
;
1288 struct cleanup
*old_chain
= NULL
;
1289 struct cleanup
*old_chain1
= NULL
;
1290 struct agent_reqs areqs
;
1292 exp
= parse_exp_1 (&action_exp
,
1293 block_for_pc (tloc
->address
), 1);
1294 old_chain
= make_cleanup (free_current_contents
, &exp
);
1296 aexpr
= gen_eval_for_expr (tloc
->address
, exp
);
1297 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1299 ax_reqs (aexpr
, &areqs
);
1300 if (areqs
.flaw
!= agent_flaw_none
)
1301 error (_("malformed expression"));
1303 if (areqs
.min_height
< 0)
1304 error (_("gdb: Internal error: expression has min height < 0"));
1305 if (areqs
.max_height
> 20)
1306 error (_("expression too complicated, try simplifying"));
1308 discard_cleanups (old_chain1
);
1309 /* Even though we're not officially collecting, add
1310 to the collect list anyway. */
1311 add_aexpr (collect
, aexpr
);
1313 do_cleanups (old_chain
);
1316 while (action_exp
&& *action_exp
++ == ',');
1318 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1320 /* We check against nested while-stepping when setting
1321 breakpoint action, so no way to run into nested
1323 gdb_assert (stepping_list
);
1325 encode_actions_1 (action
->body_list
[0], t
, tloc
, frame_reg
, frame_offset
,
1326 stepping_list
, NULL
);
1329 error (_("Invalid tracepoint command '%s'"), action
->line
);
1333 /* Render all actions into gdb protocol. */
1335 encode_actions (struct breakpoint
*t
, struct bp_location
*tloc
,
1336 char ***tdp_actions
, char ***stepping_actions
)
1338 static char tdp_buff
[2048], step_buff
[2048];
1339 char *default_collect_line
= NULL
;
1340 struct command_line
*actions
;
1341 struct command_line
*default_collect_action
= NULL
;
1343 LONGEST frame_offset
;
1344 struct cleanup
*back_to
;
1346 back_to
= make_cleanup (null_cleanup
, NULL
);
1348 clear_collection_list (&tracepoint_list
);
1349 clear_collection_list (&stepping_list
);
1351 *tdp_actions
= NULL
;
1352 *stepping_actions
= NULL
;
1354 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1355 t
->loc
->address
, &frame_reg
, &frame_offset
);
1357 actions
= t
->commands
;
1359 /* If there are default expressions to collect, make up a collect
1360 action and prepend to the action list to encode. Note that since
1361 validation is per-tracepoint (local var "xyz" might be valid for
1362 one tracepoint and not another, etc), we make up the action on
1363 the fly, and don't cache it. */
1364 if (*default_collect
)
1367 enum actionline_type linetype
;
1369 default_collect_line
= xstrprintf ("collect %s", default_collect
);
1370 make_cleanup (xfree
, default_collect_line
);
1372 line
= default_collect_line
;
1373 linetype
= validate_actionline (&line
, t
);
1374 if (linetype
!= BADLINE
)
1376 default_collect_action
= xmalloc (sizeof (struct command_line
));
1377 make_cleanup (xfree
, default_collect_action
);
1378 default_collect_action
->next
= t
->commands
;
1379 default_collect_action
->line
= line
;
1380 actions
= default_collect_action
;
1383 encode_actions_1 (actions
, t
, tloc
, frame_reg
, frame_offset
,
1384 &tracepoint_list
, &stepping_list
);
1386 memrange_sortmerge (&tracepoint_list
);
1387 memrange_sortmerge (&stepping_list
);
1389 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1391 *stepping_actions
= stringify_collection_list (&stepping_list
,
1394 do_cleanups (back_to
);
1398 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1400 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1402 collect
->aexpr_list
=
1403 xrealloc (collect
->aexpr_list
,
1404 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1405 collect
->aexpr_listsize
*= 2;
1407 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1408 collect
->next_aexpr_elt
++;
1413 start_tracing (void)
1416 VEC(breakpoint_p
) *tp_vec
= NULL
;
1418 struct breakpoint
*t
;
1419 struct trace_state_variable
*tsv
;
1420 int any_downloaded
= 0;
1422 target_trace_init ();
1424 tp_vec
= all_tracepoints ();
1425 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1427 t
->number_on_target
= 0;
1428 target_download_tracepoint (t
);
1429 t
->number_on_target
= t
->number
;
1432 VEC_free (breakpoint_p
, tp_vec
);
1434 /* No point in tracing without any tracepoints... */
1435 if (!any_downloaded
)
1436 error ("No tracepoints downloaded, not starting trace");
1438 /* Send down all the trace state variables too. */
1439 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1441 target_download_trace_state_variable (tsv
);
1444 /* Tell target to treat text-like sections as transparent. */
1445 target_trace_set_readonly_regions ();
1446 /* Set some mode flags. */
1447 target_set_disconnected_tracing (disconnected_tracing
);
1448 target_set_circular_trace_buffer (circular_trace_buffer
);
1450 /* Now insert traps and begin collecting data. */
1451 target_trace_start ();
1453 /* Reset our local state. */
1454 set_traceframe_num (-1);
1455 set_tracepoint_num (-1);
1456 set_traceframe_context (NULL
);
1457 current_trace_status()->running
= 1;
1462 Tell target to clear any previous trace experiment.
1463 Walk the list of tracepoints, and send them (and their actions)
1464 to the target. If no errors,
1465 Tell target to start a new trace experiment. */
1468 trace_start_command (char *args
, int from_tty
)
1470 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1477 trace_stop_command (char *args
, int from_tty
)
1485 target_trace_stop ();
1486 /* should change in response to reply? */
1487 current_trace_status ()->running
= 0;
1490 /* tstatus command */
1492 trace_status_command (char *args
, int from_tty
)
1494 struct trace_status
*ts
= current_trace_status ();
1497 status
= target_get_trace_status (ts
);
1502 printf_filtered (_("Using a trace file.\n"));
1505 printf_filtered (_("Trace can not be run on this target.\n"));
1510 if (!ts
->running_known
)
1512 printf_filtered (_("Run/stop status is unknown.\n"));
1514 else if (ts
->running
)
1516 printf_filtered (_("Trace is running on the target.\n"));
1517 if (disconnected_tracing
)
1518 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1520 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1524 switch (ts
->stop_reason
)
1526 case trace_never_run
:
1527 printf_filtered (_("No trace has been run on the target.\n"));
1530 printf_filtered (_("Trace stopped by a tstop command.\n"));
1532 case trace_buffer_full
:
1533 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1535 case trace_disconnected
:
1536 printf_filtered (_("Trace stopped because of disconnection.\n"));
1538 case tracepoint_passcount
:
1539 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1540 ts
->stopping_tracepoint
);
1542 case trace_stop_reason_unknown
:
1543 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1546 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1552 if (ts
->traceframes_created
>= 0
1553 && ts
->traceframe_count
!= ts
->traceframes_created
)
1555 printf_filtered (_("Buffer contains %d trace frames (of %d created total).\n"),
1556 ts
->traceframe_count
, ts
->traceframes_created
);
1558 else if (ts
->traceframe_count
>= 0)
1560 printf_filtered (_("Collected %d trace frames.\n"),
1561 ts
->traceframe_count
);
1564 if (ts
->buffer_free
>= 0)
1566 if (ts
->buffer_size
>= 0)
1568 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1569 ts
->buffer_free
, ts
->buffer_size
);
1570 if (ts
->buffer_size
> 0)
1571 printf_filtered (_(" (%d%% full)"),
1572 ((int) ((((long long) (ts
->buffer_size
1573 - ts
->buffer_free
)) * 100)
1574 / ts
->buffer_size
)));
1575 printf_filtered (_(".\n"));
1578 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1582 /* Now report on what we're doing with tfind. */
1583 if (traceframe_number
>= 0)
1584 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1585 traceframe_number
, tracepoint_number
);
1587 printf_filtered (_("Not looking at any trace frame.\n"));
1590 /* Report the trace status to uiout, in a way suitable for MI, and not
1591 suitable for CLI. If ON_STOP is true, suppress a few fields that
1592 are not meaningful in the -trace-stop response.
1594 The implementation is essentially parallel to trace_status_command, but
1595 merging them will result in unreadable code. */
1597 trace_status_mi (int on_stop
)
1599 struct trace_status
*ts
= current_trace_status ();
1601 char *string_status
;
1603 status
= target_get_trace_status (ts
);
1605 if (status
== -1 && !ts
->from_file
)
1607 ui_out_field_string (uiout
, "supported", "0");
1612 ui_out_field_string (uiout
, "supported", "file");
1614 ui_out_field_string (uiout
, "supported", "1");
1616 gdb_assert (ts
->running_known
);
1620 ui_out_field_string (uiout
, "running", "1");
1622 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
1623 Given that the frontend gets the status either on -trace-stop, or from
1624 -trace-status after re-connection, it does not seem like this
1625 information is necessary for anything. It is not necessary for either
1626 figuring the vital state of the target nor for navigation of trace
1627 frames. If the frontend wants to show the current state is some
1628 configure dialog, it can request the value when such dialog is
1629 invoked by the user. */
1633 char *stop_reason
= NULL
;
1634 int stopping_tracepoint
= -1;
1637 ui_out_field_string (uiout
, "running", "0");
1639 if (ts
->stop_reason
!= trace_stop_reason_unknown
)
1641 switch (ts
->stop_reason
)
1644 stop_reason
= "request";
1646 case trace_buffer_full
:
1647 stop_reason
= "overflow";
1649 case trace_disconnected
:
1650 stop_reason
= "disconnection";
1652 case tracepoint_passcount
:
1653 stop_reason
= "passcount";
1654 stopping_tracepoint
= ts
->stopping_tracepoint
;
1660 ui_out_field_string (uiout
, "stop-reason", stop_reason
);
1661 if (stopping_tracepoint
!= -1)
1662 ui_out_field_int (uiout
, "stopping-tracepoint",
1663 stopping_tracepoint
);
1669 if ((int) ts
->traceframe_count
!= -1)
1670 ui_out_field_int (uiout
, "frames", ts
->traceframe_count
);
1671 if ((int) ts
->buffer_size
!= -1)
1672 ui_out_field_int (uiout
, "buffer-size", (int) ts
->buffer_size
);
1673 if ((int) ts
->buffer_free
!= -1)
1674 ui_out_field_int (uiout
, "buffer-free", (int) ts
->buffer_free
);
1679 disconnect_or_stop_tracing (int from_tty
)
1681 /* It can happen that the target that was tracing went away on its
1682 own, and we didn't notice. Get a status update, and if the
1683 current target doesn't even do tracing, then assume it's not
1685 if (target_get_trace_status (current_trace_status ()) < 0)
1686 current_trace_status ()->running
= 0;
1688 if (current_trace_status ()->running
&& from_tty
)
1690 int cont
= query (_("Trace is running. Continue tracing after detach? "));
1691 /* Note that we send the query result without affecting the
1692 user's setting of disconnected_tracing, so that the answer is
1694 send_disconnected_tracing_value (cont
);
1696 /* Also ensure that we do the equivalent of a tstop command if
1697 tracing is not to continue after the detach. */
1703 /* Worker function for the various flavors of the tfind command. */
1705 finish_tfind_command (enum trace_find_type type
, int num
,
1706 ULONGEST addr1
, ULONGEST addr2
,
1709 int target_frameno
= -1, target_tracept
= -1;
1710 struct frame_id old_frame_id
;
1712 struct breakpoint
*tp
;
1714 old_frame_id
= get_frame_id (get_current_frame ());
1716 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
1719 if (type
== tfind_number
1721 && target_frameno
== -1)
1723 /* We told the target to get out of tfind mode, and it did. */
1725 else if (target_frameno
== -1)
1727 /* A request for a non-existant trace frame has failed.
1728 Our response will be different, depending on FROM_TTY:
1730 If FROM_TTY is true, meaning that this command was
1731 typed interactively by the user, then give an error
1732 and DO NOT change the state of traceframe_number etc.
1734 However if FROM_TTY is false, meaning that we're either
1735 in a script, a loop, or a user-defined command, then
1736 DON'T give an error, but DO change the state of
1737 traceframe_number etc. to invalid.
1739 The rationalle is that if you typed the command, you
1740 might just have committed a typo or something, and you'd
1741 like to NOT lose your current debugging state. However
1742 if you're in a user-defined command or especially in a
1743 loop, then you need a way to detect that the command
1744 failed WITHOUT aborting. This allows you to write
1745 scripts that search thru the trace buffer until the end,
1746 and then continue on to do something else. */
1749 error (_("Target failed to find requested trace frame."));
1753 printf_filtered ("End of trace buffer.\n");
1754 #if 0 /* dubious now? */
1755 /* The following will not recurse, since it's
1757 trace_find_command ("-1", from_tty
);
1762 tp
= get_tracepoint_by_number_on_target (target_tracept
);
1764 reinit_frame_cache ();
1765 registers_changed ();
1766 target_dcache_invalidate ();
1767 set_traceframe_num (target_frameno
);
1768 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
1769 if (target_frameno
== -1)
1770 set_traceframe_context (NULL
);
1772 set_traceframe_context (get_current_frame ());
1774 /* If we're in nonstop mode and getting out of looking at trace
1775 frames, there won't be any current frame to go back to and
1778 && (has_stack_frames () || traceframe_number
>= 0))
1780 enum print_what print_what
;
1782 /* NOTE: in immitation of the step command, try to determine
1783 whether we have made a transition from one function to
1784 another. If so, we'll print the "stack frame" (ie. the new
1785 function and it's arguments) -- otherwise we'll just show the
1788 if (frame_id_eq (old_frame_id
,
1789 get_frame_id (get_current_frame ())))
1790 print_what
= SRC_LINE
;
1792 print_what
= SRC_AND_LOC
;
1794 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1799 /* trace_find_command takes a trace frame number n,
1800 sends "QTFrame:<n>" to the target,
1801 and accepts a reply that may contain several optional pieces
1802 of information: a frame number, a tracepoint number, and an
1803 indication of whether this is a trap frame or a stepping frame.
1805 The minimal response is just "OK" (which indicates that the
1806 target does not give us a frame number or a tracepoint number).
1807 Instead of that, the target may send us a string containing
1809 F<hexnum> (gives the selected frame number)
1810 T<hexnum> (gives the selected tracepoint number)
1815 trace_find_command (char *args
, int from_tty
)
1816 { /* this should only be called with a numeric argument */
1819 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1820 error ("May not look at trace frames while trace is running.");
1822 if (args
== 0 || *args
== 0)
1823 { /* TFIND with no args means find NEXT trace frame. */
1824 if (traceframe_number
== -1)
1825 frameno
= 0; /* "next" is first one */
1827 frameno
= traceframe_number
+ 1;
1829 else if (0 == strcmp (args
, "-"))
1831 if (traceframe_number
== -1)
1832 error (_("not debugging trace buffer"));
1833 else if (from_tty
&& traceframe_number
== 0)
1834 error (_("already at start of trace buffer"));
1836 frameno
= traceframe_number
- 1;
1838 /* A hack to work around eval's need for fp to have been collected. */
1839 else if (0 == strcmp (args
, "-1"))
1842 frameno
= parse_and_eval_long (args
);
1845 error (_("invalid input (%d is less than zero)"), frameno
);
1847 finish_tfind_command (tfind_number
, frameno
, 0, 0, from_tty
);
1852 trace_find_end_command (char *args
, int from_tty
)
1854 trace_find_command ("-1", from_tty
);
1859 trace_find_none_command (char *args
, int from_tty
)
1861 trace_find_command ("-1", from_tty
);
1866 trace_find_start_command (char *args
, int from_tty
)
1868 trace_find_command ("0", from_tty
);
1871 /* tfind pc command */
1873 trace_find_pc_command (char *args
, int from_tty
)
1878 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1879 error ("May not look at trace frames while trace is running.");
1881 if (args
== 0 || *args
== 0)
1882 pc
= regcache_read_pc (get_current_regcache ());
1884 pc
= parse_and_eval_address (args
);
1886 finish_tfind_command (tfind_pc
, 0, pc
, 0, from_tty
);
1889 /* tfind tracepoint command */
1891 trace_find_tracepoint_command (char *args
, int from_tty
)
1894 struct breakpoint
*tp
;
1896 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1897 error ("May not look at trace frames while trace is running.");
1899 if (args
== 0 || *args
== 0)
1901 if (tracepoint_number
== -1)
1902 error (_("No current tracepoint -- please supply an argument."));
1904 tdp
= tracepoint_number
; /* default is current TDP */
1907 tdp
= parse_and_eval_long (args
);
1909 /* If we have the tracepoint on hand, use the number that the
1910 target knows about (which may be different if we disconnected
1911 and reconnected). */
1912 tp
= get_tracepoint (tdp
);
1914 tdp
= tp
->number_on_target
;
1916 finish_tfind_command (tfind_tp
, tdp
, 0, 0, from_tty
);
1919 /* TFIND LINE command:
1921 This command will take a sourceline for argument, just like BREAK
1922 or TRACE (ie. anything that "decode_line_1" can handle).
1924 With no argument, this command will find the next trace frame
1925 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1928 trace_find_line_command (char *args
, int from_tty
)
1930 static CORE_ADDR start_pc
, end_pc
;
1931 struct symtabs_and_lines sals
;
1932 struct symtab_and_line sal
;
1933 struct cleanup
*old_chain
;
1934 char startpc_str
[40], endpc_str
[40];
1936 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1937 error ("May not look at trace frames while trace is running.");
1939 if (args
== 0 || *args
== 0)
1941 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1943 sals
.sals
= (struct symtab_and_line
*)
1944 xmalloc (sizeof (struct symtab_and_line
));
1949 sals
= decode_line_spec (args
, 1);
1953 old_chain
= make_cleanup (xfree
, sals
.sals
);
1954 if (sal
.symtab
== 0)
1956 printf_filtered ("TFIND: No line number information available");
1959 /* This is useful for "info line *0x7f34". If we can't
1960 tell the user about a source line, at least let them
1961 have the symbolic address. */
1962 printf_filtered (" for address ");
1964 print_address (get_current_arch (), sal
.pc
, gdb_stdout
);
1965 printf_filtered (";\n -- will attempt to find by PC. \n");
1969 printf_filtered (".\n");
1970 return; /* No line, no PC; what can we do? */
1973 else if (sal
.line
> 0
1974 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1976 if (start_pc
== end_pc
)
1978 printf_filtered ("Line %d of \"%s\"",
1979 sal
.line
, sal
.symtab
->filename
);
1981 printf_filtered (" is at address ");
1982 print_address (get_current_arch (), start_pc
, gdb_stdout
);
1984 printf_filtered (" but contains no code.\n");
1985 sal
= find_pc_line (start_pc
, 0);
1987 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
1988 && start_pc
!= end_pc
)
1989 printf_filtered ("Attempting to find line %d instead.\n",
1992 error (_("Cannot find a good line."));
1996 /* Is there any case in which we get here, and have an address
1997 which the user would want to see? If we have debugging
1998 symbols and no line numbers? */
1999 error (_("Line number %d is out of range for \"%s\"."),
2000 sal
.line
, sal
.symtab
->filename
);
2002 /* Find within range of stated line. */
2004 finish_tfind_command (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
2006 finish_tfind_command (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
2007 do_cleanups (old_chain
);
2010 /* tfind range command */
2012 trace_find_range_command (char *args
, int from_tty
)
2014 static CORE_ADDR start
, stop
;
2015 char start_str
[40], stop_str
[40];
2018 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2019 error ("May not look at trace frames while trace is running.");
2021 if (args
== 0 || *args
== 0)
2022 { /* XXX FIXME: what should default behavior be? */
2023 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2027 if (0 != (tmp
= strchr (args
, ',')))
2029 *tmp
++ = '\0'; /* terminate start address */
2030 while (isspace ((int) *tmp
))
2032 start
= parse_and_eval_address (args
);
2033 stop
= parse_and_eval_address (tmp
);
2036 { /* no explicit end address? */
2037 start
= parse_and_eval_address (args
);
2038 stop
= start
+ 1; /* ??? */
2041 finish_tfind_command (tfind_range
, 0, start
, stop
, from_tty
);
2044 /* tfind outside command */
2046 trace_find_outside_command (char *args
, int from_tty
)
2048 CORE_ADDR start
, stop
;
2049 char start_str
[40], stop_str
[40];
2052 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
2053 error ("May not look at trace frames while trace is running.");
2055 if (args
== 0 || *args
== 0)
2056 { /* XXX FIXME: what should default behavior be? */
2057 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2061 if (0 != (tmp
= strchr (args
, ',')))
2063 *tmp
++ = '\0'; /* terminate start address */
2064 while (isspace ((int) *tmp
))
2066 start
= parse_and_eval_address (args
);
2067 stop
= parse_and_eval_address (tmp
);
2070 { /* no explicit end address? */
2071 start
= parse_and_eval_address (args
);
2072 stop
= start
+ 1; /* ??? */
2075 finish_tfind_command (tfind_outside
, 0, start
, stop
, from_tty
);
2078 /* info scope command: list the locals for a scope. */
2080 scope_info (char *args
, int from_tty
)
2082 struct symtabs_and_lines sals
;
2084 struct minimal_symbol
*msym
;
2085 struct block
*block
;
2086 char **canonical
, *symname
, *save_args
= args
;
2087 struct dict_iterator iter
;
2089 struct gdbarch
*gdbarch
;
2092 if (args
== 0 || *args
== 0)
2093 error (_("requires an argument (function, line or *addr) to define a scope"));
2095 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
2096 if (sals
.nelts
== 0)
2097 return; /* presumably decode_line_1 has already warned */
2099 /* Resolve line numbers to PC */
2100 resolve_sal_pc (&sals
.sals
[0]);
2101 block
= block_for_pc (sals
.sals
[0].pc
);
2105 QUIT
; /* allow user to bail out with ^C */
2106 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2108 QUIT
; /* allow user to bail out with ^C */
2110 printf_filtered ("Scope for %s:\n", save_args
);
2113 symname
= SYMBOL_PRINT_NAME (sym
);
2114 if (symname
== NULL
|| *symname
== '\0')
2115 continue; /* probably botched, certainly useless */
2117 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
2119 printf_filtered ("Symbol %s is ", symname
);
2120 switch (SYMBOL_CLASS (sym
))
2123 case LOC_UNDEF
: /* messed up symbol? */
2124 printf_filtered ("a bogus symbol, class %d.\n",
2125 SYMBOL_CLASS (sym
));
2126 count
--; /* don't count this one */
2129 printf_filtered ("a constant with value %ld (0x%lx)",
2130 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2132 case LOC_CONST_BYTES
:
2133 printf_filtered ("constant bytes: ");
2134 if (SYMBOL_TYPE (sym
))
2135 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2136 fprintf_filtered (gdb_stdout
, " %02x",
2137 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2140 printf_filtered ("in static storage at address ");
2141 printf_filtered ("%s", paddress (gdbarch
,
2142 SYMBOL_VALUE_ADDRESS (sym
)));
2145 /* GDBARCH is the architecture associated with the objfile
2146 the symbol is defined in; the target architecture may be
2147 different, and may provide additional registers. However,
2148 we do not know the target architecture at this point.
2149 We assume the objfile architecture will contain all the
2150 standard registers that occur in debug info in that
2152 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2154 if (SYMBOL_IS_ARGUMENT (sym
))
2155 printf_filtered ("an argument in register $%s",
2156 gdbarch_register_name (gdbarch
, regno
));
2158 printf_filtered ("a local variable in register $%s",
2159 gdbarch_register_name (gdbarch
, regno
));
2162 printf_filtered ("an argument at stack/frame offset %ld",
2163 SYMBOL_VALUE (sym
));
2166 printf_filtered ("a local variable at frame offset %ld",
2167 SYMBOL_VALUE (sym
));
2170 printf_filtered ("a reference argument at offset %ld",
2171 SYMBOL_VALUE (sym
));
2173 case LOC_REGPARM_ADDR
:
2174 /* Note comment at LOC_REGISTER. */
2175 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2176 printf_filtered ("the address of an argument, in register $%s",
2177 gdbarch_register_name (gdbarch
, regno
));
2180 printf_filtered ("a typedef.\n");
2183 printf_filtered ("a label at address ");
2184 printf_filtered ("%s", paddress (gdbarch
,
2185 SYMBOL_VALUE_ADDRESS (sym
)));
2188 printf_filtered ("a function at address ");
2189 printf_filtered ("%s",
2190 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2192 case LOC_UNRESOLVED
:
2193 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2196 printf_filtered ("Unresolved Static");
2199 printf_filtered ("static storage at address ");
2200 printf_filtered ("%s",
2201 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
2204 case LOC_OPTIMIZED_OUT
:
2205 printf_filtered ("optimized out.\n");
2208 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
2211 if (SYMBOL_TYPE (sym
))
2212 printf_filtered (", length %d.\n",
2213 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2215 if (BLOCK_FUNCTION (block
))
2218 block
= BLOCK_SUPERBLOCK (block
);
2221 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2225 /* worker function (cleanup) */
2227 replace_comma (void *data
)
2235 trace_dump_command (char *args
, int from_tty
)
2237 struct regcache
*regcache
;
2238 struct gdbarch
*gdbarch
;
2239 struct breakpoint
*t
;
2240 struct command_line
*action
;
2241 char *action_exp
, *next_comma
;
2242 struct cleanup
*old_cleanups
;
2243 int stepping_actions
= 0;
2244 int stepping_frame
= 0;
2245 struct bp_location
*loc
;
2247 if (tracepoint_number
== -1)
2249 warning (_("No current trace frame."));
2253 t
= get_tracepoint (tracepoint_number
);
2256 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2259 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2261 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2262 tracepoint_number
, traceframe_number
);
2264 /* The current frame is a trap frame if the frame PC is equal
2265 to the tracepoint PC. If not, then the current frame was
2266 collected during single-stepping. */
2268 regcache
= get_current_regcache ();
2269 gdbarch
= get_regcache_arch (regcache
);
2271 /* If the traceframe's address matches any of the tracepoint's
2272 locations, assume it is a direct hit rather than a while-stepping
2273 frame. (FIXME this is not reliable, should record each frame's
2276 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
2277 if (loc
->address
== regcache_read_pc (regcache
))
2280 for (action
= t
->commands
; action
; action
= action
->next
)
2282 struct cmd_list_element
*cmd
;
2284 QUIT
; /* allow user to bail out with ^C */
2285 action_exp
= action
->line
;
2286 while (isspace ((int) *action_exp
))
2289 /* The collection actions to be done while stepping are
2290 bracketed by the commands "while-stepping" and "end". */
2292 if (*action_exp
== '#') /* comment line */
2295 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2297 error (_("Bad action list item: %s"), action_exp
);
2299 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2300 stepping_actions
= 1;
2301 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2302 stepping_actions
= 0;
2303 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2305 /* Display the collected data.
2306 For the trap frame, display only what was collected at
2307 the trap. Likewise for stepping frames, display only
2308 what was collected while stepping. This means that the
2309 two boolean variables, STEPPING_FRAME and
2310 STEPPING_ACTIONS should be equal. */
2311 if (stepping_frame
== stepping_actions
)
2314 { /* repeat over a comma-separated list */
2315 QUIT
; /* allow user to bail out with ^C */
2316 if (*action_exp
== ',')
2318 while (isspace ((int) *action_exp
))
2321 next_comma
= strchr (action_exp
, ',');
2323 if (0 == strncasecmp (action_exp
, "$reg", 4))
2324 registers_info (NULL
, from_tty
);
2325 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2326 locals_info (NULL
, from_tty
);
2327 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2328 args_info (NULL
, from_tty
);
2333 make_cleanup (replace_comma
, next_comma
);
2336 printf_filtered ("%s = ", action_exp
);
2337 output_command (action_exp
, from_tty
);
2338 printf_filtered ("\n");
2342 action_exp
= next_comma
;
2344 while (action_exp
&& *action_exp
== ',');
2348 discard_cleanups (old_cleanups
);
2351 extern int trace_regblock_size
;
2354 trace_save_command (char *args
, int from_tty
)
2357 char *filename
= NULL
, *pathname
;
2358 int target_does_save
= 0;
2359 struct cleanup
*cleanup
;
2360 struct trace_status
*ts
= current_trace_status ();
2363 struct uploaded_tp
*uploaded_tps
= NULL
, *utp
;
2364 struct uploaded_tsv
*uploaded_tsvs
= NULL
, *utsv
;
2367 ULONGEST offset
= 0;
2368 #define MAX_TRACE_UPLOAD 2000
2369 gdb_byte buf
[MAX_TRACE_UPLOAD
];
2373 error_no_arg (_("file in which to save trace data"));
2375 argv
= gdb_buildargv (args
);
2376 make_cleanup_freeargv (argv
);
2378 for (; *argv
; ++argv
)
2380 if (strcmp (*argv
, "-r") == 0)
2381 target_does_save
= 1;
2382 else if (**argv
== '-')
2383 error (_("unknown option `%s'"), *argv
);
2389 error_no_arg (_("file in which to save trace data"));
2391 /* If the target is to save the data to a file on its own, then just
2392 send the command and be done with it. */
2393 if (target_does_save
)
2395 err
= target_save_trace_data (filename
);
2397 error (_("Target failed to save trace data to '%s'."),
2402 /* Get the trace status first before opening the file, so if the
2403 target is losing, we can get out without touching files. */
2404 status
= target_get_trace_status (ts
);
2406 pathname
= tilde_expand (args
);
2407 cleanup
= make_cleanup (xfree
, pathname
);
2409 fp
= fopen (pathname
, "w");
2411 error (_("Unable to open file '%s' for saving trace data (%s)"),
2412 args
, safe_strerror (errno
));
2413 make_cleanup_fclose (fp
);
2415 /* Write a file header, with a high-bit-set char to indicate a
2416 binary file, plus a hint as what this file is, and a version
2417 number in case of future needs. */
2418 written
= fwrite ("\x7fTRACE0\n", 8, 1, fp
);
2420 perror_with_name (pathname
);
2422 /* Write descriptive info. */
2424 /* Write out the size of a register block. */
2425 fprintf (fp
, "R %x\n", trace_regblock_size
);
2427 /* Write out status of the tracing run (aka "tstatus" info). */
2428 fprintf (fp
, "status %c;%s:%x",
2429 (ts
->running
? '1' : '0'),
2430 stop_reason_names
[ts
->stop_reason
], ts
->stopping_tracepoint
);
2431 if (ts
->traceframe_count
>= 0)
2432 fprintf (fp
, ";tframes:%x", ts
->traceframe_count
);
2433 if (ts
->traceframes_created
>= 0)
2434 fprintf (fp
, ";tcreated:%x", ts
->traceframes_created
);
2435 if (ts
->buffer_free
>= 0)
2436 fprintf (fp
, ";tfree:%x", ts
->buffer_free
);
2437 if (ts
->buffer_size
>= 0)
2438 fprintf (fp
, ";tsize:%x", ts
->buffer_size
);
2441 /* Note that we want to upload tracepoints and save those, rather
2442 than simply writing out the local ones, because the user may have
2443 changed tracepoints in GDB in preparation for a future tracing
2444 run, or maybe just mass-deleted all types of breakpoints as part
2445 of cleaning up. So as not to contaminate the session, leave the
2446 data in its uploaded form, don't make into real tracepoints. */
2448 /* Get trace state variables first, they may be checked when parsing
2449 uploaded commands. */
2451 target_upload_trace_state_variables (&uploaded_tsvs
);
2453 for (utsv
= uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
2459 buf
= (char *) xmalloc (strlen (utsv
->name
) * 2 + 1);
2460 bin2hex ((gdb_byte
*) (utsv
->name
), buf
, 0);
2463 fprintf (fp
, "tsv %x:%s:%x:%s\n",
2464 utsv
->number
, phex_nz (utsv
->initial_value
, 8),
2465 utsv
->builtin
, buf
);
2471 free_uploaded_tsvs (&uploaded_tsvs
);
2473 target_upload_tracepoints (&uploaded_tps
);
2475 for (utp
= uploaded_tps
; utp
; utp
= utp
->next
)
2477 fprintf (fp
, "tp T%x:%s:%c:%x:%x",
2478 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2479 (utp
->enabled
? 'E' : 'D'), utp
->step
, utp
->pass
);
2480 if (utp
->type
== bp_fast_tracepoint
)
2481 fprintf (fp
, ":F%x", utp
->orig_size
);
2483 fprintf (fp
, ":X%x,%s", (unsigned int) strlen (utp
->cond
) / 2,
2486 for (a
= 0; a
< utp
->numactions
; ++a
)
2487 fprintf (fp
, "tp A%x:%s:%s\n",
2488 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2490 for (a
= 0; a
< utp
->num_step_actions
; ++a
)
2491 fprintf (fp
, "tp S%x:%s:%s\n",
2492 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2493 utp
->step_actions
[a
]);
2496 free_uploaded_tps (&uploaded_tps
);
2498 /* Mark the end of the definition section. */
2501 /* Get and write the trace data proper. We ask for big blocks, in
2502 the hopes of efficiency, but will take less if the target has
2503 packet size limitations or some such. */
2506 gotten
= target_get_raw_trace_data (buf
, offset
, MAX_TRACE_UPLOAD
);
2508 error (_("Failure to get requested trace buffer data"));
2509 /* No more data is forthcoming, we're done. */
2512 written
= fwrite (buf
, gotten
, 1, fp
);
2513 if (written
< gotten
)
2514 perror_with_name (pathname
);
2518 /* Mark the end of trace data. */
2519 written
= fwrite (&gotten
, 4, 1, fp
);
2521 perror_with_name (pathname
);
2523 do_cleanups (cleanup
);
2525 printf_filtered (_("Trace data saved to file '%s'.\n"), args
);
2528 /* Tell the target what to do with an ongoing tracing run if GDB
2529 disconnects for some reason. */
2532 send_disconnected_tracing_value (int value
)
2534 target_set_disconnected_tracing (value
);
2538 set_disconnected_tracing (char *args
, int from_tty
,
2539 struct cmd_list_element
*c
)
2541 send_disconnected_tracing_value (disconnected_tracing
);
2545 set_circular_trace_buffer (char *args
, int from_tty
,
2546 struct cmd_list_element
*c
)
2548 target_set_circular_trace_buffer (circular_trace_buffer
);
2551 /* Convert the memory pointed to by mem into hex, placing result in buf.
2552 * Return a pointer to the last char put in buf (null)
2553 * "stolen" from sparc-stub.c
2556 static const char hexchars
[] = "0123456789abcdef";
2559 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2567 *buf
++ = hexchars
[ch
>> 4];
2568 *buf
++ = hexchars
[ch
& 0xf];
2577 get_traceframe_number (void)
2579 return traceframe_number
;
2582 /* Make the traceframe NUM be the current trace frame. Does nothing
2583 if NUM is already current. */
2586 set_traceframe_number (int num
)
2590 if (traceframe_number
== num
)
2592 /* Nothing to do. */
2596 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
2599 warning (_("could not change traceframe"));
2601 traceframe_number
= newnum
;
2603 /* Changing the traceframe changes our view of registers and of the
2605 registers_changed ();
2608 /* A cleanup used when switching away and back from tfind mode. */
2610 struct current_traceframe_cleanup
2612 /* The traceframe we were inspecting. */
2613 int traceframe_number
;
2617 do_restore_current_traceframe_cleanup (void *arg
)
2619 struct current_traceframe_cleanup
*old
= arg
;
2621 set_traceframe_number (old
->traceframe_number
);
2625 restore_current_traceframe_cleanup_dtor (void *arg
)
2627 struct current_traceframe_cleanup
*old
= arg
;
2633 make_cleanup_restore_current_traceframe (void)
2635 struct current_traceframe_cleanup
*old
;
2637 old
= xmalloc (sizeof (struct current_traceframe_cleanup
));
2638 old
->traceframe_number
= traceframe_number
;
2640 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
2641 restore_current_traceframe_cleanup_dtor
);
2644 /* Given a number and address, return an uploaded tracepoint with that
2645 number, creating if necessary. */
2647 struct uploaded_tp
*
2648 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
2650 struct uploaded_tp
*utp
;
2652 for (utp
= *utpp
; utp
; utp
= utp
->next
)
2653 if (utp
->number
== num
&& utp
->addr
== addr
)
2655 utp
= (struct uploaded_tp
*) xmalloc (sizeof (struct uploaded_tp
));
2656 memset (utp
, 0, sizeof (struct uploaded_tp
));
2665 free_uploaded_tps (struct uploaded_tp
**utpp
)
2667 struct uploaded_tp
*next_one
;
2671 next_one
= (*utpp
)->next
;
2677 /* Given a number and address, return an uploaded tracepoint with that
2678 number, creating if necessary. */
2680 struct uploaded_tsv
*
2681 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
2683 struct uploaded_tsv
*utsv
;
2685 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
2686 if (utsv
->number
== num
)
2688 utsv
= (struct uploaded_tsv
*) xmalloc (sizeof (struct uploaded_tsv
));
2689 memset (utsv
, 0, sizeof (struct uploaded_tsv
));
2691 utsv
->next
= *utsvp
;
2697 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
2699 struct uploaded_tsv
*next_one
;
2703 next_one
= (*utsvp
)->next
;
2709 /* Look for an existing tracepoint that seems similar enough to the
2710 uploaded one. Enablement isn't compared, because the user can
2711 toggle that freely, and may have done so in anticipation of the
2715 find_matching_tracepoint (struct uploaded_tp
*utp
)
2717 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
2719 struct breakpoint
*t
;
2720 struct bp_location
*loc
;
2722 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
2724 if (t
->type
== utp
->type
2725 && t
->step_count
== utp
->step
2726 && t
->pass_count
== utp
->pass
2727 /* FIXME also test conditionals and actions */
2730 /* Scan the locations for an address match. */
2731 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
2733 if (loc
->address
== utp
->addr
)
2741 /* Given a list of tracepoints uploaded from a target, attempt to
2742 match them up with existing tracepoints, and create new ones if not
2746 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
2748 struct uploaded_tp
*utp
;
2749 struct breakpoint
*t
;
2751 /* Look for GDB tracepoints that match up with our uploaded versions. */
2752 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
2754 t
= find_matching_tracepoint (utp
);
2756 printf_filtered (_("Assuming tracepoint %d is same as target's tracepoint %d at %s.\n"),
2757 t
->number
, utp
->number
, paddress (get_current_arch (), utp
->addr
));
2760 t
= create_tracepoint_from_upload (utp
);
2762 printf_filtered (_("Created tracepoint %d for target's tracepoint %d at %s.\n"),
2763 t
->number
, utp
->number
, paddress (get_current_arch (), utp
->addr
));
2765 printf_filtered (_("Failed to create tracepoint for target's tracepoint %d at %s, skipping it.\n"),
2766 utp
->number
, paddress (get_current_arch (), utp
->addr
));
2768 /* Whether found or created, record the number used by the
2769 target, to help with mapping target tracepoints back to their
2770 counterparts here. */
2772 t
->number_on_target
= utp
->number
;
2775 free_uploaded_tps (uploaded_tps
);
2778 /* Trace state variables don't have much to identify them beyond their
2779 name, so just use that to detect matches. */
2781 struct trace_state_variable
*
2782 find_matching_tsv (struct uploaded_tsv
*utsv
)
2787 return find_trace_state_variable (utsv
->name
);
2790 struct trace_state_variable
*
2791 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
2793 const char *namebase
;
2796 struct trace_state_variable
*tsv
;
2800 namebase
= utsv
->name
;
2801 sprintf (buf
, "%s", namebase
);
2806 sprintf (buf
, "%s_%d", namebase
, try_num
++);
2809 /* Fish for a name that is not in use. */
2810 /* (should check against all internal vars?) */
2811 while (find_trace_state_variable (buf
))
2812 sprintf (buf
, "%s_%d", namebase
, try_num
++);
2814 /* We have an available name, create the variable. */
2815 tsv
= create_trace_state_variable (xstrdup (buf
));
2816 tsv
->initial_value
= utsv
->initial_value
;
2817 tsv
->builtin
= utsv
->builtin
;
2822 /* Given a list of uploaded trace state variables, try to match them
2823 up with existing variables, or create additional ones. */
2826 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
2829 struct uploaded_tsv
*utsv
;
2830 struct trace_state_variable
*tsv
;
2833 /* Most likely some numbers will have to be reassigned as part of
2834 the merge, so clear them all in anticipation. */
2835 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2838 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
2840 tsv
= find_matching_tsv (utsv
);
2842 printf_filtered (_("Assuming trace state variable $%s is same as target's variable %d.\n"),
2843 tsv
->name
, utsv
->number
);
2846 tsv
= create_tsv_from_upload (utsv
);
2847 printf_filtered (_("Created trace state variable $%s for target's variable %d.\n"),
2848 tsv
->name
, utsv
->number
);
2850 /* Give precedence to numberings that come from the target. */
2852 tsv
->number
= utsv
->number
;
2855 /* Renumber everything that didn't get a target-assigned number. */
2857 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2858 if (tsv
->number
> highest
)
2859 highest
= tsv
->number
;
2862 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2863 if (tsv
->number
== 0)
2864 tsv
->number
= highest
++;
2866 free_uploaded_tsvs (uploaded_tsvs
);
2869 /* target tfile command */
2871 struct target_ops tfile_ops
;
2873 /* Fill in tfile_ops with its defined operations and properties. */
2875 #define TRACE_HEADER_SIZE 8
2877 char *trace_filename
;
2879 off_t trace_frames_offset
;
2882 int trace_regblock_size
;
2884 static void tfile_interp_line (char *line
,
2885 struct uploaded_tp
**utpp
,
2886 struct uploaded_tsv
**utsvp
);
2889 tfile_open (char *filename
, int from_tty
)
2892 struct cleanup
*old_chain
;
2895 char header
[TRACE_HEADER_SIZE
];
2896 char linebuf
[1000]; /* should be max remote packet size or so */
2898 int bytes
, i
, gotten
;
2899 struct trace_status
*ts
;
2900 struct uploaded_tp
*uploaded_tps
= NULL
;
2901 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
2903 target_preopen (from_tty
);
2905 error (_("No trace file specified."));
2907 filename
= tilde_expand (filename
);
2908 if (!IS_ABSOLUTE_PATH(filename
))
2910 temp
= concat (current_directory
, "/", filename
, (char *)NULL
);
2915 old_chain
= make_cleanup (xfree
, filename
);
2917 flags
= O_BINARY
| O_LARGEFILE
;
2919 scratch_chan
= open (filename
, flags
, 0);
2920 if (scratch_chan
< 0)
2921 perror_with_name (filename
);
2923 /* Looks semi-reasonable. Toss the old trace file and work on the new. */
2925 discard_cleanups (old_chain
); /* Don't free filename any more */
2926 unpush_target (&tfile_ops
);
2928 push_target (&tfile_ops
);
2930 trace_filename
= xstrdup (filename
);
2931 trace_fd
= scratch_chan
;
2934 /* Read the file header and test for validity. */
2935 gotten
= read (trace_fd
, &header
, TRACE_HEADER_SIZE
);
2937 perror_with_name (trace_filename
);
2938 else if (gotten
< TRACE_HEADER_SIZE
)
2939 error (_("Premature end of file while reading trace file"));
2941 bytes
+= TRACE_HEADER_SIZE
;
2942 if (!(header
[0] == 0x7f
2943 && (strncmp (header
+ 1, "TRACE0\n", 7) == 0)))
2944 error (_("File is not a valid trace file."));
2946 trace_regblock_size
= 0;
2947 ts
= current_trace_status ();
2948 /* We know we're working with a file. */
2950 /* Set defaults in case there is no status line. */
2951 ts
->running_known
= 0;
2952 ts
->stop_reason
= trace_stop_reason_unknown
;
2953 ts
->traceframe_count
= -1;
2954 ts
->buffer_free
= 0;
2956 /* Read through a section of newline-terminated lines that
2957 define things like tracepoints. */
2961 gotten
= read (trace_fd
, &byte
, 1);
2963 perror_with_name (trace_filename
);
2964 else if (gotten
< 1)
2965 error (_("Premature end of file while reading trace file"));
2970 /* Empty line marks end of the definition section. */
2975 tfile_interp_line (linebuf
, &uploaded_tps
, &uploaded_tsvs
);
2978 linebuf
[i
++] = byte
;
2980 error (_("Excessively long lines in trace file"));
2983 /* Add the file's tracepoints and variables into the current mix. */
2985 /* Get trace state variables first, they may be checked when parsing
2986 uploaded commands. */
2987 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
2989 merge_uploaded_tracepoints (&uploaded_tps
);
2991 /* Record the starting offset of the binary trace data. */
2992 trace_frames_offset
= bytes
;
2994 /* If we don't have a blocksize, we can't interpret the
2996 if (trace_regblock_size
== 0)
2997 error (_("No register block size recorded in trace file"));
2998 if (ts
->traceframe_count
<= 0)
3000 warning ("No traceframes present in this file.");
3004 #define TFILE_PID (1)
3005 inferior_appeared (current_inferior (), TFILE_PID
);
3006 inferior_ptid
= pid_to_ptid (TFILE_PID
);
3007 add_thread_silent (inferior_ptid
);
3009 post_create_inferior (&tfile_ops
, from_tty
);
3012 /* FIXME this will get defined in MI patch submission */
3013 tfind_1 (tfind_number
, 0, 0, 0, 0);
3017 /* Interpret the given line from the definitions part of the trace
3021 tfile_interp_line (char *line
,
3022 struct uploaded_tp
**utpp
, struct uploaded_tsv
**utsvp
)
3026 if (strncmp (p
, "R ", strlen ("R ")) == 0)
3029 trace_regblock_size
= strtol (p
, &p
, 16);
3031 else if (strncmp (p
, "status ", strlen ("status ")) == 0)
3033 p
+= strlen ("status ");
3034 parse_trace_status (p
, current_trace_status ());
3036 else if (strncmp (p
, "tp ", strlen ("tp ")) == 0)
3038 p
+= strlen ("tp ");
3039 parse_tracepoint_definition (p
, utpp
);
3041 else if (strncmp (p
, "tsv ", strlen ("tsv ")) == 0)
3043 p
+= strlen ("tsv ");
3044 parse_tsv_definition (p
, utsvp
);
3047 warning ("Ignoring trace file definition \"%s\"", line
);
3050 /* Parse the part of trace status syntax that is shared between
3051 the remote protocol and the trace file reader. */
3053 extern char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
3056 parse_trace_status (char *line
, struct trace_status
*ts
)
3058 char *p
= line
, *p1
, *p_temp
;
3061 ts
->running_known
= 1;
3062 ts
->running
= (*p
++ == '1');
3063 ts
->stop_reason
= trace_stop_reason_unknown
;
3064 ts
->traceframe_count
= -1;
3065 ts
->traceframes_created
= -1;
3066 ts
->buffer_free
= -1;
3067 ts
->buffer_size
= -1;
3071 p1
= strchr (p
, ':');
3073 error (_("Malformed trace status, at %s\n\
3074 Status line: '%s'\n"), p
, line
);
3075 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
3077 p
= unpack_varlen_hex (++p1
, &val
);
3078 ts
->stop_reason
= trace_buffer_full
;
3080 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
3082 p
= unpack_varlen_hex (++p1
, &val
);
3083 ts
->stop_reason
= trace_never_run
;
3085 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
], p1
- p
) == 0)
3087 p
= unpack_varlen_hex (++p1
, &val
);
3088 ts
->stop_reason
= tracepoint_passcount
;
3089 ts
->stopping_tracepoint
= val
;
3091 else if (strncmp (p
, stop_reason_names
[tstop_command
], p1
- p
) == 0)
3093 p
= unpack_varlen_hex (++p1
, &val
);
3094 ts
->stop_reason
= tstop_command
;
3096 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3098 p
= unpack_varlen_hex (++p1
, &val
);
3099 ts
->traceframe_count
= val
;
3101 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3103 p
= unpack_varlen_hex (++p1
, &val
);
3104 ts
->traceframes_created
= val
;
3106 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3108 p
= unpack_varlen_hex (++p1
, &val
);
3109 ts
->buffer_free
= val
;
3111 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3113 p
= unpack_varlen_hex (++p1
, &val
);
3114 ts
->buffer_size
= val
;
3118 /* Silently skip unknown optional info. */
3119 p_temp
= strchr (p1
+ 1, ';');
3123 /* Must be at the end. */
3129 /* Given a line of text defining a tracepoint or tracepoint action, parse
3130 it into an "uploaded tracepoint". */
3133 parse_tracepoint_definition (char *line
, struct uploaded_tp
**utpp
)
3137 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
;
3141 struct uploaded_tp
*utp
= NULL
;
3144 /* Both tracepoint and action definitions start with the same number
3145 and address sequence. */
3147 p
= unpack_varlen_hex (p
, &num
);
3148 p
++; /* skip a colon */
3149 p
= unpack_varlen_hex (p
, &addr
);
3150 p
++; /* skip a colon */
3153 enabled
= (*p
++ == 'E');
3154 p
++; /* skip a colon */
3155 p
= unpack_varlen_hex (p
, &step
);
3156 p
++; /* skip a colon */
3157 p
= unpack_varlen_hex (p
, &pass
);
3158 type
= bp_tracepoint
;
3160 /* Thumb through optional fields. */
3163 p
++; /* skip a colon */
3166 type
= bp_fast_tracepoint
;
3168 p
= unpack_varlen_hex (p
, &orig_size
);
3173 p
= unpack_varlen_hex (p
, &xlen
);
3174 p
++; /* skip a comma */
3175 cond
= (char *) xmalloc (2 * xlen
+ 1);
3176 strncpy (cond
, p
, 2 * xlen
);
3177 cond
[2 * xlen
] = '\0';
3181 warning ("Unrecognized char '%c' in tracepoint definition, skipping rest", *p
);
3183 utp
= get_uploaded_tp (num
, addr
, utpp
);
3185 utp
->enabled
= enabled
;
3190 else if (piece
== 'A')
3192 utp
= get_uploaded_tp (num
, addr
, utpp
);
3193 utp
->actions
[utp
->numactions
++] = xstrdup (p
);
3195 else if (piece
== 'S')
3197 utp
= get_uploaded_tp (num
, addr
, utpp
);
3198 utp
->step_actions
[utp
->num_step_actions
++] = xstrdup (p
);
3202 error ("Invalid tracepoint piece");
3206 /* Convert a textual description of a trace state variable into an
3210 parse_tsv_definition (char *line
, struct uploaded_tsv
**utsvp
)
3213 ULONGEST num
, initval
, builtin
;
3215 struct uploaded_tsv
*utsv
= NULL
;
3217 buf
= alloca (strlen (line
));
3220 p
= unpack_varlen_hex (p
, &num
);
3221 p
++; /* skip a colon */
3222 p
= unpack_varlen_hex (p
, &initval
);
3223 p
++; /* skip a colon */
3224 p
= unpack_varlen_hex (p
, &builtin
);
3225 p
++; /* skip a colon */
3226 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3229 utsv
= get_uploaded_tsv (num
, utsvp
);
3230 utsv
->initial_value
= initval
;
3231 utsv
->builtin
= builtin
;
3232 utsv
->name
= xstrdup (buf
);
3235 /* Close the trace file and generally clean up. */
3238 tfile_close (int quitting
)
3245 pid
= ptid_get_pid (inferior_ptid
);
3246 inferior_ptid
= null_ptid
; /* Avoid confusion from thread stuff */
3247 exit_inferior_silent (pid
);
3252 xfree (trace_filename
);
3256 tfile_files_info (struct target_ops
*t
)
3258 /* (it would be useful to mention the name of the file) */
3259 printf_filtered ("Looking at a trace file.\n");
3262 /* The trace status for a file is that tracing can never be run. */
3265 tfile_get_trace_status (struct trace_status
*ts
)
3267 /* Other bits of trace status were collected as part of opening the
3268 trace files, so nothing to do here. */
3273 /* Given the position of a traceframe in the file, figure out what
3274 address the frame was collected at. This would normally be the
3275 value of a collected PC register, but if not available, we
3279 tfile_get_traceframe_address (off_t tframe_offset
)
3283 struct breakpoint
*tp
;
3284 off_t saved_offset
= cur_offset
;
3287 /* FIXME dig pc out of collected registers */
3289 /* Fall back to using tracepoint address. */
3290 lseek (trace_fd
, tframe_offset
, SEEK_SET
);
3291 gotten
= read (trace_fd
, &tpnum
, 2);
3293 perror_with_name (trace_filename
);
3294 else if (gotten
< 2)
3295 error (_("Premature end of file while reading trace file"));
3297 tp
= get_tracepoint_by_number_on_target (tpnum
);
3298 /* FIXME this is a poor heuristic if multiple locations */
3300 addr
= tp
->loc
->address
;
3302 /* Restore our seek position. */
3303 cur_offset
= saved_offset
;
3304 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3308 /* Given a type of search and some parameters, scan the collection of
3309 traceframes in the file looking for a match. When found, return
3310 both the traceframe and tracepoint number, otherwise -1 for
3314 tfile_trace_find (enum trace_find_type type
, int num
,
3315 ULONGEST addr1
, ULONGEST addr2
, int *tpp
)
3318 int tfnum
= 0, found
= 0, gotten
;
3320 struct breakpoint
*tp
;
3321 off_t offset
, tframe_offset
;
3324 lseek (trace_fd
, trace_frames_offset
, SEEK_SET
);
3325 offset
= trace_frames_offset
;
3328 tframe_offset
= offset
;
3329 gotten
= read (trace_fd
, &tpnum
, 2);
3331 perror_with_name (trace_filename
);
3332 else if (gotten
< 2)
3333 error (_("Premature end of file while reading trace file"));
3337 gotten
= read (trace_fd
, &data_size
, 4);
3339 perror_with_name (trace_filename
);
3340 else if (gotten
< 4)
3341 error (_("Premature end of file while reading trace file"));
3350 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3351 if (tfaddr
== addr1
)
3355 tp
= get_tracepoint (num
);
3356 if (tp
&& tpnum
== tp
->number_on_target
)
3360 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3361 if (addr1
<= tfaddr
&& tfaddr
<= addr2
)
3365 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3366 if (!(addr1
<= tfaddr
&& tfaddr
<= addr2
))
3370 internal_error (__FILE__
, __LINE__
, _("unknown tfind type"));
3374 printf_filtered ("Found traceframe %d.\n", tfnum
);
3377 cur_offset
= offset
;
3378 cur_data_size
= data_size
;
3381 /* Skip past the traceframe's data. */
3382 lseek (trace_fd
, data_size
, SEEK_CUR
);
3383 offset
+= data_size
;
3384 /* Update our own count of traceframes. */
3387 /* Did not find what we were looking for. */
3393 /* Look for a block of saved registers in the traceframe, and get the
3394 requested register from it. */
3397 tfile_fetch_registers (struct target_ops
*ops
,
3398 struct regcache
*regcache
, int regno
)
3400 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3402 int i
, pos
, offset
, regn
, regsize
, gotten
;
3403 unsigned short mlen
;
3406 /* An uninitialized reg size says we're not going to be
3407 successful at getting register blocks. */
3408 if (!trace_regblock_size
)
3411 regs
= alloca (trace_regblock_size
);
3413 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3415 while (pos
< cur_data_size
)
3417 gotten
= read (trace_fd
, &block_type
, 1);
3419 perror_with_name (trace_filename
);
3420 else if (gotten
< 1)
3421 error (_("Premature end of file while reading trace file"));
3427 gotten
= read (trace_fd
, regs
, trace_regblock_size
);
3429 perror_with_name (trace_filename
);
3430 else if (gotten
< trace_regblock_size
)
3431 error (_("Premature end of file while reading trace file"));
3433 /* Assume the block is laid out in GDB register number order,
3434 each register with the size that it has in GDB. */
3436 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
3438 regsize
= register_size (gdbarch
, regn
);
3439 /* Make sure we stay within block bounds. */
3440 if (offset
+ regsize
>= trace_regblock_size
)
3442 if (!regcache_valid_p (regcache
, regn
))
3446 regcache_raw_supply (regcache
, regno
, regs
+ offset
);
3449 else if (regno
== -1)
3451 regcache_raw_supply (regcache
, regn
, regs
+ offset
);
3458 lseek (trace_fd
, 8, SEEK_CUR
);
3459 gotten
= read (trace_fd
, &mlen
, 2);
3461 perror_with_name (trace_filename
);
3462 else if (gotten
< 2)
3463 error (_("Premature end of file while reading trace file"));
3464 lseek (trace_fd
, mlen
, SEEK_CUR
);
3465 pos
+= (8 + 2 + mlen
);
3468 lseek (trace_fd
, 4 + 8, SEEK_CUR
);
3472 error ("Unknown block type '%c' (0x%x) in trace frame",
3473 block_type
, block_type
);
3480 tfile_xfer_partial (struct target_ops
*ops
, enum target_object object
,
3481 const char *annex
, gdb_byte
*readbuf
,
3482 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
3487 unsigned short mlen
;
3489 /* We're only doing regular memory for now. */
3490 if (object
!= TARGET_OBJECT_MEMORY
)
3493 if (readbuf
== NULL
)
3494 error ("tfile_xfer_partial: trace file is read-only");
3496 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3498 while (pos
< cur_data_size
)
3500 gotten
= read (trace_fd
, &block_type
, 1);
3502 perror_with_name (trace_filename
);
3503 else if (gotten
< 1)
3504 error (_("Premature end of file while reading trace file"));
3509 lseek (trace_fd
, trace_regblock_size
, SEEK_CUR
);
3510 pos
+= trace_regblock_size
;
3513 gotten
= read (trace_fd
, &maddr
, 8);
3515 perror_with_name (trace_filename
);
3516 else if (gotten
< 8)
3517 error (_("Premature end of file while reading trace file"));
3519 gotten
= read (trace_fd
, &mlen
, 2);
3521 perror_with_name (trace_filename
);
3522 else if (gotten
< 2)
3523 error (_("Premature end of file while reading trace file"));
3524 if (maddr
<= offset
&& (offset
+ len
) <= (maddr
+ mlen
))
3526 gotten
= read (trace_fd
, readbuf
, mlen
);
3528 perror_with_name (trace_filename
);
3529 else if (gotten
< mlen
)
3530 error (_("Premature end of file qwhile reading trace file"));
3534 lseek (trace_fd
, mlen
, SEEK_CUR
);
3535 pos
+= (8 + 2 + mlen
);
3538 lseek (trace_fd
, 4 + 8, SEEK_CUR
);
3542 error ("Unknown block type '%c' (0x%x) in traceframe",
3543 block_type
, block_type
);
3547 /* Indicate failure to find the requested memory block. */
3551 /* Iterate through the blocks of a trace frame, looking for a 'V'
3552 block with a matching tsv number. */
3555 tfile_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
3558 int pos
, vnum
, gotten
;
3559 unsigned short mlen
;
3561 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3563 while (pos
< cur_data_size
)
3565 gotten
= read (trace_fd
, &block_type
, 1);
3567 perror_with_name (trace_filename
);
3568 else if (gotten
< 1)
3569 error (_("Premature end of file while reading trace file"));
3574 lseek (trace_fd
, trace_regblock_size
, SEEK_CUR
);
3575 pos
+= trace_regblock_size
;
3578 lseek (trace_fd
, 8, SEEK_CUR
);
3579 gotten
= read (trace_fd
, &mlen
, 2);
3581 perror_with_name (trace_filename
);
3582 else if (gotten
< 2)
3583 error (_("Premature end of file while reading trace file"));
3584 lseek (trace_fd
, mlen
, SEEK_CUR
);
3585 pos
+= (8 + 2 + mlen
);
3588 gotten
= read (trace_fd
, &vnum
, 4);
3590 perror_with_name (trace_filename
);
3591 else if (gotten
< 4)
3592 error (_("Premature end of file while reading trace file"));
3595 gotten
= read (trace_fd
, val
, 8);
3597 perror_with_name (trace_filename
);
3598 else if (gotten
< 8)
3599 error (_("Premature end of file while reading trace file"));
3602 lseek (trace_fd
, 8, SEEK_CUR
);
3606 error ("Unknown block type '%c' (0x%x) in traceframe",
3607 block_type
, block_type
);
3611 /* Didn't find anything. */
3616 tfile_has_memory (struct target_ops
*ops
)
3622 tfile_has_stack (struct target_ops
*ops
)
3628 tfile_has_registers (struct target_ops
*ops
)
3634 init_tfile_ops (void)
3636 tfile_ops
.to_shortname
= "tfile";
3637 tfile_ops
.to_longname
= "Local trace dump file";
3639 "Use a trace file as a target. Specify the filename of the trace file.";
3640 tfile_ops
.to_open
= tfile_open
;
3641 tfile_ops
.to_close
= tfile_close
;
3642 tfile_ops
.to_fetch_registers
= tfile_fetch_registers
;
3643 tfile_ops
.to_xfer_partial
= tfile_xfer_partial
;
3644 tfile_ops
.to_files_info
= tfile_files_info
;
3645 tfile_ops
.to_get_trace_status
= tfile_get_trace_status
;
3646 tfile_ops
.to_trace_find
= tfile_trace_find
;
3647 tfile_ops
.to_get_trace_state_variable_value
= tfile_get_trace_state_variable_value
;
3648 /* core_stratum might seem more logical, but GDB doesn't like having
3649 more than one core_stratum vector. */
3650 tfile_ops
.to_stratum
= process_stratum
;
3651 tfile_ops
.to_has_memory
= tfile_has_memory
;
3652 tfile_ops
.to_has_stack
= tfile_has_stack
;
3653 tfile_ops
.to_has_registers
= tfile_has_registers
;
3654 tfile_ops
.to_magic
= OPS_MAGIC
;
3657 /* module initialization */
3659 _initialize_tracepoint (void)
3661 struct cmd_list_element
*c
;
3663 traceframe_number
= -1;
3664 tracepoint_number
= -1;
3666 if (tracepoint_list
.list
== NULL
)
3668 tracepoint_list
.listsize
= 128;
3669 tracepoint_list
.list
= xmalloc
3670 (tracepoint_list
.listsize
* sizeof (struct memrange
));
3672 if (tracepoint_list
.aexpr_list
== NULL
)
3674 tracepoint_list
.aexpr_listsize
= 128;
3675 tracepoint_list
.aexpr_list
= xmalloc
3676 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
3679 if (stepping_list
.list
== NULL
)
3681 stepping_list
.listsize
= 128;
3682 stepping_list
.list
= xmalloc
3683 (stepping_list
.listsize
* sizeof (struct memrange
));
3686 if (stepping_list
.aexpr_list
== NULL
)
3688 stepping_list
.aexpr_listsize
= 128;
3689 stepping_list
.aexpr_list
= xmalloc
3690 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
3693 add_info ("scope", scope_info
,
3694 _("List the variables local to a scope"));
3696 add_cmd ("tracepoints", class_trace
, NULL
,
3697 _("Tracing of program execution without stopping the program."),
3700 add_com ("tdump", class_trace
, trace_dump_command
,
3701 _("Print everything collected at the current tracepoint."));
3703 add_com ("tsave", class_trace
, trace_save_command
, _("\
3704 Save the trace data to a file.\n\
3705 Use the '-r' option to direct the target to save directly to the file,\n\
3706 using its own filesystem."));
3708 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
3709 Define a trace state variable.\n\
3710 Argument is a $-prefixed name, optionally followed\n\
3711 by '=' and an expression that sets the initial value\n\
3712 at the start of tracing."));
3713 set_cmd_completer (c
, expression_completer
);
3715 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
3716 Delete one or more trace state variables.\n\
3717 Arguments are the names of the variables to delete.\n\
3718 If no arguments are supplied, delete all variables."), &deletelist
);
3719 /* FIXME add a trace variable completer */
3721 add_info ("tvariables", tvariables_info
, _("\
3722 Status of trace state variables and their values.\n\
3725 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
3726 Select a trace frame;\n\
3727 No argument means forward by one frame; '-' means backward by one frame."),
3728 &tfindlist
, "tfind ", 1, &cmdlist
);
3730 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
3731 Select a trace frame whose PC is outside the given range (exclusive).\n\
3732 Usage: tfind outside addr1, addr2"),
3735 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
3736 Select a trace frame whose PC is in the given range (inclusive).\n\
3737 Usage: tfind range addr1,addr2"),
3740 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
3741 Select a trace frame by source line.\n\
3742 Argument can be a line number (with optional source file), \n\
3743 a function name, or '*' followed by an address.\n\
3744 Default argument is 'the next source line that was traced'."),
3747 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
3748 Select a trace frame by tracepoint number.\n\
3749 Default is the tracepoint for the current trace frame."),
3752 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
3753 Select a trace frame by PC.\n\
3754 Default is the current PC, or the PC of the current trace frame."),
3757 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
3758 Synonym for 'none'.\n\
3759 De-select any trace frame and resume 'live' debugging."),
3762 add_cmd ("none", class_trace
, trace_find_none_command
,
3763 _("De-select any trace frame and resume 'live' debugging."),
3766 add_cmd ("start", class_trace
, trace_find_start_command
,
3767 _("Select the first trace frame in the trace buffer."),
3770 add_com ("tstatus", class_trace
, trace_status_command
,
3771 _("Display the status of the current trace data collection."));
3773 add_com ("tstop", class_trace
, trace_stop_command
,
3774 _("Stop trace data collection."));
3776 add_com ("tstart", class_trace
, trace_start_command
,
3777 _("Start trace data collection."));
3779 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
3780 Ends a list of commands or actions.\n\
3781 Several GDB commands allow you to enter a list of commands or actions.\n\
3782 Entering \"end\" on a line by itself is the normal way to terminate\n\
3784 Note: the \"end\" command cannot be used at the gdb prompt."));
3786 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
3787 Specify single-stepping behavior at a tracepoint.\n\
3788 Argument is number of instructions to trace in single-step mode\n\
3789 following the tracepoint. This command is normally followed by\n\
3790 one or more \"collect\" commands, to specify what to collect\n\
3791 while single-stepping.\n\n\
3792 Note: this command can only be used in a tracepoint \"actions\" list."));
3794 add_com_alias ("ws", "while-stepping", class_alias
, 0);
3795 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
3797 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
3798 Specify one or more data items to be collected at a tracepoint.\n\
3799 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
3800 collect all data (variables, registers) referenced by that expression.\n\
3801 Also accepts the following special arguments:\n\
3802 $regs -- all registers.\n\
3803 $args -- all function arguments.\n\
3804 $locals -- all variables local to the block/function scope.\n\
3805 Note: this command can only be used in a tracepoint \"actions\" list."));
3807 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
3808 Specify one or more expressions to be evaluated at a tracepoint.\n\
3809 Accepts a comma-separated list of (one or more) expressions.\n\
3810 The result of each evaluation will be discarded.\n\
3811 Note: this command can only be used in a tracepoint \"actions\" list."));
3813 add_com ("actions", class_trace
, trace_actions_command
, _("\
3814 Specify the actions to be taken at a tracepoint.\n\
3815 Tracepoint actions may include collecting of specified data, \n\
3816 single-stepping, or enabling/disabling other tracepoints, \n\
3817 depending on target's capabilities."));
3819 default_collect
= xstrdup ("");
3820 add_setshow_string_cmd ("default-collect", class_trace
,
3821 &default_collect
, _("\
3822 Set the list of expressions to collect by default"), _("\
3823 Show the list of expressions to collect by default"), NULL
,
3825 &setlist
, &showlist
);
3827 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
3828 &disconnected_tracing
, _("\
3829 Set whether tracing continues after GDB disconnects."), _("\
3830 Show whether tracing continues after GDB disconnects."), _("\
3831 Use this to continue a tracing run even if GDB disconnects\n\
3832 or detaches from the target. You can reconnect later and look at\n\
3833 trace data collected in the meantime."),
3834 set_disconnected_tracing
,
3839 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
3840 &circular_trace_buffer
, _("\
3841 Set target's use of circular trace buffer."), _("\
3842 Show target's use of circular trace buffer."), _("\
3843 Use this to make the trace buffer into a circular buffer,\n\
3844 which will discard traceframes (oldest first) instead of filling\n\
3845 up and stopping the trace run."),
3846 set_circular_trace_buffer
,
3853 add_target (&tfile_ops
);