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/>. */
22 #include "arch-utils.h"
26 #include "expression.h"
31 #include "gdb_string.h"
33 #include "breakpoint.h"
34 #include "tracepoint.h"
36 extern int remote_supports_cond_tracepoints (void);
39 #include "completer.h"
41 #include "dictionary.h"
43 #include "user-regs.h"
51 /* readline include files */
52 #include "readline/readline.h"
53 #include "readline/history.h"
55 /* readline defines this. */
62 /* Maximum length of an agent aexpression.
63 This accounts for the fact that packets are limited to 400 bytes
64 (which includes everything -- including the checksum), and assumes
65 the worst case of maximum length for each of the pieces of a
68 NOTE: expressions get mem2hex'ed otherwise this would be twice as
69 large. (400 - 31)/2 == 184 */
70 #define MAX_AGENT_EXPR_LEN 184
73 extern void (*deprecated_readline_begin_hook
) (char *, ...);
74 extern char *(*deprecated_readline_hook
) (char *);
75 extern void (*deprecated_readline_end_hook
) (void);
77 /* GDB commands implemented in other modules:
80 extern void output_command (char *, int);
85 This module defines the following debugger commands:
86 trace : set a tracepoint on a function, line, or address.
87 info trace : list all debugger-defined tracepoints.
88 delete trace : delete one or more tracepoints.
89 enable trace : enable one or more tracepoints.
90 disable trace : disable one or more tracepoints.
91 actions : specify actions to be taken at a tracepoint.
92 passcount : specify a pass count for a tracepoint.
93 tstart : start a trace experiment.
94 tstop : stop a trace experiment.
95 tstatus : query the status of a trace experiment.
96 tfind : find a trace frame in the trace buffer.
97 tdump : print everything collected at the current tracepoint.
98 save-tracepoints : write tracepoint setup into a file.
100 This module defines the following user-visible debugger variables:
101 $trace_frame : sequence number of trace frame currently being debugged.
102 $trace_line : source line of trace frame currently being debugged.
103 $trace_file : source file of trace frame currently being debugged.
104 $tracepoint : tracepoint number of trace frame currently being debugged.
108 /* ======= Important global variables: ======= */
110 /* Number of last traceframe collected. */
111 static int traceframe_number
;
113 /* Tracepoint for last traceframe collected. */
114 static int tracepoint_number
;
116 /* Symbol for function for last traceframe collected */
117 static struct symbol
*traceframe_fun
;
119 /* Symtab and line for last traceframe collected */
120 static struct symtab_and_line traceframe_sal
;
122 /* Tracing command lists */
123 static struct cmd_list_element
*tfindlist
;
125 /* ======= Important command functions: ======= */
126 static void trace_actions_command (char *, int);
127 static void trace_start_command (char *, int);
128 static void trace_stop_command (char *, int);
129 static void trace_status_command (char *, int);
130 static void trace_find_command (char *, int);
131 static void trace_find_pc_command (char *, int);
132 static void trace_find_tracepoint_command (char *, int);
133 static void trace_find_line_command (char *, int);
134 static void trace_find_range_command (char *, int);
135 static void trace_find_outside_command (char *, int);
136 static void tracepoint_save_command (char *, int);
137 static void trace_dump_command (char *, int);
139 /* support routines */
141 struct collection_list
;
142 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
143 static char *mem2hex (gdb_byte
*, char *, int);
144 static void add_register (struct collection_list
*collection
,
146 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
147 static void free_actions_list (char **actions_list
);
148 static void free_actions_list_cleanup_wrapper (void *);
150 extern void _initialize_tracepoint (void);
152 /* Utility: returns true if "target remote" */
154 target_is_remote (void)
156 if (current_target
.to_shortname
&&
157 (strcmp (current_target
.to_shortname
, "remote") == 0
158 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
164 /* Utility: generate error from an incoming stub packet. */
166 trace_error (char *buf
)
169 return; /* not an error msg */
172 case '1': /* malformed packet error */
173 if (*++buf
== '0') /* general case: */
174 error (_("tracepoint.c: error in outgoing packet."));
176 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
177 strtol (buf
, NULL
, 16));
179 error (_("trace API error 0x%s."), ++buf
);
181 error (_("Target returns error code '%s'."), buf
);
185 /* Utility: wait for reply from stub, while accepting "O" packets. */
187 remote_get_noisy_reply (char **buf_p
,
190 do /* Loop on reply from remote stub. */
193 QUIT
; /* allow user to bail out with ^C */
194 getpkt (buf_p
, sizeof_buf
, 0);
197 error (_("Target does not support this command."));
198 else if (buf
[0] == 'E')
200 else if (buf
[0] == 'O' &&
202 remote_console_output (buf
+ 1); /* 'O' message from stub */
204 return buf
; /* here's the actual reply */
209 /* Set traceframe number to NUM. */
211 set_traceframe_num (int num
)
213 traceframe_number
= num
;
214 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
217 /* Set tracepoint number to NUM. */
219 set_tracepoint_num (int num
)
221 tracepoint_number
= num
;
222 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
225 /* Set externally visible debug variables for querying/printing
226 the traceframe context (line, function, file) */
229 set_traceframe_context (struct frame_info
*trace_frame
)
233 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
236 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
237 traceframe_sal
.symtab
= NULL
;
238 clear_internalvar (lookup_internalvar ("trace_func"));
239 clear_internalvar (lookup_internalvar ("trace_file"));
240 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
244 /* Save as globals for internal use. */
245 trace_pc
= get_frame_pc (trace_frame
);
246 traceframe_sal
= find_pc_line (trace_pc
, 0);
247 traceframe_fun
= find_pc_function (trace_pc
);
249 /* Save linenumber as "$trace_line", a debugger variable visible to
251 set_internalvar_integer (lookup_internalvar ("trace_line"),
252 traceframe_sal
.line
);
254 /* Save func name as "$trace_func", a debugger variable visible to
256 if (traceframe_fun
== NULL
257 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
258 clear_internalvar (lookup_internalvar ("trace_func"));
260 set_internalvar_string (lookup_internalvar ("trace_func"),
261 SYMBOL_LINKAGE_NAME (traceframe_fun
));
263 /* Save file name as "$trace_file", a debugger variable visible to
265 if (traceframe_sal
.symtab
== NULL
266 || traceframe_sal
.symtab
->filename
== NULL
)
267 clear_internalvar (lookup_internalvar ("trace_file"));
269 set_internalvar_string (lookup_internalvar ("trace_file"),
270 traceframe_sal
.symtab
->filename
);
273 /* ACTIONS functions: */
275 /* Prototypes for action-parsing utility commands */
276 static void read_actions (struct breakpoint
*);
278 /* The three functions:
279 collect_pseudocommand,
280 while_stepping_pseudocommand, and
281 end_actions_pseudocommand
282 are placeholders for "commands" that are actually ONLY to be used
283 within a tracepoint action list. If the actual function is ever called,
284 it means that somebody issued the "command" at the top level,
285 which is always an error. */
288 end_actions_pseudocommand (char *args
, int from_tty
)
290 error (_("This command cannot be used at the top level."));
294 while_stepping_pseudocommand (char *args
, int from_tty
)
296 error (_("This command can only be used in a tracepoint actions list."));
300 collect_pseudocommand (char *args
, int from_tty
)
302 error (_("This command can only be used in a tracepoint actions list."));
305 /* Enter a list of actions for a tracepoint. */
307 trace_actions_command (char *args
, int from_tty
)
309 struct breakpoint
*t
;
311 char *end_msg
= "End with a line saying just \"end\".";
313 t
= get_tracepoint_by_number (&args
, 0, 1);
316 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
321 if (deprecated_readline_begin_hook
)
322 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
323 else if (input_from_terminal_p ())
324 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
328 t
->step_count
= 0; /* read_actions may set this */
331 if (deprecated_readline_end_hook
)
332 (*deprecated_readline_end_hook
) ();
333 /* tracepoints_changed () */
335 /* else just return */
338 /* worker function */
340 read_actions (struct breakpoint
*t
)
343 char *prompt1
= "> ", *prompt2
= " > ";
344 char *prompt
= prompt1
;
345 enum actionline_type linetype
;
346 extern FILE *instream
;
347 struct action_line
*next
= NULL
, *temp
;
348 struct cleanup
*old_chain
;
350 /* Control-C quits instantly if typed while in this loop
351 since it should not wait until the user types a newline. */
353 /* FIXME: kettenis/20010823: Something is wrong here. In this file
354 STOP_SIGNAL is never defined. So this code has been left out, at
355 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
356 leads to compilation failures since the variable job_control
357 isn't declared. Leave this alone for now. */
360 signal (STOP_SIGNAL
, handle_stop_sig
);
362 old_chain
= make_cleanup_free_actions (t
);
365 /* Make sure that all output has been output. Some machines may
366 let you get away with leaving out some of the gdb_flush, but
369 gdb_flush (gdb_stdout
);
370 gdb_flush (gdb_stderr
);
372 if (deprecated_readline_hook
&& instream
== NULL
)
373 line
= (*deprecated_readline_hook
) (prompt
);
374 else if (instream
== stdin
&& ISATTY (instream
))
376 line
= gdb_readline_wrapper (prompt
);
377 if (line
&& *line
) /* add it to command history */
381 line
= gdb_readline (0);
385 line
= xstrdup ("end");
386 printf_filtered ("end\n");
389 linetype
= validate_actionline (&line
, t
);
390 if (linetype
== BADLINE
)
391 continue; /* already warned -- collect another line */
393 temp
= xmalloc (sizeof (struct action_line
));
397 if (next
== NULL
) /* first action for this tracepoint? */
398 t
->actions
= next
= temp
;
405 if (linetype
== STEPPING
) /* begin "while-stepping" */
407 if (prompt
== prompt2
)
409 warning (_("Already processing 'while-stepping'"));
413 prompt
= prompt2
; /* change prompt for stepping actions */
415 else if (linetype
== END
)
417 if (prompt
== prompt2
)
419 prompt
= prompt1
; /* end of single-stepping actions */
422 { /* end of actions */
423 if (t
->actions
->next
== NULL
)
425 /* An "end" all by itself with no other actions
426 means this tracepoint has no actions.
427 Discard empty list. */
436 signal (STOP_SIGNAL
, SIG_DFL
);
439 discard_cleanups (old_chain
);
442 /* worker function */
444 validate_actionline (char **line
, struct breakpoint
*t
)
446 struct cmd_list_element
*c
;
447 struct expression
*exp
= NULL
;
448 struct cleanup
*old_chain
= NULL
;
451 /* if EOF is typed, *line is NULL */
455 for (p
= *line
; isspace ((int) *p
);)
458 /* Symbol lookup etc. */
459 if (*p
== '\0') /* empty line: just prompt for another line. */
462 if (*p
== '#') /* comment line */
465 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
468 warning (_("'%s' is not an action that I know, or is ambiguous."),
473 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
475 struct agent_expr
*aexpr
;
476 struct agent_reqs areqs
;
479 { /* repeat over a comma-separated list */
480 QUIT
; /* allow user to bail out with ^C */
481 while (isspace ((int) *p
))
484 if (*p
== '$') /* look for special pseudo-symbols */
486 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
487 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
488 (0 == strncasecmp ("loc", p
+ 1, 3)))
493 /* else fall thru, treat p as an expression and parse it! */
495 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
496 old_chain
= make_cleanup (free_current_contents
, &exp
);
498 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
500 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
502 warning (_("constant %s (value %ld) will not be collected."),
503 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
504 SYMBOL_VALUE (exp
->elts
[2].symbol
));
507 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
509 warning (_("%s is optimized away and cannot be collected."),
510 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
515 /* We have something to collect, make sure that the expr to
516 bytecode translator can handle it and that it's not too
518 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
519 make_cleanup_free_agent_expr (aexpr
);
521 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
522 error (_("expression too complicated, try simplifying"));
524 ax_reqs (aexpr
, &areqs
);
525 (void) make_cleanup (xfree
, areqs
.reg_mask
);
527 if (areqs
.flaw
!= agent_flaw_none
)
528 error (_("malformed expression"));
530 if (areqs
.min_height
< 0)
531 error (_("gdb: Internal error: expression has min height < 0"));
533 if (areqs
.max_height
> 20)
534 error (_("expression too complicated, try simplifying"));
536 do_cleanups (old_chain
);
538 while (p
&& *p
++ == ',');
541 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
543 char *steparg
; /* in case warning is necessary */
545 while (isspace ((int) *p
))
550 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
552 warning (_("'%s': bad step-count; command ignored."), *line
);
557 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
561 warning (_("'%s' is not a supported tracepoint action."), *line
);
566 /* worker function */
568 free_actions (struct breakpoint
*t
)
570 struct action_line
*line
, *next
;
572 for (line
= t
->actions
; line
; line
= next
)
576 xfree (line
->action
);
583 do_free_actions_cleanup (void *t
)
588 static struct cleanup
*
589 make_cleanup_free_actions (struct breakpoint
*t
)
591 return make_cleanup (do_free_actions_cleanup
, t
);
595 memrange_absolute
= -1
600 int type
; /* memrange_absolute for absolute memory range,
601 else basereg number */
602 bfd_signed_vma start
;
606 struct collection_list
608 unsigned char regs_mask
[32]; /* room for up to 256 regs */
611 struct memrange
*list
;
612 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
614 struct agent_expr
**aexpr_list
;
617 tracepoint_list
, stepping_list
;
619 /* MEMRANGE functions: */
621 static int memrange_cmp (const void *, const void *);
623 /* compare memranges for qsort */
625 memrange_cmp (const void *va
, const void *vb
)
627 const struct memrange
*a
= va
, *b
= vb
;
629 if (a
->type
< b
->type
)
631 if (a
->type
> b
->type
)
633 if (a
->type
== memrange_absolute
)
635 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
637 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
642 if (a
->start
< b
->start
)
644 if (a
->start
> b
->start
)
650 /* Sort the memrange list using qsort, and merge adjacent memranges. */
652 memrange_sortmerge (struct collection_list
*memranges
)
656 qsort (memranges
->list
, memranges
->next_memrange
,
657 sizeof (struct memrange
), memrange_cmp
);
658 if (memranges
->next_memrange
> 0)
660 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
662 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
663 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
666 /* memrange b starts before memrange a ends; merge them. */
667 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
668 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
669 continue; /* next b, same a */
673 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
674 sizeof (struct memrange
));
676 memranges
->next_memrange
= a
+ 1;
680 /* Add a register to a collection list. */
682 add_register (struct collection_list
*collection
, unsigned int regno
)
685 printf_filtered ("collect register %d\n", regno
);
686 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
687 error (_("Internal: register number %d too large for tracepoint"),
689 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
692 /* Add a memrange to a collection list */
694 add_memrange (struct collection_list
*memranges
,
695 int type
, bfd_signed_vma base
,
700 printf_filtered ("(%d,", type
);
702 printf_filtered (",%ld)\n", len
);
705 /* type: memrange_absolute == memory, other n == basereg */
706 memranges
->list
[memranges
->next_memrange
].type
= type
;
707 /* base: addr if memory, offset if reg relative. */
708 memranges
->list
[memranges
->next_memrange
].start
= base
;
709 /* len: we actually save end (base + len) for convenience */
710 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
711 memranges
->next_memrange
++;
712 if (memranges
->next_memrange
>= memranges
->listsize
)
714 memranges
->listsize
*= 2;
715 memranges
->list
= xrealloc (memranges
->list
,
716 memranges
->listsize
);
719 if (type
!= memrange_absolute
) /* Better collect the base register! */
720 add_register (memranges
, type
);
723 /* Add a symbol to a collection list. */
725 collect_symbol (struct collection_list
*collect
,
727 struct gdbarch
*gdbarch
,
728 long frame_regno
, long frame_offset
)
732 bfd_signed_vma offset
;
734 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
735 switch (SYMBOL_CLASS (sym
))
738 printf_filtered ("%s: don't know symbol class %d\n",
739 SYMBOL_PRINT_NAME (sym
),
743 printf_filtered ("constant %s (value %ld) will not be collected.\n",
744 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
747 offset
= SYMBOL_VALUE_ADDRESS (sym
);
752 sprintf_vma (tmp
, offset
);
753 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
754 SYMBOL_PRINT_NAME (sym
), len
,
757 add_memrange (collect
, memrange_absolute
, offset
, len
);
760 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
762 printf_filtered ("LOC_REG[parm] %s: ",
763 SYMBOL_PRINT_NAME (sym
));
764 add_register (collect
, reg
);
765 /* Check for doubles stored in two registers. */
766 /* FIXME: how about larger types stored in 3 or more regs? */
767 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
768 len
> register_size (gdbarch
, reg
))
769 add_register (collect
, reg
+ 1);
772 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
773 printf_filtered (" (will not collect %s)\n",
774 SYMBOL_PRINT_NAME (sym
));
778 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
781 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
782 SYMBOL_PRINT_NAME (sym
), len
);
784 printf_filtered (" from frame ptr reg %d\n", reg
);
786 add_memrange (collect
, reg
, offset
, len
);
788 case LOC_REGPARM_ADDR
:
789 reg
= SYMBOL_VALUE (sym
);
793 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
794 SYMBOL_PRINT_NAME (sym
), len
);
796 printf_filtered (" from reg %d\n", reg
);
798 add_memrange (collect
, reg
, offset
, len
);
802 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
805 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
806 SYMBOL_PRINT_NAME (sym
), len
);
808 printf_filtered (" from frame ptr reg %d\n", reg
);
810 add_memrange (collect
, reg
, offset
, len
);
813 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
814 SYMBOL_PRINT_NAME (sym
));
816 case LOC_OPTIMIZED_OUT
:
817 printf_filtered ("%s has been optimized out of existence.\n",
818 SYMBOL_PRINT_NAME (sym
));
823 /* Add all locals (or args) symbols to collection list */
825 add_local_symbols (struct collection_list
*collect
,
826 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
827 long frame_regno
, long frame_offset
, int type
)
831 struct dict_iterator iter
;
834 block
= block_for_pc (pc
);
837 QUIT
; /* allow user to bail out with ^C */
838 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
840 if (SYMBOL_IS_ARGUMENT (sym
)
841 ? type
== 'A' /* collecting Arguments */
842 : type
== 'L') /* collecting Locals */
845 collect_symbol (collect
, sym
, gdbarch
,
846 frame_regno
, frame_offset
);
849 if (BLOCK_FUNCTION (block
))
852 block
= BLOCK_SUPERBLOCK (block
);
855 warning (_("No %s found in scope."),
856 type
== 'L' ? "locals" : "args");
859 /* worker function */
861 clear_collection_list (struct collection_list
*list
)
865 list
->next_memrange
= 0;
866 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
868 free_agent_expr (list
->aexpr_list
[ndx
]);
869 list
->aexpr_list
[ndx
] = NULL
;
871 list
->next_aexpr_elt
= 0;
872 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
875 /* reduce a collection list to string form (for gdb protocol) */
877 stringify_collection_list (struct collection_list
*list
, char *string
)
887 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
888 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
890 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
891 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
893 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
896 printf_filtered ("\nCollecting registers (mask): 0x");
901 QUIT
; /* allow user to bail out with ^C */
903 printf_filtered ("%02X", list
->regs_mask
[i
]);
904 sprintf (end
, "%02X", list
->regs_mask
[i
]);
907 (*str_list
)[ndx
] = xstrdup (temp_buf
);
911 printf_filtered ("\n");
912 if (list
->next_memrange
> 0 && info_verbose
)
913 printf_filtered ("Collecting memranges: \n");
914 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
916 QUIT
; /* allow user to bail out with ^C */
917 sprintf_vma (tmp2
, list
->list
[i
].start
);
920 printf_filtered ("(%d, %s, %ld)\n",
923 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
925 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
927 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
934 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
936 /* The "%X" conversion specifier expects an unsigned argument,
937 so passing -1 (memrange_absolute) to it directly gives you
938 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
940 if (list
->list
[i
].type
== memrange_absolute
)
941 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
943 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
946 count
+= strlen (end
);
947 end
= temp_buf
+ count
;
950 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
952 QUIT
; /* allow user to bail out with ^C */
953 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
955 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
960 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
961 end
+= 10; /* 'X' + 8 hex digits + ',' */
964 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
965 end
, list
->aexpr_list
[i
]->len
);
966 count
+= 2 * list
->aexpr_list
[i
]->len
;
971 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
976 (*str_list
)[ndx
] = NULL
;
988 free_actions_list_cleanup_wrapper (void *al
)
990 free_actions_list (al
);
994 free_actions_list (char **actions_list
)
998 if (actions_list
== 0)
1001 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1002 xfree (actions_list
[ndx
]);
1004 xfree (actions_list
);
1007 /* Render all actions into gdb protocol. */
1009 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1010 char ***stepping_actions
)
1012 static char tdp_buff
[2048], step_buff
[2048];
1014 struct expression
*exp
= NULL
;
1015 struct action_line
*action
;
1017 struct value
*tempval
;
1018 struct collection_list
*collect
;
1019 struct cmd_list_element
*cmd
;
1020 struct agent_expr
*aexpr
;
1022 LONGEST frame_offset
;
1025 clear_collection_list (&tracepoint_list
);
1026 clear_collection_list (&stepping_list
);
1027 collect
= &tracepoint_list
;
1029 *tdp_actions
= NULL
;
1030 *stepping_actions
= NULL
;
1032 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1033 t
->loc
->address
, &frame_reg
, &frame_offset
);
1035 for (action
= t
->actions
; action
; action
= action
->next
)
1037 QUIT
; /* allow user to bail out with ^C */
1038 action_exp
= action
->action
;
1039 while (isspace ((int) *action_exp
))
1042 if (*action_exp
== '#') /* comment line */
1045 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1047 error (_("Bad action list item: %s"), action_exp
);
1049 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1052 { /* repeat over a comma-separated list */
1053 QUIT
; /* allow user to bail out with ^C */
1054 while (isspace ((int) *action_exp
))
1057 if (0 == strncasecmp ("$reg", action_exp
, 4))
1059 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1060 add_register (collect
, i
);
1061 action_exp
= strchr (action_exp
, ','); /* more? */
1063 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1065 add_local_symbols (collect
,
1071 action_exp
= strchr (action_exp
, ','); /* more? */
1073 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1075 add_local_symbols (collect
,
1081 action_exp
= strchr (action_exp
, ','); /* more? */
1085 unsigned long addr
, len
;
1086 struct cleanup
*old_chain
= NULL
;
1087 struct cleanup
*old_chain1
= NULL
;
1088 struct agent_reqs areqs
;
1090 exp
= parse_exp_1 (&action_exp
,
1091 block_for_pc (t
->loc
->address
), 1);
1092 old_chain
= make_cleanup (free_current_contents
, &exp
);
1094 switch (exp
->elts
[0].opcode
)
1098 const char *name
= &exp
->elts
[2].string
;
1100 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1101 name
, strlen (name
));
1103 internal_error (__FILE__
, __LINE__
,
1104 _("Register $%s not available"),
1107 printf_filtered ("OP_REGISTER: ");
1108 add_register (collect
, i
);
1113 /* safe because we know it's a simple expression */
1114 tempval
= evaluate_expression (exp
);
1115 addr
= value_address (tempval
);
1116 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1117 add_memrange (collect
, memrange_absolute
, addr
, len
);
1121 collect_symbol (collect
,
1122 exp
->elts
[2].symbol
,
1128 default: /* full-fledged expression */
1129 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1131 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1133 ax_reqs (aexpr
, &areqs
);
1134 if (areqs
.flaw
!= agent_flaw_none
)
1135 error (_("malformed expression"));
1137 if (areqs
.min_height
< 0)
1138 error (_("gdb: Internal error: expression has min height < 0"));
1139 if (areqs
.max_height
> 20)
1140 error (_("expression too complicated, try simplifying"));
1142 discard_cleanups (old_chain1
);
1143 add_aexpr (collect
, aexpr
);
1145 /* take care of the registers */
1146 if (areqs
.reg_mask_len
> 0)
1151 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1153 QUIT
; /* allow user to bail out with ^C */
1154 if (areqs
.reg_mask
[ndx1
] != 0)
1156 /* assume chars have 8 bits */
1157 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1158 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1159 /* it's used -- record it */
1160 add_register (collect
,
1167 do_cleanups (old_chain
);
1170 while (action_exp
&& *action_exp
++ == ',');
1172 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1174 collect
= &stepping_list
;
1176 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1178 if (collect
== &stepping_list
) /* end stepping actions */
1179 collect
= &tracepoint_list
;
1181 break; /* end tracepoint actions */
1184 memrange_sortmerge (&tracepoint_list
);
1185 memrange_sortmerge (&stepping_list
);
1187 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1189 *stepping_actions
= stringify_collection_list (&stepping_list
,
1194 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1196 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1198 collect
->aexpr_list
=
1199 xrealloc (collect
->aexpr_list
,
1200 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1201 collect
->aexpr_listsize
*= 2;
1203 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1204 collect
->next_aexpr_elt
++;
1207 static char *target_buf
;
1208 static long target_buf_size
;
1210 /* Set "transparent" memory ranges
1212 Allow trace mechanism to treat text-like sections
1213 (and perhaps all read-only sections) transparently,
1214 i.e. don't reject memory requests from these address ranges
1215 just because they haven't been collected. */
1218 remote_set_transparent_ranges (void)
1226 return; /* No information to give. */
1228 strcpy (target_buf
, "QTro");
1229 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1231 char tmp1
[40], tmp2
[40];
1233 if ((s
->flags
& SEC_LOAD
) == 0 ||
1234 /* (s->flags & SEC_CODE) == 0 || */
1235 (s
->flags
& SEC_READONLY
) == 0)
1240 size
= bfd_get_section_size (s
);
1241 sprintf_vma (tmp1
, lma
);
1242 sprintf_vma (tmp2
, lma
+ size
);
1243 sprintf (target_buf
+ strlen (target_buf
),
1244 ":%s,%s", tmp1
, tmp2
);
1248 putpkt (target_buf
);
1249 getpkt (&target_buf
, &target_buf_size
, 0);
1255 Tell target to clear any previous trace experiment.
1256 Walk the list of tracepoints, and send them (and their actions)
1257 to the target. If no errors,
1258 Tell target to start a new trace experiment. */
1260 void download_tracepoint (struct breakpoint
*t
);
1263 trace_start_command (char *args
, int from_tty
)
1265 VEC(breakpoint_p
) *tp_vec
= NULL
;
1267 struct breakpoint
*t
;
1269 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1271 if (target_is_remote ())
1274 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1275 if (strcmp (target_buf
, "OK"))
1276 error (_("Target does not support this command."));
1278 tp_vec
= all_tracepoints ();
1279 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1281 download_tracepoint (t
);
1283 VEC_free (breakpoint_p
, tp_vec
);
1285 /* Tell target to treat text-like sections as transparent. */
1286 remote_set_transparent_ranges ();
1287 /* Now insert traps and begin collecting data. */
1289 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1290 if (strcmp (target_buf
, "OK"))
1291 error (_("Bogus reply from target: %s"), target_buf
);
1292 set_traceframe_num (-1); /* All old traceframes invalidated. */
1293 set_tracepoint_num (-1);
1294 set_traceframe_context (NULL
);
1295 trace_running_p
= 1;
1296 if (deprecated_trace_start_stop_hook
)
1297 deprecated_trace_start_stop_hook (1, from_tty
);
1301 error (_("Trace can only be run on remote targets."));
1304 /* Send the definition of a single tracepoint to the target. */
1307 download_tracepoint (struct breakpoint
*t
)
1312 char **stepping_actions
;
1314 struct cleanup
*old_chain
= NULL
;
1315 struct agent_expr
*aexpr
;
1316 struct cleanup
*aexpr_chain
= NULL
;
1318 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1319 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1321 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1322 t
->step_count
, t
->pass_count
);
1323 /* If the tracepoint has a conditional, make it into an agent
1324 expression and append to the definition. */
1327 /* Only test support at download time, we may not know target
1328 capabilities at definition time. */
1329 if (remote_supports_cond_tracepoints ())
1331 aexpr
= gen_eval_for_expr (t
->loc
->address
, t
->loc
->cond
);
1332 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
1333 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
1334 mem2hex (aexpr
->buf
, buf
+ strlen (buf
), aexpr
->len
);
1335 do_cleanups (aexpr_chain
);
1338 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t
->number
);
1344 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1345 if (strcmp (target_buf
, "OK"))
1346 error (_("Target does not support tracepoints."));
1351 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1352 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1354 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1356 /* do_single_steps (t); */
1359 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1361 QUIT
; /* allow user to bail out with ^C */
1362 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1363 t
->number
, tmp
, /* address */
1365 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1368 remote_get_noisy_reply (&target_buf
,
1370 if (strcmp (target_buf
, "OK"))
1371 error (_("Error on target while setting tracepoints."));
1374 if (stepping_actions
)
1376 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1378 QUIT
; /* allow user to bail out with ^C */
1379 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1380 t
->number
, tmp
, /* address */
1381 ((ndx
== 0) ? "S" : ""),
1382 stepping_actions
[ndx
],
1383 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1385 remote_get_noisy_reply (&target_buf
,
1387 if (strcmp (target_buf
, "OK"))
1388 error (_("Error on target while setting tracepoints."));
1391 do_cleanups (old_chain
);
1396 trace_stop_command (char *args
, int from_tty
)
1398 if (target_is_remote ())
1401 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1402 if (strcmp (target_buf
, "OK"))
1403 error (_("Bogus reply from target: %s"), target_buf
);
1404 trace_running_p
= 0;
1405 if (deprecated_trace_start_stop_hook
)
1406 deprecated_trace_start_stop_hook (0, from_tty
);
1409 error (_("Trace can only be run on remote targets."));
1412 unsigned long trace_running_p
;
1414 /* tstatus command */
1416 trace_status_command (char *args
, int from_tty
)
1418 if (target_is_remote ())
1420 putpkt ("qTStatus");
1421 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1423 if (target_buf
[0] != 'T' ||
1424 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1425 error (_("Bogus reply from target: %s"), target_buf
);
1427 /* exported for use by the GUI */
1428 trace_running_p
= (target_buf
[1] == '1');
1431 error (_("Trace can only be run on remote targets."));
1434 /* Worker function for the various flavors of the tfind command. */
1436 finish_tfind_command (char **msg
,
1440 int target_frameno
= -1, target_tracept
= -1;
1441 struct frame_id old_frame_id
;
1444 old_frame_id
= get_frame_id (get_current_frame ());
1447 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1449 while (reply
&& *reply
)
1453 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1455 /* A request for a non-existant trace frame has failed.
1456 Our response will be different, depending on FROM_TTY:
1458 If FROM_TTY is true, meaning that this command was
1459 typed interactively by the user, then give an error
1460 and DO NOT change the state of traceframe_number etc.
1462 However if FROM_TTY is false, meaning that we're either
1463 in a script, a loop, or a user-defined command, then
1464 DON'T give an error, but DO change the state of
1465 traceframe_number etc. to invalid.
1467 The rationalle is that if you typed the command, you
1468 might just have committed a typo or something, and you'd
1469 like to NOT lose your current debugging state. However
1470 if you're in a user-defined command or especially in a
1471 loop, then you need a way to detect that the command
1472 failed WITHOUT aborting. This allows you to write
1473 scripts that search thru the trace buffer until the end,
1474 and then continue on to do something else. */
1477 error (_("Target failed to find requested trace frame."));
1481 printf_filtered ("End of trace buffer.\n");
1482 /* The following will not recurse, since it's
1484 trace_find_command ("-1", from_tty
);
1485 reply
= NULL
; /* Break out of loop
1486 (avoid recursive nonsense). */
1491 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1492 error (_("Target failed to find requested trace frame."));
1494 case 'O': /* "OK"? */
1495 if (reply
[1] == 'K' && reply
[2] == '\0')
1498 error (_("Bogus reply from target: %s"), reply
);
1501 error (_("Bogus reply from target: %s"), reply
);
1504 reinit_frame_cache ();
1505 registers_changed ();
1506 set_traceframe_num (target_frameno
);
1507 set_tracepoint_num (target_tracept
);
1508 if (target_frameno
== -1)
1509 set_traceframe_context (NULL
);
1511 set_traceframe_context (get_current_frame ());
1515 enum print_what print_what
;
1517 /* NOTE: in immitation of the step command, try to determine
1518 whether we have made a transition from one function to
1519 another. If so, we'll print the "stack frame" (ie. the new
1520 function and it's arguments) -- otherwise we'll just show the
1523 if (frame_id_eq (old_frame_id
,
1524 get_frame_id (get_current_frame ())))
1525 print_what
= SRC_LINE
;
1527 print_what
= SRC_AND_LOC
;
1529 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1534 /* trace_find_command takes a trace frame number n,
1535 sends "QTFrame:<n>" to the target,
1536 and accepts a reply that may contain several optional pieces
1537 of information: a frame number, a tracepoint number, and an
1538 indication of whether this is a trap frame or a stepping frame.
1540 The minimal response is just "OK" (which indicates that the
1541 target does not give us a frame number or a tracepoint number).
1542 Instead of that, the target may send us a string containing
1544 F<hexnum> (gives the selected frame number)
1545 T<hexnum> (gives the selected tracepoint number)
1550 trace_find_command (char *args
, int from_tty
)
1551 { /* this should only be called with a numeric argument */
1554 if (target_is_remote ())
1556 if (deprecated_trace_find_hook
)
1557 deprecated_trace_find_hook (args
, from_tty
);
1559 if (args
== 0 || *args
== 0)
1560 { /* TFIND with no args means find NEXT trace frame. */
1561 if (traceframe_number
== -1)
1562 frameno
= 0; /* "next" is first one */
1564 frameno
= traceframe_number
+ 1;
1566 else if (0 == strcmp (args
, "-"))
1568 if (traceframe_number
== -1)
1569 error (_("not debugging trace buffer"));
1570 else if (from_tty
&& traceframe_number
== 0)
1571 error (_("already at start of trace buffer"));
1573 frameno
= traceframe_number
- 1;
1576 frameno
= parse_and_eval_long (args
);
1579 error (_("invalid input (%d is less than zero)"), frameno
);
1581 sprintf (target_buf
, "QTFrame:%x", frameno
);
1582 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1585 error (_("Trace can only be run on remote targets."));
1590 trace_find_end_command (char *args
, int from_tty
)
1592 trace_find_command ("-1", from_tty
);
1597 trace_find_none_command (char *args
, int from_tty
)
1599 trace_find_command ("-1", from_tty
);
1604 trace_find_start_command (char *args
, int from_tty
)
1606 trace_find_command ("0", from_tty
);
1609 /* tfind pc command */
1611 trace_find_pc_command (char *args
, int from_tty
)
1616 if (target_is_remote ())
1618 if (args
== 0 || *args
== 0)
1619 pc
= regcache_read_pc (get_current_regcache ());
1621 pc
= parse_and_eval_address (args
);
1623 sprintf_vma (tmp
, pc
);
1624 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
1625 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1628 error (_("Trace can only be run on remote targets."));
1631 /* tfind tracepoint command */
1633 trace_find_tracepoint_command (char *args
, int from_tty
)
1637 if (target_is_remote ())
1639 if (args
== 0 || *args
== 0)
1641 if (tracepoint_number
== -1)
1642 error (_("No current tracepoint -- please supply an argument."));
1644 tdp
= tracepoint_number
; /* default is current TDP */
1647 tdp
= parse_and_eval_long (args
);
1649 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1650 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1653 error (_("Trace can only be run on remote targets."));
1656 /* TFIND LINE command:
1658 This command will take a sourceline for argument, just like BREAK
1659 or TRACE (ie. anything that "decode_line_1" can handle).
1661 With no argument, this command will find the next trace frame
1662 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1665 trace_find_line_command (char *args
, int from_tty
)
1667 static CORE_ADDR start_pc
, end_pc
;
1668 struct symtabs_and_lines sals
;
1669 struct symtab_and_line sal
;
1670 struct cleanup
*old_chain
;
1671 char startpc_str
[40], endpc_str
[40];
1673 if (target_is_remote ())
1675 if (args
== 0 || *args
== 0)
1677 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1679 sals
.sals
= (struct symtab_and_line
*)
1680 xmalloc (sizeof (struct symtab_and_line
));
1685 sals
= decode_line_spec (args
, 1);
1689 old_chain
= make_cleanup (xfree
, sals
.sals
);
1690 if (sal
.symtab
== 0)
1692 struct gdbarch
*gdbarch
= get_current_arch ();
1694 printf_filtered ("TFIND: No line number information available");
1697 /* This is useful for "info line *0x7f34". If we can't
1698 tell the user about a source line, at least let them
1699 have the symbolic address. */
1700 printf_filtered (" for address ");
1702 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
1703 printf_filtered (";\n -- will attempt to find by PC. \n");
1707 printf_filtered (".\n");
1708 return; /* No line, no PC; what can we do? */
1711 else if (sal
.line
> 0
1712 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1714 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
1716 if (start_pc
== end_pc
)
1718 printf_filtered ("Line %d of \"%s\"",
1719 sal
.line
, sal
.symtab
->filename
);
1721 printf_filtered (" is at address ");
1722 print_address (gdbarch
, start_pc
, gdb_stdout
);
1724 printf_filtered (" but contains no code.\n");
1725 sal
= find_pc_line (start_pc
, 0);
1727 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1729 printf_filtered ("Attempting to find line %d instead.\n",
1732 error (_("Cannot find a good line."));
1736 /* Is there any case in which we get here, and have an address
1737 which the user would want to see? If we have debugging
1738 symbols and no line numbers? */
1739 error (_("Line number %d is out of range for \"%s\"."),
1740 sal
.line
, sal
.symtab
->filename
);
1742 sprintf_vma (startpc_str
, start_pc
);
1743 sprintf_vma (endpc_str
, end_pc
- 1);
1744 /* Find within range of stated line. */
1746 sprintf (target_buf
, "QTFrame:range:%s:%s",
1747 startpc_str
, endpc_str
);
1748 /* Find OUTSIDE OF range of CURRENT line. */
1750 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1751 startpc_str
, endpc_str
);
1752 finish_tfind_command (&target_buf
, &target_buf_size
,
1754 do_cleanups (old_chain
);
1757 error (_("Trace can only be run on remote targets."));
1760 /* tfind range command */
1762 trace_find_range_command (char *args
, int from_tty
)
1764 static CORE_ADDR start
, stop
;
1765 char start_str
[40], stop_str
[40];
1768 if (target_is_remote ())
1770 if (args
== 0 || *args
== 0)
1771 { /* XXX FIXME: what should default behavior be? */
1772 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1776 if (0 != (tmp
= strchr (args
, ',')))
1778 *tmp
++ = '\0'; /* terminate start address */
1779 while (isspace ((int) *tmp
))
1781 start
= parse_and_eval_address (args
);
1782 stop
= parse_and_eval_address (tmp
);
1785 { /* no explicit end address? */
1786 start
= parse_and_eval_address (args
);
1787 stop
= start
+ 1; /* ??? */
1790 sprintf_vma (start_str
, start
);
1791 sprintf_vma (stop_str
, stop
);
1792 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1793 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1796 error (_("Trace can only be run on remote targets."));
1799 /* tfind outside command */
1801 trace_find_outside_command (char *args
, int from_tty
)
1803 CORE_ADDR start
, stop
;
1804 char start_str
[40], stop_str
[40];
1807 if (target_is_remote ())
1809 if (args
== 0 || *args
== 0)
1810 { /* XXX FIXME: what should default behavior be? */
1811 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1815 if (0 != (tmp
= strchr (args
, ',')))
1817 *tmp
++ = '\0'; /* terminate start address */
1818 while (isspace ((int) *tmp
))
1820 start
= parse_and_eval_address (args
);
1821 stop
= parse_and_eval_address (tmp
);
1824 { /* no explicit end address? */
1825 start
= parse_and_eval_address (args
);
1826 stop
= start
+ 1; /* ??? */
1829 sprintf_vma (start_str
, start
);
1830 sprintf_vma (stop_str
, stop
);
1831 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1832 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1835 error (_("Trace can only be run on remote targets."));
1838 /* info scope command: list the locals for a scope. */
1840 scope_info (char *args
, int from_tty
)
1842 struct symtabs_and_lines sals
;
1844 struct minimal_symbol
*msym
;
1845 struct block
*block
;
1846 char **canonical
, *symname
, *save_args
= args
;
1847 struct dict_iterator iter
;
1849 struct gdbarch
*gdbarch
;
1852 if (args
== 0 || *args
== 0)
1853 error (_("requires an argument (function, line or *addr) to define a scope"));
1855 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1856 if (sals
.nelts
== 0)
1857 return; /* presumably decode_line_1 has already warned */
1859 /* Resolve line numbers to PC */
1860 resolve_sal_pc (&sals
.sals
[0]);
1861 block
= block_for_pc (sals
.sals
[0].pc
);
1865 QUIT
; /* allow user to bail out with ^C */
1866 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1868 QUIT
; /* allow user to bail out with ^C */
1870 printf_filtered ("Scope for %s:\n", save_args
);
1873 symname
= SYMBOL_PRINT_NAME (sym
);
1874 if (symname
== NULL
|| *symname
== '\0')
1875 continue; /* probably botched, certainly useless */
1877 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
1879 printf_filtered ("Symbol %s is ", symname
);
1880 switch (SYMBOL_CLASS (sym
))
1883 case LOC_UNDEF
: /* messed up symbol? */
1884 printf_filtered ("a bogus symbol, class %d.\n",
1885 SYMBOL_CLASS (sym
));
1886 count
--; /* don't count this one */
1889 printf_filtered ("a constant with value %ld (0x%lx)",
1890 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
1892 case LOC_CONST_BYTES
:
1893 printf_filtered ("constant bytes: ");
1894 if (SYMBOL_TYPE (sym
))
1895 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
1896 fprintf_filtered (gdb_stdout
, " %02x",
1897 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
1900 printf_filtered ("in static storage at address ");
1901 printf_filtered ("%s", paddress (gdbarch
,
1902 SYMBOL_VALUE_ADDRESS (sym
)));
1905 /* GDBARCH is the architecture associated with the objfile
1906 the symbol is defined in; the target architecture may be
1907 different, and may provide additional registers. However,
1908 we do not know the target architecture at this point.
1909 We assume the objfile architecture will contain all the
1910 standard registers that occur in debug info in that
1912 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1914 if (SYMBOL_IS_ARGUMENT (sym
))
1915 printf_filtered ("an argument in register $%s",
1916 gdbarch_register_name (gdbarch
, regno
));
1918 printf_filtered ("a local variable in register $%s",
1919 gdbarch_register_name (gdbarch
, regno
));
1922 printf_filtered ("an argument at stack/frame offset %ld",
1923 SYMBOL_VALUE (sym
));
1926 printf_filtered ("a local variable at frame offset %ld",
1927 SYMBOL_VALUE (sym
));
1930 printf_filtered ("a reference argument at offset %ld",
1931 SYMBOL_VALUE (sym
));
1933 case LOC_REGPARM_ADDR
:
1934 /* Note comment at LOC_REGISTER. */
1935 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1936 printf_filtered ("the address of an argument, in register $%s",
1937 gdbarch_register_name (gdbarch
, regno
));
1940 printf_filtered ("a typedef.\n");
1943 printf_filtered ("a label at address ");
1944 printf_filtered ("%s", paddress (gdbarch
,
1945 SYMBOL_VALUE_ADDRESS (sym
)));
1948 printf_filtered ("a function at address ");
1949 printf_filtered ("%s",
1950 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
1952 case LOC_UNRESOLVED
:
1953 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1956 printf_filtered ("Unresolved Static");
1959 printf_filtered ("static storage at address ");
1960 printf_filtered ("%s",
1961 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
1964 case LOC_OPTIMIZED_OUT
:
1965 printf_filtered ("optimized out.\n");
1968 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1971 if (SYMBOL_TYPE (sym
))
1972 printf_filtered (", length %d.\n",
1973 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
1975 if (BLOCK_FUNCTION (block
))
1978 block
= BLOCK_SUPERBLOCK (block
);
1981 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1985 /* worker function (cleanup) */
1987 replace_comma (void *data
)
1995 trace_dump_command (char *args
, int from_tty
)
1997 struct regcache
*regcache
;
1998 struct gdbarch
*gdbarch
;
1999 struct breakpoint
*t
;
2000 struct action_line
*action
;
2001 char *action_exp
, *next_comma
;
2002 struct cleanup
*old_cleanups
;
2003 int stepping_actions
= 0;
2004 int stepping_frame
= 0;
2006 if (!target_is_remote ())
2008 error (_("Trace can only be run on remote targets."));
2012 if (tracepoint_number
== -1)
2014 warning (_("No current trace frame."));
2018 t
= get_tracepoint (tracepoint_number
);
2021 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2024 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2026 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2027 tracepoint_number
, traceframe_number
);
2029 /* The current frame is a trap frame if the frame PC is equal
2030 to the tracepoint PC. If not, then the current frame was
2031 collected during single-stepping. */
2033 regcache
= get_current_regcache ();
2034 gdbarch
= get_regcache_arch (regcache
);
2036 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2037 - gdbarch_decr_pc_after_break (gdbarch
)));
2039 for (action
= t
->actions
; action
; action
= action
->next
)
2041 struct cmd_list_element
*cmd
;
2043 QUIT
; /* allow user to bail out with ^C */
2044 action_exp
= action
->action
;
2045 while (isspace ((int) *action_exp
))
2048 /* The collection actions to be done while stepping are
2049 bracketed by the commands "while-stepping" and "end". */
2051 if (*action_exp
== '#') /* comment line */
2054 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2056 error (_("Bad action list item: %s"), action_exp
);
2058 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2059 stepping_actions
= 1;
2060 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2061 stepping_actions
= 0;
2062 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2064 /* Display the collected data.
2065 For the trap frame, display only what was collected at
2066 the trap. Likewise for stepping frames, display only
2067 what was collected while stepping. This means that the
2068 two boolean variables, STEPPING_FRAME and
2069 STEPPING_ACTIONS should be equal. */
2070 if (stepping_frame
== stepping_actions
)
2073 { /* repeat over a comma-separated list */
2074 QUIT
; /* allow user to bail out with ^C */
2075 if (*action_exp
== ',')
2077 while (isspace ((int) *action_exp
))
2080 next_comma
= strchr (action_exp
, ',');
2082 if (0 == strncasecmp (action_exp
, "$reg", 4))
2083 registers_info (NULL
, from_tty
);
2084 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2085 locals_info (NULL
, from_tty
);
2086 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2087 args_info (NULL
, from_tty
);
2092 make_cleanup (replace_comma
, next_comma
);
2095 printf_filtered ("%s = ", action_exp
);
2096 output_command (action_exp
, from_tty
);
2097 printf_filtered ("\n");
2101 action_exp
= next_comma
;
2103 while (action_exp
&& *action_exp
== ',');
2107 discard_cleanups (old_cleanups
);
2110 /* Convert the memory pointed to by mem into hex, placing result in buf.
2111 * Return a pointer to the last char put in buf (null)
2112 * "stolen" from sparc-stub.c
2115 static const char hexchars
[] = "0123456789abcdef";
2118 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2126 *buf
++ = hexchars
[ch
>> 4];
2127 *buf
++ = hexchars
[ch
& 0xf];
2136 get_traceframe_number (void)
2138 return traceframe_number
;
2142 /* module initialization */
2144 _initialize_tracepoint (void)
2146 struct cmd_list_element
*c
;
2148 traceframe_number
= -1;
2149 tracepoint_number
= -1;
2151 if (tracepoint_list
.list
== NULL
)
2153 tracepoint_list
.listsize
= 128;
2154 tracepoint_list
.list
= xmalloc
2155 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2157 if (tracepoint_list
.aexpr_list
== NULL
)
2159 tracepoint_list
.aexpr_listsize
= 128;
2160 tracepoint_list
.aexpr_list
= xmalloc
2161 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2164 if (stepping_list
.list
== NULL
)
2166 stepping_list
.listsize
= 128;
2167 stepping_list
.list
= xmalloc
2168 (stepping_list
.listsize
* sizeof (struct memrange
));
2171 if (stepping_list
.aexpr_list
== NULL
)
2173 stepping_list
.aexpr_listsize
= 128;
2174 stepping_list
.aexpr_list
= xmalloc
2175 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2178 add_info ("scope", scope_info
,
2179 _("List the variables local to a scope"));
2181 add_cmd ("tracepoints", class_trace
, NULL
,
2182 _("Tracing of program execution without stopping the program."),
2185 add_com ("tdump", class_trace
, trace_dump_command
,
2186 _("Print everything collected at the current tracepoint."));
2188 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2189 Select a trace frame;\n\
2190 No argument means forward by one frame; '-' means backward by one frame."),
2191 &tfindlist
, "tfind ", 1, &cmdlist
);
2193 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2194 Select a trace frame whose PC is outside the given range.\n\
2195 Usage: tfind outside addr1, addr2"),
2198 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2199 Select a trace frame whose PC is in the given range.\n\
2200 Usage: tfind range addr1,addr2"),
2203 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2204 Select a trace frame by source line.\n\
2205 Argument can be a line number (with optional source file), \n\
2206 a function name, or '*' followed by an address.\n\
2207 Default argument is 'the next source line that was traced'."),
2210 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2211 Select a trace frame by tracepoint number.\n\
2212 Default is the tracepoint for the current trace frame."),
2215 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2216 Select a trace frame by PC.\n\
2217 Default is the current PC, or the PC of the current trace frame."),
2220 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2221 Synonym for 'none'.\n\
2222 De-select any trace frame and resume 'live' debugging."),
2225 add_cmd ("none", class_trace
, trace_find_none_command
,
2226 _("De-select any trace frame and resume 'live' debugging."),
2229 add_cmd ("start", class_trace
, trace_find_start_command
,
2230 _("Select the first trace frame in the trace buffer."),
2233 add_com ("tstatus", class_trace
, trace_status_command
,
2234 _("Display the status of the current trace data collection."));
2236 add_com ("tstop", class_trace
, trace_stop_command
,
2237 _("Stop trace data collection."));
2239 add_com ("tstart", class_trace
, trace_start_command
,
2240 _("Start trace data collection."));
2242 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2243 Ends a list of commands or actions.\n\
2244 Several GDB commands allow you to enter a list of commands or actions.\n\
2245 Entering \"end\" on a line by itself is the normal way to terminate\n\
2247 Note: the \"end\" command cannot be used at the gdb prompt."));
2249 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2250 Specify single-stepping behavior at a tracepoint.\n\
2251 Argument is number of instructions to trace in single-step mode\n\
2252 following the tracepoint. This command is normally followed by\n\
2253 one or more \"collect\" commands, to specify what to collect\n\
2254 while single-stepping.\n\n\
2255 Note: this command can only be used in a tracepoint \"actions\" list."));
2257 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2258 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2260 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2261 Specify one or more data items to be collected at a tracepoint.\n\
2262 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2263 collect all data (variables, registers) referenced by that expression.\n\
2264 Also accepts the following special arguments:\n\
2265 $regs -- all registers.\n\
2266 $args -- all function arguments.\n\
2267 $locals -- all variables local to the block/function scope.\n\
2268 Note: this command can only be used in a tracepoint \"actions\" list."));
2270 add_com ("actions", class_trace
, trace_actions_command
, _("\
2271 Specify the actions to be taken at a tracepoint.\n\
2272 Tracepoint actions may include collecting of specified data, \n\
2273 single-stepping, or enabling/disabling other tracepoints, \n\
2274 depending on target's capabilities."));
2276 target_buf_size
= 2048;
2277 target_buf
= xmalloc (target_buf_size
);