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 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 "tracepoint.h"
36 #include "completer.h"
38 #include "dictionary.h"
40 #include "user-regs.h"
45 /* readline include files */
46 #include "readline/readline.h"
47 #include "readline/history.h"
49 /* readline defines this. */
56 /* Maximum length of an agent aexpression.
57 This accounts for the fact that packets are limited to 400 bytes
58 (which includes everything -- including the checksum), and assumes
59 the worst case of maximum length for each of the pieces of a
62 NOTE: expressions get mem2hex'ed otherwise this would be twice as
63 large. (400 - 31)/2 == 184 */
64 #define MAX_AGENT_EXPR_LEN 184
67 extern void (*deprecated_readline_begin_hook
) (char *, ...);
68 extern char *(*deprecated_readline_hook
) (char *);
69 extern void (*deprecated_readline_end_hook
) (void);
70 extern int addressprint
; /* Print machine addresses? */
72 /* GDB commands implemented in other modules:
75 extern void output_command (char *, int);
80 This module defines the following debugger commands:
81 trace : set a tracepoint on a function, line, or address.
82 info trace : list all debugger-defined tracepoints.
83 delete trace : delete one or more tracepoints.
84 enable trace : enable one or more tracepoints.
85 disable trace : disable one or more tracepoints.
86 actions : specify actions to be taken at a tracepoint.
87 passcount : specify a pass count for a tracepoint.
88 tstart : start a trace experiment.
89 tstop : stop a trace experiment.
90 tstatus : query the status of a trace experiment.
91 tfind : find a trace frame in the trace buffer.
92 tdump : print everything collected at the current tracepoint.
93 save-tracepoints : write tracepoint setup into a file.
95 This module defines the following user-visible debugger variables:
96 $trace_frame : sequence number of trace frame currently being debugged.
97 $trace_line : source line of trace frame currently being debugged.
98 $trace_file : source file of trace frame currently being debugged.
99 $tracepoint : tracepoint number of trace frame currently being debugged.
103 /* ======= Important global variables: ======= */
105 /* Chain of all tracepoints defined. */
106 struct tracepoint
*tracepoint_chain
;
108 /* Number of last tracepoint made. */
109 static int tracepoint_count
;
111 /* Number of last traceframe collected. */
112 static int traceframe_number
;
114 /* Tracepoint for last traceframe collected. */
115 static int tracepoint_number
;
117 /* Symbol for function for last traceframe collected */
118 static struct symbol
*traceframe_fun
;
120 /* Symtab and line for last traceframe collected */
121 static struct symtab_and_line traceframe_sal
;
123 /* Tracing command lists */
124 static struct cmd_list_element
*tfindlist
;
126 /* ======= Important command functions: ======= */
127 static void trace_command (char *, int);
128 static void tracepoints_info (char *, int);
129 static void delete_trace_command (char *, int);
130 static void enable_trace_command (char *, int);
131 static void disable_trace_command (char *, int);
132 static void trace_pass_command (char *, int);
133 static void trace_actions_command (char *, int);
134 static void trace_start_command (char *, int);
135 static void trace_stop_command (char *, int);
136 static void trace_status_command (char *, int);
137 static void trace_find_command (char *, int);
138 static void trace_find_pc_command (char *, int);
139 static void trace_find_tracepoint_command (char *, int);
140 static void trace_find_line_command (char *, int);
141 static void trace_find_range_command (char *, int);
142 static void trace_find_outside_command (char *, int);
143 static void tracepoint_save_command (char *, int);
144 static void trace_dump_command (char *, int);
146 /* support routines */
147 static void trace_mention (struct tracepoint
*);
149 struct collection_list
;
150 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
151 static char *mem2hex (gdb_byte
*, char *, int);
152 static void add_register (struct collection_list
*collection
,
154 static struct cleanup
*make_cleanup_free_actions (struct tracepoint
*t
);
155 static void free_actions_list (char **actions_list
);
156 static void free_actions_list_cleanup_wrapper (void *);
158 extern void _initialize_tracepoint (void);
160 /* Utility: returns true if "target remote" */
162 target_is_remote (void)
164 if (current_target
.to_shortname
&&
165 (strcmp (current_target
.to_shortname
, "remote") == 0
166 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
172 /* Utility: generate error from an incoming stub packet. */
174 trace_error (char *buf
)
177 return; /* not an error msg */
180 case '1': /* malformed packet error */
181 if (*++buf
== '0') /* general case: */
182 error (_("tracepoint.c: error in outgoing packet."));
184 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
185 strtol (buf
, NULL
, 16));
187 error (_("trace API error 0x%s."), ++buf
);
189 error (_("Target returns error code '%s'."), buf
);
193 /* Utility: wait for reply from stub, while accepting "O" packets. */
195 remote_get_noisy_reply (char **buf_p
,
198 do /* Loop on reply from remote stub. */
201 QUIT
; /* allow user to bail out with ^C */
202 getpkt (buf_p
, sizeof_buf
, 0);
205 error (_("Target does not support this command."));
206 else if (buf
[0] == 'E')
208 else if (buf
[0] == 'O' &&
210 remote_console_output (buf
+ 1); /* 'O' message from stub */
212 return buf
; /* here's the actual reply */
217 /* Set tracepoint count to NUM. */
219 set_tracepoint_count (int num
)
221 tracepoint_count
= num
;
222 set_internalvar (lookup_internalvar ("tpnum"),
223 value_from_longest (builtin_type_int
, (LONGEST
) num
));
226 /* Set traceframe number to NUM. */
228 set_traceframe_num (int num
)
230 traceframe_number
= num
;
231 set_internalvar (lookup_internalvar ("trace_frame"),
232 value_from_longest (builtin_type_int
, (LONGEST
) num
));
235 /* Set tracepoint number to NUM. */
237 set_tracepoint_num (int num
)
239 tracepoint_number
= num
;
240 set_internalvar (lookup_internalvar ("tracepoint"),
241 value_from_longest (builtin_type_int
,
245 /* Set externally visible debug variables for querying/printing
246 the traceframe context (line, function, file) */
249 set_traceframe_context (CORE_ADDR trace_pc
)
251 static struct type
*func_string
, *file_string
;
252 static struct type
*func_range
, *file_range
;
253 struct value
*func_val
;
254 struct value
*file_val
;
255 static struct type
*charstar
;
258 if (charstar
== (struct type
*) NULL
)
259 charstar
= lookup_pointer_type (builtin_type_char
);
261 if (trace_pc
== -1) /* Cease debugging any trace buffers. */
264 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
265 traceframe_sal
.symtab
= NULL
;
266 set_internalvar (lookup_internalvar ("trace_func"),
267 value_from_pointer (charstar
, (LONGEST
) 0));
268 set_internalvar (lookup_internalvar ("trace_file"),
269 value_from_pointer (charstar
, (LONGEST
) 0));
270 set_internalvar (lookup_internalvar ("trace_line"),
271 value_from_longest (builtin_type_int
,
276 /* Save as globals for internal use. */
277 traceframe_sal
= find_pc_line (trace_pc
, 0);
278 traceframe_fun
= find_pc_function (trace_pc
);
280 /* Save linenumber as "$trace_line", a debugger variable visible to
282 set_internalvar (lookup_internalvar ("trace_line"),
283 value_from_longest (builtin_type_int
,
284 (LONGEST
) traceframe_sal
.line
));
286 /* Save func name as "$trace_func", a debugger variable visible to
288 if (traceframe_fun
== NULL
||
289 SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
290 set_internalvar (lookup_internalvar ("trace_func"),
291 value_from_pointer (charstar
, (LONGEST
) 0));
294 len
= strlen (SYMBOL_LINKAGE_NAME (traceframe_fun
));
295 func_range
= create_range_type (func_range
,
296 builtin_type_int
, 0, len
- 1);
297 func_string
= create_array_type (func_string
,
298 builtin_type_char
, func_range
);
299 func_val
= allocate_value (func_string
);
300 deprecated_set_value_type (func_val
, func_string
);
301 memcpy (value_contents_raw (func_val
),
302 SYMBOL_LINKAGE_NAME (traceframe_fun
),
304 deprecated_set_value_modifiable (func_val
, 0);
305 set_internalvar (lookup_internalvar ("trace_func"), func_val
);
308 /* Save file name as "$trace_file", a debugger variable visible to
310 if (traceframe_sal
.symtab
== NULL
||
311 traceframe_sal
.symtab
->filename
== NULL
)
312 set_internalvar (lookup_internalvar ("trace_file"),
313 value_from_pointer (charstar
, (LONGEST
) 0));
316 len
= strlen (traceframe_sal
.symtab
->filename
);
317 file_range
= create_range_type (file_range
,
318 builtin_type_int
, 0, len
- 1);
319 file_string
= create_array_type (file_string
,
320 builtin_type_char
, file_range
);
321 file_val
= allocate_value (file_string
);
322 deprecated_set_value_type (file_val
, file_string
);
323 memcpy (value_contents_raw (file_val
),
324 traceframe_sal
.symtab
->filename
,
326 deprecated_set_value_modifiable (file_val
, 0);
327 set_internalvar (lookup_internalvar ("trace_file"), file_val
);
331 /* Low level routine to set a tracepoint.
332 Returns the tracepoint object so caller can set other things.
333 Does not set the tracepoint number!
334 Does not print anything.
336 ==> This routine should not be called if there is a chance of later
337 error(); otherwise it leaves a bogus tracepoint on the chain.
338 Validate your arguments BEFORE calling this routine! */
340 static struct tracepoint
*
341 set_raw_tracepoint (struct symtab_and_line sal
)
343 struct tracepoint
*t
, *tc
;
344 struct cleanup
*old_chain
;
346 t
= (struct tracepoint
*) xmalloc (sizeof (struct tracepoint
));
347 old_chain
= make_cleanup (xfree
, t
);
348 memset (t
, 0, sizeof (*t
));
350 if (sal
.symtab
== NULL
)
351 t
->source_file
= NULL
;
353 t
->source_file
= savestring (sal
.symtab
->filename
,
354 strlen (sal
.symtab
->filename
));
356 t
->section
= sal
.section
;
357 t
->language
= current_language
->la_language
;
358 t
->input_radix
= input_radix
;
359 t
->line_number
= sal
.line
;
364 t
->addr_string
= NULL
;
366 /* Add this tracepoint to the end of the chain
367 so that a list of tracepoints will come out in order
368 of increasing numbers. */
370 tc
= tracepoint_chain
;
372 tracepoint_chain
= t
;
379 discard_cleanups (old_chain
);
383 /* Set a tracepoint according to ARG (function, linenum or *address). */
385 trace_command (char *arg
, int from_tty
)
387 char **canonical
= (char **) NULL
;
388 struct symtabs_and_lines sals
;
389 struct symtab_and_line sal
;
390 struct tracepoint
*t
;
391 char *addr_start
= 0, *addr_end
= 0;
395 error (_("trace command requires an argument"));
397 if (from_tty
&& info_verbose
)
398 printf_filtered ("TRACE %s\n", arg
);
401 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
,
402 0, &canonical
, NULL
);
405 return; /* ??? Presumably decode_line_1 has already warned? */
407 /* Resolve all line numbers to PC's */
408 for (i
= 0; i
< sals
.nelts
; i
++)
409 resolve_sal_pc (&sals
.sals
[i
]);
411 /* Now set all the tracepoints. */
412 for (i
= 0; i
< sals
.nelts
; i
++)
416 t
= set_raw_tracepoint (sal
);
417 set_tracepoint_count (tracepoint_count
+ 1);
418 t
->number
= tracepoint_count
;
420 /* If a canonical line spec is needed use that instead of the
422 if (canonical
!= (char **) NULL
&& canonical
[i
] != NULL
)
423 t
->addr_string
= canonical
[i
];
425 t
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
432 printf_filtered ("Multiple tracepoints were set.\n");
433 printf_filtered ("Use 'delete trace' to delete unwanted tracepoints.\n");
437 /* Tell the user we have just set a tracepoint TP. */
440 trace_mention (struct tracepoint
*tp
)
442 printf_filtered ("Tracepoint %d", tp
->number
);
444 if (addressprint
|| (tp
->source_file
== NULL
))
446 printf_filtered (" at ");
447 printf_filtered ("%s", paddress (tp
->address
));
450 printf_filtered (": file %s, line %d.",
451 tp
->source_file
, tp
->line_number
);
453 printf_filtered ("\n");
456 /* Print information on tracepoint number TPNUM_EXP, or all if
460 tracepoints_info (char *tpnum_exp
, int from_tty
)
462 struct tracepoint
*t
;
463 struct action_line
*action
;
464 int found_a_tracepoint
= 0;
465 char wrap_indent
[80];
470 tpnum
= parse_and_eval_long (tpnum_exp
);
473 if (tpnum
== -1 || tpnum
== t
->number
)
475 extern int addressprint
; /* Print machine addresses? */
477 if (!found_a_tracepoint
++)
479 printf_filtered ("Num Enb ");
482 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
483 printf_filtered ("Address ");
485 printf_filtered ("Address ");
487 printf_filtered ("PassC StepC What\n");
489 strcpy (wrap_indent
, " ");
492 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
493 strcat (wrap_indent
, " ");
495 strcat (wrap_indent
, " ");
498 printf_filtered ("%-3d %-3s ", t
->number
,
499 t
->enabled_p
? "y" : "n");
504 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
505 tmp
= hex_string_custom (t
->address
& (CORE_ADDR
) 0xffffffff,
508 tmp
= hex_string_custom (t
->address
, 16);
510 printf_filtered ("%s ", tmp
);
512 printf_filtered ("%-5d %-5ld ", t
->pass_count
, t
->step_count
);
516 sym
= find_pc_sect_function (t
->address
, t
->section
);
519 fputs_filtered ("in ", gdb_stdout
);
520 fputs_filtered (SYMBOL_PRINT_NAME (sym
), gdb_stdout
);
521 wrap_here (wrap_indent
);
522 fputs_filtered (" at ", gdb_stdout
);
524 fputs_filtered (t
->source_file
, gdb_stdout
);
525 printf_filtered (":%d", t
->line_number
);
528 print_address_symbolic (t
->address
, gdb_stdout
, demangle
, " ");
530 printf_filtered ("\n");
533 printf_filtered (" Actions for tracepoint %d: \n", t
->number
);
534 for (action
= t
->actions
; action
; action
= action
->next
)
536 printf_filtered ("\t%s\n", action
->action
);
540 if (!found_a_tracepoint
)
543 printf_filtered ("No tracepoints.\n");
545 printf_filtered ("No tracepoint number %d.\n", tpnum
);
549 /* Optimization: the code to parse an enable, disable, or delete TP
550 command is virtually identical except for whether it performs an
551 enable, disable, or delete. Therefore I've combined them into one
552 function with an opcode. */
553 enum tracepoint_opcode
560 /* This function implements enable, disable and delete commands. */
562 tracepoint_operation (struct tracepoint
*t
, int from_tty
,
563 enum tracepoint_opcode opcode
)
565 struct tracepoint
*t2
;
567 if (t
== NULL
) /* no tracepoint operand */
574 observer_notify_tracepoint_modified (t
->number
);
578 observer_notify_tracepoint_modified (t
->number
);
581 if (tracepoint_chain
== t
)
582 tracepoint_chain
= t
->next
;
591 observer_notify_tracepoint_deleted (t
->number
);
594 xfree (t
->addr_string
);
596 xfree (t
->source_file
);
605 /* Utility: parse a tracepoint number and look it up in the list.
606 If MULTI_P is true, there might be a range of tracepoints in ARG.
607 if OPTIONAL_P is true, then if the argument is missing, the most
608 recent tracepoint (tracepoint_count) is returned. */
610 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
612 struct tracepoint
*t
;
614 char *instring
= arg
== NULL
? NULL
: *arg
;
616 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
619 tpnum
= tracepoint_count
;
621 error_no_arg (_("tracepoint number"));
624 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
628 if (instring
&& *instring
)
629 printf_filtered ("bad tracepoint number at or near '%s'\n",
632 printf_filtered ("Tracepoint argument missing and no previous tracepoint\n");
637 if (t
->number
== tpnum
)
642 /* FIXME: if we are in the middle of a range we don't want to give
643 a message. The current interface to get_number_or_range doesn't
644 allow us to discover this. */
645 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
650 parse a list of tracepoint numbers, and call a func for each. */
652 map_args_over_tracepoints (char *args
, int from_tty
,
653 enum tracepoint_opcode opcode
)
655 struct tracepoint
*t
, *tmp
;
657 if (args
== 0 || *args
== 0) /* do them all */
658 ALL_TRACEPOINTS_SAFE (t
, tmp
)
659 tracepoint_operation (t
, from_tty
, opcode
);
663 QUIT
; /* Give user option to bail out with ^C. */
664 t
= get_tracepoint_by_number (&args
, 1, 0);
665 tracepoint_operation (t
, from_tty
, opcode
);
666 while (*args
== ' ' || *args
== '\t')
671 /* The 'enable trace' command enables tracepoints.
672 Not supported by all targets. */
674 enable_trace_command (char *args
, int from_tty
)
677 map_args_over_tracepoints (args
, from_tty
, enable_op
);
680 /* The 'disable trace' command disables tracepoints.
681 Not supported by all targets. */
683 disable_trace_command (char *args
, int from_tty
)
686 map_args_over_tracepoints (args
, from_tty
, disable_op
);
689 /* Remove a tracepoint (or all if no argument) */
691 delete_trace_command (char *args
, int from_tty
)
694 if (!args
|| !*args
) /* No args implies all tracepoints; */
695 if (from_tty
) /* confirm only if from_tty... */
696 if (tracepoint_chain
) /* and if there are tracepoints to
698 if (!query ("Delete all tracepoints? "))
701 map_args_over_tracepoints (args
, from_tty
, delete_op
);
704 /* Set passcount for tracepoint.
706 First command argument is passcount, second is tracepoint number.
707 If tracepoint number omitted, apply to most recently defined.
708 Also accepts special argument "all". */
711 trace_pass_command (char *args
, int from_tty
)
713 struct tracepoint
*t1
= (struct tracepoint
*) -1, *t2
;
717 if (args
== 0 || *args
== 0)
718 error (_("passcount command requires an argument (count + optional TP num)"));
720 count
= strtoul (args
, &args
, 10); /* Count comes first, then TP num. */
722 while (*args
&& isspace ((int) *args
))
725 if (*args
&& strncasecmp (args
, "all", 3) == 0)
727 args
+= 3; /* Skip special argument "all". */
730 error (_("Junk at end of arguments."));
733 t1
= get_tracepoint_by_number (&args
, 1, 1);
740 if (t1
== (struct tracepoint
*) -1 || t1
== t2
)
742 t2
->pass_count
= count
;
743 observer_notify_tracepoint_modified (t2
->number
);
745 printf_filtered ("Setting tracepoint %d's passcount to %d\n",
749 t1
= get_tracepoint_by_number (&args
, 1, 0);
755 /* ACTIONS functions: */
757 /* Prototypes for action-parsing utility commands */
758 static void read_actions (struct tracepoint
*);
760 /* The three functions:
761 collect_pseudocommand,
762 while_stepping_pseudocommand, and
763 end_actions_pseudocommand
764 are placeholders for "commands" that are actually ONLY to be used
765 within a tracepoint action list. If the actual function is ever called,
766 it means that somebody issued the "command" at the top level,
767 which is always an error. */
770 end_actions_pseudocommand (char *args
, int from_tty
)
772 error (_("This command cannot be used at the top level."));
776 while_stepping_pseudocommand (char *args
, int from_tty
)
778 error (_("This command can only be used in a tracepoint actions list."));
782 collect_pseudocommand (char *args
, int from_tty
)
784 error (_("This command can only be used in a tracepoint actions list."));
787 /* Enter a list of actions for a tracepoint. */
789 trace_actions_command (char *args
, int from_tty
)
791 struct tracepoint
*t
;
793 char *end_msg
= "End with a line saying just \"end\".";
795 t
= get_tracepoint_by_number (&args
, 0, 1);
798 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
803 if (deprecated_readline_begin_hook
)
804 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
805 else if (input_from_terminal_p ())
806 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
810 t
->step_count
= 0; /* read_actions may set this */
813 if (deprecated_readline_end_hook
)
814 (*deprecated_readline_end_hook
) ();
815 /* tracepoints_changed () */
817 /* else just return */
820 /* worker function */
822 read_actions (struct tracepoint
*t
)
825 char *prompt1
= "> ", *prompt2
= " > ";
826 char *prompt
= prompt1
;
827 enum actionline_type linetype
;
828 extern FILE *instream
;
829 struct action_line
*next
= NULL
, *temp
;
830 struct cleanup
*old_chain
;
832 /* Control-C quits instantly if typed while in this loop
833 since it should not wait until the user types a newline. */
835 /* FIXME: kettenis/20010823: Something is wrong here. In this file
836 STOP_SIGNAL is never defined. So this code has been left out, at
837 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
838 leads to compilation failures since the variable job_control
839 isn't declared. Leave this alone for now. */
842 signal (STOP_SIGNAL
, handle_stop_sig
);
844 old_chain
= make_cleanup_free_actions (t
);
847 /* Make sure that all output has been output. Some machines may
848 let you get away with leaving out some of the gdb_flush, but
851 gdb_flush (gdb_stdout
);
852 gdb_flush (gdb_stderr
);
854 if (deprecated_readline_hook
&& instream
== NULL
)
855 line
= (*deprecated_readline_hook
) (prompt
);
856 else if (instream
== stdin
&& ISATTY (instream
))
858 line
= gdb_readline_wrapper (prompt
);
859 if (line
&& *line
) /* add it to command history */
863 line
= gdb_readline (0);
867 line
= xstrdup ("end");
868 printf_filtered ("end\n");
871 linetype
= validate_actionline (&line
, t
);
872 if (linetype
== BADLINE
)
873 continue; /* already warned -- collect another line */
875 temp
= xmalloc (sizeof (struct action_line
));
879 if (next
== NULL
) /* first action for this tracepoint? */
880 t
->actions
= next
= temp
;
887 if (linetype
== STEPPING
) /* begin "while-stepping" */
889 if (prompt
== prompt2
)
891 warning (_("Already processing 'while-stepping'"));
895 prompt
= prompt2
; /* change prompt for stepping actions */
897 else if (linetype
== END
)
899 if (prompt
== prompt2
)
901 prompt
= prompt1
; /* end of single-stepping actions */
904 { /* end of actions */
905 if (t
->actions
->next
== NULL
)
907 /* An "end" all by itself with no other actions
908 means this tracepoint has no actions.
909 Discard empty list. */
918 signal (STOP_SIGNAL
, SIG_DFL
);
921 discard_cleanups (old_chain
);
924 /* worker function */
926 validate_actionline (char **line
, struct tracepoint
*t
)
928 struct cmd_list_element
*c
;
929 struct expression
*exp
= NULL
;
930 struct cleanup
*old_chain
= NULL
;
933 /* if EOF is typed, *line is NULL */
937 for (p
= *line
; isspace ((int) *p
);)
940 /* Symbol lookup etc. */
941 if (*p
== '\0') /* empty line: just prompt for another line. */
944 if (*p
== '#') /* comment line */
947 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
950 warning (_("'%s' is not an action that I know, or is ambiguous."),
955 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
957 struct agent_expr
*aexpr
;
958 struct agent_reqs areqs
;
961 { /* repeat over a comma-separated list */
962 QUIT
; /* allow user to bail out with ^C */
963 while (isspace ((int) *p
))
966 if (*p
== '$') /* look for special pseudo-symbols */
968 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
969 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
970 (0 == strncasecmp ("loc", p
+ 1, 3)))
975 /* else fall thru, treat p as an expression and parse it! */
977 exp
= parse_exp_1 (&p
, block_for_pc (t
->address
), 1);
978 old_chain
= make_cleanup (free_current_contents
, &exp
);
980 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
982 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
984 warning (_("constant %s (value %ld) will not be collected."),
985 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
986 SYMBOL_VALUE (exp
->elts
[2].symbol
));
989 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
991 warning (_("%s is optimized away and cannot be collected."),
992 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
997 /* We have something to collect, make sure that the expr to
998 bytecode translator can handle it and that it's not too
1000 aexpr
= gen_trace_for_expr (t
->address
, exp
);
1001 make_cleanup_free_agent_expr (aexpr
);
1003 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
1004 error (_("expression too complicated, try simplifying"));
1006 ax_reqs (aexpr
, &areqs
);
1007 (void) make_cleanup (xfree
, areqs
.reg_mask
);
1009 if (areqs
.flaw
!= agent_flaw_none
)
1010 error (_("malformed expression"));
1012 if (areqs
.min_height
< 0)
1013 error (_("gdb: Internal error: expression has min height < 0"));
1015 if (areqs
.max_height
> 20)
1016 error (_("expression too complicated, try simplifying"));
1018 do_cleanups (old_chain
);
1020 while (p
&& *p
++ == ',');
1023 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
1025 char *steparg
; /* in case warning is necessary */
1027 while (isspace ((int) *p
))
1032 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
1034 warning (_("'%s': bad step-count; command ignored."), *line
);
1039 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
1043 warning (_("'%s' is not a supported tracepoint action."), *line
);
1048 /* worker function */
1050 free_actions (struct tracepoint
*t
)
1052 struct action_line
*line
, *next
;
1054 for (line
= t
->actions
; line
; line
= next
)
1058 xfree (line
->action
);
1065 do_free_actions_cleanup (void *t
)
1070 static struct cleanup
*
1071 make_cleanup_free_actions (struct tracepoint
*t
)
1073 return make_cleanup (do_free_actions_cleanup
, t
);
1077 memrange_absolute
= -1
1082 int type
; /* memrange_absolute for absolute memory range,
1083 else basereg number */
1084 bfd_signed_vma start
;
1088 struct collection_list
1090 unsigned char regs_mask
[32]; /* room for up to 256 regs */
1093 struct memrange
*list
;
1094 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
1095 long next_aexpr_elt
;
1096 struct agent_expr
**aexpr_list
;
1099 tracepoint_list
, stepping_list
;
1101 /* MEMRANGE functions: */
1103 static int memrange_cmp (const void *, const void *);
1105 /* compare memranges for qsort */
1107 memrange_cmp (const void *va
, const void *vb
)
1109 const struct memrange
*a
= va
, *b
= vb
;
1111 if (a
->type
< b
->type
)
1113 if (a
->type
> b
->type
)
1115 if (a
->type
== memrange_absolute
)
1117 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
1119 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
1124 if (a
->start
< b
->start
)
1126 if (a
->start
> b
->start
)
1132 /* Sort the memrange list using qsort, and merge adjacent memranges. */
1134 memrange_sortmerge (struct collection_list
*memranges
)
1138 qsort (memranges
->list
, memranges
->next_memrange
,
1139 sizeof (struct memrange
), memrange_cmp
);
1140 if (memranges
->next_memrange
> 0)
1142 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
1144 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
1145 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
1148 /* memrange b starts before memrange a ends; merge them. */
1149 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
1150 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
1151 continue; /* next b, same a */
1155 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
1156 sizeof (struct memrange
));
1158 memranges
->next_memrange
= a
+ 1;
1162 /* Add a register to a collection list. */
1164 add_register (struct collection_list
*collection
, unsigned int regno
)
1167 printf_filtered ("collect register %d\n", regno
);
1168 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
1169 error (_("Internal: register number %d too large for tracepoint"),
1171 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
1174 /* Add a memrange to a collection list */
1176 add_memrange (struct collection_list
*memranges
,
1177 int type
, bfd_signed_vma base
,
1182 printf_filtered ("(%d,", type
);
1184 printf_filtered (",%ld)\n", len
);
1187 /* type: memrange_absolute == memory, other n == basereg */
1188 memranges
->list
[memranges
->next_memrange
].type
= type
;
1189 /* base: addr if memory, offset if reg relative. */
1190 memranges
->list
[memranges
->next_memrange
].start
= base
;
1191 /* len: we actually save end (base + len) for convenience */
1192 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
1193 memranges
->next_memrange
++;
1194 if (memranges
->next_memrange
>= memranges
->listsize
)
1196 memranges
->listsize
*= 2;
1197 memranges
->list
= xrealloc (memranges
->list
,
1198 memranges
->listsize
);
1201 if (type
!= memrange_absolute
) /* Better collect the base register! */
1202 add_register (memranges
, type
);
1205 /* Add a symbol to a collection list. */
1207 collect_symbol (struct collection_list
*collect
,
1209 long frame_regno
, long frame_offset
)
1213 bfd_signed_vma offset
;
1215 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
1216 switch (SYMBOL_CLASS (sym
))
1219 printf_filtered ("%s: don't know symbol class %d\n",
1220 SYMBOL_PRINT_NAME (sym
),
1221 SYMBOL_CLASS (sym
));
1224 printf_filtered ("constant %s (value %ld) will not be collected.\n",
1225 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
1228 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1233 sprintf_vma (tmp
, offset
);
1234 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1235 SYMBOL_PRINT_NAME (sym
), len
,
1238 add_memrange (collect
, memrange_absolute
, offset
, len
);
1241 reg
= SYMBOL_VALUE (sym
);
1243 printf_filtered ("LOC_REG[parm] %s: ",
1244 SYMBOL_PRINT_NAME (sym
));
1245 add_register (collect
, reg
);
1246 /* Check for doubles stored in two registers. */
1247 /* FIXME: how about larger types stored in 3 or more regs? */
1248 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
1249 len
> register_size (current_gdbarch
, reg
))
1250 add_register (collect
, reg
+ 1);
1253 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1254 printf_filtered (" (will not collect %s)\n",
1255 SYMBOL_PRINT_NAME (sym
));
1259 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1262 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1263 SYMBOL_PRINT_NAME (sym
), len
);
1264 printf_vma (offset
);
1265 printf_filtered (" from frame ptr reg %d\n", reg
);
1267 add_memrange (collect
, reg
, offset
, len
);
1269 case LOC_REGPARM_ADDR
:
1270 reg
= SYMBOL_VALUE (sym
);
1274 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1275 SYMBOL_PRINT_NAME (sym
), len
);
1276 printf_vma (offset
);
1277 printf_filtered (" from reg %d\n", reg
);
1279 add_memrange (collect
, reg
, offset
, len
);
1283 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1286 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1287 SYMBOL_PRINT_NAME (sym
), len
);
1288 printf_vma (offset
);
1289 printf_filtered (" from frame ptr reg %d\n", reg
);
1291 add_memrange (collect
, reg
, offset
, len
);
1293 case LOC_UNRESOLVED
:
1294 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
1295 SYMBOL_PRINT_NAME (sym
));
1297 case LOC_OPTIMIZED_OUT
:
1298 printf_filtered ("%s has been optimized out of existence.\n",
1299 SYMBOL_PRINT_NAME (sym
));
1304 /* Add all locals (or args) symbols to collection list */
1306 add_local_symbols (struct collection_list
*collect
, CORE_ADDR pc
,
1307 long frame_regno
, long frame_offset
, int type
)
1310 struct block
*block
;
1311 struct dict_iterator iter
;
1314 block
= block_for_pc (pc
);
1317 QUIT
; /* allow user to bail out with ^C */
1318 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1320 if (SYMBOL_IS_ARGUMENT (sym
)
1321 ? type
== 'A' /* collecting Arguments */
1322 : type
== 'L') /* collecting Locals */
1325 collect_symbol (collect
, sym
, frame_regno
,
1329 if (BLOCK_FUNCTION (block
))
1332 block
= BLOCK_SUPERBLOCK (block
);
1335 warning (_("No %s found in scope."),
1336 type
== 'L' ? "locals" : "args");
1339 /* worker function */
1341 clear_collection_list (struct collection_list
*list
)
1345 list
->next_memrange
= 0;
1346 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1348 free_agent_expr (list
->aexpr_list
[ndx
]);
1349 list
->aexpr_list
[ndx
] = NULL
;
1351 list
->next_aexpr_elt
= 0;
1352 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1355 /* reduce a collection list to string form (for gdb protocol) */
1357 stringify_collection_list (struct collection_list
*list
, char *string
)
1359 char temp_buf
[2048];
1363 char *(*str_list
)[];
1367 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1368 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1370 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1371 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1373 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1376 printf_filtered ("\nCollecting registers (mask): 0x");
1381 QUIT
; /* allow user to bail out with ^C */
1383 printf_filtered ("%02X", list
->regs_mask
[i
]);
1384 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1387 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1391 printf_filtered ("\n");
1392 if (list
->next_memrange
> 0 && info_verbose
)
1393 printf_filtered ("Collecting memranges: \n");
1394 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1396 QUIT
; /* allow user to bail out with ^C */
1397 sprintf_vma (tmp2
, list
->list
[i
].start
);
1400 printf_filtered ("(%d, %s, %ld)\n",
1403 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1405 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1407 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1414 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
1416 /* The "%X" conversion specifier expects an unsigned argument,
1417 so passing -1 (memrange_absolute) to it directly gives you
1418 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1420 if (list
->list
[i
].type
== memrange_absolute
)
1421 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1423 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
1426 count
+= strlen (end
);
1427 end
= temp_buf
+ count
;
1430 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1432 QUIT
; /* allow user to bail out with ^C */
1433 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1435 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1440 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1441 end
+= 10; /* 'X' + 8 hex digits + ',' */
1444 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1445 end
, list
->aexpr_list
[i
]->len
);
1446 count
+= 2 * list
->aexpr_list
[i
]->len
;
1451 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1456 (*str_list
)[ndx
] = NULL
;
1468 free_actions_list_cleanup_wrapper (void *al
)
1470 free_actions_list (al
);
1474 free_actions_list (char **actions_list
)
1478 if (actions_list
== 0)
1481 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1482 xfree (actions_list
[ndx
]);
1484 xfree (actions_list
);
1487 /* Render all actions into gdb protocol. */
1489 encode_actions (struct tracepoint
*t
, char ***tdp_actions
,
1490 char ***stepping_actions
)
1492 static char tdp_buff
[2048], step_buff
[2048];
1494 struct expression
*exp
= NULL
;
1495 struct action_line
*action
;
1497 struct value
*tempval
;
1498 struct collection_list
*collect
;
1499 struct cmd_list_element
*cmd
;
1500 struct agent_expr
*aexpr
;
1502 LONGEST frame_offset
;
1505 clear_collection_list (&tracepoint_list
);
1506 clear_collection_list (&stepping_list
);
1507 collect
= &tracepoint_list
;
1509 *tdp_actions
= NULL
;
1510 *stepping_actions
= NULL
;
1512 gdbarch_virtual_frame_pointer (current_gdbarch
,
1513 t
->address
, &frame_reg
, &frame_offset
);
1515 for (action
= t
->actions
; action
; action
= action
->next
)
1517 QUIT
; /* allow user to bail out with ^C */
1518 action_exp
= action
->action
;
1519 while (isspace ((int) *action_exp
))
1522 if (*action_exp
== '#') /* comment line */
1525 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1527 error (_("Bad action list item: %s"), action_exp
);
1529 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1532 { /* repeat over a comma-separated list */
1533 QUIT
; /* allow user to bail out with ^C */
1534 while (isspace ((int) *action_exp
))
1537 if (0 == strncasecmp ("$reg", action_exp
, 4))
1539 for (i
= 0; i
< gdbarch_num_regs (current_gdbarch
); i
++)
1540 add_register (collect
, i
);
1541 action_exp
= strchr (action_exp
, ','); /* more? */
1543 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1545 add_local_symbols (collect
,
1550 action_exp
= strchr (action_exp
, ','); /* more? */
1552 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1554 add_local_symbols (collect
,
1559 action_exp
= strchr (action_exp
, ','); /* more? */
1563 unsigned long addr
, len
;
1564 struct cleanup
*old_chain
= NULL
;
1565 struct cleanup
*old_chain1
= NULL
;
1566 struct agent_reqs areqs
;
1568 exp
= parse_exp_1 (&action_exp
,
1569 block_for_pc (t
->address
), 1);
1570 old_chain
= make_cleanup (free_current_contents
, &exp
);
1572 switch (exp
->elts
[0].opcode
)
1576 const char *name
= &exp
->elts
[2].string
;
1578 i
= user_reg_map_name_to_regnum (current_gdbarch
,
1579 name
, strlen (name
));
1581 internal_error (__FILE__
, __LINE__
,
1582 _("Register $%s not available"),
1585 printf_filtered ("OP_REGISTER: ");
1586 add_register (collect
, i
);
1591 /* safe because we know it's a simple expression */
1592 tempval
= evaluate_expression (exp
);
1593 addr
= VALUE_ADDRESS (tempval
) + value_offset (tempval
);
1594 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1595 add_memrange (collect
, memrange_absolute
, addr
, len
);
1599 collect_symbol (collect
,
1600 exp
->elts
[2].symbol
,
1605 default: /* full-fledged expression */
1606 aexpr
= gen_trace_for_expr (t
->address
, exp
);
1608 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1610 ax_reqs (aexpr
, &areqs
);
1611 if (areqs
.flaw
!= agent_flaw_none
)
1612 error (_("malformed expression"));
1614 if (areqs
.min_height
< 0)
1615 error (_("gdb: Internal error: expression has min height < 0"));
1616 if (areqs
.max_height
> 20)
1617 error (_("expression too complicated, try simplifying"));
1619 discard_cleanups (old_chain1
);
1620 add_aexpr (collect
, aexpr
);
1622 /* take care of the registers */
1623 if (areqs
.reg_mask_len
> 0)
1628 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1630 QUIT
; /* allow user to bail out with ^C */
1631 if (areqs
.reg_mask
[ndx1
] != 0)
1633 /* assume chars have 8 bits */
1634 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1635 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1636 /* it's used -- record it */
1637 add_register (collect
,
1644 do_cleanups (old_chain
);
1647 while (action_exp
&& *action_exp
++ == ',');
1649 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1651 collect
= &stepping_list
;
1653 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1655 if (collect
== &stepping_list
) /* end stepping actions */
1656 collect
= &tracepoint_list
;
1658 break; /* end tracepoint actions */
1661 memrange_sortmerge (&tracepoint_list
);
1662 memrange_sortmerge (&stepping_list
);
1664 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1666 *stepping_actions
= stringify_collection_list (&stepping_list
,
1671 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1673 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1675 collect
->aexpr_list
=
1676 xrealloc (collect
->aexpr_list
,
1677 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1678 collect
->aexpr_listsize
*= 2;
1680 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1681 collect
->next_aexpr_elt
++;
1684 static char *target_buf
;
1685 static long target_buf_size
;
1687 /* Set "transparent" memory ranges
1689 Allow trace mechanism to treat text-like sections
1690 (and perhaps all read-only sections) transparently,
1691 i.e. don't reject memory requests from these address ranges
1692 just because they haven't been collected. */
1695 remote_set_transparent_ranges (void)
1697 extern bfd
*exec_bfd
;
1704 return; /* No information to give. */
1706 strcpy (target_buf
, "QTro");
1707 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1709 char tmp1
[40], tmp2
[40];
1711 if ((s
->flags
& SEC_LOAD
) == 0 ||
1712 /* (s->flags & SEC_CODE) == 0 || */
1713 (s
->flags
& SEC_READONLY
) == 0)
1718 size
= bfd_get_section_size (s
);
1719 sprintf_vma (tmp1
, lma
);
1720 sprintf_vma (tmp2
, lma
+ size
);
1721 sprintf (target_buf
+ strlen (target_buf
),
1722 ":%s,%s", tmp1
, tmp2
);
1726 putpkt (target_buf
);
1727 getpkt (&target_buf
, &target_buf_size
, 0);
1733 Tell target to clear any previous trace experiment.
1734 Walk the list of tracepoints, and send them (and their actions)
1735 to the target. If no errors,
1736 Tell target to start a new trace experiment. */
1739 trace_start_command (char *args
, int from_tty
)
1741 struct tracepoint
*t
;
1744 char **stepping_actions
;
1746 struct cleanup
*old_chain
= NULL
;
1748 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1750 if (target_is_remote ())
1753 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1754 if (strcmp (target_buf
, "OK"))
1755 error (_("Target does not support this command."));
1761 sprintf_vma (tmp
, t
->address
);
1762 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1764 t
->enabled_p
? 'E' : 'D',
1765 t
->step_count
, t
->pass_count
);
1770 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1771 if (strcmp (target_buf
, "OK"))
1772 error (_("Target does not support tracepoints."));
1776 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1777 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1779 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
1782 /* do_single_steps (t); */
1785 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1787 QUIT
; /* allow user to bail out with ^C */
1788 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1789 t
->number
, tmp
, /* address */
1791 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1794 remote_get_noisy_reply (&target_buf
,
1796 if (strcmp (target_buf
, "OK"))
1797 error (_("Error on target while setting tracepoints."));
1800 if (stepping_actions
)
1802 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1804 QUIT
; /* allow user to bail out with ^C */
1805 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1806 t
->number
, tmp
, /* address */
1807 ((ndx
== 0) ? "S" : ""),
1808 stepping_actions
[ndx
],
1809 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1811 remote_get_noisy_reply (&target_buf
,
1813 if (strcmp (target_buf
, "OK"))
1814 error (_("Error on target while setting tracepoints."));
1818 do_cleanups (old_chain
);
1821 /* Tell target to treat text-like sections as transparent. */
1822 remote_set_transparent_ranges ();
1823 /* Now insert traps and begin collecting data. */
1825 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1826 if (strcmp (target_buf
, "OK"))
1827 error (_("Bogus reply from target: %s"), target_buf
);
1828 set_traceframe_num (-1); /* All old traceframes invalidated. */
1829 set_tracepoint_num (-1);
1830 set_traceframe_context (-1);
1831 trace_running_p
= 1;
1832 if (deprecated_trace_start_stop_hook
)
1833 deprecated_trace_start_stop_hook (1, from_tty
);
1837 error (_("Trace can only be run on remote targets."));
1842 trace_stop_command (char *args
, int from_tty
)
1844 if (target_is_remote ())
1847 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1848 if (strcmp (target_buf
, "OK"))
1849 error (_("Bogus reply from target: %s"), target_buf
);
1850 trace_running_p
= 0;
1851 if (deprecated_trace_start_stop_hook
)
1852 deprecated_trace_start_stop_hook (0, from_tty
);
1855 error (_("Trace can only be run on remote targets."));
1858 unsigned long trace_running_p
;
1860 /* tstatus command */
1862 trace_status_command (char *args
, int from_tty
)
1864 if (target_is_remote ())
1866 putpkt ("qTStatus");
1867 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1869 if (target_buf
[0] != 'T' ||
1870 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1871 error (_("Bogus reply from target: %s"), target_buf
);
1873 /* exported for use by the GUI */
1874 trace_running_p
= (target_buf
[1] == '1');
1877 error (_("Trace can only be run on remote targets."));
1880 /* Worker function for the various flavors of the tfind command. */
1882 finish_tfind_command (char **msg
,
1886 int target_frameno
= -1, target_tracept
= -1;
1887 CORE_ADDR old_frame_addr
;
1888 struct symbol
*old_func
;
1891 old_frame_addr
= get_frame_base (get_current_frame ());
1892 old_func
= find_pc_function (read_pc ());
1895 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1897 while (reply
&& *reply
)
1901 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1903 /* A request for a non-existant trace frame has failed.
1904 Our response will be different, depending on FROM_TTY:
1906 If FROM_TTY is true, meaning that this command was
1907 typed interactively by the user, then give an error
1908 and DO NOT change the state of traceframe_number etc.
1910 However if FROM_TTY is false, meaning that we're either
1911 in a script, a loop, or a user-defined command, then
1912 DON'T give an error, but DO change the state of
1913 traceframe_number etc. to invalid.
1915 The rationalle is that if you typed the command, you
1916 might just have committed a typo or something, and you'd
1917 like to NOT lose your current debugging state. However
1918 if you're in a user-defined command or especially in a
1919 loop, then you need a way to detect that the command
1920 failed WITHOUT aborting. This allows you to write
1921 scripts that search thru the trace buffer until the end,
1922 and then continue on to do something else. */
1925 error (_("Target failed to find requested trace frame."));
1929 printf_filtered ("End of trace buffer.\n");
1930 /* The following will not recurse, since it's
1932 trace_find_command ("-1", from_tty
);
1933 reply
= NULL
; /* Break out of loop
1934 (avoid recursive nonsense). */
1939 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1940 error (_("Target failed to find requested trace frame."));
1942 case 'O': /* "OK"? */
1943 if (reply
[1] == 'K' && reply
[2] == '\0')
1946 error (_("Bogus reply from target: %s"), reply
);
1949 error (_("Bogus reply from target: %s"), reply
);
1952 reinit_frame_cache ();
1953 registers_changed ();
1954 set_traceframe_num (target_frameno
);
1955 set_tracepoint_num (target_tracept
);
1956 if (target_frameno
== -1)
1957 set_traceframe_context (-1);
1959 set_traceframe_context (read_pc ());
1963 enum print_what print_what
;
1965 /* NOTE: in immitation of the step command, try to determine
1966 whether we have made a transition from one function to
1967 another. If so, we'll print the "stack frame" (ie. the new
1968 function and it's arguments) -- otherwise we'll just show the
1971 This determination is made by checking (1) whether the
1972 current function has changed, and (2) whether the current FP
1973 has changed. Hack: if the FP wasn't collected, either at the
1974 current or the previous frame, assume that the FP has NOT
1977 if (old_func
== find_pc_function (read_pc ()) &&
1978 (old_frame_addr
== 0 ||
1979 get_frame_base (get_current_frame ()) == 0 ||
1980 old_frame_addr
== get_frame_base (get_current_frame ())))
1981 print_what
= SRC_LINE
;
1983 print_what
= SRC_AND_LOC
;
1985 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1990 /* trace_find_command takes a trace frame number n,
1991 sends "QTFrame:<n>" to the target,
1992 and accepts a reply that may contain several optional pieces
1993 of information: a frame number, a tracepoint number, and an
1994 indication of whether this is a trap frame or a stepping frame.
1996 The minimal response is just "OK" (which indicates that the
1997 target does not give us a frame number or a tracepoint number).
1998 Instead of that, the target may send us a string containing
2000 F<hexnum> (gives the selected frame number)
2001 T<hexnum> (gives the selected tracepoint number)
2006 trace_find_command (char *args
, int from_tty
)
2007 { /* this should only be called with a numeric argument */
2010 if (target_is_remote ())
2012 if (deprecated_trace_find_hook
)
2013 deprecated_trace_find_hook (args
, from_tty
);
2015 if (args
== 0 || *args
== 0)
2016 { /* TFIND with no args means find NEXT trace frame. */
2017 if (traceframe_number
== -1)
2018 frameno
= 0; /* "next" is first one */
2020 frameno
= traceframe_number
+ 1;
2022 else if (0 == strcmp (args
, "-"))
2024 if (traceframe_number
== -1)
2025 error (_("not debugging trace buffer"));
2026 else if (from_tty
&& traceframe_number
== 0)
2027 error (_("already at start of trace buffer"));
2029 frameno
= traceframe_number
- 1;
2032 frameno
= parse_and_eval_long (args
);
2035 error (_("invalid input (%d is less than zero)"), frameno
);
2037 sprintf (target_buf
, "QTFrame:%x", frameno
);
2038 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2041 error (_("Trace can only be run on remote targets."));
2046 trace_find_end_command (char *args
, int from_tty
)
2048 trace_find_command ("-1", from_tty
);
2053 trace_find_none_command (char *args
, int from_tty
)
2055 trace_find_command ("-1", from_tty
);
2060 trace_find_start_command (char *args
, int from_tty
)
2062 trace_find_command ("0", from_tty
);
2065 /* tfind pc command */
2067 trace_find_pc_command (char *args
, int from_tty
)
2072 if (target_is_remote ())
2074 if (args
== 0 || *args
== 0)
2075 pc
= read_pc (); /* default is current pc */
2077 pc
= parse_and_eval_address (args
);
2079 sprintf_vma (tmp
, pc
);
2080 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
2081 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2084 error (_("Trace can only be run on remote targets."));
2087 /* tfind tracepoint command */
2089 trace_find_tracepoint_command (char *args
, int from_tty
)
2093 if (target_is_remote ())
2095 if (args
== 0 || *args
== 0)
2097 if (tracepoint_number
== -1)
2098 error (_("No current tracepoint -- please supply an argument."));
2100 tdp
= tracepoint_number
; /* default is current TDP */
2103 tdp
= parse_and_eval_long (args
);
2105 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
2106 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2109 error (_("Trace can only be run on remote targets."));
2112 /* TFIND LINE command:
2114 This command will take a sourceline for argument, just like BREAK
2115 or TRACE (ie. anything that "decode_line_1" can handle).
2117 With no argument, this command will find the next trace frame
2118 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2121 trace_find_line_command (char *args
, int from_tty
)
2123 static CORE_ADDR start_pc
, end_pc
;
2124 struct symtabs_and_lines sals
;
2125 struct symtab_and_line sal
;
2126 struct cleanup
*old_chain
;
2127 char startpc_str
[40], endpc_str
[40];
2129 if (target_is_remote ())
2131 if (args
== 0 || *args
== 0)
2133 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2135 sals
.sals
= (struct symtab_and_line
*)
2136 xmalloc (sizeof (struct symtab_and_line
));
2141 sals
= decode_line_spec (args
, 1);
2145 old_chain
= make_cleanup (xfree
, sals
.sals
);
2146 if (sal
.symtab
== 0)
2148 printf_filtered ("TFIND: No line number information available");
2151 /* This is useful for "info line *0x7f34". If we can't
2152 tell the user about a source line, at least let them
2153 have the symbolic address. */
2154 printf_filtered (" for address ");
2156 print_address (sal
.pc
, gdb_stdout
);
2157 printf_filtered (";\n -- will attempt to find by PC. \n");
2161 printf_filtered (".\n");
2162 return; /* No line, no PC; what can we do? */
2165 else if (sal
.line
> 0
2166 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2168 if (start_pc
== end_pc
)
2170 printf_filtered ("Line %d of \"%s\"",
2171 sal
.line
, sal
.symtab
->filename
);
2173 printf_filtered (" is at address ");
2174 print_address (start_pc
, gdb_stdout
);
2176 printf_filtered (" but contains no code.\n");
2177 sal
= find_pc_line (start_pc
, 0);
2179 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
2181 printf_filtered ("Attempting to find line %d instead.\n",
2184 error (_("Cannot find a good line."));
2188 /* Is there any case in which we get here, and have an address
2189 which the user would want to see? If we have debugging
2190 symbols and no line numbers? */
2191 error (_("Line number %d is out of range for \"%s\"."),
2192 sal
.line
, sal
.symtab
->filename
);
2194 sprintf_vma (startpc_str
, start_pc
);
2195 sprintf_vma (endpc_str
, end_pc
- 1);
2196 /* Find within range of stated line. */
2198 sprintf (target_buf
, "QTFrame:range:%s:%s",
2199 startpc_str
, endpc_str
);
2200 /* Find OUTSIDE OF range of CURRENT line. */
2202 sprintf (target_buf
, "QTFrame:outside:%s:%s",
2203 startpc_str
, endpc_str
);
2204 finish_tfind_command (&target_buf
, &target_buf_size
,
2206 do_cleanups (old_chain
);
2209 error (_("Trace can only be run on remote targets."));
2212 /* tfind range command */
2214 trace_find_range_command (char *args
, int from_tty
)
2216 static CORE_ADDR start
, stop
;
2217 char start_str
[40], stop_str
[40];
2220 if (target_is_remote ())
2222 if (args
== 0 || *args
== 0)
2223 { /* XXX FIXME: what should default behavior be? */
2224 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2228 if (0 != (tmp
= strchr (args
, ',')))
2230 *tmp
++ = '\0'; /* terminate start address */
2231 while (isspace ((int) *tmp
))
2233 start
= parse_and_eval_address (args
);
2234 stop
= parse_and_eval_address (tmp
);
2237 { /* no explicit end address? */
2238 start
= parse_and_eval_address (args
);
2239 stop
= start
+ 1; /* ??? */
2242 sprintf_vma (start_str
, start
);
2243 sprintf_vma (stop_str
, stop
);
2244 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
2245 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2248 error (_("Trace can only be run on remote targets."));
2251 /* tfind outside command */
2253 trace_find_outside_command (char *args
, int from_tty
)
2255 CORE_ADDR start
, stop
;
2256 char start_str
[40], stop_str
[40];
2259 if (target_is_remote ())
2261 if (args
== 0 || *args
== 0)
2262 { /* XXX FIXME: what should default behavior be? */
2263 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2267 if (0 != (tmp
= strchr (args
, ',')))
2269 *tmp
++ = '\0'; /* terminate start address */
2270 while (isspace ((int) *tmp
))
2272 start
= parse_and_eval_address (args
);
2273 stop
= parse_and_eval_address (tmp
);
2276 { /* no explicit end address? */
2277 start
= parse_and_eval_address (args
);
2278 stop
= start
+ 1; /* ??? */
2281 sprintf_vma (start_str
, start
);
2282 sprintf_vma (stop_str
, stop
);
2283 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
2284 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2287 error (_("Trace can only be run on remote targets."));
2290 /* save-tracepoints command */
2292 tracepoint_save_command (char *args
, int from_tty
)
2294 struct tracepoint
*tp
;
2295 struct action_line
*line
;
2297 char *i1
= " ", *i2
= " ";
2298 char *indent
, *actionline
, *pathname
;
2301 if (args
== 0 || *args
== 0)
2302 error (_("Argument required (file name in which to save tracepoints)"));
2304 if (tracepoint_chain
== 0)
2306 warning (_("save-tracepoints: no tracepoints to save."));
2310 pathname
= tilde_expand (args
);
2311 if (!(fp
= fopen (pathname
, "w")))
2312 error (_("Unable to open file '%s' for saving tracepoints (%s)"),
2313 args
, safe_strerror (errno
));
2316 ALL_TRACEPOINTS (tp
)
2318 if (tp
->addr_string
)
2319 fprintf (fp
, "trace %s\n", tp
->addr_string
);
2322 sprintf_vma (tmp
, tp
->address
);
2323 fprintf (fp
, "trace *0x%s\n", tmp
);
2327 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
2331 fprintf (fp
, " actions\n");
2333 for (line
= tp
->actions
; line
; line
= line
->next
)
2335 struct cmd_list_element
*cmd
;
2337 QUIT
; /* allow user to bail out with ^C */
2338 actionline
= line
->action
;
2339 while (isspace ((int) *actionline
))
2342 fprintf (fp
, "%s%s\n", indent
, actionline
);
2343 if (*actionline
!= '#') /* skip for comment lines */
2345 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
2347 error (_("Bad action list item: %s"), actionline
);
2348 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2350 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2358 printf_filtered ("Tracepoints saved to file '%s'.\n", args
);
2362 /* info scope command: list the locals for a scope. */
2364 scope_info (char *args
, int from_tty
)
2366 struct symtabs_and_lines sals
;
2368 struct minimal_symbol
*msym
;
2369 struct block
*block
;
2370 char **canonical
, *symname
, *save_args
= args
;
2371 struct dict_iterator iter
;
2374 if (args
== 0 || *args
== 0)
2375 error (_("requires an argument (function, line or *addr) to define a scope"));
2377 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
2378 if (sals
.nelts
== 0)
2379 return; /* presumably decode_line_1 has already warned */
2381 /* Resolve line numbers to PC */
2382 resolve_sal_pc (&sals
.sals
[0]);
2383 block
= block_for_pc (sals
.sals
[0].pc
);
2387 QUIT
; /* allow user to bail out with ^C */
2388 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2390 QUIT
; /* allow user to bail out with ^C */
2392 printf_filtered ("Scope for %s:\n", save_args
);
2395 symname
= SYMBOL_PRINT_NAME (sym
);
2396 if (symname
== NULL
|| *symname
== '\0')
2397 continue; /* probably botched, certainly useless */
2399 printf_filtered ("Symbol %s is ", symname
);
2400 switch (SYMBOL_CLASS (sym
))
2403 case LOC_UNDEF
: /* messed up symbol? */
2404 printf_filtered ("a bogus symbol, class %d.\n",
2405 SYMBOL_CLASS (sym
));
2406 count
--; /* don't count this one */
2409 printf_filtered ("a constant with value %ld (0x%lx)",
2410 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2412 case LOC_CONST_BYTES
:
2413 printf_filtered ("constant bytes: ");
2414 if (SYMBOL_TYPE (sym
))
2415 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2416 fprintf_filtered (gdb_stdout
, " %02x",
2417 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2420 printf_filtered ("in static storage at address ");
2421 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
2424 if (SYMBOL_IS_ARGUMENT (sym
))
2425 printf_filtered ("an argument in register $%s",
2426 gdbarch_register_name
2427 (current_gdbarch
, SYMBOL_VALUE (sym
)));
2429 printf_filtered ("a local variable in register $%s",
2430 gdbarch_register_name
2431 (current_gdbarch
, SYMBOL_VALUE (sym
)));
2434 printf_filtered ("an argument at stack/frame offset %ld",
2435 SYMBOL_VALUE (sym
));
2438 printf_filtered ("a local variable at frame offset %ld",
2439 SYMBOL_VALUE (sym
));
2442 printf_filtered ("a reference argument at offset %ld",
2443 SYMBOL_VALUE (sym
));
2445 case LOC_REGPARM_ADDR
:
2446 printf_filtered ("the address of an argument, in register $%s",
2447 gdbarch_register_name
2448 (current_gdbarch
, SYMBOL_VALUE (sym
)));
2451 printf_filtered ("a typedef.\n");
2454 printf_filtered ("a label at address ");
2455 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
2458 printf_filtered ("a function at address ");
2459 printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2461 case LOC_UNRESOLVED
:
2462 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2465 printf_filtered ("Unresolved Static");
2468 printf_filtered ("static storage at address ");
2469 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym
)));
2472 case LOC_OPTIMIZED_OUT
:
2473 printf_filtered ("optimized out.\n");
2476 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
2479 if (SYMBOL_TYPE (sym
))
2480 printf_filtered (", length %d.\n",
2481 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2483 if (BLOCK_FUNCTION (block
))
2486 block
= BLOCK_SUPERBLOCK (block
);
2489 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2493 /* worker function (cleanup) */
2495 replace_comma (void *data
)
2503 trace_dump_command (char *args
, int from_tty
)
2505 struct regcache
*regcache
;
2506 struct gdbarch
*gdbarch
;
2507 struct tracepoint
*t
;
2508 struct action_line
*action
;
2509 char *action_exp
, *next_comma
;
2510 struct cleanup
*old_cleanups
;
2511 int stepping_actions
= 0;
2512 int stepping_frame
= 0;
2514 if (!target_is_remote ())
2516 error (_("Trace can only be run on remote targets."));
2520 if (tracepoint_number
== -1)
2522 warning (_("No current trace frame."));
2527 if (t
->number
== tracepoint_number
)
2531 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2534 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2536 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2537 tracepoint_number
, traceframe_number
);
2539 /* The current frame is a trap frame if the frame PC is equal
2540 to the tracepoint PC. If not, then the current frame was
2541 collected during single-stepping. */
2543 regcache
= get_current_regcache ();
2544 gdbarch
= get_regcache_arch (regcache
);
2546 stepping_frame
= (t
->address
!= (regcache_read_pc (regcache
)
2547 - gdbarch_decr_pc_after_break (gdbarch
)));
2549 for (action
= t
->actions
; action
; action
= action
->next
)
2551 struct cmd_list_element
*cmd
;
2553 QUIT
; /* allow user to bail out with ^C */
2554 action_exp
= action
->action
;
2555 while (isspace ((int) *action_exp
))
2558 /* The collection actions to be done while stepping are
2559 bracketed by the commands "while-stepping" and "end". */
2561 if (*action_exp
== '#') /* comment line */
2564 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2566 error (_("Bad action list item: %s"), action_exp
);
2568 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2569 stepping_actions
= 1;
2570 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2571 stepping_actions
= 0;
2572 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2574 /* Display the collected data.
2575 For the trap frame, display only what was collected at
2576 the trap. Likewise for stepping frames, display only
2577 what was collected while stepping. This means that the
2578 two boolean variables, STEPPING_FRAME and
2579 STEPPING_ACTIONS should be equal. */
2580 if (stepping_frame
== stepping_actions
)
2583 { /* repeat over a comma-separated list */
2584 QUIT
; /* allow user to bail out with ^C */
2585 if (*action_exp
== ',')
2587 while (isspace ((int) *action_exp
))
2590 next_comma
= strchr (action_exp
, ',');
2592 if (0 == strncasecmp (action_exp
, "$reg", 4))
2593 registers_info (NULL
, from_tty
);
2594 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2595 locals_info (NULL
, from_tty
);
2596 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2597 args_info (NULL
, from_tty
);
2602 make_cleanup (replace_comma
, next_comma
);
2605 printf_filtered ("%s = ", action_exp
);
2606 output_command (action_exp
, from_tty
);
2607 printf_filtered ("\n");
2611 action_exp
= next_comma
;
2613 while (action_exp
&& *action_exp
== ',');
2617 discard_cleanups (old_cleanups
);
2620 /* Convert the memory pointed to by mem into hex, placing result in buf.
2621 * Return a pointer to the last char put in buf (null)
2622 * "stolen" from sparc-stub.c
2625 static const char hexchars
[] = "0123456789abcdef";
2628 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2636 *buf
++ = hexchars
[ch
>> 4];
2637 *buf
++ = hexchars
[ch
& 0xf];
2646 get_traceframe_number (void)
2648 return traceframe_number
;
2652 /* module initialization */
2654 _initialize_tracepoint (void)
2656 struct cmd_list_element
*c
;
2658 tracepoint_chain
= 0;
2659 tracepoint_count
= 0;
2660 traceframe_number
= -1;
2661 tracepoint_number
= -1;
2663 if (tracepoint_list
.list
== NULL
)
2665 tracepoint_list
.listsize
= 128;
2666 tracepoint_list
.list
= xmalloc
2667 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2669 if (tracepoint_list
.aexpr_list
== NULL
)
2671 tracepoint_list
.aexpr_listsize
= 128;
2672 tracepoint_list
.aexpr_list
= xmalloc
2673 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2676 if (stepping_list
.list
== NULL
)
2678 stepping_list
.listsize
= 128;
2679 stepping_list
.list
= xmalloc
2680 (stepping_list
.listsize
* sizeof (struct memrange
));
2683 if (stepping_list
.aexpr_list
== NULL
)
2685 stepping_list
.aexpr_listsize
= 128;
2686 stepping_list
.aexpr_list
= xmalloc
2687 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2690 add_info ("scope", scope_info
,
2691 _("List the variables local to a scope"));
2693 add_cmd ("tracepoints", class_trace
, NULL
,
2694 _("Tracing of program execution without stopping the program."),
2697 add_info ("tracepoints", tracepoints_info
, _("\
2698 Status of tracepoints, or tracepoint number NUMBER.\n\
2699 Convenience variable \"$tpnum\" contains the number of the\n\
2700 last tracepoint set."));
2702 add_info_alias ("tp", "tracepoints", 1);
2704 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
, _("\
2705 Save current tracepoint definitions as a script.\n\
2706 Use the 'source' command in another debug session to restore them."));
2707 set_cmd_completer (c
, filename_completer
);
2709 add_com ("tdump", class_trace
, trace_dump_command
,
2710 _("Print everything collected at the current tracepoint."));
2712 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2713 Select a trace frame;\n\
2714 No argument means forward by one frame; '-' means backward by one frame."),
2715 &tfindlist
, "tfind ", 1, &cmdlist
);
2717 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2718 Select a trace frame whose PC is outside the given range.\n\
2719 Usage: tfind outside addr1, addr2"),
2722 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2723 Select a trace frame whose PC is in the given range.\n\
2724 Usage: tfind range addr1,addr2"),
2727 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2728 Select a trace frame by source line.\n\
2729 Argument can be a line number (with optional source file), \n\
2730 a function name, or '*' followed by an address.\n\
2731 Default argument is 'the next source line that was traced'."),
2734 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2735 Select a trace frame by tracepoint number.\n\
2736 Default is the tracepoint for the current trace frame."),
2739 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2740 Select a trace frame by PC.\n\
2741 Default is the current PC, or the PC of the current trace frame."),
2744 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2745 Synonym for 'none'.\n\
2746 De-select any trace frame and resume 'live' debugging."),
2749 add_cmd ("none", class_trace
, trace_find_none_command
,
2750 _("De-select any trace frame and resume 'live' debugging."),
2753 add_cmd ("start", class_trace
, trace_find_start_command
,
2754 _("Select the first trace frame in the trace buffer."),
2757 add_com ("tstatus", class_trace
, trace_status_command
,
2758 _("Display the status of the current trace data collection."));
2760 add_com ("tstop", class_trace
, trace_stop_command
,
2761 _("Stop trace data collection."));
2763 add_com ("tstart", class_trace
, trace_start_command
,
2764 _("Start trace data collection."));
2766 add_com ("passcount", class_trace
, trace_pass_command
, _("\
2767 Set the passcount for a tracepoint.\n\
2768 The trace will end when the tracepoint has been passed 'count' times.\n\
2769 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
2770 if TPNUM is omitted, passcount refers to the last tracepoint defined."));
2772 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2773 Ends a list of commands or actions.\n\
2774 Several GDB commands allow you to enter a list of commands or actions.\n\
2775 Entering \"end\" on a line by itself is the normal way to terminate\n\
2777 Note: the \"end\" command cannot be used at the gdb prompt."));
2779 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2780 Specify single-stepping behavior at a tracepoint.\n\
2781 Argument is number of instructions to trace in single-step mode\n\
2782 following the tracepoint. This command is normally followed by\n\
2783 one or more \"collect\" commands, to specify what to collect\n\
2784 while single-stepping.\n\n\
2785 Note: this command can only be used in a tracepoint \"actions\" list."));
2787 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2788 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2790 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2791 Specify one or more data items to be collected at a tracepoint.\n\
2792 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2793 collect all data (variables, registers) referenced by that expression.\n\
2794 Also accepts the following special arguments:\n\
2795 $regs -- all registers.\n\
2796 $args -- all function arguments.\n\
2797 $locals -- all variables local to the block/function scope.\n\
2798 Note: this command can only be used in a tracepoint \"actions\" list."));
2800 add_com ("actions", class_trace
, trace_actions_command
, _("\
2801 Specify the actions to be taken at a tracepoint.\n\
2802 Tracepoint actions may include collecting of specified data, \n\
2803 single-stepping, or enabling/disabling other tracepoints, \n\
2804 depending on target's capabilities."));
2806 add_cmd ("tracepoints", class_trace
, delete_trace_command
, _("\
2807 Delete specified tracepoints.\n\
2808 Arguments are tracepoint numbers, separated by spaces.\n\
2809 No argument means delete all tracepoints."),
2812 add_cmd ("tracepoints", class_trace
, disable_trace_command
, _("\
2813 Disable specified tracepoints.\n\
2814 Arguments are tracepoint numbers, separated by spaces.\n\
2815 No argument means disable all tracepoints."),
2818 add_cmd ("tracepoints", class_trace
, enable_trace_command
, _("\
2819 Enable specified tracepoints.\n\
2820 Arguments are tracepoint numbers, separated by spaces.\n\
2821 No argument means enable all tracepoints."),
2824 c
= add_com ("trace", class_trace
, trace_command
, _("\
2825 Set a tracepoint at a specified line or function or address.\n\
2826 Argument may be a line number, function name, or '*' plus an address.\n\
2827 For a line number or function, trace at the start of its code.\n\
2828 If an address is specified, trace at that exact address.\n\n\
2829 Do \"help tracepoints\" for info on other tracepoint commands."));
2830 set_cmd_completer (c
, location_completer
);
2832 add_com_alias ("tp", "trace", class_alias
, 0);
2833 add_com_alias ("tr", "trace", class_alias
, 1);
2834 add_com_alias ("tra", "trace", class_alias
, 1);
2835 add_com_alias ("trac", "trace", class_alias
, 1);
2837 target_buf_size
= 2048;
2838 target_buf
= xmalloc (target_buf_size
);