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 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/>. */
25 #include "expression.h"
30 #include "gdb_string.h"
32 #include "breakpoint.h"
33 #include "tracepoint.h"
37 #include "completer.h"
39 #include "dictionary.h"
41 #include "user-regs.h"
48 /* readline include files */
49 #include "readline/readline.h"
50 #include "readline/history.h"
52 /* readline defines this. */
59 /* Maximum length of an agent aexpression.
60 This accounts for the fact that packets are limited to 400 bytes
61 (which includes everything -- including the checksum), and assumes
62 the worst case of maximum length for each of the pieces of a
65 NOTE: expressions get mem2hex'ed otherwise this would be twice as
66 large. (400 - 31)/2 == 184 */
67 #define MAX_AGENT_EXPR_LEN 184
70 extern void (*deprecated_readline_begin_hook
) (char *, ...);
71 extern char *(*deprecated_readline_hook
) (char *);
72 extern void (*deprecated_readline_end_hook
) (void);
74 /* GDB commands implemented in other modules:
77 extern void output_command (char *, int);
82 This module defines the following debugger commands:
83 trace : set a tracepoint on a function, line, or address.
84 info trace : list all debugger-defined tracepoints.
85 delete trace : delete one or more tracepoints.
86 enable trace : enable one or more tracepoints.
87 disable trace : disable one or more tracepoints.
88 actions : specify actions to be taken at a tracepoint.
89 passcount : specify a pass count for a tracepoint.
90 tstart : start a trace experiment.
91 tstop : stop a trace experiment.
92 tstatus : query the status of a trace experiment.
93 tfind : find a trace frame in the trace buffer.
94 tdump : print everything collected at the current tracepoint.
95 save-tracepoints : write tracepoint setup into a file.
97 This module defines the following user-visible debugger variables:
98 $trace_frame : sequence number of trace frame currently being debugged.
99 $trace_line : source line of trace frame currently being debugged.
100 $trace_file : source file of trace frame currently being debugged.
101 $tracepoint : tracepoint number of trace frame currently being debugged.
105 /* ======= Important global variables: ======= */
107 /* Number of last traceframe collected. */
108 static int traceframe_number
;
110 /* Tracepoint for last traceframe collected. */
111 static int tracepoint_number
;
113 /* Symbol for function for last traceframe collected */
114 static struct symbol
*traceframe_fun
;
116 /* Symtab and line for last traceframe collected */
117 static struct symtab_and_line traceframe_sal
;
119 /* Tracing command lists */
120 static struct cmd_list_element
*tfindlist
;
122 /* ======= Important command functions: ======= */
123 static void trace_actions_command (char *, int);
124 static void trace_start_command (char *, int);
125 static void trace_stop_command (char *, int);
126 static void trace_status_command (char *, int);
127 static void trace_find_command (char *, int);
128 static void trace_find_pc_command (char *, int);
129 static void trace_find_tracepoint_command (char *, int);
130 static void trace_find_line_command (char *, int);
131 static void trace_find_range_command (char *, int);
132 static void trace_find_outside_command (char *, int);
133 static void tracepoint_save_command (char *, int);
134 static void trace_dump_command (char *, int);
136 /* support routines */
138 struct collection_list
;
139 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
140 static char *mem2hex (gdb_byte
*, char *, int);
141 static void add_register (struct collection_list
*collection
,
143 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
144 static void free_actions_list (char **actions_list
);
145 static void free_actions_list_cleanup_wrapper (void *);
147 extern void _initialize_tracepoint (void);
149 /* Utility: returns true if "target remote" */
151 target_is_remote (void)
153 if (current_target
.to_shortname
&&
154 (strcmp (current_target
.to_shortname
, "remote") == 0
155 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
161 /* Utility: generate error from an incoming stub packet. */
163 trace_error (char *buf
)
166 return; /* not an error msg */
169 case '1': /* malformed packet error */
170 if (*++buf
== '0') /* general case: */
171 error (_("tracepoint.c: error in outgoing packet."));
173 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
174 strtol (buf
, NULL
, 16));
176 error (_("trace API error 0x%s."), ++buf
);
178 error (_("Target returns error code '%s'."), buf
);
182 /* Utility: wait for reply from stub, while accepting "O" packets. */
184 remote_get_noisy_reply (char **buf_p
,
187 do /* Loop on reply from remote stub. */
190 QUIT
; /* allow user to bail out with ^C */
191 getpkt (buf_p
, sizeof_buf
, 0);
194 error (_("Target does not support this command."));
195 else if (buf
[0] == 'E')
197 else if (buf
[0] == 'O' &&
199 remote_console_output (buf
+ 1); /* 'O' message from stub */
201 return buf
; /* here's the actual reply */
206 /* Set traceframe number to NUM. */
208 set_traceframe_num (int num
)
210 traceframe_number
= num
;
211 set_internalvar (lookup_internalvar ("trace_frame"),
212 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
215 /* Set tracepoint number to NUM. */
217 set_tracepoint_num (int num
)
219 tracepoint_number
= num
;
220 set_internalvar (lookup_internalvar ("tracepoint"),
221 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
224 /* Set externally visible debug variables for querying/printing
225 the traceframe context (line, function, file) */
228 set_traceframe_context (struct frame_info
*trace_frame
)
232 static struct type
*func_string
, *file_string
;
233 static struct type
*func_range
, *file_range
;
234 struct value
*func_val
;
235 struct value
*file_val
;
238 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
241 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
242 traceframe_sal
.symtab
= NULL
;
243 set_internalvar (lookup_internalvar ("trace_func"),
244 allocate_value (builtin_type_void
));
245 set_internalvar (lookup_internalvar ("trace_file"),
246 allocate_value (builtin_type_void
));
247 set_internalvar (lookup_internalvar ("trace_line"),
248 value_from_longest (builtin_type_int32
,
253 /* Save as globals for internal use. */
254 trace_pc
= get_frame_pc (trace_frame
);
255 traceframe_sal
= find_pc_line (trace_pc
, 0);
256 traceframe_fun
= find_pc_function (trace_pc
);
258 /* Save linenumber as "$trace_line", a debugger variable visible to
260 set_internalvar (lookup_internalvar ("trace_line"),
261 value_from_longest (builtin_type_int32
,
262 (LONGEST
) traceframe_sal
.line
));
264 /* Save func name as "$trace_func", a debugger variable visible to
266 if (traceframe_fun
== NULL
||
267 SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
268 set_internalvar (lookup_internalvar ("trace_func"),
269 allocate_value (builtin_type_void
));
272 len
= strlen (SYMBOL_LINKAGE_NAME (traceframe_fun
));
273 func_range
= create_range_type (func_range
,
274 builtin_type_int32
, 0, len
- 1);
275 func_string
= create_array_type (func_string
,
276 builtin_type_true_char
, func_range
);
277 func_val
= allocate_value (func_string
);
278 deprecated_set_value_type (func_val
, func_string
);
279 memcpy (value_contents_raw (func_val
),
280 SYMBOL_LINKAGE_NAME (traceframe_fun
),
282 deprecated_set_value_modifiable (func_val
, 0);
283 set_internalvar (lookup_internalvar ("trace_func"), func_val
);
286 /* Save file name as "$trace_file", a debugger variable visible to
288 if (traceframe_sal
.symtab
== NULL
||
289 traceframe_sal
.symtab
->filename
== NULL
)
290 set_internalvar (lookup_internalvar ("trace_file"),
291 allocate_value (builtin_type_void
));
294 len
= strlen (traceframe_sal
.symtab
->filename
);
295 file_range
= create_range_type (file_range
,
296 builtin_type_int32
, 0, len
- 1);
297 file_string
= create_array_type (file_string
,
298 builtin_type_true_char
, file_range
);
299 file_val
= allocate_value (file_string
);
300 deprecated_set_value_type (file_val
, file_string
);
301 memcpy (value_contents_raw (file_val
),
302 traceframe_sal
.symtab
->filename
,
304 deprecated_set_value_modifiable (file_val
, 0);
305 set_internalvar (lookup_internalvar ("trace_file"), file_val
);
309 /* ACTIONS functions: */
311 /* Prototypes for action-parsing utility commands */
312 static void read_actions (struct breakpoint
*);
314 /* The three functions:
315 collect_pseudocommand,
316 while_stepping_pseudocommand, and
317 end_actions_pseudocommand
318 are placeholders for "commands" that are actually ONLY to be used
319 within a tracepoint action list. If the actual function is ever called,
320 it means that somebody issued the "command" at the top level,
321 which is always an error. */
324 end_actions_pseudocommand (char *args
, int from_tty
)
326 error (_("This command cannot be used at the top level."));
330 while_stepping_pseudocommand (char *args
, int from_tty
)
332 error (_("This command can only be used in a tracepoint actions list."));
336 collect_pseudocommand (char *args
, int from_tty
)
338 error (_("This command can only be used in a tracepoint actions list."));
341 /* Enter a list of actions for a tracepoint. */
343 trace_actions_command (char *args
, int from_tty
)
345 struct breakpoint
*t
;
347 char *end_msg
= "End with a line saying just \"end\".";
349 t
= get_tracepoint_by_number (&args
, 0, 1);
352 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
357 if (deprecated_readline_begin_hook
)
358 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
359 else if (input_from_terminal_p ())
360 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
364 t
->step_count
= 0; /* read_actions may set this */
367 if (deprecated_readline_end_hook
)
368 (*deprecated_readline_end_hook
) ();
369 /* tracepoints_changed () */
371 /* else just return */
374 /* worker function */
376 read_actions (struct breakpoint
*t
)
379 char *prompt1
= "> ", *prompt2
= " > ";
380 char *prompt
= prompt1
;
381 enum actionline_type linetype
;
382 extern FILE *instream
;
383 struct action_line
*next
= NULL
, *temp
;
384 struct cleanup
*old_chain
;
386 /* Control-C quits instantly if typed while in this loop
387 since it should not wait until the user types a newline. */
389 /* FIXME: kettenis/20010823: Something is wrong here. In this file
390 STOP_SIGNAL is never defined. So this code has been left out, at
391 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
392 leads to compilation failures since the variable job_control
393 isn't declared. Leave this alone for now. */
396 signal (STOP_SIGNAL
, handle_stop_sig
);
398 old_chain
= make_cleanup_free_actions (t
);
401 /* Make sure that all output has been output. Some machines may
402 let you get away with leaving out some of the gdb_flush, but
405 gdb_flush (gdb_stdout
);
406 gdb_flush (gdb_stderr
);
408 if (deprecated_readline_hook
&& instream
== NULL
)
409 line
= (*deprecated_readline_hook
) (prompt
);
410 else if (instream
== stdin
&& ISATTY (instream
))
412 line
= gdb_readline_wrapper (prompt
);
413 if (line
&& *line
) /* add it to command history */
417 line
= gdb_readline (0);
421 line
= xstrdup ("end");
422 printf_filtered ("end\n");
425 linetype
= validate_actionline (&line
, t
);
426 if (linetype
== BADLINE
)
427 continue; /* already warned -- collect another line */
429 temp
= xmalloc (sizeof (struct action_line
));
433 if (next
== NULL
) /* first action for this tracepoint? */
434 t
->actions
= next
= temp
;
441 if (linetype
== STEPPING
) /* begin "while-stepping" */
443 if (prompt
== prompt2
)
445 warning (_("Already processing 'while-stepping'"));
449 prompt
= prompt2
; /* change prompt for stepping actions */
451 else if (linetype
== END
)
453 if (prompt
== prompt2
)
455 prompt
= prompt1
; /* end of single-stepping actions */
458 { /* end of actions */
459 if (t
->actions
->next
== NULL
)
461 /* An "end" all by itself with no other actions
462 means this tracepoint has no actions.
463 Discard empty list. */
472 signal (STOP_SIGNAL
, SIG_DFL
);
475 discard_cleanups (old_chain
);
478 /* worker function */
480 validate_actionline (char **line
, struct breakpoint
*t
)
482 struct cmd_list_element
*c
;
483 struct expression
*exp
= NULL
;
484 struct cleanup
*old_chain
= NULL
;
487 /* if EOF is typed, *line is NULL */
491 for (p
= *line
; isspace ((int) *p
);)
494 /* Symbol lookup etc. */
495 if (*p
== '\0') /* empty line: just prompt for another line. */
498 if (*p
== '#') /* comment line */
501 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
504 warning (_("'%s' is not an action that I know, or is ambiguous."),
509 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
511 struct agent_expr
*aexpr
;
512 struct agent_reqs areqs
;
515 { /* repeat over a comma-separated list */
516 QUIT
; /* allow user to bail out with ^C */
517 while (isspace ((int) *p
))
520 if (*p
== '$') /* look for special pseudo-symbols */
522 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
523 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
524 (0 == strncasecmp ("loc", p
+ 1, 3)))
529 /* else fall thru, treat p as an expression and parse it! */
531 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
532 old_chain
= make_cleanup (free_current_contents
, &exp
);
534 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
536 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
538 warning (_("constant %s (value %ld) will not be collected."),
539 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
540 SYMBOL_VALUE (exp
->elts
[2].symbol
));
543 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
545 warning (_("%s is optimized away and cannot be collected."),
546 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
551 /* We have something to collect, make sure that the expr to
552 bytecode translator can handle it and that it's not too
554 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
555 make_cleanup_free_agent_expr (aexpr
);
557 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
558 error (_("expression too complicated, try simplifying"));
560 ax_reqs (aexpr
, &areqs
);
561 (void) make_cleanup (xfree
, areqs
.reg_mask
);
563 if (areqs
.flaw
!= agent_flaw_none
)
564 error (_("malformed expression"));
566 if (areqs
.min_height
< 0)
567 error (_("gdb: Internal error: expression has min height < 0"));
569 if (areqs
.max_height
> 20)
570 error (_("expression too complicated, try simplifying"));
572 do_cleanups (old_chain
);
574 while (p
&& *p
++ == ',');
577 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
579 char *steparg
; /* in case warning is necessary */
581 while (isspace ((int) *p
))
586 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
588 warning (_("'%s': bad step-count; command ignored."), *line
);
593 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
597 warning (_("'%s' is not a supported tracepoint action."), *line
);
602 /* worker function */
604 free_actions (struct breakpoint
*t
)
606 struct action_line
*line
, *next
;
608 for (line
= t
->actions
; line
; line
= next
)
612 xfree (line
->action
);
619 do_free_actions_cleanup (void *t
)
624 static struct cleanup
*
625 make_cleanup_free_actions (struct breakpoint
*t
)
627 return make_cleanup (do_free_actions_cleanup
, t
);
631 memrange_absolute
= -1
636 int type
; /* memrange_absolute for absolute memory range,
637 else basereg number */
638 bfd_signed_vma start
;
642 struct collection_list
644 unsigned char regs_mask
[32]; /* room for up to 256 regs */
647 struct memrange
*list
;
648 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
650 struct agent_expr
**aexpr_list
;
653 tracepoint_list
, stepping_list
;
655 /* MEMRANGE functions: */
657 static int memrange_cmp (const void *, const void *);
659 /* compare memranges for qsort */
661 memrange_cmp (const void *va
, const void *vb
)
663 const struct memrange
*a
= va
, *b
= vb
;
665 if (a
->type
< b
->type
)
667 if (a
->type
> b
->type
)
669 if (a
->type
== memrange_absolute
)
671 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
673 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
678 if (a
->start
< b
->start
)
680 if (a
->start
> b
->start
)
686 /* Sort the memrange list using qsort, and merge adjacent memranges. */
688 memrange_sortmerge (struct collection_list
*memranges
)
692 qsort (memranges
->list
, memranges
->next_memrange
,
693 sizeof (struct memrange
), memrange_cmp
);
694 if (memranges
->next_memrange
> 0)
696 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
698 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
699 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
702 /* memrange b starts before memrange a ends; merge them. */
703 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
704 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
705 continue; /* next b, same a */
709 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
710 sizeof (struct memrange
));
712 memranges
->next_memrange
= a
+ 1;
716 /* Add a register to a collection list. */
718 add_register (struct collection_list
*collection
, unsigned int regno
)
721 printf_filtered ("collect register %d\n", regno
);
722 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
723 error (_("Internal: register number %d too large for tracepoint"),
725 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
728 /* Add a memrange to a collection list */
730 add_memrange (struct collection_list
*memranges
,
731 int type
, bfd_signed_vma base
,
736 printf_filtered ("(%d,", type
);
738 printf_filtered (",%ld)\n", len
);
741 /* type: memrange_absolute == memory, other n == basereg */
742 memranges
->list
[memranges
->next_memrange
].type
= type
;
743 /* base: addr if memory, offset if reg relative. */
744 memranges
->list
[memranges
->next_memrange
].start
= base
;
745 /* len: we actually save end (base + len) for convenience */
746 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
747 memranges
->next_memrange
++;
748 if (memranges
->next_memrange
>= memranges
->listsize
)
750 memranges
->listsize
*= 2;
751 memranges
->list
= xrealloc (memranges
->list
,
752 memranges
->listsize
);
755 if (type
!= memrange_absolute
) /* Better collect the base register! */
756 add_register (memranges
, type
);
759 /* Add a symbol to a collection list. */
761 collect_symbol (struct collection_list
*collect
,
763 long frame_regno
, long frame_offset
)
767 bfd_signed_vma offset
;
769 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
770 switch (SYMBOL_CLASS (sym
))
773 printf_filtered ("%s: don't know symbol class %d\n",
774 SYMBOL_PRINT_NAME (sym
),
778 printf_filtered ("constant %s (value %ld) will not be collected.\n",
779 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
782 offset
= SYMBOL_VALUE_ADDRESS (sym
);
787 sprintf_vma (tmp
, offset
);
788 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
789 SYMBOL_PRINT_NAME (sym
), len
,
792 add_memrange (collect
, memrange_absolute
, offset
, len
);
795 reg
= SYMBOL_VALUE (sym
);
797 printf_filtered ("LOC_REG[parm] %s: ",
798 SYMBOL_PRINT_NAME (sym
));
799 add_register (collect
, reg
);
800 /* Check for doubles stored in two registers. */
801 /* FIXME: how about larger types stored in 3 or more regs? */
802 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
803 len
> register_size (current_gdbarch
, reg
))
804 add_register (collect
, reg
+ 1);
807 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
808 printf_filtered (" (will not collect %s)\n",
809 SYMBOL_PRINT_NAME (sym
));
813 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
816 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
817 SYMBOL_PRINT_NAME (sym
), len
);
819 printf_filtered (" from frame ptr reg %d\n", reg
);
821 add_memrange (collect
, reg
, offset
, len
);
823 case LOC_REGPARM_ADDR
:
824 reg
= SYMBOL_VALUE (sym
);
828 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
829 SYMBOL_PRINT_NAME (sym
), len
);
831 printf_filtered (" from reg %d\n", reg
);
833 add_memrange (collect
, reg
, offset
, len
);
837 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
840 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
841 SYMBOL_PRINT_NAME (sym
), len
);
843 printf_filtered (" from frame ptr reg %d\n", reg
);
845 add_memrange (collect
, reg
, offset
, len
);
848 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
849 SYMBOL_PRINT_NAME (sym
));
851 case LOC_OPTIMIZED_OUT
:
852 printf_filtered ("%s has been optimized out of existence.\n",
853 SYMBOL_PRINT_NAME (sym
));
858 /* Add all locals (or args) symbols to collection list */
860 add_local_symbols (struct collection_list
*collect
, CORE_ADDR pc
,
861 long frame_regno
, long frame_offset
, int type
)
865 struct dict_iterator iter
;
868 block
= block_for_pc (pc
);
871 QUIT
; /* allow user to bail out with ^C */
872 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
874 if (SYMBOL_IS_ARGUMENT (sym
)
875 ? type
== 'A' /* collecting Arguments */
876 : type
== 'L') /* collecting Locals */
879 collect_symbol (collect
, sym
, frame_regno
,
883 if (BLOCK_FUNCTION (block
))
886 block
= BLOCK_SUPERBLOCK (block
);
889 warning (_("No %s found in scope."),
890 type
== 'L' ? "locals" : "args");
893 /* worker function */
895 clear_collection_list (struct collection_list
*list
)
899 list
->next_memrange
= 0;
900 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
902 free_agent_expr (list
->aexpr_list
[ndx
]);
903 list
->aexpr_list
[ndx
] = NULL
;
905 list
->next_aexpr_elt
= 0;
906 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
909 /* reduce a collection list to string form (for gdb protocol) */
911 stringify_collection_list (struct collection_list
*list
, char *string
)
921 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
922 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
924 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
925 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
927 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
930 printf_filtered ("\nCollecting registers (mask): 0x");
935 QUIT
; /* allow user to bail out with ^C */
937 printf_filtered ("%02X", list
->regs_mask
[i
]);
938 sprintf (end
, "%02X", list
->regs_mask
[i
]);
941 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
945 printf_filtered ("\n");
946 if (list
->next_memrange
> 0 && info_verbose
)
947 printf_filtered ("Collecting memranges: \n");
948 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
950 QUIT
; /* allow user to bail out with ^C */
951 sprintf_vma (tmp2
, list
->list
[i
].start
);
954 printf_filtered ("(%d, %s, %ld)\n",
957 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
959 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
961 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
968 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
970 /* The "%X" conversion specifier expects an unsigned argument,
971 so passing -1 (memrange_absolute) to it directly gives you
972 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
974 if (list
->list
[i
].type
== memrange_absolute
)
975 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
977 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
980 count
+= strlen (end
);
981 end
= temp_buf
+ count
;
984 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
986 QUIT
; /* allow user to bail out with ^C */
987 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
989 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
994 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
995 end
+= 10; /* 'X' + 8 hex digits + ',' */
998 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
999 end
, list
->aexpr_list
[i
]->len
);
1000 count
+= 2 * list
->aexpr_list
[i
]->len
;
1005 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1010 (*str_list
)[ndx
] = NULL
;
1022 free_actions_list_cleanup_wrapper (void *al
)
1024 free_actions_list (al
);
1028 free_actions_list (char **actions_list
)
1032 if (actions_list
== 0)
1035 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1036 xfree (actions_list
[ndx
]);
1038 xfree (actions_list
);
1041 /* Render all actions into gdb protocol. */
1043 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1044 char ***stepping_actions
)
1046 static char tdp_buff
[2048], step_buff
[2048];
1048 struct expression
*exp
= NULL
;
1049 struct action_line
*action
;
1051 struct value
*tempval
;
1052 struct collection_list
*collect
;
1053 struct cmd_list_element
*cmd
;
1054 struct agent_expr
*aexpr
;
1056 LONGEST frame_offset
;
1059 clear_collection_list (&tracepoint_list
);
1060 clear_collection_list (&stepping_list
);
1061 collect
= &tracepoint_list
;
1063 *tdp_actions
= NULL
;
1064 *stepping_actions
= NULL
;
1066 gdbarch_virtual_frame_pointer (current_gdbarch
,
1067 t
->loc
->address
, &frame_reg
, &frame_offset
);
1069 for (action
= t
->actions
; action
; action
= action
->next
)
1071 QUIT
; /* allow user to bail out with ^C */
1072 action_exp
= action
->action
;
1073 while (isspace ((int) *action_exp
))
1076 if (*action_exp
== '#') /* comment line */
1079 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1081 error (_("Bad action list item: %s"), action_exp
);
1083 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1086 { /* repeat over a comma-separated list */
1087 QUIT
; /* allow user to bail out with ^C */
1088 while (isspace ((int) *action_exp
))
1091 if (0 == strncasecmp ("$reg", action_exp
, 4))
1093 for (i
= 0; i
< gdbarch_num_regs (current_gdbarch
); i
++)
1094 add_register (collect
, i
);
1095 action_exp
= strchr (action_exp
, ','); /* more? */
1097 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1099 add_local_symbols (collect
,
1104 action_exp
= strchr (action_exp
, ','); /* more? */
1106 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1108 add_local_symbols (collect
,
1113 action_exp
= strchr (action_exp
, ','); /* more? */
1117 unsigned long addr
, len
;
1118 struct cleanup
*old_chain
= NULL
;
1119 struct cleanup
*old_chain1
= NULL
;
1120 struct agent_reqs areqs
;
1122 exp
= parse_exp_1 (&action_exp
,
1123 block_for_pc (t
->loc
->address
), 1);
1124 old_chain
= make_cleanup (free_current_contents
, &exp
);
1126 switch (exp
->elts
[0].opcode
)
1130 const char *name
= &exp
->elts
[2].string
;
1132 i
= user_reg_map_name_to_regnum (current_gdbarch
,
1133 name
, strlen (name
));
1135 internal_error (__FILE__
, __LINE__
,
1136 _("Register $%s not available"),
1139 printf_filtered ("OP_REGISTER: ");
1140 add_register (collect
, i
);
1145 /* safe because we know it's a simple expression */
1146 tempval
= evaluate_expression (exp
);
1147 addr
= VALUE_ADDRESS (tempval
) + value_offset (tempval
);
1148 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1149 add_memrange (collect
, memrange_absolute
, addr
, len
);
1153 collect_symbol (collect
,
1154 exp
->elts
[2].symbol
,
1159 default: /* full-fledged expression */
1160 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1162 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1164 ax_reqs (aexpr
, &areqs
);
1165 if (areqs
.flaw
!= agent_flaw_none
)
1166 error (_("malformed expression"));
1168 if (areqs
.min_height
< 0)
1169 error (_("gdb: Internal error: expression has min height < 0"));
1170 if (areqs
.max_height
> 20)
1171 error (_("expression too complicated, try simplifying"));
1173 discard_cleanups (old_chain1
);
1174 add_aexpr (collect
, aexpr
);
1176 /* take care of the registers */
1177 if (areqs
.reg_mask_len
> 0)
1182 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1184 QUIT
; /* allow user to bail out with ^C */
1185 if (areqs
.reg_mask
[ndx1
] != 0)
1187 /* assume chars have 8 bits */
1188 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1189 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1190 /* it's used -- record it */
1191 add_register (collect
,
1198 do_cleanups (old_chain
);
1201 while (action_exp
&& *action_exp
++ == ',');
1203 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1205 collect
= &stepping_list
;
1207 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1209 if (collect
== &stepping_list
) /* end stepping actions */
1210 collect
= &tracepoint_list
;
1212 break; /* end tracepoint actions */
1215 memrange_sortmerge (&tracepoint_list
);
1216 memrange_sortmerge (&stepping_list
);
1218 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1220 *stepping_actions
= stringify_collection_list (&stepping_list
,
1225 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1227 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1229 collect
->aexpr_list
=
1230 xrealloc (collect
->aexpr_list
,
1231 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1232 collect
->aexpr_listsize
*= 2;
1234 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1235 collect
->next_aexpr_elt
++;
1238 static char *target_buf
;
1239 static long target_buf_size
;
1241 /* Set "transparent" memory ranges
1243 Allow trace mechanism to treat text-like sections
1244 (and perhaps all read-only sections) transparently,
1245 i.e. don't reject memory requests from these address ranges
1246 just because they haven't been collected. */
1249 remote_set_transparent_ranges (void)
1257 return; /* No information to give. */
1259 strcpy (target_buf
, "QTro");
1260 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1262 char tmp1
[40], tmp2
[40];
1264 if ((s
->flags
& SEC_LOAD
) == 0 ||
1265 /* (s->flags & SEC_CODE) == 0 || */
1266 (s
->flags
& SEC_READONLY
) == 0)
1271 size
= bfd_get_section_size (s
);
1272 sprintf_vma (tmp1
, lma
);
1273 sprintf_vma (tmp2
, lma
+ size
);
1274 sprintf (target_buf
+ strlen (target_buf
),
1275 ":%s,%s", tmp1
, tmp2
);
1279 putpkt (target_buf
);
1280 getpkt (&target_buf
, &target_buf_size
, 0);
1286 Tell target to clear any previous trace experiment.
1287 Walk the list of tracepoints, and send them (and their actions)
1288 to the target. If no errors,
1289 Tell target to start a new trace experiment. */
1291 void download_tracepoint (struct breakpoint
*t
);
1294 trace_start_command (char *args
, int from_tty
)
1296 VEC(breakpoint_p
) *tp_vec
= NULL
;
1298 struct breakpoint
*t
;
1300 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1302 if (target_is_remote ())
1305 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1306 if (strcmp (target_buf
, "OK"))
1307 error (_("Target does not support this command."));
1309 tp_vec
= all_tracepoints ();
1310 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1312 download_tracepoint (t
);
1314 VEC_free (breakpoint_p
, tp_vec
);
1316 /* Tell target to treat text-like sections as transparent. */
1317 remote_set_transparent_ranges ();
1318 /* Now insert traps and begin collecting data. */
1320 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1321 if (strcmp (target_buf
, "OK"))
1322 error (_("Bogus reply from target: %s"), target_buf
);
1323 set_traceframe_num (-1); /* All old traceframes invalidated. */
1324 set_tracepoint_num (-1);
1325 set_traceframe_context (NULL
);
1326 trace_running_p
= 1;
1327 if (deprecated_trace_start_stop_hook
)
1328 deprecated_trace_start_stop_hook (1, from_tty
);
1332 error (_("Trace can only be run on remote targets."));
1335 /* Send the definition of a single tracepoint to the target. */
1338 download_tracepoint (struct breakpoint
*t
)
1343 char **stepping_actions
;
1345 struct cleanup
*old_chain
= NULL
;
1347 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1348 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1350 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1351 t
->step_count
, t
->pass_count
);
1356 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1357 if (strcmp (target_buf
, "OK"))
1358 error (_("Target does not support tracepoints."));
1363 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1364 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1366 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1368 /* do_single_steps (t); */
1371 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1373 QUIT
; /* allow user to bail out with ^C */
1374 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1375 t
->number
, tmp
, /* address */
1377 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1380 remote_get_noisy_reply (&target_buf
,
1382 if (strcmp (target_buf
, "OK"))
1383 error (_("Error on target while setting tracepoints."));
1386 if (stepping_actions
)
1388 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1390 QUIT
; /* allow user to bail out with ^C */
1391 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1392 t
->number
, tmp
, /* address */
1393 ((ndx
== 0) ? "S" : ""),
1394 stepping_actions
[ndx
],
1395 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1397 remote_get_noisy_reply (&target_buf
,
1399 if (strcmp (target_buf
, "OK"))
1400 error (_("Error on target while setting tracepoints."));
1403 do_cleanups (old_chain
);
1408 trace_stop_command (char *args
, int from_tty
)
1410 if (target_is_remote ())
1413 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1414 if (strcmp (target_buf
, "OK"))
1415 error (_("Bogus reply from target: %s"), target_buf
);
1416 trace_running_p
= 0;
1417 if (deprecated_trace_start_stop_hook
)
1418 deprecated_trace_start_stop_hook (0, from_tty
);
1421 error (_("Trace can only be run on remote targets."));
1424 unsigned long trace_running_p
;
1426 /* tstatus command */
1428 trace_status_command (char *args
, int from_tty
)
1430 if (target_is_remote ())
1432 putpkt ("qTStatus");
1433 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1435 if (target_buf
[0] != 'T' ||
1436 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1437 error (_("Bogus reply from target: %s"), target_buf
);
1439 /* exported for use by the GUI */
1440 trace_running_p
= (target_buf
[1] == '1');
1443 error (_("Trace can only be run on remote targets."));
1446 /* Worker function for the various flavors of the tfind command. */
1448 finish_tfind_command (char **msg
,
1452 int target_frameno
= -1, target_tracept
= -1;
1453 struct frame_id old_frame_id
;
1456 old_frame_id
= get_frame_id (get_current_frame ());
1459 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1461 while (reply
&& *reply
)
1465 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1467 /* A request for a non-existant trace frame has failed.
1468 Our response will be different, depending on FROM_TTY:
1470 If FROM_TTY is true, meaning that this command was
1471 typed interactively by the user, then give an error
1472 and DO NOT change the state of traceframe_number etc.
1474 However if FROM_TTY is false, meaning that we're either
1475 in a script, a loop, or a user-defined command, then
1476 DON'T give an error, but DO change the state of
1477 traceframe_number etc. to invalid.
1479 The rationalle is that if you typed the command, you
1480 might just have committed a typo or something, and you'd
1481 like to NOT lose your current debugging state. However
1482 if you're in a user-defined command or especially in a
1483 loop, then you need a way to detect that the command
1484 failed WITHOUT aborting. This allows you to write
1485 scripts that search thru the trace buffer until the end,
1486 and then continue on to do something else. */
1489 error (_("Target failed to find requested trace frame."));
1493 printf_filtered ("End of trace buffer.\n");
1494 /* The following will not recurse, since it's
1496 trace_find_command ("-1", from_tty
);
1497 reply
= NULL
; /* Break out of loop
1498 (avoid recursive nonsense). */
1503 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1504 error (_("Target failed to find requested trace frame."));
1506 case 'O': /* "OK"? */
1507 if (reply
[1] == 'K' && reply
[2] == '\0')
1510 error (_("Bogus reply from target: %s"), reply
);
1513 error (_("Bogus reply from target: %s"), reply
);
1516 reinit_frame_cache ();
1517 registers_changed ();
1518 set_traceframe_num (target_frameno
);
1519 set_tracepoint_num (target_tracept
);
1520 if (target_frameno
== -1)
1521 set_traceframe_context (NULL
);
1523 set_traceframe_context (get_current_frame ());
1527 enum print_what print_what
;
1529 /* NOTE: in immitation of the step command, try to determine
1530 whether we have made a transition from one function to
1531 another. If so, we'll print the "stack frame" (ie. the new
1532 function and it's arguments) -- otherwise we'll just show the
1535 if (frame_id_eq (old_frame_id
,
1536 get_frame_id (get_current_frame ())))
1537 print_what
= SRC_LINE
;
1539 print_what
= SRC_AND_LOC
;
1541 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1546 /* trace_find_command takes a trace frame number n,
1547 sends "QTFrame:<n>" to the target,
1548 and accepts a reply that may contain several optional pieces
1549 of information: a frame number, a tracepoint number, and an
1550 indication of whether this is a trap frame or a stepping frame.
1552 The minimal response is just "OK" (which indicates that the
1553 target does not give us a frame number or a tracepoint number).
1554 Instead of that, the target may send us a string containing
1556 F<hexnum> (gives the selected frame number)
1557 T<hexnum> (gives the selected tracepoint number)
1562 trace_find_command (char *args
, int from_tty
)
1563 { /* this should only be called with a numeric argument */
1566 if (target_is_remote ())
1568 if (deprecated_trace_find_hook
)
1569 deprecated_trace_find_hook (args
, from_tty
);
1571 if (args
== 0 || *args
== 0)
1572 { /* TFIND with no args means find NEXT trace frame. */
1573 if (traceframe_number
== -1)
1574 frameno
= 0; /* "next" is first one */
1576 frameno
= traceframe_number
+ 1;
1578 else if (0 == strcmp (args
, "-"))
1580 if (traceframe_number
== -1)
1581 error (_("not debugging trace buffer"));
1582 else if (from_tty
&& traceframe_number
== 0)
1583 error (_("already at start of trace buffer"));
1585 frameno
= traceframe_number
- 1;
1588 frameno
= parse_and_eval_long (args
);
1591 error (_("invalid input (%d is less than zero)"), frameno
);
1593 sprintf (target_buf
, "QTFrame:%x", frameno
);
1594 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1597 error (_("Trace can only be run on remote targets."));
1602 trace_find_end_command (char *args
, int from_tty
)
1604 trace_find_command ("-1", from_tty
);
1609 trace_find_none_command (char *args
, int from_tty
)
1611 trace_find_command ("-1", from_tty
);
1616 trace_find_start_command (char *args
, int from_tty
)
1618 trace_find_command ("0", from_tty
);
1621 /* tfind pc command */
1623 trace_find_pc_command (char *args
, int from_tty
)
1628 if (target_is_remote ())
1630 if (args
== 0 || *args
== 0)
1631 pc
= regcache_read_pc (get_current_regcache ());
1633 pc
= parse_and_eval_address (args
);
1635 sprintf_vma (tmp
, pc
);
1636 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
1637 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1640 error (_("Trace can only be run on remote targets."));
1643 /* tfind tracepoint command */
1645 trace_find_tracepoint_command (char *args
, int from_tty
)
1649 if (target_is_remote ())
1651 if (args
== 0 || *args
== 0)
1653 if (tracepoint_number
== -1)
1654 error (_("No current tracepoint -- please supply an argument."));
1656 tdp
= tracepoint_number
; /* default is current TDP */
1659 tdp
= parse_and_eval_long (args
);
1661 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1662 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1665 error (_("Trace can only be run on remote targets."));
1668 /* TFIND LINE command:
1670 This command will take a sourceline for argument, just like BREAK
1671 or TRACE (ie. anything that "decode_line_1" can handle).
1673 With no argument, this command will find the next trace frame
1674 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1677 trace_find_line_command (char *args
, int from_tty
)
1679 static CORE_ADDR start_pc
, end_pc
;
1680 struct symtabs_and_lines sals
;
1681 struct symtab_and_line sal
;
1682 struct cleanup
*old_chain
;
1683 char startpc_str
[40], endpc_str
[40];
1685 if (target_is_remote ())
1687 if (args
== 0 || *args
== 0)
1689 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1691 sals
.sals
= (struct symtab_and_line
*)
1692 xmalloc (sizeof (struct symtab_and_line
));
1697 sals
= decode_line_spec (args
, 1);
1701 old_chain
= make_cleanup (xfree
, sals
.sals
);
1702 if (sal
.symtab
== 0)
1704 printf_filtered ("TFIND: No line number information available");
1707 /* This is useful for "info line *0x7f34". If we can't
1708 tell the user about a source line, at least let them
1709 have the symbolic address. */
1710 printf_filtered (" for address ");
1712 print_address (sal
.pc
, gdb_stdout
);
1713 printf_filtered (";\n -- will attempt to find by PC. \n");
1717 printf_filtered (".\n");
1718 return; /* No line, no PC; what can we do? */
1721 else if (sal
.line
> 0
1722 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1724 if (start_pc
== end_pc
)
1726 printf_filtered ("Line %d of \"%s\"",
1727 sal
.line
, sal
.symtab
->filename
);
1729 printf_filtered (" is at address ");
1730 print_address (start_pc
, gdb_stdout
);
1732 printf_filtered (" but contains no code.\n");
1733 sal
= find_pc_line (start_pc
, 0);
1735 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1737 printf_filtered ("Attempting to find line %d instead.\n",
1740 error (_("Cannot find a good line."));
1744 /* Is there any case in which we get here, and have an address
1745 which the user would want to see? If we have debugging
1746 symbols and no line numbers? */
1747 error (_("Line number %d is out of range for \"%s\"."),
1748 sal
.line
, sal
.symtab
->filename
);
1750 sprintf_vma (startpc_str
, start_pc
);
1751 sprintf_vma (endpc_str
, end_pc
- 1);
1752 /* Find within range of stated line. */
1754 sprintf (target_buf
, "QTFrame:range:%s:%s",
1755 startpc_str
, endpc_str
);
1756 /* Find OUTSIDE OF range of CURRENT line. */
1758 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1759 startpc_str
, endpc_str
);
1760 finish_tfind_command (&target_buf
, &target_buf_size
,
1762 do_cleanups (old_chain
);
1765 error (_("Trace can only be run on remote targets."));
1768 /* tfind range command */
1770 trace_find_range_command (char *args
, int from_tty
)
1772 static CORE_ADDR start
, stop
;
1773 char start_str
[40], stop_str
[40];
1776 if (target_is_remote ())
1778 if (args
== 0 || *args
== 0)
1779 { /* XXX FIXME: what should default behavior be? */
1780 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1784 if (0 != (tmp
= strchr (args
, ',')))
1786 *tmp
++ = '\0'; /* terminate start address */
1787 while (isspace ((int) *tmp
))
1789 start
= parse_and_eval_address (args
);
1790 stop
= parse_and_eval_address (tmp
);
1793 { /* no explicit end address? */
1794 start
= parse_and_eval_address (args
);
1795 stop
= start
+ 1; /* ??? */
1798 sprintf_vma (start_str
, start
);
1799 sprintf_vma (stop_str
, stop
);
1800 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1801 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1804 error (_("Trace can only be run on remote targets."));
1807 /* tfind outside command */
1809 trace_find_outside_command (char *args
, int from_tty
)
1811 CORE_ADDR start
, stop
;
1812 char start_str
[40], stop_str
[40];
1815 if (target_is_remote ())
1817 if (args
== 0 || *args
== 0)
1818 { /* XXX FIXME: what should default behavior be? */
1819 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1823 if (0 != (tmp
= strchr (args
, ',')))
1825 *tmp
++ = '\0'; /* terminate start address */
1826 while (isspace ((int) *tmp
))
1828 start
= parse_and_eval_address (args
);
1829 stop
= parse_and_eval_address (tmp
);
1832 { /* no explicit end address? */
1833 start
= parse_and_eval_address (args
);
1834 stop
= start
+ 1; /* ??? */
1837 sprintf_vma (start_str
, start
);
1838 sprintf_vma (stop_str
, stop
);
1839 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1840 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1843 error (_("Trace can only be run on remote targets."));
1846 /* info scope command: list the locals for a scope. */
1848 scope_info (char *args
, int from_tty
)
1850 struct symtabs_and_lines sals
;
1852 struct minimal_symbol
*msym
;
1853 struct block
*block
;
1854 char **canonical
, *symname
, *save_args
= args
;
1855 struct dict_iterator iter
;
1858 if (args
== 0 || *args
== 0)
1859 error (_("requires an argument (function, line or *addr) to define a scope"));
1861 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1862 if (sals
.nelts
== 0)
1863 return; /* presumably decode_line_1 has already warned */
1865 /* Resolve line numbers to PC */
1866 resolve_sal_pc (&sals
.sals
[0]);
1867 block
= block_for_pc (sals
.sals
[0].pc
);
1871 QUIT
; /* allow user to bail out with ^C */
1872 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1874 QUIT
; /* allow user to bail out with ^C */
1876 printf_filtered ("Scope for %s:\n", save_args
);
1879 symname
= SYMBOL_PRINT_NAME (sym
);
1880 if (symname
== NULL
|| *symname
== '\0')
1881 continue; /* probably botched, certainly useless */
1883 printf_filtered ("Symbol %s is ", symname
);
1884 switch (SYMBOL_CLASS (sym
))
1887 case LOC_UNDEF
: /* messed up symbol? */
1888 printf_filtered ("a bogus symbol, class %d.\n",
1889 SYMBOL_CLASS (sym
));
1890 count
--; /* don't count this one */
1893 printf_filtered ("a constant with value %ld (0x%lx)",
1894 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
1896 case LOC_CONST_BYTES
:
1897 printf_filtered ("constant bytes: ");
1898 if (SYMBOL_TYPE (sym
))
1899 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
1900 fprintf_filtered (gdb_stdout
, " %02x",
1901 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
1904 printf_filtered ("in static storage at address ");
1905 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1908 if (SYMBOL_IS_ARGUMENT (sym
))
1909 printf_filtered ("an argument in register $%s",
1910 gdbarch_register_name
1911 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1913 printf_filtered ("a local variable in register $%s",
1914 gdbarch_register_name
1915 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1918 printf_filtered ("an argument at stack/frame offset %ld",
1919 SYMBOL_VALUE (sym
));
1922 printf_filtered ("a local variable at frame offset %ld",
1923 SYMBOL_VALUE (sym
));
1926 printf_filtered ("a reference argument at offset %ld",
1927 SYMBOL_VALUE (sym
));
1929 case LOC_REGPARM_ADDR
:
1930 printf_filtered ("the address of an argument, in register $%s",
1931 gdbarch_register_name
1932 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1935 printf_filtered ("a typedef.\n");
1938 printf_filtered ("a label at address ");
1939 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1942 printf_filtered ("a function at address ");
1943 printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
1945 case LOC_UNRESOLVED
:
1946 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1949 printf_filtered ("Unresolved Static");
1952 printf_filtered ("static storage at address ");
1953 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym
)));
1956 case LOC_OPTIMIZED_OUT
:
1957 printf_filtered ("optimized out.\n");
1960 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1963 if (SYMBOL_TYPE (sym
))
1964 printf_filtered (", length %d.\n",
1965 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
1967 if (BLOCK_FUNCTION (block
))
1970 block
= BLOCK_SUPERBLOCK (block
);
1973 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1977 /* worker function (cleanup) */
1979 replace_comma (void *data
)
1987 trace_dump_command (char *args
, int from_tty
)
1989 struct regcache
*regcache
;
1990 struct gdbarch
*gdbarch
;
1991 struct breakpoint
*t
;
1992 struct action_line
*action
;
1993 char *action_exp
, *next_comma
;
1994 struct cleanup
*old_cleanups
;
1995 int stepping_actions
= 0;
1996 int stepping_frame
= 0;
1998 if (!target_is_remote ())
2000 error (_("Trace can only be run on remote targets."));
2004 if (tracepoint_number
== -1)
2006 warning (_("No current trace frame."));
2010 t
= get_tracepoint (tracepoint_number
);
2013 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2016 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2018 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2019 tracepoint_number
, traceframe_number
);
2021 /* The current frame is a trap frame if the frame PC is equal
2022 to the tracepoint PC. If not, then the current frame was
2023 collected during single-stepping. */
2025 regcache
= get_current_regcache ();
2026 gdbarch
= get_regcache_arch (regcache
);
2028 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2029 - gdbarch_decr_pc_after_break (gdbarch
)));
2031 for (action
= t
->actions
; action
; action
= action
->next
)
2033 struct cmd_list_element
*cmd
;
2035 QUIT
; /* allow user to bail out with ^C */
2036 action_exp
= action
->action
;
2037 while (isspace ((int) *action_exp
))
2040 /* The collection actions to be done while stepping are
2041 bracketed by the commands "while-stepping" and "end". */
2043 if (*action_exp
== '#') /* comment line */
2046 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2048 error (_("Bad action list item: %s"), action_exp
);
2050 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2051 stepping_actions
= 1;
2052 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2053 stepping_actions
= 0;
2054 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2056 /* Display the collected data.
2057 For the trap frame, display only what was collected at
2058 the trap. Likewise for stepping frames, display only
2059 what was collected while stepping. This means that the
2060 two boolean variables, STEPPING_FRAME and
2061 STEPPING_ACTIONS should be equal. */
2062 if (stepping_frame
== stepping_actions
)
2065 { /* repeat over a comma-separated list */
2066 QUIT
; /* allow user to bail out with ^C */
2067 if (*action_exp
== ',')
2069 while (isspace ((int) *action_exp
))
2072 next_comma
= strchr (action_exp
, ',');
2074 if (0 == strncasecmp (action_exp
, "$reg", 4))
2075 registers_info (NULL
, from_tty
);
2076 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2077 locals_info (NULL
, from_tty
);
2078 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2079 args_info (NULL
, from_tty
);
2084 make_cleanup (replace_comma
, next_comma
);
2087 printf_filtered ("%s = ", action_exp
);
2088 output_command (action_exp
, from_tty
);
2089 printf_filtered ("\n");
2093 action_exp
= next_comma
;
2095 while (action_exp
&& *action_exp
== ',');
2099 discard_cleanups (old_cleanups
);
2102 /* Convert the memory pointed to by mem into hex, placing result in buf.
2103 * Return a pointer to the last char put in buf (null)
2104 * "stolen" from sparc-stub.c
2107 static const char hexchars
[] = "0123456789abcdef";
2110 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2118 *buf
++ = hexchars
[ch
>> 4];
2119 *buf
++ = hexchars
[ch
& 0xf];
2128 get_traceframe_number (void)
2130 return traceframe_number
;
2134 /* module initialization */
2136 _initialize_tracepoint (void)
2138 struct cmd_list_element
*c
;
2140 traceframe_number
= -1;
2141 tracepoint_number
= -1;
2143 if (tracepoint_list
.list
== NULL
)
2145 tracepoint_list
.listsize
= 128;
2146 tracepoint_list
.list
= xmalloc
2147 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2149 if (tracepoint_list
.aexpr_list
== NULL
)
2151 tracepoint_list
.aexpr_listsize
= 128;
2152 tracepoint_list
.aexpr_list
= xmalloc
2153 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2156 if (stepping_list
.list
== NULL
)
2158 stepping_list
.listsize
= 128;
2159 stepping_list
.list
= xmalloc
2160 (stepping_list
.listsize
* sizeof (struct memrange
));
2163 if (stepping_list
.aexpr_list
== NULL
)
2165 stepping_list
.aexpr_listsize
= 128;
2166 stepping_list
.aexpr_list
= xmalloc
2167 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2170 add_info ("scope", scope_info
,
2171 _("List the variables local to a scope"));
2173 add_cmd ("tracepoints", class_trace
, NULL
,
2174 _("Tracing of program execution without stopping the program."),
2177 add_com ("tdump", class_trace
, trace_dump_command
,
2178 _("Print everything collected at the current tracepoint."));
2180 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2181 Select a trace frame;\n\
2182 No argument means forward by one frame; '-' means backward by one frame."),
2183 &tfindlist
, "tfind ", 1, &cmdlist
);
2185 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2186 Select a trace frame whose PC is outside the given range.\n\
2187 Usage: tfind outside addr1, addr2"),
2190 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2191 Select a trace frame whose PC is in the given range.\n\
2192 Usage: tfind range addr1,addr2"),
2195 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2196 Select a trace frame by source line.\n\
2197 Argument can be a line number (with optional source file), \n\
2198 a function name, or '*' followed by an address.\n\
2199 Default argument is 'the next source line that was traced'."),
2202 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2203 Select a trace frame by tracepoint number.\n\
2204 Default is the tracepoint for the current trace frame."),
2207 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2208 Select a trace frame by PC.\n\
2209 Default is the current PC, or the PC of the current trace frame."),
2212 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2213 Synonym for 'none'.\n\
2214 De-select any trace frame and resume 'live' debugging."),
2217 add_cmd ("none", class_trace
, trace_find_none_command
,
2218 _("De-select any trace frame and resume 'live' debugging."),
2221 add_cmd ("start", class_trace
, trace_find_start_command
,
2222 _("Select the first trace frame in the trace buffer."),
2225 add_com ("tstatus", class_trace
, trace_status_command
,
2226 _("Display the status of the current trace data collection."));
2228 add_com ("tstop", class_trace
, trace_stop_command
,
2229 _("Stop trace data collection."));
2231 add_com ("tstart", class_trace
, trace_start_command
,
2232 _("Start trace data collection."));
2234 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2235 Ends a list of commands or actions.\n\
2236 Several GDB commands allow you to enter a list of commands or actions.\n\
2237 Entering \"end\" on a line by itself is the normal way to terminate\n\
2239 Note: the \"end\" command cannot be used at the gdb prompt."));
2241 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2242 Specify single-stepping behavior at a tracepoint.\n\
2243 Argument is number of instructions to trace in single-step mode\n\
2244 following the tracepoint. This command is normally followed by\n\
2245 one or more \"collect\" commands, to specify what to collect\n\
2246 while single-stepping.\n\n\
2247 Note: this command can only be used in a tracepoint \"actions\" list."));
2249 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2250 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2252 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2253 Specify one or more data items to be collected at a tracepoint.\n\
2254 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2255 collect all data (variables, registers) referenced by that expression.\n\
2256 Also accepts the following special arguments:\n\
2257 $regs -- all registers.\n\
2258 $args -- all function arguments.\n\
2259 $locals -- all variables local to the block/function scope.\n\
2260 Note: this command can only be used in a tracepoint \"actions\" list."));
2262 add_com ("actions", class_trace
, trace_actions_command
, _("\
2263 Specify the actions to be taken at a tracepoint.\n\
2264 Tracepoint actions may include collecting of specified data, \n\
2265 single-stepping, or enabling/disabling other tracepoints, \n\
2266 depending on target's capabilities."));
2268 target_buf_size
= 2048;
2269 target_buf
= xmalloc (target_buf_size
);