1 /* Tracing functionality for remote targets in custom GDB protocol
2 Copyright 1997, 1998, 1999, 2000, 2001 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"
36 #include "gdb-events.h"
41 /* readline include files */
42 #include <readline/readline.h>
43 #include <readline/history.h>
45 /* readline defines this. */
52 /* maximum length of an agent aexpression.
53 this accounts for the fact that packets are limited to 400 bytes
54 (which includes everything -- including the checksum), and assumes
55 the worst case of maximum length for each of the pieces of a
58 NOTE: expressions get mem2hex'ed otherwise this would be twice as
59 large. (400 - 31)/2 == 184 */
60 #define MAX_AGENT_EXPR_LEN 184
63 extern int info_verbose
;
64 extern void (*readline_begin_hook
) (char *, ...);
65 extern char *(*readline_hook
) (char *);
66 extern void (*readline_end_hook
) (void);
67 extern void x_command (char *, int);
68 extern int addressprint
; /* Print machine addresses? */
70 /* GDB commands implemented in other modules:
73 extern void output_command (char *, int);
74 extern void registers_info (char *, int);
75 extern void args_info (char *, int);
76 extern void locals_info (char *, int);
79 /* If this definition isn't overridden by the header files, assume
80 that isatty and fileno exist on this system. */
82 #define ISATTY(FP) (isatty (fileno (FP)))
88 This module defines the following debugger commands:
89 trace : set a tracepoint on a function, line, or address.
90 info trace : list all debugger-defined tracepoints.
91 delete trace : delete one or more tracepoints.
92 enable trace : enable one or more tracepoints.
93 disable trace : disable one or more tracepoints.
94 actions : specify actions to be taken at a tracepoint.
95 passcount : specify a pass count for a tracepoint.
96 tstart : start a trace experiment.
97 tstop : stop a trace experiment.
98 tstatus : query the status of a trace experiment.
99 tfind : find a trace frame in the trace buffer.
100 tdump : print everything collected at the current tracepoint.
101 save-tracepoints : write tracepoint setup into a file.
103 This module defines the following user-visible debugger variables:
104 $trace_frame : sequence number of trace frame currently being debugged.
105 $trace_line : source line of trace frame currently being debugged.
106 $trace_file : source file of trace frame currently being debugged.
107 $tracepoint : tracepoint number of trace frame currently being debugged.
111 /* ======= Important global variables: ======= */
113 /* Chain of all tracepoints defined. */
114 struct tracepoint
*tracepoint_chain
;
116 /* Number of last tracepoint made. */
117 static int tracepoint_count
;
119 /* Number of last traceframe collected. */
120 static int traceframe_number
;
122 /* Tracepoint for last traceframe collected. */
123 static int tracepoint_number
;
125 /* Symbol for function for last traceframe collected */
126 static struct symbol
*traceframe_fun
;
128 /* Symtab and line for last traceframe collected */
129 static struct symtab_and_line traceframe_sal
;
131 /* Tracing command lists */
132 static struct cmd_list_element
*tfindlist
;
134 /* ======= Important command functions: ======= */
135 static void trace_command (char *, int);
136 static void tracepoints_info (char *, int);
137 static void delete_trace_command (char *, int);
138 static void enable_trace_command (char *, int);
139 static void disable_trace_command (char *, int);
140 static void trace_pass_command (char *, int);
141 static void trace_actions_command (char *, int);
142 static void trace_start_command (char *, int);
143 static void trace_stop_command (char *, int);
144 static void trace_status_command (char *, int);
145 static void trace_find_command (char *, int);
146 static void trace_find_pc_command (char *, int);
147 static void trace_find_tracepoint_command (char *, int);
148 static void trace_find_line_command (char *, int);
149 static void trace_find_range_command (char *, int);
150 static void trace_find_outside_command (char *, int);
151 static void tracepoint_save_command (char *, int);
152 static void trace_dump_command (char *, int);
154 /* support routines */
155 static void trace_mention (struct tracepoint
*);
157 struct collection_list
;
158 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
159 static unsigned char *mem2hex (unsigned char *, unsigned char *, int);
160 static void add_register (struct collection_list
*collection
,
162 static struct cleanup
*make_cleanup_free_actions (struct tracepoint
*t
);
163 static void free_actions_list (char **actions_list
);
164 static void free_actions_list_cleanup_wrapper (void *);
166 extern void _initialize_tracepoint (void);
168 /* Utility: returns true if "target remote" */
170 target_is_remote (void)
172 if (current_target
.to_shortname
&&
173 strcmp (current_target
.to_shortname
, "remote") == 0)
179 /* Utility: generate error from an incoming stub packet. */
181 trace_error (char *buf
)
184 return; /* not an error msg */
187 case '1': /* malformed packet error */
188 if (*++buf
== '0') /* general case: */
189 error ("tracepoint.c: error in outgoing packet.");
191 error ("tracepoint.c: error in outgoing packet at field #%d.",
192 strtol (buf
, NULL
, 16));
194 error ("trace API error 0x%s.", ++buf
);
196 error ("Target returns error code '%s'.", buf
);
200 /* Utility: wait for reply from stub, while accepting "O" packets */
202 remote_get_noisy_reply (char *buf
,
205 do /* loop on reply from remote stub */
207 QUIT
; /* allow user to bail out with ^C */
208 getpkt (buf
, sizeof_buf
, 0);
210 error ("Target does not support this command.");
211 else if (buf
[0] == 'E')
213 else if (buf
[0] == 'O' &&
215 remote_console_output (buf
+ 1); /* 'O' message from stub */
217 return buf
; /* here's the actual reply */
222 /* Set tracepoint count to NUM. */
224 set_tracepoint_count (int num
)
226 tracepoint_count
= num
;
227 set_internalvar (lookup_internalvar ("tpnum"),
228 value_from_longest (builtin_type_int
, (LONGEST
) num
));
231 /* Set traceframe number to NUM. */
233 set_traceframe_num (int num
)
235 traceframe_number
= num
;
236 set_internalvar (lookup_internalvar ("trace_frame"),
237 value_from_longest (builtin_type_int
, (LONGEST
) num
));
240 /* Set tracepoint number to NUM. */
242 set_tracepoint_num (int 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 (CORE_ADDR trace_pc
)
255 static struct type
*func_string
, *file_string
;
256 static struct type
*func_range
, *file_range
;
257 static value_ptr func_val
, file_val
;
258 static struct type
*charstar
;
261 if (charstar
== (struct type
*) NULL
)
262 charstar
= lookup_pointer_type (builtin_type_char
);
264 if (trace_pc
== -1) /* cease debugging any trace buffers */
267 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
268 traceframe_sal
.symtab
= NULL
;
269 set_internalvar (lookup_internalvar ("trace_func"),
270 value_from_pointer (charstar
, (LONGEST
) 0));
271 set_internalvar (lookup_internalvar ("trace_file"),
272 value_from_pointer (charstar
, (LONGEST
) 0));
273 set_internalvar (lookup_internalvar ("trace_line"),
274 value_from_pointer (builtin_type_int
, (LONGEST
) - 1));
278 /* save as globals for internal use */
279 traceframe_sal
= find_pc_line (trace_pc
, 0);
280 traceframe_fun
= find_pc_function (trace_pc
);
282 /* save linenumber as "$trace_line", a debugger variable visible to users */
283 set_internalvar (lookup_internalvar ("trace_line"),
284 value_from_longest (builtin_type_int
,
285 (LONGEST
) traceframe_sal
.line
));
287 /* save func name as "$trace_func", a debugger variable visible to users */
288 if (traceframe_fun
== NULL
||
289 SYMBOL_NAME (traceframe_fun
) == NULL
)
290 set_internalvar (lookup_internalvar ("trace_func"),
291 value_from_pointer (charstar
, (LONGEST
) 0));
294 len
= strlen (SYMBOL_NAME (traceframe_fun
));
295 func_range
= create_range_type (func_range
,
296 builtin_type_int
, 0, len
- 1);
297 func_string
= create_array_type (func_string
,
298 builtin_type_char
, func_range
);
299 func_val
= allocate_value (func_string
);
300 VALUE_TYPE (func_val
) = func_string
;
301 memcpy (VALUE_CONTENTS_RAW (func_val
),
302 SYMBOL_NAME (traceframe_fun
),
304 func_val
->modifiable
= 0;
305 set_internalvar (lookup_internalvar ("trace_func"), func_val
);
308 /* save file name as "$trace_file", a debugger variable visible to users */
309 if (traceframe_sal
.symtab
== NULL
||
310 traceframe_sal
.symtab
->filename
== NULL
)
311 set_internalvar (lookup_internalvar ("trace_file"),
312 value_from_pointer (charstar
, (LONGEST
) 0));
315 len
= strlen (traceframe_sal
.symtab
->filename
);
316 file_range
= create_range_type (file_range
,
317 builtin_type_int
, 0, len
- 1);
318 file_string
= create_array_type (file_string
,
319 builtin_type_char
, file_range
);
320 file_val
= allocate_value (file_string
);
321 VALUE_TYPE (file_val
) = file_string
;
322 memcpy (VALUE_CONTENTS_RAW (file_val
),
323 traceframe_sal
.symtab
->filename
,
325 file_val
->modifiable
= 0;
326 set_internalvar (lookup_internalvar ("trace_file"), file_val
);
330 /* Low level routine to set a tracepoint.
331 Returns the tracepoint object so caller can set other things.
332 Does not set the tracepoint number!
333 Does not print anything.
335 ==> This routine should not be called if there is a chance of later
336 error(); otherwise it leaves a bogus tracepoint on the chain. Validate
337 your arguments BEFORE calling this routine! */
339 static struct tracepoint
*
340 set_raw_tracepoint (struct symtab_and_line sal
)
342 register struct tracepoint
*t
, *tc
;
343 struct cleanup
*old_chain
;
345 t
= (struct tracepoint
*) xmalloc (sizeof (struct tracepoint
));
346 old_chain
= make_cleanup (xfree
, t
);
347 memset (t
, 0, sizeof (*t
));
349 if (sal
.symtab
== NULL
)
350 t
->source_file
= NULL
;
352 t
->source_file
= savestring (sal
.symtab
->filename
,
353 strlen (sal
.symtab
->filename
));
355 t
->section
= sal
.section
;
356 t
->language
= current_language
->la_language
;
357 t
->input_radix
= input_radix
;
358 t
->line_number
= sal
.line
;
359 t
->enabled
= enabled
;
363 t
->addr_string
= NULL
;
365 /* Add this tracepoint to the end of the chain
366 so that a list of tracepoints will come out in order
367 of increasing numbers. */
369 tc
= tracepoint_chain
;
371 tracepoint_chain
= t
;
378 discard_cleanups (old_chain
);
382 /* Set a tracepoint according to ARG (function, linenum or *address) */
384 trace_command (char *arg
, int from_tty
)
386 char **canonical
= (char **) NULL
;
387 struct symtabs_and_lines sals
;
388 struct symtab_and_line sal
;
389 struct tracepoint
*t
;
390 char *addr_start
= 0, *addr_end
= 0;
394 error ("trace command requires an argument");
396 if (from_tty
&& info_verbose
)
397 printf_filtered ("TRACE %s\n", arg
);
400 sals
= decode_line_1 (&arg
, 1, (struct symtab
*) NULL
, 0, &canonical
);
403 return; /* ??? Presumably decode_line_1 has already warned? */
405 /* Resolve all line numbers to PC's */
406 for (i
= 0; i
< sals
.nelts
; i
++)
407 resolve_sal_pc (&sals
.sals
[i
]);
409 /* Now set all the tracepoints. */
410 for (i
= 0; i
< sals
.nelts
; i
++)
414 t
= set_raw_tracepoint (sal
);
415 set_tracepoint_count (tracepoint_count
+ 1);
416 t
->number
= tracepoint_count
;
418 /* If a canonical line spec is needed use that instead of the
420 if (canonical
!= (char **) NULL
&& canonical
[i
] != NULL
)
421 t
->addr_string
= canonical
[i
];
423 t
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
427 /* Let the UI know of any additions */
428 if (create_tracepoint_hook
)
429 create_tracepoint_hook (t
);
434 printf_filtered ("Multiple tracepoints were set.\n");
435 printf_filtered ("Use 'delete trace' to delete unwanted tracepoints.\n");
439 /* Tell the user we have just set a tracepoint TP. */
442 trace_mention (struct tracepoint
*tp
)
444 printf_filtered ("Tracepoint %d", tp
->number
);
446 if (addressprint
|| (tp
->source_file
== NULL
))
448 printf_filtered (" at ");
449 print_address_numeric (tp
->address
, 1, gdb_stdout
);
452 printf_filtered (": file %s, line %d.",
453 tp
->source_file
, tp
->line_number
);
455 printf_filtered ("\n");
458 /* Print information on tracepoint number TPNUM_EXP, or all if omitted. */
461 tracepoints_info (char *tpnum_exp
, int from_tty
)
463 struct tracepoint
*t
;
464 struct action_line
*action
;
465 int found_a_tracepoint
= 0;
466 char wrap_indent
[80];
471 tpnum
= parse_and_eval_long (tpnum_exp
);
474 if (tpnum
== -1 || tpnum
== t
->number
)
476 extern int addressprint
; /* print machine addresses? */
478 if (!found_a_tracepoint
++)
480 printf_filtered ("Num Enb ");
483 if (TARGET_ADDR_BIT
<= 32)
484 printf_filtered ("Address ");
486 printf_filtered ("Address ");
488 printf_filtered ("PassC StepC What\n");
490 strcpy (wrap_indent
, " ");
493 if (TARGET_ADDR_BIT
<= 32)
494 strcat (wrap_indent
, " ");
496 strcat (wrap_indent
, " ");
499 printf_filtered ("%-3d %-3s ", t
->number
,
500 t
->enabled
== enabled
? "y" : "n");
505 if (TARGET_ADDR_BIT
<= 32)
506 tmp
= longest_local_hex_string_custom (t
->address
507 & (CORE_ADDR
) 0xffffffff,
510 tmp
= longest_local_hex_string_custom (t
->address
, "016l");
512 printf_filtered ("%s ", tmp
);
514 printf_filtered ("%-5d %-5ld ", t
->pass_count
, t
->step_count
);
518 sym
= find_pc_sect_function (t
->address
, t
->section
);
521 fputs_filtered ("in ", gdb_stdout
);
522 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
523 wrap_here (wrap_indent
);
524 fputs_filtered (" at ", gdb_stdout
);
526 fputs_filtered (t
->source_file
, gdb_stdout
);
527 printf_filtered (":%d", t
->line_number
);
530 print_address_symbolic (t
->address
, gdb_stdout
, demangle
, " ");
532 printf_filtered ("\n");
535 printf_filtered (" Actions for tracepoint %d: \n", t
->number
);
536 for (action
= t
->actions
; action
; action
= action
->next
)
538 printf_filtered ("\t%s\n", action
->action
);
542 if (!found_a_tracepoint
)
545 printf_filtered ("No tracepoints.\n");
547 printf_filtered ("No tracepoint number %d.\n", tpnum
);
551 /* Optimization: the code to parse an enable, disable, or delete TP command
552 is virtually identical except for whether it performs an enable, disable,
553 or delete. Therefore I've combined them into one function with an opcode.
555 enum tracepoint_opcode
562 /* This function implements enable, disable and delete commands. */
564 tracepoint_operation (struct tracepoint
*t
, int from_tty
,
565 enum tracepoint_opcode opcode
)
567 struct tracepoint
*t2
;
569 if (t
== NULL
) /* no tracepoint operand */
575 t
->enabled
= enabled
;
576 if (modify_tracepoint_hook
)
577 modify_tracepoint_hook (t
);
578 tracepoint_modify_event (t
->number
);
581 t
->enabled
= disabled
;
582 if (modify_tracepoint_hook
)
583 modify_tracepoint_hook (t
);
584 tracepoint_modify_event (t
->number
);
587 if (tracepoint_chain
== t
)
588 tracepoint_chain
= t
->next
;
593 tracepoint_delete_event (t2
->number
);
598 /* Let the UI know of any deletions */
599 if (delete_tracepoint_hook
)
600 delete_tracepoint_hook (t
);
603 xfree (t
->addr_string
);
605 xfree (t
->source_file
);
614 /* Utility: parse a tracepoint number and look it up in the list.
615 If MULTI_P is true, there might be a range of tracepoints in ARG.
616 if OPTIONAL_P is true, then if the argument is missing, the most
617 recent tracepoint (tracepoint_count) is returned. */
619 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
621 struct tracepoint
*t
;
623 char *instring
= arg
== NULL
? NULL
: *arg
;
625 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
628 tpnum
= tracepoint_count
;
630 error_no_arg ("tracepoint number");
633 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
637 if (instring
&& *instring
)
638 printf_filtered ("bad tracepoint number at or near '%s'\n", instring
);
640 printf_filtered ("Tracepoint argument missing and no previous tracepoint\n");
645 if (t
->number
== tpnum
)
650 /* FIXME: if we are in the middle of a range we don't want to give
651 a message. The current interface to get_number_or_range doesn't
652 allow us to discover this. */
653 printf_unfiltered ("No tracepoint number %d.\n", tpnum
);
657 /* Utility: parse a list of tracepoint numbers, and call a func for each. */
659 map_args_over_tracepoints (char *args
, int from_tty
,
660 enum tracepoint_opcode opcode
)
662 struct tracepoint
*t
, *tmp
;
664 if (args
== 0 || *args
== 0) /* do them all */
665 ALL_TRACEPOINTS_SAFE (t
, tmp
)
666 tracepoint_operation (t
, from_tty
, opcode
);
670 QUIT
; /* give user option to bail out with ^C */
671 t
= get_tracepoint_by_number (&args
, 1, 0);
672 tracepoint_operation (t
, from_tty
, opcode
);
673 while (*args
== ' ' || *args
== '\t')
678 /* The 'enable trace' command enables tracepoints. Not supported by all targets. */
680 enable_trace_command (char *args
, int from_tty
)
683 map_args_over_tracepoints (args
, from_tty
, enable_op
);
686 /* The 'disable trace' command enables tracepoints. Not supported by all targets. */
688 disable_trace_command (char *args
, int from_tty
)
691 map_args_over_tracepoints (args
, from_tty
, disable_op
);
694 /* Remove a tracepoint (or all if no argument) */
696 delete_trace_command (char *args
, int from_tty
)
699 if (!args
|| !*args
) /* No args implies all tracepoints; */
700 if (from_tty
) /* confirm only if from_tty... */
701 if (tracepoint_chain
) /* and if there are tracepoints to delete! */
702 if (!query ("Delete all tracepoints? "))
705 map_args_over_tracepoints (args
, from_tty
, delete_op
);
708 /* Set passcount for tracepoint.
710 First command argument is passcount, second is tracepoint number.
711 If tracepoint number omitted, apply to most recently defined.
712 Also accepts special argument "all". */
715 trace_pass_command (char *args
, int from_tty
)
717 struct tracepoint
*t1
= (struct tracepoint
*) -1, *t2
;
721 if (args
== 0 || *args
== 0)
722 error ("passcount 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)
731 args
+= 3; /* skip special argument "all" */
734 error ("Junk at end of arguments.");
737 t1
= get_tracepoint_by_number (&args
, 1, 1);
744 if (t1
== (struct tracepoint
*) -1 || t1
== t2
)
746 t2
->pass_count
= count
;
747 if (modify_tracepoint_hook
)
748 modify_tracepoint_hook (t2
);
749 tracepoint_modify_event (t2
->number
);
751 printf_filtered ("Setting tracepoint %d's passcount to %d\n",
755 t1
= get_tracepoint_by_number (&args
, 1, 0);
761 /* ACTIONS functions: */
763 /* Prototypes for action-parsing utility commands */
764 static void read_actions (struct tracepoint
*);
766 /* The three functions:
767 collect_pseudocommand,
768 while_stepping_pseudocommand, and
769 end_actions_pseudocommand
770 are placeholders for "commands" that are actually ONLY to be used
771 within a tracepoint action list. If the actual function is ever called,
772 it means that somebody issued the "command" at the top level,
773 which is always an error. */
776 end_actions_pseudocommand (char *args
, int from_tty
)
778 error ("This command cannot be used at the top level.");
782 while_stepping_pseudocommand (char *args
, int from_tty
)
784 error ("This command can only be used in a tracepoint actions list.");
788 collect_pseudocommand (char *args
, int from_tty
)
790 error ("This command can only be used in a tracepoint actions list.");
793 /* Enter a list of actions for a tracepoint. */
795 trace_actions_command (char *args
, int from_tty
)
797 struct tracepoint
*t
;
799 char *end_msg
= "End with a line saying just \"end\".";
801 t
= get_tracepoint_by_number (&args
, 0, 1);
804 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
809 if (readline_begin_hook
)
810 (*readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
811 else if (input_from_terminal_p ())
812 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
816 t
->step_count
= 0; /* read_actions may set this */
819 if (readline_end_hook
)
820 (*readline_end_hook
) ();
821 /* tracepoints_changed () */
823 /* else just return */
826 /* worker function */
828 read_actions (struct tracepoint
*t
)
831 char *prompt1
= "> ", *prompt2
= " > ";
832 char *prompt
= prompt1
;
833 enum actionline_type linetype
;
834 extern FILE *instream
;
835 struct action_line
*next
= NULL
, *temp
;
836 struct cleanup
*old_chain
;
838 /* Control-C quits instantly if typed while in this loop
839 since it should not wait until the user types a newline. */
845 signal (STOP_SIGNAL
, handle_stop_sig
);
847 signal (STOP_SIGNAL
, stop_sig
);
850 old_chain
= make_cleanup_free_actions (t
);
853 /* Make sure that all output has been output. Some machines may let
854 you get away with leaving out some of the gdb_flush, but not all. */
856 gdb_flush (gdb_stdout
);
857 gdb_flush (gdb_stderr
);
859 if (readline_hook
&& instream
== NULL
)
860 line
= (*readline_hook
) (prompt
);
861 else if (instream
== stdin
&& ISATTY (instream
))
863 line
= readline (prompt
);
864 if (line
&& *line
) /* add it to command history */
868 line
= gdb_readline (0);
870 linetype
= validate_actionline (&line
, t
);
871 if (linetype
== BADLINE
)
872 continue; /* already warned -- collect another line */
874 temp
= xmalloc (sizeof (struct action_line
));
878 if (next
== NULL
) /* first action for this tracepoint? */
879 t
->actions
= next
= temp
;
886 if (linetype
== STEPPING
) /* begin "while-stepping" */
888 if (prompt
== prompt2
)
890 warning ("Already processing 'while-stepping'");
894 prompt
= prompt2
; /* change prompt for stepping actions */
896 else if (linetype
== END
)
898 if (prompt
== prompt2
)
900 prompt
= prompt1
; /* end of single-stepping actions */
903 { /* end of actions */
904 if (t
->actions
->next
== NULL
)
906 /* an "end" all by itself with no other actions means
907 this tracepoint has no actions. Discard empty list. */
916 signal (STOP_SIGNAL
, SIG_DFL
);
919 discard_cleanups (old_chain
);
922 /* worker function */
924 validate_actionline (char **line
, struct tracepoint
*t
)
926 struct cmd_list_element
*c
;
927 struct expression
*exp
= NULL
;
928 struct cleanup
*old_chain
= NULL
;
931 for (p
= *line
; isspace ((int) *p
);)
934 /* symbol lookup etc. */
935 if (*p
== '\0') /* empty line: just prompt for another line. */
938 if (*p
== '#') /* comment line */
941 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
944 warning ("'%s' is not an action that I know, or is ambiguous.", p
);
948 if (c
->function
.cfunc
== collect_pseudocommand
)
950 struct agent_expr
*aexpr
;
951 struct agent_reqs areqs
;
954 { /* repeat over a comma-separated list */
955 QUIT
; /* allow user to bail out with ^C */
956 while (isspace ((int) *p
))
959 if (*p
== '$') /* look for special pseudo-symbols */
961 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
962 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
963 (0 == strncasecmp ("loc", p
+ 1, 3)))
968 /* else fall thru, treat p as an expression and parse it! */
970 exp
= parse_exp_1 (&p
, block_for_pc (t
->address
), 1);
971 old_chain
= make_cleanup (free_current_contents
, &exp
);
973 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
975 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
977 warning ("constant %s (value %ld) will not be collected.",
978 SYMBOL_NAME (exp
->elts
[2].symbol
),
979 SYMBOL_VALUE (exp
->elts
[2].symbol
));
982 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
984 warning ("%s is optimized away and cannot be collected.",
985 SYMBOL_NAME (exp
->elts
[2].symbol
));
990 /* we have something to collect, make sure that the expr to
991 bytecode translator can handle it and that it's not too long */
992 aexpr
= gen_trace_for_expr (t
->address
, exp
);
993 make_cleanup_free_agent_expr (aexpr
);
995 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
996 error ("expression too complicated, try simplifying");
998 ax_reqs (aexpr
, &areqs
);
999 (void) make_cleanup (xfree
, areqs
.reg_mask
);
1001 if (areqs
.flaw
!= agent_flaw_none
)
1002 error ("malformed expression");
1004 if (areqs
.min_height
< 0)
1005 error ("gdb: Internal error: expression has min height < 0");
1007 if (areqs
.max_height
> 20)
1008 error ("expression too complicated, try simplifying");
1010 do_cleanups (old_chain
);
1012 while (p
&& *p
++ == ',');
1015 else if (c
->function
.cfunc
== while_stepping_pseudocommand
)
1017 char *steparg
; /* in case warning is necessary */
1019 while (isspace ((int) *p
))
1024 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
1026 warning ("'%s': bad step-count; command ignored.", *line
);
1031 else if (c
->function
.cfunc
== end_actions_pseudocommand
)
1035 warning ("'%s' is not a supported tracepoint action.", *line
);
1040 /* worker function */
1042 free_actions (struct tracepoint
*t
)
1044 struct action_line
*line
, *next
;
1046 for (line
= t
->actions
; line
; line
= next
)
1050 xfree (line
->action
);
1057 do_free_actions_cleanup (void *t
)
1062 static struct cleanup
*
1063 make_cleanup_free_actions (struct tracepoint
*t
)
1065 return make_cleanup (do_free_actions_cleanup
, t
);
1070 int type
; /* 0 for absolute memory range, else basereg number */
1071 bfd_signed_vma start
;
1075 struct collection_list
1077 unsigned char regs_mask
[8]; /* room for up to 256 regs */
1080 struct memrange
*list
;
1081 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
1082 long next_aexpr_elt
;
1083 struct agent_expr
**aexpr_list
;
1086 tracepoint_list
, stepping_list
;
1088 /* MEMRANGE functions: */
1090 static int memrange_cmp (const void *, const void *);
1092 /* compare memranges for qsort */
1094 memrange_cmp (const void *va
, const void *vb
)
1096 const struct memrange
*a
= va
, *b
= vb
;
1098 if (a
->type
< b
->type
)
1100 if (a
->type
> b
->type
)
1104 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
1106 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
1111 if (a
->start
< b
->start
)
1113 if (a
->start
> b
->start
)
1119 /* Sort the memrange list using qsort, and merge adjacent memranges */
1121 memrange_sortmerge (struct collection_list
*memranges
)
1125 qsort (memranges
->list
, memranges
->next_memrange
,
1126 sizeof (struct memrange
), memrange_cmp
);
1127 if (memranges
->next_memrange
> 0)
1129 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
1131 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
1132 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
1133 MAX_REGISTER_VIRTUAL_SIZE
)
1135 /* memrange b starts before memrange a ends; merge them. */
1136 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
1137 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
1138 continue; /* next b, same a */
1142 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
1143 sizeof (struct memrange
));
1145 memranges
->next_memrange
= a
+ 1;
1149 /* Add a register to a collection list */
1151 add_register (struct collection_list
*collection
, unsigned int regno
)
1154 printf_filtered ("collect register %d\n", regno
);
1155 if (regno
> (8 * sizeof (collection
->regs_mask
)))
1156 error ("Internal: register number %d too large for tracepoint",
1158 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
1161 /* Add a memrange to a collection list */
1163 add_memrange (struct collection_list
*memranges
, int type
, bfd_signed_vma base
,
1168 printf_filtered ("(%d,", type
);
1170 printf_filtered (",%ld)\n", len
);
1173 /* type: 0 == memory, n == basereg */
1174 memranges
->list
[memranges
->next_memrange
].type
= type
;
1175 /* base: addr if memory, offset if reg relative. */
1176 memranges
->list
[memranges
->next_memrange
].start
= base
;
1177 /* len: we actually save end (base + len) for convenience */
1178 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
1179 memranges
->next_memrange
++;
1180 if (memranges
->next_memrange
>= memranges
->listsize
)
1182 memranges
->listsize
*= 2;
1183 memranges
->list
= xrealloc (memranges
->list
,
1184 memranges
->listsize
);
1187 if (type
!= -1) /* better collect the base register! */
1188 add_register (memranges
, type
);
1191 /* Add a symbol to a collection list */
1193 collect_symbol (struct collection_list
*collect
, struct symbol
*sym
,
1194 long frame_regno
, long frame_offset
)
1198 bfd_signed_vma offset
;
1200 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
1201 switch (SYMBOL_CLASS (sym
))
1204 printf_filtered ("%s: don't know symbol class %d\n",
1205 SYMBOL_NAME (sym
), SYMBOL_CLASS (sym
));
1208 printf_filtered ("constant %s (value %ld) will not be collected.\n",
1209 SYMBOL_NAME (sym
), SYMBOL_VALUE (sym
));
1212 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1217 sprintf_vma (tmp
, offset
);
1218 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1219 SYMBOL_NAME (sym
), len
, tmp
/* address */);
1221 add_memrange (collect
, -1, offset
, len
); /* 0 == memory */
1225 reg
= SYMBOL_VALUE (sym
);
1227 printf_filtered ("LOC_REG[parm] %s: ", SYMBOL_NAME (sym
));
1228 add_register (collect
, reg
);
1229 /* check for doubles stored in two registers */
1230 /* FIXME: how about larger types stored in 3 or more regs? */
1231 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
1232 len
> REGISTER_RAW_SIZE (reg
))
1233 add_register (collect
, reg
+ 1);
1236 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1237 printf_filtered (" (will not collect %s)\n",
1242 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1245 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1246 SYMBOL_NAME (sym
), len
);
1247 printf_vma (offset
);
1248 printf_filtered (" from frame ptr reg %d\n", reg
);
1250 add_memrange (collect
, reg
, offset
, len
);
1252 case LOC_REGPARM_ADDR
:
1253 reg
= SYMBOL_VALUE (sym
);
1257 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1258 SYMBOL_NAME (sym
), len
);
1259 printf_vma (offset
);
1260 printf_filtered (" from reg %d\n", reg
);
1262 add_memrange (collect
, reg
, offset
, len
);
1267 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1270 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1271 SYMBOL_NAME (sym
), len
);
1272 printf_vma (offset
);
1273 printf_filtered (" from frame ptr reg %d\n", reg
);
1275 add_memrange (collect
, reg
, offset
, len
);
1278 case LOC_BASEREG_ARG
:
1279 reg
= SYMBOL_BASEREG (sym
);
1280 offset
= SYMBOL_VALUE (sym
);
1283 printf_filtered ("LOC_BASEREG %s: collect %ld bytes at offset ",
1284 SYMBOL_NAME (sym
), len
);
1285 printf_vma (offset
);
1286 printf_filtered (" from basereg %d\n", reg
);
1288 add_memrange (collect
, reg
, offset
, len
);
1290 case LOC_UNRESOLVED
:
1291 printf_filtered ("Don't know LOC_UNRESOLVED %s\n", SYMBOL_NAME (sym
));
1293 case LOC_OPTIMIZED_OUT
:
1294 printf_filtered ("%s has been optimized out of existence.\n",
1300 /* Add all locals (or args) symbols to collection list */
1302 add_local_symbols (struct collection_list
*collect
, CORE_ADDR pc
,
1303 long frame_regno
, long frame_offset
, int type
)
1306 struct block
*block
;
1307 int i
, nsyms
, count
= 0;
1309 block
= block_for_pc (pc
);
1312 QUIT
; /* allow user to bail out with ^C */
1313 nsyms
= BLOCK_NSYMS (block
);
1314 for (i
= 0; i
< nsyms
; i
++)
1316 sym
= BLOCK_SYM (block
, i
);
1317 switch (SYMBOL_CLASS (sym
))
1320 warning ("don't know how to trace local symbol %s",
1326 if (type
== 'L') /* collecting Locals */
1329 collect_symbol (collect
, sym
, frame_regno
, frame_offset
);
1336 case LOC_REGPARM_ADDR
:
1337 case LOC_BASEREG_ARG
:
1338 if (type
== 'A') /* collecting Arguments */
1341 collect_symbol (collect
, sym
, frame_regno
, frame_offset
);
1345 if (BLOCK_FUNCTION (block
))
1348 block
= BLOCK_SUPERBLOCK (block
);
1351 warning ("No %s found in scope.", type
== 'L' ? "locals" : "args");
1354 /* worker function */
1356 clear_collection_list (struct collection_list
*list
)
1360 list
->next_memrange
= 0;
1361 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1363 free_agent_expr (list
->aexpr_list
[ndx
]);
1364 list
->aexpr_list
[ndx
] = NULL
;
1366 list
->next_aexpr_elt
= 0;
1367 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1370 /* reduce a collection list to string form (for gdb protocol) */
1372 stringify_collection_list (struct collection_list
*list
, char *string
)
1374 char temp_buf
[2048];
1378 char *(*str_list
)[];
1382 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1383 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1385 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1386 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1388 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1391 printf_filtered ("\nCollecting registers (mask): 0x");
1396 QUIT
; /* allow user to bail out with ^C */
1398 printf_filtered ("%02X", list
->regs_mask
[i
]);
1399 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1402 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1406 printf_filtered ("\n");
1407 if (list
->next_memrange
> 0 && info_verbose
)
1408 printf_filtered ("Collecting memranges: \n");
1409 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1411 QUIT
; /* allow user to bail out with ^C */
1412 sprintf_vma (tmp2
, list
->list
[i
].start
);
1415 printf_filtered ("(%d, %s, %ld)\n",
1418 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1420 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1422 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1428 sprintf (end
, "M%X,%s,%lX",
1431 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1433 count
+= strlen (end
);
1437 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1439 QUIT
; /* allow user to bail out with ^C */
1440 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1442 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1447 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1448 end
+= 10; /* 'X' + 8 hex digits + ',' */
1451 end
= mem2hex (list
->aexpr_list
[i
]->buf
, end
, list
->aexpr_list
[i
]->len
);
1452 count
+= 2 * list
->aexpr_list
[i
]->len
;
1457 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1462 (*str_list
)[ndx
] = NULL
;
1471 free_actions_list_cleanup_wrapper (void *al
)
1473 free_actions_list (al
);
1477 free_actions_list (char **actions_list
)
1481 if (actions_list
== 0)
1484 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1485 xfree (actions_list
[ndx
]);
1487 xfree (actions_list
);
1490 /* render all actions into gdb protocol */
1492 encode_actions (struct tracepoint
*t
, char ***tdp_actions
,
1493 char ***stepping_actions
)
1495 static char tdp_buff
[2048], step_buff
[2048];
1497 struct expression
*exp
= NULL
;
1498 struct action_line
*action
;
1501 struct collection_list
*collect
;
1502 struct cmd_list_element
*cmd
;
1503 struct agent_expr
*aexpr
;
1504 long frame_reg
, frame_offset
;
1507 clear_collection_list (&tracepoint_list
);
1508 clear_collection_list (&stepping_list
);
1509 collect
= &tracepoint_list
;
1511 *tdp_actions
= NULL
;
1512 *stepping_actions
= NULL
;
1514 TARGET_VIRTUAL_FRAME_POINTER (t
->address
, &frame_reg
, &frame_offset
);
1516 for (action
= t
->actions
; action
; action
= action
->next
)
1518 QUIT
; /* allow user to bail out with ^C */
1519 action_exp
= action
->action
;
1520 while (isspace ((int) *action_exp
))
1523 if (*action_exp
== '#') /* comment line */
1526 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1528 error ("Bad action list item: %s", action_exp
);
1530 if (cmd
->function
.cfunc
== collect_pseudocommand
)
1533 { /* repeat over a comma-separated list */
1534 QUIT
; /* allow user to bail out with ^C */
1535 while (isspace ((int) *action_exp
))
1538 if (0 == strncasecmp ("$reg", action_exp
, 4))
1540 for (i
= 0; i
< NUM_REGS
; i
++)
1541 add_register (collect
, i
);
1542 action_exp
= strchr (action_exp
, ','); /* more? */
1544 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1546 add_local_symbols (collect
,
1551 action_exp
= strchr (action_exp
, ','); /* more? */
1553 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1555 add_local_symbols (collect
,
1560 action_exp
= strchr (action_exp
, ','); /* more? */
1564 unsigned long addr
, len
;
1565 struct cleanup
*old_chain
= NULL
;
1566 struct cleanup
*old_chain1
= NULL
;
1567 struct agent_reqs areqs
;
1569 exp
= parse_exp_1 (&action_exp
,
1570 block_for_pc (t
->address
), 1);
1571 old_chain
= make_cleanup (free_current_contents
, &exp
);
1573 switch (exp
->elts
[0].opcode
)
1576 i
= exp
->elts
[1].longconst
;
1578 printf_filtered ("OP_REGISTER: ");
1579 add_register (collect
, i
);
1583 /* safe because we know it's a simple expression */
1584 tempval
= evaluate_expression (exp
);
1585 addr
= VALUE_ADDRESS (tempval
) + VALUE_OFFSET (tempval
);
1586 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1587 add_memrange (collect
, -1, addr
, len
);
1591 collect_symbol (collect
,
1592 exp
->elts
[2].symbol
,
1597 default: /* full-fledged expression */
1598 aexpr
= gen_trace_for_expr (t
->address
, exp
);
1600 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1602 ax_reqs (aexpr
, &areqs
);
1603 if (areqs
.flaw
!= agent_flaw_none
)
1604 error ("malformed expression");
1606 if (areqs
.min_height
< 0)
1607 error ("gdb: Internal error: expression has min height < 0");
1608 if (areqs
.max_height
> 20)
1609 error ("expression too complicated, try simplifying");
1611 discard_cleanups (old_chain1
);
1612 add_aexpr (collect
, aexpr
);
1614 /* take care of the registers */
1615 if (areqs
.reg_mask_len
> 0)
1620 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1622 QUIT
; /* allow user to bail out with ^C */
1623 if (areqs
.reg_mask
[ndx1
] != 0)
1625 /* assume chars have 8 bits */
1626 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1627 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1628 /* it's used -- record it */
1629 add_register (collect
, ndx1
* 8 + ndx2
);
1635 do_cleanups (old_chain
);
1638 while (action_exp
&& *action_exp
++ == ',');
1640 else if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
1642 collect
= &stepping_list
;
1644 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
1646 if (collect
== &stepping_list
) /* end stepping actions */
1647 collect
= &tracepoint_list
;
1649 break; /* end tracepoint actions */
1652 memrange_sortmerge (&tracepoint_list
);
1653 memrange_sortmerge (&stepping_list
);
1655 *tdp_actions
= stringify_collection_list (&tracepoint_list
, tdp_buff
);
1656 *stepping_actions
= stringify_collection_list (&stepping_list
, step_buff
);
1660 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1662 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1664 collect
->aexpr_list
=
1665 xrealloc (collect
->aexpr_list
,
1666 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1667 collect
->aexpr_listsize
*= 2;
1669 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1670 collect
->next_aexpr_elt
++;
1673 static char target_buf
[2048];
1675 /* Set "transparent" memory ranges
1677 Allow trace mechanism to treat text-like sections
1678 (and perhaps all read-only sections) transparently,
1679 i.e. don't reject memory requests from these address ranges
1680 just because they haven't been collected. */
1683 remote_set_transparent_ranges (void)
1685 extern bfd
*exec_bfd
;
1692 return; /* no information to give. */
1694 strcpy (target_buf
, "QTro");
1695 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1697 char tmp1
[40], tmp2
[40];
1699 if ((s
->flags
& SEC_LOAD
) == 0 ||
1700 /* (s->flags & SEC_CODE) == 0 || */
1701 (s
->flags
& SEC_READONLY
) == 0)
1706 size
= bfd_get_section_size_before_reloc (s
);
1707 sprintf_vma (tmp1
, lma
);
1708 sprintf_vma (tmp2
, lma
+ size
);
1709 sprintf (target_buf
+ strlen (target_buf
),
1710 ":%s,%s", tmp1
, tmp2
);
1714 putpkt (target_buf
);
1715 getpkt (target_buf
, sizeof (target_buf
), 0);
1721 Tell target to clear any previous trace experiment.
1722 Walk the list of tracepoints, and send them (and their actions)
1723 to the target. If no errors,
1724 Tell target to start a new trace experiment. */
1727 trace_start_command (char *args
, int from_tty
)
1728 { /* STUB_COMM MOSTLY_IMPLEMENTED */
1729 struct tracepoint
*t
;
1732 char **stepping_actions
;
1734 struct cleanup
*old_chain
= NULL
;
1736 dont_repeat (); /* like "run", dangerous to repeat accidentally */
1738 if (target_is_remote ())
1741 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1742 if (strcmp (target_buf
, "OK"))
1743 error ("Target does not support this command.");
1749 sprintf_vma (tmp
, t
->address
);
1750 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
, tmp
, /* address */
1751 t
->enabled
== enabled
? 'E' : 'D',
1752 t
->step_count
, t
->pass_count
);
1757 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1758 if (strcmp (target_buf
, "OK"))
1759 error ("Target does not support tracepoints.");
1763 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1764 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1766 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
1769 /* do_single_steps (t); */
1772 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1774 QUIT
; /* allow user to bail out with ^C */
1775 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1776 t
->number
, tmp
, /* address */
1778 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1781 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1782 if (strcmp (target_buf
, "OK"))
1783 error ("Error on target while setting tracepoints.");
1786 if (stepping_actions
)
1788 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1790 QUIT
; /* allow user to bail out with ^C */
1791 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1792 t
->number
, tmp
, /* address */
1793 ((ndx
== 0) ? "S" : ""),
1794 stepping_actions
[ndx
],
1795 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1797 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1798 if (strcmp (target_buf
, "OK"))
1799 error ("Error on target while setting tracepoints.");
1803 do_cleanups (old_chain
);
1806 /* Tell target to treat text-like sections as transparent */
1807 remote_set_transparent_ranges ();
1808 /* Now insert traps and begin collecting data */
1810 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1811 if (strcmp (target_buf
, "OK"))
1812 error ("Bogus reply from target: %s", target_buf
);
1813 set_traceframe_num (-1); /* all old traceframes invalidated */
1814 set_tracepoint_num (-1);
1815 set_traceframe_context (-1);
1816 trace_running_p
= 1;
1817 if (trace_start_stop_hook
)
1818 trace_start_stop_hook (1, from_tty
);
1822 error ("Trace can only be run on remote targets.");
1827 trace_stop_command (char *args
, int from_tty
)
1828 { /* STUB_COMM IS_IMPLEMENTED */
1829 if (target_is_remote ())
1832 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1833 if (strcmp (target_buf
, "OK"))
1834 error ("Bogus reply from target: %s", target_buf
);
1835 trace_running_p
= 0;
1836 if (trace_start_stop_hook
)
1837 trace_start_stop_hook (0, from_tty
);
1840 error ("Trace can only be run on remote targets.");
1843 unsigned long trace_running_p
;
1845 /* tstatus command */
1847 trace_status_command (char *args
, int from_tty
)
1848 { /* STUB_COMM IS_IMPLEMENTED */
1849 if (target_is_remote ())
1851 putpkt ("qTStatus");
1852 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1854 if (target_buf
[0] != 'T' ||
1855 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1856 error ("Bogus reply from target: %s", target_buf
);
1858 /* exported for use by the GUI */
1859 trace_running_p
= (target_buf
[1] == '1');
1862 error ("Trace can only be run on remote targets.");
1865 /* Worker function for the various flavors of the tfind command */
1867 finish_tfind_command (char *msg
,
1871 int target_frameno
= -1, target_tracept
= -1;
1872 CORE_ADDR old_frame_addr
;
1873 struct symbol
*old_func
;
1876 old_frame_addr
= FRAME_FP (get_current_frame ());
1877 old_func
= find_pc_function (read_pc ());
1880 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1882 while (reply
&& *reply
)
1886 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1888 /* A request for a non-existant trace frame has failed.
1889 Our response will be different, depending on FROM_TTY:
1891 If FROM_TTY is true, meaning that this command was
1892 typed interactively by the user, then give an error
1893 and DO NOT change the state of traceframe_number etc.
1895 However if FROM_TTY is false, meaning that we're either
1896 in a script, a loop, or a user-defined command, then
1897 DON'T give an error, but DO change the state of
1898 traceframe_number etc. to invalid.
1900 The rationalle is that if you typed the command, you
1901 might just have committed a typo or something, and you'd
1902 like to NOT lose your current debugging state. However
1903 if you're in a user-defined command or especially in a
1904 loop, then you need a way to detect that the command
1905 failed WITHOUT aborting. This allows you to write
1906 scripts that search thru the trace buffer until the end,
1907 and then continue on to do something else. */
1910 error ("Target failed to find requested trace frame.");
1914 printf_filtered ("End of trace buffer.\n");
1915 /* The following will not recurse, since it's special-cased */
1916 trace_find_command ("-1", from_tty
);
1917 reply
= NULL
; /* break out of loop,
1918 (avoid recursive nonsense) */
1923 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1924 error ("Target failed to find requested trace frame.");
1926 case 'O': /* "OK"? */
1927 if (reply
[1] == 'K' && reply
[2] == '\0')
1930 error ("Bogus reply from target: %s", reply
);
1933 error ("Bogus reply from target: %s", reply
);
1936 flush_cached_frames ();
1937 registers_changed ();
1938 select_frame (get_current_frame (), 0);
1939 set_traceframe_num (target_frameno
);
1940 set_tracepoint_num (target_tracept
);
1941 if (target_frameno
== -1)
1942 set_traceframe_context (-1);
1944 set_traceframe_context (read_pc ());
1950 /* NOTE: in immitation of the step command, try to determine
1951 whether we have made a transition from one function to another.
1952 If so, we'll print the "stack frame" (ie. the new function and
1953 it's arguments) -- otherwise we'll just show the new source line.
1955 This determination is made by checking (1) whether the current
1956 function has changed, and (2) whether the current FP has changed.
1957 Hack: if the FP wasn't collected, either at the current or the
1958 previous frame, assume that the FP has NOT changed. */
1960 if (old_func
== find_pc_function (read_pc ()) &&
1961 (old_frame_addr
== 0 ||
1962 FRAME_FP (get_current_frame ()) == 0 ||
1963 old_frame_addr
== FRAME_FP (get_current_frame ())))
1968 print_stack_frame (selected_frame
, selected_frame_level
, source_only
);
1973 /* trace_find_command takes a trace frame number n,
1974 sends "QTFrame:<n>" to the target,
1975 and accepts a reply that may contain several optional pieces
1976 of information: a frame number, a tracepoint number, and an
1977 indication of whether this is a trap frame or a stepping frame.
1979 The minimal response is just "OK" (which indicates that the
1980 target does not give us a frame number or a tracepoint number).
1981 Instead of that, the target may send us a string containing
1983 F<hexnum> (gives the selected frame number)
1984 T<hexnum> (gives the selected tracepoint number)
1989 trace_find_command (char *args
, int from_tty
)
1990 { /* STUB_COMM PART_IMPLEMENTED */
1991 /* this should only be called with a numeric argument */
1994 if (target_is_remote ())
1996 if (trace_find_hook
)
1997 trace_find_hook (args
, from_tty
);
1999 if (args
== 0 || *args
== 0)
2000 { /* TFIND with no args means find NEXT trace frame. */
2001 if (traceframe_number
== -1)
2002 frameno
= 0; /* "next" is first one */
2004 frameno
= traceframe_number
+ 1;
2006 else if (0 == strcmp (args
, "-"))
2008 if (traceframe_number
== -1)
2009 error ("not debugging trace buffer");
2010 else if (from_tty
&& traceframe_number
== 0)
2011 error ("already at start of trace buffer");
2013 frameno
= traceframe_number
- 1;
2016 frameno
= parse_and_eval_long (args
);
2019 error ("invalid input (%d is less than zero)", frameno
);
2021 sprintf (target_buf
, "QTFrame:%x", frameno
);
2022 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2025 error ("Trace can only be run on remote targets.");
2030 trace_find_end_command (char *args
, int from_tty
)
2032 trace_find_command ("-1", from_tty
);
2037 trace_find_none_command (char *args
, int from_tty
)
2039 trace_find_command ("-1", from_tty
);
2044 trace_find_start_command (char *args
, int from_tty
)
2046 trace_find_command ("0", from_tty
);
2049 /* tfind pc command */
2051 trace_find_pc_command (char *args
, int from_tty
)
2052 { /* STUB_COMM PART_IMPLEMENTED */
2056 if (target_is_remote ())
2058 if (args
== 0 || *args
== 0)
2059 pc
= read_pc (); /* default is current pc */
2061 pc
= parse_and_eval_address (args
);
2063 sprintf_vma (tmp
, pc
);
2064 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
2065 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2068 error ("Trace can only be run on remote targets.");
2071 /* tfind tracepoint command */
2073 trace_find_tracepoint_command (char *args
, int from_tty
)
2074 { /* STUB_COMM PART_IMPLEMENTED */
2077 if (target_is_remote ())
2079 if (args
== 0 || *args
== 0)
2080 if (tracepoint_number
== -1)
2081 error ("No current tracepoint -- please supply an argument.");
2083 tdp
= tracepoint_number
; /* default is current TDP */
2085 tdp
= parse_and_eval_long (args
);
2087 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
2088 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2091 error ("Trace can only be run on remote targets.");
2094 /* TFIND LINE command:
2096 This command will take a sourceline for argument, just like BREAK
2097 or TRACE (ie. anything that "decode_line_1" can handle).
2099 With no argument, this command will find the next trace frame
2100 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2103 trace_find_line_command (char *args
, int from_tty
)
2104 { /* STUB_COMM PART_IMPLEMENTED */
2105 static CORE_ADDR start_pc
, end_pc
;
2106 struct symtabs_and_lines sals
;
2107 struct symtab_and_line sal
;
2108 struct cleanup
*old_chain
;
2109 char startpc_str
[40], endpc_str
[40];
2111 if (target_is_remote ())
2113 if (args
== 0 || *args
== 0)
2115 sal
= find_pc_line ((get_current_frame ())->pc
, 0);
2117 sals
.sals
= (struct symtab_and_line
*)
2118 xmalloc (sizeof (struct symtab_and_line
));
2123 sals
= decode_line_spec (args
, 1);
2127 old_chain
= make_cleanup (xfree
, sals
.sals
);
2128 if (sal
.symtab
== 0)
2130 printf_filtered ("TFIND: No line number information available");
2133 /* This is useful for "info line *0x7f34". If we can't tell the
2134 user about a source line, at least let them have the symbolic
2136 printf_filtered (" for address ");
2138 print_address (sal
.pc
, gdb_stdout
);
2139 printf_filtered (";\n -- will attempt to find by PC. \n");
2143 printf_filtered (".\n");
2144 return; /* no line, no PC; what can we do? */
2147 else if (sal
.line
> 0
2148 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2150 if (start_pc
== end_pc
)
2152 printf_filtered ("Line %d of \"%s\"",
2153 sal
.line
, sal
.symtab
->filename
);
2155 printf_filtered (" is at address ");
2156 print_address (start_pc
, gdb_stdout
);
2158 printf_filtered (" but contains no code.\n");
2159 sal
= find_pc_line (start_pc
, 0);
2161 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
2163 printf_filtered ("Attempting to find line %d instead.\n",
2166 error ("Cannot find a good line.");
2170 /* Is there any case in which we get here, and have an address
2171 which the user would want to see? If we have debugging symbols
2172 and no line numbers? */
2173 error ("Line number %d is out of range for \"%s\".\n",
2174 sal
.line
, sal
.symtab
->filename
);
2176 sprintf_vma (startpc_str
, start_pc
);
2177 sprintf_vma (endpc_str
, end_pc
- 1);
2178 if (args
&& *args
) /* find within range of stated line */
2179 sprintf (target_buf
, "QTFrame:range:%s:%s", startpc_str
, endpc_str
);
2180 else /* find OUTSIDE OF range of CURRENT line */
2181 sprintf (target_buf
, "QTFrame:outside:%s:%s", startpc_str
, endpc_str
);
2182 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2183 do_cleanups (old_chain
);
2186 error ("Trace can only be run on remote targets.");
2189 /* tfind range command */
2191 trace_find_range_command (char *args
, int from_tty
)
2193 static CORE_ADDR start
, stop
;
2194 char start_str
[40], stop_str
[40];
2197 if (target_is_remote ())
2199 if (args
== 0 || *args
== 0)
2200 { /* XXX FIXME: what should default behavior be? */
2201 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2205 if (0 != (tmp
= strchr (args
, ',')))
2207 *tmp
++ = '\0'; /* terminate start address */
2208 while (isspace ((int) *tmp
))
2210 start
= parse_and_eval_address (args
);
2211 stop
= parse_and_eval_address (tmp
);
2214 { /* no explicit end address? */
2215 start
= parse_and_eval_address (args
);
2216 stop
= start
+ 1; /* ??? */
2219 sprintf_vma (start_str
, start
);
2220 sprintf_vma (stop_str
, stop
);
2221 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
2222 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2225 error ("Trace can only be run on remote targets.");
2228 /* tfind outside command */
2230 trace_find_outside_command (char *args
, int from_tty
)
2232 CORE_ADDR start
, stop
;
2233 char start_str
[40], stop_str
[40];
2236 if (target_is_remote ())
2238 if (args
== 0 || *args
== 0)
2239 { /* XXX FIXME: what should default behavior be? */
2240 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2244 if (0 != (tmp
= strchr (args
, ',')))
2246 *tmp
++ = '\0'; /* terminate start address */
2247 while (isspace ((int) *tmp
))
2249 start
= parse_and_eval_address (args
);
2250 stop
= parse_and_eval_address (tmp
);
2253 { /* no explicit end address? */
2254 start
= parse_and_eval_address (args
);
2255 stop
= start
+ 1; /* ??? */
2258 sprintf_vma (start_str
, start
);
2259 sprintf_vma (stop_str
, stop
);
2260 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
2261 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2264 error ("Trace can only be run on remote targets.");
2267 /* save-tracepoints command */
2269 tracepoint_save_command (char *args
, int from_tty
)
2271 struct tracepoint
*tp
;
2272 struct action_line
*line
;
2274 char *i1
= " ", *i2
= " ";
2275 char *indent
, *actionline
;
2278 if (args
== 0 || *args
== 0)
2279 error ("Argument required (file name in which to save tracepoints");
2281 if (tracepoint_chain
== 0)
2283 warning ("save-tracepoints: no tracepoints to save.\n");
2287 if (!(fp
= fopen (args
, "w")))
2288 error ("Unable to open file '%s' for saving tracepoints");
2290 ALL_TRACEPOINTS (tp
)
2292 if (tp
->addr_string
)
2293 fprintf (fp
, "trace %s\n", tp
->addr_string
);
2296 sprintf_vma (tmp
, tp
->address
);
2297 fprintf (fp
, "trace *0x%s\n", tmp
);
2301 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
2305 fprintf (fp
, " actions\n");
2307 for (line
= tp
->actions
; line
; line
= line
->next
)
2309 struct cmd_list_element
*cmd
;
2311 QUIT
; /* allow user to bail out with ^C */
2312 actionline
= line
->action
;
2313 while (isspace ((int) *actionline
))
2316 fprintf (fp
, "%s%s\n", indent
, actionline
);
2317 if (*actionline
!= '#') /* skip for comment lines */
2319 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
2321 error ("Bad action list item: %s", actionline
);
2322 if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
2324 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
2332 printf_filtered ("Tracepoints saved to file '%s'.\n", args
);
2336 /* info scope command: list the locals for a scope. */
2338 scope_info (char *args
, int from_tty
)
2340 struct symtabs_and_lines sals
;
2342 struct minimal_symbol
*msym
;
2343 struct block
*block
;
2344 char **canonical
, *symname
, *save_args
= args
;
2345 int i
, j
, nsyms
, count
= 0;
2347 if (args
== 0 || *args
== 0)
2348 error ("requires an argument (function, line or *addr) to define a scope");
2350 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2351 if (sals
.nelts
== 0)
2352 return; /* presumably decode_line_1 has already warned */
2354 /* Resolve line numbers to PC */
2355 resolve_sal_pc (&sals
.sals
[0]);
2356 block
= block_for_pc (sals
.sals
[0].pc
);
2360 QUIT
; /* allow user to bail out with ^C */
2361 nsyms
= BLOCK_NSYMS (block
);
2362 for (i
= 0; i
< nsyms
; i
++)
2364 QUIT
; /* allow user to bail out with ^C */
2366 printf_filtered ("Scope for %s:\n", save_args
);
2368 sym
= BLOCK_SYM (block
, i
);
2369 symname
= SYMBOL_NAME (sym
);
2370 if (symname
== NULL
|| *symname
== '\0')
2371 continue; /* probably botched, certainly useless */
2373 printf_filtered ("Symbol %s is ", symname
);
2374 switch (SYMBOL_CLASS (sym
))
2377 case LOC_UNDEF
: /* messed up symbol? */
2378 printf_filtered ("a bogus symbol, class %d.\n",
2379 SYMBOL_CLASS (sym
));
2380 count
--; /* don't count this one */
2383 printf_filtered ("a constant with value %ld (0x%lx)",
2384 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2386 case LOC_CONST_BYTES
:
2387 printf_filtered ("constant bytes: ");
2388 if (SYMBOL_TYPE (sym
))
2389 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2390 fprintf_filtered (gdb_stdout
, " %02x",
2391 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2394 printf_filtered ("in static storage at address ");
2395 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2398 printf_filtered ("a local variable in register $%s",
2399 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2403 printf_filtered ("an argument at stack/frame offset %ld",
2404 SYMBOL_VALUE (sym
));
2407 printf_filtered ("a local variable at frame offset %ld",
2408 SYMBOL_VALUE (sym
));
2411 printf_filtered ("a reference argument at offset %ld",
2412 SYMBOL_VALUE (sym
));
2415 printf_filtered ("an argument in register $%s",
2416 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2418 case LOC_REGPARM_ADDR
:
2419 printf_filtered ("the address of an argument, in register $%s",
2420 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2423 printf_filtered ("a typedef.\n");
2426 printf_filtered ("a label at address ");
2427 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2430 printf_filtered ("a function at address ");
2431 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)), 1,
2435 printf_filtered ("a variable at offset %ld from register $%s",
2437 REGISTER_NAME (SYMBOL_BASEREG (sym
)));
2439 case LOC_BASEREG_ARG
:
2440 printf_filtered ("an argument at offset %ld from register $%s",
2442 REGISTER_NAME (SYMBOL_BASEREG (sym
)));
2444 case LOC_UNRESOLVED
:
2445 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
2447 printf_filtered ("Unresolved Static");
2450 printf_filtered ("static storage at address ");
2451 print_address_numeric (SYMBOL_VALUE_ADDRESS (msym
), 1,
2455 case LOC_OPTIMIZED_OUT
:
2456 printf_filtered ("optimized out.\n");
2459 if (SYMBOL_TYPE (sym
))
2460 printf_filtered (", length %d.\n",
2461 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2463 if (BLOCK_FUNCTION (block
))
2466 block
= BLOCK_SUPERBLOCK (block
);
2469 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2473 /* worker function (cleanup) */
2475 replace_comma (void *data
)
2483 trace_dump_command (char *args
, int from_tty
)
2485 struct tracepoint
*t
;
2486 struct action_line
*action
;
2487 char *action_exp
, *next_comma
;
2488 struct cleanup
*old_cleanups
;
2489 int stepping_actions
= 0;
2490 int stepping_frame
= 0;
2492 if (!target_is_remote ())
2494 error ("Trace can only be run on remote targets.");
2498 if (tracepoint_number
== -1)
2500 warning ("No current trace frame.");
2505 if (t
->number
== tracepoint_number
)
2509 error ("No known tracepoint matches 'current' tracepoint #%d.",
2512 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2514 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2515 tracepoint_number
, traceframe_number
);
2517 /* The current frame is a trap frame if the frame PC is equal
2518 to the tracepoint PC. If not, then the current frame was
2519 collected during single-stepping. */
2521 stepping_frame
= (t
->address
!= read_pc ());
2523 for (action
= t
->actions
; action
; action
= action
->next
)
2525 struct cmd_list_element
*cmd
;
2527 QUIT
; /* allow user to bail out with ^C */
2528 action_exp
= action
->action
;
2529 while (isspace ((int) *action_exp
))
2532 /* The collection actions to be done while stepping are
2533 bracketed by the commands "while-stepping" and "end". */
2535 if (*action_exp
== '#') /* comment line */
2538 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2540 error ("Bad action list item: %s", action_exp
);
2542 if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
2543 stepping_actions
= 1;
2544 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
2545 stepping_actions
= 0;
2546 else if (cmd
->function
.cfunc
== collect_pseudocommand
)
2548 /* Display the collected data.
2549 For the trap frame, display only what was collected at the trap.
2550 Likewise for stepping frames, display only what was collected
2551 while stepping. This means that the two boolean variables,
2552 STEPPING_FRAME and STEPPING_ACTIONS should be equal. */
2553 if (stepping_frame
== stepping_actions
)
2556 { /* repeat over a comma-separated list */
2557 QUIT
; /* allow user to bail out with ^C */
2558 if (*action_exp
== ',')
2560 while (isspace ((int) *action_exp
))
2563 next_comma
= strchr (action_exp
, ',');
2565 if (0 == strncasecmp (action_exp
, "$reg", 4))
2566 registers_info (NULL
, from_tty
);
2567 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2568 locals_info (NULL
, from_tty
);
2569 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2570 args_info (NULL
, from_tty
);
2575 make_cleanup (replace_comma
, next_comma
);
2578 printf_filtered ("%s = ", action_exp
);
2579 output_command (action_exp
, from_tty
);
2580 printf_filtered ("\n");
2584 action_exp
= next_comma
;
2586 while (action_exp
&& *action_exp
== ',');
2590 discard_cleanups (old_cleanups
);
2593 /* Convert the memory pointed to by mem into hex, placing result in buf.
2594 * Return a pointer to the last char put in buf (null)
2595 * "stolen" from sparc-stub.c
2598 static const char hexchars
[] = "0123456789abcdef";
2600 static unsigned char *
2601 mem2hex (unsigned char *mem
, unsigned char *buf
, int count
)
2609 *buf
++ = hexchars
[ch
>> 4];
2610 *buf
++ = hexchars
[ch
& 0xf];
2619 get_traceframe_number (void)
2621 return traceframe_number
;
2625 /* module initialization */
2627 _initialize_tracepoint (void)
2629 struct cmd_list_element
*c
;
2631 tracepoint_chain
= 0;
2632 tracepoint_count
= 0;
2633 traceframe_number
= -1;
2634 tracepoint_number
= -1;
2636 set_internalvar (lookup_internalvar ("tpnum"),
2637 value_from_longest (builtin_type_int
, (LONGEST
) 0));
2638 set_internalvar (lookup_internalvar ("trace_frame"),
2639 value_from_longest (builtin_type_int
, (LONGEST
) - 1));
2641 if (tracepoint_list
.list
== NULL
)
2643 tracepoint_list
.listsize
= 128;
2644 tracepoint_list
.list
= xmalloc
2645 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2647 if (tracepoint_list
.aexpr_list
== NULL
)
2649 tracepoint_list
.aexpr_listsize
= 128;
2650 tracepoint_list
.aexpr_list
= xmalloc
2651 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2654 if (stepping_list
.list
== NULL
)
2656 stepping_list
.listsize
= 128;
2657 stepping_list
.list
= xmalloc
2658 (stepping_list
.listsize
* sizeof (struct memrange
));
2661 if (stepping_list
.aexpr_list
== NULL
)
2663 stepping_list
.aexpr_listsize
= 128;
2664 stepping_list
.aexpr_list
= xmalloc
2665 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2668 add_info ("scope", scope_info
,
2669 "List the variables local to a scope");
2671 add_cmd ("tracepoints", class_trace
, NO_FUNCTION
,
2672 "Tracing of program execution without stopping the program.",
2675 add_info ("tracepoints", tracepoints_info
,
2676 "Status of tracepoints, or tracepoint number NUMBER.\n\
2677 Convenience variable \"$tpnum\" contains the number of the\n\
2678 last tracepoint set.");
2680 add_info_alias ("tp", "tracepoints", 1);
2682 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
,
2683 "Save current tracepoint definitions as a script.\n\
2684 Use the 'source' command in another debug session to restore them.");
2685 c
->completer
= filename_completer
;
2687 add_com ("tdump", class_trace
, trace_dump_command
,
2688 "Print everything collected at the current tracepoint.");
2690 add_prefix_cmd ("tfind", class_trace
, trace_find_command
,
2691 "Select a trace frame;\n\
2692 No argument means forward by one frame; '-' meand backward by one frame.",
2693 &tfindlist
, "tfind ", 1, &cmdlist
);
2695 add_cmd ("outside", class_trace
, trace_find_outside_command
,
2696 "Select a trace frame whose PC is outside the given \
2697 range.\nUsage: tfind outside addr1, addr2",
2700 add_cmd ("range", class_trace
, trace_find_range_command
,
2701 "Select a trace frame whose PC is in the given range.\n\
2702 Usage: tfind range addr1,addr2",
2705 add_cmd ("line", class_trace
, trace_find_line_command
,
2706 "Select a trace frame by source line.\n\
2707 Argument can be a line number (with optional source file), \n\
2708 a function name, or '*' followed by an address.\n\
2709 Default argument is 'the next source line that was traced'.",
2712 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
,
2713 "Select a trace frame by tracepoint number.\n\
2714 Default is the tracepoint for the current trace frame.",
2717 add_cmd ("pc", class_trace
, trace_find_pc_command
,
2718 "Select a trace frame by PC.\n\
2719 Default is the current PC, or the PC of the current trace frame.",
2722 add_cmd ("end", class_trace
, trace_find_end_command
,
2723 "Synonym for 'none'.\n\
2724 De-select any trace frame and resume 'live' debugging.",
2727 add_cmd ("none", class_trace
, trace_find_none_command
,
2728 "De-select any trace frame and resume 'live' debugging.",
2731 add_cmd ("start", class_trace
, trace_find_start_command
,
2732 "Select the first trace frame in the trace buffer.",
2735 add_com ("tstatus", class_trace
, trace_status_command
,
2736 "Display the status of the current trace data collection.");
2738 add_com ("tstop", class_trace
, trace_stop_command
,
2739 "Stop trace data collection.");
2741 add_com ("tstart", class_trace
, trace_start_command
,
2742 "Start trace data collection.");
2744 add_com ("passcount", class_trace
, trace_pass_command
,
2745 "Set the passcount for a tracepoint.\n\
2746 The trace will end when the tracepoint has been passed 'count' times.\n\
2747 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
2748 if TPNUM is omitted, passcount refers to the last tracepoint defined.");
2750 add_com ("end", class_trace
, end_actions_pseudocommand
,
2751 "Ends a list of commands or actions.\n\
2752 Several GDB commands allow you to enter a list of commands or actions.\n\
2753 Entering \"end\" on a line by itself is the normal way to terminate\n\
2755 Note: the \"end\" command cannot be used at the gdb prompt.");
2757 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
,
2758 "Specify single-stepping behavior at a tracepoint.\n\
2759 Argument is number of instructions to trace in single-step mode\n\
2760 following the tracepoint. This command is normally followed by\n\
2761 one or more \"collect\" commands, to specify what to collect\n\
2762 while single-stepping.\n\n\
2763 Note: this command can only be used in a tracepoint \"actions\" list.");
2765 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2766 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2768 add_com ("collect", class_trace
, collect_pseudocommand
,
2769 "Specify one or more data items to be collected at a tracepoint.\n\
2770 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2771 collect all data (variables, registers) referenced by that expression.\n\
2772 Also accepts the following special arguments:\n\
2773 $regs -- all registers.\n\
2774 $args -- all function arguments.\n\
2775 $locals -- all variables local to the block/function scope.\n\
2776 Note: this command can only be used in a tracepoint \"actions\" list.");
2778 add_com ("actions", class_trace
, trace_actions_command
,
2779 "Specify the actions to be taken at a tracepoint.\n\
2780 Tracepoint actions may include collecting of specified data, \n\
2781 single-stepping, or enabling/disabling other tracepoints, \n\
2782 depending on target's capabilities.");
2784 add_cmd ("tracepoints", class_trace
, delete_trace_command
,
2785 "Delete specified tracepoints.\n\
2786 Arguments are tracepoint numbers, separated by spaces.\n\
2787 No argument means delete all tracepoints.",
2790 add_cmd ("tracepoints", class_trace
, disable_trace_command
,
2791 "Disable specified tracepoints.\n\
2792 Arguments are tracepoint numbers, separated by spaces.\n\
2793 No argument means disable all tracepoints.",
2796 add_cmd ("tracepoints", class_trace
, enable_trace_command
,
2797 "Enable specified tracepoints.\n\
2798 Arguments are tracepoint numbers, separated by spaces.\n\
2799 No argument means enable all tracepoints.",
2802 add_com ("trace", class_trace
, trace_command
,
2803 "Set a tracepoint at a specified line or function or address.\n\
2804 Argument may be a line number, function name, or '*' plus an address.\n\
2805 For a line number or function, trace at the start of its code.\n\
2806 If an address is specified, trace at that exact address.\n\n\
2807 Do \"help tracepoints\" for info on other tracepoint commands.");
2809 add_com_alias ("tp", "trace", class_alias
, 0);
2810 add_com_alias ("tr", "trace", class_alias
, 1);
2811 add_com_alias ("tra", "trace", class_alias
, 1);
2812 add_com_alias ("trac", "trace", class_alias
, 1);