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"
50 /* readline include files */
51 #include "readline/readline.h"
52 #include "readline/history.h"
54 /* readline defines this. */
61 extern void stop_tracing ();
63 /* Maximum length of an agent aexpression.
64 This accounts for the fact that packets are limited to 400 bytes
65 (which includes everything -- including the checksum), and assumes
66 the worst case of maximum length for each of the pieces of a
69 NOTE: expressions get mem2hex'ed otherwise this would be twice as
70 large. (400 - 31)/2 == 184 */
71 #define MAX_AGENT_EXPR_LEN 184
73 /* A hook used to notify the UI of tracepoint operations. */
75 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
76 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
78 extern void (*deprecated_readline_begin_hook
) (char *, ...);
79 extern char *(*deprecated_readline_hook
) (char *);
80 extern void (*deprecated_readline_end_hook
) (void);
82 /* GDB commands implemented in other modules:
85 extern void output_command (char *, int);
90 This module defines the following debugger commands:
91 trace : set a tracepoint on a function, line, or address.
92 info trace : list all debugger-defined tracepoints.
93 delete trace : delete one or more tracepoints.
94 enable trace : enable one or more tracepoints.
95 disable trace : disable one or more tracepoints.
96 actions : specify actions to be taken at a tracepoint.
97 passcount : specify a pass count for a tracepoint.
98 tstart : start a trace experiment.
99 tstop : stop a trace experiment.
100 tstatus : query the status of a trace experiment.
101 tfind : find a trace frame in the trace buffer.
102 tdump : print everything collected at the current tracepoint.
103 save-tracepoints : write tracepoint setup into a file.
105 This module defines the following user-visible debugger variables:
106 $trace_frame : sequence number of trace frame currently being debugged.
107 $trace_line : source line of trace frame currently being debugged.
108 $trace_file : source file of trace frame currently being debugged.
109 $tracepoint : tracepoint number of trace frame currently being debugged.
113 /* ======= Important global variables: ======= */
115 /* The list of all trace state variables. We don't retain pointers to
116 any of these for any reason - API is by name or number only - so it
117 works to have a vector of objects. */
119 typedef struct trace_state_variable tsv_s
;
122 static VEC(tsv_s
) *tvariables
;
124 /* The next integer to assign to a variable. */
126 static int next_tsv_number
= 1;
128 /* Number of last traceframe collected. */
129 static int traceframe_number
;
131 /* Tracepoint for last traceframe collected. */
132 static int tracepoint_number
;
134 /* Symbol for function for last traceframe collected */
135 static struct symbol
*traceframe_fun
;
137 /* Symtab and line for last traceframe collected */
138 static struct symtab_and_line traceframe_sal
;
140 /* Tracing command lists */
141 static struct cmd_list_element
*tfindlist
;
143 /* List of expressions to collect by default at each tracepoint hit. */
144 char *default_collect
= "";
146 static int disconnected_tracing
;
148 /* ======= Important command functions: ======= */
149 static void trace_actions_command (char *, int);
150 static void trace_start_command (char *, int);
151 static void trace_stop_command (char *, int);
152 static void trace_status_command (char *, int);
153 static void trace_find_command (char *, int);
154 static void trace_find_pc_command (char *, int);
155 static void trace_find_tracepoint_command (char *, int);
156 static void trace_find_line_command (char *, int);
157 static void trace_find_range_command (char *, int);
158 static void trace_find_outside_command (char *, int);
159 static void tracepoint_save_command (char *, int);
160 static void trace_dump_command (char *, int);
162 /* support routines */
164 struct collection_list
;
165 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
166 static char *mem2hex (gdb_byte
*, char *, int);
167 static void add_register (struct collection_list
*collection
,
169 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
171 extern void send_disconnected_tracing_value (int value
);
173 extern void _initialize_tracepoint (void);
175 /* Set traceframe number to NUM. */
177 set_traceframe_num (int num
)
179 traceframe_number
= num
;
180 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
183 /* Set tracepoint number to NUM. */
185 set_tracepoint_num (int num
)
187 tracepoint_number
= num
;
188 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
191 /* Set externally visible debug variables for querying/printing
192 the traceframe context (line, function, file) */
195 set_traceframe_context (struct frame_info
*trace_frame
)
199 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
202 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
203 traceframe_sal
.symtab
= NULL
;
204 clear_internalvar (lookup_internalvar ("trace_func"));
205 clear_internalvar (lookup_internalvar ("trace_file"));
206 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
210 /* Save as globals for internal use. */
211 trace_pc
= get_frame_pc (trace_frame
);
212 traceframe_sal
= find_pc_line (trace_pc
, 0);
213 traceframe_fun
= find_pc_function (trace_pc
);
215 /* Save linenumber as "$trace_line", a debugger variable visible to
217 set_internalvar_integer (lookup_internalvar ("trace_line"),
218 traceframe_sal
.line
);
220 /* Save func name as "$trace_func", a debugger variable visible to
222 if (traceframe_fun
== NULL
223 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
224 clear_internalvar (lookup_internalvar ("trace_func"));
226 set_internalvar_string (lookup_internalvar ("trace_func"),
227 SYMBOL_LINKAGE_NAME (traceframe_fun
));
229 /* Save file name as "$trace_file", a debugger variable visible to
231 if (traceframe_sal
.symtab
== NULL
232 || traceframe_sal
.symtab
->filename
== NULL
)
233 clear_internalvar (lookup_internalvar ("trace_file"));
235 set_internalvar_string (lookup_internalvar ("trace_file"),
236 traceframe_sal
.symtab
->filename
);
239 /* Create a new trace state variable with the given name. */
241 struct trace_state_variable
*
242 create_trace_state_variable (const char *name
)
244 struct trace_state_variable tsv
;
246 memset (&tsv
, 0, sizeof (tsv
));
248 tsv
.number
= next_tsv_number
++;
249 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
252 /* Look for a trace state variable of the given name. */
254 struct trace_state_variable
*
255 find_trace_state_variable (const char *name
)
257 struct trace_state_variable
*tsv
;
260 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
261 if (strcmp (name
, tsv
->name
) == 0)
268 delete_trace_state_variable (const char *name
)
270 struct trace_state_variable
*tsv
;
273 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
274 if (strcmp (name
, tsv
->name
) == 0)
276 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
280 warning (_("No trace variable named \"$%s\", not deleting"), name
);
283 /* The 'tvariable' command collects a name and optional expression to
284 evaluate into an initial value. */
287 trace_variable_command (char *args
, int from_tty
)
289 struct expression
*expr
;
290 struct cleanup
*old_chain
;
291 struct internalvar
*intvar
= NULL
;
293 struct trace_state_variable
*tsv
;
296 error_no_arg (_("trace state variable name"));
298 /* All the possible valid arguments are expressions. */
299 expr
= parse_expression (args
);
300 old_chain
= make_cleanup (free_current_contents
, &expr
);
302 if (expr
->nelts
== 0)
303 error (_("No expression?"));
305 /* Only allow two syntaxes; "$name" and "$name=value". */
306 if (expr
->elts
[0].opcode
== OP_INTERNALVAR
)
308 intvar
= expr
->elts
[1].internalvar
;
310 else if (expr
->elts
[0].opcode
== BINOP_ASSIGN
311 && expr
->elts
[1].opcode
== OP_INTERNALVAR
)
313 intvar
= expr
->elts
[2].internalvar
;
314 initval
= value_as_long (evaluate_subexpression_type (expr
, 4));
317 error (_("Syntax must be $NAME [ = EXPR ]"));
320 error (_("No name given"));
322 if (strlen (internalvar_name (intvar
)) <= 0)
323 error (_("Must supply a non-empty variable name"));
325 /* If the variable already exists, just change its initial value. */
326 tsv
= find_trace_state_variable (internalvar_name (intvar
));
329 tsv
->initial_value
= initval
;
330 printf_filtered (_("Trace state variable $%s now has initial value %s.\n"),
331 tsv
->name
, plongest (tsv
->initial_value
));
335 /* Create a new variable. */
336 tsv
= create_trace_state_variable (internalvar_name (intvar
));
337 tsv
->initial_value
= initval
;
339 printf_filtered (_("Trace state variable $%s created, with initial value %s.\n"),
340 tsv
->name
, plongest (tsv
->initial_value
));
342 do_cleanups (old_chain
);
346 delete_trace_variable_command (char *args
, int from_tty
)
350 struct cleanup
*back_to
;
351 struct trace_state_variable
*tsv
;
355 if (query (_("Delete all trace state variables? ")))
356 VEC_free (tsv_s
, tvariables
);
361 argv
= gdb_buildargv (args
);
362 back_to
= make_cleanup_freeargv (argv
);
364 for (i
= 0; argv
[i
] != NULL
; i
++)
367 delete_trace_state_variable (argv
[i
] + 1);
369 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv
[i
]);
372 do_cleanups (back_to
);
377 /* List all the trace state variables. */
380 tvariables_info (char *args
, int from_tty
)
382 struct trace_state_variable
*tsv
;
387 if (VEC_length (tsv_s
, tvariables
) == 0)
389 printf_filtered (_("No trace state variables.\n"));
393 /* Try to acquire values from the target. */
394 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
395 tsv
->value_known
= target_get_trace_state_variable_value (tsv
->number
,
398 printf_filtered (_("Name\t\t Initial\tCurrent\n"));
400 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
402 printf_filtered ("$%s", tsv
->name
);
403 print_spaces_filtered (17 - strlen (tsv
->name
), gdb_stdout
);
404 printf_filtered ("%s ", plongest (tsv
->initial_value
));
405 print_spaces_filtered (11 - strlen (plongest (tsv
->initial_value
)), gdb_stdout
);
406 if (tsv
->value_known
)
407 printf_filtered (" %s", plongest (tsv
->value
));
408 else if (trace_running_p
|| traceframe_number
>= 0)
409 /* The value is/was defined, but we don't have it. */
410 printf_filtered (_(" <unknown>"));
412 /* It is not meaningful to ask about the value. */
413 printf_filtered (_(" <undefined>"));
414 printf_filtered ("\n");
418 /* ACTIONS functions: */
420 /* Prototypes for action-parsing utility commands */
421 static void read_actions (struct breakpoint
*);
423 /* The three functions:
424 collect_pseudocommand,
425 while_stepping_pseudocommand, and
426 end_actions_pseudocommand
427 are placeholders for "commands" that are actually ONLY to be used
428 within a tracepoint action list. If the actual function is ever called,
429 it means that somebody issued the "command" at the top level,
430 which is always an error. */
433 end_actions_pseudocommand (char *args
, int from_tty
)
435 error (_("This command cannot be used at the top level."));
439 while_stepping_pseudocommand (char *args
, int from_tty
)
441 error (_("This command can only be used in a tracepoint actions list."));
445 collect_pseudocommand (char *args
, int from_tty
)
447 error (_("This command can only be used in a tracepoint actions list."));
451 teval_pseudocommand (char *args
, int from_tty
)
453 error (_("This command can only be used in a tracepoint actions list."));
456 /* Enter a list of actions for a tracepoint. */
458 trace_actions_command (char *args
, int from_tty
)
460 struct breakpoint
*t
;
462 char *end_msg
= "End with a line saying just \"end\".";
464 t
= get_tracepoint_by_number (&args
, 0, 1);
467 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
472 if (deprecated_readline_begin_hook
)
473 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
474 else if (input_from_terminal_p ())
475 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
479 t
->step_count
= 0; /* read_actions may set this */
482 if (deprecated_readline_end_hook
)
483 (*deprecated_readline_end_hook
) ();
484 /* tracepoints_changed () */
486 /* else just return */
489 /* worker function */
491 read_actions (struct breakpoint
*t
)
494 char *prompt1
= "> ", *prompt2
= " > ";
495 char *prompt
= prompt1
;
496 enum actionline_type linetype
;
497 extern FILE *instream
;
498 struct action_line
*next
= NULL
, *temp
;
499 struct cleanup
*old_chain
;
501 /* Control-C quits instantly if typed while in this loop
502 since it should not wait until the user types a newline. */
504 /* FIXME: kettenis/20010823: Something is wrong here. In this file
505 STOP_SIGNAL is never defined. So this code has been left out, at
506 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
507 leads to compilation failures since the variable job_control
508 isn't declared. Leave this alone for now. */
511 signal (STOP_SIGNAL
, handle_stop_sig
);
513 old_chain
= make_cleanup_free_actions (t
);
516 /* Make sure that all output has been output. Some machines may
517 let you get away with leaving out some of the gdb_flush, but
520 gdb_flush (gdb_stdout
);
521 gdb_flush (gdb_stderr
);
523 if (deprecated_readline_hook
&& instream
== NULL
)
524 line
= (*deprecated_readline_hook
) (prompt
);
525 else if (instream
== stdin
&& ISATTY (instream
))
527 line
= gdb_readline_wrapper (prompt
);
528 if (line
&& *line
) /* add it to command history */
532 line
= gdb_readline (0);
536 line
= xstrdup ("end");
537 printf_filtered ("end\n");
540 linetype
= validate_actionline (&line
, t
);
541 if (linetype
== BADLINE
)
542 continue; /* already warned -- collect another line */
544 temp
= xmalloc (sizeof (struct action_line
));
548 if (next
== NULL
) /* first action for this tracepoint? */
549 t
->actions
= next
= temp
;
556 if (linetype
== STEPPING
) /* begin "while-stepping" */
558 if (prompt
== prompt2
)
560 warning (_("Already processing 'while-stepping'"));
564 prompt
= prompt2
; /* change prompt for stepping actions */
566 else if (linetype
== END
)
568 if (prompt
== prompt2
)
570 prompt
= prompt1
; /* end of single-stepping actions */
573 { /* end of actions */
574 if (t
->actions
->next
== NULL
)
576 /* An "end" all by itself with no other actions
577 means this tracepoint has no actions.
578 Discard empty list. */
587 signal (STOP_SIGNAL
, SIG_DFL
);
590 discard_cleanups (old_chain
);
593 /* worker function */
595 validate_actionline (char **line
, struct breakpoint
*t
)
597 struct cmd_list_element
*c
;
598 struct expression
*exp
= NULL
;
599 struct cleanup
*old_chain
= NULL
;
602 /* if EOF is typed, *line is NULL */
606 for (p
= *line
; isspace ((int) *p
);)
609 /* Symbol lookup etc. */
610 if (*p
== '\0') /* empty line: just prompt for another line. */
613 if (*p
== '#') /* comment line */
616 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
619 warning (_("'%s' is not an action that I know, or is ambiguous."),
624 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
626 struct agent_expr
*aexpr
;
627 struct agent_reqs areqs
;
630 { /* repeat over a comma-separated list */
631 QUIT
; /* allow user to bail out with ^C */
632 while (isspace ((int) *p
))
635 if (*p
== '$') /* look for special pseudo-symbols */
637 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
638 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
639 (0 == strncasecmp ("loc", p
+ 1, 3)))
644 /* else fall thru, treat p as an expression and parse it! */
646 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
647 old_chain
= make_cleanup (free_current_contents
, &exp
);
649 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
651 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
653 warning (_("constant %s (value %ld) will not be collected."),
654 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
655 SYMBOL_VALUE (exp
->elts
[2].symbol
));
658 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
660 warning (_("%s is optimized away and cannot be collected."),
661 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
666 /* We have something to collect, make sure that the expr to
667 bytecode translator can handle it and that it's not too
669 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
670 make_cleanup_free_agent_expr (aexpr
);
672 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
673 error (_("expression too complicated, try simplifying"));
675 ax_reqs (aexpr
, &areqs
);
676 (void) make_cleanup (xfree
, areqs
.reg_mask
);
678 if (areqs
.flaw
!= agent_flaw_none
)
679 error (_("malformed expression"));
681 if (areqs
.min_height
< 0)
682 error (_("gdb: Internal error: expression has min height < 0"));
684 if (areqs
.max_height
> 20)
685 error (_("expression too complicated, try simplifying"));
687 do_cleanups (old_chain
);
689 while (p
&& *p
++ == ',');
692 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
694 struct agent_expr
*aexpr
;
697 { /* repeat over a comma-separated list */
698 QUIT
; /* allow user to bail out with ^C */
699 while (isspace ((int) *p
))
702 /* Only expressions are allowed for this action. */
703 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
704 old_chain
= make_cleanup (free_current_contents
, &exp
);
706 /* We have something to evaluate, make sure that the expr to
707 bytecode translator can handle it and that it's not too
709 aexpr
= gen_eval_for_expr (t
->loc
->address
, exp
);
710 make_cleanup_free_agent_expr (aexpr
);
712 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
713 error (_("expression too complicated, try simplifying"));
715 do_cleanups (old_chain
);
717 while (p
&& *p
++ == ',');
720 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
722 char *steparg
; /* in case warning is necessary */
724 while (isspace ((int) *p
))
729 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
731 warning (_("'%s': bad step-count; command ignored."), *line
);
736 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
740 warning (_("'%s' is not a supported tracepoint action."), *line
);
745 /* worker function */
747 free_actions (struct breakpoint
*t
)
749 struct action_line
*line
, *next
;
751 for (line
= t
->actions
; line
; line
= next
)
755 xfree (line
->action
);
762 do_free_actions_cleanup (void *t
)
767 static struct cleanup
*
768 make_cleanup_free_actions (struct breakpoint
*t
)
770 return make_cleanup (do_free_actions_cleanup
, t
);
774 memrange_absolute
= -1
779 int type
; /* memrange_absolute for absolute memory range,
780 else basereg number */
781 bfd_signed_vma start
;
785 struct collection_list
787 unsigned char regs_mask
[32]; /* room for up to 256 regs */
790 struct memrange
*list
;
791 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
793 struct agent_expr
**aexpr_list
;
796 tracepoint_list
, stepping_list
;
798 /* MEMRANGE functions: */
800 static int memrange_cmp (const void *, const void *);
802 /* compare memranges for qsort */
804 memrange_cmp (const void *va
, const void *vb
)
806 const struct memrange
*a
= va
, *b
= vb
;
808 if (a
->type
< b
->type
)
810 if (a
->type
> b
->type
)
812 if (a
->type
== memrange_absolute
)
814 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
816 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
821 if (a
->start
< b
->start
)
823 if (a
->start
> b
->start
)
829 /* Sort the memrange list using qsort, and merge adjacent memranges. */
831 memrange_sortmerge (struct collection_list
*memranges
)
835 qsort (memranges
->list
, memranges
->next_memrange
,
836 sizeof (struct memrange
), memrange_cmp
);
837 if (memranges
->next_memrange
> 0)
839 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
841 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
842 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
845 /* memrange b starts before memrange a ends; merge them. */
846 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
847 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
848 continue; /* next b, same a */
852 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
853 sizeof (struct memrange
));
855 memranges
->next_memrange
= a
+ 1;
859 /* Add a register to a collection list. */
861 add_register (struct collection_list
*collection
, unsigned int regno
)
864 printf_filtered ("collect register %d\n", regno
);
865 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
866 error (_("Internal: register number %d too large for tracepoint"),
868 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
871 /* Add a memrange to a collection list */
873 add_memrange (struct collection_list
*memranges
,
874 int type
, bfd_signed_vma base
,
879 printf_filtered ("(%d,", type
);
881 printf_filtered (",%ld)\n", len
);
884 /* type: memrange_absolute == memory, other n == basereg */
885 memranges
->list
[memranges
->next_memrange
].type
= type
;
886 /* base: addr if memory, offset if reg relative. */
887 memranges
->list
[memranges
->next_memrange
].start
= base
;
888 /* len: we actually save end (base + len) for convenience */
889 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
890 memranges
->next_memrange
++;
891 if (memranges
->next_memrange
>= memranges
->listsize
)
893 memranges
->listsize
*= 2;
894 memranges
->list
= xrealloc (memranges
->list
,
895 memranges
->listsize
);
898 if (type
!= memrange_absolute
) /* Better collect the base register! */
899 add_register (memranges
, type
);
902 /* Add a symbol to a collection list. */
904 collect_symbol (struct collection_list
*collect
,
906 struct gdbarch
*gdbarch
,
907 long frame_regno
, long frame_offset
,
912 bfd_signed_vma offset
;
914 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
915 switch (SYMBOL_CLASS (sym
))
918 printf_filtered ("%s: don't know symbol class %d\n",
919 SYMBOL_PRINT_NAME (sym
),
923 printf_filtered ("constant %s (value %ld) will not be collected.\n",
924 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
927 offset
= SYMBOL_VALUE_ADDRESS (sym
);
932 sprintf_vma (tmp
, offset
);
933 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
934 SYMBOL_PRINT_NAME (sym
), len
,
937 add_memrange (collect
, memrange_absolute
, offset
, len
);
940 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
942 printf_filtered ("LOC_REG[parm] %s: ",
943 SYMBOL_PRINT_NAME (sym
));
944 add_register (collect
, reg
);
945 /* Check for doubles stored in two registers. */
946 /* FIXME: how about larger types stored in 3 or more regs? */
947 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
948 len
> register_size (gdbarch
, reg
))
949 add_register (collect
, reg
+ 1);
952 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
953 printf_filtered (" (will not collect %s)\n",
954 SYMBOL_PRINT_NAME (sym
));
958 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
961 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
962 SYMBOL_PRINT_NAME (sym
), len
);
964 printf_filtered (" from frame ptr reg %d\n", reg
);
966 add_memrange (collect
, reg
, offset
, len
);
968 case LOC_REGPARM_ADDR
:
969 reg
= SYMBOL_VALUE (sym
);
973 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
974 SYMBOL_PRINT_NAME (sym
), len
);
976 printf_filtered (" from reg %d\n", reg
);
978 add_memrange (collect
, reg
, offset
, len
);
982 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
985 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
986 SYMBOL_PRINT_NAME (sym
), len
);
988 printf_filtered (" from frame ptr reg %d\n", reg
);
990 add_memrange (collect
, reg
, offset
, len
);
993 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
994 SYMBOL_PRINT_NAME (sym
));
996 case LOC_OPTIMIZED_OUT
:
997 printf_filtered ("%s has been optimized out of existence.\n",
998 SYMBOL_PRINT_NAME (sym
));
1003 struct agent_expr
*aexpr
;
1004 struct cleanup
*old_chain1
= NULL
;
1005 struct agent_reqs areqs
;
1007 aexpr
= gen_trace_for_var (scope
, sym
);
1009 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1011 ax_reqs (aexpr
, &areqs
);
1012 if (areqs
.flaw
!= agent_flaw_none
)
1013 error (_("malformed expression"));
1015 if (areqs
.min_height
< 0)
1016 error (_("gdb: Internal error: expression has min height < 0"));
1017 if (areqs
.max_height
> 20)
1018 error (_("expression too complicated, try simplifying"));
1020 discard_cleanups (old_chain1
);
1021 add_aexpr (collect
, aexpr
);
1023 /* take care of the registers */
1024 if (areqs
.reg_mask_len
> 0)
1028 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1030 QUIT
; /* allow user to bail out with ^C */
1031 if (areqs
.reg_mask
[ndx1
] != 0)
1033 /* assume chars have 8 bits */
1034 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1035 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1036 /* it's used -- record it */
1037 add_register (collect
,
1047 /* Add all locals (or args) symbols to collection list */
1049 add_local_symbols (struct collection_list
*collect
,
1050 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1051 long frame_regno
, long frame_offset
, int type
)
1054 struct block
*block
;
1055 struct dict_iterator iter
;
1058 block
= block_for_pc (pc
);
1061 QUIT
; /* allow user to bail out with ^C */
1062 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1064 if (SYMBOL_IS_ARGUMENT (sym
)
1065 ? type
== 'A' /* collecting Arguments */
1066 : type
== 'L') /* collecting Locals */
1069 collect_symbol (collect
, sym
, gdbarch
,
1070 frame_regno
, frame_offset
, pc
);
1073 if (BLOCK_FUNCTION (block
))
1076 block
= BLOCK_SUPERBLOCK (block
);
1079 warning (_("No %s found in scope."),
1080 type
== 'L' ? "locals" : "args");
1083 /* worker function */
1085 clear_collection_list (struct collection_list
*list
)
1089 list
->next_memrange
= 0;
1090 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1092 free_agent_expr (list
->aexpr_list
[ndx
]);
1093 list
->aexpr_list
[ndx
] = NULL
;
1095 list
->next_aexpr_elt
= 0;
1096 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1099 /* reduce a collection list to string form (for gdb protocol) */
1101 stringify_collection_list (struct collection_list
*list
, char *string
)
1103 char temp_buf
[2048];
1107 char *(*str_list
)[];
1111 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1112 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1114 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1115 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1117 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1120 printf_filtered ("\nCollecting registers (mask): 0x");
1125 QUIT
; /* allow user to bail out with ^C */
1127 printf_filtered ("%02X", list
->regs_mask
[i
]);
1128 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1131 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1135 printf_filtered ("\n");
1136 if (list
->next_memrange
> 0 && info_verbose
)
1137 printf_filtered ("Collecting memranges: \n");
1138 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1140 QUIT
; /* allow user to bail out with ^C */
1141 sprintf_vma (tmp2
, list
->list
[i
].start
);
1144 printf_filtered ("(%d, %s, %ld)\n",
1147 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1149 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1151 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1158 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
1160 /* The "%X" conversion specifier expects an unsigned argument,
1161 so passing -1 (memrange_absolute) to it directly gives you
1162 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1164 if (list
->list
[i
].type
== memrange_absolute
)
1165 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1167 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
1170 count
+= strlen (end
);
1171 end
= temp_buf
+ count
;
1174 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1176 QUIT
; /* allow user to bail out with ^C */
1177 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1179 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1184 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1185 end
+= 10; /* 'X' + 8 hex digits + ',' */
1188 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1189 end
, list
->aexpr_list
[i
]->len
);
1190 count
+= 2 * list
->aexpr_list
[i
]->len
;
1195 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1200 (*str_list
)[ndx
] = NULL
;
1211 /* Render all actions into gdb protocol. */
1213 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1214 char ***stepping_actions
)
1216 static char tdp_buff
[2048], step_buff
[2048];
1218 struct expression
*exp
= NULL
;
1219 struct action_line
*action
;
1221 struct value
*tempval
;
1222 struct collection_list
*collect
;
1223 struct cmd_list_element
*cmd
;
1224 struct agent_expr
*aexpr
;
1226 LONGEST frame_offset
;
1227 char *default_collect_line
= NULL
;
1228 struct action_line
*default_collect_action
= NULL
;
1230 clear_collection_list (&tracepoint_list
);
1231 clear_collection_list (&stepping_list
);
1232 collect
= &tracepoint_list
;
1234 *tdp_actions
= NULL
;
1235 *stepping_actions
= NULL
;
1237 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1238 t
->loc
->address
, &frame_reg
, &frame_offset
);
1240 action
= t
->actions
;
1242 /* If there are default expressions to collect, make up a collect
1243 action and prepend to the action list to encode. Note that since
1244 validation is per-tracepoint (local var "xyz" might be valid for
1245 one tracepoint and not another, etc), we make up the action on
1246 the fly, and don't cache it. */
1247 if (*default_collect
)
1250 enum actionline_type linetype
;
1252 default_collect_line
= xmalloc (12 + strlen (default_collect
));
1253 sprintf (default_collect_line
, "collect %s", default_collect
);
1254 line
= default_collect_line
;
1255 linetype
= validate_actionline (&line
, t
);
1256 if (linetype
!= BADLINE
)
1258 default_collect_action
= xmalloc (sizeof (struct action_line
));
1259 default_collect_action
->next
= t
->actions
;
1260 default_collect_action
->action
= line
;
1261 action
= default_collect_action
;
1265 for (; action
; action
= action
->next
)
1267 QUIT
; /* allow user to bail out with ^C */
1268 action_exp
= action
->action
;
1269 while (isspace ((int) *action_exp
))
1272 if (*action_exp
== '#') /* comment line */
1275 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1277 error (_("Bad action list item: %s"), action_exp
);
1279 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1282 { /* repeat over a comma-separated list */
1283 QUIT
; /* allow user to bail out with ^C */
1284 while (isspace ((int) *action_exp
))
1287 if (0 == strncasecmp ("$reg", action_exp
, 4))
1289 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1290 add_register (collect
, i
);
1291 action_exp
= strchr (action_exp
, ','); /* more? */
1293 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1295 add_local_symbols (collect
,
1301 action_exp
= strchr (action_exp
, ','); /* more? */
1303 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1305 add_local_symbols (collect
,
1311 action_exp
= strchr (action_exp
, ','); /* more? */
1315 unsigned long addr
, len
;
1316 struct cleanup
*old_chain
= NULL
;
1317 struct cleanup
*old_chain1
= NULL
;
1318 struct agent_reqs areqs
;
1320 exp
= parse_exp_1 (&action_exp
,
1321 block_for_pc (t
->loc
->address
), 1);
1322 old_chain
= make_cleanup (free_current_contents
, &exp
);
1324 switch (exp
->elts
[0].opcode
)
1328 const char *name
= &exp
->elts
[2].string
;
1330 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1331 name
, strlen (name
));
1333 internal_error (__FILE__
, __LINE__
,
1334 _("Register $%s not available"),
1337 printf_filtered ("OP_REGISTER: ");
1338 add_register (collect
, i
);
1343 /* safe because we know it's a simple expression */
1344 tempval
= evaluate_expression (exp
);
1345 addr
= value_address (tempval
);
1346 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1347 add_memrange (collect
, memrange_absolute
, addr
, len
);
1351 collect_symbol (collect
,
1352 exp
->elts
[2].symbol
,
1359 default: /* full-fledged expression */
1360 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1362 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1364 ax_reqs (aexpr
, &areqs
);
1365 if (areqs
.flaw
!= agent_flaw_none
)
1366 error (_("malformed expression"));
1368 if (areqs
.min_height
< 0)
1369 error (_("gdb: Internal error: expression has min height < 0"));
1370 if (areqs
.max_height
> 20)
1371 error (_("expression too complicated, try simplifying"));
1373 discard_cleanups (old_chain1
);
1374 add_aexpr (collect
, aexpr
);
1376 /* take care of the registers */
1377 if (areqs
.reg_mask_len
> 0)
1382 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1384 QUIT
; /* allow user to bail out with ^C */
1385 if (areqs
.reg_mask
[ndx1
] != 0)
1387 /* assume chars have 8 bits */
1388 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1389 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1390 /* it's used -- record it */
1391 add_register (collect
,
1398 do_cleanups (old_chain
);
1401 while (action_exp
&& *action_exp
++ == ',');
1403 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1406 { /* repeat over a comma-separated list */
1407 QUIT
; /* allow user to bail out with ^C */
1408 while (isspace ((int) *action_exp
))
1412 unsigned long addr
, len
;
1413 struct cleanup
*old_chain
= NULL
;
1414 struct cleanup
*old_chain1
= NULL
;
1415 struct agent_reqs areqs
;
1417 exp
= parse_exp_1 (&action_exp
,
1418 block_for_pc (t
->loc
->address
), 1);
1419 old_chain
= make_cleanup (free_current_contents
, &exp
);
1421 aexpr
= gen_eval_for_expr (t
->loc
->address
, exp
);
1422 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1424 ax_reqs (aexpr
, &areqs
);
1425 if (areqs
.flaw
!= agent_flaw_none
)
1426 error (_("malformed expression"));
1428 if (areqs
.min_height
< 0)
1429 error (_("gdb: Internal error: expression has min height < 0"));
1430 if (areqs
.max_height
> 20)
1431 error (_("expression too complicated, try simplifying"));
1433 discard_cleanups (old_chain1
);
1434 /* Even though we're not officially collecting, add
1435 to the collect list anyway. */
1436 add_aexpr (collect
, aexpr
);
1438 do_cleanups (old_chain
);
1441 while (action_exp
&& *action_exp
++ == ',');
1443 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1445 collect
= &stepping_list
;
1447 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1449 if (collect
== &stepping_list
) /* end stepping actions */
1450 collect
= &tracepoint_list
;
1452 break; /* end tracepoint actions */
1455 memrange_sortmerge (&tracepoint_list
);
1456 memrange_sortmerge (&stepping_list
);
1458 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1460 *stepping_actions
= stringify_collection_list (&stepping_list
,
1463 xfree (default_collect_line
);
1464 xfree (default_collect_action
);
1468 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1470 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1472 collect
->aexpr_list
=
1473 xrealloc (collect
->aexpr_list
,
1474 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1475 collect
->aexpr_listsize
*= 2;
1477 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1478 collect
->next_aexpr_elt
++;
1483 Tell target to clear any previous trace experiment.
1484 Walk the list of tracepoints, and send them (and their actions)
1485 to the target. If no errors,
1486 Tell target to start a new trace experiment. */
1489 trace_start_command (char *args
, int from_tty
)
1492 VEC(breakpoint_p
) *tp_vec
= NULL
;
1494 struct breakpoint
*t
;
1495 struct trace_state_variable
*tsv
;
1496 int any_downloaded
= 0;
1498 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1500 target_trace_init ();
1502 tp_vec
= all_tracepoints ();
1503 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1505 t
->number_on_target
= 0;
1506 target_download_tracepoint (t
);
1507 t
->number_on_target
= t
->number
;
1510 VEC_free (breakpoint_p
, tp_vec
);
1512 /* No point in tracing without any tracepoints... */
1513 if (!any_downloaded
)
1514 error ("No tracepoints downloaded, not starting trace");
1516 /* Init any trace state variables that start with nonzero values. */
1517 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1519 if (tsv
->initial_value
!= 0)
1520 target_download_trace_state_variable (tsv
);
1523 /* Tell target to treat text-like sections as transparent. */
1524 target_trace_set_readonly_regions ();
1526 /* Now insert traps and begin collecting data. */
1527 target_trace_start ();
1529 /* Reset our local state. */
1530 set_traceframe_num (-1);
1531 set_tracepoint_num (-1);
1532 set_traceframe_context (NULL
);
1533 trace_running_p
= 1;
1538 trace_stop_command (char *args
, int from_tty
)
1546 target_trace_stop ();
1547 trace_running_p
= 0;
1550 unsigned long trace_running_p
;
1555 int status
= target_get_trace_status (NULL
);
1557 /* exported for use by the GUI */
1558 trace_running_p
= (status
> 0);
1563 /* tstatus command */
1565 trace_status_command (char *args
, int from_tty
)
1567 int status
= get_trace_status ();
1570 printf_filtered (_("Trace can not be run on the target.\n"));
1571 else if (trace_running_p
)
1573 printf_filtered (_("Trace is running on the target.\n"));
1574 if (disconnected_tracing
)
1575 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1577 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1580 printf_filtered (_("Trace is not running on the target.\n"));
1582 if (traceframe_number
>= 0)
1583 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1584 traceframe_number
, tracepoint_number
);
1586 printf_filtered (_("Not looking at any trace frame.\n"));
1590 disconnect_or_stop_tracing (int from_tty
)
1592 if (trace_running_p
&& from_tty
)
1594 int cont
= query (_("Trace is running. Continue tracing after detach? "));
1595 /* Note that we send the query result without affecting the
1596 user's setting of disconnected_tracing, so that the answer is
1598 send_disconnected_tracing_value (cont
);
1600 /* Also ensure that we do the equivalent of a tstop command if
1601 tracing is not to continue after the detach. */
1607 /* Worker function for the various flavors of the tfind command. */
1609 finish_tfind_command (enum trace_find_type type
, int num
,
1610 ULONGEST addr1
, ULONGEST addr2
,
1613 int target_frameno
= -1, target_tracept
= -1;
1614 struct frame_id old_frame_id
;
1616 struct breakpoint
*tp
;
1618 old_frame_id
= get_frame_id (get_current_frame ());
1620 target_frameno
= target_trace_find (type
, num
, addr1
, addr2
,
1623 if (type
== tfind_number
1625 && target_frameno
== -1)
1627 /* We told the target to get out of tfind mode, and it did. */
1629 else if (target_frameno
== -1)
1631 /* A request for a non-existant trace frame has failed.
1632 Our response will be different, depending on FROM_TTY:
1634 If FROM_TTY is true, meaning that this command was
1635 typed interactively by the user, then give an error
1636 and DO NOT change the state of traceframe_number etc.
1638 However if FROM_TTY is false, meaning that we're either
1639 in a script, a loop, or a user-defined command, then
1640 DON'T give an error, but DO change the state of
1641 traceframe_number etc. to invalid.
1643 The rationalle is that if you typed the command, you
1644 might just have committed a typo or something, and you'd
1645 like to NOT lose your current debugging state. However
1646 if you're in a user-defined command or especially in a
1647 loop, then you need a way to detect that the command
1648 failed WITHOUT aborting. This allows you to write
1649 scripts that search thru the trace buffer until the end,
1650 and then continue on to do something else. */
1653 error (_("Target failed to find requested trace frame."));
1657 printf_filtered ("End of trace buffer.\n");
1658 #if 0 /* dubious now? */
1659 /* The following will not recurse, since it's
1661 trace_find_command ("-1", from_tty
);
1666 tp
= get_tracepoint_by_number_on_target (target_tracept
);
1668 reinit_frame_cache ();
1669 registers_changed ();
1670 set_traceframe_num (target_frameno
);
1671 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
1672 if (target_frameno
== -1)
1673 set_traceframe_context (NULL
);
1675 set_traceframe_context (get_current_frame ());
1679 enum print_what print_what
;
1681 /* NOTE: in immitation of the step command, try to determine
1682 whether we have made a transition from one function to
1683 another. If so, we'll print the "stack frame" (ie. the new
1684 function and it's arguments) -- otherwise we'll just show the
1687 if (frame_id_eq (old_frame_id
,
1688 get_frame_id (get_current_frame ())))
1689 print_what
= SRC_LINE
;
1691 print_what
= SRC_AND_LOC
;
1693 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1698 /* trace_find_command takes a trace frame number n,
1699 sends "QTFrame:<n>" to the target,
1700 and accepts a reply that may contain several optional pieces
1701 of information: a frame number, a tracepoint number, and an
1702 indication of whether this is a trap frame or a stepping frame.
1704 The minimal response is just "OK" (which indicates that the
1705 target does not give us a frame number or a tracepoint number).
1706 Instead of that, the target may send us a string containing
1708 F<hexnum> (gives the selected frame number)
1709 T<hexnum> (gives the selected tracepoint number)
1714 trace_find_command (char *args
, int from_tty
)
1715 { /* this should only be called with a numeric argument */
1718 if (trace_running_p
)
1719 error ("May not look at trace frames while trace is running.");
1721 if (args
== 0 || *args
== 0)
1722 { /* TFIND with no args means find NEXT trace frame. */
1723 if (traceframe_number
== -1)
1724 frameno
= 0; /* "next" is first one */
1726 frameno
= traceframe_number
+ 1;
1728 else if (0 == strcmp (args
, "-"))
1730 if (traceframe_number
== -1)
1731 error (_("not debugging trace buffer"));
1732 else if (from_tty
&& traceframe_number
== 0)
1733 error (_("already at start of trace buffer"));
1735 frameno
= traceframe_number
- 1;
1737 /* A hack to work around eval's need for fp to have been collected. */
1738 else if (0 == strcmp (args
, "-1"))
1741 frameno
= parse_and_eval_long (args
);
1744 error (_("invalid input (%d is less than zero)"), frameno
);
1746 finish_tfind_command (tfind_number
, frameno
, 0, 0, from_tty
);
1751 trace_find_end_command (char *args
, int from_tty
)
1753 trace_find_command ("-1", from_tty
);
1758 trace_find_none_command (char *args
, int from_tty
)
1760 trace_find_command ("-1", from_tty
);
1765 trace_find_start_command (char *args
, int from_tty
)
1767 trace_find_command ("0", from_tty
);
1770 /* tfind pc command */
1772 trace_find_pc_command (char *args
, int from_tty
)
1777 if (trace_running_p
)
1778 error ("May not look at trace frames while trace is running.");
1780 if (args
== 0 || *args
== 0)
1781 pc
= regcache_read_pc (get_current_regcache ());
1783 pc
= parse_and_eval_address (args
);
1785 finish_tfind_command (tfind_pc
, 0, pc
, 0, from_tty
);
1788 /* tfind tracepoint command */
1790 trace_find_tracepoint_command (char *args
, int from_tty
)
1793 struct breakpoint
*tp
;
1795 if (trace_running_p
)
1796 error ("May not look at trace frames while trace is running.");
1798 if (args
== 0 || *args
== 0)
1800 if (tracepoint_number
== -1)
1801 error (_("No current tracepoint -- please supply an argument."));
1803 tdp
= tracepoint_number
; /* default is current TDP */
1806 tdp
= parse_and_eval_long (args
);
1808 /* If we have the tracepoint on hand, use the number that the
1809 target knows about (which may be different if we disconnected
1810 and reconnected). */
1811 tp
= get_tracepoint (tdp
);
1813 tdp
= tp
->number_on_target
;
1815 finish_tfind_command (tfind_tp
, tdp
, 0, 0, from_tty
);
1818 /* TFIND LINE command:
1820 This command will take a sourceline for argument, just like BREAK
1821 or TRACE (ie. anything that "decode_line_1" can handle).
1823 With no argument, this command will find the next trace frame
1824 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1827 trace_find_line_command (char *args
, int from_tty
)
1829 static CORE_ADDR start_pc
, end_pc
;
1830 struct symtabs_and_lines sals
;
1831 struct symtab_and_line sal
;
1832 struct cleanup
*old_chain
;
1833 char startpc_str
[40], endpc_str
[40];
1835 if (trace_running_p
)
1836 error ("May not look at trace frames while trace is running.");
1838 if (args
== 0 || *args
== 0)
1840 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1842 sals
.sals
= (struct symtab_and_line
*)
1843 xmalloc (sizeof (struct symtab_and_line
));
1848 sals
= decode_line_spec (args
, 1);
1852 old_chain
= make_cleanup (xfree
, sals
.sals
);
1853 if (sal
.symtab
== 0)
1855 printf_filtered ("TFIND: No line number information available");
1858 /* This is useful for "info line *0x7f34". If we can't
1859 tell the user about a source line, at least let them
1860 have the symbolic address. */
1861 printf_filtered (" for address ");
1863 print_address (get_current_arch (), sal
.pc
, gdb_stdout
);
1864 printf_filtered (";\n -- will attempt to find by PC. \n");
1868 printf_filtered (".\n");
1869 return; /* No line, no PC; what can we do? */
1872 else if (sal
.line
> 0
1873 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1875 if (start_pc
== end_pc
)
1877 printf_filtered ("Line %d of \"%s\"",
1878 sal
.line
, sal
.symtab
->filename
);
1880 printf_filtered (" is at address ");
1881 print_address (get_current_arch (), start_pc
, gdb_stdout
);
1883 printf_filtered (" but contains no code.\n");
1884 sal
= find_pc_line (start_pc
, 0);
1886 && find_line_pc_range (sal
, &start_pc
, &end_pc
)
1887 && start_pc
!= end_pc
)
1888 printf_filtered ("Attempting to find line %d instead.\n",
1891 error (_("Cannot find a good line."));
1895 /* Is there any case in which we get here, and have an address
1896 which the user would want to see? If we have debugging
1897 symbols and no line numbers? */
1898 error (_("Line number %d is out of range for \"%s\"."),
1899 sal
.line
, sal
.symtab
->filename
);
1901 /* Find within range of stated line. */
1903 finish_tfind_command (tfind_range
, 0, start_pc
, end_pc
- 1, from_tty
);
1905 finish_tfind_command (tfind_outside
, 0, start_pc
, end_pc
- 1, from_tty
);
1906 do_cleanups (old_chain
);
1909 /* tfind range command */
1911 trace_find_range_command (char *args
, int from_tty
)
1913 static CORE_ADDR start
, stop
;
1914 char start_str
[40], stop_str
[40];
1917 if (trace_running_p
)
1918 error ("May not look at trace frames while trace is running.");
1920 if (args
== 0 || *args
== 0)
1921 { /* XXX FIXME: what should default behavior be? */
1922 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1926 if (0 != (tmp
= strchr (args
, ',')))
1928 *tmp
++ = '\0'; /* terminate start address */
1929 while (isspace ((int) *tmp
))
1931 start
= parse_and_eval_address (args
);
1932 stop
= parse_and_eval_address (tmp
);
1935 { /* no explicit end address? */
1936 start
= parse_and_eval_address (args
);
1937 stop
= start
+ 1; /* ??? */
1940 finish_tfind_command (tfind_range
, 0, start
, stop
, from_tty
);
1943 /* tfind outside command */
1945 trace_find_outside_command (char *args
, int from_tty
)
1947 CORE_ADDR start
, stop
;
1948 char start_str
[40], stop_str
[40];
1951 if (trace_running_p
)
1952 error ("May not look at trace frames while trace is running.");
1954 if (args
== 0 || *args
== 0)
1955 { /* XXX FIXME: what should default behavior be? */
1956 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1960 if (0 != (tmp
= strchr (args
, ',')))
1962 *tmp
++ = '\0'; /* terminate start address */
1963 while (isspace ((int) *tmp
))
1965 start
= parse_and_eval_address (args
);
1966 stop
= parse_and_eval_address (tmp
);
1969 { /* no explicit end address? */
1970 start
= parse_and_eval_address (args
);
1971 stop
= start
+ 1; /* ??? */
1974 finish_tfind_command (tfind_outside
, 0, start
, stop
, from_tty
);
1977 /* info scope command: list the locals for a scope. */
1979 scope_info (char *args
, int from_tty
)
1981 struct symtabs_and_lines sals
;
1983 struct minimal_symbol
*msym
;
1984 struct block
*block
;
1985 char **canonical
, *symname
, *save_args
= args
;
1986 struct dict_iterator iter
;
1988 struct gdbarch
*gdbarch
;
1991 if (args
== 0 || *args
== 0)
1992 error (_("requires an argument (function, line or *addr) to define a scope"));
1994 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1995 if (sals
.nelts
== 0)
1996 return; /* presumably decode_line_1 has already warned */
1998 /* Resolve line numbers to PC */
1999 resolve_sal_pc (&sals
.sals
[0]);
2000 block
= block_for_pc (sals
.sals
[0].pc
);
2004 QUIT
; /* allow user to bail out with ^C */
2005 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2007 QUIT
; /* allow user to bail out with ^C */
2009 printf_filtered ("Scope for %s:\n", save_args
);
2012 symname
= SYMBOL_PRINT_NAME (sym
);
2013 if (symname
== NULL
|| *symname
== '\0')
2014 continue; /* probably botched, certainly useless */
2016 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
2018 printf_filtered ("Symbol %s is ", symname
);
2019 switch (SYMBOL_CLASS (sym
))
2022 case LOC_UNDEF
: /* messed up symbol? */
2023 printf_filtered ("a bogus symbol, class %d.\n",
2024 SYMBOL_CLASS (sym
));
2025 count
--; /* don't count this one */
2028 printf_filtered ("a constant with value %ld (0x%lx)",
2029 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2031 case LOC_CONST_BYTES
:
2032 printf_filtered ("constant bytes: ");
2033 if (SYMBOL_TYPE (sym
))
2034 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2035 fprintf_filtered (gdb_stdout
, " %02x",
2036 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2039 printf_filtered ("in static storage at address ");
2040 printf_filtered ("%s", paddress (gdbarch
,
2041 SYMBOL_VALUE_ADDRESS (sym
)));
2044 /* GDBARCH is the architecture associated with the objfile
2045 the symbol is defined in; the target architecture may be
2046 different, and may provide additional registers. However,
2047 we do not know the target architecture at this point.
2048 We assume the objfile architecture will contain all the
2049 standard registers that occur in debug info in that
2051 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2053 if (SYMBOL_IS_ARGUMENT (sym
))
2054 printf_filtered ("an argument in register $%s",
2055 gdbarch_register_name (gdbarch
, regno
));
2057 printf_filtered ("a local variable in register $%s",
2058 gdbarch_register_name (gdbarch
, regno
));
2061 printf_filtered ("an argument at stack/frame offset %ld",
2062 SYMBOL_VALUE (sym
));
2065 printf_filtered ("a local variable at frame offset %ld",
2066 SYMBOL_VALUE (sym
));
2069 printf_filtered ("a reference argument at offset %ld",
2070 SYMBOL_VALUE (sym
));
2072 case LOC_REGPARM_ADDR
:
2073 /* Note comment at LOC_REGISTER. */
2074 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2075 printf_filtered ("the address of an argument, in register $%s",
2076 gdbarch_register_name (gdbarch
, regno
));
2079 printf_filtered ("a typedef.\n");
2082 printf_filtered ("a label at address ");
2083 printf_filtered ("%s", paddress (gdbarch
,
2084 SYMBOL_VALUE_ADDRESS (sym
)));
2087 printf_filtered ("a function at address ");
2088 printf_filtered ("%s",
2089 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2091 case LOC_UNRESOLVED
:
2092 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2095 printf_filtered ("Unresolved Static");
2098 printf_filtered ("static storage at address ");
2099 printf_filtered ("%s",
2100 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
2103 case LOC_OPTIMIZED_OUT
:
2104 printf_filtered ("optimized out.\n");
2107 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
2110 if (SYMBOL_TYPE (sym
))
2111 printf_filtered (", length %d.\n",
2112 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2114 if (BLOCK_FUNCTION (block
))
2117 block
= BLOCK_SUPERBLOCK (block
);
2120 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2124 /* worker function (cleanup) */
2126 replace_comma (void *data
)
2134 trace_dump_command (char *args
, int from_tty
)
2136 struct regcache
*regcache
;
2137 struct gdbarch
*gdbarch
;
2138 struct breakpoint
*t
;
2139 struct action_line
*action
;
2140 char *action_exp
, *next_comma
;
2141 struct cleanup
*old_cleanups
;
2142 int stepping_actions
= 0;
2143 int stepping_frame
= 0;
2145 if (tracepoint_number
== -1)
2147 warning (_("No current trace frame."));
2151 t
= get_tracepoint (tracepoint_number
);
2154 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2157 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2159 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2160 tracepoint_number
, traceframe_number
);
2162 /* The current frame is a trap frame if the frame PC is equal
2163 to the tracepoint PC. If not, then the current frame was
2164 collected during single-stepping. */
2166 regcache
= get_current_regcache ();
2167 gdbarch
= get_regcache_arch (regcache
);
2169 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)));
2171 for (action
= t
->actions
; action
; action
= action
->next
)
2173 struct cmd_list_element
*cmd
;
2175 QUIT
; /* allow user to bail out with ^C */
2176 action_exp
= action
->action
;
2177 while (isspace ((int) *action_exp
))
2180 /* The collection actions to be done while stepping are
2181 bracketed by the commands "while-stepping" and "end". */
2183 if (*action_exp
== '#') /* comment line */
2186 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2188 error (_("Bad action list item: %s"), action_exp
);
2190 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2191 stepping_actions
= 1;
2192 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2193 stepping_actions
= 0;
2194 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2196 /* Display the collected data.
2197 For the trap frame, display only what was collected at
2198 the trap. Likewise for stepping frames, display only
2199 what was collected while stepping. This means that the
2200 two boolean variables, STEPPING_FRAME and
2201 STEPPING_ACTIONS should be equal. */
2202 if (stepping_frame
== stepping_actions
)
2205 { /* repeat over a comma-separated list */
2206 QUIT
; /* allow user to bail out with ^C */
2207 if (*action_exp
== ',')
2209 while (isspace ((int) *action_exp
))
2212 next_comma
= strchr (action_exp
, ',');
2214 if (0 == strncasecmp (action_exp
, "$reg", 4))
2215 registers_info (NULL
, from_tty
);
2216 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2217 locals_info (NULL
, from_tty
);
2218 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2219 args_info (NULL
, from_tty
);
2224 make_cleanup (replace_comma
, next_comma
);
2227 printf_filtered ("%s = ", action_exp
);
2228 output_command (action_exp
, from_tty
);
2229 printf_filtered ("\n");
2233 action_exp
= next_comma
;
2235 while (action_exp
&& *action_exp
== ',');
2239 discard_cleanups (old_cleanups
);
2242 /* Tell the target what to do with an ongoing tracing run if GDB
2243 disconnects for some reason. */
2246 send_disconnected_tracing_value (int value
)
2248 target_set_disconnected_tracing (value
);
2252 set_disconnected_tracing (char *args
, int from_tty
,
2253 struct cmd_list_element
*c
)
2255 send_disconnected_tracing_value (disconnected_tracing
);
2258 /* Convert the memory pointed to by mem into hex, placing result in buf.
2259 * Return a pointer to the last char put in buf (null)
2260 * "stolen" from sparc-stub.c
2263 static const char hexchars
[] = "0123456789abcdef";
2266 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2274 *buf
++ = hexchars
[ch
>> 4];
2275 *buf
++ = hexchars
[ch
& 0xf];
2284 get_traceframe_number (void)
2286 return traceframe_number
;
2289 /* module initialization */
2291 _initialize_tracepoint (void)
2293 struct cmd_list_element
*c
;
2295 traceframe_number
= -1;
2296 tracepoint_number
= -1;
2298 if (tracepoint_list
.list
== NULL
)
2300 tracepoint_list
.listsize
= 128;
2301 tracepoint_list
.list
= xmalloc
2302 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2304 if (tracepoint_list
.aexpr_list
== NULL
)
2306 tracepoint_list
.aexpr_listsize
= 128;
2307 tracepoint_list
.aexpr_list
= xmalloc
2308 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2311 if (stepping_list
.list
== NULL
)
2313 stepping_list
.listsize
= 128;
2314 stepping_list
.list
= xmalloc
2315 (stepping_list
.listsize
* sizeof (struct memrange
));
2318 if (stepping_list
.aexpr_list
== NULL
)
2320 stepping_list
.aexpr_listsize
= 128;
2321 stepping_list
.aexpr_list
= xmalloc
2322 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2325 add_info ("scope", scope_info
,
2326 _("List the variables local to a scope"));
2328 add_cmd ("tracepoints", class_trace
, NULL
,
2329 _("Tracing of program execution without stopping the program."),
2332 add_com ("tdump", class_trace
, trace_dump_command
,
2333 _("Print everything collected at the current tracepoint."));
2335 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
2336 Define a trace state variable.\n\
2337 Argument is a $-prefixed name, optionally followed\n\
2338 by '=' and an expression that sets the initial value\n\
2339 at the start of tracing."));
2340 set_cmd_completer (c
, expression_completer
);
2342 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
2343 Delete one or more trace state variables.\n\
2344 Arguments are the names of the variables to delete.\n\
2345 If no arguments are supplied, delete all variables."), &deletelist
);
2346 /* FIXME add a trace variable completer */
2348 add_info ("tvariables", tvariables_info
, _("\
2349 Status of trace state variables and their values.\n\
2352 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2353 Select a trace frame;\n\
2354 No argument means forward by one frame; '-' means backward by one frame."),
2355 &tfindlist
, "tfind ", 1, &cmdlist
);
2357 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2358 Select a trace frame whose PC is outside the given range.\n\
2359 Usage: tfind outside addr1, addr2"),
2362 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2363 Select a trace frame whose PC is in the given range.\n\
2364 Usage: tfind range addr1,addr2"),
2367 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2368 Select a trace frame by source line.\n\
2369 Argument can be a line number (with optional source file), \n\
2370 a function name, or '*' followed by an address.\n\
2371 Default argument is 'the next source line that was traced'."),
2374 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2375 Select a trace frame by tracepoint number.\n\
2376 Default is the tracepoint for the current trace frame."),
2379 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2380 Select a trace frame by PC.\n\
2381 Default is the current PC, or the PC of the current trace frame."),
2384 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2385 Synonym for 'none'.\n\
2386 De-select any trace frame and resume 'live' debugging."),
2389 add_cmd ("none", class_trace
, trace_find_none_command
,
2390 _("De-select any trace frame and resume 'live' debugging."),
2393 add_cmd ("start", class_trace
, trace_find_start_command
,
2394 _("Select the first trace frame in the trace buffer."),
2397 add_com ("tstatus", class_trace
, trace_status_command
,
2398 _("Display the status of the current trace data collection."));
2400 add_com ("tstop", class_trace
, trace_stop_command
,
2401 _("Stop trace data collection."));
2403 add_com ("tstart", class_trace
, trace_start_command
,
2404 _("Start trace data collection."));
2406 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2407 Ends a list of commands or actions.\n\
2408 Several GDB commands allow you to enter a list of commands or actions.\n\
2409 Entering \"end\" on a line by itself is the normal way to terminate\n\
2411 Note: the \"end\" command cannot be used at the gdb prompt."));
2413 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2414 Specify single-stepping behavior at a tracepoint.\n\
2415 Argument is number of instructions to trace in single-step mode\n\
2416 following the tracepoint. This command is normally followed by\n\
2417 one or more \"collect\" commands, to specify what to collect\n\
2418 while single-stepping.\n\n\
2419 Note: this command can only be used in a tracepoint \"actions\" list."));
2421 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2422 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2424 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2425 Specify one or more data items to be collected at a tracepoint.\n\
2426 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2427 collect all data (variables, registers) referenced by that expression.\n\
2428 Also accepts the following special arguments:\n\
2429 $regs -- all registers.\n\
2430 $args -- all function arguments.\n\
2431 $locals -- all variables local to the block/function scope.\n\
2432 Note: this command can only be used in a tracepoint \"actions\" list."));
2434 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
2435 Specify one or more expressions to be evaluated at a tracepoint.\n\
2436 Accepts a comma-separated list of (one or more) expressions.\n\
2437 The result of each evaluation will be discarded.\n\
2438 Note: this command can only be used in a tracepoint \"actions\" list."));
2440 add_com ("actions", class_trace
, trace_actions_command
, _("\
2441 Specify the actions to be taken at a tracepoint.\n\
2442 Tracepoint actions may include collecting of specified data, \n\
2443 single-stepping, or enabling/disabling other tracepoints, \n\
2444 depending on target's capabilities."));
2446 default_collect
= xstrdup ("");
2447 add_setshow_string_cmd ("default-collect", class_trace
,
2448 &default_collect
, _("\
2449 Set the list of expressions to collect by default"), _("\
2450 Show the list of expressions to collect by default"), NULL
,
2452 &setlist
, &showlist
);
2454 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
2455 &disconnected_tracing
, _("\
2456 Set whether tracing continues after GDB disconnects."), _("\
2457 Show whether tracing continues after GDB disconnects."), _("\
2458 Use this to continue a tracing run even if GDB disconnects\n\
2459 or detaches from the target. You can reconnect later and look at\n\
2460 trace data collected in the meantime."),
2461 set_disconnected_tracing
,