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"
38 #include "completer.h"
40 #include "dictionary.h"
42 #include "user-regs.h"
50 /* readline include files */
51 #include "readline/readline.h"
52 #include "readline/history.h"
54 /* readline defines this. */
61 /* Maximum length of an agent aexpression.
62 This accounts for the fact that packets are limited to 400 bytes
63 (which includes everything -- including the checksum), and assumes
64 the worst case of maximum length for each of the pieces of a
67 NOTE: expressions get mem2hex'ed otherwise this would be twice as
68 large. (400 - 31)/2 == 184 */
69 #define MAX_AGENT_EXPR_LEN 184
72 extern void (*deprecated_readline_begin_hook
) (char *, ...);
73 extern char *(*deprecated_readline_hook
) (char *);
74 extern void (*deprecated_readline_end_hook
) (void);
76 /* GDB commands implemented in other modules:
79 extern void output_command (char *, int);
84 This module defines the following debugger commands:
85 trace : set a tracepoint on a function, line, or address.
86 info trace : list all debugger-defined tracepoints.
87 delete trace : delete one or more tracepoints.
88 enable trace : enable one or more tracepoints.
89 disable trace : disable one or more tracepoints.
90 actions : specify actions to be taken at a tracepoint.
91 passcount : specify a pass count for a tracepoint.
92 tstart : start a trace experiment.
93 tstop : stop a trace experiment.
94 tstatus : query the status of a trace experiment.
95 tfind : find a trace frame in the trace buffer.
96 tdump : print everything collected at the current tracepoint.
97 save-tracepoints : write tracepoint setup into a file.
99 This module defines the following user-visible debugger variables:
100 $trace_frame : sequence number of trace frame currently being debugged.
101 $trace_line : source line of trace frame currently being debugged.
102 $trace_file : source file of trace frame currently being debugged.
103 $tracepoint : tracepoint number of trace frame currently being debugged.
107 /* ======= Important global variables: ======= */
109 /* Number of last traceframe collected. */
110 static int traceframe_number
;
112 /* Tracepoint for last traceframe collected. */
113 static int tracepoint_number
;
115 /* Symbol for function for last traceframe collected */
116 static struct symbol
*traceframe_fun
;
118 /* Symtab and line for last traceframe collected */
119 static struct symtab_and_line traceframe_sal
;
121 /* Tracing command lists */
122 static struct cmd_list_element
*tfindlist
;
124 /* ======= Important command functions: ======= */
125 static void trace_actions_command (char *, int);
126 static void trace_start_command (char *, int);
127 static void trace_stop_command (char *, int);
128 static void trace_status_command (char *, int);
129 static void trace_find_command (char *, int);
130 static void trace_find_pc_command (char *, int);
131 static void trace_find_tracepoint_command (char *, int);
132 static void trace_find_line_command (char *, int);
133 static void trace_find_range_command (char *, int);
134 static void trace_find_outside_command (char *, int);
135 static void tracepoint_save_command (char *, int);
136 static void trace_dump_command (char *, int);
138 /* support routines */
140 struct collection_list
;
141 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
142 static char *mem2hex (gdb_byte
*, char *, int);
143 static void add_register (struct collection_list
*collection
,
145 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
146 static void free_actions_list (char **actions_list
);
147 static void free_actions_list_cleanup_wrapper (void *);
149 extern void _initialize_tracepoint (void);
151 /* Utility: returns true if "target remote" */
153 target_is_remote (void)
155 if (current_target
.to_shortname
&&
156 (strcmp (current_target
.to_shortname
, "remote") == 0
157 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
163 /* Utility: generate error from an incoming stub packet. */
165 trace_error (char *buf
)
168 return; /* not an error msg */
171 case '1': /* malformed packet error */
172 if (*++buf
== '0') /* general case: */
173 error (_("tracepoint.c: error in outgoing packet."));
175 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
176 strtol (buf
, NULL
, 16));
178 error (_("trace API error 0x%s."), ++buf
);
180 error (_("Target returns error code '%s'."), buf
);
184 /* Utility: wait for reply from stub, while accepting "O" packets. */
186 remote_get_noisy_reply (char **buf_p
,
189 do /* Loop on reply from remote stub. */
192 QUIT
; /* allow user to bail out with ^C */
193 getpkt (buf_p
, sizeof_buf
, 0);
196 error (_("Target does not support this command."));
197 else if (buf
[0] == 'E')
199 else if (buf
[0] == 'O' &&
201 remote_console_output (buf
+ 1); /* 'O' message from stub */
203 return buf
; /* here's the actual reply */
208 /* Set traceframe number to NUM. */
210 set_traceframe_num (int num
)
212 traceframe_number
= num
;
213 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
216 /* Set tracepoint number to NUM. */
218 set_tracepoint_num (int num
)
220 tracepoint_number
= num
;
221 set_internalvar_integer (lookup_internalvar ("tracepoint"), 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 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
235 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
236 traceframe_sal
.symtab
= NULL
;
237 clear_internalvar (lookup_internalvar ("trace_func"));
238 clear_internalvar (lookup_internalvar ("trace_file"));
239 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
243 /* Save as globals for internal use. */
244 trace_pc
= get_frame_pc (trace_frame
);
245 traceframe_sal
= find_pc_line (trace_pc
, 0);
246 traceframe_fun
= find_pc_function (trace_pc
);
248 /* Save linenumber as "$trace_line", a debugger variable visible to
250 set_internalvar_integer (lookup_internalvar ("trace_line"),
251 traceframe_sal
.line
);
253 /* Save func name as "$trace_func", a debugger variable visible to
255 if (traceframe_fun
== NULL
256 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
257 clear_internalvar (lookup_internalvar ("trace_func"));
259 set_internalvar_string (lookup_internalvar ("trace_func"),
260 SYMBOL_LINKAGE_NAME (traceframe_fun
));
262 /* Save file name as "$trace_file", a debugger variable visible to
264 if (traceframe_sal
.symtab
== NULL
265 || traceframe_sal
.symtab
->filename
== NULL
)
266 clear_internalvar (lookup_internalvar ("trace_file"));
268 set_internalvar_string (lookup_internalvar ("trace_file"),
269 traceframe_sal
.symtab
->filename
);
272 /* ACTIONS functions: */
274 /* Prototypes for action-parsing utility commands */
275 static void read_actions (struct breakpoint
*);
277 /* The three functions:
278 collect_pseudocommand,
279 while_stepping_pseudocommand, and
280 end_actions_pseudocommand
281 are placeholders for "commands" that are actually ONLY to be used
282 within a tracepoint action list. If the actual function is ever called,
283 it means that somebody issued the "command" at the top level,
284 which is always an error. */
287 end_actions_pseudocommand (char *args
, int from_tty
)
289 error (_("This command cannot be used at the top level."));
293 while_stepping_pseudocommand (char *args
, int from_tty
)
295 error (_("This command can only be used in a tracepoint actions list."));
299 collect_pseudocommand (char *args
, int from_tty
)
301 error (_("This command can only be used in a tracepoint actions list."));
304 /* Enter a list of actions for a tracepoint. */
306 trace_actions_command (char *args
, int from_tty
)
308 struct breakpoint
*t
;
310 char *end_msg
= "End with a line saying just \"end\".";
312 t
= get_tracepoint_by_number (&args
, 0, 1);
315 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
320 if (deprecated_readline_begin_hook
)
321 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
322 else if (input_from_terminal_p ())
323 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
327 t
->step_count
= 0; /* read_actions may set this */
330 if (deprecated_readline_end_hook
)
331 (*deprecated_readline_end_hook
) ();
332 /* tracepoints_changed () */
334 /* else just return */
337 /* worker function */
339 read_actions (struct breakpoint
*t
)
342 char *prompt1
= "> ", *prompt2
= " > ";
343 char *prompt
= prompt1
;
344 enum actionline_type linetype
;
345 extern FILE *instream
;
346 struct action_line
*next
= NULL
, *temp
;
347 struct cleanup
*old_chain
;
349 /* Control-C quits instantly if typed while in this loop
350 since it should not wait until the user types a newline. */
352 /* FIXME: kettenis/20010823: Something is wrong here. In this file
353 STOP_SIGNAL is never defined. So this code has been left out, at
354 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
355 leads to compilation failures since the variable job_control
356 isn't declared. Leave this alone for now. */
359 signal (STOP_SIGNAL
, handle_stop_sig
);
361 old_chain
= make_cleanup_free_actions (t
);
364 /* Make sure that all output has been output. Some machines may
365 let you get away with leaving out some of the gdb_flush, but
368 gdb_flush (gdb_stdout
);
369 gdb_flush (gdb_stderr
);
371 if (deprecated_readline_hook
&& instream
== NULL
)
372 line
= (*deprecated_readline_hook
) (prompt
);
373 else if (instream
== stdin
&& ISATTY (instream
))
375 line
= gdb_readline_wrapper (prompt
);
376 if (line
&& *line
) /* add it to command history */
380 line
= gdb_readline (0);
384 line
= xstrdup ("end");
385 printf_filtered ("end\n");
388 linetype
= validate_actionline (&line
, t
);
389 if (linetype
== BADLINE
)
390 continue; /* already warned -- collect another line */
392 temp
= xmalloc (sizeof (struct action_line
));
396 if (next
== NULL
) /* first action for this tracepoint? */
397 t
->actions
= next
= temp
;
404 if (linetype
== STEPPING
) /* begin "while-stepping" */
406 if (prompt
== prompt2
)
408 warning (_("Already processing 'while-stepping'"));
412 prompt
= prompt2
; /* change prompt for stepping actions */
414 else if (linetype
== END
)
416 if (prompt
== prompt2
)
418 prompt
= prompt1
; /* end of single-stepping actions */
421 { /* end of actions */
422 if (t
->actions
->next
== NULL
)
424 /* An "end" all by itself with no other actions
425 means this tracepoint has no actions.
426 Discard empty list. */
435 signal (STOP_SIGNAL
, SIG_DFL
);
438 discard_cleanups (old_chain
);
441 /* worker function */
443 validate_actionline (char **line
, struct breakpoint
*t
)
445 struct cmd_list_element
*c
;
446 struct expression
*exp
= NULL
;
447 struct cleanup
*old_chain
= NULL
;
450 /* if EOF is typed, *line is NULL */
454 for (p
= *line
; isspace ((int) *p
);)
457 /* Symbol lookup etc. */
458 if (*p
== '\0') /* empty line: just prompt for another line. */
461 if (*p
== '#') /* comment line */
464 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
467 warning (_("'%s' is not an action that I know, or is ambiguous."),
472 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
474 struct agent_expr
*aexpr
;
475 struct agent_reqs areqs
;
478 { /* repeat over a comma-separated list */
479 QUIT
; /* allow user to bail out with ^C */
480 while (isspace ((int) *p
))
483 if (*p
== '$') /* look for special pseudo-symbols */
485 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
486 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
487 (0 == strncasecmp ("loc", p
+ 1, 3)))
492 /* else fall thru, treat p as an expression and parse it! */
494 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
495 old_chain
= make_cleanup (free_current_contents
, &exp
);
497 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
499 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
501 warning (_("constant %s (value %ld) will not be collected."),
502 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
503 SYMBOL_VALUE (exp
->elts
[2].symbol
));
506 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
508 warning (_("%s is optimized away and cannot be collected."),
509 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
514 /* We have something to collect, make sure that the expr to
515 bytecode translator can handle it and that it's not too
517 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
518 make_cleanup_free_agent_expr (aexpr
);
520 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
521 error (_("expression too complicated, try simplifying"));
523 ax_reqs (aexpr
, &areqs
);
524 (void) make_cleanup (xfree
, areqs
.reg_mask
);
526 if (areqs
.flaw
!= agent_flaw_none
)
527 error (_("malformed expression"));
529 if (areqs
.min_height
< 0)
530 error (_("gdb: Internal error: expression has min height < 0"));
532 if (areqs
.max_height
> 20)
533 error (_("expression too complicated, try simplifying"));
535 do_cleanups (old_chain
);
537 while (p
&& *p
++ == ',');
540 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
542 char *steparg
; /* in case warning is necessary */
544 while (isspace ((int) *p
))
549 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
551 warning (_("'%s': bad step-count; command ignored."), *line
);
556 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
560 warning (_("'%s' is not a supported tracepoint action."), *line
);
565 /* worker function */
567 free_actions (struct breakpoint
*t
)
569 struct action_line
*line
, *next
;
571 for (line
= t
->actions
; line
; line
= next
)
575 xfree (line
->action
);
582 do_free_actions_cleanup (void *t
)
587 static struct cleanup
*
588 make_cleanup_free_actions (struct breakpoint
*t
)
590 return make_cleanup (do_free_actions_cleanup
, t
);
594 memrange_absolute
= -1
599 int type
; /* memrange_absolute for absolute memory range,
600 else basereg number */
601 bfd_signed_vma start
;
605 struct collection_list
607 unsigned char regs_mask
[32]; /* room for up to 256 regs */
610 struct memrange
*list
;
611 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
613 struct agent_expr
**aexpr_list
;
616 tracepoint_list
, stepping_list
;
618 /* MEMRANGE functions: */
620 static int memrange_cmp (const void *, const void *);
622 /* compare memranges for qsort */
624 memrange_cmp (const void *va
, const void *vb
)
626 const struct memrange
*a
= va
, *b
= vb
;
628 if (a
->type
< b
->type
)
630 if (a
->type
> b
->type
)
632 if (a
->type
== memrange_absolute
)
634 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
636 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
641 if (a
->start
< b
->start
)
643 if (a
->start
> b
->start
)
649 /* Sort the memrange list using qsort, and merge adjacent memranges. */
651 memrange_sortmerge (struct collection_list
*memranges
)
655 qsort (memranges
->list
, memranges
->next_memrange
,
656 sizeof (struct memrange
), memrange_cmp
);
657 if (memranges
->next_memrange
> 0)
659 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
661 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
662 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
665 /* memrange b starts before memrange a ends; merge them. */
666 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
667 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
668 continue; /* next b, same a */
672 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
673 sizeof (struct memrange
));
675 memranges
->next_memrange
= a
+ 1;
679 /* Add a register to a collection list. */
681 add_register (struct collection_list
*collection
, unsigned int regno
)
684 printf_filtered ("collect register %d\n", regno
);
685 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
686 error (_("Internal: register number %d too large for tracepoint"),
688 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
691 /* Add a memrange to a collection list */
693 add_memrange (struct collection_list
*memranges
,
694 int type
, bfd_signed_vma base
,
699 printf_filtered ("(%d,", type
);
701 printf_filtered (",%ld)\n", len
);
704 /* type: memrange_absolute == memory, other n == basereg */
705 memranges
->list
[memranges
->next_memrange
].type
= type
;
706 /* base: addr if memory, offset if reg relative. */
707 memranges
->list
[memranges
->next_memrange
].start
= base
;
708 /* len: we actually save end (base + len) for convenience */
709 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
710 memranges
->next_memrange
++;
711 if (memranges
->next_memrange
>= memranges
->listsize
)
713 memranges
->listsize
*= 2;
714 memranges
->list
= xrealloc (memranges
->list
,
715 memranges
->listsize
);
718 if (type
!= memrange_absolute
) /* Better collect the base register! */
719 add_register (memranges
, type
);
722 /* Add a symbol to a collection list. */
724 collect_symbol (struct collection_list
*collect
,
726 struct gdbarch
*gdbarch
,
727 long frame_regno
, long frame_offset
)
731 bfd_signed_vma offset
;
733 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
734 switch (SYMBOL_CLASS (sym
))
737 printf_filtered ("%s: don't know symbol class %d\n",
738 SYMBOL_PRINT_NAME (sym
),
742 printf_filtered ("constant %s (value %ld) will not be collected.\n",
743 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
746 offset
= SYMBOL_VALUE_ADDRESS (sym
);
751 sprintf_vma (tmp
, offset
);
752 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
753 SYMBOL_PRINT_NAME (sym
), len
,
756 add_memrange (collect
, memrange_absolute
, offset
, len
);
759 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
761 printf_filtered ("LOC_REG[parm] %s: ",
762 SYMBOL_PRINT_NAME (sym
));
763 add_register (collect
, reg
);
764 /* Check for doubles stored in two registers. */
765 /* FIXME: how about larger types stored in 3 or more regs? */
766 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
767 len
> register_size (gdbarch
, reg
))
768 add_register (collect
, reg
+ 1);
771 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
772 printf_filtered (" (will not collect %s)\n",
773 SYMBOL_PRINT_NAME (sym
));
777 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
780 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
781 SYMBOL_PRINT_NAME (sym
), len
);
783 printf_filtered (" from frame ptr reg %d\n", reg
);
785 add_memrange (collect
, reg
, offset
, len
);
787 case LOC_REGPARM_ADDR
:
788 reg
= SYMBOL_VALUE (sym
);
792 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
793 SYMBOL_PRINT_NAME (sym
), len
);
795 printf_filtered (" from reg %d\n", reg
);
797 add_memrange (collect
, reg
, offset
, len
);
801 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
804 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
805 SYMBOL_PRINT_NAME (sym
), len
);
807 printf_filtered (" from frame ptr reg %d\n", reg
);
809 add_memrange (collect
, reg
, offset
, len
);
812 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
813 SYMBOL_PRINT_NAME (sym
));
815 case LOC_OPTIMIZED_OUT
:
816 printf_filtered ("%s has been optimized out of existence.\n",
817 SYMBOL_PRINT_NAME (sym
));
822 /* Add all locals (or args) symbols to collection list */
824 add_local_symbols (struct collection_list
*collect
,
825 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
826 long frame_regno
, long frame_offset
, int type
)
830 struct dict_iterator iter
;
833 block
= block_for_pc (pc
);
836 QUIT
; /* allow user to bail out with ^C */
837 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
839 if (SYMBOL_IS_ARGUMENT (sym
)
840 ? type
== 'A' /* collecting Arguments */
841 : type
== 'L') /* collecting Locals */
844 collect_symbol (collect
, sym
, gdbarch
,
845 frame_regno
, frame_offset
);
848 if (BLOCK_FUNCTION (block
))
851 block
= BLOCK_SUPERBLOCK (block
);
854 warning (_("No %s found in scope."),
855 type
== 'L' ? "locals" : "args");
858 /* worker function */
860 clear_collection_list (struct collection_list
*list
)
864 list
->next_memrange
= 0;
865 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
867 free_agent_expr (list
->aexpr_list
[ndx
]);
868 list
->aexpr_list
[ndx
] = NULL
;
870 list
->next_aexpr_elt
= 0;
871 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
874 /* reduce a collection list to string form (for gdb protocol) */
876 stringify_collection_list (struct collection_list
*list
, char *string
)
886 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
887 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
889 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
890 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
892 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
895 printf_filtered ("\nCollecting registers (mask): 0x");
900 QUIT
; /* allow user to bail out with ^C */
902 printf_filtered ("%02X", list
->regs_mask
[i
]);
903 sprintf (end
, "%02X", list
->regs_mask
[i
]);
906 (*str_list
)[ndx
] = xstrdup (temp_buf
);
910 printf_filtered ("\n");
911 if (list
->next_memrange
> 0 && info_verbose
)
912 printf_filtered ("Collecting memranges: \n");
913 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
915 QUIT
; /* allow user to bail out with ^C */
916 sprintf_vma (tmp2
, list
->list
[i
].start
);
919 printf_filtered ("(%d, %s, %ld)\n",
922 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
924 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
926 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
933 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
935 /* The "%X" conversion specifier expects an unsigned argument,
936 so passing -1 (memrange_absolute) to it directly gives you
937 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
939 if (list
->list
[i
].type
== memrange_absolute
)
940 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
942 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
945 count
+= strlen (end
);
946 end
= temp_buf
+ count
;
949 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
951 QUIT
; /* allow user to bail out with ^C */
952 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
954 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
959 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
960 end
+= 10; /* 'X' + 8 hex digits + ',' */
963 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
964 end
, list
->aexpr_list
[i
]->len
);
965 count
+= 2 * list
->aexpr_list
[i
]->len
;
970 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
975 (*str_list
)[ndx
] = NULL
;
987 free_actions_list_cleanup_wrapper (void *al
)
989 free_actions_list (al
);
993 free_actions_list (char **actions_list
)
997 if (actions_list
== 0)
1000 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1001 xfree (actions_list
[ndx
]);
1003 xfree (actions_list
);
1006 /* Render all actions into gdb protocol. */
1008 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1009 char ***stepping_actions
)
1011 static char tdp_buff
[2048], step_buff
[2048];
1013 struct expression
*exp
= NULL
;
1014 struct action_line
*action
;
1016 struct value
*tempval
;
1017 struct collection_list
*collect
;
1018 struct cmd_list_element
*cmd
;
1019 struct agent_expr
*aexpr
;
1021 LONGEST frame_offset
;
1024 clear_collection_list (&tracepoint_list
);
1025 clear_collection_list (&stepping_list
);
1026 collect
= &tracepoint_list
;
1028 *tdp_actions
= NULL
;
1029 *stepping_actions
= NULL
;
1031 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1032 t
->loc
->address
, &frame_reg
, &frame_offset
);
1034 for (action
= t
->actions
; action
; action
= action
->next
)
1036 QUIT
; /* allow user to bail out with ^C */
1037 action_exp
= action
->action
;
1038 while (isspace ((int) *action_exp
))
1041 if (*action_exp
== '#') /* comment line */
1044 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1046 error (_("Bad action list item: %s"), action_exp
);
1048 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1051 { /* repeat over a comma-separated list */
1052 QUIT
; /* allow user to bail out with ^C */
1053 while (isspace ((int) *action_exp
))
1056 if (0 == strncasecmp ("$reg", action_exp
, 4))
1058 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1059 add_register (collect
, i
);
1060 action_exp
= strchr (action_exp
, ','); /* more? */
1062 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1064 add_local_symbols (collect
,
1070 action_exp
= strchr (action_exp
, ','); /* more? */
1072 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1074 add_local_symbols (collect
,
1080 action_exp
= strchr (action_exp
, ','); /* more? */
1084 unsigned long addr
, len
;
1085 struct cleanup
*old_chain
= NULL
;
1086 struct cleanup
*old_chain1
= NULL
;
1087 struct agent_reqs areqs
;
1089 exp
= parse_exp_1 (&action_exp
,
1090 block_for_pc (t
->loc
->address
), 1);
1091 old_chain
= make_cleanup (free_current_contents
, &exp
);
1093 switch (exp
->elts
[0].opcode
)
1097 const char *name
= &exp
->elts
[2].string
;
1099 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1100 name
, strlen (name
));
1102 internal_error (__FILE__
, __LINE__
,
1103 _("Register $%s not available"),
1106 printf_filtered ("OP_REGISTER: ");
1107 add_register (collect
, i
);
1112 /* safe because we know it's a simple expression */
1113 tempval
= evaluate_expression (exp
);
1114 addr
= value_address (tempval
);
1115 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1116 add_memrange (collect
, memrange_absolute
, addr
, len
);
1120 collect_symbol (collect
,
1121 exp
->elts
[2].symbol
,
1127 default: /* full-fledged expression */
1128 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1130 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1132 ax_reqs (aexpr
, &areqs
);
1133 if (areqs
.flaw
!= agent_flaw_none
)
1134 error (_("malformed expression"));
1136 if (areqs
.min_height
< 0)
1137 error (_("gdb: Internal error: expression has min height < 0"));
1138 if (areqs
.max_height
> 20)
1139 error (_("expression too complicated, try simplifying"));
1141 discard_cleanups (old_chain1
);
1142 add_aexpr (collect
, aexpr
);
1144 /* take care of the registers */
1145 if (areqs
.reg_mask_len
> 0)
1150 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1152 QUIT
; /* allow user to bail out with ^C */
1153 if (areqs
.reg_mask
[ndx1
] != 0)
1155 /* assume chars have 8 bits */
1156 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1157 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1158 /* it's used -- record it */
1159 add_register (collect
,
1166 do_cleanups (old_chain
);
1169 while (action_exp
&& *action_exp
++ == ',');
1171 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1173 collect
= &stepping_list
;
1175 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1177 if (collect
== &stepping_list
) /* end stepping actions */
1178 collect
= &tracepoint_list
;
1180 break; /* end tracepoint actions */
1183 memrange_sortmerge (&tracepoint_list
);
1184 memrange_sortmerge (&stepping_list
);
1186 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1188 *stepping_actions
= stringify_collection_list (&stepping_list
,
1193 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1195 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1197 collect
->aexpr_list
=
1198 xrealloc (collect
->aexpr_list
,
1199 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1200 collect
->aexpr_listsize
*= 2;
1202 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1203 collect
->next_aexpr_elt
++;
1206 static char *target_buf
;
1207 static long target_buf_size
;
1209 /* Set "transparent" memory ranges
1211 Allow trace mechanism to treat text-like sections
1212 (and perhaps all read-only sections) transparently,
1213 i.e. don't reject memory requests from these address ranges
1214 just because they haven't been collected. */
1217 remote_set_transparent_ranges (void)
1225 return; /* No information to give. */
1227 strcpy (target_buf
, "QTro");
1228 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1230 char tmp1
[40], tmp2
[40];
1232 if ((s
->flags
& SEC_LOAD
) == 0 ||
1233 /* (s->flags & SEC_CODE) == 0 || */
1234 (s
->flags
& SEC_READONLY
) == 0)
1239 size
= bfd_get_section_size (s
);
1240 sprintf_vma (tmp1
, lma
);
1241 sprintf_vma (tmp2
, lma
+ size
);
1242 sprintf (target_buf
+ strlen (target_buf
),
1243 ":%s,%s", tmp1
, tmp2
);
1247 putpkt (target_buf
);
1248 getpkt (&target_buf
, &target_buf_size
, 0);
1254 Tell target to clear any previous trace experiment.
1255 Walk the list of tracepoints, and send them (and their actions)
1256 to the target. If no errors,
1257 Tell target to start a new trace experiment. */
1259 void download_tracepoint (struct breakpoint
*t
);
1262 trace_start_command (char *args
, int from_tty
)
1264 VEC(breakpoint_p
) *tp_vec
= NULL
;
1266 struct breakpoint
*t
;
1268 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1270 if (target_is_remote ())
1273 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1274 if (strcmp (target_buf
, "OK"))
1275 error (_("Target does not support this command."));
1277 tp_vec
= all_tracepoints ();
1278 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1280 download_tracepoint (t
);
1282 VEC_free (breakpoint_p
, tp_vec
);
1284 /* Tell target to treat text-like sections as transparent. */
1285 remote_set_transparent_ranges ();
1286 /* Now insert traps and begin collecting data. */
1288 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1289 if (strcmp (target_buf
, "OK"))
1290 error (_("Bogus reply from target: %s"), target_buf
);
1291 set_traceframe_num (-1); /* All old traceframes invalidated. */
1292 set_tracepoint_num (-1);
1293 set_traceframe_context (NULL
);
1294 trace_running_p
= 1;
1295 if (deprecated_trace_start_stop_hook
)
1296 deprecated_trace_start_stop_hook (1, from_tty
);
1300 error (_("Trace can only be run on remote targets."));
1303 /* Send the definition of a single tracepoint to the target. */
1306 download_tracepoint (struct breakpoint
*t
)
1311 char **stepping_actions
;
1313 struct cleanup
*old_chain
= NULL
;
1315 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1316 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1318 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1319 t
->step_count
, t
->pass_count
);
1324 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1325 if (strcmp (target_buf
, "OK"))
1326 error (_("Target does not support tracepoints."));
1331 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1332 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1334 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1336 /* do_single_steps (t); */
1339 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1341 QUIT
; /* allow user to bail out with ^C */
1342 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1343 t
->number
, tmp
, /* address */
1345 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1348 remote_get_noisy_reply (&target_buf
,
1350 if (strcmp (target_buf
, "OK"))
1351 error (_("Error on target while setting tracepoints."));
1354 if (stepping_actions
)
1356 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1358 QUIT
; /* allow user to bail out with ^C */
1359 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1360 t
->number
, tmp
, /* address */
1361 ((ndx
== 0) ? "S" : ""),
1362 stepping_actions
[ndx
],
1363 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1365 remote_get_noisy_reply (&target_buf
,
1367 if (strcmp (target_buf
, "OK"))
1368 error (_("Error on target while setting tracepoints."));
1371 do_cleanups (old_chain
);
1376 trace_stop_command (char *args
, int from_tty
)
1378 if (target_is_remote ())
1381 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1382 if (strcmp (target_buf
, "OK"))
1383 error (_("Bogus reply from target: %s"), target_buf
);
1384 trace_running_p
= 0;
1385 if (deprecated_trace_start_stop_hook
)
1386 deprecated_trace_start_stop_hook (0, from_tty
);
1389 error (_("Trace can only be run on remote targets."));
1392 unsigned long trace_running_p
;
1394 /* tstatus command */
1396 trace_status_command (char *args
, int from_tty
)
1398 if (target_is_remote ())
1400 putpkt ("qTStatus");
1401 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1403 if (target_buf
[0] != 'T' ||
1404 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1405 error (_("Bogus reply from target: %s"), target_buf
);
1407 /* exported for use by the GUI */
1408 trace_running_p
= (target_buf
[1] == '1');
1411 error (_("Trace can only be run on remote targets."));
1414 /* Worker function for the various flavors of the tfind command. */
1416 finish_tfind_command (char **msg
,
1420 int target_frameno
= -1, target_tracept
= -1;
1421 struct frame_id old_frame_id
;
1424 old_frame_id
= get_frame_id (get_current_frame ());
1427 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1429 while (reply
&& *reply
)
1433 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1435 /* A request for a non-existant trace frame has failed.
1436 Our response will be different, depending on FROM_TTY:
1438 If FROM_TTY is true, meaning that this command was
1439 typed interactively by the user, then give an error
1440 and DO NOT change the state of traceframe_number etc.
1442 However if FROM_TTY is false, meaning that we're either
1443 in a script, a loop, or a user-defined command, then
1444 DON'T give an error, but DO change the state of
1445 traceframe_number etc. to invalid.
1447 The rationalle is that if you typed the command, you
1448 might just have committed a typo or something, and you'd
1449 like to NOT lose your current debugging state. However
1450 if you're in a user-defined command or especially in a
1451 loop, then you need a way to detect that the command
1452 failed WITHOUT aborting. This allows you to write
1453 scripts that search thru the trace buffer until the end,
1454 and then continue on to do something else. */
1457 error (_("Target failed to find requested trace frame."));
1461 printf_filtered ("End of trace buffer.\n");
1462 /* The following will not recurse, since it's
1464 trace_find_command ("-1", from_tty
);
1465 reply
= NULL
; /* Break out of loop
1466 (avoid recursive nonsense). */
1471 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1472 error (_("Target failed to find requested trace frame."));
1474 case 'O': /* "OK"? */
1475 if (reply
[1] == 'K' && reply
[2] == '\0')
1478 error (_("Bogus reply from target: %s"), reply
);
1481 error (_("Bogus reply from target: %s"), reply
);
1484 reinit_frame_cache ();
1485 registers_changed ();
1486 set_traceframe_num (target_frameno
);
1487 set_tracepoint_num (target_tracept
);
1488 if (target_frameno
== -1)
1489 set_traceframe_context (NULL
);
1491 set_traceframe_context (get_current_frame ());
1495 enum print_what print_what
;
1497 /* NOTE: in immitation of the step command, try to determine
1498 whether we have made a transition from one function to
1499 another. If so, we'll print the "stack frame" (ie. the new
1500 function and it's arguments) -- otherwise we'll just show the
1503 if (frame_id_eq (old_frame_id
,
1504 get_frame_id (get_current_frame ())))
1505 print_what
= SRC_LINE
;
1507 print_what
= SRC_AND_LOC
;
1509 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1514 /* trace_find_command takes a trace frame number n,
1515 sends "QTFrame:<n>" to the target,
1516 and accepts a reply that may contain several optional pieces
1517 of information: a frame number, a tracepoint number, and an
1518 indication of whether this is a trap frame or a stepping frame.
1520 The minimal response is just "OK" (which indicates that the
1521 target does not give us a frame number or a tracepoint number).
1522 Instead of that, the target may send us a string containing
1524 F<hexnum> (gives the selected frame number)
1525 T<hexnum> (gives the selected tracepoint number)
1530 trace_find_command (char *args
, int from_tty
)
1531 { /* this should only be called with a numeric argument */
1534 if (target_is_remote ())
1536 if (deprecated_trace_find_hook
)
1537 deprecated_trace_find_hook (args
, from_tty
);
1539 if (args
== 0 || *args
== 0)
1540 { /* TFIND with no args means find NEXT trace frame. */
1541 if (traceframe_number
== -1)
1542 frameno
= 0; /* "next" is first one */
1544 frameno
= traceframe_number
+ 1;
1546 else if (0 == strcmp (args
, "-"))
1548 if (traceframe_number
== -1)
1549 error (_("not debugging trace buffer"));
1550 else if (from_tty
&& traceframe_number
== 0)
1551 error (_("already at start of trace buffer"));
1553 frameno
= traceframe_number
- 1;
1556 frameno
= parse_and_eval_long (args
);
1559 error (_("invalid input (%d is less than zero)"), frameno
);
1561 sprintf (target_buf
, "QTFrame:%x", frameno
);
1562 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1565 error (_("Trace can only be run on remote targets."));
1570 trace_find_end_command (char *args
, int from_tty
)
1572 trace_find_command ("-1", from_tty
);
1577 trace_find_none_command (char *args
, int from_tty
)
1579 trace_find_command ("-1", from_tty
);
1584 trace_find_start_command (char *args
, int from_tty
)
1586 trace_find_command ("0", from_tty
);
1589 /* tfind pc command */
1591 trace_find_pc_command (char *args
, int from_tty
)
1596 if (target_is_remote ())
1598 if (args
== 0 || *args
== 0)
1599 pc
= regcache_read_pc (get_current_regcache ());
1601 pc
= parse_and_eval_address (args
);
1603 sprintf_vma (tmp
, pc
);
1604 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
1605 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1608 error (_("Trace can only be run on remote targets."));
1611 /* tfind tracepoint command */
1613 trace_find_tracepoint_command (char *args
, int from_tty
)
1617 if (target_is_remote ())
1619 if (args
== 0 || *args
== 0)
1621 if (tracepoint_number
== -1)
1622 error (_("No current tracepoint -- please supply an argument."));
1624 tdp
= tracepoint_number
; /* default is current TDP */
1627 tdp
= parse_and_eval_long (args
);
1629 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1630 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1633 error (_("Trace can only be run on remote targets."));
1636 /* TFIND LINE command:
1638 This command will take a sourceline for argument, just like BREAK
1639 or TRACE (ie. anything that "decode_line_1" can handle).
1641 With no argument, this command will find the next trace frame
1642 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1645 trace_find_line_command (char *args
, int from_tty
)
1647 static CORE_ADDR start_pc
, end_pc
;
1648 struct symtabs_and_lines sals
;
1649 struct symtab_and_line sal
;
1650 struct cleanup
*old_chain
;
1651 char startpc_str
[40], endpc_str
[40];
1653 if (target_is_remote ())
1655 if (args
== 0 || *args
== 0)
1657 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1659 sals
.sals
= (struct symtab_and_line
*)
1660 xmalloc (sizeof (struct symtab_and_line
));
1665 sals
= decode_line_spec (args
, 1);
1669 old_chain
= make_cleanup (xfree
, sals
.sals
);
1670 if (sal
.symtab
== 0)
1672 struct gdbarch
*gdbarch
= get_current_arch ();
1674 printf_filtered ("TFIND: No line number information available");
1677 /* This is useful for "info line *0x7f34". If we can't
1678 tell the user about a source line, at least let them
1679 have the symbolic address. */
1680 printf_filtered (" for address ");
1682 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
1683 printf_filtered (";\n -- will attempt to find by PC. \n");
1687 printf_filtered (".\n");
1688 return; /* No line, no PC; what can we do? */
1691 else if (sal
.line
> 0
1692 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1694 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
1696 if (start_pc
== end_pc
)
1698 printf_filtered ("Line %d of \"%s\"",
1699 sal
.line
, sal
.symtab
->filename
);
1701 printf_filtered (" is at address ");
1702 print_address (gdbarch
, start_pc
, gdb_stdout
);
1704 printf_filtered (" but contains no code.\n");
1705 sal
= find_pc_line (start_pc
, 0);
1707 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1709 printf_filtered ("Attempting to find line %d instead.\n",
1712 error (_("Cannot find a good line."));
1716 /* Is there any case in which we get here, and have an address
1717 which the user would want to see? If we have debugging
1718 symbols and no line numbers? */
1719 error (_("Line number %d is out of range for \"%s\"."),
1720 sal
.line
, sal
.symtab
->filename
);
1722 sprintf_vma (startpc_str
, start_pc
);
1723 sprintf_vma (endpc_str
, end_pc
- 1);
1724 /* Find within range of stated line. */
1726 sprintf (target_buf
, "QTFrame:range:%s:%s",
1727 startpc_str
, endpc_str
);
1728 /* Find OUTSIDE OF range of CURRENT line. */
1730 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1731 startpc_str
, endpc_str
);
1732 finish_tfind_command (&target_buf
, &target_buf_size
,
1734 do_cleanups (old_chain
);
1737 error (_("Trace can only be run on remote targets."));
1740 /* tfind range command */
1742 trace_find_range_command (char *args
, int from_tty
)
1744 static CORE_ADDR start
, stop
;
1745 char start_str
[40], stop_str
[40];
1748 if (target_is_remote ())
1750 if (args
== 0 || *args
== 0)
1751 { /* XXX FIXME: what should default behavior be? */
1752 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1756 if (0 != (tmp
= strchr (args
, ',')))
1758 *tmp
++ = '\0'; /* terminate start address */
1759 while (isspace ((int) *tmp
))
1761 start
= parse_and_eval_address (args
);
1762 stop
= parse_and_eval_address (tmp
);
1765 { /* no explicit end address? */
1766 start
= parse_and_eval_address (args
);
1767 stop
= start
+ 1; /* ??? */
1770 sprintf_vma (start_str
, start
);
1771 sprintf_vma (stop_str
, stop
);
1772 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1773 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1776 error (_("Trace can only be run on remote targets."));
1779 /* tfind outside command */
1781 trace_find_outside_command (char *args
, int from_tty
)
1783 CORE_ADDR start
, stop
;
1784 char start_str
[40], stop_str
[40];
1787 if (target_is_remote ())
1789 if (args
== 0 || *args
== 0)
1790 { /* XXX FIXME: what should default behavior be? */
1791 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1795 if (0 != (tmp
= strchr (args
, ',')))
1797 *tmp
++ = '\0'; /* terminate start address */
1798 while (isspace ((int) *tmp
))
1800 start
= parse_and_eval_address (args
);
1801 stop
= parse_and_eval_address (tmp
);
1804 { /* no explicit end address? */
1805 start
= parse_and_eval_address (args
);
1806 stop
= start
+ 1; /* ??? */
1809 sprintf_vma (start_str
, start
);
1810 sprintf_vma (stop_str
, stop
);
1811 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1812 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1815 error (_("Trace can only be run on remote targets."));
1818 /* info scope command: list the locals for a scope. */
1820 scope_info (char *args
, int from_tty
)
1822 struct symtabs_and_lines sals
;
1824 struct minimal_symbol
*msym
;
1825 struct block
*block
;
1826 char **canonical
, *symname
, *save_args
= args
;
1827 struct dict_iterator iter
;
1829 struct gdbarch
*gdbarch
;
1832 if (args
== 0 || *args
== 0)
1833 error (_("requires an argument (function, line or *addr) to define a scope"));
1835 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1836 if (sals
.nelts
== 0)
1837 return; /* presumably decode_line_1 has already warned */
1839 /* Resolve line numbers to PC */
1840 resolve_sal_pc (&sals
.sals
[0]);
1841 block
= block_for_pc (sals
.sals
[0].pc
);
1845 QUIT
; /* allow user to bail out with ^C */
1846 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1848 QUIT
; /* allow user to bail out with ^C */
1850 printf_filtered ("Scope for %s:\n", save_args
);
1853 symname
= SYMBOL_PRINT_NAME (sym
);
1854 if (symname
== NULL
|| *symname
== '\0')
1855 continue; /* probably botched, certainly useless */
1857 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
1859 printf_filtered ("Symbol %s is ", symname
);
1860 switch (SYMBOL_CLASS (sym
))
1863 case LOC_UNDEF
: /* messed up symbol? */
1864 printf_filtered ("a bogus symbol, class %d.\n",
1865 SYMBOL_CLASS (sym
));
1866 count
--; /* don't count this one */
1869 printf_filtered ("a constant with value %ld (0x%lx)",
1870 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
1872 case LOC_CONST_BYTES
:
1873 printf_filtered ("constant bytes: ");
1874 if (SYMBOL_TYPE (sym
))
1875 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
1876 fprintf_filtered (gdb_stdout
, " %02x",
1877 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
1880 printf_filtered ("in static storage at address ");
1881 printf_filtered ("%s", paddress (gdbarch
,
1882 SYMBOL_VALUE_ADDRESS (sym
)));
1885 /* GDBARCH is the architecture associated with the objfile
1886 the symbol is defined in; the target architecture may be
1887 different, and may provide additional registers. However,
1888 we do not know the target architecture at this point.
1889 We assume the objfile architecture will contain all the
1890 standard registers that occur in debug info in that
1892 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1894 if (SYMBOL_IS_ARGUMENT (sym
))
1895 printf_filtered ("an argument in register $%s",
1896 gdbarch_register_name (gdbarch
, regno
));
1898 printf_filtered ("a local variable in register $%s",
1899 gdbarch_register_name (gdbarch
, regno
));
1902 printf_filtered ("an argument at stack/frame offset %ld",
1903 SYMBOL_VALUE (sym
));
1906 printf_filtered ("a local variable at frame offset %ld",
1907 SYMBOL_VALUE (sym
));
1910 printf_filtered ("a reference argument at offset %ld",
1911 SYMBOL_VALUE (sym
));
1913 case LOC_REGPARM_ADDR
:
1914 /* Note comment at LOC_REGISTER. */
1915 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1916 printf_filtered ("the address of an argument, in register $%s",
1917 gdbarch_register_name (gdbarch
, regno
));
1920 printf_filtered ("a typedef.\n");
1923 printf_filtered ("a label at address ");
1924 printf_filtered ("%s", paddress (gdbarch
,
1925 SYMBOL_VALUE_ADDRESS (sym
)));
1928 printf_filtered ("a function at address ");
1929 printf_filtered ("%s",
1930 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
1932 case LOC_UNRESOLVED
:
1933 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1936 printf_filtered ("Unresolved Static");
1939 printf_filtered ("static storage at address ");
1940 printf_filtered ("%s",
1941 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
1944 case LOC_OPTIMIZED_OUT
:
1945 printf_filtered ("optimized out.\n");
1948 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1951 if (SYMBOL_TYPE (sym
))
1952 printf_filtered (", length %d.\n",
1953 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
1955 if (BLOCK_FUNCTION (block
))
1958 block
= BLOCK_SUPERBLOCK (block
);
1961 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1965 /* worker function (cleanup) */
1967 replace_comma (void *data
)
1975 trace_dump_command (char *args
, int from_tty
)
1977 struct regcache
*regcache
;
1978 struct gdbarch
*gdbarch
;
1979 struct breakpoint
*t
;
1980 struct action_line
*action
;
1981 char *action_exp
, *next_comma
;
1982 struct cleanup
*old_cleanups
;
1983 int stepping_actions
= 0;
1984 int stepping_frame
= 0;
1986 if (!target_is_remote ())
1988 error (_("Trace can only be run on remote targets."));
1992 if (tracepoint_number
== -1)
1994 warning (_("No current trace frame."));
1998 t
= get_tracepoint (tracepoint_number
);
2001 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2004 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2006 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2007 tracepoint_number
, traceframe_number
);
2009 /* The current frame is a trap frame if the frame PC is equal
2010 to the tracepoint PC. If not, then the current frame was
2011 collected during single-stepping. */
2013 regcache
= get_current_regcache ();
2014 gdbarch
= get_regcache_arch (regcache
);
2016 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2017 - gdbarch_decr_pc_after_break (gdbarch
)));
2019 for (action
= t
->actions
; action
; action
= action
->next
)
2021 struct cmd_list_element
*cmd
;
2023 QUIT
; /* allow user to bail out with ^C */
2024 action_exp
= action
->action
;
2025 while (isspace ((int) *action_exp
))
2028 /* The collection actions to be done while stepping are
2029 bracketed by the commands "while-stepping" and "end". */
2031 if (*action_exp
== '#') /* comment line */
2034 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2036 error (_("Bad action list item: %s"), action_exp
);
2038 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2039 stepping_actions
= 1;
2040 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2041 stepping_actions
= 0;
2042 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2044 /* Display the collected data.
2045 For the trap frame, display only what was collected at
2046 the trap. Likewise for stepping frames, display only
2047 what was collected while stepping. This means that the
2048 two boolean variables, STEPPING_FRAME and
2049 STEPPING_ACTIONS should be equal. */
2050 if (stepping_frame
== stepping_actions
)
2053 { /* repeat over a comma-separated list */
2054 QUIT
; /* allow user to bail out with ^C */
2055 if (*action_exp
== ',')
2057 while (isspace ((int) *action_exp
))
2060 next_comma
= strchr (action_exp
, ',');
2062 if (0 == strncasecmp (action_exp
, "$reg", 4))
2063 registers_info (NULL
, from_tty
);
2064 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2065 locals_info (NULL
, from_tty
);
2066 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2067 args_info (NULL
, from_tty
);
2072 make_cleanup (replace_comma
, next_comma
);
2075 printf_filtered ("%s = ", action_exp
);
2076 output_command (action_exp
, from_tty
);
2077 printf_filtered ("\n");
2081 action_exp
= next_comma
;
2083 while (action_exp
&& *action_exp
== ',');
2087 discard_cleanups (old_cleanups
);
2090 /* Convert the memory pointed to by mem into hex, placing result in buf.
2091 * Return a pointer to the last char put in buf (null)
2092 * "stolen" from sparc-stub.c
2095 static const char hexchars
[] = "0123456789abcdef";
2098 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2106 *buf
++ = hexchars
[ch
>> 4];
2107 *buf
++ = hexchars
[ch
& 0xf];
2116 get_traceframe_number (void)
2118 return traceframe_number
;
2122 /* module initialization */
2124 _initialize_tracepoint (void)
2126 struct cmd_list_element
*c
;
2128 traceframe_number
= -1;
2129 tracepoint_number
= -1;
2131 if (tracepoint_list
.list
== NULL
)
2133 tracepoint_list
.listsize
= 128;
2134 tracepoint_list
.list
= xmalloc
2135 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2137 if (tracepoint_list
.aexpr_list
== NULL
)
2139 tracepoint_list
.aexpr_listsize
= 128;
2140 tracepoint_list
.aexpr_list
= xmalloc
2141 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2144 if (stepping_list
.list
== NULL
)
2146 stepping_list
.listsize
= 128;
2147 stepping_list
.list
= xmalloc
2148 (stepping_list
.listsize
* sizeof (struct memrange
));
2151 if (stepping_list
.aexpr_list
== NULL
)
2153 stepping_list
.aexpr_listsize
= 128;
2154 stepping_list
.aexpr_list
= xmalloc
2155 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2158 add_info ("scope", scope_info
,
2159 _("List the variables local to a scope"));
2161 add_cmd ("tracepoints", class_trace
, NULL
,
2162 _("Tracing of program execution without stopping the program."),
2165 add_com ("tdump", class_trace
, trace_dump_command
,
2166 _("Print everything collected at the current tracepoint."));
2168 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2169 Select a trace frame;\n\
2170 No argument means forward by one frame; '-' means backward by one frame."),
2171 &tfindlist
, "tfind ", 1, &cmdlist
);
2173 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2174 Select a trace frame whose PC is outside the given range.\n\
2175 Usage: tfind outside addr1, addr2"),
2178 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2179 Select a trace frame whose PC is in the given range.\n\
2180 Usage: tfind range addr1,addr2"),
2183 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2184 Select a trace frame by source line.\n\
2185 Argument can be a line number (with optional source file), \n\
2186 a function name, or '*' followed by an address.\n\
2187 Default argument is 'the next source line that was traced'."),
2190 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2191 Select a trace frame by tracepoint number.\n\
2192 Default is the tracepoint for the current trace frame."),
2195 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2196 Select a trace frame by PC.\n\
2197 Default is the current PC, or the PC of the current trace frame."),
2200 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2201 Synonym for 'none'.\n\
2202 De-select any trace frame and resume 'live' debugging."),
2205 add_cmd ("none", class_trace
, trace_find_none_command
,
2206 _("De-select any trace frame and resume 'live' debugging."),
2209 add_cmd ("start", class_trace
, trace_find_start_command
,
2210 _("Select the first trace frame in the trace buffer."),
2213 add_com ("tstatus", class_trace
, trace_status_command
,
2214 _("Display the status of the current trace data collection."));
2216 add_com ("tstop", class_trace
, trace_stop_command
,
2217 _("Stop trace data collection."));
2219 add_com ("tstart", class_trace
, trace_start_command
,
2220 _("Start trace data collection."));
2222 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2223 Ends a list of commands or actions.\n\
2224 Several GDB commands allow you to enter a list of commands or actions.\n\
2225 Entering \"end\" on a line by itself is the normal way to terminate\n\
2227 Note: the \"end\" command cannot be used at the gdb prompt."));
2229 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2230 Specify single-stepping behavior at a tracepoint.\n\
2231 Argument is number of instructions to trace in single-step mode\n\
2232 following the tracepoint. This command is normally followed by\n\
2233 one or more \"collect\" commands, to specify what to collect\n\
2234 while single-stepping.\n\n\
2235 Note: this command can only be used in a tracepoint \"actions\" list."));
2237 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2238 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2240 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2241 Specify one or more data items to be collected at a tracepoint.\n\
2242 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2243 collect all data (variables, registers) referenced by that expression.\n\
2244 Also accepts the following special arguments:\n\
2245 $regs -- all registers.\n\
2246 $args -- all function arguments.\n\
2247 $locals -- all variables local to the block/function scope.\n\
2248 Note: this command can only be used in a tracepoint \"actions\" list."));
2250 add_com ("actions", class_trace
, trace_actions_command
, _("\
2251 Specify the actions to be taken at a tracepoint.\n\
2252 Tracepoint actions may include collecting of specified data, \n\
2253 single-stepping, or enabling/disabling other tracepoints, \n\
2254 depending on target's capabilities."));
2256 target_buf_size
= 2048;
2257 target_buf
= xmalloc (target_buf_size
);