1 /* Tracing functionality for remote targets in custom GDB protocol
2 Copyright 1997, 1998 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
25 #include "expression.h"
30 #include "gdb_string.h"
32 #include "tracepoint.h"
38 /* readline include files */
39 #include <readline/readline.h>
40 #include <readline/history.h>
42 /* readline defines this. */
49 /* maximum length of an agent aexpression.
50 this accounts for the fact that packets are limited to 400 bytes
51 (which includes everything -- including the checksum), and assumes
52 the worst case of maximum length for each of the pieces of a
55 NOTE: expressions get mem2hex'ed otherwise this would be twice as
56 large. (400 - 31)/2 == 184 */
57 #define MAX_AGENT_EXPR_LEN 184
60 extern int info_verbose
;
61 extern void (*readline_begin_hook
) PARAMS ((char *,...));
62 extern char *(*readline_hook
) PARAMS ((char *));
63 extern void (*readline_end_hook
) PARAMS ((void));
64 extern void x_command
PARAMS ((char *, int));
65 extern int addressprint
; /* Print machine addresses? */
67 /* GDB commands implemented in other modules:
70 extern void output_command
PARAMS ((char *, int));
71 extern void registers_info
PARAMS ((char *, int));
72 extern void args_info
PARAMS ((char *, int));
73 extern void locals_info
PARAMS ((char *, int));
76 /* If this definition isn't overridden by the header files, assume
77 that isatty and fileno exist on this system. */
79 #define ISATTY(FP) (isatty (fileno (FP)))
85 This module defines the following debugger commands:
86 trace : set a tracepoint on a function, line, or address.
87 info trace : list all debugger-defined tracepoints.
88 delete trace : delete one or more tracepoints.
89 enable trace : enable one or more tracepoints.
90 disable trace : disable one or more tracepoints.
91 actions : specify actions to be taken at a tracepoint.
92 passcount : specify a pass count for a tracepoint.
93 tstart : start a trace experiment.
94 tstop : stop a trace experiment.
95 tstatus : query the status of a trace experiment.
96 tfind : find a trace frame in the trace buffer.
97 tdump : print everything collected at the current tracepoint.
98 save-tracepoints : write tracepoint setup into a file.
100 This module defines the following user-visible debugger variables:
101 $trace_frame : sequence number of trace frame currently being debugged.
102 $trace_line : source line of trace frame currently being debugged.
103 $trace_file : source file of trace frame currently being debugged.
104 $tracepoint : tracepoint number of trace frame currently being debugged.
108 /* ======= Important global variables: ======= */
110 /* Chain of all tracepoints defined. */
111 struct tracepoint
*tracepoint_chain
;
113 /* Number of last tracepoint made. */
114 static int tracepoint_count
;
116 /* Number of last traceframe collected. */
117 static int traceframe_number
;
119 /* Tracepoint for last traceframe collected. */
120 static int tracepoint_number
;
122 /* Symbol for function for last traceframe collected */
123 static struct symbol
*traceframe_fun
;
125 /* Symtab and line for last traceframe collected */
126 static struct symtab_and_line traceframe_sal
;
128 /* Tracing command lists */
129 static struct cmd_list_element
*tfindlist
;
131 /* ======= Important command functions: ======= */
132 static void trace_command
PARAMS ((char *, int));
133 static void tracepoints_info
PARAMS ((char *, int));
134 static void delete_trace_command
PARAMS ((char *, int));
135 static void enable_trace_command
PARAMS ((char *, int));
136 static void disable_trace_command
PARAMS ((char *, int));
137 static void trace_pass_command
PARAMS ((char *, int));
138 static void trace_actions_command
PARAMS ((char *, int));
139 static void trace_start_command
PARAMS ((char *, int));
140 static void trace_stop_command
PARAMS ((char *, int));
141 static void trace_status_command
PARAMS ((char *, int));
142 static void trace_find_command
PARAMS ((char *, int));
143 static void trace_find_pc_command
PARAMS ((char *, int));
144 static void trace_find_tracepoint_command
PARAMS ((char *, int));
145 static void trace_find_line_command
PARAMS ((char *, int));
146 static void trace_find_range_command
PARAMS ((char *, int));
147 static void trace_find_outside_command
PARAMS ((char *, int));
148 static void tracepoint_save_command
PARAMS ((char *, int));
149 static void trace_dump_command
PARAMS ((char *, int));
151 /* support routines */
152 static void trace_mention
PARAMS ((struct tracepoint
*));
154 struct collection_list
;
155 static void add_aexpr
PARAMS ((struct collection_list
*, struct agent_expr
*));
156 static unsigned char *mem2hex (unsigned char *, unsigned char *, int);
157 static void add_register
PARAMS ((struct collection_list
* collection
,
158 unsigned int regno
));
159 static void free_actions_list
PARAMS ((char **actions_list
));
160 static void free_actions_list_cleanup_wrapper
PARAMS ((void *));
162 extern void _initialize_tracepoint
PARAMS ((void));
164 /* Utility: returns true if "target remote" */
168 if (current_target
.to_shortname
&&
169 strcmp (current_target
.to_shortname
, "remote") == 0)
175 /* Utility: generate error from an incoming stub packet. */
181 return; /* not an error msg */
184 case '1': /* malformed packet error */
185 if (*++buf
== '0') /* general case: */
186 error ("tracepoint.c: error in outgoing packet.");
188 error ("tracepoint.c: error in outgoing packet at field #%d.",
189 strtol (buf
, NULL
, 16));
191 error ("trace API error 0x%s.", ++buf
);
193 error ("Target returns error code '%s'.", buf
);
197 /* Utility: wait for reply from stub, while accepting "O" packets */
199 remote_get_noisy_reply (buf
)
202 do /* loop on reply from remote stub */
204 QUIT
; /* allow user to bail out with ^C */
207 error ("Target does not support this command.");
208 else if (buf
[0] == 'E')
210 else if (buf
[0] == 'O' &&
212 remote_console_output (buf
+ 1); /* 'O' message from stub */
214 return buf
; /* here's the actual reply */
219 /* Set tracepoint count to NUM. */
221 set_tracepoint_count (num
)
224 tracepoint_count
= num
;
225 set_internalvar (lookup_internalvar ("tpnum"),
226 value_from_longest (builtin_type_int
, (LONGEST
) num
));
229 /* Set traceframe number to NUM. */
231 set_traceframe_num (num
)
234 traceframe_number
= num
;
235 set_internalvar (lookup_internalvar ("trace_frame"),
236 value_from_longest (builtin_type_int
, (LONGEST
) num
));
239 /* Set tracepoint number to NUM. */
241 set_tracepoint_num (num
)
244 tracepoint_number
= num
;
245 set_internalvar (lookup_internalvar ("tracepoint"),
246 value_from_longest (builtin_type_int
, (LONGEST
) num
));
249 /* Set externally visible debug variables for querying/printing
250 the traceframe context (line, function, file) */
253 set_traceframe_context (trace_pc
)
256 static struct type
*func_string
, *file_string
;
257 static struct type
*func_range
, *file_range
;
258 static value_ptr func_val
, file_val
;
259 static struct type
*charstar
;
262 if (charstar
== (struct type
*) NULL
)
263 charstar
= lookup_pointer_type (builtin_type_char
);
265 if (trace_pc
== -1) /* cease debugging any trace buffers */
268 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
269 traceframe_sal
.symtab
= NULL
;
270 set_internalvar (lookup_internalvar ("trace_func"),
271 value_from_longest (charstar
, (LONGEST
) 0));
272 set_internalvar (lookup_internalvar ("trace_file"),
273 value_from_longest (charstar
, (LONGEST
) 0));
274 set_internalvar (lookup_internalvar ("trace_line"),
275 value_from_longest (builtin_type_int
, (LONGEST
) - 1));
279 /* save as globals for internal use */
280 traceframe_sal
= find_pc_line (trace_pc
, 0);
281 traceframe_fun
= find_pc_function (trace_pc
);
283 /* save linenumber as "$trace_line", a debugger variable visible to users */
284 set_internalvar (lookup_internalvar ("trace_line"),
285 value_from_longest (builtin_type_int
,
286 (LONGEST
) traceframe_sal
.line
));
288 /* save func name as "$trace_func", a debugger variable visible to users */
289 if (traceframe_fun
== NULL
||
290 SYMBOL_NAME (traceframe_fun
) == NULL
)
291 set_internalvar (lookup_internalvar ("trace_func"),
292 value_from_longest (charstar
, (LONGEST
) 0));
295 len
= strlen (SYMBOL_NAME (traceframe_fun
));
296 func_range
= create_range_type (func_range
,
297 builtin_type_int
, 0, len
- 1);
298 func_string
= create_array_type (func_string
,
299 builtin_type_char
, func_range
);
300 func_val
= allocate_value (func_string
);
301 VALUE_TYPE (func_val
) = func_string
;
302 memcpy (VALUE_CONTENTS_RAW (func_val
),
303 SYMBOL_NAME (traceframe_fun
),
305 func_val
->modifiable
= 0;
306 set_internalvar (lookup_internalvar ("trace_func"), func_val
);
309 /* save file name as "$trace_file", a debugger variable visible to users */
310 if (traceframe_sal
.symtab
== NULL
||
311 traceframe_sal
.symtab
->filename
== NULL
)
312 set_internalvar (lookup_internalvar ("trace_file"),
313 value_from_longest (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 VALUE_TYPE (file_val
) = file_string
;
323 memcpy (VALUE_CONTENTS_RAW (file_val
),
324 traceframe_sal
.symtab
->filename
,
326 file_val
->modifiable
= 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. Validate
338 your arguments BEFORE calling this routine! */
340 static struct tracepoint
*
341 set_raw_tracepoint (sal
)
342 struct symtab_and_line sal
;
344 register struct tracepoint
*t
, *tc
;
345 struct cleanup
*old_chain
;
347 t
= (struct tracepoint
*) xmalloc (sizeof (struct tracepoint
));
348 old_chain
= make_cleanup (free
, t
);
349 memset (t
, 0, sizeof (*t
));
351 if (sal
.symtab
== NULL
)
352 t
->source_file
= NULL
;
354 t
->source_file
= savestring (sal
.symtab
->filename
,
355 strlen (sal
.symtab
->filename
));
357 t
->section
= sal
.section
;
358 t
->language
= current_language
->la_language
;
359 t
->input_radix
= input_radix
;
360 t
->line_number
= sal
.line
;
361 t
->enabled
= enabled
;
365 t
->addr_string
= NULL
;
367 /* Add this tracepoint to the end of the chain
368 so that a list of tracepoints will come out in order
369 of increasing numbers. */
371 tc
= tracepoint_chain
;
373 tracepoint_chain
= t
;
380 discard_cleanups (old_chain
);
384 /* Set a tracepoint according to ARG (function, linenum or *address) */
386 trace_command (arg
, from_tty
)
390 char **canonical
= (char **) NULL
;
391 struct symtabs_and_lines sals
;
392 struct symtab_and_line sal
;
393 struct tracepoint
*t
;
394 char *addr_start
= 0, *addr_end
= 0;
398 error ("trace command requires an argument");
400 if (from_tty
&& info_verbose
)
401 printf_filtered ("TRACE %s\n", arg
);
404 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, &canonical
);
407 return; /* ??? Presumably decode_line_1 has already warned? */
409 /* Resolve all line numbers to PC's */
410 for (i
= 0; i
< sals
.nelts
; i
++)
411 resolve_sal_pc (&sals
.sals
[i
]);
413 /* Now set all the tracepoints. */
414 for (i
= 0; i
< sals
.nelts
; i
++)
418 t
= set_raw_tracepoint (sal
);
419 set_tracepoint_count (tracepoint_count
+ 1);
420 t
->number
= tracepoint_count
;
422 /* If a canonical line spec is needed use that instead of the
424 if (canonical
!= (char **) NULL
&& canonical
[i
] != NULL
)
425 t
->addr_string
= canonical
[i
];
427 t
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
431 /* Let the UI know of any additions */
432 if (create_tracepoint_hook
)
433 create_tracepoint_hook (t
);
438 printf_filtered ("Multiple tracepoints were set.\n");
439 printf_filtered ("Use 'delete trace' to delete unwanted tracepoints.\n");
443 /* Tell the user we have just set a tracepoint TP. */
447 struct tracepoint
*tp
;
449 printf_filtered ("Tracepoint %d", tp
->number
);
451 if (addressprint
|| (tp
->source_file
== NULL
))
453 printf_filtered (" at ");
454 print_address_numeric (tp
->address
, 1, gdb_stdout
);
457 printf_filtered (": file %s, line %d.",
458 tp
->source_file
, tp
->line_number
);
460 printf_filtered ("\n");
463 /* Print information on tracepoint number TPNUM_EXP, or all if omitted. */
466 tracepoints_info (tpnum_exp
, from_tty
)
470 struct tracepoint
*t
;
471 struct action_line
*action
;
472 int found_a_tracepoint
= 0;
473 char wrap_indent
[80];
478 tpnum
= parse_and_eval_address (tpnum_exp
);
481 if (tpnum
== -1 || tpnum
== t
->number
)
483 extern int addressprint
; /* print machine addresses? */
485 if (!found_a_tracepoint
++)
487 printf_filtered ("Num Enb ");
489 printf_filtered ("Address ");
490 printf_filtered ("PassC StepC What\n");
492 strcpy (wrap_indent
, " ");
494 strcat (wrap_indent
, " ");
496 printf_filtered ("%-3d %-3s ", t
->number
,
497 t
->enabled
== enabled
? "y" : "n");
499 printf_filtered ("%s ",
500 local_hex_string_custom ((unsigned long) t
->address
,
502 printf_filtered ("%-5d %-5d ", t
->pass_count
, t
->step_count
);
506 sym
= find_pc_sect_function (t
->address
, t
->section
);
509 fputs_filtered ("in ", gdb_stdout
);
510 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
511 wrap_here (wrap_indent
);
512 fputs_filtered (" at ", gdb_stdout
);
514 fputs_filtered (t
->source_file
, gdb_stdout
);
515 printf_filtered (":%d", t
->line_number
);
518 print_address_symbolic (t
->address
, gdb_stdout
, demangle
, " ");
520 printf_filtered ("\n");
523 printf_filtered (" Actions for tracepoint %d: \n", t
->number
);
524 for (action
= t
->actions
; action
; action
= action
->next
)
526 printf_filtered ("\t%s\n", action
->action
);
530 if (!found_a_tracepoint
)
533 printf_filtered ("No tracepoints.\n");
535 printf_filtered ("No tracepoint number %d.\n", tpnum
);
539 /* Optimization: the code to parse an enable, disable, or delete TP command
540 is virtually identical except for whether it performs an enable, disable,
541 or delete. Therefore I've combined them into one function with an opcode.
543 enum tracepoint_opcode
550 /* This function implements enable, disable and delete commands. */
552 tracepoint_operation (t
, from_tty
, opcode
)
553 struct tracepoint
*t
;
555 enum tracepoint_opcode opcode
;
557 struct tracepoint
*t2
;
562 t
->enabled
= enabled
;
563 if (modify_tracepoint_hook
)
564 modify_tracepoint_hook (t
);
567 t
->enabled
= disabled
;
568 if (modify_tracepoint_hook
)
569 modify_tracepoint_hook (t
);
572 if (tracepoint_chain
== t
)
573 tracepoint_chain
= t
->next
;
582 /* Let the UI know of any deletions */
583 if (delete_tracepoint_hook
)
584 delete_tracepoint_hook (t
);
587 free (t
->addr_string
);
589 free (t
->source_file
);
598 /* Utility: parse a tracepoint number and look it up in the list. */
600 get_tracepoint_by_number (arg
)
603 struct tracepoint
*t
;
609 error ("Bad tracepoint argument");
611 if (*arg
== 0 || **arg
== 0) /* empty arg means refer to last tp */
612 tpnum
= tracepoint_count
;
613 else if (**arg
== '$') /* handle convenience variable */
615 /* Make a copy of the name, so we can null-terminate it
616 to pass to lookup_internalvar(). */
618 while (isalnum ((int) *end
) || *end
== '_')
620 copy
= (char *) alloca (end
- *arg
);
621 strncpy (copy
, *arg
+ 1, (end
- *arg
- 1));
622 copy
[end
- *arg
- 1] = '\0';
625 val
= value_of_internalvar (lookup_internalvar (copy
));
626 if (TYPE_CODE (VALUE_TYPE (val
)) != TYPE_CODE_INT
)
627 error ("Convenience variable must have integral type.");
628 tpnum
= (int) value_as_long (val
);
631 /* handle tracepoint number */
633 tpnum
= strtol (*arg
, arg
, 0);
634 if (tpnum
== 0) /* possible strtol failure */
635 while (**arg
&& !isspace ((int) **arg
))
636 (*arg
)++; /* advance to next white space, if any */
639 if (t
->number
== tpnum
)
643 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
647 /* Utility: parse a list of tracepoint numbers, and call a func for each. */
649 map_args_over_tracepoints (args
, from_tty
, opcode
)
652 enum tracepoint_opcode opcode
;
654 struct tracepoint
*t
, *tmp
;
656 if (args
== 0 || *args
== 0) /* do them all */
657 ALL_TRACEPOINTS_SAFE (t
, tmp
)
658 tracepoint_operation (t
, from_tty
, opcode
);
662 QUIT
; /* give user option to bail out with ^C */
663 t
= get_tracepoint_by_number (&args
);
665 tracepoint_operation (t
, from_tty
, opcode
);
666 while (*args
== ' ' || *args
== '\t')
671 /* The 'enable trace' command enables tracepoints. Not supported by all targets. */
673 enable_trace_command (args
, from_tty
)
678 map_args_over_tracepoints (args
, from_tty
, enable_op
);
681 /* The 'disable trace' command enables tracepoints. Not supported by all targets. */
683 disable_trace_command (args
, from_tty
)
688 map_args_over_tracepoints (args
, from_tty
, disable_op
);
691 /* Remove a tracepoint (or all if no argument) */
693 delete_trace_command (args
, from_tty
)
698 if (!args
|| !*args
) /* No args implies all tracepoints; */
699 if (from_tty
) /* confirm only if from_tty... */
700 if (tracepoint_chain
) /* and if there are tracepoints to delete! */
701 if (!query ("Delete all tracepoints? "))
704 map_args_over_tracepoints (args
, from_tty
, delete_op
);
707 /* Set passcount for tracepoint.
709 First command argument is passcount, second is tracepoint number.
710 If tracepoint number omitted, apply to most recently defined.
711 Also accepts special argument "all". */
714 trace_pass_command (args
, from_tty
)
718 struct tracepoint
*t1
= (struct tracepoint
*) -1, *t2
;
721 if (args
== 0 || *args
== 0)
722 error ("PASS command requires an argument (count + optional TP num)");
724 count
= strtoul (args
, &args
, 10); /* count comes first, then TP num */
726 while (*args
&& isspace ((int) *args
))
729 if (*args
&& strncasecmp (args
, "all", 3) == 0)
730 args
+= 3; /* skip special argument "all" */
732 t1
= get_tracepoint_by_number (&args
);
735 error ("Junk at end of arguments.");
738 return; /* error, bad tracepoint number */
741 if (t1
== (struct tracepoint
*) -1 || t1
== t2
)
743 t2
->pass_count
= count
;
744 if (modify_tracepoint_hook
)
745 modify_tracepoint_hook (t2
);
747 printf_filtered ("Setting tracepoint %d's passcount to %d\n",
752 /* ACTIONS functions: */
754 /* Prototypes for action-parsing utility commands */
755 static void read_actions
PARAMS ((struct tracepoint
*));
757 /* The three functions:
758 collect_pseudocommand,
759 while_stepping_pseudocommand, and
760 end_actions_pseudocommand
761 are placeholders for "commands" that are actually ONLY to be used
762 within a tracepoint action list. If the actual function is ever called,
763 it means that somebody issued the "command" at the top level,
764 which is always an error. */
767 end_actions_pseudocommand (args
, from_tty
)
771 error ("This command cannot be used at the top level.");
775 while_stepping_pseudocommand (args
, from_tty
)
779 error ("This command can only be used in a tracepoint actions list.");
783 collect_pseudocommand (args
, from_tty
)
787 error ("This command can only be used in a tracepoint actions list.");
790 /* Enter a list of actions for a tracepoint. */
792 trace_actions_command (args
, from_tty
)
796 struct tracepoint
*t
;
798 char *end_msg
= "End with a line saying just \"end\".";
800 t
= get_tracepoint_by_number (&args
);
803 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
808 if (readline_begin_hook
)
809 (*readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
810 else if (input_from_terminal_p ())
811 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
815 t
->step_count
= 0; /* read_actions may set this */
818 if (readline_end_hook
)
819 (*readline_end_hook
) ();
821 /* tracepoints_changed () */
823 /* else error, just return; */
826 /* worker function */
829 struct tracepoint
*t
;
832 char *prompt1
= "> ", *prompt2
= " > ";
833 char *prompt
= prompt1
;
834 enum actionline_type linetype
;
835 extern FILE *instream
;
836 struct action_line
*next
= NULL
, *temp
;
837 struct cleanup
*old_chain
;
839 /* Control-C quits instantly if typed while in this loop
840 since it should not wait until the user types a newline. */
846 signal (STOP_SIGNAL
, handle_stop_sig
);
848 signal (STOP_SIGNAL
, stop_sig
);
851 old_chain
= make_cleanup ((make_cleanup_func
) free_actions
, (void *) t
);
854 /* Make sure that all output has been output. Some machines may let
855 you get away with leaving out some of the gdb_flush, but not all. */
857 gdb_flush (gdb_stdout
);
858 gdb_flush (gdb_stderr
);
860 if (readline_hook
&& instream
== NULL
)
861 line
= (*readline_hook
) (prompt
);
862 else if (instream
== stdin
&& ISATTY (instream
))
864 line
= readline (prompt
);
865 if (line
&& *line
) /* add it to command history */
869 line
= gdb_readline (0);
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 means
908 this tracepoint has no actions. Discard empty list. */
917 signal (STOP_SIGNAL
, SIG_DFL
);
920 discard_cleanups (old_chain
);
923 /* worker function */
925 validate_actionline (line
, t
)
927 struct tracepoint
*t
;
929 struct cmd_list_element
*c
;
930 struct expression
*exp
= NULL
;
931 struct cleanup
*old_chain
= NULL
;
934 for (p
= *line
; isspace ((int) *p
);)
937 /* symbol lookup etc. */
938 if (*p
== '\0') /* empty line: just prompt for another line. */
941 if (*p
== '#') /* comment line */
944 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
947 warning ("'%s' is not an action that I know, or is ambiguous.", p
);
951 if (c
->function
.cfunc
== collect_pseudocommand
)
953 struct agent_expr
*aexpr
;
954 struct agent_reqs areqs
;
957 { /* repeat over a comma-separated list */
958 QUIT
; /* allow user to bail out with ^C */
959 while (isspace ((int) *p
))
962 if (*p
== '$') /* look for special pseudo-symbols */
964 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
965 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
966 (0 == strncasecmp ("loc", p
+ 1, 3)))
971 /* else fall thru, treat p as an expression and parse it! */
973 exp
= parse_exp_1 (&p
, block_for_pc (t
->address
), 1);
974 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
977 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
979 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
981 warning ("constant %s (value %ld) will not be collected.",
982 SYMBOL_NAME (exp
->elts
[2].symbol
),
983 SYMBOL_VALUE (exp
->elts
[2].symbol
));
986 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
988 warning ("%s is optimized away and cannot be collected.",
989 SYMBOL_NAME (exp
->elts
[2].symbol
));
994 /* we have something to collect, make sure that the expr to
995 bytecode translator can handle it and that it's not too long */
996 aexpr
= gen_trace_for_expr (t
->address
, exp
);
997 (void) make_cleanup ((make_cleanup_func
) free_agent_expr
, aexpr
);
999 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
1000 error ("expression too complicated, try simplifying");
1002 ax_reqs (aexpr
, &areqs
);
1003 (void) make_cleanup (free
, areqs
.reg_mask
);
1005 if (areqs
.flaw
!= agent_flaw_none
)
1006 error ("malformed expression");
1008 if (areqs
.min_height
< 0)
1009 error ("gdb: Internal error: expression has min height < 0");
1011 if (areqs
.max_height
> 20)
1012 error ("expression too complicated, try simplifying");
1014 do_cleanups (old_chain
);
1016 while (p
&& *p
++ == ',');
1019 else if (c
->function
.cfunc
== while_stepping_pseudocommand
)
1021 char *steparg
; /* in case warning is necessary */
1023 while (isspace ((int) *p
))
1028 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
1030 warning ("'%s': bad step-count; command ignored.", *line
);
1035 else if (c
->function
.cfunc
== end_actions_pseudocommand
)
1039 warning ("'%s' is not a supported tracepoint action.", *line
);
1044 /* worker function */
1047 struct tracepoint
*t
;
1049 struct action_line
*line
, *next
;
1051 for (line
= t
->actions
; line
; line
= next
)
1055 free (line
->action
);
1063 int type
; /* 0 for absolute memory range, else basereg number */
1064 bfd_signed_vma start
;
1068 struct collection_list
1070 unsigned char regs_mask
[8]; /* room for up to 256 regs */
1073 struct memrange
*list
;
1074 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
1075 long next_aexpr_elt
;
1076 struct agent_expr
**aexpr_list
;
1079 tracepoint_list
, stepping_list
;
1081 /* MEMRANGE functions: */
1083 static int memrange_cmp
PARAMS ((const void *, const void *));
1085 /* compare memranges for qsort */
1087 memrange_cmp (va
, vb
)
1091 const struct memrange
*a
= va
, *b
= vb
;
1093 if (a
->type
< b
->type
)
1095 if (a
->type
> b
->type
)
1099 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
1101 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
1106 if (a
->start
< b
->start
)
1108 if (a
->start
> b
->start
)
1114 /* Sort the memrange list using qsort, and merge adjacent memranges */
1116 memrange_sortmerge (memranges
)
1117 struct collection_list
*memranges
;
1121 qsort (memranges
->list
, memranges
->next_memrange
,
1122 sizeof (struct memrange
), memrange_cmp
);
1123 if (memranges
->next_memrange
> 0)
1125 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
1127 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
1128 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
1129 MAX_REGISTER_VIRTUAL_SIZE
)
1131 /* memrange b starts before memrange a ends; merge them. */
1132 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
1133 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
1134 continue; /* next b, same a */
1138 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
1139 sizeof (struct memrange
));
1141 memranges
->next_memrange
= a
+ 1;
1145 /* Add a register to a collection list */
1147 add_register (collection
, regno
)
1148 struct collection_list
*collection
;
1152 printf_filtered ("collect register %d\n", regno
);
1153 if (regno
> (8 * sizeof (collection
->regs_mask
)))
1154 error ("Internal: register number %d too large for tracepoint",
1156 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
1159 /* Add a memrange to a collection list */
1161 add_memrange (memranges
, type
, base
, len
)
1162 struct collection_list
*memranges
;
1164 bfd_signed_vma base
;
1169 printf_filtered ("(%d,", type
);
1171 printf_filtered (",%ld)\n", len
);
1174 /* type: 0 == memory, n == basereg */
1175 memranges
->list
[memranges
->next_memrange
].type
= type
;
1176 /* base: addr if memory, offset if reg relative. */
1177 memranges
->list
[memranges
->next_memrange
].start
= base
;
1178 /* len: we actually save end (base + len) for convenience */
1179 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
1180 memranges
->next_memrange
++;
1181 if (memranges
->next_memrange
>= memranges
->listsize
)
1183 memranges
->listsize
*= 2;
1184 memranges
->list
= xrealloc (memranges
->list
,
1185 memranges
->listsize
);
1188 if (type
!= -1) /* better collect the base register! */
1189 add_register (memranges
, type
);
1192 /* Add a symbol to a collection list */
1194 collect_symbol (collect
, sym
, frame_regno
, frame_offset
)
1195 struct collection_list
*collect
;
1202 bfd_signed_vma offset
;
1204 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
1205 switch (SYMBOL_CLASS (sym
))
1208 printf_filtered ("%s: don't know symbol class %d\n",
1209 SYMBOL_NAME (sym
), SYMBOL_CLASS (sym
));
1212 printf_filtered ("constant %s (value %ld) will not be collected.\n",
1213 SYMBOL_NAME (sym
), SYMBOL_VALUE (sym
));
1216 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1221 sprintf_vma (tmp
, offset
);
1222 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1223 SYMBOL_NAME (sym
), len
, tmp
/* address */);
1225 add_memrange (collect
, -1, offset
, len
); /* 0 == memory */
1229 reg
= SYMBOL_VALUE (sym
);
1231 printf_filtered ("LOC_REG[parm] %s: ", SYMBOL_NAME (sym
));
1232 add_register (collect
, reg
);
1233 /* check for doubles stored in two registers */
1234 /* FIXME: how about larger types stored in 3 or more regs? */
1235 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
1236 len
> REGISTER_RAW_SIZE (reg
))
1237 add_register (collect
, reg
+ 1);
1240 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1241 printf_filtered (" (will not collect %s)\n",
1246 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1249 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1250 SYMBOL_NAME (sym
), len
);
1251 printf_vma (offset
);
1252 printf_filtered (" from frame ptr reg %d\n", reg
);
1254 add_memrange (collect
, reg
, offset
, len
);
1256 case LOC_REGPARM_ADDR
:
1257 reg
= SYMBOL_VALUE (sym
);
1261 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1262 SYMBOL_NAME (sym
), len
);
1263 printf_vma (offset
);
1264 printf_filtered (" from reg %d\n", reg
);
1266 add_memrange (collect
, reg
, offset
, len
);
1271 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1274 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1275 SYMBOL_NAME (sym
), len
);
1276 printf_vma (offset
);
1277 printf_filtered (" from frame ptr reg %d\n", reg
);
1279 add_memrange (collect
, reg
, offset
, len
);
1282 case LOC_BASEREG_ARG
:
1283 reg
= SYMBOL_BASEREG (sym
);
1284 offset
= SYMBOL_VALUE (sym
);
1287 printf_filtered ("LOC_BASEREG %s: collect %ld bytes at offset ",
1288 SYMBOL_NAME (sym
), len
);
1289 printf_vma (offset
);
1290 printf_filtered (" from basereg %d\n", reg
);
1292 add_memrange (collect
, reg
, offset
, len
);
1294 case LOC_UNRESOLVED
:
1295 printf_filtered ("Don't know LOC_UNRESOLVED %s\n", SYMBOL_NAME (sym
));
1297 case LOC_OPTIMIZED_OUT
:
1298 printf_filtered ("%s has been optimized out of existance.\n",
1304 /* Add all locals (or args) symbols to collection list */
1306 add_local_symbols (collect
, pc
, frame_regno
, frame_offset
, type
)
1307 struct collection_list
*collect
;
1314 struct block
*block
;
1315 int i
, nsyms
, count
= 0;
1317 block
= block_for_pc (pc
);
1320 QUIT
; /* allow user to bail out with ^C */
1321 nsyms
= BLOCK_NSYMS (block
);
1322 for (i
= 0; i
< nsyms
; i
++)
1324 sym
= BLOCK_SYM (block
, i
);
1325 switch (SYMBOL_CLASS (sym
))
1328 warning ("don't know how to trace local symbol %s",
1334 if (type
== 'L') /* collecting Locals */
1337 collect_symbol (collect
, sym
, frame_regno
, frame_offset
);
1344 case LOC_REGPARM_ADDR
:
1345 case LOC_BASEREG_ARG
:
1346 if (type
== 'A') /* collecting Arguments */
1349 collect_symbol (collect
, sym
, frame_regno
, frame_offset
);
1353 if (BLOCK_FUNCTION (block
))
1356 block
= BLOCK_SUPERBLOCK (block
);
1359 warning ("No %s found in scope.", type
== 'L' ? "locals" : "args");
1362 /* worker function */
1364 clear_collection_list (list
)
1365 struct collection_list
*list
;
1369 list
->next_memrange
= 0;
1370 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1372 free_agent_expr (list
->aexpr_list
[ndx
]);
1373 list
->aexpr_list
[ndx
] = NULL
;
1375 list
->next_aexpr_elt
= 0;
1376 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1379 /* reduce a collection list to string form (for gdb protocol) */
1381 stringify_collection_list (list
, string
)
1382 struct collection_list
*list
;
1385 char temp_buf
[2048];
1389 char *(*str_list
)[];
1393 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1394 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1396 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1397 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1399 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1402 printf_filtered ("\nCollecting registers (mask): 0x");
1407 QUIT
; /* allow user to bail out with ^C */
1409 printf_filtered ("%02X", list
->regs_mask
[i
]);
1410 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1413 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1417 printf_filtered ("\n");
1418 if (list
->next_memrange
> 0 && info_verbose
)
1419 printf_filtered ("Collecting memranges: \n");
1420 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1422 QUIT
; /* allow user to bail out with ^C */
1423 sprintf_vma (tmp2
, list
->list
[i
].start
);
1426 printf_filtered ("(%d, %s, %ld)\n",
1429 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1431 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1433 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1439 sprintf (end
, "M%X,%s,%lX",
1442 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1444 count
+= strlen (end
);
1448 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1450 QUIT
; /* allow user to bail out with ^C */
1451 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1453 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1458 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1459 end
+= 10; /* 'X' + 8 hex digits + ',' */
1462 end
= mem2hex (list
->aexpr_list
[i
]->buf
, end
, list
->aexpr_list
[i
]->len
);
1463 count
+= 2 * list
->aexpr_list
[i
]->len
;
1468 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1473 (*str_list
)[ndx
] = NULL
;
1482 free_actions_list_cleanup_wrapper (al
)
1485 free_actions_list (al
);
1489 free_actions_list (actions_list
)
1490 char **actions_list
;
1494 if (actions_list
== 0)
1497 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1498 free (actions_list
[ndx
]);
1500 free (actions_list
);
1503 /* render all actions into gdb protocol */
1505 encode_actions (t
, tdp_actions
, stepping_actions
)
1506 struct tracepoint
*t
;
1507 char ***tdp_actions
;
1508 char ***stepping_actions
;
1510 static char tdp_buff
[2048], step_buff
[2048];
1512 struct expression
*exp
= NULL
;
1513 struct action_line
*action
;
1516 struct collection_list
*collect
;
1517 struct cmd_list_element
*cmd
;
1518 struct agent_expr
*aexpr
;
1519 long frame_reg
, frame_offset
;
1522 clear_collection_list (&tracepoint_list
);
1523 clear_collection_list (&stepping_list
);
1524 collect
= &tracepoint_list
;
1526 *tdp_actions
= NULL
;
1527 *stepping_actions
= NULL
;
1529 TARGET_VIRTUAL_FRAME_POINTER (t
->address
, &frame_reg
, &frame_offset
);
1531 for (action
= t
->actions
; action
; action
= action
->next
)
1533 QUIT
; /* allow user to bail out with ^C */
1534 action_exp
= action
->action
;
1535 while (isspace ((int) *action_exp
))
1538 if (*action_exp
== '#') /* comment line */
1541 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1543 error ("Bad action list item: %s", action_exp
);
1545 if (cmd
->function
.cfunc
== collect_pseudocommand
)
1548 { /* repeat over a comma-separated list */
1549 QUIT
; /* allow user to bail out with ^C */
1550 while (isspace ((int) *action_exp
))
1553 if (0 == strncasecmp ("$reg", action_exp
, 4))
1555 for (i
= 0; i
< NUM_REGS
; i
++)
1556 add_register (collect
, i
);
1557 action_exp
= strchr (action_exp
, ','); /* more? */
1559 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1561 add_local_symbols (collect
,
1566 action_exp
= strchr (action_exp
, ','); /* more? */
1568 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1570 add_local_symbols (collect
,
1575 action_exp
= strchr (action_exp
, ','); /* more? */
1579 unsigned long addr
, len
;
1580 struct cleanup
*old_chain
= NULL
;
1581 struct cleanup
*old_chain1
= NULL
;
1582 struct agent_reqs areqs
;
1584 exp
= parse_exp_1 (&action_exp
, block_for_pc (t
->address
), 1);
1585 old_chain
= make_cleanup ((make_cleanup_func
)
1586 free_current_contents
, &exp
);
1588 switch (exp
->elts
[0].opcode
)
1591 i
= exp
->elts
[1].longconst
;
1593 printf_filtered ("OP_REGISTER: ");
1594 add_register (collect
, i
);
1598 /* safe because we know it's a simple expression */
1599 tempval
= evaluate_expression (exp
);
1600 addr
= VALUE_ADDRESS (tempval
) + VALUE_OFFSET (tempval
);
1601 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1602 add_memrange (collect
, -1, addr
, len
);
1606 collect_symbol (collect
,
1607 exp
->elts
[2].symbol
,
1612 default: /* full-fledged expression */
1613 aexpr
= gen_trace_for_expr (t
->address
, exp
);
1615 old_chain1
= make_cleanup ((make_cleanup_func
)
1616 free_agent_expr
, aexpr
);
1618 ax_reqs (aexpr
, &areqs
);
1619 if (areqs
.flaw
!= agent_flaw_none
)
1620 error ("malformed expression");
1622 if (areqs
.min_height
< 0)
1623 error ("gdb: Internal error: expression has min height < 0");
1624 if (areqs
.max_height
> 20)
1625 error ("expression too complicated, try simplifying");
1627 discard_cleanups (old_chain1
);
1628 add_aexpr (collect
, aexpr
);
1630 /* take care of the registers */
1631 if (areqs
.reg_mask_len
> 0)
1636 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1638 QUIT
; /* allow user to bail out with ^C */
1639 if (areqs
.reg_mask
[ndx1
] != 0)
1641 /* assume chars have 8 bits */
1642 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1643 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1644 /* it's used -- record it */
1645 add_register (collect
, ndx1
* 8 + ndx2
);
1651 do_cleanups (old_chain
);
1654 while (action_exp
&& *action_exp
++ == ',');
1656 else if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
1658 collect
= &stepping_list
;
1660 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
1662 if (collect
== &stepping_list
) /* end stepping actions */
1663 collect
= &tracepoint_list
;
1665 break; /* end tracepoint actions */
1668 memrange_sortmerge (&tracepoint_list
);
1669 memrange_sortmerge (&stepping_list
);
1671 *tdp_actions
= stringify_collection_list (&tracepoint_list
, &tdp_buff
);
1672 *stepping_actions
= stringify_collection_list (&stepping_list
, &step_buff
);
1676 add_aexpr (collect
, aexpr
)
1677 struct collection_list
*collect
;
1678 struct agent_expr
*aexpr
;
1680 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1682 collect
->aexpr_list
=
1683 xrealloc (collect
->aexpr_list
,
1684 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1685 collect
->aexpr_listsize
*= 2;
1687 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1688 collect
->next_aexpr_elt
++;
1691 static char target_buf
[2048];
1693 /* Set "transparent" memory ranges
1695 Allow trace mechanism to treat text-like sections
1696 (and perhaps all read-only sections) transparently,
1697 i.e. don't reject memory requests from these address ranges
1698 just because they haven't been collected. */
1701 remote_set_transparent_ranges (void)
1703 extern bfd
*exec_bfd
;
1710 return; /* no information to give. */
1712 strcpy (target_buf
, "QTro");
1713 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1715 char tmp1
[40], tmp2
[40];
1717 if ((s
->flags
& SEC_LOAD
) == 0 ||
1718 /* (s->flags & SEC_CODE) == 0 || */
1719 (s
->flags
& SEC_READONLY
) == 0)
1724 size
= bfd_get_section_size_before_reloc (s
);
1725 sprintf_vma (tmp1
, lma
);
1726 sprintf_vma (tmp2
, lma
+ size
);
1727 sprintf (target_buf
+ strlen (target_buf
),
1728 ":%s,%s", tmp1
, tmp2
);
1732 putpkt (target_buf
);
1733 getpkt (target_buf
, 0);
1739 Tell target to clear any previous trace experiment.
1740 Walk the list of tracepoints, and send them (and their actions)
1741 to the target. If no errors,
1742 Tell target to start a new trace experiment. */
1745 trace_start_command (args
, from_tty
)
1748 { /* STUB_COMM MOSTLY_IMPLEMENTED */
1749 struct tracepoint
*t
;
1752 char **stepping_actions
;
1754 struct cleanup
*old_chain
= NULL
;
1756 dont_repeat (); /* like "run", dangerous to repeat accidentally */
1758 if (target_is_remote ())
1761 remote_get_noisy_reply (target_buf
);
1762 if (strcmp (target_buf
, "OK"))
1763 error ("Target does not support this command.");
1769 sprintf_vma (tmp
, t
->address
);
1770 sprintf (buf
, "QTDP:%x:%s:%c:%x:%x", t
->number
, tmp
, /* address */
1771 t
->enabled
== enabled
? 'E' : 'D',
1772 t
->step_count
, t
->pass_count
);
1777 remote_get_noisy_reply (target_buf
);
1778 if (strcmp (target_buf
, "OK"))
1779 error ("Target does not support tracepoints.");
1783 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1784 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1786 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
1789 /* do_single_steps (t); */
1792 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1794 QUIT
; /* allow user to bail out with ^C */
1795 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1796 t
->number
, tmp
, /* address */
1798 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1801 remote_get_noisy_reply (target_buf
);
1802 if (strcmp (target_buf
, "OK"))
1803 error ("Error on target while setting tracepoints.");
1806 if (stepping_actions
)
1808 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1810 QUIT
; /* allow user to bail out with ^C */
1811 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1812 t
->number
, tmp
, /* address */
1813 ((ndx
== 0) ? "S" : ""),
1814 stepping_actions
[ndx
],
1815 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1817 remote_get_noisy_reply (target_buf
);
1818 if (strcmp (target_buf
, "OK"))
1819 error ("Error on target while setting tracepoints.");
1823 do_cleanups (old_chain
);
1826 /* Tell target to treat text-like sections as transparent */
1827 remote_set_transparent_ranges ();
1828 /* Now insert traps and begin collecting data */
1830 remote_get_noisy_reply (target_buf
);
1831 if (strcmp (target_buf
, "OK"))
1832 error ("Bogus reply from target: %s", target_buf
);
1833 set_traceframe_num (-1); /* all old traceframes invalidated */
1834 set_tracepoint_num (-1);
1835 set_traceframe_context (-1);
1836 trace_running_p
= 1;
1837 if (trace_start_stop_hook
)
1838 trace_start_stop_hook (1, from_tty
);
1842 error ("Trace can only be run on remote targets.");
1847 trace_stop_command (args
, from_tty
)
1850 { /* STUB_COMM IS_IMPLEMENTED */
1851 if (target_is_remote ())
1854 remote_get_noisy_reply (target_buf
);
1855 if (strcmp (target_buf
, "OK"))
1856 error ("Bogus reply from target: %s", target_buf
);
1857 trace_running_p
= 0;
1858 if (trace_start_stop_hook
)
1859 trace_start_stop_hook (0, from_tty
);
1862 error ("Trace can only be run on remote targets.");
1865 unsigned long trace_running_p
;
1867 /* tstatus command */
1869 trace_status_command (args
, from_tty
)
1872 { /* STUB_COMM IS_IMPLEMENTED */
1873 if (target_is_remote ())
1875 putpkt ("qTStatus");
1876 remote_get_noisy_reply (target_buf
);
1878 if (target_buf
[0] != 'T' ||
1879 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1880 error ("Bogus reply from target: %s", target_buf
);
1882 /* exported for use by the GUI */
1883 trace_running_p
= (target_buf
[1] == '1');
1886 error ("Trace can only be run on remote targets.");
1889 /* Worker function for the various flavors of the tfind command */
1891 finish_tfind_command (msg
, from_tty
)
1895 int target_frameno
= -1, target_tracept
= -1;
1896 CORE_ADDR old_frame_addr
;
1897 struct symbol
*old_func
;
1900 old_frame_addr
= FRAME_FP (get_current_frame ());
1901 old_func
= find_pc_function (read_pc ());
1904 reply
= remote_get_noisy_reply (msg
);
1906 while (reply
&& *reply
)
1910 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1912 /* A request for a non-existant trace frame has failed.
1913 Our response will be different, depending on FROM_TTY:
1915 If FROM_TTY is true, meaning that this command was
1916 typed interactively by the user, then give an error
1917 and DO NOT change the state of traceframe_number etc.
1919 However if FROM_TTY is false, meaning that we're either
1920 in a script, a loop, or a user-defined command, then
1921 DON'T give an error, but DO change the state of
1922 traceframe_number etc. to invalid.
1924 The rationalle is that if you typed the command, you
1925 might just have committed a typo or something, and you'd
1926 like to NOT lose your current debugging state. However
1927 if you're in a user-defined command or especially in a
1928 loop, then you need a way to detect that the command
1929 failed WITHOUT aborting. This allows you to write
1930 scripts that search thru the trace buffer until the end,
1931 and then continue on to do something else. */
1934 error ("Target failed to find requested trace frame.");
1938 printf_filtered ("End of trace buffer.\n");
1939 /* The following will not recurse, since it's special-cased */
1940 trace_find_command ("-1", from_tty
);
1941 reply
= NULL
; /* break out of loop,
1942 (avoid recursive nonsense) */
1947 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1948 error ("Target failed to find requested trace frame.");
1950 case 'O': /* "OK"? */
1951 if (reply
[1] == 'K' && reply
[2] == '\0')
1954 error ("Bogus reply from target: %s", reply
);
1957 error ("Bogus reply from target: %s", reply
);
1960 flush_cached_frames ();
1961 registers_changed ();
1962 select_frame (get_current_frame (), 0);
1963 set_traceframe_num (target_frameno
);
1964 set_tracepoint_num (target_tracept
);
1965 if (target_frameno
== -1)
1966 set_traceframe_context (-1);
1968 set_traceframe_context (read_pc ());
1974 /* NOTE: in immitation of the step command, try to determine
1975 whether we have made a transition from one function to another.
1976 If so, we'll print the "stack frame" (ie. the new function and
1977 it's arguments) -- otherwise we'll just show the new source line.
1979 This determination is made by checking (1) whether the current
1980 function has changed, and (2) whether the current FP has changed.
1981 Hack: if the FP wasn't collected, either at the current or the
1982 previous frame, assume that the FP has NOT changed. */
1984 if (old_func
== find_pc_function (read_pc ()) &&
1985 (old_frame_addr
== 0 ||
1986 FRAME_FP (get_current_frame ()) == 0 ||
1987 old_frame_addr
== FRAME_FP (get_current_frame ())))
1992 print_stack_frame (selected_frame
, selected_frame_level
, source_only
);
1997 /* trace_find_command takes a trace frame number n,
1998 sends "QTFrame:<n>" to the target,
1999 and accepts a reply that may contain several optional pieces
2000 of information: a frame number, a tracepoint number, and an
2001 indication of whether this is a trap frame or a stepping frame.
2003 The minimal response is just "OK" (which indicates that the
2004 target does not give us a frame number or a tracepoint number).
2005 Instead of that, the target may send us a string containing
2007 F<hexnum> (gives the selected frame number)
2008 T<hexnum> (gives the selected tracepoint number)
2013 trace_find_command (args
, from_tty
)
2016 { /* STUB_COMM PART_IMPLEMENTED */
2017 /* this should only be called with a numeric argument */
2020 if (target_is_remote ())
2022 if (trace_find_hook
)
2023 trace_find_hook (args
, from_tty
);
2025 if (args
== 0 || *args
== 0)
2026 { /* TFIND with no args means find NEXT trace frame. */
2027 if (traceframe_number
== -1)
2028 frameno
= 0; /* "next" is first one */
2030 frameno
= traceframe_number
+ 1;
2032 else if (0 == strcmp (args
, "-"))
2034 if (traceframe_number
== -1)
2035 error ("not debugging trace buffer");
2036 else if (from_tty
&& traceframe_number
== 0)
2037 error ("already at start of trace buffer");
2039 frameno
= traceframe_number
- 1;
2042 frameno
= parse_and_eval_address (args
);
2045 error ("invalid input (%d is less than zero)", frameno
);
2047 sprintf (target_buf
, "QTFrame:%x", frameno
);
2048 finish_tfind_command (target_buf
, from_tty
);
2051 error ("Trace can only be run on remote targets.");
2056 trace_find_end_command (args
, from_tty
)
2060 trace_find_command ("-1", from_tty
);
2065 trace_find_none_command (args
, from_tty
)
2069 trace_find_command ("-1", from_tty
);
2074 trace_find_start_command (args
, from_tty
)
2078 trace_find_command ("0", from_tty
);
2081 /* tfind pc command */
2083 trace_find_pc_command (args
, from_tty
)
2086 { /* STUB_COMM PART_IMPLEMENTED */
2090 if (target_is_remote ())
2092 if (args
== 0 || *args
== 0)
2093 pc
= read_pc (); /* default is current pc */
2095 pc
= parse_and_eval_address (args
);
2097 sprintf_vma (tmp
, pc
);
2098 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
2099 finish_tfind_command (target_buf
, from_tty
);
2102 error ("Trace can only be run on remote targets.");
2105 /* tfind tracepoint command */
2107 trace_find_tracepoint_command (args
, from_tty
)
2110 { /* STUB_COMM PART_IMPLEMENTED */
2113 if (target_is_remote ())
2115 if (args
== 0 || *args
== 0)
2116 if (tracepoint_number
== -1)
2117 error ("No current tracepoint -- please supply an argument.");
2119 tdp
= tracepoint_number
; /* default is current TDP */
2121 tdp
= parse_and_eval_address (args
);
2123 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
2124 finish_tfind_command (target_buf
, from_tty
);
2127 error ("Trace can only be run on remote targets.");
2130 /* TFIND LINE command:
2132 This command will take a sourceline for argument, just like BREAK
2133 or TRACE (ie. anything that "decode_line_1" can handle).
2135 With no argument, this command will find the next trace frame
2136 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2139 trace_find_line_command (args
, from_tty
)
2142 { /* STUB_COMM PART_IMPLEMENTED */
2143 static CORE_ADDR start_pc
, end_pc
;
2144 struct symtabs_and_lines sals
;
2145 struct symtab_and_line sal
;
2146 struct cleanup
*old_chain
;
2147 char startpc_str
[40], endpc_str
[40];
2149 if (target_is_remote ())
2151 if (args
== 0 || *args
== 0)
2153 sal
= find_pc_line ((get_current_frame ())->pc
, 0);
2155 sals
.sals
= (struct symtab_and_line
*)
2156 xmalloc (sizeof (struct symtab_and_line
));
2161 sals
= decode_line_spec (args
, 1);
2165 old_chain
= make_cleanup (free
, sals
.sals
);
2166 if (sal
.symtab
== 0)
2168 printf_filtered ("TFIND: No line number information available");
2171 /* This is useful for "info line *0x7f34". If we can't tell the
2172 user about a source line, at least let them have the symbolic
2174 printf_filtered (" for address ");
2176 print_address (sal
.pc
, gdb_stdout
);
2177 printf_filtered (";\n -- will attempt to find by PC. \n");
2181 printf_filtered (".\n");
2182 return; /* no line, no PC; what can we do? */
2185 else if (sal
.line
> 0
2186 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2188 if (start_pc
== end_pc
)
2190 printf_filtered ("Line %d of \"%s\"",
2191 sal
.line
, sal
.symtab
->filename
);
2193 printf_filtered (" is at address ");
2194 print_address (start_pc
, gdb_stdout
);
2196 printf_filtered (" but contains no code.\n");
2197 sal
= find_pc_line (start_pc
, 0);
2199 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
2201 printf_filtered ("Attempting to find line %d instead.\n",
2204 error ("Cannot find a good line.");
2208 /* Is there any case in which we get here, and have an address
2209 which the user would want to see? If we have debugging symbols
2210 and no line numbers? */
2211 error ("Line number %d is out of range for \"%s\".\n",
2212 sal
.line
, sal
.symtab
->filename
);
2214 sprintf_vma (startpc_str
, start_pc
);
2215 sprintf_vma (endpc_str
, end_pc
- 1);
2216 if (args
&& *args
) /* find within range of stated line */
2217 sprintf (target_buf
, "QTFrame:range:%s:%s", startpc_str
, endpc_str
);
2218 else /* find OUTSIDE OF range of CURRENT line */
2219 sprintf (target_buf
, "QTFrame:outside:%s:%s", startpc_str
, endpc_str
);
2220 finish_tfind_command (target_buf
, from_tty
);
2221 do_cleanups (old_chain
);
2224 error ("Trace can only be run on remote targets.");
2227 /* tfind range command */
2229 trace_find_range_command (args
, from_tty
)
2233 static CORE_ADDR start
, stop
;
2234 char start_str
[40], stop_str
[40];
2237 if (target_is_remote ())
2239 if (args
== 0 || *args
== 0)
2240 { /* XXX FIXME: what should default behavior be? */
2241 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2245 if (0 != (tmp
= strchr (args
, ',')))
2247 *tmp
++ = '\0'; /* terminate start address */
2248 while (isspace ((int) *tmp
))
2250 start
= parse_and_eval_address (args
);
2251 stop
= parse_and_eval_address (tmp
);
2254 { /* no explicit end address? */
2255 start
= parse_and_eval_address (args
);
2256 stop
= start
+ 1; /* ??? */
2259 sprintf_vma (start_str
, start
);
2260 sprintf_vma (stop_str
, stop
);
2261 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
2262 finish_tfind_command (target_buf
, from_tty
);
2265 error ("Trace can only be run on remote targets.");
2268 /* tfind outside command */
2270 trace_find_outside_command (args
, from_tty
)
2274 CORE_ADDR start
, stop
;
2275 char start_str
[40], stop_str
[40];
2278 if (target_is_remote ())
2280 if (args
== 0 || *args
== 0)
2281 { /* XXX FIXME: what should default behavior be? */
2282 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2286 if (0 != (tmp
= strchr (args
, ',')))
2288 *tmp
++ = '\0'; /* terminate start address */
2289 while (isspace ((int) *tmp
))
2291 start
= parse_and_eval_address (args
);
2292 stop
= parse_and_eval_address (tmp
);
2295 { /* no explicit end address? */
2296 start
= parse_and_eval_address (args
);
2297 stop
= start
+ 1; /* ??? */
2300 sprintf_vma (start_str
, start
);
2301 sprintf_vma (stop_str
, stop
);
2302 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
2303 finish_tfind_command (target_buf
, from_tty
);
2306 error ("Trace can only be run on remote targets.");
2309 /* save-tracepoints command */
2311 tracepoint_save_command (args
, from_tty
)
2315 struct tracepoint
*tp
;
2316 struct action_line
*line
;
2318 char *i1
= " ", *i2
= " ";
2319 char *indent
, *actionline
;
2322 if (args
== 0 || *args
== 0)
2323 error ("Argument required (file name in which to save tracepoints");
2325 if (tracepoint_chain
== 0)
2327 warning ("save-tracepoints: no tracepoints to save.\n");
2331 if (!(fp
= fopen (args
, "w")))
2332 error ("Unable to open file '%s' for saving tracepoints");
2334 ALL_TRACEPOINTS (tp
)
2336 if (tp
->addr_string
)
2337 fprintf (fp
, "trace %s\n", tp
->addr_string
);
2340 sprintf_vma (tmp
, tp
->address
);
2341 fprintf (fp
, "trace *0x%s\n", tmp
);
2345 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
2349 fprintf (fp
, " actions\n");
2351 for (line
= tp
->actions
; line
; line
= line
->next
)
2353 struct cmd_list_element
*cmd
;
2355 QUIT
; /* allow user to bail out with ^C */
2356 actionline
= line
->action
;
2357 while (isspace ((int) *actionline
))
2360 fprintf (fp
, "%s%s\n", indent
, actionline
);
2361 if (*actionline
!= '#') /* skip for comment lines */
2363 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
2365 error ("Bad action list item: %s", actionline
);
2366 if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
2368 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
2376 printf_filtered ("Tracepoints saved to file '%s'.\n", args
);
2380 /* info scope command: list the locals for a scope. */
2382 scope_info (args
, from_tty
)
2386 struct symtabs_and_lines sals
;
2388 struct minimal_symbol
*msym
;
2389 struct block
*block
;
2390 char **canonical
, *symname
, *save_args
= args
;
2391 int i
, j
, nsyms
, count
= 0;
2393 if (args
== 0 || *args
== 0)
2394 error ("requires an argument (function, line or *addr) to define a scope");
2396 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2397 if (sals
.nelts
== 0)
2398 return; /* presumably decode_line_1 has already warned */
2400 /* Resolve line numbers to PC */
2401 resolve_sal_pc (&sals
.sals
[0]);
2402 block
= block_for_pc (sals
.sals
[0].pc
);
2406 QUIT
; /* allow user to bail out with ^C */
2407 nsyms
= BLOCK_NSYMS (block
);
2408 for (i
= 0; i
< nsyms
; i
++)
2410 QUIT
; /* allow user to bail out with ^C */
2412 printf_filtered ("Scope for %s:\n", save_args
);
2414 sym
= BLOCK_SYM (block
, i
);
2415 symname
= SYMBOL_NAME (sym
);
2416 if (symname
== NULL
|| *symname
== '\0')
2417 continue; /* probably botched, certainly useless */
2419 printf_filtered ("Symbol %s is ", symname
);
2420 switch (SYMBOL_CLASS (sym
))
2423 case LOC_UNDEF
: /* messed up symbol? */
2424 printf_filtered ("a bogus symbol, class %d.\n",
2425 SYMBOL_CLASS (sym
));
2426 count
--; /* don't count this one */
2429 printf_filtered ("a constant with value %ld (0x%lx)",
2430 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2432 case LOC_CONST_BYTES
:
2433 printf_filtered ("constant bytes: ");
2434 if (SYMBOL_TYPE (sym
))
2435 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2436 fprintf_filtered (gdb_stdout
, " %02x",
2437 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2440 printf_filtered ("in static storage at address ");
2441 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2444 printf_filtered ("a local variable in register $%s",
2445 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2449 printf_filtered ("an argument at stack/frame offset %ld",
2450 SYMBOL_VALUE (sym
));
2453 printf_filtered ("a local variable at frame offset %ld",
2454 SYMBOL_VALUE (sym
));
2457 printf_filtered ("a reference argument at offset %ld",
2458 SYMBOL_VALUE (sym
));
2461 printf_filtered ("an argument in register $%s",
2462 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2464 case LOC_REGPARM_ADDR
:
2465 printf_filtered ("the address of an argument, in register $%s",
2466 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2469 printf_filtered ("a typedef.\n");
2472 printf_filtered ("a label at address ");
2473 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2476 printf_filtered ("a function at address ");
2477 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)), 1,
2481 printf_filtered ("a variable at offset %ld from register $%s",
2483 REGISTER_NAME (SYMBOL_BASEREG (sym
)));
2485 case LOC_BASEREG_ARG
:
2486 printf_filtered ("an argument at offset %ld from register $%s",
2488 REGISTER_NAME (SYMBOL_BASEREG (sym
)));
2490 case LOC_UNRESOLVED
:
2491 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
2493 printf_filtered ("Unresolved Static");
2496 printf_filtered ("static storage at address ");
2497 print_address_numeric (SYMBOL_VALUE_ADDRESS (msym
), 1,
2501 case LOC_OPTIMIZED_OUT
:
2502 printf_filtered ("optimized out.\n");
2505 if (SYMBOL_TYPE (sym
))
2506 printf_filtered (", length %d.\n",
2507 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2509 if (BLOCK_FUNCTION (block
))
2512 block
= BLOCK_SUPERBLOCK (block
);
2515 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2519 /* worker function (cleanup) */
2521 replace_comma (comma
)
2529 trace_dump_command (args
, from_tty
)
2533 struct tracepoint
*t
;
2534 struct action_line
*action
;
2535 char *action_exp
, *next_comma
;
2536 struct cleanup
*old_cleanups
;
2537 int stepping_actions
= 0;
2538 int stepping_frame
= 0;
2540 if (!target_is_remote ())
2542 error ("Trace can only be run on remote targets.");
2546 if (tracepoint_number
== -1)
2548 warning ("No current trace frame.");
2553 if (t
->number
== tracepoint_number
)
2557 error ("No known tracepoint matches 'current' tracepoint #%d.",
2560 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2562 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2563 tracepoint_number
, traceframe_number
);
2565 /* The current frame is a trap frame if the frame PC is equal
2566 to the tracepoint PC. If not, then the current frame was
2567 collected during single-stepping. */
2569 stepping_frame
= (t
->address
!= read_pc ());
2571 for (action
= t
->actions
; action
; action
= action
->next
)
2573 struct cmd_list_element
*cmd
;
2575 QUIT
; /* allow user to bail out with ^C */
2576 action_exp
= action
->action
;
2577 while (isspace ((int) *action_exp
))
2580 /* The collection actions to be done while stepping are
2581 bracketed by the commands "while-stepping" and "end". */
2583 if (*action_exp
== '#') /* comment line */
2586 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2588 error ("Bad action list item: %s", action_exp
);
2590 if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
2591 stepping_actions
= 1;
2592 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
2593 stepping_actions
= 0;
2594 else if (cmd
->function
.cfunc
== collect_pseudocommand
)
2596 /* Display the collected data.
2597 For the trap frame, display only what was collected at the trap.
2598 Likewise for stepping frames, display only what was collected
2599 while stepping. This means that the two boolean variables,
2600 STEPPING_FRAME and STEPPING_ACTIONS should be equal. */
2601 if (stepping_frame
== stepping_actions
)
2604 { /* repeat over a comma-separated list */
2605 QUIT
; /* allow user to bail out with ^C */
2606 if (*action_exp
== ',')
2608 while (isspace ((int) *action_exp
))
2611 next_comma
= strchr (action_exp
, ',');
2613 if (0 == strncasecmp (action_exp
, "$reg", 4))
2614 registers_info (NULL
, from_tty
);
2615 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2616 locals_info (NULL
, from_tty
);
2617 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2618 args_info (NULL
, from_tty
);
2623 make_cleanup (replace_comma
, next_comma
);
2626 printf_filtered ("%s = ", action_exp
);
2627 output_command (action_exp
, from_tty
);
2628 printf_filtered ("\n");
2632 action_exp
= next_comma
;
2634 while (action_exp
&& *action_exp
== ',');
2638 discard_cleanups (old_cleanups
);
2641 /* Convert the memory pointed to by mem into hex, placing result in buf.
2642 * Return a pointer to the last char put in buf (null)
2643 * "stolen" from sparc-stub.c
2646 static const char hexchars
[] = "0123456789abcdef";
2648 static unsigned char *
2649 mem2hex (mem
, buf
, count
)
2660 *buf
++ = hexchars
[ch
>> 4];
2661 *buf
++ = hexchars
[ch
& 0xf];
2670 get_traceframe_number ()
2672 return traceframe_number
;
2676 /* module initialization */
2678 _initialize_tracepoint ()
2680 tracepoint_chain
= 0;
2681 tracepoint_count
= 0;
2682 traceframe_number
= -1;
2683 tracepoint_number
= -1;
2685 set_internalvar (lookup_internalvar ("tpnum"),
2686 value_from_longest (builtin_type_int
, (LONGEST
) 0));
2687 set_internalvar (lookup_internalvar ("trace_frame"),
2688 value_from_longest (builtin_type_int
, (LONGEST
) - 1));
2690 if (tracepoint_list
.list
== NULL
)
2692 tracepoint_list
.listsize
= 128;
2693 tracepoint_list
.list
= xmalloc
2694 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2696 if (tracepoint_list
.aexpr_list
== NULL
)
2698 tracepoint_list
.aexpr_listsize
= 128;
2699 tracepoint_list
.aexpr_list
= xmalloc
2700 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2703 if (stepping_list
.list
== NULL
)
2705 stepping_list
.listsize
= 128;
2706 stepping_list
.list
= xmalloc
2707 (stepping_list
.listsize
* sizeof (struct memrange
));
2710 if (stepping_list
.aexpr_list
== NULL
)
2712 stepping_list
.aexpr_listsize
= 128;
2713 stepping_list
.aexpr_list
= xmalloc
2714 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2717 add_info ("scope", scope_info
,
2718 "List the variables local to a scope");
2720 add_cmd ("tracepoints", class_trace
, NO_FUNCTION
,
2721 "Tracing of program execution without stopping the program.",
2724 add_info ("tracepoints", tracepoints_info
,
2725 "Status of tracepoints, or tracepoint number NUMBER.\n\
2726 Convenience variable \"$tpnum\" contains the number of the\n\
2727 last tracepoint set.");
2729 add_info_alias ("tp", "tracepoints", 1);
2731 add_com ("save-tracepoints", class_trace
, tracepoint_save_command
,
2732 "Save current tracepoint definitions as a script.\n\
2733 Use the 'source' command in another debug session to restore them.");
2735 add_com ("tdump", class_trace
, trace_dump_command
,
2736 "Print everything collected at the current tracepoint.");
2738 add_prefix_cmd ("tfind", class_trace
, trace_find_command
,
2739 "Select a trace frame;\n\
2740 No argument means forward by one frame; '-' meand backward by one frame.",
2741 &tfindlist
, "tfind ", 1, &cmdlist
);
2743 add_cmd ("outside", class_trace
, trace_find_outside_command
,
2744 "Select a trace frame whose PC is outside the given \
2745 range.\nUsage: tfind outside addr1, addr2",
2748 add_cmd ("range", class_trace
, trace_find_range_command
,
2749 "Select a trace frame whose PC is in the given range.\n\
2750 Usage: tfind range addr1,addr2",
2753 add_cmd ("line", class_trace
, trace_find_line_command
,
2754 "Select a trace frame by source line.\n\
2755 Argument can be a line number (with optional source file), \n\
2756 a function name, or '*' followed by an address.\n\
2757 Default argument is 'the next source line that was traced'.",
2760 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
,
2761 "Select a trace frame by tracepoint number.\n\
2762 Default is the tracepoint for the current trace frame.",
2765 add_cmd ("pc", class_trace
, trace_find_pc_command
,
2766 "Select a trace frame by PC.\n\
2767 Default is the current PC, or the PC of the current trace frame.",
2770 add_cmd ("end", class_trace
, trace_find_end_command
,
2771 "Synonym for 'none'.\n\
2772 De-select any trace frame and resume 'live' debugging.",
2775 add_cmd ("none", class_trace
, trace_find_none_command
,
2776 "De-select any trace frame and resume 'live' debugging.",
2779 add_cmd ("start", class_trace
, trace_find_start_command
,
2780 "Select the first trace frame in the trace buffer.",
2783 add_com ("tstatus", class_trace
, trace_status_command
,
2784 "Display the status of the current trace data collection.");
2786 add_com ("tstop", class_trace
, trace_stop_command
,
2787 "Stop trace data collection.");
2789 add_com ("tstart", class_trace
, trace_start_command
,
2790 "Start trace data collection.");
2792 add_com ("passcount", class_trace
, trace_pass_command
,
2793 "Set the passcount for a tracepoint.\n\
2794 The trace will end when the tracepoint has been passed 'count' times.\n\
2795 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
2796 if TPNUM is omitted, passcount refers to the last tracepoint defined.");
2798 add_com ("end", class_trace
, end_actions_pseudocommand
,
2799 "Ends a list of commands or actions.\n\
2800 Several GDB commands allow you to enter a list of commands or actions.\n\
2801 Entering \"end\" on a line by itself is the normal way to terminate\n\
2803 Note: the \"end\" command cannot be used at the gdb prompt.");
2805 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
,
2806 "Specify single-stepping behavior at a tracepoint.\n\
2807 Argument is number of instructions to trace in single-step mode\n\
2808 following the tracepoint. This command is normally followed by\n\
2809 one or more \"collect\" commands, to specify what to collect\n\
2810 while single-stepping.\n\n\
2811 Note: this command can only be used in a tracepoint \"actions\" list.");
2813 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2814 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2816 add_com ("collect", class_trace
, collect_pseudocommand
,
2817 "Specify one or more data items to be collected at a tracepoint.\n\
2818 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2819 collect all data (variables, registers) referenced by that expression.\n\
2820 Also accepts the following special arguments:\n\
2821 $regs -- all registers.\n\
2822 $args -- all function arguments.\n\
2823 $locals -- all variables local to the block/function scope.\n\
2824 Note: this command can only be used in a tracepoint \"actions\" list.");
2826 add_com ("actions", class_trace
, trace_actions_command
,
2827 "Specify the actions to be taken at a tracepoint.\n\
2828 Tracepoint actions may include collecting of specified data, \n\
2829 single-stepping, or enabling/disabling other tracepoints, \n\
2830 depending on target's capabilities.");
2832 add_cmd ("tracepoints", class_trace
, delete_trace_command
,
2833 "Delete specified tracepoints.\n\
2834 Arguments are tracepoint numbers, separated by spaces.\n\
2835 No argument means delete all tracepoints.",
2838 add_cmd ("tracepoints", class_trace
, disable_trace_command
,
2839 "Disable specified tracepoints.\n\
2840 Arguments are tracepoint numbers, separated by spaces.\n\
2841 No argument means disable all tracepoints.",
2844 add_cmd ("tracepoints", class_trace
, enable_trace_command
,
2845 "Enable specified tracepoints.\n\
2846 Arguments are tracepoint numbers, separated by spaces.\n\
2847 No argument means enable all tracepoints.",
2850 add_com ("trace", class_trace
, trace_command
,
2851 "Set a tracepoint at a specified line or function or address.\n\
2852 Argument may be a line number, function name, or '*' plus an address.\n\
2853 For a line number or function, trace at the start of its code.\n\
2854 If an address is specified, trace at that exact address.\n\n\
2855 Do \"help tracepoints\" for info on other tracepoint commands.");
2857 add_com_alias ("tp", "trace", class_alias
, 0);
2858 add_com_alias ("tr", "trace", class_alias
, 1);
2859 add_com_alias ("tra", "trace", class_alias
, 1);
2860 add_com_alias ("trac", "trace", class_alias
, 1);