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"
35 #include "completer.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 ");
482 printf_filtered ("Address ");
483 printf_filtered ("PassC StepC What\n");
485 strcpy (wrap_indent
, " ");
487 strcat (wrap_indent
, " ");
489 printf_filtered ("%-3d %-3s ", t
->number
,
490 t
->enabled
== enabled
? "y" : "n");
492 printf_filtered ("%s ",
493 local_hex_string_custom ((unsigned long) t
->address
,
495 printf_filtered ("%-5d %-5ld ", t
->pass_count
, t
->step_count
);
499 sym
= find_pc_sect_function (t
->address
, t
->section
);
502 fputs_filtered ("in ", gdb_stdout
);
503 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
504 wrap_here (wrap_indent
);
505 fputs_filtered (" at ", gdb_stdout
);
507 fputs_filtered (t
->source_file
, gdb_stdout
);
508 printf_filtered (":%d", t
->line_number
);
511 print_address_symbolic (t
->address
, gdb_stdout
, demangle
, " ");
513 printf_filtered ("\n");
516 printf_filtered (" Actions for tracepoint %d: \n", t
->number
);
517 for (action
= t
->actions
; action
; action
= action
->next
)
519 printf_filtered ("\t%s\n", action
->action
);
523 if (!found_a_tracepoint
)
526 printf_filtered ("No tracepoints.\n");
528 printf_filtered ("No tracepoint number %d.\n", tpnum
);
532 /* Optimization: the code to parse an enable, disable, or delete TP command
533 is virtually identical except for whether it performs an enable, disable,
534 or delete. Therefore I've combined them into one function with an opcode.
536 enum tracepoint_opcode
543 /* This function implements enable, disable and delete commands. */
545 tracepoint_operation (struct tracepoint
*t
, int from_tty
,
546 enum tracepoint_opcode opcode
)
548 struct tracepoint
*t2
;
550 if (t
== NULL
) /* no tracepoint operand */
556 t
->enabled
= enabled
;
557 if (modify_tracepoint_hook
)
558 modify_tracepoint_hook (t
);
561 t
->enabled
= disabled
;
562 if (modify_tracepoint_hook
)
563 modify_tracepoint_hook (t
);
566 if (tracepoint_chain
== t
)
567 tracepoint_chain
= t
->next
;
576 /* Let the UI know of any deletions */
577 if (delete_tracepoint_hook
)
578 delete_tracepoint_hook (t
);
581 xfree (t
->addr_string
);
583 xfree (t
->source_file
);
592 /* Utility: parse a tracepoint number and look it up in the list.
593 If MULTI_P is true, there might be a range of tracepoints in ARG.
594 if OPTIONAL_P is true, then if the argument is missing, the most
595 recent tracepoint (tracepoint_count) is returned. */
597 get_tracepoint_by_number (char **arg
, int multi_p
, int optional_p
)
599 struct tracepoint
*t
;
601 char *instring
= arg
== NULL
? NULL
: *arg
;
603 if (arg
== NULL
|| *arg
== NULL
|| ! **arg
)
606 tpnum
= tracepoint_count
;
608 error_no_arg ("tracepoint number");
611 tpnum
= multi_p
? get_number_or_range (arg
) : get_number (arg
);
615 if (instring
&& *instring
)
616 printf_filtered ("bad tracepoint number at or near '%s'\n", instring
);
618 printf_filtered ("Tracepoint argument missing and no previous tracepoint\n");
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 (char *args
, int from_tty
,
638 enum tracepoint_opcode opcode
)
640 struct tracepoint
*t
, *tmp
;
642 if (args
== 0 || *args
== 0) /* do them all */
643 ALL_TRACEPOINTS_SAFE (t
, tmp
)
644 tracepoint_operation (t
, from_tty
, opcode
);
648 QUIT
; /* give user option to bail out with ^C */
649 t
= get_tracepoint_by_number (&args
, 1, 0);
650 tracepoint_operation (t
, from_tty
, opcode
);
651 while (*args
== ' ' || *args
== '\t')
656 /* The 'enable trace' command enables tracepoints. Not supported by all targets. */
658 enable_trace_command (char *args
, int from_tty
)
661 map_args_over_tracepoints (args
, from_tty
, enable_op
);
664 /* The 'disable trace' command enables tracepoints. Not supported by all targets. */
666 disable_trace_command (char *args
, int from_tty
)
669 map_args_over_tracepoints (args
, from_tty
, disable_op
);
672 /* Remove a tracepoint (or all if no argument) */
674 delete_trace_command (char *args
, int from_tty
)
677 if (!args
|| !*args
) /* No args implies all tracepoints; */
678 if (from_tty
) /* confirm only if from_tty... */
679 if (tracepoint_chain
) /* and if there are tracepoints to delete! */
680 if (!query ("Delete all tracepoints? "))
683 map_args_over_tracepoints (args
, from_tty
, delete_op
);
686 /* Set passcount for tracepoint.
688 First command argument is passcount, second is tracepoint number.
689 If tracepoint number omitted, apply to most recently defined.
690 Also accepts special argument "all". */
693 trace_pass_command (char *args
, int from_tty
)
695 struct tracepoint
*t1
= (struct tracepoint
*) -1, *t2
;
699 if (args
== 0 || *args
== 0)
700 error ("passcount command requires an argument (count + optional TP num)");
702 count
= strtoul (args
, &args
, 10); /* count comes first, then TP num */
704 while (*args
&& isspace ((int) *args
))
707 if (*args
&& strncasecmp (args
, "all", 3) == 0)
709 args
+= 3; /* skip special argument "all" */
712 error ("Junk at end of arguments.");
715 t1
= get_tracepoint_by_number (&args
, 1, 1);
722 if (t1
== (struct tracepoint
*) -1 || t1
== t2
)
724 t2
->pass_count
= count
;
725 if (modify_tracepoint_hook
)
726 modify_tracepoint_hook (t2
);
728 printf_filtered ("Setting tracepoint %d's passcount to %d\n",
732 t1
= get_tracepoint_by_number (&args
, 1, 0);
738 /* ACTIONS functions: */
740 /* Prototypes for action-parsing utility commands */
741 static void read_actions (struct tracepoint
*);
743 /* The three functions:
744 collect_pseudocommand,
745 while_stepping_pseudocommand, and
746 end_actions_pseudocommand
747 are placeholders for "commands" that are actually ONLY to be used
748 within a tracepoint action list. If the actual function is ever called,
749 it means that somebody issued the "command" at the top level,
750 which is always an error. */
753 end_actions_pseudocommand (char *args
, int from_tty
)
755 error ("This command cannot be used at the top level.");
759 while_stepping_pseudocommand (char *args
, int from_tty
)
761 error ("This command can only be used in a tracepoint actions list.");
765 collect_pseudocommand (char *args
, int from_tty
)
767 error ("This command can only be used in a tracepoint actions list.");
770 /* Enter a list of actions for a tracepoint. */
772 trace_actions_command (char *args
, int from_tty
)
774 struct tracepoint
*t
;
776 char *end_msg
= "End with a line saying just \"end\".";
778 t
= get_tracepoint_by_number (&args
, 0, 1);
781 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
786 if (readline_begin_hook
)
787 (*readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
788 else if (input_from_terminal_p ())
789 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
793 t
->step_count
= 0; /* read_actions may set this */
796 if (readline_end_hook
)
797 (*readline_end_hook
) ();
798 /* tracepoints_changed () */
800 /* else just return */
803 /* worker function */
805 read_actions (struct tracepoint
*t
)
808 char *prompt1
= "> ", *prompt2
= " > ";
809 char *prompt
= prompt1
;
810 enum actionline_type linetype
;
811 extern FILE *instream
;
812 struct action_line
*next
= NULL
, *temp
;
813 struct cleanup
*old_chain
;
815 /* Control-C quits instantly if typed while in this loop
816 since it should not wait until the user types a newline. */
822 signal (STOP_SIGNAL
, handle_stop_sig
);
824 signal (STOP_SIGNAL
, stop_sig
);
827 old_chain
= make_cleanup_free_actions (t
);
830 /* Make sure that all output has been output. Some machines may let
831 you get away with leaving out some of the gdb_flush, but not all. */
833 gdb_flush (gdb_stdout
);
834 gdb_flush (gdb_stderr
);
836 if (readline_hook
&& instream
== NULL
)
837 line
= (*readline_hook
) (prompt
);
838 else if (instream
== stdin
&& ISATTY (instream
))
840 line
= readline (prompt
);
841 if (line
&& *line
) /* add it to command history */
845 line
= gdb_readline (0);
847 linetype
= validate_actionline (&line
, t
);
848 if (linetype
== BADLINE
)
849 continue; /* already warned -- collect another line */
851 temp
= xmalloc (sizeof (struct action_line
));
855 if (next
== NULL
) /* first action for this tracepoint? */
856 t
->actions
= next
= temp
;
863 if (linetype
== STEPPING
) /* begin "while-stepping" */
865 if (prompt
== prompt2
)
867 warning ("Already processing 'while-stepping'");
871 prompt
= prompt2
; /* change prompt for stepping actions */
873 else if (linetype
== END
)
875 if (prompt
== prompt2
)
877 prompt
= prompt1
; /* end of single-stepping actions */
880 { /* end of actions */
881 if (t
->actions
->next
== NULL
)
883 /* an "end" all by itself with no other actions means
884 this tracepoint has no actions. Discard empty list. */
893 signal (STOP_SIGNAL
, SIG_DFL
);
896 discard_cleanups (old_chain
);
899 /* worker function */
901 validate_actionline (char **line
, struct tracepoint
*t
)
903 struct cmd_list_element
*c
;
904 struct expression
*exp
= NULL
;
905 struct cleanup
*old_chain
= NULL
;
908 for (p
= *line
; isspace ((int) *p
);)
911 /* symbol lookup etc. */
912 if (*p
== '\0') /* empty line: just prompt for another line. */
915 if (*p
== '#') /* comment line */
918 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
921 warning ("'%s' is not an action that I know, or is ambiguous.", p
);
925 if (c
->function
.cfunc
== collect_pseudocommand
)
927 struct agent_expr
*aexpr
;
928 struct agent_reqs areqs
;
931 { /* repeat over a comma-separated list */
932 QUIT
; /* allow user to bail out with ^C */
933 while (isspace ((int) *p
))
936 if (*p
== '$') /* look for special pseudo-symbols */
938 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
939 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
940 (0 == strncasecmp ("loc", p
+ 1, 3)))
945 /* else fall thru, treat p as an expression and parse it! */
947 exp
= parse_exp_1 (&p
, block_for_pc (t
->address
), 1);
948 old_chain
= make_cleanup (free_current_contents
, &exp
);
950 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
952 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
954 warning ("constant %s (value %ld) will not be collected.",
955 SYMBOL_NAME (exp
->elts
[2].symbol
),
956 SYMBOL_VALUE (exp
->elts
[2].symbol
));
959 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
961 warning ("%s is optimized away and cannot be collected.",
962 SYMBOL_NAME (exp
->elts
[2].symbol
));
967 /* we have something to collect, make sure that the expr to
968 bytecode translator can handle it and that it's not too long */
969 aexpr
= gen_trace_for_expr (t
->address
, exp
);
970 make_cleanup_free_agent_expr (aexpr
);
972 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
973 error ("expression too complicated, try simplifying");
975 ax_reqs (aexpr
, &areqs
);
976 (void) make_cleanup (xfree
, areqs
.reg_mask
);
978 if (areqs
.flaw
!= agent_flaw_none
)
979 error ("malformed expression");
981 if (areqs
.min_height
< 0)
982 error ("gdb: Internal error: expression has min height < 0");
984 if (areqs
.max_height
> 20)
985 error ("expression too complicated, try simplifying");
987 do_cleanups (old_chain
);
989 while (p
&& *p
++ == ',');
992 else if (c
->function
.cfunc
== while_stepping_pseudocommand
)
994 char *steparg
; /* in case warning is necessary */
996 while (isspace ((int) *p
))
1001 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
1003 warning ("'%s': bad step-count; command ignored.", *line
);
1008 else if (c
->function
.cfunc
== end_actions_pseudocommand
)
1012 warning ("'%s' is not a supported tracepoint action.", *line
);
1017 /* worker function */
1019 free_actions (struct tracepoint
*t
)
1021 struct action_line
*line
, *next
;
1023 for (line
= t
->actions
; line
; line
= next
)
1027 xfree (line
->action
);
1034 do_free_actions_cleanup (void *t
)
1039 static struct cleanup
*
1040 make_cleanup_free_actions (struct tracepoint
*t
)
1042 return make_cleanup (do_free_actions_cleanup
, t
);
1047 int type
; /* 0 for absolute memory range, else basereg number */
1048 bfd_signed_vma start
;
1052 struct collection_list
1054 unsigned char regs_mask
[8]; /* room for up to 256 regs */
1057 struct memrange
*list
;
1058 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
1059 long next_aexpr_elt
;
1060 struct agent_expr
**aexpr_list
;
1063 tracepoint_list
, stepping_list
;
1065 /* MEMRANGE functions: */
1067 static int memrange_cmp (const void *, const void *);
1069 /* compare memranges for qsort */
1071 memrange_cmp (const void *va
, const void *vb
)
1073 const struct memrange
*a
= va
, *b
= vb
;
1075 if (a
->type
< b
->type
)
1077 if (a
->type
> b
->type
)
1081 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
1083 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
1088 if (a
->start
< b
->start
)
1090 if (a
->start
> b
->start
)
1096 /* Sort the memrange list using qsort, and merge adjacent memranges */
1098 memrange_sortmerge (struct collection_list
*memranges
)
1102 qsort (memranges
->list
, memranges
->next_memrange
,
1103 sizeof (struct memrange
), memrange_cmp
);
1104 if (memranges
->next_memrange
> 0)
1106 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
1108 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
1109 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
1110 MAX_REGISTER_VIRTUAL_SIZE
)
1112 /* memrange b starts before memrange a ends; merge them. */
1113 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
1114 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
1115 continue; /* next b, same a */
1119 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
1120 sizeof (struct memrange
));
1122 memranges
->next_memrange
= a
+ 1;
1126 /* Add a register to a collection list */
1128 add_register (struct collection_list
*collection
, unsigned int regno
)
1131 printf_filtered ("collect register %d\n", regno
);
1132 if (regno
> (8 * sizeof (collection
->regs_mask
)))
1133 error ("Internal: register number %d too large for tracepoint",
1135 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
1138 /* Add a memrange to a collection list */
1140 add_memrange (struct collection_list
*memranges
, int type
, bfd_signed_vma base
,
1145 printf_filtered ("(%d,", type
);
1147 printf_filtered (",%ld)\n", len
);
1150 /* type: 0 == memory, n == basereg */
1151 memranges
->list
[memranges
->next_memrange
].type
= type
;
1152 /* base: addr if memory, offset if reg relative. */
1153 memranges
->list
[memranges
->next_memrange
].start
= base
;
1154 /* len: we actually save end (base + len) for convenience */
1155 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
1156 memranges
->next_memrange
++;
1157 if (memranges
->next_memrange
>= memranges
->listsize
)
1159 memranges
->listsize
*= 2;
1160 memranges
->list
= xrealloc (memranges
->list
,
1161 memranges
->listsize
);
1164 if (type
!= -1) /* better collect the base register! */
1165 add_register (memranges
, type
);
1168 /* Add a symbol to a collection list */
1170 collect_symbol (struct collection_list
*collect
, struct symbol
*sym
,
1171 long frame_regno
, long frame_offset
)
1175 bfd_signed_vma offset
;
1177 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
1178 switch (SYMBOL_CLASS (sym
))
1181 printf_filtered ("%s: don't know symbol class %d\n",
1182 SYMBOL_NAME (sym
), SYMBOL_CLASS (sym
));
1185 printf_filtered ("constant %s (value %ld) will not be collected.\n",
1186 SYMBOL_NAME (sym
), SYMBOL_VALUE (sym
));
1189 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1194 sprintf_vma (tmp
, offset
);
1195 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1196 SYMBOL_NAME (sym
), len
, tmp
/* address */);
1198 add_memrange (collect
, -1, offset
, len
); /* 0 == memory */
1202 reg
= SYMBOL_VALUE (sym
);
1204 printf_filtered ("LOC_REG[parm] %s: ", SYMBOL_NAME (sym
));
1205 add_register (collect
, reg
);
1206 /* check for doubles stored in two registers */
1207 /* FIXME: how about larger types stored in 3 or more regs? */
1208 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
1209 len
> REGISTER_RAW_SIZE (reg
))
1210 add_register (collect
, reg
+ 1);
1213 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1214 printf_filtered (" (will not collect %s)\n",
1219 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1222 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1223 SYMBOL_NAME (sym
), len
);
1224 printf_vma (offset
);
1225 printf_filtered (" from frame ptr reg %d\n", reg
);
1227 add_memrange (collect
, reg
, offset
, len
);
1229 case LOC_REGPARM_ADDR
:
1230 reg
= SYMBOL_VALUE (sym
);
1234 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1235 SYMBOL_NAME (sym
), len
);
1236 printf_vma (offset
);
1237 printf_filtered (" from reg %d\n", reg
);
1239 add_memrange (collect
, reg
, offset
, len
);
1244 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1247 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1248 SYMBOL_NAME (sym
), len
);
1249 printf_vma (offset
);
1250 printf_filtered (" from frame ptr reg %d\n", reg
);
1252 add_memrange (collect
, reg
, offset
, len
);
1255 case LOC_BASEREG_ARG
:
1256 reg
= SYMBOL_BASEREG (sym
);
1257 offset
= SYMBOL_VALUE (sym
);
1260 printf_filtered ("LOC_BASEREG %s: collect %ld bytes at offset ",
1261 SYMBOL_NAME (sym
), len
);
1262 printf_vma (offset
);
1263 printf_filtered (" from basereg %d\n", reg
);
1265 add_memrange (collect
, reg
, offset
, len
);
1267 case LOC_UNRESOLVED
:
1268 printf_filtered ("Don't know LOC_UNRESOLVED %s\n", SYMBOL_NAME (sym
));
1270 case LOC_OPTIMIZED_OUT
:
1271 printf_filtered ("%s has been optimized out of existence.\n",
1277 /* Add all locals (or args) symbols to collection list */
1279 add_local_symbols (struct collection_list
*collect
, CORE_ADDR pc
,
1280 long frame_regno
, long frame_offset
, int type
)
1283 struct block
*block
;
1284 int i
, nsyms
, count
= 0;
1286 block
= block_for_pc (pc
);
1289 QUIT
; /* allow user to bail out with ^C */
1290 nsyms
= BLOCK_NSYMS (block
);
1291 for (i
= 0; i
< nsyms
; i
++)
1293 sym
= BLOCK_SYM (block
, i
);
1294 switch (SYMBOL_CLASS (sym
))
1297 warning ("don't know how to trace local symbol %s",
1303 if (type
== 'L') /* collecting Locals */
1306 collect_symbol (collect
, sym
, frame_regno
, frame_offset
);
1313 case LOC_REGPARM_ADDR
:
1314 case LOC_BASEREG_ARG
:
1315 if (type
== 'A') /* collecting Arguments */
1318 collect_symbol (collect
, sym
, frame_regno
, frame_offset
);
1322 if (BLOCK_FUNCTION (block
))
1325 block
= BLOCK_SUPERBLOCK (block
);
1328 warning ("No %s found in scope.", type
== 'L' ? "locals" : "args");
1331 /* worker function */
1333 clear_collection_list (struct collection_list
*list
)
1337 list
->next_memrange
= 0;
1338 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1340 free_agent_expr (list
->aexpr_list
[ndx
]);
1341 list
->aexpr_list
[ndx
] = NULL
;
1343 list
->next_aexpr_elt
= 0;
1344 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1347 /* reduce a collection list to string form (for gdb protocol) */
1349 stringify_collection_list (struct collection_list
*list
, char *string
)
1351 char temp_buf
[2048];
1355 char *(*str_list
)[];
1359 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1360 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1362 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1363 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1365 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1368 printf_filtered ("\nCollecting registers (mask): 0x");
1373 QUIT
; /* allow user to bail out with ^C */
1375 printf_filtered ("%02X", list
->regs_mask
[i
]);
1376 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1379 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
1383 printf_filtered ("\n");
1384 if (list
->next_memrange
> 0 && info_verbose
)
1385 printf_filtered ("Collecting memranges: \n");
1386 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1388 QUIT
; /* allow user to bail out with ^C */
1389 sprintf_vma (tmp2
, list
->list
[i
].start
);
1392 printf_filtered ("(%d, %s, %ld)\n",
1395 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1397 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1399 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1405 sprintf (end
, "M%X,%s,%lX",
1408 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1410 count
+= strlen (end
);
1414 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1416 QUIT
; /* allow user to bail out with ^C */
1417 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1419 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1424 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1425 end
+= 10; /* 'X' + 8 hex digits + ',' */
1428 end
= mem2hex (list
->aexpr_list
[i
]->buf
, end
, list
->aexpr_list
[i
]->len
);
1429 count
+= 2 * list
->aexpr_list
[i
]->len
;
1434 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1439 (*str_list
)[ndx
] = NULL
;
1448 free_actions_list_cleanup_wrapper (void *al
)
1450 free_actions_list (al
);
1454 free_actions_list (char **actions_list
)
1458 if (actions_list
== 0)
1461 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1462 xfree (actions_list
[ndx
]);
1464 xfree (actions_list
);
1467 /* render all actions into gdb protocol */
1469 encode_actions (struct tracepoint
*t
, char ***tdp_actions
,
1470 char ***stepping_actions
)
1472 static char tdp_buff
[2048], step_buff
[2048];
1474 struct expression
*exp
= NULL
;
1475 struct action_line
*action
;
1478 struct collection_list
*collect
;
1479 struct cmd_list_element
*cmd
;
1480 struct agent_expr
*aexpr
;
1481 long frame_reg
, frame_offset
;
1484 clear_collection_list (&tracepoint_list
);
1485 clear_collection_list (&stepping_list
);
1486 collect
= &tracepoint_list
;
1488 *tdp_actions
= NULL
;
1489 *stepping_actions
= NULL
;
1491 TARGET_VIRTUAL_FRAME_POINTER (t
->address
, &frame_reg
, &frame_offset
);
1493 for (action
= t
->actions
; action
; action
= action
->next
)
1495 QUIT
; /* allow user to bail out with ^C */
1496 action_exp
= action
->action
;
1497 while (isspace ((int) *action_exp
))
1500 if (*action_exp
== '#') /* comment line */
1503 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1505 error ("Bad action list item: %s", action_exp
);
1507 if (cmd
->function
.cfunc
== collect_pseudocommand
)
1510 { /* repeat over a comma-separated list */
1511 QUIT
; /* allow user to bail out with ^C */
1512 while (isspace ((int) *action_exp
))
1515 if (0 == strncasecmp ("$reg", action_exp
, 4))
1517 for (i
= 0; i
< NUM_REGS
; i
++)
1518 add_register (collect
, i
);
1519 action_exp
= strchr (action_exp
, ','); /* more? */
1521 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1523 add_local_symbols (collect
,
1528 action_exp
= strchr (action_exp
, ','); /* more? */
1530 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1532 add_local_symbols (collect
,
1537 action_exp
= strchr (action_exp
, ','); /* more? */
1541 unsigned long addr
, len
;
1542 struct cleanup
*old_chain
= NULL
;
1543 struct cleanup
*old_chain1
= NULL
;
1544 struct agent_reqs areqs
;
1546 exp
= parse_exp_1 (&action_exp
, block_for_pc (t
->address
), 1);
1547 old_chain
= make_cleanup (free_current_contents
, &exp
);
1549 switch (exp
->elts
[0].opcode
)
1552 i
= exp
->elts
[1].longconst
;
1554 printf_filtered ("OP_REGISTER: ");
1555 add_register (collect
, i
);
1559 /* safe because we know it's a simple expression */
1560 tempval
= evaluate_expression (exp
);
1561 addr
= VALUE_ADDRESS (tempval
) + VALUE_OFFSET (tempval
);
1562 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1563 add_memrange (collect
, -1, addr
, len
);
1567 collect_symbol (collect
,
1568 exp
->elts
[2].symbol
,
1573 default: /* full-fledged expression */
1574 aexpr
= gen_trace_for_expr (t
->address
, exp
);
1576 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1578 ax_reqs (aexpr
, &areqs
);
1579 if (areqs
.flaw
!= agent_flaw_none
)
1580 error ("malformed expression");
1582 if (areqs
.min_height
< 0)
1583 error ("gdb: Internal error: expression has min height < 0");
1584 if (areqs
.max_height
> 20)
1585 error ("expression too complicated, try simplifying");
1587 discard_cleanups (old_chain1
);
1588 add_aexpr (collect
, aexpr
);
1590 /* take care of the registers */
1591 if (areqs
.reg_mask_len
> 0)
1596 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1598 QUIT
; /* allow user to bail out with ^C */
1599 if (areqs
.reg_mask
[ndx1
] != 0)
1601 /* assume chars have 8 bits */
1602 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1603 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1604 /* it's used -- record it */
1605 add_register (collect
, ndx1
* 8 + ndx2
);
1611 do_cleanups (old_chain
);
1614 while (action_exp
&& *action_exp
++ == ',');
1616 else if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
1618 collect
= &stepping_list
;
1620 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
1622 if (collect
== &stepping_list
) /* end stepping actions */
1623 collect
= &tracepoint_list
;
1625 break; /* end tracepoint actions */
1628 memrange_sortmerge (&tracepoint_list
);
1629 memrange_sortmerge (&stepping_list
);
1631 *tdp_actions
= stringify_collection_list (&tracepoint_list
, tdp_buff
);
1632 *stepping_actions
= stringify_collection_list (&stepping_list
, step_buff
);
1636 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1638 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1640 collect
->aexpr_list
=
1641 xrealloc (collect
->aexpr_list
,
1642 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1643 collect
->aexpr_listsize
*= 2;
1645 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1646 collect
->next_aexpr_elt
++;
1649 static char target_buf
[2048];
1651 /* Set "transparent" memory ranges
1653 Allow trace mechanism to treat text-like sections
1654 (and perhaps all read-only sections) transparently,
1655 i.e. don't reject memory requests from these address ranges
1656 just because they haven't been collected. */
1659 remote_set_transparent_ranges (void)
1661 extern bfd
*exec_bfd
;
1668 return; /* no information to give. */
1670 strcpy (target_buf
, "QTro");
1671 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1673 char tmp1
[40], tmp2
[40];
1675 if ((s
->flags
& SEC_LOAD
) == 0 ||
1676 /* (s->flags & SEC_CODE) == 0 || */
1677 (s
->flags
& SEC_READONLY
) == 0)
1682 size
= bfd_get_section_size_before_reloc (s
);
1683 sprintf_vma (tmp1
, lma
);
1684 sprintf_vma (tmp2
, lma
+ size
);
1685 sprintf (target_buf
+ strlen (target_buf
),
1686 ":%s,%s", tmp1
, tmp2
);
1690 putpkt (target_buf
);
1691 getpkt (target_buf
, sizeof (target_buf
), 0);
1697 Tell target to clear any previous trace experiment.
1698 Walk the list of tracepoints, and send them (and their actions)
1699 to the target. If no errors,
1700 Tell target to start a new trace experiment. */
1703 trace_start_command (char *args
, int from_tty
)
1704 { /* STUB_COMM MOSTLY_IMPLEMENTED */
1705 struct tracepoint
*t
;
1708 char **stepping_actions
;
1710 struct cleanup
*old_chain
= NULL
;
1712 dont_repeat (); /* like "run", dangerous to repeat accidentally */
1714 if (target_is_remote ())
1717 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1718 if (strcmp (target_buf
, "OK"))
1719 error ("Target does not support this command.");
1725 sprintf_vma (tmp
, t
->address
);
1726 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
, tmp
, /* address */
1727 t
->enabled
== enabled
? 'E' : 'D',
1728 t
->step_count
, t
->pass_count
);
1733 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1734 if (strcmp (target_buf
, "OK"))
1735 error ("Target does not support tracepoints.");
1739 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1740 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1742 (void) make_cleanup (free_actions_list_cleanup_wrapper
,
1745 /* do_single_steps (t); */
1748 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1750 QUIT
; /* allow user to bail out with ^C */
1751 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1752 t
->number
, tmp
, /* address */
1754 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1757 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1758 if (strcmp (target_buf
, "OK"))
1759 error ("Error on target while setting tracepoints.");
1762 if (stepping_actions
)
1764 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1766 QUIT
; /* allow user to bail out with ^C */
1767 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1768 t
->number
, tmp
, /* address */
1769 ((ndx
== 0) ? "S" : ""),
1770 stepping_actions
[ndx
],
1771 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1773 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1774 if (strcmp (target_buf
, "OK"))
1775 error ("Error on target while setting tracepoints.");
1779 do_cleanups (old_chain
);
1782 /* Tell target to treat text-like sections as transparent */
1783 remote_set_transparent_ranges ();
1784 /* Now insert traps and begin collecting data */
1786 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1787 if (strcmp (target_buf
, "OK"))
1788 error ("Bogus reply from target: %s", target_buf
);
1789 set_traceframe_num (-1); /* all old traceframes invalidated */
1790 set_tracepoint_num (-1);
1791 set_traceframe_context (-1);
1792 trace_running_p
= 1;
1793 if (trace_start_stop_hook
)
1794 trace_start_stop_hook (1, from_tty
);
1798 error ("Trace can only be run on remote targets.");
1803 trace_stop_command (char *args
, int from_tty
)
1804 { /* STUB_COMM IS_IMPLEMENTED */
1805 if (target_is_remote ())
1808 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1809 if (strcmp (target_buf
, "OK"))
1810 error ("Bogus reply from target: %s", target_buf
);
1811 trace_running_p
= 0;
1812 if (trace_start_stop_hook
)
1813 trace_start_stop_hook (0, from_tty
);
1816 error ("Trace can only be run on remote targets.");
1819 unsigned long trace_running_p
;
1821 /* tstatus command */
1823 trace_status_command (char *args
, int from_tty
)
1824 { /* STUB_COMM IS_IMPLEMENTED */
1825 if (target_is_remote ())
1827 putpkt ("qTStatus");
1828 remote_get_noisy_reply (target_buf
, sizeof (target_buf
));
1830 if (target_buf
[0] != 'T' ||
1831 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1832 error ("Bogus reply from target: %s", target_buf
);
1834 /* exported for use by the GUI */
1835 trace_running_p
= (target_buf
[1] == '1');
1838 error ("Trace can only be run on remote targets.");
1841 /* Worker function for the various flavors of the tfind command */
1843 finish_tfind_command (char *msg
,
1847 int target_frameno
= -1, target_tracept
= -1;
1848 CORE_ADDR old_frame_addr
;
1849 struct symbol
*old_func
;
1852 old_frame_addr
= FRAME_FP (get_current_frame ());
1853 old_func
= find_pc_function (read_pc ());
1856 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1858 while (reply
&& *reply
)
1862 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1864 /* A request for a non-existant trace frame has failed.
1865 Our response will be different, depending on FROM_TTY:
1867 If FROM_TTY is true, meaning that this command was
1868 typed interactively by the user, then give an error
1869 and DO NOT change the state of traceframe_number etc.
1871 However if FROM_TTY is false, meaning that we're either
1872 in a script, a loop, or a user-defined command, then
1873 DON'T give an error, but DO change the state of
1874 traceframe_number etc. to invalid.
1876 The rationalle is that if you typed the command, you
1877 might just have committed a typo or something, and you'd
1878 like to NOT lose your current debugging state. However
1879 if you're in a user-defined command or especially in a
1880 loop, then you need a way to detect that the command
1881 failed WITHOUT aborting. This allows you to write
1882 scripts that search thru the trace buffer until the end,
1883 and then continue on to do something else. */
1886 error ("Target failed to find requested trace frame.");
1890 printf_filtered ("End of trace buffer.\n");
1891 /* The following will not recurse, since it's special-cased */
1892 trace_find_command ("-1", from_tty
);
1893 reply
= NULL
; /* break out of loop,
1894 (avoid recursive nonsense) */
1899 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1900 error ("Target failed to find requested trace frame.");
1902 case 'O': /* "OK"? */
1903 if (reply
[1] == 'K' && reply
[2] == '\0')
1906 error ("Bogus reply from target: %s", reply
);
1909 error ("Bogus reply from target: %s", reply
);
1912 flush_cached_frames ();
1913 registers_changed ();
1914 select_frame (get_current_frame (), 0);
1915 set_traceframe_num (target_frameno
);
1916 set_tracepoint_num (target_tracept
);
1917 if (target_frameno
== -1)
1918 set_traceframe_context (-1);
1920 set_traceframe_context (read_pc ());
1926 /* NOTE: in immitation of the step command, try to determine
1927 whether we have made a transition from one function to another.
1928 If so, we'll print the "stack frame" (ie. the new function and
1929 it's arguments) -- otherwise we'll just show the new source line.
1931 This determination is made by checking (1) whether the current
1932 function has changed, and (2) whether the current FP has changed.
1933 Hack: if the FP wasn't collected, either at the current or the
1934 previous frame, assume that the FP has NOT changed. */
1936 if (old_func
== find_pc_function (read_pc ()) &&
1937 (old_frame_addr
== 0 ||
1938 FRAME_FP (get_current_frame ()) == 0 ||
1939 old_frame_addr
== FRAME_FP (get_current_frame ())))
1944 print_stack_frame (selected_frame
, selected_frame_level
, source_only
);
1949 /* trace_find_command takes a trace frame number n,
1950 sends "QTFrame:<n>" to the target,
1951 and accepts a reply that may contain several optional pieces
1952 of information: a frame number, a tracepoint number, and an
1953 indication of whether this is a trap frame or a stepping frame.
1955 The minimal response is just "OK" (which indicates that the
1956 target does not give us a frame number or a tracepoint number).
1957 Instead of that, the target may send us a string containing
1959 F<hexnum> (gives the selected frame number)
1960 T<hexnum> (gives the selected tracepoint number)
1965 trace_find_command (char *args
, int from_tty
)
1966 { /* STUB_COMM PART_IMPLEMENTED */
1967 /* this should only be called with a numeric argument */
1970 if (target_is_remote ())
1972 if (trace_find_hook
)
1973 trace_find_hook (args
, from_tty
);
1975 if (args
== 0 || *args
== 0)
1976 { /* TFIND with no args means find NEXT trace frame. */
1977 if (traceframe_number
== -1)
1978 frameno
= 0; /* "next" is first one */
1980 frameno
= traceframe_number
+ 1;
1982 else if (0 == strcmp (args
, "-"))
1984 if (traceframe_number
== -1)
1985 error ("not debugging trace buffer");
1986 else if (from_tty
&& traceframe_number
== 0)
1987 error ("already at start of trace buffer");
1989 frameno
= traceframe_number
- 1;
1992 frameno
= parse_and_eval_long (args
);
1995 error ("invalid input (%d is less than zero)", frameno
);
1997 sprintf (target_buf
, "QTFrame:%x", frameno
);
1998 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2001 error ("Trace can only be run on remote targets.");
2006 trace_find_end_command (char *args
, int from_tty
)
2008 trace_find_command ("-1", from_tty
);
2013 trace_find_none_command (char *args
, int from_tty
)
2015 trace_find_command ("-1", from_tty
);
2020 trace_find_start_command (char *args
, int from_tty
)
2022 trace_find_command ("0", from_tty
);
2025 /* tfind pc command */
2027 trace_find_pc_command (char *args
, int from_tty
)
2028 { /* STUB_COMM PART_IMPLEMENTED */
2032 if (target_is_remote ())
2034 if (args
== 0 || *args
== 0)
2035 pc
= read_pc (); /* default is current pc */
2037 pc
= parse_and_eval_address (args
);
2039 sprintf_vma (tmp
, pc
);
2040 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
2041 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2044 error ("Trace can only be run on remote targets.");
2047 /* tfind tracepoint command */
2049 trace_find_tracepoint_command (char *args
, int from_tty
)
2050 { /* STUB_COMM PART_IMPLEMENTED */
2053 if (target_is_remote ())
2055 if (args
== 0 || *args
== 0)
2056 if (tracepoint_number
== -1)
2057 error ("No current tracepoint -- please supply an argument.");
2059 tdp
= tracepoint_number
; /* default is current TDP */
2061 tdp
= parse_and_eval_long (args
);
2063 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
2064 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2067 error ("Trace can only be run on remote targets.");
2070 /* TFIND LINE command:
2072 This command will take a sourceline for argument, just like BREAK
2073 or TRACE (ie. anything that "decode_line_1" can handle).
2075 With no argument, this command will find the next trace frame
2076 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2079 trace_find_line_command (char *args
, int from_tty
)
2080 { /* STUB_COMM PART_IMPLEMENTED */
2081 static CORE_ADDR start_pc
, end_pc
;
2082 struct symtabs_and_lines sals
;
2083 struct symtab_and_line sal
;
2084 struct cleanup
*old_chain
;
2085 char startpc_str
[40], endpc_str
[40];
2087 if (target_is_remote ())
2089 if (args
== 0 || *args
== 0)
2091 sal
= find_pc_line ((get_current_frame ())->pc
, 0);
2093 sals
.sals
= (struct symtab_and_line
*)
2094 xmalloc (sizeof (struct symtab_and_line
));
2099 sals
= decode_line_spec (args
, 1);
2103 old_chain
= make_cleanup (xfree
, sals
.sals
);
2104 if (sal
.symtab
== 0)
2106 printf_filtered ("TFIND: No line number information available");
2109 /* This is useful for "info line *0x7f34". If we can't tell the
2110 user about a source line, at least let them have the symbolic
2112 printf_filtered (" for address ");
2114 print_address (sal
.pc
, gdb_stdout
);
2115 printf_filtered (";\n -- will attempt to find by PC. \n");
2119 printf_filtered (".\n");
2120 return; /* no line, no PC; what can we do? */
2123 else if (sal
.line
> 0
2124 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2126 if (start_pc
== end_pc
)
2128 printf_filtered ("Line %d of \"%s\"",
2129 sal
.line
, sal
.symtab
->filename
);
2131 printf_filtered (" is at address ");
2132 print_address (start_pc
, gdb_stdout
);
2134 printf_filtered (" but contains no code.\n");
2135 sal
= find_pc_line (start_pc
, 0);
2137 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
2139 printf_filtered ("Attempting to find line %d instead.\n",
2142 error ("Cannot find a good line.");
2146 /* Is there any case in which we get here, and have an address
2147 which the user would want to see? If we have debugging symbols
2148 and no line numbers? */
2149 error ("Line number %d is out of range for \"%s\".\n",
2150 sal
.line
, sal
.symtab
->filename
);
2152 sprintf_vma (startpc_str
, start_pc
);
2153 sprintf_vma (endpc_str
, end_pc
- 1);
2154 if (args
&& *args
) /* find within range of stated line */
2155 sprintf (target_buf
, "QTFrame:range:%s:%s", startpc_str
, endpc_str
);
2156 else /* find OUTSIDE OF range of CURRENT line */
2157 sprintf (target_buf
, "QTFrame:outside:%s:%s", startpc_str
, endpc_str
);
2158 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2159 do_cleanups (old_chain
);
2162 error ("Trace can only be run on remote targets.");
2165 /* tfind range command */
2167 trace_find_range_command (char *args
, int from_tty
)
2169 static CORE_ADDR start
, stop
;
2170 char start_str
[40], stop_str
[40];
2173 if (target_is_remote ())
2175 if (args
== 0 || *args
== 0)
2176 { /* XXX FIXME: what should default behavior be? */
2177 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2181 if (0 != (tmp
= strchr (args
, ',')))
2183 *tmp
++ = '\0'; /* terminate start address */
2184 while (isspace ((int) *tmp
))
2186 start
= parse_and_eval_address (args
);
2187 stop
= parse_and_eval_address (tmp
);
2190 { /* no explicit end address? */
2191 start
= parse_and_eval_address (args
);
2192 stop
= start
+ 1; /* ??? */
2195 sprintf_vma (start_str
, start
);
2196 sprintf_vma (stop_str
, stop
);
2197 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
2198 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2201 error ("Trace can only be run on remote targets.");
2204 /* tfind outside command */
2206 trace_find_outside_command (char *args
, int from_tty
)
2208 CORE_ADDR start
, stop
;
2209 char start_str
[40], stop_str
[40];
2212 if (target_is_remote ())
2214 if (args
== 0 || *args
== 0)
2215 { /* XXX FIXME: what should default behavior be? */
2216 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2220 if (0 != (tmp
= strchr (args
, ',')))
2222 *tmp
++ = '\0'; /* terminate start address */
2223 while (isspace ((int) *tmp
))
2225 start
= parse_and_eval_address (args
);
2226 stop
= parse_and_eval_address (tmp
);
2229 { /* no explicit end address? */
2230 start
= parse_and_eval_address (args
);
2231 stop
= start
+ 1; /* ??? */
2234 sprintf_vma (start_str
, start
);
2235 sprintf_vma (stop_str
, stop
);
2236 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
2237 finish_tfind_command (target_buf
, sizeof (target_buf
), from_tty
);
2240 error ("Trace can only be run on remote targets.");
2243 /* save-tracepoints command */
2245 tracepoint_save_command (char *args
, int from_tty
)
2247 struct tracepoint
*tp
;
2248 struct action_line
*line
;
2250 char *i1
= " ", *i2
= " ";
2251 char *indent
, *actionline
;
2254 if (args
== 0 || *args
== 0)
2255 error ("Argument required (file name in which to save tracepoints");
2257 if (tracepoint_chain
== 0)
2259 warning ("save-tracepoints: no tracepoints to save.\n");
2263 if (!(fp
= fopen (args
, "w")))
2264 error ("Unable to open file '%s' for saving tracepoints");
2266 ALL_TRACEPOINTS (tp
)
2268 if (tp
->addr_string
)
2269 fprintf (fp
, "trace %s\n", tp
->addr_string
);
2272 sprintf_vma (tmp
, tp
->address
);
2273 fprintf (fp
, "trace *0x%s\n", tmp
);
2277 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
2281 fprintf (fp
, " actions\n");
2283 for (line
= tp
->actions
; line
; line
= line
->next
)
2285 struct cmd_list_element
*cmd
;
2287 QUIT
; /* allow user to bail out with ^C */
2288 actionline
= line
->action
;
2289 while (isspace ((int) *actionline
))
2292 fprintf (fp
, "%s%s\n", indent
, actionline
);
2293 if (*actionline
!= '#') /* skip for comment lines */
2295 cmd
= lookup_cmd (&actionline
, cmdlist
, "", -1, 1);
2297 error ("Bad action list item: %s", actionline
);
2298 if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
2300 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
2308 printf_filtered ("Tracepoints saved to file '%s'.\n", args
);
2312 /* info scope command: list the locals for a scope. */
2314 scope_info (char *args
, int from_tty
)
2316 struct symtabs_and_lines sals
;
2318 struct minimal_symbol
*msym
;
2319 struct block
*block
;
2320 char **canonical
, *symname
, *save_args
= args
;
2321 int i
, j
, nsyms
, count
= 0;
2323 if (args
== 0 || *args
== 0)
2324 error ("requires an argument (function, line or *addr) to define a scope");
2326 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2327 if (sals
.nelts
== 0)
2328 return; /* presumably decode_line_1 has already warned */
2330 /* Resolve line numbers to PC */
2331 resolve_sal_pc (&sals
.sals
[0]);
2332 block
= block_for_pc (sals
.sals
[0].pc
);
2336 QUIT
; /* allow user to bail out with ^C */
2337 nsyms
= BLOCK_NSYMS (block
);
2338 for (i
= 0; i
< nsyms
; i
++)
2340 QUIT
; /* allow user to bail out with ^C */
2342 printf_filtered ("Scope for %s:\n", save_args
);
2344 sym
= BLOCK_SYM (block
, i
);
2345 symname
= SYMBOL_NAME (sym
);
2346 if (symname
== NULL
|| *symname
== '\0')
2347 continue; /* probably botched, certainly useless */
2349 printf_filtered ("Symbol %s is ", symname
);
2350 switch (SYMBOL_CLASS (sym
))
2353 case LOC_UNDEF
: /* messed up symbol? */
2354 printf_filtered ("a bogus symbol, class %d.\n",
2355 SYMBOL_CLASS (sym
));
2356 count
--; /* don't count this one */
2359 printf_filtered ("a constant with value %ld (0x%lx)",
2360 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2362 case LOC_CONST_BYTES
:
2363 printf_filtered ("constant bytes: ");
2364 if (SYMBOL_TYPE (sym
))
2365 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2366 fprintf_filtered (gdb_stdout
, " %02x",
2367 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2370 printf_filtered ("in static storage at address ");
2371 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2374 printf_filtered ("a local variable in register $%s",
2375 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2379 printf_filtered ("an argument at stack/frame offset %ld",
2380 SYMBOL_VALUE (sym
));
2383 printf_filtered ("a local variable at frame offset %ld",
2384 SYMBOL_VALUE (sym
));
2387 printf_filtered ("a reference argument at offset %ld",
2388 SYMBOL_VALUE (sym
));
2391 printf_filtered ("an argument in register $%s",
2392 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2394 case LOC_REGPARM_ADDR
:
2395 printf_filtered ("the address of an argument, in register $%s",
2396 REGISTER_NAME (SYMBOL_VALUE (sym
)));
2399 printf_filtered ("a typedef.\n");
2402 printf_filtered ("a label at address ");
2403 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2406 printf_filtered ("a function at address ");
2407 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)), 1,
2411 printf_filtered ("a variable at offset %ld from register $%s",
2413 REGISTER_NAME (SYMBOL_BASEREG (sym
)));
2415 case LOC_BASEREG_ARG
:
2416 printf_filtered ("an argument at offset %ld from register $%s",
2418 REGISTER_NAME (SYMBOL_BASEREG (sym
)));
2420 case LOC_UNRESOLVED
:
2421 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
2423 printf_filtered ("Unresolved Static");
2426 printf_filtered ("static storage at address ");
2427 print_address_numeric (SYMBOL_VALUE_ADDRESS (msym
), 1,
2431 case LOC_OPTIMIZED_OUT
:
2432 printf_filtered ("optimized out.\n");
2435 if (SYMBOL_TYPE (sym
))
2436 printf_filtered (", length %d.\n",
2437 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2439 if (BLOCK_FUNCTION (block
))
2442 block
= BLOCK_SUPERBLOCK (block
);
2445 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2449 /* worker function (cleanup) */
2451 replace_comma (void *data
)
2459 trace_dump_command (char *args
, int from_tty
)
2461 struct tracepoint
*t
;
2462 struct action_line
*action
;
2463 char *action_exp
, *next_comma
;
2464 struct cleanup
*old_cleanups
;
2465 int stepping_actions
= 0;
2466 int stepping_frame
= 0;
2468 if (!target_is_remote ())
2470 error ("Trace can only be run on remote targets.");
2474 if (tracepoint_number
== -1)
2476 warning ("No current trace frame.");
2481 if (t
->number
== tracepoint_number
)
2485 error ("No known tracepoint matches 'current' tracepoint #%d.",
2488 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2490 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2491 tracepoint_number
, traceframe_number
);
2493 /* The current frame is a trap frame if the frame PC is equal
2494 to the tracepoint PC. If not, then the current frame was
2495 collected during single-stepping. */
2497 stepping_frame
= (t
->address
!= read_pc ());
2499 for (action
= t
->actions
; action
; action
= action
->next
)
2501 struct cmd_list_element
*cmd
;
2503 QUIT
; /* allow user to bail out with ^C */
2504 action_exp
= action
->action
;
2505 while (isspace ((int) *action_exp
))
2508 /* The collection actions to be done while stepping are
2509 bracketed by the commands "while-stepping" and "end". */
2511 if (*action_exp
== '#') /* comment line */
2514 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2516 error ("Bad action list item: %s", action_exp
);
2518 if (cmd
->function
.cfunc
== while_stepping_pseudocommand
)
2519 stepping_actions
= 1;
2520 else if (cmd
->function
.cfunc
== end_actions_pseudocommand
)
2521 stepping_actions
= 0;
2522 else if (cmd
->function
.cfunc
== collect_pseudocommand
)
2524 /* Display the collected data.
2525 For the trap frame, display only what was collected at the trap.
2526 Likewise for stepping frames, display only what was collected
2527 while stepping. This means that the two boolean variables,
2528 STEPPING_FRAME and STEPPING_ACTIONS should be equal. */
2529 if (stepping_frame
== stepping_actions
)
2532 { /* repeat over a comma-separated list */
2533 QUIT
; /* allow user to bail out with ^C */
2534 if (*action_exp
== ',')
2536 while (isspace ((int) *action_exp
))
2539 next_comma
= strchr (action_exp
, ',');
2541 if (0 == strncasecmp (action_exp
, "$reg", 4))
2542 registers_info (NULL
, from_tty
);
2543 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2544 locals_info (NULL
, from_tty
);
2545 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2546 args_info (NULL
, from_tty
);
2551 make_cleanup (replace_comma
, next_comma
);
2554 printf_filtered ("%s = ", action_exp
);
2555 output_command (action_exp
, from_tty
);
2556 printf_filtered ("\n");
2560 action_exp
= next_comma
;
2562 while (action_exp
&& *action_exp
== ',');
2566 discard_cleanups (old_cleanups
);
2569 /* Convert the memory pointed to by mem into hex, placing result in buf.
2570 * Return a pointer to the last char put in buf (null)
2571 * "stolen" from sparc-stub.c
2574 static const char hexchars
[] = "0123456789abcdef";
2576 static unsigned char *
2577 mem2hex (unsigned char *mem
, unsigned char *buf
, int count
)
2585 *buf
++ = hexchars
[ch
>> 4];
2586 *buf
++ = hexchars
[ch
& 0xf];
2595 get_traceframe_number (void)
2597 return traceframe_number
;
2601 /* module initialization */
2603 _initialize_tracepoint (void)
2605 struct cmd_list_element
*c
;
2607 tracepoint_chain
= 0;
2608 tracepoint_count
= 0;
2609 traceframe_number
= -1;
2610 tracepoint_number
= -1;
2612 set_internalvar (lookup_internalvar ("tpnum"),
2613 value_from_longest (builtin_type_int
, (LONGEST
) 0));
2614 set_internalvar (lookup_internalvar ("trace_frame"),
2615 value_from_longest (builtin_type_int
, (LONGEST
) - 1));
2617 if (tracepoint_list
.list
== NULL
)
2619 tracepoint_list
.listsize
= 128;
2620 tracepoint_list
.list
= xmalloc
2621 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2623 if (tracepoint_list
.aexpr_list
== NULL
)
2625 tracepoint_list
.aexpr_listsize
= 128;
2626 tracepoint_list
.aexpr_list
= xmalloc
2627 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2630 if (stepping_list
.list
== NULL
)
2632 stepping_list
.listsize
= 128;
2633 stepping_list
.list
= xmalloc
2634 (stepping_list
.listsize
* sizeof (struct memrange
));
2637 if (stepping_list
.aexpr_list
== NULL
)
2639 stepping_list
.aexpr_listsize
= 128;
2640 stepping_list
.aexpr_list
= xmalloc
2641 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2644 add_info ("scope", scope_info
,
2645 "List the variables local to a scope");
2647 add_cmd ("tracepoints", class_trace
, NO_FUNCTION
,
2648 "Tracing of program execution without stopping the program.",
2651 add_info ("tracepoints", tracepoints_info
,
2652 "Status of tracepoints, or tracepoint number NUMBER.\n\
2653 Convenience variable \"$tpnum\" contains the number of the\n\
2654 last tracepoint set.");
2656 add_info_alias ("tp", "tracepoints", 1);
2658 c
= add_com ("save-tracepoints", class_trace
, tracepoint_save_command
,
2659 "Save current tracepoint definitions as a script.\n\
2660 Use the 'source' command in another debug session to restore them.");
2661 c
->completer
= filename_completer
;
2663 add_com ("tdump", class_trace
, trace_dump_command
,
2664 "Print everything collected at the current tracepoint.");
2666 add_prefix_cmd ("tfind", class_trace
, trace_find_command
,
2667 "Select a trace frame;\n\
2668 No argument means forward by one frame; '-' meand backward by one frame.",
2669 &tfindlist
, "tfind ", 1, &cmdlist
);
2671 add_cmd ("outside", class_trace
, trace_find_outside_command
,
2672 "Select a trace frame whose PC is outside the given \
2673 range.\nUsage: tfind outside addr1, addr2",
2676 add_cmd ("range", class_trace
, trace_find_range_command
,
2677 "Select a trace frame whose PC is in the given range.\n\
2678 Usage: tfind range addr1,addr2",
2681 add_cmd ("line", class_trace
, trace_find_line_command
,
2682 "Select a trace frame by source line.\n\
2683 Argument can be a line number (with optional source file), \n\
2684 a function name, or '*' followed by an address.\n\
2685 Default argument is 'the next source line that was traced'.",
2688 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
,
2689 "Select a trace frame by tracepoint number.\n\
2690 Default is the tracepoint for the current trace frame.",
2693 add_cmd ("pc", class_trace
, trace_find_pc_command
,
2694 "Select a trace frame by PC.\n\
2695 Default is the current PC, or the PC of the current trace frame.",
2698 add_cmd ("end", class_trace
, trace_find_end_command
,
2699 "Synonym for 'none'.\n\
2700 De-select any trace frame and resume 'live' debugging.",
2703 add_cmd ("none", class_trace
, trace_find_none_command
,
2704 "De-select any trace frame and resume 'live' debugging.",
2707 add_cmd ("start", class_trace
, trace_find_start_command
,
2708 "Select the first trace frame in the trace buffer.",
2711 add_com ("tstatus", class_trace
, trace_status_command
,
2712 "Display the status of the current trace data collection.");
2714 add_com ("tstop", class_trace
, trace_stop_command
,
2715 "Stop trace data collection.");
2717 add_com ("tstart", class_trace
, trace_start_command
,
2718 "Start trace data collection.");
2720 add_com ("passcount", class_trace
, trace_pass_command
,
2721 "Set the passcount for a tracepoint.\n\
2722 The trace will end when the tracepoint has been passed 'count' times.\n\
2723 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
2724 if TPNUM is omitted, passcount refers to the last tracepoint defined.");
2726 add_com ("end", class_trace
, end_actions_pseudocommand
,
2727 "Ends a list of commands or actions.\n\
2728 Several GDB commands allow you to enter a list of commands or actions.\n\
2729 Entering \"end\" on a line by itself is the normal way to terminate\n\
2731 Note: the \"end\" command cannot be used at the gdb prompt.");
2733 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
,
2734 "Specify single-stepping behavior at a tracepoint.\n\
2735 Argument is number of instructions to trace in single-step mode\n\
2736 following the tracepoint. This command is normally followed by\n\
2737 one or more \"collect\" commands, to specify what to collect\n\
2738 while single-stepping.\n\n\
2739 Note: this command can only be used in a tracepoint \"actions\" list.");
2741 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2742 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2744 add_com ("collect", class_trace
, collect_pseudocommand
,
2745 "Specify one or more data items to be collected at a tracepoint.\n\
2746 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2747 collect all data (variables, registers) referenced by that expression.\n\
2748 Also accepts the following special arguments:\n\
2749 $regs -- all registers.\n\
2750 $args -- all function arguments.\n\
2751 $locals -- all variables local to the block/function scope.\n\
2752 Note: this command can only be used in a tracepoint \"actions\" list.");
2754 add_com ("actions", class_trace
, trace_actions_command
,
2755 "Specify the actions to be taken at a tracepoint.\n\
2756 Tracepoint actions may include collecting of specified data, \n\
2757 single-stepping, or enabling/disabling other tracepoints, \n\
2758 depending on target's capabilities.");
2760 add_cmd ("tracepoints", class_trace
, delete_trace_command
,
2761 "Delete specified tracepoints.\n\
2762 Arguments are tracepoint numbers, separated by spaces.\n\
2763 No argument means delete all tracepoints.",
2766 add_cmd ("tracepoints", class_trace
, disable_trace_command
,
2767 "Disable specified tracepoints.\n\
2768 Arguments are tracepoint numbers, separated by spaces.\n\
2769 No argument means disable all tracepoints.",
2772 add_cmd ("tracepoints", class_trace
, enable_trace_command
,
2773 "Enable specified tracepoints.\n\
2774 Arguments are tracepoint numbers, separated by spaces.\n\
2775 No argument means enable all tracepoints.",
2778 add_com ("trace", class_trace
, trace_command
,
2779 "Set a tracepoint at a specified line or function or address.\n\
2780 Argument may be a line number, function name, or '*' plus an address.\n\
2781 For a line number or function, trace at the start of its code.\n\
2782 If an address is specified, trace at that exact address.\n\n\
2783 Do \"help tracepoints\" for info on other tracepoint commands.");
2785 add_com_alias ("tp", "trace", class_alias
, 0);
2786 add_com_alias ("tr", "trace", class_alias
, 1);
2787 add_com_alias ("tra", "trace", class_alias
, 1);
2788 add_com_alias ("trac", "trace", class_alias
, 1);