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 Tell target to clear any previous trace experiment.
1414 Walk the list of tracepoints, and send them (and their actions)
1415 to the target. If no errors,
1416 Tell target to start a new trace experiment. */
1419 trace_start_command (char *args
, int from_tty
)
1422 VEC(breakpoint_p
) *tp_vec
= NULL
;
1424 struct breakpoint
*t
;
1425 struct trace_state_variable
*tsv
;
1426 int any_downloaded
= 0;
1428 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1430 target_trace_init ();
1432 tp_vec
= all_tracepoints ();
1433 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1435 t
->number_on_target
= 0;
1436 target_download_tracepoint (t
);
1437 t
->number_on_target
= t
->number
;
1440 VEC_free (breakpoint_p
, tp_vec
);
1442 /* No point in tracing without any tracepoints... */
1443 if (!any_downloaded
)
1444 error ("No tracepoints downloaded, not starting trace");
1446 /* Send down all the trace state variables too. */
1447 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1449 target_download_trace_state_variable (tsv
);
1452 /* Tell target to treat text-like sections as transparent. */
1453 target_trace_set_readonly_regions ();
1454 /* Set some mode flags. */
1455 target_set_disconnected_tracing (disconnected_tracing
);
1456 target_set_circular_trace_buffer (circular_trace_buffer
);
1458 /* Now insert traps and begin collecting data. */
1459 target_trace_start ();
1461 /* Reset our local state. */
1462 set_traceframe_num (-1);
1463 set_tracepoint_num (-1);
1464 set_traceframe_context (NULL
);
1465 current_trace_status()->running
= 1;
1470 trace_stop_command (char *args
, int from_tty
)
1478 target_trace_stop ();
1479 /* should change in response to reply? */
1480 current_trace_status ()->running
= 0;
1483 /* tstatus command */
1485 trace_status_command (char *args
, int from_tty
)
1487 struct trace_status
*ts
= current_trace_status ();
1490 status
= target_get_trace_status (ts
);
1495 printf_filtered (_("Using a trace file.\n"));
1498 printf_filtered (_("Trace can not be run on this target.\n"));
1503 if (!ts
->running_known
)
1505 printf_filtered (_("Run/stop status is unknown.\n"));
1507 else if (ts
->running
)
1509 printf_filtered (_("Trace is running on the target.\n"));
1510 if (disconnected_tracing
)
1511 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1513 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1517 switch (ts
->stop_reason
)
1519 case trace_never_run
:
1520 printf_filtered (_("No trace has been run on the target.\n"));
1523 printf_filtered (_("Trace stopped by a tstop command.\n"));
1525 case trace_buffer_full
:
1526 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1528 case trace_disconnected
:
1529 printf_filtered (_("Trace stopped because of disconnection.\n"));
1531 case tracepoint_passcount
:
1532 /* FIXME account for number on target */
1533 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1534 ts
->stopping_tracepoint
);
1536 case trace_stop_reason_unknown
:
1537 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1540 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1546 if (ts
->traceframes_created
>= 0
1547 && ts
->traceframe_count
!= ts
->traceframes_created
)
1549 printf_filtered (_("Buffer contains %d trace frames (of %d created total).\n"),
1550 ts
->traceframe_count
, ts
->traceframes_created
);
1552 else if (ts
->traceframe_count
>= 0)
1554 printf_filtered (_("Collected %d trace frames.\n"),
1555 ts
->traceframe_count
);
1558 if (ts
->buffer_free
>= 0)
1560 if (ts
->buffer_size
>= 0)
1562 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1563 ts
->buffer_free
, ts
->buffer_size
);
1564 if (ts
->buffer_size
> 0)
1565 printf_filtered (_(" (%d%% full)"),
1566 ((int) ((((long long) (ts
->buffer_size
1567 - ts
->buffer_free
)) * 100)
1568 / ts
->buffer_size
)));
1569 printf_filtered (_(".\n"));
1572 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1576 /* Now report on what we're doing with tfind. */
1577 if (traceframe_number
>= 0)
1578 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1579 traceframe_number
, tracepoint_number
);
1581 printf_filtered (_("Not looking at any trace frame.\n"));
1585 disconnect_or_stop_tracing (int from_tty
)
1587 /* It can happen that the target that was tracing went away on its
1588 own, and we didn't notice. Get a status update, and if the
1589 current target doesn't even do tracing, then assume it's not
1591 if (target_get_trace_status (current_trace_status ()) < 0)
1592 current_trace_status ()->running
= 0;
1594 if (current_trace_status ()->running
&& from_tty
)
1596 int cont
= query (_("Trace is running. Continue tracing after detach? "));
1597 /* Note that we send the query result without affecting the
1598 user's setting of disconnected_tracing, so that the answer is
1600 send_disconnected_tracing_value (cont
);
1602 /* Also ensure that we do the equivalent of a tstop command if
1603 tracing is not to continue after the detach. */
1609 /* Worker function for the various flavors of the tfind command. */
1611 finish_tfind_command (enum trace_find_type type
, int num
,
1612 ULONGEST addr1
, ULONGEST addr2
,
1615 int target_frameno
= -1, target_tracept
= -1;
1616 struct frame_id old_frame_id
;
1618 struct breakpoint
*tp
;
1620 old_frame_id
= get_frame_id (get_current_frame ());
1622 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
1625 if (type
== tfind_number
1627 && target_frameno
== -1)
1629 /* We told the target to get out of tfind mode, and it did. */
1631 else if (target_frameno
== -1)
1633 /* A request for a non-existant trace frame has failed.
1634 Our response will be different, depending on FROM_TTY:
1636 If FROM_TTY is true, meaning that this command was
1637 typed interactively by the user, then give an error
1638 and DO NOT change the state of traceframe_number etc.
1640 However if FROM_TTY is false, meaning that we're either
1641 in a script, a loop, or a user-defined command, then
1642 DON'T give an error, but DO change the state of
1643 traceframe_number etc. to invalid.
1645 The rationalle is that if you typed the command, you
1646 might just have committed a typo or something, and you'd
1647 like to NOT lose your current debugging state. However
1648 if you're in a user-defined command or especially in a
1649 loop, then you need a way to detect that the command
1650 failed WITHOUT aborting. This allows you to write
1651 scripts that search thru the trace buffer until the end,
1652 and then continue on to do something else. */
1655 error (_("Target failed to find requested trace frame."));
1659 printf_filtered ("End of trace buffer.\n");
1660 #if 0 /* dubious now? */
1661 /* The following will not recurse, since it's
1663 trace_find_command ("-1", from_tty
);
1668 tp
= get_tracepoint_by_number_on_target (target_tracept
);
1670 reinit_frame_cache ();
1671 registers_changed ();
1672 target_dcache_invalidate ();
1673 set_traceframe_num (target_frameno
);
1674 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
1675 if (target_frameno
== -1)
1676 set_traceframe_context (NULL
);
1678 set_traceframe_context (get_current_frame ());
1680 /* If we're in nonstop mode and getting out of looking at trace
1681 frames, there won't be any current frame to go back to and
1684 && (has_stack_frames () || traceframe_number
>= 0))
1686 enum print_what print_what
;
1688 /* NOTE: in immitation of the step command, try to determine
1689 whether we have made a transition from one function to
1690 another. If so, we'll print the "stack frame" (ie. the new
1691 function and it's arguments) -- otherwise we'll just show the
1694 if (frame_id_eq (old_frame_id
,
1695 get_frame_id (get_current_frame ())))
1696 print_what
= SRC_LINE
;
1698 print_what
= SRC_AND_LOC
;
1700 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1705 /* trace_find_command takes a trace frame number n,
1706 sends "QTFrame:<n>" to the target,
1707 and accepts a reply that may contain several optional pieces
1708 of information: a frame number, a tracepoint number, and an
1709 indication of whether this is a trap frame or a stepping frame.
1711 The minimal response is just "OK" (which indicates that the
1712 target does not give us a frame number or a tracepoint number).
1713 Instead of that, the target may send us a string containing
1715 F<hexnum> (gives the selected frame number)
1716 T<hexnum> (gives the selected tracepoint number)
1721 trace_find_command (char *args
, int from_tty
)
1722 { /* this should only be called with a numeric argument */
1725 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1726 error ("May not look at trace frames while trace is running.");
1728 if (args
== 0 || *args
== 0)
1729 { /* TFIND with no args means find NEXT trace frame. */
1730 if (traceframe_number
== -1)
1731 frameno
= 0; /* "next" is first one */
1733 frameno
= traceframe_number
+ 1;
1735 else if (0 == strcmp (args
, "-"))
1737 if (traceframe_number
== -1)
1738 error (_("not debugging trace buffer"));
1739 else if (from_tty
&& traceframe_number
== 0)
1740 error (_("already at start of trace buffer"));
1742 frameno
= traceframe_number
- 1;
1744 /* A hack to work around eval's need for fp to have been collected. */
1745 else if (0 == strcmp (args
, "-1"))
1748 frameno
= parse_and_eval_long (args
);
1751 error (_("invalid input (%d is less than zero)"), frameno
);
1753 finish_tfind_command (tfind_number
, frameno
, 0, 0, from_tty
);
1758 trace_find_end_command (char *args
, int from_tty
)
1760 trace_find_command ("-1", from_tty
);
1765 trace_find_none_command (char *args
, int from_tty
)
1767 trace_find_command ("-1", from_tty
);
1772 trace_find_start_command (char *args
, int from_tty
)
1774 trace_find_command ("0", from_tty
);
1777 /* tfind pc command */
1779 trace_find_pc_command (char *args
, int from_tty
)
1784 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1785 error ("May not look at trace frames while trace is running.");
1787 if (args
== 0 || *args
== 0)
1788 pc
= regcache_read_pc (get_current_regcache ());
1790 pc
= parse_and_eval_address (args
);
1792 finish_tfind_command (tfind_pc
, 0, pc
, 0, from_tty
);
1795 /* tfind tracepoint command */
1797 trace_find_tracepoint_command (char *args
, int from_tty
)
1800 struct breakpoint
*tp
;
1802 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1803 error ("May not look at trace frames while trace is running.");
1805 if (args
== 0 || *args
== 0)
1807 if (tracepoint_number
== -1)
1808 error (_("No current tracepoint -- please supply an argument."));
1810 tdp
= tracepoint_number
; /* default is current TDP */
1813 tdp
= parse_and_eval_long (args
);
1815 /* If we have the tracepoint on hand, use the number that the
1816 target knows about (which may be different if we disconnected
1817 and reconnected). */
1818 tp
= get_tracepoint (tdp
);
1820 tdp
= tp
->number_on_target
;
1822 finish_tfind_command (tfind_tp
, tdp
, 0, 0, from_tty
);
1825 /* TFIND LINE command:
1827 This command will take a sourceline for argument, just like BREAK
1828 or TRACE (ie. anything that "decode_line_1" can handle).
1830 With no argument, this command will find the next trace frame
1831 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1834 trace_find_line_command (char *args
, int from_tty
)
1836 static CORE_ADDR start_pc
, end_pc
;
1837 struct symtabs_and_lines sals
;
1838 struct symtab_and_line sal
;
1839 struct cleanup
*old_chain
;
1840 char startpc_str
[40], endpc_str
[40];
1842 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1843 error ("May not look at trace frames while trace is running.");
1845 if (args
== 0 || *args
== 0)
1847 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1849 sals
.sals
= (struct symtab_and_line
*)
1850 xmalloc (sizeof (struct symtab_and_line
));
1855 sals
= decode_line_spec (args
, 1);
1859 old_chain
= make_cleanup (xfree
, sals
.sals
);
1860 if (sal
.symtab
== 0)
1862 printf_filtered ("TFIND: No line number information available");
1865 /* This is useful for "info line *0x7f34". If we can't
1866 tell the user about a source line, at least let them
1867 have the symbolic address. */
1868 printf_filtered (" for address ");
1870 print_address (get_current_arch (), sal
.pc
, gdb_stdout
);
1871 printf_filtered (";\n -- will attempt to find by PC. \n");
1875 printf_filtered (".\n");
1876 return; /* No line, no PC; what can we do? */
1879 else if (sal
.line
> 0
1880 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1882 if (start_pc
== end_pc
)
1884 printf_filtered ("Line %d of \"%s\"",
1885 sal
.line
, sal
.symtab
->filename
);
1887 printf_filtered (" is at address ");
1888 print_address (get_current_arch (), start_pc
, gdb_stdout
);
1890 printf_filtered (" but contains no code.\n");
1891 sal
= find_pc_line (start_pc
, 0);
1893 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
1894 && start_pc
!= end_pc
)
1895 printf_filtered ("Attempting to find line %d instead.\n",
1898 error (_("Cannot find a good line."));
1902 /* Is there any case in which we get here, and have an address
1903 which the user would want to see? If we have debugging
1904 symbols and no line numbers? */
1905 error (_("Line number %d is out of range for \"%s\"."),
1906 sal
.line
, sal
.symtab
->filename
);
1908 /* Find within range of stated line. */
1910 finish_tfind_command (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
1912 finish_tfind_command (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
1913 do_cleanups (old_chain
);
1916 /* tfind range command */
1918 trace_find_range_command (char *args
, int from_tty
)
1920 static CORE_ADDR start
, stop
;
1921 char start_str
[40], stop_str
[40];
1924 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1925 error ("May not look at trace frames while trace is running.");
1927 if (args
== 0 || *args
== 0)
1928 { /* XXX FIXME: what should default behavior be? */
1929 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1933 if (0 != (tmp
= strchr (args
, ',')))
1935 *tmp
++ = '\0'; /* terminate start address */
1936 while (isspace ((int) *tmp
))
1938 start
= parse_and_eval_address (args
);
1939 stop
= parse_and_eval_address (tmp
);
1942 { /* no explicit end address? */
1943 start
= parse_and_eval_address (args
);
1944 stop
= start
+ 1; /* ??? */
1947 finish_tfind_command (tfind_range
, 0, start
, stop
, from_tty
);
1950 /* tfind outside command */
1952 trace_find_outside_command (char *args
, int from_tty
)
1954 CORE_ADDR start
, stop
;
1955 char start_str
[40], stop_str
[40];
1958 if (current_trace_status ()->running
&& !current_trace_status ()->from_file
)
1959 error ("May not look at trace frames while trace is running.");
1961 if (args
== 0 || *args
== 0)
1962 { /* XXX FIXME: what should default behavior be? */
1963 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1967 if (0 != (tmp
= strchr (args
, ',')))
1969 *tmp
++ = '\0'; /* terminate start address */
1970 while (isspace ((int) *tmp
))
1972 start
= parse_and_eval_address (args
);
1973 stop
= parse_and_eval_address (tmp
);
1976 { /* no explicit end address? */
1977 start
= parse_and_eval_address (args
);
1978 stop
= start
+ 1; /* ??? */
1981 finish_tfind_command (tfind_outside
, 0, start
, stop
, from_tty
);
1984 /* info scope command: list the locals for a scope. */
1986 scope_info (char *args
, int from_tty
)
1988 struct symtabs_and_lines sals
;
1990 struct minimal_symbol
*msym
;
1991 struct block
*block
;
1992 char **canonical
, *symname
, *save_args
= args
;
1993 struct dict_iterator iter
;
1995 struct gdbarch
*gdbarch
;
1998 if (args
== 0 || *args
== 0)
1999 error (_("requires an argument (function, line or *addr) to define a scope"));
2001 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
2002 if (sals
.nelts
== 0)
2003 return; /* presumably decode_line_1 has already warned */
2005 /* Resolve line numbers to PC */
2006 resolve_sal_pc (&sals
.sals
[0]);
2007 block
= block_for_pc (sals
.sals
[0].pc
);
2011 QUIT
; /* allow user to bail out with ^C */
2012 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2014 QUIT
; /* allow user to bail out with ^C */
2016 printf_filtered ("Scope for %s:\n", save_args
);
2019 symname
= SYMBOL_PRINT_NAME (sym
);
2020 if (symname
== NULL
|| *symname
== '\0')
2021 continue; /* probably botched, certainly useless */
2023 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
2025 printf_filtered ("Symbol %s is ", symname
);
2026 switch (SYMBOL_CLASS (sym
))
2029 case LOC_UNDEF
: /* messed up symbol? */
2030 printf_filtered ("a bogus symbol, class %d.\n",
2031 SYMBOL_CLASS (sym
));
2032 count
--; /* don't count this one */
2035 printf_filtered ("a constant with value %ld (0x%lx)",
2036 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2038 case LOC_CONST_BYTES
:
2039 printf_filtered ("constant bytes: ");
2040 if (SYMBOL_TYPE (sym
))
2041 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2042 fprintf_filtered (gdb_stdout
, " %02x",
2043 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2046 printf_filtered ("in static storage at address ");
2047 printf_filtered ("%s", paddress (gdbarch
,
2048 SYMBOL_VALUE_ADDRESS (sym
)));
2051 /* GDBARCH is the architecture associated with the objfile
2052 the symbol is defined in; the target architecture may be
2053 different, and may provide additional registers. However,
2054 we do not know the target architecture at this point.
2055 We assume the objfile architecture will contain all the
2056 standard registers that occur in debug info in that
2058 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2060 if (SYMBOL_IS_ARGUMENT (sym
))
2061 printf_filtered ("an argument in register $%s",
2062 gdbarch_register_name (gdbarch
, regno
));
2064 printf_filtered ("a local variable in register $%s",
2065 gdbarch_register_name (gdbarch
, regno
));
2068 printf_filtered ("an argument at stack/frame offset %ld",
2069 SYMBOL_VALUE (sym
));
2072 printf_filtered ("a local variable at frame offset %ld",
2073 SYMBOL_VALUE (sym
));
2076 printf_filtered ("a reference argument at offset %ld",
2077 SYMBOL_VALUE (sym
));
2079 case LOC_REGPARM_ADDR
:
2080 /* Note comment at LOC_REGISTER. */
2081 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2082 printf_filtered ("the address of an argument, in register $%s",
2083 gdbarch_register_name (gdbarch
, regno
));
2086 printf_filtered ("a typedef.\n");
2089 printf_filtered ("a label at address ");
2090 printf_filtered ("%s", paddress (gdbarch
,
2091 SYMBOL_VALUE_ADDRESS (sym
)));
2094 printf_filtered ("a function at address ");
2095 printf_filtered ("%s",
2096 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2098 case LOC_UNRESOLVED
:
2099 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2102 printf_filtered ("Unresolved Static");
2105 printf_filtered ("static storage at address ");
2106 printf_filtered ("%s",
2107 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
2110 case LOC_OPTIMIZED_OUT
:
2111 printf_filtered ("optimized out.\n");
2114 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
2117 if (SYMBOL_TYPE (sym
))
2118 printf_filtered (", length %d.\n",
2119 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2121 if (BLOCK_FUNCTION (block
))
2124 block
= BLOCK_SUPERBLOCK (block
);
2127 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2131 /* worker function (cleanup) */
2133 replace_comma (void *data
)
2141 trace_dump_command (char *args
, int from_tty
)
2143 struct regcache
*regcache
;
2144 struct gdbarch
*gdbarch
;
2145 struct breakpoint
*t
;
2146 struct command_line
*action
;
2147 char *action_exp
, *next_comma
;
2148 struct cleanup
*old_cleanups
;
2149 int stepping_actions
= 0;
2150 int stepping_frame
= 0;
2151 struct bp_location
*loc
;
2153 if (tracepoint_number
== -1)
2155 warning (_("No current trace frame."));
2159 t
= get_tracepoint (tracepoint_number
);
2162 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2165 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2167 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2168 tracepoint_number
, traceframe_number
);
2170 /* The current frame is a trap frame if the frame PC is equal
2171 to the tracepoint PC. If not, then the current frame was
2172 collected during single-stepping. */
2174 regcache
= get_current_regcache ();
2175 gdbarch
= get_regcache_arch (regcache
);
2177 /* If the traceframe's address matches any of the tracepoint's
2178 locations, assume it is a direct hit rather than a while-stepping
2179 frame. (FIXME this is not reliable, should record each frame's
2182 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
2183 if (loc
->address
== regcache_read_pc (regcache
))
2186 for (action
= t
->commands
; action
; action
= action
->next
)
2188 struct cmd_list_element
*cmd
;
2190 QUIT
; /* allow user to bail out with ^C */
2191 action_exp
= action
->line
;
2192 while (isspace ((int) *action_exp
))
2195 /* The collection actions to be done while stepping are
2196 bracketed by the commands "while-stepping" and "end". */
2198 if (*action_exp
== '#') /* comment line */
2201 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2203 error (_("Bad action list item: %s"), action_exp
);
2205 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2206 stepping_actions
= 1;
2207 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2208 stepping_actions
= 0;
2209 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2211 /* Display the collected data.
2212 For the trap frame, display only what was collected at
2213 the trap. Likewise for stepping frames, display only
2214 what was collected while stepping. This means that the
2215 two boolean variables, STEPPING_FRAME and
2216 STEPPING_ACTIONS should be equal. */
2217 if (stepping_frame
== stepping_actions
)
2220 { /* repeat over a comma-separated list */
2221 QUIT
; /* allow user to bail out with ^C */
2222 if (*action_exp
== ',')
2224 while (isspace ((int) *action_exp
))
2227 next_comma
= strchr (action_exp
, ',');
2229 if (0 == strncasecmp (action_exp
, "$reg", 4))
2230 registers_info (NULL
, from_tty
);
2231 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2232 locals_info (NULL
, from_tty
);
2233 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2234 args_info (NULL
, from_tty
);
2239 make_cleanup (replace_comma
, next_comma
);
2242 printf_filtered ("%s = ", action_exp
);
2243 output_command (action_exp
, from_tty
);
2244 printf_filtered ("\n");
2248 action_exp
= next_comma
;
2250 while (action_exp
&& *action_exp
== ',');
2254 discard_cleanups (old_cleanups
);
2257 extern int trace_regblock_size
;
2260 trace_save_command (char *args
, int from_tty
)
2263 char *filename
= NULL
, *pathname
;
2264 int target_does_save
= 0;
2265 struct cleanup
*cleanup
;
2266 struct trace_status
*ts
= current_trace_status ();
2269 struct uploaded_tp
*uploaded_tps
= NULL
, *utp
;
2270 struct uploaded_tsv
*uploaded_tsvs
= NULL
, *utsv
;
2273 ULONGEST offset
= 0;
2274 #define MAX_TRACE_UPLOAD 2000
2275 gdb_byte buf
[MAX_TRACE_UPLOAD
];
2279 error_no_arg (_("file in which to save trace data"));
2281 argv
= gdb_buildargv (args
);
2282 make_cleanup_freeargv (argv
);
2284 for (; *argv
; ++argv
)
2286 if (strcmp (*argv
, "-r") == 0)
2287 target_does_save
= 1;
2288 else if (**argv
== '-')
2289 error (_("unknown option `%s'"), *argv
);
2295 error_no_arg (_("file in which to save trace data"));
2297 /* If the target is to save the data to a file on its own, then just
2298 send the command and be done with it. */
2299 if (target_does_save
)
2301 err
= target_save_trace_data (filename
);
2303 error (_("Target failed to save trace data to '%s'."),
2308 /* Get the trace status first before opening the file, so if the
2309 target is losing, we can get out without touching files. */
2310 status
= target_get_trace_status (ts
);
2312 pathname
= tilde_expand (args
);
2313 cleanup
= make_cleanup (xfree
, pathname
);
2315 fp
= fopen (pathname
, "w");
2317 error (_("Unable to open file '%s' for saving trace data (%s)"),
2318 args
, safe_strerror (errno
));
2319 make_cleanup_fclose (fp
);
2321 /* Write a file header, with a high-bit-set char to indicate a
2322 binary file, plus a hint as what this file is, and a version
2323 number in case of future needs. */
2324 written
= fwrite ("\x7fTRACE0\n", 8, 1, fp
);
2326 perror_with_name (pathname
);
2328 /* Write descriptive info. */
2330 /* Write out the size of a register block. */
2331 fprintf (fp
, "R %x\n", trace_regblock_size
);
2333 /* Write out status of the tracing run (aka "tstatus" info). */
2334 fprintf (fp
, "status %c;%s:%x",
2335 (ts
->running
? '1' : '0'),
2336 stop_reason_names
[ts
->stop_reason
], ts
->stopping_tracepoint
);
2337 if (ts
->traceframe_count
>= 0)
2338 fprintf (fp
, ";tframes:%x", ts
->traceframe_count
);
2339 if (ts
->traceframes_created
>= 0)
2340 fprintf (fp
, ";tcreated:%x", ts
->traceframes_created
);
2341 if (ts
->buffer_free
>= 0)
2342 fprintf (fp
, ";tfree:%x", ts
->buffer_free
);
2343 if (ts
->buffer_size
>= 0)
2344 fprintf (fp
, ";tsize:%x", ts
->buffer_size
);
2347 /* Note that we want to upload tracepoints and save those, rather
2348 than simply writing out the local ones, because the user may have
2349 changed tracepoints in GDB in preparation for a future tracing
2350 run, or maybe just mass-deleted all types of breakpoints as part
2351 of cleaning up. So as not to contaminate the session, leave the
2352 data in its uploaded form, don't make into real tracepoints. */
2354 /* Get trace state variables first, they may be checked when parsing
2355 uploaded commands. */
2357 target_upload_trace_state_variables (&uploaded_tsvs
);
2359 for (utsv
= uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
2365 buf
= (char *) xmalloc (strlen (utsv
->name
) * 2 + 1);
2366 bin2hex ((gdb_byte
*) (utsv
->name
), buf
, 0);
2369 fprintf (fp
, "tsv %x:%s:%x:%s\n",
2370 utsv
->number
, phex_nz (utsv
->initial_value
, 8),
2371 utsv
->builtin
, buf
);
2377 free_uploaded_tsvs (&uploaded_tsvs
);
2379 target_upload_tracepoints (&uploaded_tps
);
2381 for (utp
= uploaded_tps
; utp
; utp
= utp
->next
)
2383 fprintf (fp
, "tp T%x:%s:%c:%x:%x",
2384 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2385 (utp
->enabled
? 'E' : 'D'), utp
->step
, utp
->pass
);
2386 if (utp
->type
== bp_fast_tracepoint
)
2387 fprintf (fp
, ":F%x", utp
->orig_size
);
2389 fprintf (fp
, ":X%x,%s", (unsigned int) strlen (utp
->cond
) / 2,
2392 for (a
= 0; a
< utp
->numactions
; ++a
)
2393 fprintf (fp
, "tp A%x:%s:%s\n",
2394 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2396 for (a
= 0; a
< utp
->num_step_actions
; ++a
)
2397 fprintf (fp
, "tp S%x:%s:%s\n",
2398 utp
->number
, phex_nz (utp
->addr
, sizeof (utp
->addr
)),
2399 utp
->step_actions
[a
]);
2402 free_uploaded_tps (&uploaded_tps
);
2404 /* Mark the end of the definition section. */
2407 /* Get and write the trace data proper. We ask for big blocks, in
2408 the hopes of efficiency, but will take less if the target has
2409 packet size limitations or some such. */
2412 gotten
= target_get_raw_trace_data (buf
, offset
, MAX_TRACE_UPLOAD
);
2414 error (_("Failure to get requested trace buffer data"));
2415 /* No more data is forthcoming, we're done. */
2418 written
= fwrite (buf
, gotten
, 1, fp
);
2419 if (written
< gotten
)
2420 perror_with_name (pathname
);
2424 /* Mark the end of trace data. */
2425 written
= fwrite (&gotten
, 4, 1, fp
);
2427 perror_with_name (pathname
);
2429 do_cleanups (cleanup
);
2431 printf_filtered (_("Trace data saved to file '%s'.\n"), args
);
2434 /* Tell the target what to do with an ongoing tracing run if GDB
2435 disconnects for some reason. */
2438 send_disconnected_tracing_value (int value
)
2440 target_set_disconnected_tracing (value
);
2444 set_disconnected_tracing (char *args
, int from_tty
,
2445 struct cmd_list_element
*c
)
2447 send_disconnected_tracing_value (disconnected_tracing
);
2451 set_circular_trace_buffer (char *args
, int from_tty
,
2452 struct cmd_list_element
*c
)
2454 target_set_circular_trace_buffer (circular_trace_buffer
);
2457 /* Convert the memory pointed to by mem into hex, placing result in buf.
2458 * Return a pointer to the last char put in buf (null)
2459 * "stolen" from sparc-stub.c
2462 static const char hexchars
[] = "0123456789abcdef";
2465 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2473 *buf
++ = hexchars
[ch
>> 4];
2474 *buf
++ = hexchars
[ch
& 0xf];
2483 get_traceframe_number (void)
2485 return traceframe_number
;
2488 /* Make the traceframe NUM be the current trace frame. Does nothing
2489 if NUM is already current. */
2492 set_traceframe_number (int num
)
2496 if (traceframe_number
== num
)
2498 /* Nothing to do. */
2502 newnum
= target_trace_find (tfind_number
, num
, 0, 0, NULL
);
2505 warning (_("could not change traceframe"));
2507 traceframe_number
= newnum
;
2509 /* Changing the traceframe changes our view of registers and of the
2511 registers_changed ();
2514 /* A cleanup used when switching away and back from tfind mode. */
2516 struct current_traceframe_cleanup
2518 /* The traceframe we were inspecting. */
2519 int traceframe_number
;
2523 do_restore_current_traceframe_cleanup (void *arg
)
2525 struct current_traceframe_cleanup
*old
= arg
;
2527 set_traceframe_number (old
->traceframe_number
);
2531 restore_current_traceframe_cleanup_dtor (void *arg
)
2533 struct current_traceframe_cleanup
*old
= arg
;
2539 make_cleanup_restore_current_traceframe (void)
2541 struct current_traceframe_cleanup
*old
;
2543 old
= xmalloc (sizeof (struct current_traceframe_cleanup
));
2544 old
->traceframe_number
= traceframe_number
;
2546 return make_cleanup_dtor (do_restore_current_traceframe_cleanup
, old
,
2547 restore_current_traceframe_cleanup_dtor
);
2550 /* Given a number and address, return an uploaded tracepoint with that
2551 number, creating if necessary. */
2553 struct uploaded_tp
*
2554 get_uploaded_tp (int num
, ULONGEST addr
, struct uploaded_tp
**utpp
)
2556 struct uploaded_tp
*utp
;
2558 for (utp
= *utpp
; utp
; utp
= utp
->next
)
2559 if (utp
->number
== num
&& utp
->addr
== addr
)
2561 utp
= (struct uploaded_tp
*) xmalloc (sizeof (struct uploaded_tp
));
2562 memset (utp
, 0, sizeof (struct uploaded_tp
));
2571 free_uploaded_tps (struct uploaded_tp
**utpp
)
2573 struct uploaded_tp
*next_one
;
2577 next_one
= (*utpp
)->next
;
2583 /* Given a number and address, return an uploaded tracepoint with that
2584 number, creating if necessary. */
2586 struct uploaded_tsv
*
2587 get_uploaded_tsv (int num
, struct uploaded_tsv
**utsvp
)
2589 struct uploaded_tsv
*utsv
;
2591 for (utsv
= *utsvp
; utsv
; utsv
= utsv
->next
)
2592 if (utsv
->number
== num
)
2594 utsv
= (struct uploaded_tsv
*) xmalloc (sizeof (struct uploaded_tsv
));
2595 memset (utsv
, 0, sizeof (struct uploaded_tsv
));
2597 utsv
->next
= *utsvp
;
2603 free_uploaded_tsvs (struct uploaded_tsv
**utsvp
)
2605 struct uploaded_tsv
*next_one
;
2609 next_one
= (*utsvp
)->next
;
2615 /* Look for an existing tracepoint that seems similar enough to the
2616 uploaded one. Enablement isn't compared, because the user can
2617 toggle that freely, and may have done so in anticipation of the
2621 find_matching_tracepoint (struct uploaded_tp
*utp
)
2623 VEC(breakpoint_p
) *tp_vec
= all_tracepoints ();
2625 struct breakpoint
*t
;
2626 struct bp_location
*loc
;
2628 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
2630 if (t
->type
== utp
->type
2631 && t
->step_count
== utp
->step
2632 && t
->pass_count
== utp
->pass
2633 /* FIXME also test conditionals and actions */
2636 /* Scan the locations for an address match. */
2637 for (loc
= t
->loc
; loc
; loc
= loc
->next
)
2639 if (loc
->address
== utp
->addr
)
2647 /* Given a list of tracepoints uploaded from a target, attempt to
2648 match them up with existing tracepoints, and create new ones if not
2652 merge_uploaded_tracepoints (struct uploaded_tp
**uploaded_tps
)
2654 struct uploaded_tp
*utp
;
2655 struct breakpoint
*t
;
2657 /* Look for GDB tracepoints that match up with our uploaded versions. */
2658 for (utp
= *uploaded_tps
; utp
; utp
= utp
->next
)
2660 t
= find_matching_tracepoint (utp
);
2662 printf_filtered (_("Assuming tracepoint %d is same as target's tracepoint %d at %s.\n"),
2663 t
->number
, utp
->number
, paddress (get_current_arch (), utp
->addr
));
2666 t
= create_tracepoint_from_upload (utp
);
2668 printf_filtered (_("Created tracepoint %d for target's tracepoint %d at %s.\n"),
2669 t
->number
, utp
->number
, paddress (get_current_arch (), utp
->addr
));
2671 printf_filtered (_("Failed to create tracepoint for target's tracepoint %d at %s, skipping it.\n"),
2672 utp
->number
, paddress (get_current_arch (), utp
->addr
));
2674 /* Whether found or created, record the number used by the
2675 target, to help with mapping target tracepoints back to their
2676 counterparts here. */
2678 t
->number_on_target
= utp
->number
;
2681 free_uploaded_tps (uploaded_tps
);
2684 /* Trace state variables don't have much to identify them beyond their
2685 name, so just use that to detect matches. */
2687 struct trace_state_variable
*
2688 find_matching_tsv (struct uploaded_tsv
*utsv
)
2693 return find_trace_state_variable (utsv
->name
);
2696 struct trace_state_variable
*
2697 create_tsv_from_upload (struct uploaded_tsv
*utsv
)
2699 const char *namebase
;
2702 struct trace_state_variable
*tsv
;
2706 namebase
= utsv
->name
;
2707 sprintf (buf
, "%s", namebase
);
2712 sprintf (buf
, "%s_%d", namebase
, try_num
++);
2715 /* Fish for a name that is not in use. */
2716 /* (should check against all internal vars?) */
2717 while (find_trace_state_variable (buf
))
2718 sprintf (buf
, "%s_%d", namebase
, try_num
++);
2720 /* We have an available name, create the variable. */
2721 tsv
= create_trace_state_variable (xstrdup (buf
));
2722 tsv
->initial_value
= utsv
->initial_value
;
2723 tsv
->builtin
= utsv
->builtin
;
2728 /* Given a list of uploaded trace state variables, try to match them
2729 up with existing variables, or create additional ones. */
2732 merge_uploaded_trace_state_variables (struct uploaded_tsv
**uploaded_tsvs
)
2735 struct uploaded_tsv
*utsv
;
2736 struct trace_state_variable
*tsv
;
2739 /* Most likely some numbers will have to be reassigned as part of
2740 the merge, so clear them all in anticipation. */
2741 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2744 for (utsv
= *uploaded_tsvs
; utsv
; utsv
= utsv
->next
)
2746 tsv
= find_matching_tsv (utsv
);
2748 printf_filtered (_("Assuming trace state variable $%s is same as target's variable %d.\n"),
2749 tsv
->name
, utsv
->number
);
2752 tsv
= create_tsv_from_upload (utsv
);
2753 printf_filtered (_("Created trace state variable $%s for target's variable %d.\n"),
2754 tsv
->name
, utsv
->number
);
2756 /* Give precedence to numberings that come from the target. */
2758 tsv
->number
= utsv
->number
;
2761 /* Renumber everything that didn't get a target-assigned number. */
2763 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2764 if (tsv
->number
> highest
)
2765 highest
= tsv
->number
;
2768 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
2769 if (tsv
->number
== 0)
2770 tsv
->number
= highest
++;
2772 free_uploaded_tsvs (uploaded_tsvs
);
2775 /* target tfile command */
2777 struct target_ops tfile_ops
;
2779 /* Fill in tfile_ops with its defined operations and properties. */
2781 #define TRACE_HEADER_SIZE 8
2783 char *trace_filename
;
2785 off_t trace_frames_offset
;
2788 int trace_regblock_size
;
2790 static void tfile_interp_line (char *line
,
2791 struct uploaded_tp
**utpp
,
2792 struct uploaded_tsv
**utsvp
);
2795 tfile_open (char *filename
, int from_tty
)
2798 struct cleanup
*old_chain
;
2801 char header
[TRACE_HEADER_SIZE
];
2802 char linebuf
[1000]; /* should be max remote packet size or so */
2804 int bytes
, i
, gotten
;
2805 struct trace_status
*ts
;
2806 struct uploaded_tp
*uploaded_tps
= NULL
;
2807 struct uploaded_tsv
*uploaded_tsvs
= NULL
;
2809 target_preopen (from_tty
);
2811 error (_("No trace file specified."));
2813 filename
= tilde_expand (filename
);
2814 if (!IS_ABSOLUTE_PATH(filename
))
2816 temp
= concat (current_directory
, "/", filename
, (char *)NULL
);
2821 old_chain
= make_cleanup (xfree
, filename
);
2823 flags
= O_BINARY
| O_LARGEFILE
;
2825 scratch_chan
= open (filename
, flags
, 0);
2826 if (scratch_chan
< 0)
2827 perror_with_name (filename
);
2829 /* Looks semi-reasonable. Toss the old trace file and work on the new. */
2831 discard_cleanups (old_chain
); /* Don't free filename any more */
2832 unpush_target (&tfile_ops
);
2834 push_target (&tfile_ops
);
2836 trace_filename
= xstrdup (filename
);
2837 trace_fd
= scratch_chan
;
2840 /* Read the file header and test for validity. */
2841 gotten
= read (trace_fd
, &header
, TRACE_HEADER_SIZE
);
2843 perror_with_name (trace_filename
);
2844 else if (gotten
< TRACE_HEADER_SIZE
)
2845 error (_("Premature end of file while reading trace file"));
2847 bytes
+= TRACE_HEADER_SIZE
;
2848 if (!(header
[0] == 0x7f
2849 && (strncmp (header
+ 1, "TRACE0\n", 7) == 0)))
2850 error (_("File is not a valid trace file."));
2852 trace_regblock_size
= 0;
2853 ts
= current_trace_status ();
2854 /* We know we're working with a file. */
2856 /* Set defaults in case there is no status line. */
2857 ts
->running_known
= 0;
2858 ts
->stop_reason
= trace_stop_reason_unknown
;
2859 ts
->traceframe_count
= -1;
2860 ts
->buffer_free
= 0;
2862 /* Read through a section of newline-terminated lines that
2863 define things like tracepoints. */
2867 gotten
= read (trace_fd
, &byte
, 1);
2869 perror_with_name (trace_filename
);
2870 else if (gotten
< 1)
2871 error (_("Premature end of file while reading trace file"));
2876 /* Empty line marks end of the definition section. */
2881 tfile_interp_line (linebuf
, &uploaded_tps
, &uploaded_tsvs
);
2884 linebuf
[i
++] = byte
;
2886 error (_("Excessively long lines in trace file"));
2889 /* Add the file's tracepoints and variables into the current mix. */
2891 /* Get trace state variables first, they may be checked when parsing
2892 uploaded commands. */
2893 merge_uploaded_trace_state_variables (&uploaded_tsvs
);
2895 merge_uploaded_tracepoints (&uploaded_tps
);
2897 /* Record the starting offset of the binary trace data. */
2898 trace_frames_offset
= bytes
;
2900 /* If we don't have a blocksize, we can't interpret the
2902 if (trace_regblock_size
== 0)
2903 error (_("No register block size recorded in trace file"));
2904 if (ts
->traceframe_count
<= 0)
2906 warning ("No traceframes present in this file.");
2910 #define TFILE_PID (1)
2911 inferior_appeared (current_inferior (), TFILE_PID
);
2912 inferior_ptid
= pid_to_ptid (TFILE_PID
);
2913 add_thread_silent (inferior_ptid
);
2915 post_create_inferior (&tfile_ops
, from_tty
);
2918 /* FIXME this will get defined in MI patch submission */
2919 tfind_1 (tfind_number
, 0, 0, 0, 0);
2923 /* Interpret the given line from the definitions part of the trace
2927 tfile_interp_line (char *line
,
2928 struct uploaded_tp
**utpp
, struct uploaded_tsv
**utsvp
)
2932 if (strncmp (p
, "R ", strlen ("R ")) == 0)
2935 trace_regblock_size
= strtol (p
, &p
, 16);
2937 else if (strncmp (p
, "status ", strlen ("status ")) == 0)
2939 p
+= strlen ("status ");
2940 parse_trace_status (p
, current_trace_status ());
2942 else if (strncmp (p
, "tp ", strlen ("tp ")) == 0)
2944 p
+= strlen ("tp ");
2945 parse_tracepoint_definition (p
, utpp
);
2947 else if (strncmp (p
, "tsv ", strlen ("tsv ")) == 0)
2949 p
+= strlen ("tsv ");
2950 parse_tsv_definition (p
, utsvp
);
2953 warning ("Ignoring trace file definition \"%s\"", line
);
2956 /* Parse the part of trace status syntax that is shared between
2957 the remote protocol and the trace file reader. */
2959 extern char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
2962 parse_trace_status (char *line
, struct trace_status
*ts
)
2964 char *p
= line
, *p1
, *p_temp
;
2967 ts
->running_known
= 1;
2968 ts
->running
= (*p
++ == '1');
2969 ts
->stop_reason
= trace_stop_reason_unknown
;
2970 ts
->traceframe_count
= -1;
2971 ts
->traceframes_created
= -1;
2972 ts
->buffer_free
= -1;
2973 ts
->buffer_size
= -1;
2977 p1
= strchr (p
, ':');
2979 error (_("Malformed trace status, at %s\n\
2980 Status line: '%s'\n"), p
, line
);
2981 if (strncmp (p
, stop_reason_names
[trace_buffer_full
], p1
- p
) == 0)
2983 p
= unpack_varlen_hex (++p1
, &val
);
2984 ts
->stop_reason
= trace_buffer_full
;
2986 else if (strncmp (p
, stop_reason_names
[trace_never_run
], p1
- p
) == 0)
2988 p
= unpack_varlen_hex (++p1
, &val
);
2989 ts
->stop_reason
= trace_never_run
;
2991 else if (strncmp (p
, stop_reason_names
[tracepoint_passcount
], p1
- p
) == 0)
2993 p
= unpack_varlen_hex (++p1
, &val
);
2994 ts
->stop_reason
= tracepoint_passcount
;
2995 ts
->stopping_tracepoint
= val
;
2997 else if (strncmp (p
, stop_reason_names
[tstop_command
], p1
- p
) == 0)
2999 p
= unpack_varlen_hex (++p1
, &val
);
3000 ts
->stop_reason
= tstop_command
;
3002 else if (strncmp (p
, "tframes", p1
- p
) == 0)
3004 p
= unpack_varlen_hex (++p1
, &val
);
3005 ts
->traceframe_count
= val
;
3007 else if (strncmp (p
, "tcreated", p1
- p
) == 0)
3009 p
= unpack_varlen_hex (++p1
, &val
);
3010 ts
->traceframes_created
= val
;
3012 else if (strncmp (p
, "tfree", p1
- p
) == 0)
3014 p
= unpack_varlen_hex (++p1
, &val
);
3015 ts
->buffer_free
= val
;
3017 else if (strncmp (p
, "tsize", p1
- p
) == 0)
3019 p
= unpack_varlen_hex (++p1
, &val
);
3020 ts
->buffer_size
= val
;
3024 /* Silently skip unknown optional info. */
3025 p_temp
= strchr (p1
+ 1, ';');
3029 /* Must be at the end. */
3035 /* Given a line of text defining a tracepoint or tracepoint action, parse
3036 it into an "uploaded tracepoint". */
3039 parse_tracepoint_definition (char *line
, struct uploaded_tp
**utpp
)
3043 ULONGEST num
, addr
, step
, pass
, orig_size
, xlen
;
3047 struct uploaded_tp
*utp
= NULL
;
3050 /* Both tracepoint and action definitions start with the same number
3051 and address sequence. */
3053 p
= unpack_varlen_hex (p
, &num
);
3054 p
++; /* skip a colon */
3055 p
= unpack_varlen_hex (p
, &addr
);
3056 p
++; /* skip a colon */
3059 enabled
= (*p
++ == 'E');
3060 p
++; /* skip a colon */
3061 p
= unpack_varlen_hex (p
, &step
);
3062 p
++; /* skip a colon */
3063 p
= unpack_varlen_hex (p
, &pass
);
3064 type
= bp_tracepoint
;
3066 /* Thumb through optional fields. */
3069 p
++; /* skip a colon */
3072 type
= bp_fast_tracepoint
;
3074 p
= unpack_varlen_hex (p
, &orig_size
);
3079 p
= unpack_varlen_hex (p
, &xlen
);
3080 p
++; /* skip a comma */
3081 cond
= (char *) xmalloc (2 * xlen
+ 1);
3082 strncpy (cond
, p
, 2 * xlen
);
3083 cond
[2 * xlen
] = '\0';
3087 warning ("Unrecognized char '%c' in tracepoint definition, skipping rest", *p
);
3089 utp
= get_uploaded_tp (num
, addr
, utpp
);
3091 utp
->enabled
= enabled
;
3096 else if (piece
== 'A')
3098 utp
= get_uploaded_tp (num
, addr
, utpp
);
3099 utp
->actions
[utp
->numactions
++] = xstrdup (p
);
3101 else if (piece
== 'S')
3103 utp
= get_uploaded_tp (num
, addr
, utpp
);
3104 utp
->step_actions
[utp
->num_step_actions
++] = xstrdup (p
);
3108 error ("Invalid tracepoint piece");
3112 /* Convert a textual description of a trace state variable into an
3116 parse_tsv_definition (char *line
, struct uploaded_tsv
**utsvp
)
3119 ULONGEST num
, initval
, builtin
;
3121 struct uploaded_tsv
*utsv
= NULL
;
3123 buf
= alloca (strlen (line
));
3126 p
= unpack_varlen_hex (p
, &num
);
3127 p
++; /* skip a colon */
3128 p
= unpack_varlen_hex (p
, &initval
);
3129 p
++; /* skip a colon */
3130 p
= unpack_varlen_hex (p
, &builtin
);
3131 p
++; /* skip a colon */
3132 end
= hex2bin (p
, (gdb_byte
*) buf
, strlen (p
) / 2);
3135 utsv
= get_uploaded_tsv (num
, utsvp
);
3136 utsv
->initial_value
= initval
;
3137 utsv
->builtin
= builtin
;
3138 utsv
->name
= xstrdup (buf
);
3141 /* Close the trace file and generally clean up. */
3144 tfile_close (int quitting
)
3151 pid
= ptid_get_pid (inferior_ptid
);
3152 inferior_ptid
= null_ptid
; /* Avoid confusion from thread stuff */
3153 exit_inferior_silent (pid
);
3158 xfree (trace_filename
);
3162 tfile_files_info (struct target_ops
*t
)
3164 /* (it would be useful to mention the name of the file) */
3165 printf_filtered ("Looking at a trace file.\n");
3168 /* The trace status for a file is that tracing can never be run. */
3171 tfile_get_trace_status (struct trace_status
*ts
)
3173 /* Other bits of trace status were collected as part of opening the
3174 trace files, so nothing to do here. */
3179 /* Given the position of a traceframe in the file, figure out what
3180 address the frame was collected at. This would normally be the
3181 value of a collected PC register, but if not available, we
3185 tfile_get_traceframe_address (off_t tframe_offset
)
3189 struct breakpoint
*tp
;
3190 off_t saved_offset
= cur_offset
;
3193 /* FIXME dig pc out of collected registers */
3195 /* Fall back to using tracepoint address. */
3196 lseek (trace_fd
, tframe_offset
, SEEK_SET
);
3197 gotten
= read (trace_fd
, &tpnum
, 2);
3199 perror_with_name (trace_filename
);
3200 else if (gotten
< 2)
3201 error (_("Premature end of file while reading trace file"));
3203 tp
= get_tracepoint_by_number_on_target (tpnum
);
3204 /* FIXME this is a poor heuristic if multiple locations */
3206 addr
= tp
->loc
->address
;
3208 /* Restore our seek position. */
3209 cur_offset
= saved_offset
;
3210 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3214 /* Given a type of search and some parameters, scan the collection of
3215 traceframes in the file looking for a match. When found, return
3216 both the traceframe and tracepoint number, otherwise -1 for
3220 tfile_trace_find (enum trace_find_type type
, int num
,
3221 ULONGEST addr1
, ULONGEST addr2
, int *tpp
)
3224 int tfnum
= 0, found
= 0, gotten
;
3226 struct breakpoint
*tp
;
3227 off_t offset
, tframe_offset
;
3230 lseek (trace_fd
, trace_frames_offset
, SEEK_SET
);
3231 offset
= trace_frames_offset
;
3234 tframe_offset
= offset
;
3235 gotten
= read (trace_fd
, &tpnum
, 2);
3237 perror_with_name (trace_filename
);
3238 else if (gotten
< 2)
3239 error (_("Premature end of file while reading trace file"));
3243 gotten
= read (trace_fd
, &data_size
, 4);
3245 perror_with_name (trace_filename
);
3246 else if (gotten
< 4)
3247 error (_("Premature end of file while reading trace file"));
3256 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3257 if (tfaddr
== addr1
)
3261 tp
= get_tracepoint (num
);
3262 if (tp
&& tpnum
== tp
->number_on_target
)
3266 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3267 if (addr1
<= tfaddr
&& tfaddr
<= addr2
)
3271 tfaddr
= tfile_get_traceframe_address (tframe_offset
);
3272 if (!(addr1
<= tfaddr
&& tfaddr
<= addr2
))
3276 internal_error (__FILE__
, __LINE__
, _("unknown tfind type"));
3280 printf_filtered ("Found traceframe %d.\n", tfnum
);
3283 cur_offset
= offset
;
3284 cur_data_size
= data_size
;
3287 /* Skip past the traceframe's data. */
3288 lseek (trace_fd
, data_size
, SEEK_CUR
);
3289 offset
+= data_size
;
3290 /* Update our own count of traceframes. */
3293 /* Did not find what we were looking for. */
3299 /* Look for a block of saved registers in the traceframe, and get the
3300 requested register from it. */
3303 tfile_fetch_registers (struct target_ops
*ops
,
3304 struct regcache
*regcache
, int regno
)
3306 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3308 int i
, pos
, offset
, regn
, regsize
, gotten
;
3309 unsigned short mlen
;
3312 /* An uninitialized reg size says we're not going to be
3313 successful at getting register blocks. */
3314 if (!trace_regblock_size
)
3317 regs
= alloca (trace_regblock_size
);
3319 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3321 while (pos
< cur_data_size
)
3323 gotten
= read (trace_fd
, &block_type
, 1);
3325 perror_with_name (trace_filename
);
3326 else if (gotten
< 1)
3327 error (_("Premature end of file while reading trace file"));
3333 gotten
= read (trace_fd
, regs
, trace_regblock_size
);
3335 perror_with_name (trace_filename
);
3336 else if (gotten
< trace_regblock_size
)
3337 error (_("Premature end of file while reading trace file"));
3339 /* Assume the block is laid out in GDB register number order,
3340 each register with the size that it has in GDB. */
3342 for (regn
= 0; regn
< gdbarch_num_regs (gdbarch
); regn
++)
3344 regsize
= register_size (gdbarch
, regn
);
3345 /* Make sure we stay within block bounds. */
3346 if (offset
+ regsize
>= trace_regblock_size
)
3348 if (!regcache_valid_p (regcache
, regn
))
3352 regcache_raw_supply (regcache
, regno
, regs
+ offset
);
3355 else if (regno
== -1)
3357 regcache_raw_supply (regcache
, regn
, regs
+ offset
);
3364 lseek (trace_fd
, 8, SEEK_CUR
);
3365 gotten
= read (trace_fd
, &mlen
, 2);
3367 perror_with_name (trace_filename
);
3368 else if (gotten
< 2)
3369 error (_("Premature end of file while reading trace file"));
3370 lseek (trace_fd
, mlen
, SEEK_CUR
);
3371 pos
+= (8 + 2 + mlen
);
3374 lseek (trace_fd
, 4 + 8, SEEK_CUR
);
3378 error ("Unknown block type '%c' (0x%x) in trace frame",
3379 block_type
, block_type
);
3386 tfile_xfer_partial (struct target_ops
*ops
, enum target_object object
,
3387 const char *annex
, gdb_byte
*readbuf
,
3388 const gdb_byte
*writebuf
, ULONGEST offset
, LONGEST len
)
3393 unsigned short mlen
;
3395 /* We're only doing regular memory for now. */
3396 if (object
!= TARGET_OBJECT_MEMORY
)
3399 if (readbuf
== NULL
)
3400 error ("tfile_xfer_partial: trace file is read-only");
3402 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3404 while (pos
< cur_data_size
)
3406 gotten
= read (trace_fd
, &block_type
, 1);
3408 perror_with_name (trace_filename
);
3409 else if (gotten
< 1)
3410 error (_("Premature end of file while reading trace file"));
3415 lseek (trace_fd
, trace_regblock_size
, SEEK_CUR
);
3416 pos
+= trace_regblock_size
;
3419 gotten
= read (trace_fd
, &maddr
, 8);
3421 perror_with_name (trace_filename
);
3422 else if (gotten
< 8)
3423 error (_("Premature end of file while reading trace file"));
3425 gotten
= read (trace_fd
, &mlen
, 2);
3427 perror_with_name (trace_filename
);
3428 else if (gotten
< 2)
3429 error (_("Premature end of file while reading trace file"));
3430 if (maddr
<= offset
&& (offset
+ len
) <= (maddr
+ mlen
))
3432 gotten
= read (trace_fd
, readbuf
, mlen
);
3434 perror_with_name (trace_filename
);
3435 else if (gotten
< mlen
)
3436 error (_("Premature end of file qwhile reading trace file"));
3440 lseek (trace_fd
, mlen
, SEEK_CUR
);
3441 pos
+= (8 + 2 + mlen
);
3444 lseek (trace_fd
, 4 + 8, SEEK_CUR
);
3448 error ("Unknown block type '%c' (0x%x) in traceframe",
3449 block_type
, block_type
);
3453 /* Indicate failure to find the requested memory block. */
3457 /* Iterate through the blocks of a trace frame, looking for a 'V'
3458 block with a matching tsv number. */
3461 tfile_get_trace_state_variable_value (int tsvnum
, LONGEST
*val
)
3464 int pos
, vnum
, gotten
;
3465 unsigned short mlen
;
3467 lseek (trace_fd
, cur_offset
, SEEK_SET
);
3469 while (pos
< cur_data_size
)
3471 gotten
= read (trace_fd
, &block_type
, 1);
3473 perror_with_name (trace_filename
);
3474 else if (gotten
< 1)
3475 error (_("Premature end of file while reading trace file"));
3480 lseek (trace_fd
, trace_regblock_size
, SEEK_CUR
);
3481 pos
+= trace_regblock_size
;
3484 lseek (trace_fd
, 8, SEEK_CUR
);
3485 gotten
= read (trace_fd
, &mlen
, 2);
3487 perror_with_name (trace_filename
);
3488 else if (gotten
< 2)
3489 error (_("Premature end of file while reading trace file"));
3490 lseek (trace_fd
, mlen
, SEEK_CUR
);
3491 pos
+= (8 + 2 + mlen
);
3494 gotten
= read (trace_fd
, &vnum
, 4);
3496 perror_with_name (trace_filename
);
3497 else if (gotten
< 4)
3498 error (_("Premature end of file while reading trace file"));
3501 gotten
= read (trace_fd
, val
, 8);
3503 perror_with_name (trace_filename
);
3504 else if (gotten
< 8)
3505 error (_("Premature end of file while reading trace file"));
3508 lseek (trace_fd
, 8, SEEK_CUR
);
3512 error ("Unknown block type '%c' (0x%x) in traceframe",
3513 block_type
, block_type
);
3517 /* Didn't find anything. */
3522 tfile_has_memory (struct target_ops
*ops
)
3528 tfile_has_stack (struct target_ops
*ops
)
3534 tfile_has_registers (struct target_ops
*ops
)
3540 init_tfile_ops (void)
3542 tfile_ops
.to_shortname
= "tfile";
3543 tfile_ops
.to_longname
= "Local trace dump file";
3545 "Use a trace file as a target. Specify the filename of the trace file.";
3546 tfile_ops
.to_open
= tfile_open
;
3547 tfile_ops
.to_close
= tfile_close
;
3548 tfile_ops
.to_fetch_registers
= tfile_fetch_registers
;
3549 tfile_ops
.to_xfer_partial
= tfile_xfer_partial
;
3550 tfile_ops
.to_files_info
= tfile_files_info
;
3551 tfile_ops
.to_get_trace_status
= tfile_get_trace_status
;
3552 tfile_ops
.to_trace_find
= tfile_trace_find
;
3553 tfile_ops
.to_get_trace_state_variable_value
= tfile_get_trace_state_variable_value
;
3554 /* core_stratum might seem more logical, but GDB doesn't like having
3555 more than one core_stratum vector. */
3556 tfile_ops
.to_stratum
= process_stratum
;
3557 tfile_ops
.to_has_memory
= tfile_has_memory
;
3558 tfile_ops
.to_has_stack
= tfile_has_stack
;
3559 tfile_ops
.to_has_registers
= tfile_has_registers
;
3560 tfile_ops
.to_magic
= OPS_MAGIC
;
3563 /* module initialization */
3565 _initialize_tracepoint (void)
3567 struct cmd_list_element
*c
;
3569 traceframe_number
= -1;
3570 tracepoint_number
= -1;
3572 if (tracepoint_list
.list
== NULL
)
3574 tracepoint_list
.listsize
= 128;
3575 tracepoint_list
.list
= xmalloc
3576 (tracepoint_list
.listsize
* sizeof (struct memrange
));
3578 if (tracepoint_list
.aexpr_list
== NULL
)
3580 tracepoint_list
.aexpr_listsize
= 128;
3581 tracepoint_list
.aexpr_list
= xmalloc
3582 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
3585 if (stepping_list
.list
== NULL
)
3587 stepping_list
.listsize
= 128;
3588 stepping_list
.list
= xmalloc
3589 (stepping_list
.listsize
* sizeof (struct memrange
));
3592 if (stepping_list
.aexpr_list
== NULL
)
3594 stepping_list
.aexpr_listsize
= 128;
3595 stepping_list
.aexpr_list
= xmalloc
3596 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
3599 add_info ("scope", scope_info
,
3600 _("List the variables local to a scope"));
3602 add_cmd ("tracepoints", class_trace
, NULL
,
3603 _("Tracing of program execution without stopping the program."),
3606 add_com ("tdump", class_trace
, trace_dump_command
,
3607 _("Print everything collected at the current tracepoint."));
3609 add_com ("tsave", class_trace
, trace_save_command
, _("\
3610 Save the trace data to a file.\n\
3611 Use the '-r' option to direct the target to save directly to the file,\n\
3612 using its own filesystem."));
3614 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
3615 Define a trace state variable.\n\
3616 Argument is a $-prefixed name, optionally followed\n\
3617 by '=' and an expression that sets the initial value\n\
3618 at the start of tracing."));
3619 set_cmd_completer (c
, expression_completer
);
3621 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
3622 Delete one or more trace state variables.\n\
3623 Arguments are the names of the variables to delete.\n\
3624 If no arguments are supplied, delete all variables."), &deletelist
);
3625 /* FIXME add a trace variable completer */
3627 add_info ("tvariables", tvariables_info
, _("\
3628 Status of trace state variables and their values.\n\
3631 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
3632 Select a trace frame;\n\
3633 No argument means forward by one frame; '-' means backward by one frame."),
3634 &tfindlist
, "tfind ", 1, &cmdlist
);
3636 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
3637 Select a trace frame whose PC is outside the given range (exclusive).\n\
3638 Usage: tfind outside addr1, addr2"),
3641 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
3642 Select a trace frame whose PC is in the given range (inclusive).\n\
3643 Usage: tfind range addr1,addr2"),
3646 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
3647 Select a trace frame by source line.\n\
3648 Argument can be a line number (with optional source file), \n\
3649 a function name, or '*' followed by an address.\n\
3650 Default argument is 'the next source line that was traced'."),
3653 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
3654 Select a trace frame by tracepoint number.\n\
3655 Default is the tracepoint for the current trace frame."),
3658 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
3659 Select a trace frame by PC.\n\
3660 Default is the current PC, or the PC of the current trace frame."),
3663 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
3664 Synonym for 'none'.\n\
3665 De-select any trace frame and resume 'live' debugging."),
3668 add_cmd ("none", class_trace
, trace_find_none_command
,
3669 _("De-select any trace frame and resume 'live' debugging."),
3672 add_cmd ("start", class_trace
, trace_find_start_command
,
3673 _("Select the first trace frame in the trace buffer."),
3676 add_com ("tstatus", class_trace
, trace_status_command
,
3677 _("Display the status of the current trace data collection."));
3679 add_com ("tstop", class_trace
, trace_stop_command
,
3680 _("Stop trace data collection."));
3682 add_com ("tstart", class_trace
, trace_start_command
,
3683 _("Start trace data collection."));
3685 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
3686 Ends a list of commands or actions.\n\
3687 Several GDB commands allow you to enter a list of commands or actions.\n\
3688 Entering \"end\" on a line by itself is the normal way to terminate\n\
3690 Note: the \"end\" command cannot be used at the gdb prompt."));
3692 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
3693 Specify single-stepping behavior at a tracepoint.\n\
3694 Argument is number of instructions to trace in single-step mode\n\
3695 following the tracepoint. This command is normally followed by\n\
3696 one or more \"collect\" commands, to specify what to collect\n\
3697 while single-stepping.\n\n\
3698 Note: this command can only be used in a tracepoint \"actions\" list."));
3700 add_com_alias ("ws", "while-stepping", class_alias
, 0);
3701 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
3703 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
3704 Specify one or more data items to be collected at a tracepoint.\n\
3705 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
3706 collect all data (variables, registers) referenced by that expression.\n\
3707 Also accepts the following special arguments:\n\
3708 $regs -- all registers.\n\
3709 $args -- all function arguments.\n\
3710 $locals -- all variables local to the block/function scope.\n\
3711 Note: this command can only be used in a tracepoint \"actions\" list."));
3713 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
3714 Specify one or more expressions to be evaluated at a tracepoint.\n\
3715 Accepts a comma-separated list of (one or more) expressions.\n\
3716 The result of each evaluation will be discarded.\n\
3717 Note: this command can only be used in a tracepoint \"actions\" list."));
3719 add_com ("actions", class_trace
, trace_actions_command
, _("\
3720 Specify the actions to be taken at a tracepoint.\n\
3721 Tracepoint actions may include collecting of specified data, \n\
3722 single-stepping, or enabling/disabling other tracepoints, \n\
3723 depending on target's capabilities."));
3725 default_collect
= xstrdup ("");
3726 add_setshow_string_cmd ("default-collect", class_trace
,
3727 &default_collect
, _("\
3728 Set the list of expressions to collect by default"), _("\
3729 Show the list of expressions to collect by default"), NULL
,
3731 &setlist
, &showlist
);
3733 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
3734 &disconnected_tracing
, _("\
3735 Set whether tracing continues after GDB disconnects."), _("\
3736 Show whether tracing continues after GDB disconnects."), _("\
3737 Use this to continue a tracing run even if GDB disconnects\n\
3738 or detaches from the target. You can reconnect later and look at\n\
3739 trace data collected in the meantime."),
3740 set_disconnected_tracing
,
3745 add_setshow_boolean_cmd ("circular-trace-buffer", no_class
,
3746 &circular_trace_buffer
, _("\
3747 Set target's use of circular trace buffer."), _("\
3748 Show target's use of circular trace buffer."), _("\
3749 Use this to make the trace buffer into a circular buffer,\n\
3750 which will discard traceframes (oldest first) instead of filling\n\
3751 up and stopping the trace run."),
3752 set_circular_trace_buffer
,
3759 add_target (&tfile_ops
);