1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007, 2008, 2009 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "expression.h"
30 #include "gdb_string.h"
32 #include "breakpoint.h"
33 #include "tracepoint.h"
37 #include "completer.h"
39 #include "dictionary.h"
41 #include "user-regs.h"
48 /* readline include files */
49 #include "readline/readline.h"
50 #include "readline/history.h"
52 /* readline defines this. */
59 /* Maximum length of an agent aexpression.
60 This accounts for the fact that packets are limited to 400 bytes
61 (which includes everything -- including the checksum), and assumes
62 the worst case of maximum length for each of the pieces of a
65 NOTE: expressions get mem2hex'ed otherwise this would be twice as
66 large. (400 - 31)/2 == 184 */
67 #define MAX_AGENT_EXPR_LEN 184
70 extern void (*deprecated_readline_begin_hook
) (char *, ...);
71 extern char *(*deprecated_readline_hook
) (char *);
72 extern void (*deprecated_readline_end_hook
) (void);
74 /* GDB commands implemented in other modules:
77 extern void output_command (char *, int);
82 This module defines the following debugger commands:
83 trace : set a tracepoint on a function, line, or address.
84 info trace : list all debugger-defined tracepoints.
85 delete trace : delete one or more tracepoints.
86 enable trace : enable one or more tracepoints.
87 disable trace : disable one or more tracepoints.
88 actions : specify actions to be taken at a tracepoint.
89 passcount : specify a pass count for a tracepoint.
90 tstart : start a trace experiment.
91 tstop : stop a trace experiment.
92 tstatus : query the status of a trace experiment.
93 tfind : find a trace frame in the trace buffer.
94 tdump : print everything collected at the current tracepoint.
95 save-tracepoints : write tracepoint setup into a file.
97 This module defines the following user-visible debugger variables:
98 $trace_frame : sequence number of trace frame currently being debugged.
99 $trace_line : source line of trace frame currently being debugged.
100 $trace_file : source file of trace frame currently being debugged.
101 $tracepoint : tracepoint number of trace frame currently being debugged.
105 /* ======= Important global variables: ======= */
107 /* Number of last traceframe collected. */
108 static int traceframe_number
;
110 /* Tracepoint for last traceframe collected. */
111 static int tracepoint_number
;
113 /* Symbol for function for last traceframe collected */
114 static struct symbol
*traceframe_fun
;
116 /* Symtab and line for last traceframe collected */
117 static struct symtab_and_line traceframe_sal
;
119 /* Tracing command lists */
120 static struct cmd_list_element
*tfindlist
;
122 /* ======= Important command functions: ======= */
123 static void trace_actions_command (char *, int);
124 static void trace_start_command (char *, int);
125 static void trace_stop_command (char *, int);
126 static void trace_status_command (char *, int);
127 static void trace_find_command (char *, int);
128 static void trace_find_pc_command (char *, int);
129 static void trace_find_tracepoint_command (char *, int);
130 static void trace_find_line_command (char *, int);
131 static void trace_find_range_command (char *, int);
132 static void trace_find_outside_command (char *, int);
133 static void tracepoint_save_command (char *, int);
134 static void trace_dump_command (char *, int);
136 /* support routines */
138 struct collection_list
;
139 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
140 static char *mem2hex (gdb_byte
*, char *, int);
141 static void add_register (struct collection_list
*collection
,
143 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
144 static void free_actions_list (char **actions_list
);
145 static void free_actions_list_cleanup_wrapper (void *);
147 extern void _initialize_tracepoint (void);
149 /* Utility: returns true if "target remote" */
151 target_is_remote (void)
153 if (current_target
.to_shortname
&&
154 (strcmp (current_target
.to_shortname
, "remote") == 0
155 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
161 /* Utility: generate error from an incoming stub packet. */
163 trace_error (char *buf
)
166 return; /* not an error msg */
169 case '1': /* malformed packet error */
170 if (*++buf
== '0') /* general case: */
171 error (_("tracepoint.c: error in outgoing packet."));
173 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
174 strtol (buf
, NULL
, 16));
176 error (_("trace API error 0x%s."), ++buf
);
178 error (_("Target returns error code '%s'."), buf
);
182 /* Utility: wait for reply from stub, while accepting "O" packets. */
184 remote_get_noisy_reply (char **buf_p
,
187 do /* Loop on reply from remote stub. */
190 QUIT
; /* allow user to bail out with ^C */
191 getpkt (buf_p
, sizeof_buf
, 0);
194 error (_("Target does not support this command."));
195 else if (buf
[0] == 'E')
197 else if (buf
[0] == 'O' &&
199 remote_console_output (buf
+ 1); /* 'O' message from stub */
201 return buf
; /* here's the actual reply */
206 /* Set traceframe number to NUM. */
208 set_traceframe_num (int num
)
210 traceframe_number
= num
;
211 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
214 /* Set tracepoint number to NUM. */
216 set_tracepoint_num (int num
)
218 tracepoint_number
= num
;
219 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
222 /* Set externally visible debug variables for querying/printing
223 the traceframe context (line, function, file) */
226 set_traceframe_context (struct frame_info
*trace_frame
)
230 static struct type
*func_string
, *file_string
;
231 static struct type
*func_range
, *file_range
;
232 struct value
*func_val
;
233 struct value
*file_val
;
236 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
239 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
240 traceframe_sal
.symtab
= NULL
;
241 clear_internalvar (lookup_internalvar ("trace_func"));
242 clear_internalvar (lookup_internalvar ("trace_file"));
243 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
247 /* Save as globals for internal use. */
248 trace_pc
= get_frame_pc (trace_frame
);
249 traceframe_sal
= find_pc_line (trace_pc
, 0);
250 traceframe_fun
= find_pc_function (trace_pc
);
252 /* Save linenumber as "$trace_line", a debugger variable visible to
254 set_internalvar_integer (lookup_internalvar ("trace_line"),
255 traceframe_sal
.line
);
257 /* Save func name as "$trace_func", a debugger variable visible to
259 if (traceframe_fun
== NULL
260 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
261 clear_internalvar (lookup_internalvar ("trace_func"));
264 len
= strlen (SYMBOL_LINKAGE_NAME (traceframe_fun
));
265 func_range
= create_range_type (func_range
,
266 builtin_type_int32
, 0, len
- 1);
267 func_string
= create_array_type (func_string
,
268 builtin_type_true_char
, func_range
);
269 func_val
= allocate_value (func_string
);
270 deprecated_set_value_type (func_val
, func_string
);
271 memcpy (value_contents_raw (func_val
),
272 SYMBOL_LINKAGE_NAME (traceframe_fun
),
274 deprecated_set_value_modifiable (func_val
, 0);
275 set_internalvar (lookup_internalvar ("trace_func"), func_val
);
278 /* Save file name as "$trace_file", a debugger variable visible to
280 if (traceframe_sal
.symtab
== NULL
281 || traceframe_sal
.symtab
->filename
== NULL
)
282 clear_internalvar (lookup_internalvar ("trace_file"));
285 len
= strlen (traceframe_sal
.symtab
->filename
);
286 file_range
= create_range_type (file_range
,
287 builtin_type_int32
, 0, len
- 1);
288 file_string
= create_array_type (file_string
,
289 builtin_type_true_char
, file_range
);
290 file_val
= allocate_value (file_string
);
291 deprecated_set_value_type (file_val
, file_string
);
292 memcpy (value_contents_raw (file_val
),
293 traceframe_sal
.symtab
->filename
,
295 deprecated_set_value_modifiable (file_val
, 0);
296 set_internalvar (lookup_internalvar ("trace_file"), file_val
);
300 /* ACTIONS functions: */
302 /* Prototypes for action-parsing utility commands */
303 static void read_actions (struct breakpoint
*);
305 /* The three functions:
306 collect_pseudocommand,
307 while_stepping_pseudocommand, and
308 end_actions_pseudocommand
309 are placeholders for "commands" that are actually ONLY to be used
310 within a tracepoint action list. If the actual function is ever called,
311 it means that somebody issued the "command" at the top level,
312 which is always an error. */
315 end_actions_pseudocommand (char *args
, int from_tty
)
317 error (_("This command cannot be used at the top level."));
321 while_stepping_pseudocommand (char *args
, int from_tty
)
323 error (_("This command can only be used in a tracepoint actions list."));
327 collect_pseudocommand (char *args
, int from_tty
)
329 error (_("This command can only be used in a tracepoint actions list."));
332 /* Enter a list of actions for a tracepoint. */
334 trace_actions_command (char *args
, int from_tty
)
336 struct breakpoint
*t
;
338 char *end_msg
= "End with a line saying just \"end\".";
340 t
= get_tracepoint_by_number (&args
, 0, 1);
343 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
348 if (deprecated_readline_begin_hook
)
349 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
350 else if (input_from_terminal_p ())
351 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
355 t
->step_count
= 0; /* read_actions may set this */
358 if (deprecated_readline_end_hook
)
359 (*deprecated_readline_end_hook
) ();
360 /* tracepoints_changed () */
362 /* else just return */
365 /* worker function */
367 read_actions (struct breakpoint
*t
)
370 char *prompt1
= "> ", *prompt2
= " > ";
371 char *prompt
= prompt1
;
372 enum actionline_type linetype
;
373 extern FILE *instream
;
374 struct action_line
*next
= NULL
, *temp
;
375 struct cleanup
*old_chain
;
377 /* Control-C quits instantly if typed while in this loop
378 since it should not wait until the user types a newline. */
380 /* FIXME: kettenis/20010823: Something is wrong here. In this file
381 STOP_SIGNAL is never defined. So this code has been left out, at
382 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
383 leads to compilation failures since the variable job_control
384 isn't declared. Leave this alone for now. */
387 signal (STOP_SIGNAL
, handle_stop_sig
);
389 old_chain
= make_cleanup_free_actions (t
);
392 /* Make sure that all output has been output. Some machines may
393 let you get away with leaving out some of the gdb_flush, but
396 gdb_flush (gdb_stdout
);
397 gdb_flush (gdb_stderr
);
399 if (deprecated_readline_hook
&& instream
== NULL
)
400 line
= (*deprecated_readline_hook
) (prompt
);
401 else if (instream
== stdin
&& ISATTY (instream
))
403 line
= gdb_readline_wrapper (prompt
);
404 if (line
&& *line
) /* add it to command history */
408 line
= gdb_readline (0);
412 line
= xstrdup ("end");
413 printf_filtered ("end\n");
416 linetype
= validate_actionline (&line
, t
);
417 if (linetype
== BADLINE
)
418 continue; /* already warned -- collect another line */
420 temp
= xmalloc (sizeof (struct action_line
));
424 if (next
== NULL
) /* first action for this tracepoint? */
425 t
->actions
= next
= temp
;
432 if (linetype
== STEPPING
) /* begin "while-stepping" */
434 if (prompt
== prompt2
)
436 warning (_("Already processing 'while-stepping'"));
440 prompt
= prompt2
; /* change prompt for stepping actions */
442 else if (linetype
== END
)
444 if (prompt
== prompt2
)
446 prompt
= prompt1
; /* end of single-stepping actions */
449 { /* end of actions */
450 if (t
->actions
->next
== NULL
)
452 /* An "end" all by itself with no other actions
453 means this tracepoint has no actions.
454 Discard empty list. */
463 signal (STOP_SIGNAL
, SIG_DFL
);
466 discard_cleanups (old_chain
);
469 /* worker function */
471 validate_actionline (char **line
, struct breakpoint
*t
)
473 struct cmd_list_element
*c
;
474 struct expression
*exp
= NULL
;
475 struct cleanup
*old_chain
= NULL
;
478 /* if EOF is typed, *line is NULL */
482 for (p
= *line
; isspace ((int) *p
);)
485 /* Symbol lookup etc. */
486 if (*p
== '\0') /* empty line: just prompt for another line. */
489 if (*p
== '#') /* comment line */
492 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
495 warning (_("'%s' is not an action that I know, or is ambiguous."),
500 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
502 struct agent_expr
*aexpr
;
503 struct agent_reqs areqs
;
506 { /* repeat over a comma-separated list */
507 QUIT
; /* allow user to bail out with ^C */
508 while (isspace ((int) *p
))
511 if (*p
== '$') /* look for special pseudo-symbols */
513 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
514 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
515 (0 == strncasecmp ("loc", p
+ 1, 3)))
520 /* else fall thru, treat p as an expression and parse it! */
522 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
523 old_chain
= make_cleanup (free_current_contents
, &exp
);
525 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
527 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
529 warning (_("constant %s (value %ld) will not be collected."),
530 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
531 SYMBOL_VALUE (exp
->elts
[2].symbol
));
534 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
536 warning (_("%s is optimized away and cannot be collected."),
537 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
542 /* We have something to collect, make sure that the expr to
543 bytecode translator can handle it and that it's not too
545 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
546 make_cleanup_free_agent_expr (aexpr
);
548 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
549 error (_("expression too complicated, try simplifying"));
551 ax_reqs (aexpr
, &areqs
);
552 (void) make_cleanup (xfree
, areqs
.reg_mask
);
554 if (areqs
.flaw
!= agent_flaw_none
)
555 error (_("malformed expression"));
557 if (areqs
.min_height
< 0)
558 error (_("gdb: Internal error: expression has min height < 0"));
560 if (areqs
.max_height
> 20)
561 error (_("expression too complicated, try simplifying"));
563 do_cleanups (old_chain
);
565 while (p
&& *p
++ == ',');
568 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
570 char *steparg
; /* in case warning is necessary */
572 while (isspace ((int) *p
))
577 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
579 warning (_("'%s': bad step-count; command ignored."), *line
);
584 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
588 warning (_("'%s' is not a supported tracepoint action."), *line
);
593 /* worker function */
595 free_actions (struct breakpoint
*t
)
597 struct action_line
*line
, *next
;
599 for (line
= t
->actions
; line
; line
= next
)
603 xfree (line
->action
);
610 do_free_actions_cleanup (void *t
)
615 static struct cleanup
*
616 make_cleanup_free_actions (struct breakpoint
*t
)
618 return make_cleanup (do_free_actions_cleanup
, t
);
622 memrange_absolute
= -1
627 int type
; /* memrange_absolute for absolute memory range,
628 else basereg number */
629 bfd_signed_vma start
;
633 struct collection_list
635 unsigned char regs_mask
[32]; /* room for up to 256 regs */
638 struct memrange
*list
;
639 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
641 struct agent_expr
**aexpr_list
;
644 tracepoint_list
, stepping_list
;
646 /* MEMRANGE functions: */
648 static int memrange_cmp (const void *, const void *);
650 /* compare memranges for qsort */
652 memrange_cmp (const void *va
, const void *vb
)
654 const struct memrange
*a
= va
, *b
= vb
;
656 if (a
->type
< b
->type
)
658 if (a
->type
> b
->type
)
660 if (a
->type
== memrange_absolute
)
662 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
664 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
669 if (a
->start
< b
->start
)
671 if (a
->start
> b
->start
)
677 /* Sort the memrange list using qsort, and merge adjacent memranges. */
679 memrange_sortmerge (struct collection_list
*memranges
)
683 qsort (memranges
->list
, memranges
->next_memrange
,
684 sizeof (struct memrange
), memrange_cmp
);
685 if (memranges
->next_memrange
> 0)
687 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
689 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
690 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
693 /* memrange b starts before memrange a ends; merge them. */
694 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
695 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
696 continue; /* next b, same a */
700 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
701 sizeof (struct memrange
));
703 memranges
->next_memrange
= a
+ 1;
707 /* Add a register to a collection list. */
709 add_register (struct collection_list
*collection
, unsigned int regno
)
712 printf_filtered ("collect register %d\n", regno
);
713 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
714 error (_("Internal: register number %d too large for tracepoint"),
716 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
719 /* Add a memrange to a collection list */
721 add_memrange (struct collection_list
*memranges
,
722 int type
, bfd_signed_vma base
,
727 printf_filtered ("(%d,", type
);
729 printf_filtered (",%ld)\n", len
);
732 /* type: memrange_absolute == memory, other n == basereg */
733 memranges
->list
[memranges
->next_memrange
].type
= type
;
734 /* base: addr if memory, offset if reg relative. */
735 memranges
->list
[memranges
->next_memrange
].start
= base
;
736 /* len: we actually save end (base + len) for convenience */
737 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
738 memranges
->next_memrange
++;
739 if (memranges
->next_memrange
>= memranges
->listsize
)
741 memranges
->listsize
*= 2;
742 memranges
->list
= xrealloc (memranges
->list
,
743 memranges
->listsize
);
746 if (type
!= memrange_absolute
) /* Better collect the base register! */
747 add_register (memranges
, type
);
750 /* Add a symbol to a collection list. */
752 collect_symbol (struct collection_list
*collect
,
754 long frame_regno
, long frame_offset
)
758 bfd_signed_vma offset
;
760 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
761 switch (SYMBOL_CLASS (sym
))
764 printf_filtered ("%s: don't know symbol class %d\n",
765 SYMBOL_PRINT_NAME (sym
),
769 printf_filtered ("constant %s (value %ld) will not be collected.\n",
770 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
773 offset
= SYMBOL_VALUE_ADDRESS (sym
);
778 sprintf_vma (tmp
, offset
);
779 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
780 SYMBOL_PRINT_NAME (sym
), len
,
783 add_memrange (collect
, memrange_absolute
, offset
, len
);
786 reg
= SYMBOL_VALUE (sym
);
788 printf_filtered ("LOC_REG[parm] %s: ",
789 SYMBOL_PRINT_NAME (sym
));
790 add_register (collect
, reg
);
791 /* Check for doubles stored in two registers. */
792 /* FIXME: how about larger types stored in 3 or more regs? */
793 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
794 len
> register_size (current_gdbarch
, reg
))
795 add_register (collect
, reg
+ 1);
798 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
799 printf_filtered (" (will not collect %s)\n",
800 SYMBOL_PRINT_NAME (sym
));
804 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
807 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
808 SYMBOL_PRINT_NAME (sym
), len
);
810 printf_filtered (" from frame ptr reg %d\n", reg
);
812 add_memrange (collect
, reg
, offset
, len
);
814 case LOC_REGPARM_ADDR
:
815 reg
= SYMBOL_VALUE (sym
);
819 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
820 SYMBOL_PRINT_NAME (sym
), len
);
822 printf_filtered (" from reg %d\n", reg
);
824 add_memrange (collect
, reg
, offset
, len
);
828 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
831 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
832 SYMBOL_PRINT_NAME (sym
), len
);
834 printf_filtered (" from frame ptr reg %d\n", reg
);
836 add_memrange (collect
, reg
, offset
, len
);
839 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
840 SYMBOL_PRINT_NAME (sym
));
842 case LOC_OPTIMIZED_OUT
:
843 printf_filtered ("%s has been optimized out of existence.\n",
844 SYMBOL_PRINT_NAME (sym
));
849 /* Add all locals (or args) symbols to collection list */
851 add_local_symbols (struct collection_list
*collect
, CORE_ADDR pc
,
852 long frame_regno
, long frame_offset
, int type
)
856 struct dict_iterator iter
;
859 block
= block_for_pc (pc
);
862 QUIT
; /* allow user to bail out with ^C */
863 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
865 if (SYMBOL_IS_ARGUMENT (sym
)
866 ? type
== 'A' /* collecting Arguments */
867 : type
== 'L') /* collecting Locals */
870 collect_symbol (collect
, sym
, frame_regno
,
874 if (BLOCK_FUNCTION (block
))
877 block
= BLOCK_SUPERBLOCK (block
);
880 warning (_("No %s found in scope."),
881 type
== 'L' ? "locals" : "args");
884 /* worker function */
886 clear_collection_list (struct collection_list
*list
)
890 list
->next_memrange
= 0;
891 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
893 free_agent_expr (list
->aexpr_list
[ndx
]);
894 list
->aexpr_list
[ndx
] = NULL
;
896 list
->next_aexpr_elt
= 0;
897 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
900 /* reduce a collection list to string form (for gdb protocol) */
902 stringify_collection_list (struct collection_list
*list
, char *string
)
912 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
913 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
915 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
916 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
918 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
921 printf_filtered ("\nCollecting registers (mask): 0x");
926 QUIT
; /* allow user to bail out with ^C */
928 printf_filtered ("%02X", list
->regs_mask
[i
]);
929 sprintf (end
, "%02X", list
->regs_mask
[i
]);
932 (*str_list
)[ndx
] = xstrdup (temp_buf
);
936 printf_filtered ("\n");
937 if (list
->next_memrange
> 0 && info_verbose
)
938 printf_filtered ("Collecting memranges: \n");
939 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
941 QUIT
; /* allow user to bail out with ^C */
942 sprintf_vma (tmp2
, list
->list
[i
].start
);
945 printf_filtered ("(%d, %s, %ld)\n",
948 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
950 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
952 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
959 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
961 /* The "%X" conversion specifier expects an unsigned argument,
962 so passing -1 (memrange_absolute) to it directly gives you
963 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
965 if (list
->list
[i
].type
== memrange_absolute
)
966 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
968 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
971 count
+= strlen (end
);
972 end
= temp_buf
+ count
;
975 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
977 QUIT
; /* allow user to bail out with ^C */
978 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
980 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
985 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
986 end
+= 10; /* 'X' + 8 hex digits + ',' */
989 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
990 end
, list
->aexpr_list
[i
]->len
);
991 count
+= 2 * list
->aexpr_list
[i
]->len
;
996 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1001 (*str_list
)[ndx
] = NULL
;
1013 free_actions_list_cleanup_wrapper (void *al
)
1015 free_actions_list (al
);
1019 free_actions_list (char **actions_list
)
1023 if (actions_list
== 0)
1026 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1027 xfree (actions_list
[ndx
]);
1029 xfree (actions_list
);
1032 /* Render all actions into gdb protocol. */
1034 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1035 char ***stepping_actions
)
1037 static char tdp_buff
[2048], step_buff
[2048];
1039 struct expression
*exp
= NULL
;
1040 struct action_line
*action
;
1042 struct value
*tempval
;
1043 struct collection_list
*collect
;
1044 struct cmd_list_element
*cmd
;
1045 struct agent_expr
*aexpr
;
1047 LONGEST frame_offset
;
1050 clear_collection_list (&tracepoint_list
);
1051 clear_collection_list (&stepping_list
);
1052 collect
= &tracepoint_list
;
1054 *tdp_actions
= NULL
;
1055 *stepping_actions
= NULL
;
1057 gdbarch_virtual_frame_pointer (current_gdbarch
,
1058 t
->loc
->address
, &frame_reg
, &frame_offset
);
1060 for (action
= t
->actions
; action
; action
= action
->next
)
1062 QUIT
; /* allow user to bail out with ^C */
1063 action_exp
= action
->action
;
1064 while (isspace ((int) *action_exp
))
1067 if (*action_exp
== '#') /* comment line */
1070 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1072 error (_("Bad action list item: %s"), action_exp
);
1074 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1077 { /* repeat over a comma-separated list */
1078 QUIT
; /* allow user to bail out with ^C */
1079 while (isspace ((int) *action_exp
))
1082 if (0 == strncasecmp ("$reg", action_exp
, 4))
1084 for (i
= 0; i
< gdbarch_num_regs (current_gdbarch
); i
++)
1085 add_register (collect
, i
);
1086 action_exp
= strchr (action_exp
, ','); /* more? */
1088 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1090 add_local_symbols (collect
,
1095 action_exp
= strchr (action_exp
, ','); /* more? */
1097 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1099 add_local_symbols (collect
,
1104 action_exp
= strchr (action_exp
, ','); /* more? */
1108 unsigned long addr
, len
;
1109 struct cleanup
*old_chain
= NULL
;
1110 struct cleanup
*old_chain1
= NULL
;
1111 struct agent_reqs areqs
;
1113 exp
= parse_exp_1 (&action_exp
,
1114 block_for_pc (t
->loc
->address
), 1);
1115 old_chain
= make_cleanup (free_current_contents
, &exp
);
1117 switch (exp
->elts
[0].opcode
)
1121 const char *name
= &exp
->elts
[2].string
;
1123 i
= user_reg_map_name_to_regnum (current_gdbarch
,
1124 name
, strlen (name
));
1126 internal_error (__FILE__
, __LINE__
,
1127 _("Register $%s not available"),
1130 printf_filtered ("OP_REGISTER: ");
1131 add_register (collect
, i
);
1136 /* safe because we know it's a simple expression */
1137 tempval
= evaluate_expression (exp
);
1138 addr
= value_address (tempval
);
1139 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1140 add_memrange (collect
, memrange_absolute
, addr
, len
);
1144 collect_symbol (collect
,
1145 exp
->elts
[2].symbol
,
1150 default: /* full-fledged expression */
1151 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1153 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1155 ax_reqs (aexpr
, &areqs
);
1156 if (areqs
.flaw
!= agent_flaw_none
)
1157 error (_("malformed expression"));
1159 if (areqs
.min_height
< 0)
1160 error (_("gdb: Internal error: expression has min height < 0"));
1161 if (areqs
.max_height
> 20)
1162 error (_("expression too complicated, try simplifying"));
1164 discard_cleanups (old_chain1
);
1165 add_aexpr (collect
, aexpr
);
1167 /* take care of the registers */
1168 if (areqs
.reg_mask_len
> 0)
1173 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1175 QUIT
; /* allow user to bail out with ^C */
1176 if (areqs
.reg_mask
[ndx1
] != 0)
1178 /* assume chars have 8 bits */
1179 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1180 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1181 /* it's used -- record it */
1182 add_register (collect
,
1189 do_cleanups (old_chain
);
1192 while (action_exp
&& *action_exp
++ == ',');
1194 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1196 collect
= &stepping_list
;
1198 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1200 if (collect
== &stepping_list
) /* end stepping actions */
1201 collect
= &tracepoint_list
;
1203 break; /* end tracepoint actions */
1206 memrange_sortmerge (&tracepoint_list
);
1207 memrange_sortmerge (&stepping_list
);
1209 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1211 *stepping_actions
= stringify_collection_list (&stepping_list
,
1216 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1218 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1220 collect
->aexpr_list
=
1221 xrealloc (collect
->aexpr_list
,
1222 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1223 collect
->aexpr_listsize
*= 2;
1225 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1226 collect
->next_aexpr_elt
++;
1229 static char *target_buf
;
1230 static long target_buf_size
;
1232 /* Set "transparent" memory ranges
1234 Allow trace mechanism to treat text-like sections
1235 (and perhaps all read-only sections) transparently,
1236 i.e. don't reject memory requests from these address ranges
1237 just because they haven't been collected. */
1240 remote_set_transparent_ranges (void)
1248 return; /* No information to give. */
1250 strcpy (target_buf
, "QTro");
1251 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1253 char tmp1
[40], tmp2
[40];
1255 if ((s
->flags
& SEC_LOAD
) == 0 ||
1256 /* (s->flags & SEC_CODE) == 0 || */
1257 (s
->flags
& SEC_READONLY
) == 0)
1262 size
= bfd_get_section_size (s
);
1263 sprintf_vma (tmp1
, lma
);
1264 sprintf_vma (tmp2
, lma
+ size
);
1265 sprintf (target_buf
+ strlen (target_buf
),
1266 ":%s,%s", tmp1
, tmp2
);
1270 putpkt (target_buf
);
1271 getpkt (&target_buf
, &target_buf_size
, 0);
1277 Tell target to clear any previous trace experiment.
1278 Walk the list of tracepoints, and send them (and their actions)
1279 to the target. If no errors,
1280 Tell target to start a new trace experiment. */
1282 void download_tracepoint (struct breakpoint
*t
);
1285 trace_start_command (char *args
, int from_tty
)
1287 VEC(breakpoint_p
) *tp_vec
= NULL
;
1289 struct breakpoint
*t
;
1291 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1293 if (target_is_remote ())
1296 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1297 if (strcmp (target_buf
, "OK"))
1298 error (_("Target does not support this command."));
1300 tp_vec
= all_tracepoints ();
1301 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1303 download_tracepoint (t
);
1305 VEC_free (breakpoint_p
, tp_vec
);
1307 /* Tell target to treat text-like sections as transparent. */
1308 remote_set_transparent_ranges ();
1309 /* Now insert traps and begin collecting data. */
1311 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1312 if (strcmp (target_buf
, "OK"))
1313 error (_("Bogus reply from target: %s"), target_buf
);
1314 set_traceframe_num (-1); /* All old traceframes invalidated. */
1315 set_tracepoint_num (-1);
1316 set_traceframe_context (NULL
);
1317 trace_running_p
= 1;
1318 if (deprecated_trace_start_stop_hook
)
1319 deprecated_trace_start_stop_hook (1, from_tty
);
1323 error (_("Trace can only be run on remote targets."));
1326 /* Send the definition of a single tracepoint to the target. */
1329 download_tracepoint (struct breakpoint
*t
)
1334 char **stepping_actions
;
1336 struct cleanup
*old_chain
= NULL
;
1338 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1339 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1341 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1342 t
->step_count
, t
->pass_count
);
1347 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1348 if (strcmp (target_buf
, "OK"))
1349 error (_("Target does not support tracepoints."));
1354 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1355 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1357 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1359 /* do_single_steps (t); */
1362 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1364 QUIT
; /* allow user to bail out with ^C */
1365 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1366 t
->number
, tmp
, /* address */
1368 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1371 remote_get_noisy_reply (&target_buf
,
1373 if (strcmp (target_buf
, "OK"))
1374 error (_("Error on target while setting tracepoints."));
1377 if (stepping_actions
)
1379 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1381 QUIT
; /* allow user to bail out with ^C */
1382 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1383 t
->number
, tmp
, /* address */
1384 ((ndx
== 0) ? "S" : ""),
1385 stepping_actions
[ndx
],
1386 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1388 remote_get_noisy_reply (&target_buf
,
1390 if (strcmp (target_buf
, "OK"))
1391 error (_("Error on target while setting tracepoints."));
1394 do_cleanups (old_chain
);
1399 trace_stop_command (char *args
, int from_tty
)
1401 if (target_is_remote ())
1404 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1405 if (strcmp (target_buf
, "OK"))
1406 error (_("Bogus reply from target: %s"), target_buf
);
1407 trace_running_p
= 0;
1408 if (deprecated_trace_start_stop_hook
)
1409 deprecated_trace_start_stop_hook (0, from_tty
);
1412 error (_("Trace can only be run on remote targets."));
1415 unsigned long trace_running_p
;
1417 /* tstatus command */
1419 trace_status_command (char *args
, int from_tty
)
1421 if (target_is_remote ())
1423 putpkt ("qTStatus");
1424 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1426 if (target_buf
[0] != 'T' ||
1427 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1428 error (_("Bogus reply from target: %s"), target_buf
);
1430 /* exported for use by the GUI */
1431 trace_running_p
= (target_buf
[1] == '1');
1434 error (_("Trace can only be run on remote targets."));
1437 /* Worker function for the various flavors of the tfind command. */
1439 finish_tfind_command (char **msg
,
1443 int target_frameno
= -1, target_tracept
= -1;
1444 struct frame_id old_frame_id
;
1447 old_frame_id
= get_frame_id (get_current_frame ());
1450 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1452 while (reply
&& *reply
)
1456 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1458 /* A request for a non-existant trace frame has failed.
1459 Our response will be different, depending on FROM_TTY:
1461 If FROM_TTY is true, meaning that this command was
1462 typed interactively by the user, then give an error
1463 and DO NOT change the state of traceframe_number etc.
1465 However if FROM_TTY is false, meaning that we're either
1466 in a script, a loop, or a user-defined command, then
1467 DON'T give an error, but DO change the state of
1468 traceframe_number etc. to invalid.
1470 The rationalle is that if you typed the command, you
1471 might just have committed a typo or something, and you'd
1472 like to NOT lose your current debugging state. However
1473 if you're in a user-defined command or especially in a
1474 loop, then you need a way to detect that the command
1475 failed WITHOUT aborting. This allows you to write
1476 scripts that search thru the trace buffer until the end,
1477 and then continue on to do something else. */
1480 error (_("Target failed to find requested trace frame."));
1484 printf_filtered ("End of trace buffer.\n");
1485 /* The following will not recurse, since it's
1487 trace_find_command ("-1", from_tty
);
1488 reply
= NULL
; /* Break out of loop
1489 (avoid recursive nonsense). */
1494 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1495 error (_("Target failed to find requested trace frame."));
1497 case 'O': /* "OK"? */
1498 if (reply
[1] == 'K' && reply
[2] == '\0')
1501 error (_("Bogus reply from target: %s"), reply
);
1504 error (_("Bogus reply from target: %s"), reply
);
1507 reinit_frame_cache ();
1508 registers_changed ();
1509 set_traceframe_num (target_frameno
);
1510 set_tracepoint_num (target_tracept
);
1511 if (target_frameno
== -1)
1512 set_traceframe_context (NULL
);
1514 set_traceframe_context (get_current_frame ());
1518 enum print_what print_what
;
1520 /* NOTE: in immitation of the step command, try to determine
1521 whether we have made a transition from one function to
1522 another. If so, we'll print the "stack frame" (ie. the new
1523 function and it's arguments) -- otherwise we'll just show the
1526 if (frame_id_eq (old_frame_id
,
1527 get_frame_id (get_current_frame ())))
1528 print_what
= SRC_LINE
;
1530 print_what
= SRC_AND_LOC
;
1532 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1537 /* trace_find_command takes a trace frame number n,
1538 sends "QTFrame:<n>" to the target,
1539 and accepts a reply that may contain several optional pieces
1540 of information: a frame number, a tracepoint number, and an
1541 indication of whether this is a trap frame or a stepping frame.
1543 The minimal response is just "OK" (which indicates that the
1544 target does not give us a frame number or a tracepoint number).
1545 Instead of that, the target may send us a string containing
1547 F<hexnum> (gives the selected frame number)
1548 T<hexnum> (gives the selected tracepoint number)
1553 trace_find_command (char *args
, int from_tty
)
1554 { /* this should only be called with a numeric argument */
1557 if (target_is_remote ())
1559 if (deprecated_trace_find_hook
)
1560 deprecated_trace_find_hook (args
, from_tty
);
1562 if (args
== 0 || *args
== 0)
1563 { /* TFIND with no args means find NEXT trace frame. */
1564 if (traceframe_number
== -1)
1565 frameno
= 0; /* "next" is first one */
1567 frameno
= traceframe_number
+ 1;
1569 else if (0 == strcmp (args
, "-"))
1571 if (traceframe_number
== -1)
1572 error (_("not debugging trace buffer"));
1573 else if (from_tty
&& traceframe_number
== 0)
1574 error (_("already at start of trace buffer"));
1576 frameno
= traceframe_number
- 1;
1579 frameno
= parse_and_eval_long (args
);
1582 error (_("invalid input (%d is less than zero)"), frameno
);
1584 sprintf (target_buf
, "QTFrame:%x", frameno
);
1585 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1588 error (_("Trace can only be run on remote targets."));
1593 trace_find_end_command (char *args
, int from_tty
)
1595 trace_find_command ("-1", from_tty
);
1600 trace_find_none_command (char *args
, int from_tty
)
1602 trace_find_command ("-1", from_tty
);
1607 trace_find_start_command (char *args
, int from_tty
)
1609 trace_find_command ("0", from_tty
);
1612 /* tfind pc command */
1614 trace_find_pc_command (char *args
, int from_tty
)
1619 if (target_is_remote ())
1621 if (args
== 0 || *args
== 0)
1622 pc
= regcache_read_pc (get_current_regcache ());
1624 pc
= parse_and_eval_address (args
);
1626 sprintf_vma (tmp
, pc
);
1627 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
1628 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1631 error (_("Trace can only be run on remote targets."));
1634 /* tfind tracepoint command */
1636 trace_find_tracepoint_command (char *args
, int from_tty
)
1640 if (target_is_remote ())
1642 if (args
== 0 || *args
== 0)
1644 if (tracepoint_number
== -1)
1645 error (_("No current tracepoint -- please supply an argument."));
1647 tdp
= tracepoint_number
; /* default is current TDP */
1650 tdp
= parse_and_eval_long (args
);
1652 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1653 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1656 error (_("Trace can only be run on remote targets."));
1659 /* TFIND LINE command:
1661 This command will take a sourceline for argument, just like BREAK
1662 or TRACE (ie. anything that "decode_line_1" can handle).
1664 With no argument, this command will find the next trace frame
1665 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1668 trace_find_line_command (char *args
, int from_tty
)
1670 static CORE_ADDR start_pc
, end_pc
;
1671 struct symtabs_and_lines sals
;
1672 struct symtab_and_line sal
;
1673 struct cleanup
*old_chain
;
1674 char startpc_str
[40], endpc_str
[40];
1676 if (target_is_remote ())
1678 if (args
== 0 || *args
== 0)
1680 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1682 sals
.sals
= (struct symtab_and_line
*)
1683 xmalloc (sizeof (struct symtab_and_line
));
1688 sals
= decode_line_spec (args
, 1);
1692 old_chain
= make_cleanup (xfree
, sals
.sals
);
1693 if (sal
.symtab
== 0)
1695 printf_filtered ("TFIND: No line number information available");
1698 /* This is useful for "info line *0x7f34". If we can't
1699 tell the user about a source line, at least let them
1700 have the symbolic address. */
1701 printf_filtered (" for address ");
1703 print_address (sal
.pc
, gdb_stdout
);
1704 printf_filtered (";\n -- will attempt to find by PC. \n");
1708 printf_filtered (".\n");
1709 return; /* No line, no PC; what can we do? */
1712 else if (sal
.line
> 0
1713 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1715 if (start_pc
== end_pc
)
1717 printf_filtered ("Line %d of \"%s\"",
1718 sal
.line
, sal
.symtab
->filename
);
1720 printf_filtered (" is at address ");
1721 print_address (start_pc
, gdb_stdout
);
1723 printf_filtered (" but contains no code.\n");
1724 sal
= find_pc_line (start_pc
, 0);
1726 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1728 printf_filtered ("Attempting to find line %d instead.\n",
1731 error (_("Cannot find a good line."));
1735 /* Is there any case in which we get here, and have an address
1736 which the user would want to see? If we have debugging
1737 symbols and no line numbers? */
1738 error (_("Line number %d is out of range for \"%s\"."),
1739 sal
.line
, sal
.symtab
->filename
);
1741 sprintf_vma (startpc_str
, start_pc
);
1742 sprintf_vma (endpc_str
, end_pc
- 1);
1743 /* Find within range of stated line. */
1745 sprintf (target_buf
, "QTFrame:range:%s:%s",
1746 startpc_str
, endpc_str
);
1747 /* Find OUTSIDE OF range of CURRENT line. */
1749 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1750 startpc_str
, endpc_str
);
1751 finish_tfind_command (&target_buf
, &target_buf_size
,
1753 do_cleanups (old_chain
);
1756 error (_("Trace can only be run on remote targets."));
1759 /* tfind range command */
1761 trace_find_range_command (char *args
, int from_tty
)
1763 static CORE_ADDR start
, stop
;
1764 char start_str
[40], stop_str
[40];
1767 if (target_is_remote ())
1769 if (args
== 0 || *args
== 0)
1770 { /* XXX FIXME: what should default behavior be? */
1771 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1775 if (0 != (tmp
= strchr (args
, ',')))
1777 *tmp
++ = '\0'; /* terminate start address */
1778 while (isspace ((int) *tmp
))
1780 start
= parse_and_eval_address (args
);
1781 stop
= parse_and_eval_address (tmp
);
1784 { /* no explicit end address? */
1785 start
= parse_and_eval_address (args
);
1786 stop
= start
+ 1; /* ??? */
1789 sprintf_vma (start_str
, start
);
1790 sprintf_vma (stop_str
, stop
);
1791 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1792 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1795 error (_("Trace can only be run on remote targets."));
1798 /* tfind outside command */
1800 trace_find_outside_command (char *args
, int from_tty
)
1802 CORE_ADDR start
, stop
;
1803 char start_str
[40], stop_str
[40];
1806 if (target_is_remote ())
1808 if (args
== 0 || *args
== 0)
1809 { /* XXX FIXME: what should default behavior be? */
1810 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1814 if (0 != (tmp
= strchr (args
, ',')))
1816 *tmp
++ = '\0'; /* terminate start address */
1817 while (isspace ((int) *tmp
))
1819 start
= parse_and_eval_address (args
);
1820 stop
= parse_and_eval_address (tmp
);
1823 { /* no explicit end address? */
1824 start
= parse_and_eval_address (args
);
1825 stop
= start
+ 1; /* ??? */
1828 sprintf_vma (start_str
, start
);
1829 sprintf_vma (stop_str
, stop
);
1830 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1831 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1834 error (_("Trace can only be run on remote targets."));
1837 /* info scope command: list the locals for a scope. */
1839 scope_info (char *args
, int from_tty
)
1841 struct symtabs_and_lines sals
;
1843 struct minimal_symbol
*msym
;
1844 struct block
*block
;
1845 char **canonical
, *symname
, *save_args
= args
;
1846 struct dict_iterator iter
;
1849 if (args
== 0 || *args
== 0)
1850 error (_("requires an argument (function, line or *addr) to define a scope"));
1852 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1853 if (sals
.nelts
== 0)
1854 return; /* presumably decode_line_1 has already warned */
1856 /* Resolve line numbers to PC */
1857 resolve_sal_pc (&sals
.sals
[0]);
1858 block
= block_for_pc (sals
.sals
[0].pc
);
1862 QUIT
; /* allow user to bail out with ^C */
1863 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1865 QUIT
; /* allow user to bail out with ^C */
1867 printf_filtered ("Scope for %s:\n", save_args
);
1870 symname
= SYMBOL_PRINT_NAME (sym
);
1871 if (symname
== NULL
|| *symname
== '\0')
1872 continue; /* probably botched, certainly useless */
1874 printf_filtered ("Symbol %s is ", symname
);
1875 switch (SYMBOL_CLASS (sym
))
1878 case LOC_UNDEF
: /* messed up symbol? */
1879 printf_filtered ("a bogus symbol, class %d.\n",
1880 SYMBOL_CLASS (sym
));
1881 count
--; /* don't count this one */
1884 printf_filtered ("a constant with value %ld (0x%lx)",
1885 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
1887 case LOC_CONST_BYTES
:
1888 printf_filtered ("constant bytes: ");
1889 if (SYMBOL_TYPE (sym
))
1890 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
1891 fprintf_filtered (gdb_stdout
, " %02x",
1892 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
1895 printf_filtered ("in static storage at address ");
1896 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1899 if (SYMBOL_IS_ARGUMENT (sym
))
1900 printf_filtered ("an argument in register $%s",
1901 gdbarch_register_name
1902 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1904 printf_filtered ("a local variable in register $%s",
1905 gdbarch_register_name
1906 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1909 printf_filtered ("an argument at stack/frame offset %ld",
1910 SYMBOL_VALUE (sym
));
1913 printf_filtered ("a local variable at frame offset %ld",
1914 SYMBOL_VALUE (sym
));
1917 printf_filtered ("a reference argument at offset %ld",
1918 SYMBOL_VALUE (sym
));
1920 case LOC_REGPARM_ADDR
:
1921 printf_filtered ("the address of an argument, in register $%s",
1922 gdbarch_register_name
1923 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1926 printf_filtered ("a typedef.\n");
1929 printf_filtered ("a label at address ");
1930 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1933 printf_filtered ("a function at address ");
1934 printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
1936 case LOC_UNRESOLVED
:
1937 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1940 printf_filtered ("Unresolved Static");
1943 printf_filtered ("static storage at address ");
1944 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym
)));
1947 case LOC_OPTIMIZED_OUT
:
1948 printf_filtered ("optimized out.\n");
1951 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1954 if (SYMBOL_TYPE (sym
))
1955 printf_filtered (", length %d.\n",
1956 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
1958 if (BLOCK_FUNCTION (block
))
1961 block
= BLOCK_SUPERBLOCK (block
);
1964 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1968 /* worker function (cleanup) */
1970 replace_comma (void *data
)
1978 trace_dump_command (char *args
, int from_tty
)
1980 struct regcache
*regcache
;
1981 struct gdbarch
*gdbarch
;
1982 struct breakpoint
*t
;
1983 struct action_line
*action
;
1984 char *action_exp
, *next_comma
;
1985 struct cleanup
*old_cleanups
;
1986 int stepping_actions
= 0;
1987 int stepping_frame
= 0;
1989 if (!target_is_remote ())
1991 error (_("Trace can only be run on remote targets."));
1995 if (tracepoint_number
== -1)
1997 warning (_("No current trace frame."));
2001 t
= get_tracepoint (tracepoint_number
);
2004 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2007 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2009 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2010 tracepoint_number
, traceframe_number
);
2012 /* The current frame is a trap frame if the frame PC is equal
2013 to the tracepoint PC. If not, then the current frame was
2014 collected during single-stepping. */
2016 regcache
= get_current_regcache ();
2017 gdbarch
= get_regcache_arch (regcache
);
2019 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2020 - gdbarch_decr_pc_after_break (gdbarch
)));
2022 for (action
= t
->actions
; action
; action
= action
->next
)
2024 struct cmd_list_element
*cmd
;
2026 QUIT
; /* allow user to bail out with ^C */
2027 action_exp
= action
->action
;
2028 while (isspace ((int) *action_exp
))
2031 /* The collection actions to be done while stepping are
2032 bracketed by the commands "while-stepping" and "end". */
2034 if (*action_exp
== '#') /* comment line */
2037 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2039 error (_("Bad action list item: %s"), action_exp
);
2041 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2042 stepping_actions
= 1;
2043 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2044 stepping_actions
= 0;
2045 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2047 /* Display the collected data.
2048 For the trap frame, display only what was collected at
2049 the trap. Likewise for stepping frames, display only
2050 what was collected while stepping. This means that the
2051 two boolean variables, STEPPING_FRAME and
2052 STEPPING_ACTIONS should be equal. */
2053 if (stepping_frame
== stepping_actions
)
2056 { /* repeat over a comma-separated list */
2057 QUIT
; /* allow user to bail out with ^C */
2058 if (*action_exp
== ',')
2060 while (isspace ((int) *action_exp
))
2063 next_comma
= strchr (action_exp
, ',');
2065 if (0 == strncasecmp (action_exp
, "$reg", 4))
2066 registers_info (NULL
, from_tty
);
2067 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2068 locals_info (NULL
, from_tty
);
2069 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2070 args_info (NULL
, from_tty
);
2075 make_cleanup (replace_comma
, next_comma
);
2078 printf_filtered ("%s = ", action_exp
);
2079 output_command (action_exp
, from_tty
);
2080 printf_filtered ("\n");
2084 action_exp
= next_comma
;
2086 while (action_exp
&& *action_exp
== ',');
2090 discard_cleanups (old_cleanups
);
2093 /* Convert the memory pointed to by mem into hex, placing result in buf.
2094 * Return a pointer to the last char put in buf (null)
2095 * "stolen" from sparc-stub.c
2098 static const char hexchars
[] = "0123456789abcdef";
2101 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2109 *buf
++ = hexchars
[ch
>> 4];
2110 *buf
++ = hexchars
[ch
& 0xf];
2119 get_traceframe_number (void)
2121 return traceframe_number
;
2125 /* module initialization */
2127 _initialize_tracepoint (void)
2129 struct cmd_list_element
*c
;
2131 traceframe_number
= -1;
2132 tracepoint_number
= -1;
2134 if (tracepoint_list
.list
== NULL
)
2136 tracepoint_list
.listsize
= 128;
2137 tracepoint_list
.list
= xmalloc
2138 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2140 if (tracepoint_list
.aexpr_list
== NULL
)
2142 tracepoint_list
.aexpr_listsize
= 128;
2143 tracepoint_list
.aexpr_list
= xmalloc
2144 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2147 if (stepping_list
.list
== NULL
)
2149 stepping_list
.listsize
= 128;
2150 stepping_list
.list
= xmalloc
2151 (stepping_list
.listsize
* sizeof (struct memrange
));
2154 if (stepping_list
.aexpr_list
== NULL
)
2156 stepping_list
.aexpr_listsize
= 128;
2157 stepping_list
.aexpr_list
= xmalloc
2158 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2161 add_info ("scope", scope_info
,
2162 _("List the variables local to a scope"));
2164 add_cmd ("tracepoints", class_trace
, NULL
,
2165 _("Tracing of program execution without stopping the program."),
2168 add_com ("tdump", class_trace
, trace_dump_command
,
2169 _("Print everything collected at the current tracepoint."));
2171 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2172 Select a trace frame;\n\
2173 No argument means forward by one frame; '-' means backward by one frame."),
2174 &tfindlist
, "tfind ", 1, &cmdlist
);
2176 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2177 Select a trace frame whose PC is outside the given range.\n\
2178 Usage: tfind outside addr1, addr2"),
2181 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2182 Select a trace frame whose PC is in the given range.\n\
2183 Usage: tfind range addr1,addr2"),
2186 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2187 Select a trace frame by source line.\n\
2188 Argument can be a line number (with optional source file), \n\
2189 a function name, or '*' followed by an address.\n\
2190 Default argument is 'the next source line that was traced'."),
2193 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2194 Select a trace frame by tracepoint number.\n\
2195 Default is the tracepoint for the current trace frame."),
2198 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2199 Select a trace frame by PC.\n\
2200 Default is the current PC, or the PC of the current trace frame."),
2203 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2204 Synonym for 'none'.\n\
2205 De-select any trace frame and resume 'live' debugging."),
2208 add_cmd ("none", class_trace
, trace_find_none_command
,
2209 _("De-select any trace frame and resume 'live' debugging."),
2212 add_cmd ("start", class_trace
, trace_find_start_command
,
2213 _("Select the first trace frame in the trace buffer."),
2216 add_com ("tstatus", class_trace
, trace_status_command
,
2217 _("Display the status of the current trace data collection."));
2219 add_com ("tstop", class_trace
, trace_stop_command
,
2220 _("Stop trace data collection."));
2222 add_com ("tstart", class_trace
, trace_start_command
,
2223 _("Start trace data collection."));
2225 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2226 Ends a list of commands or actions.\n\
2227 Several GDB commands allow you to enter a list of commands or actions.\n\
2228 Entering \"end\" on a line by itself is the normal way to terminate\n\
2230 Note: the \"end\" command cannot be used at the gdb prompt."));
2232 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2233 Specify single-stepping behavior at a tracepoint.\n\
2234 Argument is number of instructions to trace in single-step mode\n\
2235 following the tracepoint. This command is normally followed by\n\
2236 one or more \"collect\" commands, to specify what to collect\n\
2237 while single-stepping.\n\n\
2238 Note: this command can only be used in a tracepoint \"actions\" list."));
2240 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2241 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2243 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2244 Specify one or more data items to be collected at a tracepoint.\n\
2245 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2246 collect all data (variables, registers) referenced by that expression.\n\
2247 Also accepts the following special arguments:\n\
2248 $regs -- all registers.\n\
2249 $args -- all function arguments.\n\
2250 $locals -- all variables local to the block/function scope.\n\
2251 Note: this command can only be used in a tracepoint \"actions\" list."));
2253 add_com ("actions", class_trace
, trace_actions_command
, _("\
2254 Specify the actions to be taken at a tracepoint.\n\
2255 Tracepoint actions may include collecting of specified data, \n\
2256 single-stepping, or enabling/disabling other tracepoints, \n\
2257 depending on target's capabilities."));
2259 target_buf_size
= 2048;
2260 target_buf
= xmalloc (target_buf_size
);