1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007, 2008, 2009 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "expression.h"
30 #include "gdb_string.h"
32 #include "breakpoint.h"
33 #include "tracepoint.h"
37 #include "completer.h"
39 #include "dictionary.h"
41 #include "user-regs.h"
49 /* readline include files */
50 #include "readline/readline.h"
51 #include "readline/history.h"
53 /* readline defines this. */
60 /* Maximum length of an agent aexpression.
61 This accounts for the fact that packets are limited to 400 bytes
62 (which includes everything -- including the checksum), and assumes
63 the worst case of maximum length for each of the pieces of a
66 NOTE: expressions get mem2hex'ed otherwise this would be twice as
67 large. (400 - 31)/2 == 184 */
68 #define MAX_AGENT_EXPR_LEN 184
71 extern void (*deprecated_readline_begin_hook
) (char *, ...);
72 extern char *(*deprecated_readline_hook
) (char *);
73 extern void (*deprecated_readline_end_hook
) (void);
75 /* GDB commands implemented in other modules:
78 extern void output_command (char *, int);
83 This module defines the following debugger commands:
84 trace : set a tracepoint on a function, line, or address.
85 info trace : list all debugger-defined tracepoints.
86 delete trace : delete one or more tracepoints.
87 enable trace : enable one or more tracepoints.
88 disable trace : disable one or more tracepoints.
89 actions : specify actions to be taken at a tracepoint.
90 passcount : specify a pass count for a tracepoint.
91 tstart : start a trace experiment.
92 tstop : stop a trace experiment.
93 tstatus : query the status of a trace experiment.
94 tfind : find a trace frame in the trace buffer.
95 tdump : print everything collected at the current tracepoint.
96 save-tracepoints : write tracepoint setup into a file.
98 This module defines the following user-visible debugger variables:
99 $trace_frame : sequence number of trace frame currently being debugged.
100 $trace_line : source line of trace frame currently being debugged.
101 $trace_file : source file of trace frame currently being debugged.
102 $tracepoint : tracepoint number of trace frame currently being debugged.
106 /* ======= Important global variables: ======= */
108 /* Number of last traceframe collected. */
109 static int traceframe_number
;
111 /* Tracepoint for last traceframe collected. */
112 static int tracepoint_number
;
114 /* Symbol for function for last traceframe collected */
115 static struct symbol
*traceframe_fun
;
117 /* Symtab and line for last traceframe collected */
118 static struct symtab_and_line traceframe_sal
;
120 /* Tracing command lists */
121 static struct cmd_list_element
*tfindlist
;
123 /* ======= Important command functions: ======= */
124 static void trace_actions_command (char *, int);
125 static void trace_start_command (char *, int);
126 static void trace_stop_command (char *, int);
127 static void trace_status_command (char *, int);
128 static void trace_find_command (char *, int);
129 static void trace_find_pc_command (char *, int);
130 static void trace_find_tracepoint_command (char *, int);
131 static void trace_find_line_command (char *, int);
132 static void trace_find_range_command (char *, int);
133 static void trace_find_outside_command (char *, int);
134 static void tracepoint_save_command (char *, int);
135 static void trace_dump_command (char *, int);
137 /* support routines */
139 struct collection_list
;
140 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
141 static char *mem2hex (gdb_byte
*, char *, int);
142 static void add_register (struct collection_list
*collection
,
144 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
145 static void free_actions_list (char **actions_list
);
146 static void free_actions_list_cleanup_wrapper (void *);
148 extern void _initialize_tracepoint (void);
150 /* Utility: returns true if "target remote" */
152 target_is_remote (void)
154 if (current_target
.to_shortname
&&
155 (strcmp (current_target
.to_shortname
, "remote") == 0
156 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
162 /* Utility: generate error from an incoming stub packet. */
164 trace_error (char *buf
)
167 return; /* not an error msg */
170 case '1': /* malformed packet error */
171 if (*++buf
== '0') /* general case: */
172 error (_("tracepoint.c: error in outgoing packet."));
174 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
175 strtol (buf
, NULL
, 16));
177 error (_("trace API error 0x%s."), ++buf
);
179 error (_("Target returns error code '%s'."), buf
);
183 /* Utility: wait for reply from stub, while accepting "O" packets. */
185 remote_get_noisy_reply (char **buf_p
,
188 do /* Loop on reply from remote stub. */
191 QUIT
; /* allow user to bail out with ^C */
192 getpkt (buf_p
, sizeof_buf
, 0);
195 error (_("Target does not support this command."));
196 else if (buf
[0] == 'E')
198 else if (buf
[0] == 'O' &&
200 remote_console_output (buf
+ 1); /* 'O' message from stub */
202 return buf
; /* here's the actual reply */
207 /* Set traceframe number to NUM. */
209 set_traceframe_num (int num
)
211 traceframe_number
= num
;
212 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
215 /* Set tracepoint number to NUM. */
217 set_tracepoint_num (int num
)
219 tracepoint_number
= num
;
220 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
223 /* Set externally visible debug variables for querying/printing
224 the traceframe context (line, function, file) */
227 set_traceframe_context (struct frame_info
*trace_frame
)
231 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
234 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
235 traceframe_sal
.symtab
= NULL
;
236 clear_internalvar (lookup_internalvar ("trace_func"));
237 clear_internalvar (lookup_internalvar ("trace_file"));
238 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
242 /* Save as globals for internal use. */
243 trace_pc
= get_frame_pc (trace_frame
);
244 traceframe_sal
= find_pc_line (trace_pc
, 0);
245 traceframe_fun
= find_pc_function (trace_pc
);
247 /* Save linenumber as "$trace_line", a debugger variable visible to
249 set_internalvar_integer (lookup_internalvar ("trace_line"),
250 traceframe_sal
.line
);
252 /* Save func name as "$trace_func", a debugger variable visible to
254 if (traceframe_fun
== NULL
255 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
256 clear_internalvar (lookup_internalvar ("trace_func"));
258 set_internalvar_string (lookup_internalvar ("trace_func"),
259 SYMBOL_LINKAGE_NAME (traceframe_fun
));
261 /* Save file name as "$trace_file", a debugger variable visible to
263 if (traceframe_sal
.symtab
== NULL
264 || traceframe_sal
.symtab
->filename
== NULL
)
265 clear_internalvar (lookup_internalvar ("trace_file"));
267 set_internalvar_string (lookup_internalvar ("trace_file"),
268 traceframe_sal
.symtab
->filename
);
271 /* ACTIONS functions: */
273 /* Prototypes for action-parsing utility commands */
274 static void read_actions (struct breakpoint
*);
276 /* The three functions:
277 collect_pseudocommand,
278 while_stepping_pseudocommand, and
279 end_actions_pseudocommand
280 are placeholders for "commands" that are actually ONLY to be used
281 within a tracepoint action list. If the actual function is ever called,
282 it means that somebody issued the "command" at the top level,
283 which is always an error. */
286 end_actions_pseudocommand (char *args
, int from_tty
)
288 error (_("This command cannot be used at the top level."));
292 while_stepping_pseudocommand (char *args
, int from_tty
)
294 error (_("This command can only be used in a tracepoint actions list."));
298 collect_pseudocommand (char *args
, int from_tty
)
300 error (_("This command can only be used in a tracepoint actions list."));
303 /* Enter a list of actions for a tracepoint. */
305 trace_actions_command (char *args
, int from_tty
)
307 struct breakpoint
*t
;
309 char *end_msg
= "End with a line saying just \"end\".";
311 t
= get_tracepoint_by_number (&args
, 0, 1);
314 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
319 if (deprecated_readline_begin_hook
)
320 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
321 else if (input_from_terminal_p ())
322 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
326 t
->step_count
= 0; /* read_actions may set this */
329 if (deprecated_readline_end_hook
)
330 (*deprecated_readline_end_hook
) ();
331 /* tracepoints_changed () */
333 /* else just return */
336 /* worker function */
338 read_actions (struct breakpoint
*t
)
341 char *prompt1
= "> ", *prompt2
= " > ";
342 char *prompt
= prompt1
;
343 enum actionline_type linetype
;
344 extern FILE *instream
;
345 struct action_line
*next
= NULL
, *temp
;
346 struct cleanup
*old_chain
;
348 /* Control-C quits instantly if typed while in this loop
349 since it should not wait until the user types a newline. */
351 /* FIXME: kettenis/20010823: Something is wrong here. In this file
352 STOP_SIGNAL is never defined. So this code has been left out, at
353 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
354 leads to compilation failures since the variable job_control
355 isn't declared. Leave this alone for now. */
358 signal (STOP_SIGNAL
, handle_stop_sig
);
360 old_chain
= make_cleanup_free_actions (t
);
363 /* Make sure that all output has been output. Some machines may
364 let you get away with leaving out some of the gdb_flush, but
367 gdb_flush (gdb_stdout
);
368 gdb_flush (gdb_stderr
);
370 if (deprecated_readline_hook
&& instream
== NULL
)
371 line
= (*deprecated_readline_hook
) (prompt
);
372 else if (instream
== stdin
&& ISATTY (instream
))
374 line
= gdb_readline_wrapper (prompt
);
375 if (line
&& *line
) /* add it to command history */
379 line
= gdb_readline (0);
383 line
= xstrdup ("end");
384 printf_filtered ("end\n");
387 linetype
= validate_actionline (&line
, t
);
388 if (linetype
== BADLINE
)
389 continue; /* already warned -- collect another line */
391 temp
= xmalloc (sizeof (struct action_line
));
395 if (next
== NULL
) /* first action for this tracepoint? */
396 t
->actions
= next
= temp
;
403 if (linetype
== STEPPING
) /* begin "while-stepping" */
405 if (prompt
== prompt2
)
407 warning (_("Already processing 'while-stepping'"));
411 prompt
= prompt2
; /* change prompt for stepping actions */
413 else if (linetype
== END
)
415 if (prompt
== prompt2
)
417 prompt
= prompt1
; /* end of single-stepping actions */
420 { /* end of actions */
421 if (t
->actions
->next
== NULL
)
423 /* An "end" all by itself with no other actions
424 means this tracepoint has no actions.
425 Discard empty list. */
434 signal (STOP_SIGNAL
, SIG_DFL
);
437 discard_cleanups (old_chain
);
440 /* worker function */
442 validate_actionline (char **line
, struct breakpoint
*t
)
444 struct cmd_list_element
*c
;
445 struct expression
*exp
= NULL
;
446 struct cleanup
*old_chain
= NULL
;
449 /* if EOF is typed, *line is NULL */
453 for (p
= *line
; isspace ((int) *p
);)
456 /* Symbol lookup etc. */
457 if (*p
== '\0') /* empty line: just prompt for another line. */
460 if (*p
== '#') /* comment line */
463 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
466 warning (_("'%s' is not an action that I know, or is ambiguous."),
471 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
473 struct agent_expr
*aexpr
;
474 struct agent_reqs areqs
;
477 { /* repeat over a comma-separated list */
478 QUIT
; /* allow user to bail out with ^C */
479 while (isspace ((int) *p
))
482 if (*p
== '$') /* look for special pseudo-symbols */
484 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
485 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
486 (0 == strncasecmp ("loc", p
+ 1, 3)))
491 /* else fall thru, treat p as an expression and parse it! */
493 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
494 old_chain
= make_cleanup (free_current_contents
, &exp
);
496 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
498 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
500 warning (_("constant %s (value %ld) will not be collected."),
501 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
502 SYMBOL_VALUE (exp
->elts
[2].symbol
));
505 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
507 warning (_("%s is optimized away and cannot be collected."),
508 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
513 /* We have something to collect, make sure that the expr to
514 bytecode translator can handle it and that it's not too
516 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
517 make_cleanup_free_agent_expr (aexpr
);
519 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
520 error (_("expression too complicated, try simplifying"));
522 ax_reqs (aexpr
, &areqs
);
523 (void) make_cleanup (xfree
, areqs
.reg_mask
);
525 if (areqs
.flaw
!= agent_flaw_none
)
526 error (_("malformed expression"));
528 if (areqs
.min_height
< 0)
529 error (_("gdb: Internal error: expression has min height < 0"));
531 if (areqs
.max_height
> 20)
532 error (_("expression too complicated, try simplifying"));
534 do_cleanups (old_chain
);
536 while (p
&& *p
++ == ',');
539 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
541 char *steparg
; /* in case warning is necessary */
543 while (isspace ((int) *p
))
548 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
550 warning (_("'%s': bad step-count; command ignored."), *line
);
555 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
559 warning (_("'%s' is not a supported tracepoint action."), *line
);
564 /* worker function */
566 free_actions (struct breakpoint
*t
)
568 struct action_line
*line
, *next
;
570 for (line
= t
->actions
; line
; line
= next
)
574 xfree (line
->action
);
581 do_free_actions_cleanup (void *t
)
586 static struct cleanup
*
587 make_cleanup_free_actions (struct breakpoint
*t
)
589 return make_cleanup (do_free_actions_cleanup
, t
);
593 memrange_absolute
= -1
598 int type
; /* memrange_absolute for absolute memory range,
599 else basereg number */
600 bfd_signed_vma start
;
604 struct collection_list
606 unsigned char regs_mask
[32]; /* room for up to 256 regs */
609 struct memrange
*list
;
610 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
612 struct agent_expr
**aexpr_list
;
615 tracepoint_list
, stepping_list
;
617 /* MEMRANGE functions: */
619 static int memrange_cmp (const void *, const void *);
621 /* compare memranges for qsort */
623 memrange_cmp (const void *va
, const void *vb
)
625 const struct memrange
*a
= va
, *b
= vb
;
627 if (a
->type
< b
->type
)
629 if (a
->type
> b
->type
)
631 if (a
->type
== memrange_absolute
)
633 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
635 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
640 if (a
->start
< b
->start
)
642 if (a
->start
> b
->start
)
648 /* Sort the memrange list using qsort, and merge adjacent memranges. */
650 memrange_sortmerge (struct collection_list
*memranges
)
654 qsort (memranges
->list
, memranges
->next_memrange
,
655 sizeof (struct memrange
), memrange_cmp
);
656 if (memranges
->next_memrange
> 0)
658 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
660 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
661 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
664 /* memrange b starts before memrange a ends; merge them. */
665 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
666 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
667 continue; /* next b, same a */
671 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
672 sizeof (struct memrange
));
674 memranges
->next_memrange
= a
+ 1;
678 /* Add a register to a collection list. */
680 add_register (struct collection_list
*collection
, unsigned int regno
)
683 printf_filtered ("collect register %d\n", regno
);
684 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
685 error (_("Internal: register number %d too large for tracepoint"),
687 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
690 /* Add a memrange to a collection list */
692 add_memrange (struct collection_list
*memranges
,
693 int type
, bfd_signed_vma base
,
698 printf_filtered ("(%d,", type
);
700 printf_filtered (",%ld)\n", len
);
703 /* type: memrange_absolute == memory, other n == basereg */
704 memranges
->list
[memranges
->next_memrange
].type
= type
;
705 /* base: addr if memory, offset if reg relative. */
706 memranges
->list
[memranges
->next_memrange
].start
= base
;
707 /* len: we actually save end (base + len) for convenience */
708 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
709 memranges
->next_memrange
++;
710 if (memranges
->next_memrange
>= memranges
->listsize
)
712 memranges
->listsize
*= 2;
713 memranges
->list
= xrealloc (memranges
->list
,
714 memranges
->listsize
);
717 if (type
!= memrange_absolute
) /* Better collect the base register! */
718 add_register (memranges
, type
);
721 /* Add a symbol to a collection list. */
723 collect_symbol (struct collection_list
*collect
,
725 struct gdbarch
*gdbarch
,
726 long frame_regno
, long frame_offset
)
730 bfd_signed_vma offset
;
732 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
733 switch (SYMBOL_CLASS (sym
))
736 printf_filtered ("%s: don't know symbol class %d\n",
737 SYMBOL_PRINT_NAME (sym
),
741 printf_filtered ("constant %s (value %ld) will not be collected.\n",
742 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
745 offset
= SYMBOL_VALUE_ADDRESS (sym
);
750 sprintf_vma (tmp
, offset
);
751 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
752 SYMBOL_PRINT_NAME (sym
), len
,
755 add_memrange (collect
, memrange_absolute
, offset
, len
);
758 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
760 printf_filtered ("LOC_REG[parm] %s: ",
761 SYMBOL_PRINT_NAME (sym
));
762 add_register (collect
, reg
);
763 /* Check for doubles stored in two registers. */
764 /* FIXME: how about larger types stored in 3 or more regs? */
765 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
766 len
> register_size (gdbarch
, reg
))
767 add_register (collect
, reg
+ 1);
770 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
771 printf_filtered (" (will not collect %s)\n",
772 SYMBOL_PRINT_NAME (sym
));
776 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
779 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
780 SYMBOL_PRINT_NAME (sym
), len
);
782 printf_filtered (" from frame ptr reg %d\n", reg
);
784 add_memrange (collect
, reg
, offset
, len
);
786 case LOC_REGPARM_ADDR
:
787 reg
= SYMBOL_VALUE (sym
);
791 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
792 SYMBOL_PRINT_NAME (sym
), len
);
794 printf_filtered (" from reg %d\n", reg
);
796 add_memrange (collect
, reg
, offset
, len
);
800 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
803 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
804 SYMBOL_PRINT_NAME (sym
), len
);
806 printf_filtered (" from frame ptr reg %d\n", reg
);
808 add_memrange (collect
, reg
, offset
, len
);
811 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
812 SYMBOL_PRINT_NAME (sym
));
814 case LOC_OPTIMIZED_OUT
:
815 printf_filtered ("%s has been optimized out of existence.\n",
816 SYMBOL_PRINT_NAME (sym
));
821 /* Add all locals (or args) symbols to collection list */
823 add_local_symbols (struct collection_list
*collect
,
824 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
825 long frame_regno
, long frame_offset
, int type
)
829 struct dict_iterator iter
;
832 block
= block_for_pc (pc
);
835 QUIT
; /* allow user to bail out with ^C */
836 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
838 if (SYMBOL_IS_ARGUMENT (sym
)
839 ? type
== 'A' /* collecting Arguments */
840 : type
== 'L') /* collecting Locals */
843 collect_symbol (collect
, sym
, gdbarch
,
844 frame_regno
, frame_offset
);
847 if (BLOCK_FUNCTION (block
))
850 block
= BLOCK_SUPERBLOCK (block
);
853 warning (_("No %s found in scope."),
854 type
== 'L' ? "locals" : "args");
857 /* worker function */
859 clear_collection_list (struct collection_list
*list
)
863 list
->next_memrange
= 0;
864 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
866 free_agent_expr (list
->aexpr_list
[ndx
]);
867 list
->aexpr_list
[ndx
] = NULL
;
869 list
->next_aexpr_elt
= 0;
870 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
873 /* reduce a collection list to string form (for gdb protocol) */
875 stringify_collection_list (struct collection_list
*list
, char *string
)
885 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
886 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
888 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
889 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
891 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
894 printf_filtered ("\nCollecting registers (mask): 0x");
899 QUIT
; /* allow user to bail out with ^C */
901 printf_filtered ("%02X", list
->regs_mask
[i
]);
902 sprintf (end
, "%02X", list
->regs_mask
[i
]);
905 (*str_list
)[ndx
] = xstrdup (temp_buf
);
909 printf_filtered ("\n");
910 if (list
->next_memrange
> 0 && info_verbose
)
911 printf_filtered ("Collecting memranges: \n");
912 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
914 QUIT
; /* allow user to bail out with ^C */
915 sprintf_vma (tmp2
, list
->list
[i
].start
);
918 printf_filtered ("(%d, %s, %ld)\n",
921 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
923 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
925 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
932 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
934 /* The "%X" conversion specifier expects an unsigned argument,
935 so passing -1 (memrange_absolute) to it directly gives you
936 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
938 if (list
->list
[i
].type
== memrange_absolute
)
939 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
941 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
944 count
+= strlen (end
);
945 end
= temp_buf
+ count
;
948 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
950 QUIT
; /* allow user to bail out with ^C */
951 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
953 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
958 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
959 end
+= 10; /* 'X' + 8 hex digits + ',' */
962 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
963 end
, list
->aexpr_list
[i
]->len
);
964 count
+= 2 * list
->aexpr_list
[i
]->len
;
969 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
974 (*str_list
)[ndx
] = NULL
;
986 free_actions_list_cleanup_wrapper (void *al
)
988 free_actions_list (al
);
992 free_actions_list (char **actions_list
)
996 if (actions_list
== 0)
999 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1000 xfree (actions_list
[ndx
]);
1002 xfree (actions_list
);
1005 /* Render all actions into gdb protocol. */
1007 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1008 char ***stepping_actions
)
1010 static char tdp_buff
[2048], step_buff
[2048];
1012 struct expression
*exp
= NULL
;
1013 struct action_line
*action
;
1015 struct value
*tempval
;
1016 struct collection_list
*collect
;
1017 struct cmd_list_element
*cmd
;
1018 struct agent_expr
*aexpr
;
1020 LONGEST frame_offset
;
1023 clear_collection_list (&tracepoint_list
);
1024 clear_collection_list (&stepping_list
);
1025 collect
= &tracepoint_list
;
1027 *tdp_actions
= NULL
;
1028 *stepping_actions
= NULL
;
1030 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1031 t
->loc
->address
, &frame_reg
, &frame_offset
);
1033 for (action
= t
->actions
; action
; action
= action
->next
)
1035 QUIT
; /* allow user to bail out with ^C */
1036 action_exp
= action
->action
;
1037 while (isspace ((int) *action_exp
))
1040 if (*action_exp
== '#') /* comment line */
1043 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1045 error (_("Bad action list item: %s"), action_exp
);
1047 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1050 { /* repeat over a comma-separated list */
1051 QUIT
; /* allow user to bail out with ^C */
1052 while (isspace ((int) *action_exp
))
1055 if (0 == strncasecmp ("$reg", action_exp
, 4))
1057 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1058 add_register (collect
, i
);
1059 action_exp
= strchr (action_exp
, ','); /* more? */
1061 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1063 add_local_symbols (collect
,
1069 action_exp
= strchr (action_exp
, ','); /* more? */
1071 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1073 add_local_symbols (collect
,
1079 action_exp
= strchr (action_exp
, ','); /* more? */
1083 unsigned long addr
, len
;
1084 struct cleanup
*old_chain
= NULL
;
1085 struct cleanup
*old_chain1
= NULL
;
1086 struct agent_reqs areqs
;
1088 exp
= parse_exp_1 (&action_exp
,
1089 block_for_pc (t
->loc
->address
), 1);
1090 old_chain
= make_cleanup (free_current_contents
, &exp
);
1092 switch (exp
->elts
[0].opcode
)
1096 const char *name
= &exp
->elts
[2].string
;
1098 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1099 name
, strlen (name
));
1101 internal_error (__FILE__
, __LINE__
,
1102 _("Register $%s not available"),
1105 printf_filtered ("OP_REGISTER: ");
1106 add_register (collect
, i
);
1111 /* safe because we know it's a simple expression */
1112 tempval
= evaluate_expression (exp
);
1113 addr
= value_address (tempval
);
1114 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1115 add_memrange (collect
, memrange_absolute
, addr
, len
);
1119 collect_symbol (collect
,
1120 exp
->elts
[2].symbol
,
1126 default: /* full-fledged expression */
1127 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1129 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1131 ax_reqs (aexpr
, &areqs
);
1132 if (areqs
.flaw
!= agent_flaw_none
)
1133 error (_("malformed expression"));
1135 if (areqs
.min_height
< 0)
1136 error (_("gdb: Internal error: expression has min height < 0"));
1137 if (areqs
.max_height
> 20)
1138 error (_("expression too complicated, try simplifying"));
1140 discard_cleanups (old_chain1
);
1141 add_aexpr (collect
, aexpr
);
1143 /* take care of the registers */
1144 if (areqs
.reg_mask_len
> 0)
1149 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1151 QUIT
; /* allow user to bail out with ^C */
1152 if (areqs
.reg_mask
[ndx1
] != 0)
1154 /* assume chars have 8 bits */
1155 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1156 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1157 /* it's used -- record it */
1158 add_register (collect
,
1165 do_cleanups (old_chain
);
1168 while (action_exp
&& *action_exp
++ == ',');
1170 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1172 collect
= &stepping_list
;
1174 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1176 if (collect
== &stepping_list
) /* end stepping actions */
1177 collect
= &tracepoint_list
;
1179 break; /* end tracepoint actions */
1182 memrange_sortmerge (&tracepoint_list
);
1183 memrange_sortmerge (&stepping_list
);
1185 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1187 *stepping_actions
= stringify_collection_list (&stepping_list
,
1192 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1194 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1196 collect
->aexpr_list
=
1197 xrealloc (collect
->aexpr_list
,
1198 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1199 collect
->aexpr_listsize
*= 2;
1201 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1202 collect
->next_aexpr_elt
++;
1205 static char *target_buf
;
1206 static long target_buf_size
;
1208 /* Set "transparent" memory ranges
1210 Allow trace mechanism to treat text-like sections
1211 (and perhaps all read-only sections) transparently,
1212 i.e. don't reject memory requests from these address ranges
1213 just because they haven't been collected. */
1216 remote_set_transparent_ranges (void)
1224 return; /* No information to give. */
1226 strcpy (target_buf
, "QTro");
1227 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1229 char tmp1
[40], tmp2
[40];
1231 if ((s
->flags
& SEC_LOAD
) == 0 ||
1232 /* (s->flags & SEC_CODE) == 0 || */
1233 (s
->flags
& SEC_READONLY
) == 0)
1238 size
= bfd_get_section_size (s
);
1239 sprintf_vma (tmp1
, lma
);
1240 sprintf_vma (tmp2
, lma
+ size
);
1241 sprintf (target_buf
+ strlen (target_buf
),
1242 ":%s,%s", tmp1
, tmp2
);
1246 putpkt (target_buf
);
1247 getpkt (&target_buf
, &target_buf_size
, 0);
1253 Tell target to clear any previous trace experiment.
1254 Walk the list of tracepoints, and send them (and their actions)
1255 to the target. If no errors,
1256 Tell target to start a new trace experiment. */
1258 void download_tracepoint (struct breakpoint
*t
);
1261 trace_start_command (char *args
, int from_tty
)
1263 VEC(breakpoint_p
) *tp_vec
= NULL
;
1265 struct breakpoint
*t
;
1267 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1269 if (target_is_remote ())
1272 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1273 if (strcmp (target_buf
, "OK"))
1274 error (_("Target does not support this command."));
1276 tp_vec
= all_tracepoints ();
1277 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1279 download_tracepoint (t
);
1281 VEC_free (breakpoint_p
, tp_vec
);
1283 /* Tell target to treat text-like sections as transparent. */
1284 remote_set_transparent_ranges ();
1285 /* Now insert traps and begin collecting data. */
1287 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1288 if (strcmp (target_buf
, "OK"))
1289 error (_("Bogus reply from target: %s"), target_buf
);
1290 set_traceframe_num (-1); /* All old traceframes invalidated. */
1291 set_tracepoint_num (-1);
1292 set_traceframe_context (NULL
);
1293 trace_running_p
= 1;
1294 if (deprecated_trace_start_stop_hook
)
1295 deprecated_trace_start_stop_hook (1, from_tty
);
1299 error (_("Trace can only be run on remote targets."));
1302 /* Send the definition of a single tracepoint to the target. */
1305 download_tracepoint (struct breakpoint
*t
)
1310 char **stepping_actions
;
1312 struct cleanup
*old_chain
= NULL
;
1314 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1315 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1317 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1318 t
->step_count
, t
->pass_count
);
1323 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1324 if (strcmp (target_buf
, "OK"))
1325 error (_("Target does not support tracepoints."));
1330 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1331 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1333 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1335 /* do_single_steps (t); */
1338 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1340 QUIT
; /* allow user to bail out with ^C */
1341 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1342 t
->number
, tmp
, /* address */
1344 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1347 remote_get_noisy_reply (&target_buf
,
1349 if (strcmp (target_buf
, "OK"))
1350 error (_("Error on target while setting tracepoints."));
1353 if (stepping_actions
)
1355 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1357 QUIT
; /* allow user to bail out with ^C */
1358 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1359 t
->number
, tmp
, /* address */
1360 ((ndx
== 0) ? "S" : ""),
1361 stepping_actions
[ndx
],
1362 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1364 remote_get_noisy_reply (&target_buf
,
1366 if (strcmp (target_buf
, "OK"))
1367 error (_("Error on target while setting tracepoints."));
1370 do_cleanups (old_chain
);
1375 trace_stop_command (char *args
, int from_tty
)
1377 if (target_is_remote ())
1380 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1381 if (strcmp (target_buf
, "OK"))
1382 error (_("Bogus reply from target: %s"), target_buf
);
1383 trace_running_p
= 0;
1384 if (deprecated_trace_start_stop_hook
)
1385 deprecated_trace_start_stop_hook (0, from_tty
);
1388 error (_("Trace can only be run on remote targets."));
1391 unsigned long trace_running_p
;
1393 /* tstatus command */
1395 trace_status_command (char *args
, int from_tty
)
1397 if (target_is_remote ())
1399 putpkt ("qTStatus");
1400 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1402 if (target_buf
[0] != 'T' ||
1403 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1404 error (_("Bogus reply from target: %s"), target_buf
);
1406 /* exported for use by the GUI */
1407 trace_running_p
= (target_buf
[1] == '1');
1410 error (_("Trace can only be run on remote targets."));
1413 /* Worker function for the various flavors of the tfind command. */
1415 finish_tfind_command (char **msg
,
1419 int target_frameno
= -1, target_tracept
= -1;
1420 struct frame_id old_frame_id
;
1423 old_frame_id
= get_frame_id (get_current_frame ());
1426 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1428 while (reply
&& *reply
)
1432 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1434 /* A request for a non-existant trace frame has failed.
1435 Our response will be different, depending on FROM_TTY:
1437 If FROM_TTY is true, meaning that this command was
1438 typed interactively by the user, then give an error
1439 and DO NOT change the state of traceframe_number etc.
1441 However if FROM_TTY is false, meaning that we're either
1442 in a script, a loop, or a user-defined command, then
1443 DON'T give an error, but DO change the state of
1444 traceframe_number etc. to invalid.
1446 The rationalle is that if you typed the command, you
1447 might just have committed a typo or something, and you'd
1448 like to NOT lose your current debugging state. However
1449 if you're in a user-defined command or especially in a
1450 loop, then you need a way to detect that the command
1451 failed WITHOUT aborting. This allows you to write
1452 scripts that search thru the trace buffer until the end,
1453 and then continue on to do something else. */
1456 error (_("Target failed to find requested trace frame."));
1460 printf_filtered ("End of trace buffer.\n");
1461 /* The following will not recurse, since it's
1463 trace_find_command ("-1", from_tty
);
1464 reply
= NULL
; /* Break out of loop
1465 (avoid recursive nonsense). */
1470 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1471 error (_("Target failed to find requested trace frame."));
1473 case 'O': /* "OK"? */
1474 if (reply
[1] == 'K' && reply
[2] == '\0')
1477 error (_("Bogus reply from target: %s"), reply
);
1480 error (_("Bogus reply from target: %s"), reply
);
1483 reinit_frame_cache ();
1484 registers_changed ();
1485 set_traceframe_num (target_frameno
);
1486 set_tracepoint_num (target_tracept
);
1487 if (target_frameno
== -1)
1488 set_traceframe_context (NULL
);
1490 set_traceframe_context (get_current_frame ());
1494 enum print_what print_what
;
1496 /* NOTE: in immitation of the step command, try to determine
1497 whether we have made a transition from one function to
1498 another. If so, we'll print the "stack frame" (ie. the new
1499 function and it's arguments) -- otherwise we'll just show the
1502 if (frame_id_eq (old_frame_id
,
1503 get_frame_id (get_current_frame ())))
1504 print_what
= SRC_LINE
;
1506 print_what
= SRC_AND_LOC
;
1508 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1513 /* trace_find_command takes a trace frame number n,
1514 sends "QTFrame:<n>" to the target,
1515 and accepts a reply that may contain several optional pieces
1516 of information: a frame number, a tracepoint number, and an
1517 indication of whether this is a trap frame or a stepping frame.
1519 The minimal response is just "OK" (which indicates that the
1520 target does not give us a frame number or a tracepoint number).
1521 Instead of that, the target may send us a string containing
1523 F<hexnum> (gives the selected frame number)
1524 T<hexnum> (gives the selected tracepoint number)
1529 trace_find_command (char *args
, int from_tty
)
1530 { /* this should only be called with a numeric argument */
1533 if (target_is_remote ())
1535 if (deprecated_trace_find_hook
)
1536 deprecated_trace_find_hook (args
, from_tty
);
1538 if (args
== 0 || *args
== 0)
1539 { /* TFIND with no args means find NEXT trace frame. */
1540 if (traceframe_number
== -1)
1541 frameno
= 0; /* "next" is first one */
1543 frameno
= traceframe_number
+ 1;
1545 else if (0 == strcmp (args
, "-"))
1547 if (traceframe_number
== -1)
1548 error (_("not debugging trace buffer"));
1549 else if (from_tty
&& traceframe_number
== 0)
1550 error (_("already at start of trace buffer"));
1552 frameno
= traceframe_number
- 1;
1555 frameno
= parse_and_eval_long (args
);
1558 error (_("invalid input (%d is less than zero)"), frameno
);
1560 sprintf (target_buf
, "QTFrame:%x", frameno
);
1561 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1564 error (_("Trace can only be run on remote targets."));
1569 trace_find_end_command (char *args
, int from_tty
)
1571 trace_find_command ("-1", from_tty
);
1576 trace_find_none_command (char *args
, int from_tty
)
1578 trace_find_command ("-1", from_tty
);
1583 trace_find_start_command (char *args
, int from_tty
)
1585 trace_find_command ("0", from_tty
);
1588 /* tfind pc command */
1590 trace_find_pc_command (char *args
, int from_tty
)
1595 if (target_is_remote ())
1597 if (args
== 0 || *args
== 0)
1598 pc
= regcache_read_pc (get_current_regcache ());
1600 pc
= parse_and_eval_address (args
);
1602 sprintf_vma (tmp
, pc
);
1603 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
1604 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1607 error (_("Trace can only be run on remote targets."));
1610 /* tfind tracepoint command */
1612 trace_find_tracepoint_command (char *args
, int from_tty
)
1616 if (target_is_remote ())
1618 if (args
== 0 || *args
== 0)
1620 if (tracepoint_number
== -1)
1621 error (_("No current tracepoint -- please supply an argument."));
1623 tdp
= tracepoint_number
; /* default is current TDP */
1626 tdp
= parse_and_eval_long (args
);
1628 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1629 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1632 error (_("Trace can only be run on remote targets."));
1635 /* TFIND LINE command:
1637 This command will take a sourceline for argument, just like BREAK
1638 or TRACE (ie. anything that "decode_line_1" can handle).
1640 With no argument, this command will find the next trace frame
1641 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1644 trace_find_line_command (char *args
, int from_tty
)
1646 static CORE_ADDR start_pc
, end_pc
;
1647 struct symtabs_and_lines sals
;
1648 struct symtab_and_line sal
;
1649 struct cleanup
*old_chain
;
1650 char startpc_str
[40], endpc_str
[40];
1652 if (target_is_remote ())
1654 if (args
== 0 || *args
== 0)
1656 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1658 sals
.sals
= (struct symtab_and_line
*)
1659 xmalloc (sizeof (struct symtab_and_line
));
1664 sals
= decode_line_spec (args
, 1);
1668 old_chain
= make_cleanup (xfree
, sals
.sals
);
1669 if (sal
.symtab
== 0)
1671 printf_filtered ("TFIND: No line number information available");
1674 /* This is useful for "info line *0x7f34". If we can't
1675 tell the user about a source line, at least let them
1676 have the symbolic address. */
1677 printf_filtered (" for address ");
1679 print_address (sal
.pc
, gdb_stdout
);
1680 printf_filtered (";\n -- will attempt to find by PC. \n");
1684 printf_filtered (".\n");
1685 return; /* No line, no PC; what can we do? */
1688 else if (sal
.line
> 0
1689 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1691 if (start_pc
== end_pc
)
1693 printf_filtered ("Line %d of \"%s\"",
1694 sal
.line
, sal
.symtab
->filename
);
1696 printf_filtered (" is at address ");
1697 print_address (start_pc
, gdb_stdout
);
1699 printf_filtered (" but contains no code.\n");
1700 sal
= find_pc_line (start_pc
, 0);
1702 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1704 printf_filtered ("Attempting to find line %d instead.\n",
1707 error (_("Cannot find a good line."));
1711 /* Is there any case in which we get here, and have an address
1712 which the user would want to see? If we have debugging
1713 symbols and no line numbers? */
1714 error (_("Line number %d is out of range for \"%s\"."),
1715 sal
.line
, sal
.symtab
->filename
);
1717 sprintf_vma (startpc_str
, start_pc
);
1718 sprintf_vma (endpc_str
, end_pc
- 1);
1719 /* Find within range of stated line. */
1721 sprintf (target_buf
, "QTFrame:range:%s:%s",
1722 startpc_str
, endpc_str
);
1723 /* Find OUTSIDE OF range of CURRENT line. */
1725 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1726 startpc_str
, endpc_str
);
1727 finish_tfind_command (&target_buf
, &target_buf_size
,
1729 do_cleanups (old_chain
);
1732 error (_("Trace can only be run on remote targets."));
1735 /* tfind range command */
1737 trace_find_range_command (char *args
, int from_tty
)
1739 static CORE_ADDR start
, stop
;
1740 char start_str
[40], stop_str
[40];
1743 if (target_is_remote ())
1745 if (args
== 0 || *args
== 0)
1746 { /* XXX FIXME: what should default behavior be? */
1747 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1751 if (0 != (tmp
= strchr (args
, ',')))
1753 *tmp
++ = '\0'; /* terminate start address */
1754 while (isspace ((int) *tmp
))
1756 start
= parse_and_eval_address (args
);
1757 stop
= parse_and_eval_address (tmp
);
1760 { /* no explicit end address? */
1761 start
= parse_and_eval_address (args
);
1762 stop
= start
+ 1; /* ??? */
1765 sprintf_vma (start_str
, start
);
1766 sprintf_vma (stop_str
, stop
);
1767 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1768 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1771 error (_("Trace can only be run on remote targets."));
1774 /* tfind outside command */
1776 trace_find_outside_command (char *args
, int from_tty
)
1778 CORE_ADDR start
, stop
;
1779 char start_str
[40], stop_str
[40];
1782 if (target_is_remote ())
1784 if (args
== 0 || *args
== 0)
1785 { /* XXX FIXME: what should default behavior be? */
1786 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1790 if (0 != (tmp
= strchr (args
, ',')))
1792 *tmp
++ = '\0'; /* terminate start address */
1793 while (isspace ((int) *tmp
))
1795 start
= parse_and_eval_address (args
);
1796 stop
= parse_and_eval_address (tmp
);
1799 { /* no explicit end address? */
1800 start
= parse_and_eval_address (args
);
1801 stop
= start
+ 1; /* ??? */
1804 sprintf_vma (start_str
, start
);
1805 sprintf_vma (stop_str
, stop
);
1806 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1807 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1810 error (_("Trace can only be run on remote targets."));
1813 /* info scope command: list the locals for a scope. */
1815 scope_info (char *args
, int from_tty
)
1817 struct symtabs_and_lines sals
;
1819 struct minimal_symbol
*msym
;
1820 struct block
*block
;
1821 char **canonical
, *symname
, *save_args
= args
;
1822 struct dict_iterator iter
;
1824 struct gdbarch
*gdbarch
;
1827 if (args
== 0 || *args
== 0)
1828 error (_("requires an argument (function, line or *addr) to define a scope"));
1830 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1831 if (sals
.nelts
== 0)
1832 return; /* presumably decode_line_1 has already warned */
1834 /* Resolve line numbers to PC */
1835 resolve_sal_pc (&sals
.sals
[0]);
1836 block
= block_for_pc (sals
.sals
[0].pc
);
1840 QUIT
; /* allow user to bail out with ^C */
1841 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1843 QUIT
; /* allow user to bail out with ^C */
1845 printf_filtered ("Scope for %s:\n", save_args
);
1848 symname
= SYMBOL_PRINT_NAME (sym
);
1849 if (symname
== NULL
|| *symname
== '\0')
1850 continue; /* probably botched, certainly useless */
1852 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
1854 printf_filtered ("Symbol %s is ", symname
);
1855 switch (SYMBOL_CLASS (sym
))
1858 case LOC_UNDEF
: /* messed up symbol? */
1859 printf_filtered ("a bogus symbol, class %d.\n",
1860 SYMBOL_CLASS (sym
));
1861 count
--; /* don't count this one */
1864 printf_filtered ("a constant with value %ld (0x%lx)",
1865 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
1867 case LOC_CONST_BYTES
:
1868 printf_filtered ("constant bytes: ");
1869 if (SYMBOL_TYPE (sym
))
1870 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
1871 fprintf_filtered (gdb_stdout
, " %02x",
1872 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
1875 printf_filtered ("in static storage at address ");
1876 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1879 /* GDBARCH is the architecture associated with the objfile
1880 the symbol is defined in; the target architecture may be
1881 different, and may provide additional registers. However,
1882 we do not know the target architecture at this point.
1883 We assume the objfile architecture will contain all the
1884 standard registers that occur in debug info in that
1886 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1888 if (SYMBOL_IS_ARGUMENT (sym
))
1889 printf_filtered ("an argument in register $%s",
1890 gdbarch_register_name (gdbarch
, regno
));
1892 printf_filtered ("a local variable in register $%s",
1893 gdbarch_register_name (gdbarch
, regno
));
1896 printf_filtered ("an argument at stack/frame offset %ld",
1897 SYMBOL_VALUE (sym
));
1900 printf_filtered ("a local variable at frame offset %ld",
1901 SYMBOL_VALUE (sym
));
1904 printf_filtered ("a reference argument at offset %ld",
1905 SYMBOL_VALUE (sym
));
1907 case LOC_REGPARM_ADDR
:
1908 /* Note comment at LOC_REGISTER. */
1909 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1910 printf_filtered ("the address of an argument, in register $%s",
1911 gdbarch_register_name (gdbarch
, regno
));
1914 printf_filtered ("a typedef.\n");
1917 printf_filtered ("a label at address ");
1918 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1921 printf_filtered ("a function at address ");
1922 printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
1924 case LOC_UNRESOLVED
:
1925 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1928 printf_filtered ("Unresolved Static");
1931 printf_filtered ("static storage at address ");
1932 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym
)));
1935 case LOC_OPTIMIZED_OUT
:
1936 printf_filtered ("optimized out.\n");
1939 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1942 if (SYMBOL_TYPE (sym
))
1943 printf_filtered (", length %d.\n",
1944 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
1946 if (BLOCK_FUNCTION (block
))
1949 block
= BLOCK_SUPERBLOCK (block
);
1952 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1956 /* worker function (cleanup) */
1958 replace_comma (void *data
)
1966 trace_dump_command (char *args
, int from_tty
)
1968 struct regcache
*regcache
;
1969 struct gdbarch
*gdbarch
;
1970 struct breakpoint
*t
;
1971 struct action_line
*action
;
1972 char *action_exp
, *next_comma
;
1973 struct cleanup
*old_cleanups
;
1974 int stepping_actions
= 0;
1975 int stepping_frame
= 0;
1977 if (!target_is_remote ())
1979 error (_("Trace can only be run on remote targets."));
1983 if (tracepoint_number
== -1)
1985 warning (_("No current trace frame."));
1989 t
= get_tracepoint (tracepoint_number
);
1992 error (_("No known tracepoint matches 'current' tracepoint #%d."),
1995 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
1997 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
1998 tracepoint_number
, traceframe_number
);
2000 /* The current frame is a trap frame if the frame PC is equal
2001 to the tracepoint PC. If not, then the current frame was
2002 collected during single-stepping. */
2004 regcache
= get_current_regcache ();
2005 gdbarch
= get_regcache_arch (regcache
);
2007 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2008 - gdbarch_decr_pc_after_break (gdbarch
)));
2010 for (action
= t
->actions
; action
; action
= action
->next
)
2012 struct cmd_list_element
*cmd
;
2014 QUIT
; /* allow user to bail out with ^C */
2015 action_exp
= action
->action
;
2016 while (isspace ((int) *action_exp
))
2019 /* The collection actions to be done while stepping are
2020 bracketed by the commands "while-stepping" and "end". */
2022 if (*action_exp
== '#') /* comment line */
2025 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2027 error (_("Bad action list item: %s"), action_exp
);
2029 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2030 stepping_actions
= 1;
2031 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2032 stepping_actions
= 0;
2033 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2035 /* Display the collected data.
2036 For the trap frame, display only what was collected at
2037 the trap. Likewise for stepping frames, display only
2038 what was collected while stepping. This means that the
2039 two boolean variables, STEPPING_FRAME and
2040 STEPPING_ACTIONS should be equal. */
2041 if (stepping_frame
== stepping_actions
)
2044 { /* repeat over a comma-separated list */
2045 QUIT
; /* allow user to bail out with ^C */
2046 if (*action_exp
== ',')
2048 while (isspace ((int) *action_exp
))
2051 next_comma
= strchr (action_exp
, ',');
2053 if (0 == strncasecmp (action_exp
, "$reg", 4))
2054 registers_info (NULL
, from_tty
);
2055 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2056 locals_info (NULL
, from_tty
);
2057 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2058 args_info (NULL
, from_tty
);
2063 make_cleanup (replace_comma
, next_comma
);
2066 printf_filtered ("%s = ", action_exp
);
2067 output_command (action_exp
, from_tty
);
2068 printf_filtered ("\n");
2072 action_exp
= next_comma
;
2074 while (action_exp
&& *action_exp
== ',');
2078 discard_cleanups (old_cleanups
);
2081 /* Convert the memory pointed to by mem into hex, placing result in buf.
2082 * Return a pointer to the last char put in buf (null)
2083 * "stolen" from sparc-stub.c
2086 static const char hexchars
[] = "0123456789abcdef";
2089 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2097 *buf
++ = hexchars
[ch
>> 4];
2098 *buf
++ = hexchars
[ch
& 0xf];
2107 get_traceframe_number (void)
2109 return traceframe_number
;
2113 /* module initialization */
2115 _initialize_tracepoint (void)
2117 struct cmd_list_element
*c
;
2119 traceframe_number
= -1;
2120 tracepoint_number
= -1;
2122 if (tracepoint_list
.list
== NULL
)
2124 tracepoint_list
.listsize
= 128;
2125 tracepoint_list
.list
= xmalloc
2126 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2128 if (tracepoint_list
.aexpr_list
== NULL
)
2130 tracepoint_list
.aexpr_listsize
= 128;
2131 tracepoint_list
.aexpr_list
= xmalloc
2132 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2135 if (stepping_list
.list
== NULL
)
2137 stepping_list
.listsize
= 128;
2138 stepping_list
.list
= xmalloc
2139 (stepping_list
.listsize
* sizeof (struct memrange
));
2142 if (stepping_list
.aexpr_list
== NULL
)
2144 stepping_list
.aexpr_listsize
= 128;
2145 stepping_list
.aexpr_list
= xmalloc
2146 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2149 add_info ("scope", scope_info
,
2150 _("List the variables local to a scope"));
2152 add_cmd ("tracepoints", class_trace
, NULL
,
2153 _("Tracing of program execution without stopping the program."),
2156 add_com ("tdump", class_trace
, trace_dump_command
,
2157 _("Print everything collected at the current tracepoint."));
2159 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2160 Select a trace frame;\n\
2161 No argument means forward by one frame; '-' means backward by one frame."),
2162 &tfindlist
, "tfind ", 1, &cmdlist
);
2164 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2165 Select a trace frame whose PC is outside the given range.\n\
2166 Usage: tfind outside addr1, addr2"),
2169 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2170 Select a trace frame whose PC is in the given range.\n\
2171 Usage: tfind range addr1,addr2"),
2174 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2175 Select a trace frame by source line.\n\
2176 Argument can be a line number (with optional source file), \n\
2177 a function name, or '*' followed by an address.\n\
2178 Default argument is 'the next source line that was traced'."),
2181 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2182 Select a trace frame by tracepoint number.\n\
2183 Default is the tracepoint for the current trace frame."),
2186 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2187 Select a trace frame by PC.\n\
2188 Default is the current PC, or the PC of the current trace frame."),
2191 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2192 Synonym for 'none'.\n\
2193 De-select any trace frame and resume 'live' debugging."),
2196 add_cmd ("none", class_trace
, trace_find_none_command
,
2197 _("De-select any trace frame and resume 'live' debugging."),
2200 add_cmd ("start", class_trace
, trace_find_start_command
,
2201 _("Select the first trace frame in the trace buffer."),
2204 add_com ("tstatus", class_trace
, trace_status_command
,
2205 _("Display the status of the current trace data collection."));
2207 add_com ("tstop", class_trace
, trace_stop_command
,
2208 _("Stop trace data collection."));
2210 add_com ("tstart", class_trace
, trace_start_command
,
2211 _("Start trace data collection."));
2213 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2214 Ends a list of commands or actions.\n\
2215 Several GDB commands allow you to enter a list of commands or actions.\n\
2216 Entering \"end\" on a line by itself is the normal way to terminate\n\
2218 Note: the \"end\" command cannot be used at the gdb prompt."));
2220 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2221 Specify single-stepping behavior at a tracepoint.\n\
2222 Argument is number of instructions to trace in single-step mode\n\
2223 following the tracepoint. This command is normally followed by\n\
2224 one or more \"collect\" commands, to specify what to collect\n\
2225 while single-stepping.\n\n\
2226 Note: this command can only be used in a tracepoint \"actions\" list."));
2228 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2229 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2231 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2232 Specify one or more data items to be collected at a tracepoint.\n\
2233 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2234 collect all data (variables, registers) referenced by that expression.\n\
2235 Also accepts the following special arguments:\n\
2236 $regs -- all registers.\n\
2237 $args -- all function arguments.\n\
2238 $locals -- all variables local to the block/function scope.\n\
2239 Note: this command can only be used in a tracepoint \"actions\" list."));
2241 add_com ("actions", class_trace
, trace_actions_command
, _("\
2242 Specify the actions to be taken at a tracepoint.\n\
2243 Tracepoint actions may include collecting of specified data, \n\
2244 single-stepping, or enabling/disabling other tracepoints, \n\
2245 depending on target's capabilities."));
2247 target_buf_size
= 2048;
2248 target_buf
= xmalloc (target_buf_size
);