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
;
559 if (t
== NULL
) /* no tracepoint operand */
565 t
->enabled
= enabled
;
566 if (modify_tracepoint_hook
)
567 modify_tracepoint_hook (t
);
570 t
->enabled
= disabled
;
571 if (modify_tracepoint_hook
)
572 modify_tracepoint_hook (t
);
575 if (tracepoint_chain
== t
)
576 tracepoint_chain
= t
->next
;
585 /* Let the UI know of any deletions */
586 if (delete_tracepoint_hook
)
587 delete_tracepoint_hook (t
);
590 free (t
->addr_string
);
592 free (t
->source_file
);
601 /* Utility: parse a tracepoint number and look it up in the list.
602 If MULTI_P is true, there might be a range of tracepoints in ARG. */
604 get_tracepoint_by_number (arg
, multi_p
)
608 struct tracepoint
*t
;
609 char *instring
= *arg
;
613 error_no_arg ("tracepoint number");
615 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
618 printf_filtered ("bad tracepoint number at or near '%s'\n", instring
);
623 if (t
->number
== tpnum
)
628 /* FIXME: if we are in the middle of a range we don't want to give
629 a message. The current interface to get_number_or_range doesn't
630 allow us to discover this. */
631 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
635 /* Utility: parse a list of tracepoint numbers, and call a func for each. */
637 map_args_over_tracepoints (args
, from_tty
, opcode
)
640 enum tracepoint_opcode opcode
;
642 struct tracepoint
*t
, *tmp
;
644 if (args
== 0 || *args
== 0) /* do them all */
645 ALL_TRACEPOINTS_SAFE (t
, tmp
)
646 tracepoint_operation (t
, from_tty
, opcode
);
650 QUIT
; /* give user option to bail out with ^C */
651 t
= get_tracepoint_by_number (&args
, 1);
652 tracepoint_operation (t
, from_tty
, opcode
);
653 while (*args
== ' ' || *args
== '\t')
658 /* The 'enable trace' command enables tracepoints. Not supported by all targets. */
660 enable_trace_command (args
, from_tty
)
665 map_args_over_tracepoints (args
, from_tty
, enable_op
);
668 /* The 'disable trace' command enables tracepoints. Not supported by all targets. */
670 disable_trace_command (args
, from_tty
)
675 map_args_over_tracepoints (args
, from_tty
, disable_op
);
678 /* Remove a tracepoint (or all if no argument) */
680 delete_trace_command (args
, from_tty
)
685 if (!args
|| !*args
) /* No args implies all tracepoints; */
686 if (from_tty
) /* confirm only if from_tty... */
687 if (tracepoint_chain
) /* and if there are tracepoints to delete! */
688 if (!query ("Delete all tracepoints? "))
691 map_args_over_tracepoints (args
, from_tty
, delete_op
);
694 /* Set passcount for tracepoint.
696 First command argument is passcount, second is tracepoint number.
697 If tracepoint number omitted, apply to most recently defined.
698 Also accepts special argument "all". */
701 trace_pass_command (args
, from_tty
)
705 struct tracepoint
*t1
= (struct tracepoint
*) -1, *t2
;
709 if (args
== 0 || *args
== 0)
710 error ("PASS command requires an argument (count + optional TP num)");
712 count
= strtoul (args
, &args
, 10); /* count comes first, then TP num */
714 while (*args
&& isspace ((int) *args
))
717 if (*args
&& strncasecmp (args
, "all", 3) == 0)
719 args
+= 3; /* skip special argument "all" */
722 error ("Junk at end of arguments.");
725 t1
= get_tracepoint_by_number (&args
, 1);
732 if (t1
== (struct tracepoint
*) -1 || t1
== t2
)
734 t2
->pass_count
= count
;
735 if (modify_tracepoint_hook
)
736 modify_tracepoint_hook (t2
);
738 printf_filtered ("Setting tracepoint %d's passcount to %d\n",
743 t1
= get_tracepoint_by_number (&args
, 1);
748 /* ACTIONS functions: */
750 /* Prototypes for action-parsing utility commands */
751 static void read_actions
PARAMS ((struct tracepoint
*));
753 /* The three functions:
754 collect_pseudocommand,
755 while_stepping_pseudocommand, and
756 end_actions_pseudocommand
757 are placeholders for "commands" that are actually ONLY to be used
758 within a tracepoint action list. If the actual function is ever called,
759 it means that somebody issued the "command" at the top level,
760 which is always an error. */
763 end_actions_pseudocommand (args
, from_tty
)
767 error ("This command cannot be used at the top level.");
771 while_stepping_pseudocommand (args
, from_tty
)
775 error ("This command can only be used in a tracepoint actions list.");
779 collect_pseudocommand (args
, from_tty
)
783 error ("This command can only be used in a tracepoint actions list.");
786 /* Enter a list of actions for a tracepoint. */
788 trace_actions_command (args
, from_tty
)
792 struct tracepoint
*t
;
794 char *end_msg
= "End with a line saying just \"end\".";
796 t
= get_tracepoint_by_number (&args
, 0);
799 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
804 if (readline_begin_hook
)
805 (*readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
806 else if (input_from_terminal_p ())
807 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
811 t
->step_count
= 0; /* read_actions may set this */
814 if (readline_end_hook
)
815 (*readline_end_hook
) ();
816 /* tracepoints_changed () */
818 /* else just return */
821 /* worker function */
824 struct tracepoint
*t
;
827 char *prompt1
= "> ", *prompt2
= " > ";
828 char *prompt
= prompt1
;
829 enum actionline_type linetype
;
830 extern FILE *instream
;
831 struct action_line
*next
= NULL
, *temp
;
832 struct cleanup
*old_chain
;
834 /* Control-C quits instantly if typed while in this loop
835 since it should not wait until the user types a newline. */
841 signal (STOP_SIGNAL
, handle_stop_sig
);
843 signal (STOP_SIGNAL
, stop_sig
);
846 old_chain
= make_cleanup ((make_cleanup_func
) free_actions
, (void *) t
);
849 /* Make sure that all output has been output. Some machines may let
850 you get away with leaving out some of the gdb_flush, but not all. */
852 gdb_flush (gdb_stdout
);
853 gdb_flush (gdb_stderr
);
855 if (readline_hook
&& instream
== NULL
)
856 line
= (*readline_hook
) (prompt
);
857 else if (instream
== stdin
&& ISATTY (instream
))
859 line
= readline (prompt
);
860 if (line
&& *line
) /* add it to command history */
864 line
= gdb_readline (0);
866 linetype
= validate_actionline (&line
, t
);
867 if (linetype
== BADLINE
)
868 continue; /* already warned -- collect another line */
870 temp
= xmalloc (sizeof (struct action_line
));
874 if (next
== NULL
) /* first action for this tracepoint? */
875 t
->actions
= next
= temp
;
882 if (linetype
== STEPPING
) /* begin "while-stepping" */
884 if (prompt
== prompt2
)
886 warning ("Already processing 'while-stepping'");
890 prompt
= prompt2
; /* change prompt for stepping actions */
892 else if (linetype
== END
)
894 if (prompt
== prompt2
)
896 prompt
= prompt1
; /* end of single-stepping actions */
899 { /* end of actions */
900 if (t
->actions
->next
== NULL
)
902 /* an "end" all by itself with no other actions means
903 this tracepoint has no actions. Discard empty list. */
912 signal (STOP_SIGNAL
, SIG_DFL
);
915 discard_cleanups (old_chain
);
918 /* worker function */
920 validate_actionline (line
, t
)
922 struct tracepoint
*t
;
924 struct cmd_list_element
*c
;
925 struct expression
*exp
= NULL
;
926 struct cleanup
*old_chain
= NULL
;
929 for (p
= *line
; isspace ((int) *p
);)
932 /* symbol lookup etc. */
933 if (*p
== '\0') /* empty line: just prompt for another line. */
936 if (*p
== '#') /* comment line */
939 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
942 warning ("'%s' is not an action that I know, or is ambiguous.", p
);
946 if (c
->function
.cfunc
== collect_pseudocommand
)
948 struct agent_expr
*aexpr
;
949 struct agent_reqs areqs
;
952 { /* repeat over a comma-separated list */
953 QUIT
; /* allow user to bail out with ^C */
954 while (isspace ((int) *p
))
957 if (*p
== '$') /* look for special pseudo-symbols */
959 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
960 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
961 (0 == strncasecmp ("loc", p
+ 1, 3)))
966 /* else fall thru, treat p as an expression and parse it! */
968 exp
= parse_exp_1 (&p
, block_for_pc (t
->address
), 1);
969 old_chain
= make_cleanup ((make_cleanup_func
) free_current_contents
,
972 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
974 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
976 warning ("constant %s (value %ld) will not be collected.",
977 SYMBOL_NAME (exp
->elts
[2].symbol
),
978 SYMBOL_VALUE (exp
->elts
[2].symbol
));
981 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
983 warning ("%s is optimized away and cannot be collected.",
984 SYMBOL_NAME (exp
->elts
[2].symbol
));
989 /* we have something to collect, make sure that the expr to
990 bytecode translator can handle it and that it's not too long */
991 aexpr
= gen_trace_for_expr (t
->address
, exp
);
992 (void) make_cleanup ((make_cleanup_func
) free_agent_expr
, aexpr
);
994 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
995 error ("expression too complicated, try simplifying");
997 ax_reqs (aexpr
, &areqs
);
998 (void) make_cleanup (free
, areqs
.reg_mask
);
1000 if (areqs
.flaw
!= agent_flaw_none
)
1001 error ("malformed expression");
1003 if (areqs
.min_height
< 0)
1004 error ("gdb: Internal error: expression has min height < 0");
1006 if (areqs
.max_height
> 20)
1007 error ("expression too complicated, try simplifying");
1009 do_cleanups (old_chain
);
1011 while (p
&& *p
++ == ',');
1014 else if (c
->function
.cfunc
== while_stepping_pseudocommand
)
1016 char *steparg
; /* in case warning is necessary */
1018 while (isspace ((int) *p
))
1023 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
1025 warning ("'%s': bad step-count; command ignored.", *line
);
1030 else if (c
->function
.cfunc
== end_actions_pseudocommand
)
1034 warning ("'%s' is not a supported tracepoint action.", *line
);
1039 /* worker function */
1042 struct tracepoint
*t
;
1044 struct action_line
*line
, *next
;
1046 for (line
= t
->actions
; line
; line
= next
)
1050 free (line
->action
);
1058 int type
; /* 0 for absolute memory range, else basereg number */
1059 bfd_signed_vma start
;
1063 struct collection_list
1065 unsigned char regs_mask
[8]; /* room for up to 256 regs */
1068 struct memrange
*list
;
1069 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
1070 long next_aexpr_elt
;
1071 struct agent_expr
**aexpr_list
;
1074 tracepoint_list
, stepping_list
;
1076 /* MEMRANGE functions: */
1078 static int memrange_cmp
PARAMS ((const void *, const void *));
1080 /* compare memranges for qsort */
1082 memrange_cmp (va
, vb
)
1086 const struct memrange
*a
= va
, *b
= vb
;
1088 if (a
->type
< b
->type
)
1090 if (a
->type
> b
->type
)
1094 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
1096 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
1101 if (a
->start
< b
->start
)
1103 if (a
->start
> b
->start
)
1109 /* Sort the memrange list using qsort, and merge adjacent memranges */
1111 memrange_sortmerge (memranges
)
1112 struct collection_list
*memranges
;
1116 qsort (memranges
->list
, memranges
->next_memrange
,
1117 sizeof (struct memrange
), memrange_cmp
);
1118 if (memranges
->next_memrange
> 0)
1120 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
1122 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
1123 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
1124 MAX_REGISTER_VIRTUAL_SIZE
)
1126 /* memrange b starts before memrange a ends; merge them. */
1127 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
1128 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
1129 continue; /* next b, same a */
1133 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
1134 sizeof (struct memrange
));
1136 memranges
->next_memrange
= a
+ 1;
1140 /* Add a register to a collection list */
1142 add_register (collection
, regno
)
1143 struct collection_list
*collection
;
1147 printf_filtered ("collect register %d\n", regno
);
1148 if (regno
> (8 * sizeof (collection
->regs_mask
)))
1149 error ("Internal: register number %d too large for tracepoint",
1151 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
1154 /* Add a memrange to a collection list */
1156 add_memrange (memranges
, type
, base
, len
)
1157 struct collection_list
*memranges
;
1159 bfd_signed_vma base
;
1164 printf_filtered ("(%d,", type
);
1166 printf_filtered (",%ld)\n", len
);
1169 /* type: 0 == memory, n == basereg */
1170 memranges
->list
[memranges
->next_memrange
].type
= type
;
1171 /* base: addr if memory, offset if reg relative. */
1172 memranges
->list
[memranges
->next_memrange
].start
= base
;
1173 /* len: we actually save end (base + len) for convenience */
1174 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
1175 memranges
->next_memrange
++;
1176 if (memranges
->next_memrange
>= memranges
->listsize
)
1178 memranges
->listsize
*= 2;
1179 memranges
->list
= xrealloc (memranges
->list
,
1180 memranges
->listsize
);
1183 if (type
!= -1) /* better collect the base register! */
1184 add_register (memranges
, type
);
1187 /* Add a symbol to a collection list */
1189 collect_symbol (collect
, sym
, frame_regno
, frame_offset
)
1190 struct collection_list
*collect
;
1197 bfd_signed_vma offset
;
1199 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
1200 switch (SYMBOL_CLASS (sym
))
1203 printf_filtered ("%s: don't know symbol class %d\n",
1204 SYMBOL_NAME (sym
), SYMBOL_CLASS (sym
));
1207 printf_filtered ("constant %s (value %ld) will not be collected.\n",
1208 SYMBOL_NAME (sym
), SYMBOL_VALUE (sym
));
1211 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1216 sprintf_vma (tmp
, offset
);
1217 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1218 SYMBOL_NAME (sym
), len
, tmp
/* address */);
1220 add_memrange (collect
, -1, offset
, len
); /* 0 == memory */
1224 reg
= SYMBOL_VALUE (sym
);
1226 printf_filtered ("LOC_REG[parm] %s: ", SYMBOL_NAME (sym
));
1227 add_register (collect
, reg
);
1228 /* check for doubles stored in two registers */
1229 /* FIXME: how about larger types stored in 3 or more regs? */
1230 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
1231 len
> REGISTER_RAW_SIZE (reg
))
1232 add_register (collect
, reg
+ 1);
1235 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1236 printf_filtered (" (will not collect %s)\n",
1241 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1244 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1245 SYMBOL_NAME (sym
), len
);
1246 printf_vma (offset
);
1247 printf_filtered (" from frame ptr reg %d\n", reg
);
1249 add_memrange (collect
, reg
, offset
, len
);
1251 case LOC_REGPARM_ADDR
:
1252 reg
= SYMBOL_VALUE (sym
);
1256 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1257 SYMBOL_NAME (sym
), len
);
1258 printf_vma (offset
);
1259 printf_filtered (" from reg %d\n", reg
);
1261 add_memrange (collect
, reg
, offset
, len
);
1266 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1269 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1270 SYMBOL_NAME (sym
), len
);
1271 printf_vma (offset
);
1272 printf_filtered (" from frame ptr reg %d\n", reg
);
1274 add_memrange (collect
, reg
, offset
, len
);
1277 case LOC_BASEREG_ARG
:
1278 reg
= SYMBOL_BASEREG (sym
);
1279 offset
= SYMBOL_VALUE (sym
);
1282 printf_filtered ("LOC_BASEREG %s: collect %ld bytes at offset ",
1283 SYMBOL_NAME (sym
), len
);
1284 printf_vma (offset
);
1285 printf_filtered (" from basereg %d\n", reg
);
1287 add_memrange (collect
, reg
, offset
, len
);
1289 case LOC_UNRESOLVED
:
1290 printf_filtered ("Don't know LOC_UNRESOLVED %s\n", SYMBOL_NAME (sym
));
1292 case LOC_OPTIMIZED_OUT
:
1293 printf_filtered ("%s has been optimized out of existance.\n",
1299 /* Add all locals (or args) symbols to collection list */
1301 add_local_symbols (collect
, pc
, frame_regno
, frame_offset
, type
)
1302 struct collection_list
*collect
;
1309 struct block
*block
;
1310 int i
, nsyms
, count
= 0;
1312 block
= block_for_pc (pc
);
1315 QUIT
; /* allow user to bail out with ^C */
1316 nsyms
= BLOCK_NSYMS (block
);
1317 for (i
= 0; i
< nsyms
; i
++)
1319 sym
= BLOCK_SYM (block
, i
);
1320 switch (SYMBOL_CLASS (sym
))
1323 warning ("don't know how to trace local symbol %s",
1329 if (type
== 'L') /* collecting Locals */
1332 collect_symbol (collect
, sym
, frame_regno
, frame_offset
);
1339 case LOC_REGPARM_ADDR
:
1340 case LOC_BASEREG_ARG
:
1341 if (type
== 'A') /* collecting Arguments */
1344 collect_symbol (collect
, sym
, frame_regno
, frame_offset
);
1348 if (BLOCK_FUNCTION (block
))
1351 block
= BLOCK_SUPERBLOCK (block
);
1354 warning ("No %s found in scope.", type
== 'L' ? "locals" : "args");
1357 /* worker function */
1359 clear_collection_list (list
)
1360 struct collection_list
*list
;
1364 list
->next_memrange
= 0;
1365 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1367 free_agent_expr (list
->aexpr_list
[ndx
]);
1368 list
->aexpr_list
[ndx
] = NULL
;
1370 list
->next_aexpr_elt
= 0;
1371 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1374 /* reduce a collection list to string form (for gdb protocol) */
1376 stringify_collection_list (list
, string
)
1377 struct collection_list
*list
;
1380 char temp_buf
[2048];
1384 char *(*str_list
)[];
1388 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1389 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1391 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1392 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1394 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1397 printf_filtered ("\nCollecting registers (mask): 0x");
1402 QUIT
; /* allow user to bail out with ^C */
1404 printf_filtered ("%02X", list
->regs_mask
[i
]);
1405 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1408 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1412 printf_filtered ("\n");
1413 if (list
->next_memrange
> 0 && info_verbose
)
1414 printf_filtered ("Collecting memranges: \n");
1415 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1417 QUIT
; /* allow user to bail out with ^C */
1418 sprintf_vma (tmp2
, list
->list
[i
].start
);
1421 printf_filtered ("(%d, %s, %ld)\n",
1424 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1426 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1428 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1434 sprintf (end
, "M%X,%s,%lX",
1437 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1439 count
+= strlen (end
);
1443 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1445 QUIT
; /* allow user to bail out with ^C */
1446 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1448 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1453 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1454 end
+= 10; /* 'X' + 8 hex digits + ',' */
1457 end
= mem2hex (list
->aexpr_list
[i
]->buf
, end
, list
->aexpr_list
[i
]->len
);
1458 count
+= 2 * list
->aexpr_list
[i
]->len
;
1463 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1468 (*str_list
)[ndx
] = NULL
;
1477 free_actions_list_cleanup_wrapper (al
)
1480 free_actions_list (al
);
1484 free_actions_list (actions_list
)
1485 char **actions_list
;
1489 if (actions_list
== 0)
1492 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1493 free (actions_list
[ndx
]);
1495 free (actions_list
);
1498 /* render all actions into gdb protocol */
1500 encode_actions (t
, tdp_actions
, stepping_actions
)
1501 struct tracepoint
*t
;
1502 char ***tdp_actions
;
1503 char ***stepping_actions
;
1505 static char tdp_buff
[2048], step_buff
[2048];
1507 struct expression
*exp
= NULL
;
1508 struct action_line
*action
;
1511 struct collection_list
*collect
;
1512 struct cmd_list_element
*cmd
;
1513 struct agent_expr
*aexpr
;
1514 long frame_reg
, frame_offset
;
1517 clear_collection_list (&tracepoint_list
);
1518 clear_collection_list (&stepping_list
);
1519 collect
= &tracepoint_list
;
1521 *tdp_actions
= NULL
;
1522 *stepping_actions
= NULL
;
1524 TARGET_VIRTUAL_FRAME_POINTER (t
->address
, &frame_reg
, &frame_offset
);
1526 for (action
= t
->actions
; action
; action
= action
->next
)
1528 QUIT
; /* allow user to bail out with ^C */
1529 action_exp
= action
->action
;
1530 while (isspace ((int) *action_exp
))
1533 if (*action_exp
== '#') /* comment line */
1536 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1538 error ("Bad action list item: %s", action_exp
);
1540 if (cmd
->function
.cfunc
== collect_pseudocommand
)
1543 { /* repeat over a comma-separated list */
1544 QUIT
; /* allow user to bail out with ^C */
1545 while (isspace ((int) *action_exp
))
1548 if (0 == strncasecmp ("$reg", action_exp
, 4))
1550 for (i
= 0; i
< NUM_REGS
; i
++)
1551 add_register (collect
, i
);
1552 action_exp
= strchr (action_exp
, ','); /* more? */
1554 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1556 add_local_symbols (collect
,
1561 action_exp
= strchr (action_exp
, ','); /* more? */
1563 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1565 add_local_symbols (collect
,
1570 action_exp
= strchr (action_exp
, ','); /* more? */
1574 unsigned long addr
, len
;
1575 struct cleanup
*old_chain
= NULL
;
1576 struct cleanup
*old_chain1
= NULL
;
1577 struct agent_reqs areqs
;
1579 exp
= parse_exp_1 (&action_exp
, block_for_pc (t
->address
), 1);
1580 old_chain
= make_cleanup ((make_cleanup_func
)
1581 free_current_contents
, &exp
);
1583 switch (exp
->elts
[0].opcode
)
1586 i
= exp
->elts
[1].longconst
;
1588 printf_filtered ("OP_REGISTER: ");
1589 add_register (collect
, i
);
1593 /* safe because we know it's a simple expression */
1594 tempval
= evaluate_expression (exp
);
1595 addr
= VALUE_ADDRESS (tempval
) + VALUE_OFFSET (tempval
);
1596 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1597 add_memrange (collect
, -1, addr
, len
);
1601 collect_symbol (collect
,
1602 exp
->elts
[2].symbol
,
1607 default: /* full-fledged expression */
1608 aexpr
= gen_trace_for_expr (t
->address
, exp
);
1610 old_chain1
= make_cleanup ((make_cleanup_func
)
1611 free_agent_expr
, aexpr
);
1613 ax_reqs (aexpr
, &areqs
);
1614 if (areqs
.flaw
!= agent_flaw_none
)
1615 error ("malformed expression");
1617 if (areqs
.min_height
< 0)
1618 error ("gdb: Internal error: expression has min height < 0");
1619 if (areqs
.max_height
> 20)
1620 error ("expression too complicated, try simplifying");
1622 discard_cleanups (old_chain1
);
1623 add_aexpr (collect
, aexpr
);
1625 /* take care of the registers */
1626 if (areqs
.reg_mask_len
> 0)
1631 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1633 QUIT
; /* allow user to bail out with ^C */
1634 if (areqs
.reg_mask
[ndx1
] != 0)
1636 /* assume chars have 8 bits */
1637 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1638 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1639 /* it's used -- record it */
1640 add_register (collect
, ndx1
* 8 + ndx2
);
1646 do_cleanups (old_chain
);
1649 while (action_exp
&& *action_exp
++ == ',');
1651 else if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
1653 collect
= &stepping_list
;
1655 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
1657 if (collect
== &stepping_list
) /* end stepping actions */
1658 collect
= &tracepoint_list
;
1660 break; /* end tracepoint actions */
1663 memrange_sortmerge (&tracepoint_list
);
1664 memrange_sortmerge (&stepping_list
);
1666 *tdp_actions
= stringify_collection_list (&tracepoint_list
, &tdp_buff
);
1667 *stepping_actions
= stringify_collection_list (&stepping_list
, &step_buff
);
1671 add_aexpr (collect
, aexpr
)
1672 struct collection_list
*collect
;
1673 struct agent_expr
*aexpr
;
1675 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1677 collect
->aexpr_list
=
1678 xrealloc (collect
->aexpr_list
,
1679 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1680 collect
->aexpr_listsize
*= 2;
1682 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1683 collect
->next_aexpr_elt
++;
1686 static char target_buf
[2048];
1688 /* Set "transparent" memory ranges
1690 Allow trace mechanism to treat text-like sections
1691 (and perhaps all read-only sections) transparently,
1692 i.e. don't reject memory requests from these address ranges
1693 just because they haven't been collected. */
1696 remote_set_transparent_ranges (void)
1698 extern bfd
*exec_bfd
;
1705 return; /* no information to give. */
1707 strcpy (target_buf
, "QTro");
1708 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1710 char tmp1
[40], tmp2
[40];
1712 if ((s
->flags
& SEC_LOAD
) == 0 ||
1713 /* (s->flags & SEC_CODE) == 0 || */
1714 (s
->flags
& SEC_READONLY
) == 0)
1719 size
= bfd_get_section_size_before_reloc (s
);
1720 sprintf_vma (tmp1
, lma
);
1721 sprintf_vma (tmp2
, lma
+ size
);
1722 sprintf (target_buf
+ strlen (target_buf
),
1723 ":%s,%s", tmp1
, tmp2
);
1727 putpkt (target_buf
);
1728 getpkt (target_buf
, 0);
1734 Tell target to clear any previous trace experiment.
1735 Walk the list of tracepoints, and send them (and their actions)
1736 to the target. If no errors,
1737 Tell target to start a new trace experiment. */
1740 trace_start_command (args
, from_tty
)
1743 { /* STUB_COMM MOSTLY_IMPLEMENTED */
1744 struct tracepoint
*t
;
1747 char **stepping_actions
;
1749 struct cleanup
*old_chain
= NULL
;
1751 dont_repeat (); /* like "run", dangerous to repeat accidentally */
1753 if (target_is_remote ())
1756 remote_get_noisy_reply (target_buf
);
1757 if (strcmp (target_buf
, "OK"))
1758 error ("Target does not support this command.");
1764 sprintf_vma (tmp
, t
->address
);
1765 sprintf (buf
, "QTDP:%x:%s:%c:%x:%x", t
->number
, tmp
, /* address */
1766 t
->enabled
== enabled
? 'E' : 'D',
1767 t
->step_count
, t
->pass_count
);
1772 remote_get_noisy_reply (target_buf
);
1773 if (strcmp (target_buf
, "OK"))
1774 error ("Target does not support tracepoints.");
1778 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1779 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1781 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
1784 /* do_single_steps (t); */
1787 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1789 QUIT
; /* allow user to bail out with ^C */
1790 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1791 t
->number
, tmp
, /* address */
1793 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1796 remote_get_noisy_reply (target_buf
);
1797 if (strcmp (target_buf
, "OK"))
1798 error ("Error on target while setting tracepoints.");
1801 if (stepping_actions
)
1803 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1805 QUIT
; /* allow user to bail out with ^C */
1806 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1807 t
->number
, tmp
, /* address */
1808 ((ndx
== 0) ? "S" : ""),
1809 stepping_actions
[ndx
],
1810 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1812 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
);
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 (trace_start_stop_hook
)
1833 trace_start_stop_hook (1, from_tty
);
1837 error ("Trace can only be run on remote targets.");
1842 trace_stop_command (args
, from_tty
)
1845 { /* STUB_COMM IS_IMPLEMENTED */
1846 if (target_is_remote ())
1849 remote_get_noisy_reply (target_buf
);
1850 if (strcmp (target_buf
, "OK"))
1851 error ("Bogus reply from target: %s", target_buf
);
1852 trace_running_p
= 0;
1853 if (trace_start_stop_hook
)
1854 trace_start_stop_hook (0, from_tty
);
1857 error ("Trace can only be run on remote targets.");
1860 unsigned long trace_running_p
;
1862 /* tstatus command */
1864 trace_status_command (args
, from_tty
)
1867 { /* STUB_COMM IS_IMPLEMENTED */
1868 if (target_is_remote ())
1870 putpkt ("qTStatus");
1871 remote_get_noisy_reply (target_buf
);
1873 if (target_buf
[0] != 'T' ||
1874 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1875 error ("Bogus reply from target: %s", target_buf
);
1877 /* exported for use by the GUI */
1878 trace_running_p
= (target_buf
[1] == '1');
1881 error ("Trace can only be run on remote targets.");
1884 /* Worker function for the various flavors of the tfind command */
1886 finish_tfind_command (msg
, from_tty
)
1890 int target_frameno
= -1, target_tracept
= -1;
1891 CORE_ADDR old_frame_addr
;
1892 struct symbol
*old_func
;
1895 old_frame_addr
= FRAME_FP (get_current_frame ());
1896 old_func
= find_pc_function (read_pc ());
1899 reply
= remote_get_noisy_reply (msg
);
1901 while (reply
&& *reply
)
1905 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1907 /* A request for a non-existant trace frame has failed.
1908 Our response will be different, depending on FROM_TTY:
1910 If FROM_TTY is true, meaning that this command was
1911 typed interactively by the user, then give an error
1912 and DO NOT change the state of traceframe_number etc.
1914 However if FROM_TTY is false, meaning that we're either
1915 in a script, a loop, or a user-defined command, then
1916 DON'T give an error, but DO change the state of
1917 traceframe_number etc. to invalid.
1919 The rationalle is that if you typed the command, you
1920 might just have committed a typo or something, and you'd
1921 like to NOT lose your current debugging state. However
1922 if you're in a user-defined command or especially in a
1923 loop, then you need a way to detect that the command
1924 failed WITHOUT aborting. This allows you to write
1925 scripts that search thru the trace buffer until the end,
1926 and then continue on to do something else. */
1929 error ("Target failed to find requested trace frame.");
1933 printf_filtered ("End of trace buffer.\n");
1934 /* The following will not recurse, since it's special-cased */
1935 trace_find_command ("-1", from_tty
);
1936 reply
= NULL
; /* break out of loop,
1937 (avoid recursive nonsense) */
1942 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1943 error ("Target failed to find requested trace frame.");
1945 case 'O': /* "OK"? */
1946 if (reply
[1] == 'K' && reply
[2] == '\0')
1949 error ("Bogus reply from target: %s", reply
);
1952 error ("Bogus reply from target: %s", reply
);
1955 flush_cached_frames ();
1956 registers_changed ();
1957 select_frame (get_current_frame (), 0);
1958 set_traceframe_num (target_frameno
);
1959 set_tracepoint_num (target_tracept
);
1960 if (target_frameno
== -1)
1961 set_traceframe_context (-1);
1963 set_traceframe_context (read_pc ());
1969 /* NOTE: in immitation of the step command, try to determine
1970 whether we have made a transition from one function to another.
1971 If so, we'll print the "stack frame" (ie. the new function and
1972 it's arguments) -- otherwise we'll just show the new source line.
1974 This determination is made by checking (1) whether the current
1975 function has changed, and (2) whether the current FP has changed.
1976 Hack: if the FP wasn't collected, either at the current or the
1977 previous frame, assume that the FP has NOT changed. */
1979 if (old_func
== find_pc_function (read_pc ()) &&
1980 (old_frame_addr
== 0 ||
1981 FRAME_FP (get_current_frame ()) == 0 ||
1982 old_frame_addr
== FRAME_FP (get_current_frame ())))
1987 print_stack_frame (selected_frame
, selected_frame_level
, source_only
);
1992 /* trace_find_command takes a trace frame number n,
1993 sends "QTFrame:<n>" to the target,
1994 and accepts a reply that may contain several optional pieces
1995 of information: a frame number, a tracepoint number, and an
1996 indication of whether this is a trap frame or a stepping frame.
1998 The minimal response is just "OK" (which indicates that the
1999 target does not give us a frame number or a tracepoint number).
2000 Instead of that, the target may send us a string containing
2002 F<hexnum> (gives the selected frame number)
2003 T<hexnum> (gives the selected tracepoint number)
2008 trace_find_command (args
, from_tty
)
2011 { /* STUB_COMM PART_IMPLEMENTED */
2012 /* this should only be called with a numeric argument */
2015 if (target_is_remote ())
2017 if (trace_find_hook
)
2018 trace_find_hook (args
, from_tty
);
2020 if (args
== 0 || *args
== 0)
2021 { /* TFIND with no args means find NEXT trace frame. */
2022 if (traceframe_number
== -1)
2023 frameno
= 0; /* "next" is first one */
2025 frameno
= traceframe_number
+ 1;
2027 else if (0 == strcmp (args
, "-"))
2029 if (traceframe_number
== -1)
2030 error ("not debugging trace buffer");
2031 else if (from_tty
&& traceframe_number
== 0)
2032 error ("already at start of trace buffer");
2034 frameno
= traceframe_number
- 1;
2037 frameno
= parse_and_eval_address (args
);
2040 error ("invalid input (%d is less than zero)", frameno
);
2042 sprintf (target_buf
, "QTFrame:%x", frameno
);
2043 finish_tfind_command (target_buf
, from_tty
);
2046 error ("Trace can only be run on remote targets.");
2051 trace_find_end_command (args
, from_tty
)
2055 trace_find_command ("-1", from_tty
);
2060 trace_find_none_command (args
, from_tty
)
2064 trace_find_command ("-1", from_tty
);
2069 trace_find_start_command (args
, from_tty
)
2073 trace_find_command ("0", from_tty
);
2076 /* tfind pc command */
2078 trace_find_pc_command (args
, from_tty
)
2081 { /* STUB_COMM PART_IMPLEMENTED */
2085 if (target_is_remote ())
2087 if (args
== 0 || *args
== 0)
2088 pc
= read_pc (); /* default is current pc */
2090 pc
= parse_and_eval_address (args
);
2092 sprintf_vma (tmp
, pc
);
2093 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
2094 finish_tfind_command (target_buf
, from_tty
);
2097 error ("Trace can only be run on remote targets.");
2100 /* tfind tracepoint command */
2102 trace_find_tracepoint_command (args
, from_tty
)
2105 { /* STUB_COMM PART_IMPLEMENTED */
2108 if (target_is_remote ())
2110 if (args
== 0 || *args
== 0)
2111 if (tracepoint_number
== -1)
2112 error ("No current tracepoint -- please supply an argument.");
2114 tdp
= tracepoint_number
; /* default is current TDP */
2116 tdp
= parse_and_eval_address (args
);
2118 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
2119 finish_tfind_command (target_buf
, from_tty
);
2122 error ("Trace can only be run on remote targets.");
2125 /* TFIND LINE command:
2127 This command will take a sourceline for argument, just like BREAK
2128 or TRACE (ie. anything that "decode_line_1" can handle).
2130 With no argument, this command will find the next trace frame
2131 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2134 trace_find_line_command (args
, from_tty
)
2137 { /* STUB_COMM PART_IMPLEMENTED */
2138 static CORE_ADDR start_pc
, end_pc
;
2139 struct symtabs_and_lines sals
;
2140 struct symtab_and_line sal
;
2141 struct cleanup
*old_chain
;
2142 char startpc_str
[40], endpc_str
[40];
2144 if (target_is_remote ())
2146 if (args
== 0 || *args
== 0)
2148 sal
= find_pc_line ((get_current_frame ())->pc
, 0);
2150 sals
.sals
= (struct symtab_and_line
*)
2151 xmalloc (sizeof (struct symtab_and_line
));
2156 sals
= decode_line_spec (args
, 1);
2160 old_chain
= make_cleanup (free
, sals
.sals
);
2161 if (sal
.symtab
== 0)
2163 printf_filtered ("TFIND: No line number information available");
2166 /* This is useful for "info line *0x7f34". If we can't tell the
2167 user about a source line, at least let them have the symbolic
2169 printf_filtered (" for address ");
2171 print_address (sal
.pc
, gdb_stdout
);
2172 printf_filtered (";\n -- will attempt to find by PC. \n");
2176 printf_filtered (".\n");
2177 return; /* no line, no PC; what can we do? */
2180 else if (sal
.line
> 0
2181 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2183 if (start_pc
== end_pc
)
2185 printf_filtered ("Line %d of \"%s\"",
2186 sal
.line
, sal
.symtab
->filename
);
2188 printf_filtered (" is at address ");
2189 print_address (start_pc
, gdb_stdout
);
2191 printf_filtered (" but contains no code.\n");
2192 sal
= find_pc_line (start_pc
, 0);
2194 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
2196 printf_filtered ("Attempting to find line %d instead.\n",
2199 error ("Cannot find a good line.");
2203 /* Is there any case in which we get here, and have an address
2204 which the user would want to see? If we have debugging symbols
2205 and no line numbers? */
2206 error ("Line number %d is out of range for \"%s\".\n",
2207 sal
.line
, sal
.symtab
->filename
);
2209 sprintf_vma (startpc_str
, start_pc
);
2210 sprintf_vma (endpc_str
, end_pc
- 1);
2211 if (args
&& *args
) /* find within range of stated line */
2212 sprintf (target_buf
, "QTFrame:range:%s:%s", startpc_str
, endpc_str
);
2213 else /* find OUTSIDE OF range of CURRENT line */
2214 sprintf (target_buf
, "QTFrame:outside:%s:%s", startpc_str
, endpc_str
);
2215 finish_tfind_command (target_buf
, from_tty
);
2216 do_cleanups (old_chain
);
2219 error ("Trace can only be run on remote targets.");
2222 /* tfind range command */
2224 trace_find_range_command (args
, from_tty
)
2228 static CORE_ADDR start
, stop
;
2229 char start_str
[40], stop_str
[40];
2232 if (target_is_remote ())
2234 if (args
== 0 || *args
== 0)
2235 { /* XXX FIXME: what should default behavior be? */
2236 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2240 if (0 != (tmp
= strchr (args
, ',')))
2242 *tmp
++ = '\0'; /* terminate start address */
2243 while (isspace ((int) *tmp
))
2245 start
= parse_and_eval_address (args
);
2246 stop
= parse_and_eval_address (tmp
);
2249 { /* no explicit end address? */
2250 start
= parse_and_eval_address (args
);
2251 stop
= start
+ 1; /* ??? */
2254 sprintf_vma (start_str
, start
);
2255 sprintf_vma (stop_str
, stop
);
2256 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
2257 finish_tfind_command (target_buf
, from_tty
);
2260 error ("Trace can only be run on remote targets.");
2263 /* tfind outside command */
2265 trace_find_outside_command (args
, from_tty
)
2269 CORE_ADDR start
, stop
;
2270 char start_str
[40], stop_str
[40];
2273 if (target_is_remote ())
2275 if (args
== 0 || *args
== 0)
2276 { /* XXX FIXME: what should default behavior be? */
2277 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2281 if (0 != (tmp
= strchr (args
, ',')))
2283 *tmp
++ = '\0'; /* terminate start address */
2284 while (isspace ((int) *tmp
))
2286 start
= parse_and_eval_address (args
);
2287 stop
= parse_and_eval_address (tmp
);
2290 { /* no explicit end address? */
2291 start
= parse_and_eval_address (args
);
2292 stop
= start
+ 1; /* ??? */
2295 sprintf_vma (start_str
, start
);
2296 sprintf_vma (stop_str
, stop
);
2297 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
2298 finish_tfind_command (target_buf
, from_tty
);
2301 error ("Trace can only be run on remote targets.");
2304 /* save-tracepoints command */
2306 tracepoint_save_command (args
, from_tty
)
2310 struct tracepoint
*tp
;
2311 struct action_line
*line
;
2313 char *i1
= " ", *i2
= " ";
2314 char *indent
, *actionline
;
2317 if (args
== 0 || *args
== 0)
2318 error ("Argument required (file name in which to save tracepoints");
2320 if (tracepoint_chain
== 0)
2322 warning ("save-tracepoints: no tracepoints to save.\n");
2326 if (!(fp
= fopen (args
, "w")))
2327 error ("Unable to open file '%s' for saving tracepoints");
2329 ALL_TRACEPOINTS (tp
)
2331 if (tp
->addr_string
)
2332 fprintf (fp
, "trace %s\n", tp
->addr_string
);
2335 sprintf_vma (tmp
, tp
->address
);
2336 fprintf (fp
, "trace *0x%s\n", tmp
);
2340 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
2344 fprintf (fp
, " actions\n");
2346 for (line
= tp
->actions
; line
; line
= line
->next
)
2348 struct cmd_list_element
*cmd
;
2350 QUIT
; /* allow user to bail out with ^C */
2351 actionline
= line
->action
;
2352 while (isspace ((int) *actionline
))
2355 fprintf (fp
, "%s%s\n", indent
, actionline
);
2356 if (*actionline
!= '#') /* skip for comment lines */
2358 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
2360 error ("Bad action list item: %s", actionline
);
2361 if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
2363 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
2371 printf_filtered ("Tracepoints saved to file '%s'.\n", args
);
2375 /* info scope command: list the locals for a scope. */
2377 scope_info (args
, from_tty
)
2381 struct symtabs_and_lines sals
;
2383 struct minimal_symbol
*msym
;
2384 struct block
*block
;
2385 char **canonical
, *symname
, *save_args
= args
;
2386 int i
, j
, nsyms
, count
= 0;
2388 if (args
== 0 || *args
== 0)
2389 error ("requires an argument (function, line or *addr) to define a scope");
2391 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2392 if (sals
.nelts
== 0)
2393 return; /* presumably decode_line_1 has already warned */
2395 /* Resolve line numbers to PC */
2396 resolve_sal_pc (&sals
.sals
[0]);
2397 block
= block_for_pc (sals
.sals
[0].pc
);
2401 QUIT
; /* allow user to bail out with ^C */
2402 nsyms
= BLOCK_NSYMS (block
);
2403 for (i
= 0; i
< nsyms
; i
++)
2405 QUIT
; /* allow user to bail out with ^C */
2407 printf_filtered ("Scope for %s:\n", save_args
);
2409 sym
= BLOCK_SYM (block
, i
);
2410 symname
= SYMBOL_NAME (sym
);
2411 if (symname
== NULL
|| *symname
== '\0')
2412 continue; /* probably botched, certainly useless */
2414 printf_filtered ("Symbol %s is ", symname
);
2415 switch (SYMBOL_CLASS (sym
))
2418 case LOC_UNDEF
: /* messed up symbol? */
2419 printf_filtered ("a bogus symbol, class %d.\n",
2420 SYMBOL_CLASS (sym
));
2421 count
--; /* don't count this one */
2424 printf_filtered ("a constant with value %ld (0x%lx)",
2425 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2427 case LOC_CONST_BYTES
:
2428 printf_filtered ("constant bytes: ");
2429 if (SYMBOL_TYPE (sym
))
2430 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2431 fprintf_filtered (gdb_stdout
, " %02x",
2432 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2435 printf_filtered ("in static storage at address ");
2436 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2439 printf_filtered ("a local variable in register $%s",
2440 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2444 printf_filtered ("an argument at stack/frame offset %ld",
2445 SYMBOL_VALUE (sym
));
2448 printf_filtered ("a local variable at frame offset %ld",
2449 SYMBOL_VALUE (sym
));
2452 printf_filtered ("a reference argument at offset %ld",
2453 SYMBOL_VALUE (sym
));
2456 printf_filtered ("an argument in register $%s",
2457 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2459 case LOC_REGPARM_ADDR
:
2460 printf_filtered ("the address of an argument, in register $%s",
2461 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2464 printf_filtered ("a typedef.\n");
2467 printf_filtered ("a label at address ");
2468 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2471 printf_filtered ("a function at address ");
2472 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)), 1,
2476 printf_filtered ("a variable at offset %ld from register $%s",
2478 REGISTER_NAME (SYMBOL_BASEREG (sym
)));
2480 case LOC_BASEREG_ARG
:
2481 printf_filtered ("an argument at offset %ld from register $%s",
2483 REGISTER_NAME (SYMBOL_BASEREG (sym
)));
2485 case LOC_UNRESOLVED
:
2486 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
2488 printf_filtered ("Unresolved Static");
2491 printf_filtered ("static storage at address ");
2492 print_address_numeric (SYMBOL_VALUE_ADDRESS (msym
), 1,
2496 case LOC_OPTIMIZED_OUT
:
2497 printf_filtered ("optimized out.\n");
2500 if (SYMBOL_TYPE (sym
))
2501 printf_filtered (", length %d.\n",
2502 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2504 if (BLOCK_FUNCTION (block
))
2507 block
= BLOCK_SUPERBLOCK (block
);
2510 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2514 /* worker function (cleanup) */
2516 replace_comma (comma
)
2524 trace_dump_command (args
, from_tty
)
2528 struct tracepoint
*t
;
2529 struct action_line
*action
;
2530 char *action_exp
, *next_comma
;
2531 struct cleanup
*old_cleanups
;
2532 int stepping_actions
= 0;
2533 int stepping_frame
= 0;
2535 if (!target_is_remote ())
2537 error ("Trace can only be run on remote targets.");
2541 if (tracepoint_number
== -1)
2543 warning ("No current trace frame.");
2548 if (t
->number
== tracepoint_number
)
2552 error ("No known tracepoint matches 'current' tracepoint #%d.",
2555 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2557 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2558 tracepoint_number
, traceframe_number
);
2560 /* The current frame is a trap frame if the frame PC is equal
2561 to the tracepoint PC. If not, then the current frame was
2562 collected during single-stepping. */
2564 stepping_frame
= (t
->address
!= read_pc ());
2566 for (action
= t
->actions
; action
; action
= action
->next
)
2568 struct cmd_list_element
*cmd
;
2570 QUIT
; /* allow user to bail out with ^C */
2571 action_exp
= action
->action
;
2572 while (isspace ((int) *action_exp
))
2575 /* The collection actions to be done while stepping are
2576 bracketed by the commands "while-stepping" and "end". */
2578 if (*action_exp
== '#') /* comment line */
2581 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2583 error ("Bad action list item: %s", action_exp
);
2585 if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
2586 stepping_actions
= 1;
2587 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
2588 stepping_actions
= 0;
2589 else if (cmd
->function
.cfunc
== collect_pseudocommand
)
2591 /* Display the collected data.
2592 For the trap frame, display only what was collected at the trap.
2593 Likewise for stepping frames, display only what was collected
2594 while stepping. This means that the two boolean variables,
2595 STEPPING_FRAME and STEPPING_ACTIONS should be equal. */
2596 if (stepping_frame
== stepping_actions
)
2599 { /* repeat over a comma-separated list */
2600 QUIT
; /* allow user to bail out with ^C */
2601 if (*action_exp
== ',')
2603 while (isspace ((int) *action_exp
))
2606 next_comma
= strchr (action_exp
, ',');
2608 if (0 == strncasecmp (action_exp
, "$reg", 4))
2609 registers_info (NULL
, from_tty
);
2610 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2611 locals_info (NULL
, from_tty
);
2612 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2613 args_info (NULL
, from_tty
);
2618 make_cleanup (replace_comma
, next_comma
);
2621 printf_filtered ("%s = ", action_exp
);
2622 output_command (action_exp
, from_tty
);
2623 printf_filtered ("\n");
2627 action_exp
= next_comma
;
2629 while (action_exp
&& *action_exp
== ',');
2633 discard_cleanups (old_cleanups
);
2636 /* Convert the memory pointed to by mem into hex, placing result in buf.
2637 * Return a pointer to the last char put in buf (null)
2638 * "stolen" from sparc-stub.c
2641 static const char hexchars
[] = "0123456789abcdef";
2643 static unsigned char *
2644 mem2hex (mem
, buf
, count
)
2655 *buf
++ = hexchars
[ch
>> 4];
2656 *buf
++ = hexchars
[ch
& 0xf];
2665 get_traceframe_number ()
2667 return traceframe_number
;
2671 /* module initialization */
2673 _initialize_tracepoint ()
2675 tracepoint_chain
= 0;
2676 tracepoint_count
= 0;
2677 traceframe_number
= -1;
2678 tracepoint_number
= -1;
2680 set_internalvar (lookup_internalvar ("tpnum"),
2681 value_from_longest (builtin_type_int
, (LONGEST
) 0));
2682 set_internalvar (lookup_internalvar ("trace_frame"),
2683 value_from_longest (builtin_type_int
, (LONGEST
) - 1));
2685 if (tracepoint_list
.list
== NULL
)
2687 tracepoint_list
.listsize
= 128;
2688 tracepoint_list
.list
= xmalloc
2689 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2691 if (tracepoint_list
.aexpr_list
== NULL
)
2693 tracepoint_list
.aexpr_listsize
= 128;
2694 tracepoint_list
.aexpr_list
= xmalloc
2695 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2698 if (stepping_list
.list
== NULL
)
2700 stepping_list
.listsize
= 128;
2701 stepping_list
.list
= xmalloc
2702 (stepping_list
.listsize
* sizeof (struct memrange
));
2705 if (stepping_list
.aexpr_list
== NULL
)
2707 stepping_list
.aexpr_listsize
= 128;
2708 stepping_list
.aexpr_list
= xmalloc
2709 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2712 add_info ("scope", scope_info
,
2713 "List the variables local to a scope");
2715 add_cmd ("tracepoints", class_trace
, NO_FUNCTION
,
2716 "Tracing of program execution without stopping the program.",
2719 add_info ("tracepoints", tracepoints_info
,
2720 "Status of tracepoints, or tracepoint number NUMBER.\n\
2721 Convenience variable \"$tpnum\" contains the number of the\n\
2722 last tracepoint set.");
2724 add_info_alias ("tp", "tracepoints", 1);
2726 add_com ("save-tracepoints", class_trace
, tracepoint_save_command
,
2727 "Save current tracepoint definitions as a script.\n\
2728 Use the 'source' command in another debug session to restore them.");
2730 add_com ("tdump", class_trace
, trace_dump_command
,
2731 "Print everything collected at the current tracepoint.");
2733 add_prefix_cmd ("tfind", class_trace
, trace_find_command
,
2734 "Select a trace frame;\n\
2735 No argument means forward by one frame; '-' meand backward by one frame.",
2736 &tfindlist
, "tfind ", 1, &cmdlist
);
2738 add_cmd ("outside", class_trace
, trace_find_outside_command
,
2739 "Select a trace frame whose PC is outside the given \
2740 range.\nUsage: tfind outside addr1, addr2",
2743 add_cmd ("range", class_trace
, trace_find_range_command
,
2744 "Select a trace frame whose PC is in the given range.\n\
2745 Usage: tfind range addr1,addr2",
2748 add_cmd ("line", class_trace
, trace_find_line_command
,
2749 "Select a trace frame by source line.\n\
2750 Argument can be a line number (with optional source file), \n\
2751 a function name, or '*' followed by an address.\n\
2752 Default argument is 'the next source line that was traced'.",
2755 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
,
2756 "Select a trace frame by tracepoint number.\n\
2757 Default is the tracepoint for the current trace frame.",
2760 add_cmd ("pc", class_trace
, trace_find_pc_command
,
2761 "Select a trace frame by PC.\n\
2762 Default is the current PC, or the PC of the current trace frame.",
2765 add_cmd ("end", class_trace
, trace_find_end_command
,
2766 "Synonym for 'none'.\n\
2767 De-select any trace frame and resume 'live' debugging.",
2770 add_cmd ("none", class_trace
, trace_find_none_command
,
2771 "De-select any trace frame and resume 'live' debugging.",
2774 add_cmd ("start", class_trace
, trace_find_start_command
,
2775 "Select the first trace frame in the trace buffer.",
2778 add_com ("tstatus", class_trace
, trace_status_command
,
2779 "Display the status of the current trace data collection.");
2781 add_com ("tstop", class_trace
, trace_stop_command
,
2782 "Stop trace data collection.");
2784 add_com ("tstart", class_trace
, trace_start_command
,
2785 "Start trace data collection.");
2787 add_com ("passcount", class_trace
, trace_pass_command
,
2788 "Set the passcount for a tracepoint.\n\
2789 The trace will end when the tracepoint has been passed 'count' times.\n\
2790 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
2791 if TPNUM is omitted, passcount refers to the last tracepoint defined.");
2793 add_com ("end", class_trace
, end_actions_pseudocommand
,
2794 "Ends a list of commands or actions.\n\
2795 Several GDB commands allow you to enter a list of commands or actions.\n\
2796 Entering \"end\" on a line by itself is the normal way to terminate\n\
2798 Note: the \"end\" command cannot be used at the gdb prompt.");
2800 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
,
2801 "Specify single-stepping behavior at a tracepoint.\n\
2802 Argument is number of instructions to trace in single-step mode\n\
2803 following the tracepoint. This command is normally followed by\n\
2804 one or more \"collect\" commands, to specify what to collect\n\
2805 while single-stepping.\n\n\
2806 Note: this command can only be used in a tracepoint \"actions\" list.");
2808 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2809 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2811 add_com ("collect", class_trace
, collect_pseudocommand
,
2812 "Specify one or more data items to be collected at a tracepoint.\n\
2813 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2814 collect all data (variables, registers) referenced by that expression.\n\
2815 Also accepts the following special arguments:\n\
2816 $regs -- all registers.\n\
2817 $args -- all function arguments.\n\
2818 $locals -- all variables local to the block/function scope.\n\
2819 Note: this command can only be used in a tracepoint \"actions\" list.");
2821 add_com ("actions", class_trace
, trace_actions_command
,
2822 "Specify the actions to be taken at a tracepoint.\n\
2823 Tracepoint actions may include collecting of specified data, \n\
2824 single-stepping, or enabling/disabling other tracepoints, \n\
2825 depending on target's capabilities.");
2827 add_cmd ("tracepoints", class_trace
, delete_trace_command
,
2828 "Delete specified tracepoints.\n\
2829 Arguments are tracepoint numbers, separated by spaces.\n\
2830 No argument means delete all tracepoints.",
2833 add_cmd ("tracepoints", class_trace
, disable_trace_command
,
2834 "Disable specified tracepoints.\n\
2835 Arguments are tracepoint numbers, separated by spaces.\n\
2836 No argument means disable all tracepoints.",
2839 add_cmd ("tracepoints", class_trace
, enable_trace_command
,
2840 "Enable specified tracepoints.\n\
2841 Arguments are tracepoint numbers, separated by spaces.\n\
2842 No argument means enable all tracepoints.",
2845 add_com ("trace", class_trace
, trace_command
,
2846 "Set a tracepoint at a specified line or function or address.\n\
2847 Argument may be a line number, function name, or '*' plus an address.\n\
2848 For a line number or function, trace at the start of its code.\n\
2849 If an address is specified, trace at that exact address.\n\n\
2850 Do \"help tracepoints\" for info on other tracepoint commands.");
2852 add_com_alias ("tp", "trace", class_alias
, 0);
2853 add_com_alias ("tr", "trace", class_alias
, 1);
2854 add_com_alias ("tra", "trace", class_alias
, 1);
2855 add_com_alias ("trac", "trace", class_alias
, 1);