1 /* Tracing functionality for remote targets in custom GDB protocol
2 Copyright 1997 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, Boston, MA 02111-1307, USA. */
23 #include "tracepoint.h"
25 #include "expression.h"
30 #include "gdb_string.h"
32 /* readline include files */
36 /* readline defines this. */
43 extern int info_verbose
;
44 extern void (*readline_begin_hook
) PARAMS ((char *, ...));
45 extern char * (*readline_hook
) PARAMS ((char *));
46 extern void (*readline_end_hook
) PARAMS ((void));
48 /* If this definition isn't overridden by the header files, assume
49 that isatty and fileno exist on this system. */
51 #define ISATTY(FP) (isatty (fileno (FP)))
57 This module defines the following debugger commands:
58 trace : set a tracepoint on a function, line, or address.
59 info trace : list all debugger-defined tracepoints.
60 delete trace : delete one or more tracepoints.
61 enable trace : enable one or more tracepoints.
62 disable trace : disable one or more tracepoints.
63 actions : specify actions to be taken at a tracepoint.
64 passcount : specify a pass count for a tracepoint.
65 tstart : start a trace experiment.
66 tstop : stop a trace experiment.
67 tstatus : query the status of a trace experiment.
68 tfind : find a trace frame in the trace buffer.
69 tdump : print everything collected at the current tracepoint.
70 save-tracepoints : write tracepoint setup into a file.
72 This module defines the following user-visible debugger variables:
73 $trace_frame : sequence number of trace frame currently being debugged.
74 $trace_line : source line of trace frame currently being debugged.
75 $trace_file : source file of trace frame currently being debugged.
76 $tracepoint : tracepoint number of trace frame currently being debugged.
80 /* ======= Important global variables: ======= */
82 /* Chain of all tracepoints defined. */
83 struct tracepoint
*tracepoint_chain
;
85 /* Number of last tracepoint made. */
86 static int tracepoint_count
;
88 /* Number of last traceframe collected. */
89 static int traceframe_number
;
91 /* Tracepoint for last traceframe collected. */
92 static int tracepoint_number
;
94 /* Symbol for function for last traceframe collected */
95 static struct symbol
*traceframe_fun
;
97 /* Symtab and line for last traceframe collected */
98 static struct symtab_and_line traceframe_sal
;
100 /* Tracing command lists */
101 static struct cmd_list_element
*tfindlist
;
102 static struct cmd_list_element
*tracelist
;
104 /* ======= Important command functions: ======= */
105 static void trace_command
PARAMS ((char *, int));
106 static void tracepoints_info
PARAMS ((char *, int));
107 static void delete_trace_command
PARAMS ((char *, int));
108 static void enable_trace_command
PARAMS ((char *, int));
109 static void disable_trace_command
PARAMS ((char *, int));
110 static void trace_pass_command
PARAMS ((char *, int));
111 static void trace_actions_command
PARAMS ((char *, int));
112 static void trace_start_command
PARAMS ((char *, int));
113 static void trace_stop_command
PARAMS ((char *, int));
114 static void trace_status_command
PARAMS ((char *, int));
115 static void trace_find_command
PARAMS ((char *, int));
116 static void trace_find_pc_command
PARAMS ((char *, int));
117 static void trace_find_tracepoint_command
PARAMS ((char *, int));
118 static void trace_find_line_command
PARAMS ((char *, int));
119 static void trace_find_range_command
PARAMS ((char *, int));
120 static void trace_find_outside_command
PARAMS ((char *, int));
121 static void tracepoint_save_command
PARAMS ((char *, int));
122 static void trace_dump_command
PARAMS ((char *, int));
125 /* Utility: returns true if "target remote" */
129 if (current_target
.to_shortname
&&
130 strcmp (current_target
.to_shortname
, "remote") == 0)
136 /* Utility: generate error from an incoming stub packet. */
142 return; /* not an error msg */
145 case '1': /* malformed packet error */
146 if (*++buf
== '0') /* general case: */
147 error ("tracepoint.c: error in outgoing packet.");
149 error ("tracepoint.c: error in outgoing packet at field #%d.",
150 strtol (buf
, NULL
, 16));
152 error ("trace API error 0x%s.", ++buf
);
154 error ("Target returns error code '%s'.", buf
);
158 /* Utility: wait for reply from stub, while accepting "O" packets */
160 remote_get_noisy_reply (buf
)
163 do /* loop on reply from remote stub */
167 error ("Target does not support this command.");
168 else if (buf
[0] == 'E')
170 else if (buf
[0] == 'O' &&
172 remote_console_output (buf
+ 1); /* 'O' message from stub */
174 return buf
; /* here's the actual reply */
178 /* Set tracepoint count to NUM. */
180 set_tracepoint_count (num
)
183 tracepoint_count
= num
;
184 set_internalvar (lookup_internalvar ("tpnum"),
185 value_from_longest (builtin_type_int
, (LONGEST
) num
));
188 /* Set traceframe number to NUM. */
190 set_traceframe_num (num
)
193 traceframe_number
= num
;
194 set_internalvar (lookup_internalvar ("trace_frame"),
195 value_from_longest (builtin_type_int
, (LONGEST
) num
));
198 /* Set tracepoint number to NUM. */
200 set_tracepoint_num (num
)
203 tracepoint_number
= num
;
204 set_internalvar (lookup_internalvar ("tracepoint"),
205 value_from_longest (builtin_type_int
, (LONGEST
) num
));
208 /* Set externally visible debug variables for querying/printing
209 the traceframe context (line, function, file) */
212 set_traceframe_context (trace_pc
)
215 static struct type
*func_string
, *file_string
;
216 static struct type
*func_range
, *file_range
;
217 static value_ptr func_val
, file_val
;
218 static struct type
*charstar
;
221 if (charstar
== (struct type
*) NULL
)
222 charstar
= lookup_pointer_type (builtin_type_char
);
224 if (trace_pc
== -1) /* cease debugging any trace buffers */
227 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
228 traceframe_sal
.symtab
= NULL
;
229 set_internalvar (lookup_internalvar ("trace_func"),
230 value_from_longest (charstar
, (LONGEST
) 0));
231 set_internalvar (lookup_internalvar ("trace_file"),
232 value_from_longest (charstar
, (LONGEST
) 0));
233 set_internalvar (lookup_internalvar ("trace_line"),
234 value_from_longest (builtin_type_int
, (LONGEST
) -1));
238 /* save as globals for internal use */
239 traceframe_sal
= find_pc_line (trace_pc
, 0);
240 traceframe_fun
= find_pc_function (trace_pc
);
242 /* save linenumber as "$trace_line", a debugger variable visible to users */
243 set_internalvar (lookup_internalvar ("trace_line"),
244 value_from_longest (builtin_type_int
,
245 (LONGEST
) traceframe_sal
.line
));
247 /* save func name as "$trace_func", a debugger variable visible to users */
248 if (traceframe_fun
== NULL
||
249 SYMBOL_NAME (traceframe_fun
) == NULL
)
250 set_internalvar (lookup_internalvar ("trace_func"),
251 value_from_longest (charstar
, (LONGEST
) 0));
254 len
= strlen (SYMBOL_NAME (traceframe_fun
));
255 func_range
= create_range_type (func_range
,
256 builtin_type_int
, 0, len
- 1);
257 func_string
= create_array_type (func_string
,
258 builtin_type_char
, func_range
);
259 func_val
= allocate_value (func_string
);
260 VALUE_TYPE (func_val
) = func_string
;
261 memcpy (VALUE_CONTENTS_RAW (func_val
),
262 SYMBOL_NAME (traceframe_fun
),
264 func_val
->modifiable
= 0;
265 set_internalvar (lookup_internalvar ("trace_func"), func_val
);
268 /* save file name as "$trace_file", a debugger variable visible to users */
269 if (traceframe_sal
.symtab
== NULL
||
270 traceframe_sal
.symtab
->filename
== NULL
)
271 set_internalvar (lookup_internalvar ("trace_file"),
272 value_from_longest (charstar
, (LONGEST
) 0));
275 len
= strlen (traceframe_sal
.symtab
->filename
);
276 file_range
= create_range_type (file_range
,
277 builtin_type_int
, 0, len
- 1);
278 file_string
= create_array_type (file_string
,
279 builtin_type_char
, file_range
);
280 file_val
= allocate_value (file_string
);
281 VALUE_TYPE (file_val
) = file_string
;
282 memcpy (VALUE_CONTENTS_RAW (file_val
),
283 traceframe_sal
.symtab
->filename
,
285 file_val
->modifiable
= 0;
286 set_internalvar (lookup_internalvar ("trace_file"), file_val
);
290 /* Low level routine to set a tracepoint.
291 Returns the tracepoint object so caller can set other things.
292 Does not set the tracepoint number!
293 Does not print anything.
295 ==> This routine should not be called if there is a chance of later
296 error(); otherwise it leaves a bogus tracepoint on the chain. Validate
297 your arguments BEFORE calling this routine! */
299 static struct tracepoint
*
300 set_raw_tracepoint (sal
)
301 struct symtab_and_line sal
;
303 register struct tracepoint
*t
, *tc
;
304 struct cleanup
*old_chain
;
306 t
= (struct tracepoint
*) xmalloc (sizeof (struct tracepoint
));
307 old_chain
= make_cleanup (free
, t
);
308 memset (t
, 0, sizeof (*t
));
310 if (sal
.symtab
== NULL
)
311 t
->source_file
= NULL
;
316 t
->source_file
= (char *) xmalloc (strlen (sal
.symtab
->filename
) +
317 strlen (sal
.symtab
->dirname
) + 2);
319 strcpy (t
->source_file
, sal
.symtab
->dirname
);
323 if (*(--p
) != '/') /* Will this work on Windows? */
324 strcat (t
->source_file
, "/");
325 strcat (t
->source_file
, sal
.symtab
->filename
);
328 t
->language
= current_language
->la_language
;
329 t
->input_radix
= input_radix
;
330 t
->line_number
= sal
.line
;
331 t
->enabled
= enabled
;
336 /* Add this tracepoint to the end of the chain
337 so that a list of tracepoints will come out in order
338 of increasing numbers. */
340 tc
= tracepoint_chain
;
342 tracepoint_chain
= t
;
349 discard_cleanups (old_chain
);
353 /* Set a tracepoint according to ARG (function, linenum or *address) */
355 trace_command (arg
, from_tty
)
359 char **canonical
= (char **)NULL
;
360 struct symtabs_and_lines sals
;
361 struct symtab_and_line sal
;
362 struct tracepoint
*t
;
363 char *addr_start
= 0, *addr_end
= 0, *cond_start
= 0, *cond_end
= 0;
367 error ("trace command requires an argument");
369 if (from_tty
&& info_verbose
)
370 printf_filtered ("TRACE %s\n", arg
);
378 sals
= decode_line_1 (&arg
, 1, (struct symtab
*)NULL
, 0, &canonical
);
381 return; /* ??? Presumably decode_line_1 has already warned? */
383 /* Resolve all line numbers to PC's */
384 for (i
= 0; i
< sals
.nelts
; i
++)
385 resolve_sal_pc (&sals
.sals
[i
]);
387 /* Now set all the tracepoints. */
388 for (i
= 0; i
< sals
.nelts
; i
++)
392 t
= set_raw_tracepoint (sal
);
393 set_tracepoint_count (tracepoint_count
+ 1);
394 t
->number
= tracepoint_count
;
396 /* If a canonical line spec is needed use that instead of the
398 if (canonical
!= (char **)NULL
&& canonical
[i
] != NULL
)
399 t
->addr_string
= canonical
[i
];
401 t
->addr_string
= savestring (addr_start
, addr_end
- addr_start
);
403 t
->cond_string
= savestring (cond_start
, cond_end
- cond_start
);
405 /* Let the UI know of any additions */
406 if (create_tracepoint_hook
)
407 create_tracepoint_hook (t
);
412 printf_filtered ("Multiple tracepoints were set.\n");
413 printf_filtered ("Use 'delete trace' to delete unwanted tracepoints.\n");
417 /* Print information on tracepoint number TPNUM_EXP, or all if omitted. */
420 tracepoints_info (tpnum_exp
, from_tty
)
424 struct tracepoint
*t
;
425 struct action_line
*action
;
426 int found_a_tracepoint
= 0;
427 char wrap_indent
[80];
431 char *i1
= "\t", *i2
= "\t ";
432 char *indent
, *actionline
;;
436 tpnum
= parse_and_eval_address (tpnum_exp
);
439 if (tpnum
== -1 || tpnum
== t
->number
)
441 extern int addressprint
; /* print machine addresses? */
443 if (!found_a_tracepoint
++)
445 printf_filtered ("Num Enb ");
447 printf_filtered ("Address ");
448 printf_filtered ("PassC StepC What\n");
450 strcpy (wrap_indent
, " ");
452 strcat (wrap_indent
, " ");
454 printf_filtered ("%-3d %-3s ", t
->number
,
455 t
->enabled
== enabled
? "y" : "n");
457 printf_filtered ("%s ",
458 local_hex_string_custom ((unsigned long) t
->address
,
460 printf_filtered ("%-5d %-5d ", t
->pass_count
, t
->step_count
);
464 sym
= find_pc_function (t
->address
);
467 fputs_filtered ("in ", gdb_stdout
);
468 fputs_filtered (SYMBOL_SOURCE_NAME (sym
), gdb_stdout
);
469 wrap_here (wrap_indent
);
470 fputs_filtered (" at ", gdb_stdout
);
472 fputs_filtered (t
->source_file
, gdb_stdout
);
473 printf_filtered (":%d", t
->line_number
);
476 print_address_symbolic (t
->address
, gdb_stdout
, demangle
, " ");
478 printf_filtered ("\n");
481 printf_filtered (" Actions for tracepoint %d: \n", t
->number
);
483 for (action
= t
->actions
; action
; action
= action
->next
)
486 actionline
= action
->action
;
487 while (isspace(*actionline
))
490 printf_filtered ("%s%s\n", indent
, actionline
);
491 if (0 == strncasecmp (actionline
, "while-stepping", 14))
493 else if (0 == strncasecmp (actionline
, "end", 3))
496 printf_filtered ("\t%s\n", action
->action
);
501 if (!found_a_tracepoint
)
504 printf_filtered ("No tracepoints.\n");
506 printf_filtered ("No tracepoint number %d.\n", tpnum
);
510 /* Optimization: the code to parse an enable, disable, or delete TP command
511 is virtually identical except for whether it performs an enable, disable,
512 or delete. Therefore I've combined them into one function with an opcode.
514 enum tracepoint_opcode
521 /* This function implements enable, disable and delete. */
523 tracepoint_operation (t
, from_tty
, opcode
)
524 struct tracepoint
*t
;
526 enum tracepoint_opcode opcode
;
528 struct tracepoint
*t2
;
529 struct action_line
*action
, *next
;
533 t
->enabled
= enabled
;
536 t
->enabled
= disabled
;
539 if (tracepoint_chain
== t
)
540 tracepoint_chain
= t
->next
;
549 /* Let the UI know of any deletions */
550 if (delete_tracepoint_hook
)
551 delete_tracepoint_hook (t
);
554 free (t
->cond_string
);
556 free (t
->addr_string
);
558 free (t
->source_file
);
559 for (action
= t
->actions
; action
; action
= next
)
563 free (action
->action
);
571 /* Utility: parse a tracepoint number and look it up in the list. */
573 get_tracepoint_by_number (arg
)
576 struct tracepoint
*t
;
582 error ("Bad tracepoint argument");
584 if (*arg
== 0 || **arg
== 0) /* empty arg means refer to last tp */
585 tpnum
= tracepoint_count
;
586 else if (**arg
== '$') /* handle convenience variable */
588 /* Make a copy of the name, so we can null-terminate it
589 to pass to lookup_internalvar(). */
591 while (isalnum(*end
) || *end
== '_')
593 copy
= (char *) alloca (end
- *arg
);
594 strncpy (copy
, *arg
+ 1, (end
- *arg
- 1));
595 copy
[end
- *arg
- 1] = '\0';
598 val
= value_of_internalvar (lookup_internalvar (copy
));
599 if (TYPE_CODE( VALUE_TYPE (val
)) != TYPE_CODE_INT
)
600 error ("Convenience variable must have integral type.");
601 tpnum
= (int) value_as_long (val
);
603 else /* handle tracepoint number */
605 tpnum
= strtol (*arg
, arg
, 10);
608 if (t
->number
== tpnum
)
612 warning ("No tracepoint number %d.\n", tpnum
);
616 /* Utility: parse a list of tracepoint numbers, and call a func for each. */
618 map_args_over_tracepoints (args
, from_tty
, opcode
)
621 enum tracepoint_opcode opcode
;
623 struct tracepoint
*t
;
627 if (args
== 0 || *args
== 0) /* do them all */
629 tracepoint_operation (t
, from_tty
, opcode
);
633 if (t
= get_tracepoint_by_number (&args
))
634 tracepoint_operation (t
, from_tty
, opcode
);
635 while (*args
== ' ' || *args
== '\t')
640 /* The 'enable trace' command enables tracepoints. Not supported by all targets. */
642 enable_trace_command (args
, from_tty
)
647 map_args_over_tracepoints (args
, from_tty
, enable
);
650 /* The 'disable trace' command enables tracepoints. Not supported by all targets. */
652 disable_trace_command (args
, from_tty
)
657 map_args_over_tracepoints (args
, from_tty
, disable
);
660 /* Remove a tracepoint (or all if no argument) */
662 delete_trace_command (args
, from_tty
)
668 if (!query ("Delete all tracepoints? "))
671 map_args_over_tracepoints (args
, from_tty
, delete);
674 /* Set passcount for tracepoint.
676 First command argument is passcount, second is tracepoint number.
677 If tracepoint number omitted, apply to most recently defined.
678 Also accepts special argument "all". */
681 trace_pass_command (args
, from_tty
)
685 struct tracepoint
*t1
= (struct tracepoint
*) -1, *t2
;
688 if (args
== 0 || *args
== 0)
689 error ("PASS command requires an argument (count + optional TP num)");
691 count
= strtoul (args
, &args
, 10); /* count comes first, then TP num */
693 while (*args
&& isspace (*args
))
696 if (*args
&& strncasecmp (args
, "all", 3) == 0)
697 args
+= 3; /* skip special argument "all" */
699 t1
= get_tracepoint_by_number (&args
);
702 return; /* error, bad tracepoint number */
705 if (t1
== (struct tracepoint
*) -1 || t1
== t2
)
707 t2
->pass_count
= count
;
709 printf_filtered ("Setting tracepoint %d's passcount to %d\n",
714 /* ACTIONS functions: */
716 /* Prototypes for action-parsing utility commands */
717 static void read_actions
PARAMS((struct tracepoint
*));
718 static void free_actions
PARAMS((struct tracepoint
*));
719 static char *parse_and_eval_memrange
PARAMS ((char *,
725 /* The three functions:
726 collect_pseudocom, while_stepping_pseudocom, and end_pseudocom
727 are placeholders for "commands" that are actually ONLY to be used
728 within a tracepoint action list. If the actual function is ever called,
729 it means that somebody issued the "command" at the top level,
730 which is always an error. */
733 end_pseudocom (args
, from_tty
)
735 error ("This command cannot be used at the top level.");
739 while_stepping_pseudocom (args
, from_tty
)
741 error ("This command can only be used in a tracepoint actions list.");
745 collect_pseudocom (args
, from_tty
)
747 error ("This command can only be used in a tracepoint actions list.");
750 /* Enter a list of actions for a tracepoint. */
752 trace_actions_command (args
, from_tty
)
756 struct tracepoint
*t
;
759 char *end_msg
= "End with a line saying just \"end\".";
761 if (t
= get_tracepoint_by_number (&args
))
763 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
766 if (readline_begin_hook
)
767 (*readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
768 else if (from_tty
&& input_from_terminal_p ())
769 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
774 if (readline_end_hook
)
775 (*readline_end_hook
) ();
777 /* tracepoints_changed () */
779 /* else error, just return; */
790 static enum actionline_type validate_actionline
PARAMS((char *,
791 struct tracepoint
*));
793 /* worker function */
796 struct tracepoint
*t
;
799 char *prompt1
= "> ", *prompt2
= " > ";
800 char *prompt
= prompt1
;
801 enum actionline_type linetype
;
802 extern FILE *instream
;
803 struct action_line
*next
= NULL
, *temp
;
804 struct cleanup
*old_chain
;
806 /* Control-C quits instantly if typed while in this loop
807 since it should not wait until the user types a newline. */
811 signal (STOP_SIGNAL
, stop_sig
);
813 old_chain
= make_cleanup (free_actions
, (void *) t
);
816 /* Make sure that all output has been output. Some machines may let
817 you get away with leaving out some of the gdb_flush, but not all. */
819 gdb_flush (gdb_stdout
);
820 gdb_flush (gdb_stderr
);
822 if (readline_hook
&& instream
== NULL
)
823 line
= (*readline_hook
) (prompt
);
824 else if (instream
== stdin
&& ISATTY (instream
))
825 line
= readline (prompt
);
827 line
= gdb_readline (0);
829 linetype
= validate_actionline (line
, t
);
830 if (linetype
== BADLINE
)
831 continue; /* already warned -- collect another line */
833 temp
= xmalloc (sizeof (struct action_line
));
837 if (next
== NULL
) /* first action for this tracepoint? */
838 t
->actions
= next
= temp
;
845 if (linetype
== STEPPING
) /* begin "while-stepping" */
846 if (prompt
== prompt2
)
848 warning ("Already processing 'while-stepping'");
852 prompt
= prompt2
; /* change prompt for stepping actions */
853 else if (linetype
== END
)
854 if (prompt
== prompt2
)
855 prompt
= prompt1
; /* end of single-stepping actions */
857 break; /* end of actions */
861 signal (STOP_SIGNAL
, SIG_DFL
);
864 discard_cleanups (old_chain
);
867 /* worker function */
868 static enum actionline_type
869 validate_actionline (line
, t
)
871 struct tracepoint
*t
;
874 struct expression
*exp
;
875 value_ptr temp
, temp2
;
877 for (p
= line
; isspace (*p
); )
880 /* symbol lookup etc. */
881 if (*p
== '\0') /* empty line: just prompt for another line. */
883 else if (0 == strncasecmp (p
, "collect", 7))
886 do { /* repeat over a comma-separated list */
890 if (*p
== '$') /* look for special pseudo-symbols */
893 bfd_signed_vma offset
;
895 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
896 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
897 (0 == strncasecmp ("loc", p
+ 1, 3)))
900 else if (p
[1] == '(') /* literal memrange */
901 p
= parse_and_eval_memrange (p
, t
->address
,
902 &typecode
, &offset
, &size
);
906 exp
= parse_exp_1 (&p
, block_for_pc (t
->address
), 1);
908 if (exp
->elts
[0].opcode
!= OP_VAR_VALUE
&&
909 /*exp->elts[0].opcode != OP_LONG && */
910 /*exp->elts[0].opcode != UNOP_CAST && */
911 exp
->elts
[0].opcode
!= OP_REGISTER
)
913 warning ("collect: enter variable name or register.\n");
916 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
917 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
919 warning ("%s is constant (value %d): will not be collected.",
920 SYMBOL_NAME (exp
->elts
[2].symbol
),
921 SYMBOL_VALUE (exp
->elts
[2].symbol
));
924 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
926 warning ("%s is optimized away and cannot be collected.",
927 SYMBOL_NAME (exp
->elts
[2].symbol
));
931 } while (p
&& *p
++ == ',');
934 else if (0 == strncasecmp (p
, "while-stepping", 14))
936 char *steparg
; /* in case warning is necessary */
945 t
->step_count
= strtol (p
, &p
, 0);
946 if (t
->step_count
== 0)
948 warning ("'%s' evaluates to zero -- command ignored.");
956 else if (0 == strncasecmp (p
, "end", 3))
960 warning ("'%s' is not a supported tracepoint action.", p
);
965 /* worker function */
968 struct tracepoint
*t
;
970 struct action_line
*line
, *next
;
972 for (line
= t
->actions
; line
; line
= next
)
981 int type
; /* 0 for absolute memory range, else basereg number */
982 bfd_signed_vma start
;
986 struct collection_list
{
987 unsigned char regs_mask
[8]; /* room for up to 256 regs */
990 struct memrange
*list
;
991 } tracepoint_list
, stepping_list
;
993 /* MEMRANGE functions: */
995 /* parse a memrange spec from command input */
997 parse_and_eval_memrange (arg
, addr
, typecode
, offset
, size
)
1000 long *typecode
, *size
;
1001 bfd_signed_vma
*offset
;
1004 struct expression
*exp
;
1006 if (*arg
++ != '$' || *arg
++ != '(')
1007 error ("Internal: bad argument to validate_memrange: %s", start
);
1009 if (*arg
== '$') /* register for relative memrange? */
1011 exp
= parse_exp_1 (&arg
, block_for_pc (addr
), 1);
1012 if (exp
->elts
[0].opcode
!= OP_REGISTER
)
1013 error ("Bad register operand for memrange: %s", start
);
1015 error ("missing comma for memrange: %s", start
);
1016 *typecode
= exp
->elts
[1].longconst
;
1022 /* While attractive, this fails for a number of reasons:
1023 1) parse_and_eval_address does not deal with trailing commas,
1025 2) There is no safeguard against the user trying to use
1026 an out-of-scope variable in an address expression (for instance).
1027 2.5) If you are going to allow semi-arbitrary expressions, you
1028 would need to explain which expressions are allowed, and
1029 which are not (which would provoke endless questions).
1030 3) If you are going to allow semi-arbitrary expressions in the
1031 offset and size fields, then the leading "$" of a register
1032 name no longer disambiguates the typecode field.
1035 *offset
= parse_and_eval_address (arg
);
1036 if ((arg
= strchr (arg
, ',')) == NULL
)
1037 error ("missing comma for memrange: %s", start
);
1041 *size
= parse_and_eval_address (arg
);
1042 if ((arg
= strchr (arg
, ')')) == NULL
)
1043 error ("missing close-parenthesis for memrange: %s", start
);
1048 /* This, on the other hand, doesn't work because "-1" is an
1049 expression, not an OP_LONG! Fall back to using strtol for now. */
1051 exp
= parse_exp_1 (&arg
, block_for_pc (addr
), 1);
1052 if (exp
->elts
[0].opcode
!= OP_LONG
)
1053 error ("Bad offset operand for memrange: %s", start
);
1054 *offset
= exp
->elts
[2].longconst
;
1057 error ("missing comma for memrange: %s", start
);
1059 exp
= parse_exp_1 (&arg
, block_for_pc (addr
), 1);
1060 if (exp
->elts
[0].opcode
!= OP_LONG
)
1061 error ("Bad size operand for memrange: %s", start
);
1062 *size
= exp
->elts
[2].longconst
;
1065 error ("invalid size in memrange: %s", start
);
1068 error ("missing close-parenthesis for memrange: %s", start
);
1070 *offset
= strtol (arg
, &arg
, 0);
1072 error ("missing comma for memrange: %s", start
);
1073 *size
= strtol (arg
, &arg
, 0);
1075 error ("invalid size in memrange: %s", start
);
1077 error ("missing close-parenthesis for memrange: %s", start
);
1081 printf_filtered ("Collecting memrange: (0x%x,0x%x,0x%x)\n",
1082 *typecode
, *offset
, *size
);
1087 /* compare memranges for qsort */
1090 struct memrange
*a
, *b
;
1092 if (a
->type
< b
->type
) return -1;
1093 if (a
->type
> b
->type
) return 1;
1096 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
) return -1;
1097 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
) return 1;
1101 if (a
->start
< b
->start
) return -1;
1102 if (a
->start
> b
->start
) return 1;
1107 /* Sort the memrange list using qsort, and merge adjacent memranges */
1109 memrange_sortmerge (memranges
)
1110 struct collection_list
*memranges
;
1114 qsort (memranges
->list
, memranges
->next_memrange
,
1115 sizeof (struct memrange
), memrange_cmp
);
1116 if (memranges
->next_memrange
> 0)
1118 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
1120 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
1121 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
1122 MAX_REGISTER_VIRTUAL_SIZE
)
1124 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
1125 continue; /* next b, same a */
1129 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
1130 sizeof (struct memrange
));
1132 memranges
->next_memrange
= a
+ 1;
1136 /* Add a register to a collection list */
1138 add_register (collection
, regno
)
1139 struct collection_list
*collection
;
1140 unsigned long regno
;
1143 printf_filtered ("collect register %d\n", regno
);
1144 if (regno
> (8 * sizeof (collection
->regs_mask
)))
1145 error ("Internal: register number %d too large for tracepoint",
1147 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
1150 /* Add a memrange to a collection list */
1152 add_memrange (memranges
, type
, base
, len
)
1153 struct collection_list
*memranges
;
1155 bfd_signed_vma base
;
1159 printf_filtered ("(%d,0x%x,%d)\n", type
, base
, len
);
1160 /* type: 0 == memory, n == basereg */
1161 memranges
->list
[memranges
->next_memrange
].type
= type
;
1162 /* base: addr if memory, offset if reg relative. */
1163 memranges
->list
[memranges
->next_memrange
].start
= base
;
1164 /* len: we actually save end (base + len) for convenience */
1165 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
1166 memranges
->next_memrange
++;
1167 if (memranges
->next_memrange
>= memranges
->listsize
)
1169 memranges
->listsize
*= 2;
1170 memranges
->list
= xrealloc (memranges
->list
,
1171 memranges
->listsize
);
1174 if (type
!= 0) /* better collect the base register! */
1175 add_register (memranges
, type
);
1178 /* Add a symbol to a collection list */
1180 collect_symbol (collect
, sym
)
1181 struct collection_list
*collect
;
1186 bfd_signed_vma offset
;
1188 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
1189 switch (SYMBOL_CLASS (sym
)) {
1191 printf_filtered ("%s: don't know symbol class %d\n",
1192 SYMBOL_NAME (sym
), SYMBOL_CLASS (sym
));
1195 printf_filtered ("%s is constant, value is %d: will not be collected.\n",
1196 SYMBOL_NAME (sym
), SYMBOL_VALUE (sym
));
1199 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1201 printf_filtered ("LOC_STATIC %s: collect %d bytes "
1203 SYMBOL_NAME (sym
), len
, offset
);
1204 add_memrange (collect
, 0, offset
, len
); /* 0 == memory */
1208 reg
= SYMBOL_VALUE (sym
);
1210 printf_filtered ("LOC_REG[parm] %s: ", SYMBOL_NAME (sym
));
1211 add_register (collect
, reg
);
1215 printf_filtered ("Sorry, don't know how to do LOC_ARGs yet.\n");
1216 printf_filtered (" (will not collect %s)\n",
1219 case LOC_REGPARM_ADDR
:
1220 reg
= SYMBOL_VALUE (sym
);
1224 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %d bytes at offset %d from reg %d\n",
1225 SYMBOL_NAME (sym
), len
, offset
, reg
);
1227 add_memrange (collect
, reg
, offset
, len
);
1231 offset
= SYMBOL_VALUE (sym
);
1235 printf_filtered ("LOC_LOCAL %s: Collect %d bytes at offset %d from frame ptr reg %d\n",
1236 SYMBOL_NAME (sym
), len
, offset
, reg
);
1238 add_memrange (collect
, reg
, offset
, len
);
1241 case LOC_BASEREG_ARG
:
1242 reg
= SYMBOL_BASEREG (sym
);
1243 offset
= SYMBOL_VALUE (sym
);
1246 printf_filtered ("LOC_BASEREG %s: collect %d bytes at offset %d from basereg %d\n",
1247 SYMBOL_NAME (sym
), len
, offset
, reg
);
1249 add_memrange (collect
, reg
, offset
, len
);
1251 case LOC_UNRESOLVED
:
1252 printf_filtered ("Don't know LOC_UNRESOLVED %s\n", SYMBOL_NAME (sym
));
1254 case LOC_OPTIMIZED_OUT
:
1255 printf_filtered ("%s has been optimized out of existance.\n",
1261 /* Add all locals (or args) symbols to collection list */
1263 add_local_symbols (collect
, pc
, type
)
1264 struct collection_list
*collect
;
1269 struct block
*block
;
1270 int i
, nsyms
, count
= 0;
1272 block
= block_for_pc (pc
);
1275 nsyms
= BLOCK_NSYMS (block
);
1276 for (i
= 0; i
< nsyms
; i
++)
1278 sym
= BLOCK_SYM (block
, i
);
1279 switch (SYMBOL_CLASS (sym
)) {
1284 if (type
== 'L') /* collecting Locals */
1287 collect_symbol (collect
, sym
);
1294 case LOC_REGPARM_ADDR
:
1295 case LOC_BASEREG_ARG
:
1296 if (type
== 'A') /* collecting Arguments */
1299 collect_symbol (collect
, sym
);
1303 if (BLOCK_FUNCTION (block
))
1306 block
= BLOCK_SUPERBLOCK (block
);
1309 warning ("No %s found in scope.", type
== 'L' ? "locals" : "args");
1312 /* worker function */
1314 clear_collection_list (list
)
1315 struct collection_list
*list
;
1317 list
->next_memrange
= 0;
1318 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1321 /* reduce a collection list to string form (for gdb protocol) */
1323 stringify_collection_list (list
, string
)
1324 struct collection_list
*list
;
1330 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1331 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1333 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1336 printf_filtered ("\nCollecting registers (mask): 0x");
1341 printf_filtered ("%02X", list
->regs_mask
[i
]);
1342 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1347 printf_filtered ("\n");
1348 if (list
->next_memrange
> 0 && info_verbose
)
1349 printf_filtered ("Collecting memranges: \n");
1350 for (i
= 0; i
< list
->next_memrange
; i
++)
1353 printf_filtered ("(%d, 0x%x, %d)\n",
1355 list
->list
[i
].start
,
1356 list
->list
[i
].end
- list
->list
[i
].start
);
1357 sprintf (end
, "M%X,%X,%X",
1359 list
->list
[i
].start
,
1360 list
->list
[i
].end
- list
->list
[i
].start
);
1361 end
+= strlen (end
);
1369 /* render all actions into gdb protocol */
1371 encode_actions (t
, tdp_actions
, step_count
, stepping_actions
)
1372 struct tracepoint
*t
;
1374 unsigned long *step_count
;
1375 char **stepping_actions
;
1377 struct expression
*exp
;
1378 static char tdp_buff
[2048], step_buff
[2048];
1379 struct action_line
*action
;
1381 bfd_signed_vma offset
;
1383 struct collection_list
*collect
;
1385 clear_collection_list (&tracepoint_list
);
1386 clear_collection_list (&stepping_list
);
1387 collect
= &tracepoint_list
;
1389 *tdp_actions
= NULL
;
1390 *stepping_actions
= NULL
;
1392 for (action
= t
->actions
; action
; action
= action
->next
)
1394 action_exp
= action
->action
;
1395 while (isspace (*action_exp
))
1398 if (0 == strncasecmp (action_exp
, "collect", 7))
1400 action_exp
= action_exp
+ 7;
1401 do { /* repeat over a comma-separated list */
1402 while (isspace (*action_exp
))
1405 if (0 == strncasecmp ("$reg", action_exp
, 4))
1407 for (i
= 0; i
< NUM_REGS
; i
++)
1408 add_register (collect
, i
);
1409 action_exp
= strchr (action_exp
, ','); /* more? */
1411 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1413 add_local_symbols (collect
, t
->address
, 'A');
1414 action_exp
= strchr (action_exp
, ','); /* more? */
1416 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1418 add_local_symbols (collect
, t
->address
, 'L');
1419 action_exp
= strchr (action_exp
, ','); /* more? */
1421 else if (action_exp
[0] == '$' &&
1422 action_exp
[1] == '(') /* literal memrange */
1424 long typecode
, size
;
1425 bfd_signed_vma offset
;
1427 action_exp
= parse_and_eval_memrange (action_exp
,
1432 add_memrange (collect
, typecode
, offset
, size
);
1436 unsigned long addr
, len
;
1438 exp
= parse_exp_1 (&action_exp
, block_for_pc (t
->address
), 1);
1439 switch (exp
->elts
[0].opcode
) {
1441 i
= exp
->elts
[1].longconst
;
1443 printf_filtered ("OP_REGISTER: ");
1444 add_register (collect
, i
);
1447 collect_symbol (collect
, exp
->elts
[2].symbol
);
1451 addr
= exp
->elts
[2].longconst
;
1452 if (*action_exp
== ':')
1454 exp
= parse_exp_1 (&action_exp
,
1455 block_for_pc (t
->address
),
1457 if (exp
->elts
[0].opcode
== OP_LONG
)
1458 len
= exp
->elts
[2].longconst
;
1460 error ("length field requires a literal long const");
1465 add_memrange (collect
, 0, addr
, len
);
1470 } while (action_exp
&& *action_exp
++ == ',');
1472 else if (0 == strncasecmp (action_exp
, "while-stepping", 14))
1474 collect
= &stepping_list
;
1476 else if (0 == strncasecmp (action_exp
, "end", 3))
1478 if (collect
== &stepping_list
) /* end stepping actions */
1479 collect
= &tracepoint_list
;
1481 break; /* end tracepoint actions */
1484 memrange_sortmerge (&tracepoint_list
);
1485 memrange_sortmerge (&stepping_list
);
1487 *tdp_actions
= stringify_collection_list (&tracepoint_list
, &tdp_buff
);
1488 *stepping_actions
= stringify_collection_list (&stepping_list
, &step_buff
);
1491 static char target_buf
[2048];
1495 Tell target to lear any previous trace experiment.
1496 Walk the list of tracepoints, and send them (and their actions)
1497 to the target. If no errors,
1498 Tell target to start a new trace experiment. */
1501 trace_start_command (args
, from_tty
)
1504 { /* STUB_COMM MOSTLY_IMPLEMENTED */
1505 struct tracepoint
*t
;
1508 char *stepping_actions
;
1509 unsigned long step_count
;
1511 dont_repeat (); /* like "run", dangerous to repeat accidentally */
1513 if (target_is_remote ())
1516 remote_get_noisy_reply (target_buf
);
1517 if (strcmp (target_buf
, "OK"))
1518 error ("Target does not support this command.");
1522 int ss_count
; /* if actions include singlestepping */
1523 int disable_mask
; /* ??? */
1524 int enable_mask
; /* ??? */
1526 sprintf (buf
, "QTDP:%x:%x:%c:%x:%x", t
->number
, t
->address
,
1527 t
->enabled
== enabled
? 'E' : 'D',
1528 t
->step_count
, t
->pass_count
);
1531 encode_actions (t
, &tdp_actions
, &step_count
, &stepping_actions
);
1532 /* do_single_steps (t); */
1535 if (strlen (buf
) + strlen (tdp_actions
) >= sizeof (buf
))
1536 error ("Actions for tracepoint %d too complex; "
1537 "please simplify.", t
->number
);
1538 strcat (buf
, tdp_actions
);
1540 if (stepping_actions
)
1543 if (strlen (buf
) + strlen (stepping_actions
) >= sizeof (buf
))
1544 error ("Actions for tracepoint %d too complex; "
1545 "please simplify.", t
->number
);
1546 strcat (buf
, stepping_actions
);
1550 remote_get_noisy_reply (target_buf
);
1551 if (strcmp (target_buf
, "OK"))
1552 error ("Target does not support tracepoints.");
1555 remote_get_noisy_reply (target_buf
);
1556 if (strcmp (target_buf
, "OK"))
1557 error ("Bogus reply from target: %s", target_buf
);
1558 set_traceframe_num (-1); /* all old traceframes invalidated */
1559 set_tracepoint_num (-1);
1560 set_traceframe_context(-1);
1563 printf_filtered ("Trace can only be run on remote targets.\n");
1568 trace_stop_command (args
, from_tty
)
1571 { /* STUB_COMM IS_IMPLEMENTED */
1572 if (target_is_remote ())
1575 remote_get_noisy_reply (target_buf
);
1576 if (strcmp (target_buf
, "OK"))
1577 error ("Bogus reply from target: %s", target_buf
);
1580 error ("Trace can only be run on remote targets.");
1583 /* tstatus command */
1585 trace_status_command (args
, from_tty
)
1588 { /* STUB_COMM IS_IMPLEMENTED */
1589 if (target_is_remote ())
1591 putpkt ("qTStatus");
1592 remote_get_noisy_reply (target_buf
);
1593 if (strcmp (target_buf
, "OK"))
1594 error ("Bogus reply from target: %s", target_buf
);
1597 error ("Trace can only be run on remote targets.");
1600 /* Worker function for the various flavors of the tfind command */
1602 finish_tfind_command (reply
, from_tty
)
1606 int target_frameno
= -1, target_tracept
= -1;
1608 while (reply
&& *reply
)
1611 if ((target_frameno
= strtol (++reply
, &reply
, 16)) == -1)
1613 /* A request for a non-existant trace frame has failed.
1614 Our response will be different, depending on FROM_TTY:
1616 If FROM_TTY is true, meaning that this command was
1617 typed interactively by the user, then give an error
1618 and DO NOT change the state of traceframe_number etc.
1620 However if FROM_TTY is false, meaning that we're either
1621 in a script, a loop, or a user-defined command, then
1622 DON'T give an error, but DO change the state of
1623 traceframe_number etc. to invalid.
1625 The rationalle is that if you typed the command, you
1626 might just have committed a typo or something, and you'd
1627 like to NOT lose your current debugging state. However
1628 if you're in a user-defined command or especially in a
1629 loop, then you need a way to detect that the command
1630 failed WITHOUT aborting. This allows you to write
1631 scripts that search thru the trace buffer until the end,
1632 and then continue on to do something else. */
1635 error ("Target failed to find requested trace frame.");
1639 printf_filtered ("End of trace buffer.\n");
1640 /* The following will not recurse, since it's special-cased */
1641 trace_find_command ("-1", from_tty
);
1646 if ((target_tracept
= strtol (++reply
, &reply
, 16)) == -1)
1647 error ("Target failed to find requested trace frame.");
1649 case 'O': /* "OK"? */
1650 if (reply
[1] == 'K' && reply
[2] == '\0')
1653 error ("Bogus reply from target: %s", reply
);
1656 error ("Bogus reply from target: %s", reply
);
1659 flush_cached_frames ();
1660 registers_changed ();
1661 select_frame (get_current_frame (), 0);
1662 set_traceframe_num (target_frameno
);
1663 set_tracepoint_num (target_tracept
);
1664 set_traceframe_context ((get_current_frame ())->pc
);
1667 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1670 /* trace_find_command takes a trace frame number n,
1671 sends "QTFrame:<n>" to the target,
1672 and accepts a reply that may contain several optional pieces
1673 of information: a frame number, a tracepoint number, and an
1674 indication of whether this is a trap frame or a stepping frame.
1676 The minimal response is just "OK" (which indicates that the
1677 target does not give us a frame number or a tracepoint number).
1678 Instead of that, the target may send us a string containing
1680 F<hexnum> (gives the selected frame number)
1681 T<hexnum> (gives the selected tracepoint number)
1686 trace_find_command (args
, from_tty
)
1689 { /* STUB_COMM PART_IMPLEMENTED */
1690 /* this should only be called with a numeric argument */
1692 int target_frameno
= -1, target_tracept
= -1, target_stepfrm
= 0;
1695 if (target_is_remote ())
1697 if (args
== 0 || *args
== 0)
1698 { /* TFIND with no args means find NEXT trace frame. */
1699 if (traceframe_number
== -1)
1700 frameno
= 0; /* "next" is first one */
1702 frameno
= traceframe_number
+ 1;
1704 else if (0 == strcmp (args
, "-"))
1706 if (traceframe_number
== -1)
1707 error ("not debugging trace buffer");
1708 else if (traceframe_number
== 0)
1709 error ("already at start of trace buffer");
1711 frameno
= traceframe_number
- 1;
1714 else if (0 == strcasecmp (args
, "start"))
1716 else if (0 == strcasecmp (args
, "none") ||
1717 0 == strcasecmp (args
, "end"))
1721 frameno
= parse_and_eval_address (args
);
1723 sprintf (target_buf
, "QTFrame:%x", frameno
);
1724 putpkt (target_buf
);
1725 tmp
= remote_get_noisy_reply (target_buf
);
1727 if (frameno
== -1) /* end trace debugging */
1728 { /* hopefully the stub has complied! */
1729 if (0 != strcmp (tmp
, "F-1"))
1730 error ("Bogus response from target: %s", tmp
);
1732 flush_cached_frames ();
1733 registers_changed ();
1734 select_frame (get_current_frame (), 0);
1735 set_traceframe_num (-1);
1736 set_tracepoint_num (-1);
1737 set_traceframe_context (-1);
1740 print_stack_frame (selected_frame
, selected_frame_level
, 1);
1743 finish_tfind_command (tmp
, from_tty
);
1746 error ("Trace can only be run on remote targets.");
1751 trace_find_end_command (args
, from_tty
)
1755 trace_find_command ("-1", from_tty
);
1760 trace_find_none_command (args
, from_tty
)
1764 trace_find_command ("-1", from_tty
);
1769 trace_find_start_command (args
, from_tty
)
1773 trace_find_command ("0", from_tty
);
1776 /* tfind pc command */
1778 trace_find_pc_command (args
, from_tty
)
1781 { /* STUB_COMM PART_IMPLEMENTED */
1786 if (target_is_remote ())
1788 if (args
== 0 || *args
== 0)
1789 pc
= read_pc (); /* default is current pc */
1791 pc
= parse_and_eval_address (args
);
1793 sprintf (target_buf
, "QTFrame:pc:%x", pc
);
1794 putpkt (target_buf
);
1795 tmp
= remote_get_noisy_reply (target_buf
);
1797 finish_tfind_command (tmp
, from_tty
);
1800 error ("Trace can only be run on remote targets.");
1803 /* tfind tracepoint command */
1805 trace_find_tracepoint_command (args
, from_tty
)
1808 { /* STUB_COMM PART_IMPLEMENTED */
1809 int target_frameno
, tdp
;
1812 if (target_is_remote ())
1814 if (args
== 0 || *args
== 0)
1815 if (tracepoint_number
== -1)
1816 error ("No current tracepoint -- please supply an argument.");
1818 tdp
= tracepoint_number
; /* default is current TDP */
1820 tdp
= parse_and_eval_address (args
);
1822 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1823 putpkt (target_buf
);
1824 tmp
= remote_get_noisy_reply (target_buf
);
1826 finish_tfind_command (tmp
, from_tty
);
1829 error ("Trace can only be run on remote targets.");
1832 /* TFIND LINE command:
1834 This command will take a sourceline for argument, just like BREAK
1835 or TRACE (ie. anything that "decode_line_1" can handle).
1837 With no argument, this command will find the next trace frame
1838 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1841 trace_find_line_command (args
, from_tty
)
1844 { /* STUB_COMM PART_IMPLEMENTED */
1845 static CORE_ADDR start_pc
, end_pc
;
1846 struct symtabs_and_lines sals
;
1847 struct symtab_and_line sal
;
1850 struct cleanup
*old_chain
;
1852 if (target_is_remote ())
1854 if (args
== 0 || *args
== 0)
1856 sal
= find_pc_line ((get_current_frame ())->pc
, 0);
1858 sals
.sals
= (struct symtab_and_line
*)
1859 xmalloc (sizeof (struct symtab_and_line
));
1864 sals
= decode_line_spec (args
, 1);
1868 old_chain
= make_cleanup (free
, sals
.sals
);
1869 if (sal
.symtab
== 0)
1871 printf_filtered ("TFIND: No line number information available");
1874 /* This is useful for "info line *0x7f34". If we can't tell the
1875 user about a source line, at least let them have the symbolic
1877 printf_filtered (" for address ");
1879 print_address (sal
.pc
, gdb_stdout
);
1880 printf_filtered (";\n -- will attempt to find by PC. \n");
1884 printf_filtered (".\n");
1885 return; /* no line, no PC; what can we do? */
1888 else if (sal
.line
> 0
1889 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1891 if (start_pc
== end_pc
)
1893 printf_filtered ("Line %d of \"%s\"",
1894 sal
.line
, sal
.symtab
->filename
);
1896 printf_filtered (" is at address ");
1897 print_address (start_pc
, gdb_stdout
);
1899 printf_filtered (" but contains no code.\n");
1900 sal
= find_pc_line (start_pc
, 0);
1902 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1904 printf_filtered ("Attempting to find line %d instead.\n",
1907 error ("Cannot find a good line.");
1911 /* Is there any case in which we get here, and have an address
1912 which the user would want to see? If we have debugging symbols
1913 and no line numbers? */
1914 error ("Line number %d is out of range for \"%s\".\n",
1915 sal
.line
, sal
.symtab
->filename
);
1917 if (args
&& *args
) /* find within range of stated line */
1918 sprintf (target_buf
, "QTFrame:range:%x:%x", start_pc
, end_pc
- 1);
1919 else /* find OUTSIDE OF range of CURRENT line */
1920 sprintf (target_buf
, "QTFrame:outside:%x:%x", start_pc
, end_pc
- 1);
1921 putpkt (target_buf
);
1922 tmp
= remote_get_noisy_reply (target_buf
);
1924 finish_tfind_command (tmp
, from_tty
);
1925 do_cleanups (old_chain
);
1928 error ("Trace can only be run on remote targets.");
1931 /* tfind range command */
1933 trace_find_range_command (args
, from_tty
)
1936 { /* STUB_COMM PART_IMPLEMENTED */
1937 static CORE_ADDR start
, stop
;
1941 if (target_is_remote ())
1943 if (args
== 0 || *args
== 0)
1944 { /* XXX FIXME: what should default behavior be? */
1945 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1949 if (0 != (tmp
= strchr (args
, ',' )))
1951 *tmp
++ = '\0'; /* terminate start address */
1952 while (isspace (*tmp
))
1954 start
= parse_and_eval_address (args
);
1955 stop
= parse_and_eval_address (tmp
);
1958 { /* no explicit end address? */
1959 start
= parse_and_eval_address (args
);
1960 stop
= start
+ 1; /* ??? */
1963 sprintf (target_buf
, "QTFrame:range:%x:%x", start
, stop
);
1964 putpkt (target_buf
);
1965 tmp
= remote_get_noisy_reply (target_buf
);
1967 finish_tfind_command (tmp
, from_tty
);
1970 error ("Trace can only be run on remote targets.");
1973 /* tfind outside command */
1975 trace_find_outside_command (args
, from_tty
)
1978 { /* STUB_COMM PART_IMPLEMENTED */
1979 CORE_ADDR start
, stop
;
1983 if (target_is_remote ())
1985 if (args
== 0 || *args
== 0)
1986 { /* XXX FIXME: what should default behavior be? */
1987 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1991 if (0 != (tmp
= strchr (args
, ',' )))
1993 *tmp
++ = '\0'; /* terminate start address */
1994 while (isspace (*tmp
))
1996 start
= parse_and_eval_address (args
);
1997 stop
= parse_and_eval_address (tmp
);
2000 { /* no explicit end address? */
2001 start
= parse_and_eval_address (args
);
2002 stop
= start
+ 1; /* ??? */
2005 sprintf (target_buf
, "QTFrame:outside:%x:%x", start
, stop
);
2006 putpkt (target_buf
);
2007 tmp
= remote_get_noisy_reply (target_buf
);
2009 finish_tfind_command (tmp
, from_tty
);
2012 error ("Trace can only be run on remote targets.");
2015 /* save-tracepoints command */
2017 tracepoint_save_command (args
, from_tty
)
2021 struct tracepoint
*tp
;
2022 struct action_line
*line
;
2024 char *i1
= " ", *i2
= " ";
2025 char *indent
, *actionline
;
2027 if (args
== 0 || *args
== 0)
2028 error ("Argument required (file name in which to save tracepoints");
2030 if (tracepoint_chain
== 0)
2032 warning ("save-tracepoints: no tracepoints to save.\n");
2036 if (!(fp
= fopen (args
, "w")))
2037 error ("Unable to open file '%s' for saving tracepoints");
2039 ALL_TRACEPOINTS (tp
)
2041 if (tp
->addr_string
)
2042 fprintf (fp
, "trace %s\n", tp
->addr_string
);
2044 fprintf (fp
, "trace *0x%x\n", tp
->address
);
2047 fprintf (fp
, " passcount %d\n", tp
->pass_count
);
2051 fprintf (fp
, " actions\n");
2053 for (line
= tp
->actions
; line
; line
= line
->next
)
2055 actionline
= line
->action
;
2056 while (isspace(*actionline
))
2059 fprintf (fp
, "%s%s\n", indent
, actionline
);
2060 if (0 == strncasecmp (actionline
, "while-stepping", 14))
2062 else if (0 == strncasecmp (actionline
, "end", 3))
2069 printf_filtered ("Tracepoints saved to file '%s'.\n", args
);
2073 /* info scope command: list the locals for a scope. */
2075 scope_info (args
, from_tty
)
2079 struct symtab_and_line sal
;
2080 struct symtabs_and_lines sals
;
2082 struct minimal_symbol
*msym
;
2083 struct block
*block
;
2084 char **canonical
, *symname
, *save_args
= args
;
2085 int i
, nsyms
, count
= 0;
2087 if (args
== 0 || *args
== 0)
2088 error ("requires an argument (function, line or *addr) to define a scope");
2090 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2091 if (sals
.nelts
== 0)
2092 return; /* presumably decode_line_1 has already warned */
2094 /* Resolve line numbers to PC */
2095 resolve_sal_pc (&sals
.sals
[0]);
2096 block
= block_for_pc (sals
.sals
[0].pc
);
2100 nsyms
= BLOCK_NSYMS (block
);
2101 for (i
= 0; i
< nsyms
; i
++)
2104 printf_filtered ("Scope for %s:\n", save_args
);
2106 sym
= BLOCK_SYM (block
, i
);
2107 symname
= SYMBOL_NAME (sym
);
2108 if (symname
== NULL
|| *symname
== '\0')
2109 continue; /* probably botched, certainly useless */
2111 printf_filtered ("Symbol %s is ", symname
);
2112 switch (SYMBOL_CLASS (sym
)) {
2114 case LOC_UNDEF
: /* messed up symbol? */
2115 printf_filtered ("a bogus symbol, class %d.\n",
2116 SYMBOL_CLASS (sym
));
2117 count
--; /* don't count this one */
2120 printf_filtered ("a constant with value %d (0x%x)",
2121 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2123 case LOC_CONST_BYTES
:
2124 printf_filtered ("constant bytes: ");
2125 if (SYMBOL_TYPE (sym
))
2126 for (i
= 0; i
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); i
++)
2127 fprintf_filtered (gdb_stdout
, " %02x",
2128 (unsigned) SYMBOL_VALUE_BYTES (sym
) [i
]);
2131 printf_filtered ("in static storage at address ");
2132 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2135 printf_filtered ("a local variable in register $%s",
2136 reg_names
[SYMBOL_VALUE (sym
)]);
2140 printf_filtered ("an argument at stack/frame offset %ld",
2141 SYMBOL_VALUE (sym
));
2144 printf_filtered ("a local variable at frame offset %ld",
2145 SYMBOL_VALUE (sym
));
2148 printf_filtered ("a reference argument at offset %ld",
2149 SYMBOL_VALUE (sym
));
2152 printf_filtered ("an argument in register $%s",
2153 reg_names
[SYMBOL_VALUE (sym
)]);
2155 case LOC_REGPARM_ADDR
:
2156 printf_filtered ("the address of an argument, in register $%s",
2157 reg_names
[SYMBOL_VALUE (sym
)]);
2160 printf_filtered ("a typedef.\n");
2163 printf_filtered ("a label at address ");
2164 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym
), 1, gdb_stdout
);
2167 printf_filtered ("a function at address ");
2168 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)), 1,
2172 printf_filtered ("a variable at offset %d from register $%s",
2174 reg_names
[SYMBOL_BASEREG (sym
)]);
2176 case LOC_BASEREG_ARG
:
2177 printf_filtered ("an argument at offset %d from register $%s",
2179 reg_names
[SYMBOL_BASEREG (sym
)]);
2181 case LOC_UNRESOLVED
:
2182 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, NULL
);
2184 printf_filtered ("Unresolved Static");
2187 printf_filtered ("static storage at address ");
2188 print_address_numeric (SYMBOL_VALUE_ADDRESS (msym
), 1,
2192 case LOC_OPTIMIZED_OUT
:
2193 printf_filtered ("optimized out.\n");
2196 if (SYMBOL_TYPE (sym
))
2197 printf_filtered (", length %d.\n",
2198 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2200 if (BLOCK_FUNCTION (block
))
2203 block
= BLOCK_SUPERBLOCK (block
);
2206 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2210 /* worker function (cleanup) */
2212 replace_comma (comma
)
2220 trace_dump_command (args
, from_tty
)
2224 struct tracepoint
*t
;
2225 struct action_line
*action
;
2226 char *action_exp
, *next_comma
;
2227 struct cleanup
*old_cleanups
;
2228 int stepping_actions
= 0;
2229 int stepping_frame
= 0;
2231 if (tracepoint_number
== -1)
2233 warning ("No current trace frame.");
2238 if (t
->number
== tracepoint_number
)
2242 error ("No known tracepoint matches 'current' tracepoint #%d.",
2245 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2247 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2248 tracepoint_number
, traceframe_number
);
2250 /* The current frame is a trap frame if the frame PC is equal
2251 to the tracepoint PC. If not, then the current frame was
2252 collected during single-stepping. */
2254 stepping_frame
= (t
->address
!= read_pc());
2256 for (action
= t
->actions
; action
; action
= action
->next
)
2258 action_exp
= action
->action
;
2259 while (isspace (*action_exp
))
2262 /* The collection actions to be done while stepping are
2263 bracketed by the commands "while-stepping" and "end". */
2265 if (0 == strncasecmp (action_exp
, "while-stepping", 14))
2266 stepping_actions
= 1;
2267 else if (0 == strncasecmp (action_exp
, "end", 3))
2268 stepping_actions
= 0;
2269 else if (0 == strncasecmp (action_exp
, "collect", 7))
2271 /* Display the collected data.
2272 For the trap frame, display only what was collected at the trap.
2273 Likewise for stepping frames, display only what was collected
2274 while stepping. This means that the two boolean variables,
2275 STEPPING_FRAME and STEPPING_ACTIONS should be equal. */
2276 if (stepping_frame
== stepping_actions
)
2279 do { /* repeat over a comma-separated list */
2281 if (*action_exp
== ',')
2283 while (isspace (*action_exp
))
2286 next_comma
= strchr (action_exp
, ',');
2289 make_cleanup (replace_comma
, next_comma
);
2293 if (0 == strncasecmp (action_exp
, "$reg", 4))
2294 registers_info (NULL
, from_tty
);
2295 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2296 locals_info (NULL
, from_tty
);
2297 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2298 args_info (NULL
, from_tty
);
2301 printf_filtered ("%s = ", action_exp
);
2302 output_command (action_exp
, from_tty
);
2303 printf_filtered ("\n");
2307 action_exp
= next_comma
;
2308 } while (action_exp
&& *action_exp
== ',');
2312 discard_cleanups (old_cleanups
);
2315 /* module initialization */
2317 _initialize_tracepoint ()
2319 tracepoint_chain
= 0;
2320 tracepoint_count
= 0;
2321 traceframe_number
= -1;
2322 tracepoint_number
= -1;
2324 set_internalvar (lookup_internalvar ("tpnum"),
2325 value_from_longest (builtin_type_int
, (LONGEST
) 0));
2326 set_internalvar (lookup_internalvar ("trace_frame"),
2327 value_from_longest (builtin_type_int
, (LONGEST
) 0));
2329 if (tracepoint_list
.list
== NULL
)
2331 tracepoint_list
.listsize
= 128;
2332 tracepoint_list
.list
= xmalloc
2333 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2335 if (stepping_list
.list
== NULL
)
2337 stepping_list
.listsize
= 128;
2338 stepping_list
.list
= xmalloc
2339 (stepping_list
.listsize
* sizeof (struct memrange
));
2342 add_info ("scope", scope_info
,
2343 "List the variables local to a scope");
2345 add_cmd ("tracepoints", class_trace
, NO_FUNCTION
,
2346 "Tracing of program execution without stopping the program.",
2349 add_info ("tracepoints", tracepoints_info
,
2350 "Status of tracepoints, or tracepoint number NUMBER.\n\
2351 Convenience variable \"$tpnum\" contains the number of the\n\
2352 last tracepoint set.");
2354 add_info_alias ("tp", "tracepoints", 1);
2356 add_com ("save-tracepoints", class_trace
, tracepoint_save_command
,
2357 "Save current tracepoint definitions as a script.\n\
2358 Use the 'source' command in another debug session to restore them.");
2360 add_com ("tdump", class_trace
, trace_dump_command
,
2361 "Print everything collected at the current tracepoint.");
2363 add_prefix_cmd ("tfind", class_trace
, trace_find_command
,
2364 "Select a trace frame;\n\
2365 No argument means forward by one frame; '-' meand backward by one frame.",
2366 &tfindlist
, "tfind ", 1, &cmdlist
);
2368 add_cmd ("outside", class_trace
, trace_find_outside_command
,
2369 "Select a trace frame whose PC is outside the given \
2370 range.\nUsage: tfind outside addr1, addr2",
2373 add_cmd ("range", class_trace
, trace_find_range_command
,
2374 "Select a trace frame whose PC is in the given range.\n\
2375 Usage: tfind range addr1,addr2",
2378 add_cmd ("line", class_trace
, trace_find_line_command
,
2379 "Select a trace frame by source line.\n\
2380 Argument can be a line number (with optional source file), \n\
2381 a function name, or '*' followed by an address.\n\
2382 Default argument is 'the next source line that was traced'.",
2385 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
,
2386 "Select a trace frame by tracepoint number.\n\
2387 Default is the tracepoint for the current trace frame.",
2390 add_cmd ("pc", class_trace
, trace_find_pc_command
,
2391 "Select a trace frame by PC.\n\
2392 Default is the current PC, or the PC of the current trace frame.",
2395 add_cmd ("end", class_trace
, trace_find_end_command
,
2396 "Synonym for 'none'.\n\
2397 De-select any trace frame and resume 'live' debugging.",
2400 add_cmd ("none", class_trace
, trace_find_none_command
,
2401 "De-select any trace frame and resume 'live' debugging.",
2404 add_cmd ("start", class_trace
, trace_find_start_command
,
2405 "Select the first trace frame in the trace buffer.",
2408 add_com ("tstatus", class_trace
, trace_status_command
,
2409 "Display the status of the current trace data collection.");
2411 add_com ("tstop", class_trace
, trace_stop_command
,
2412 "Stop trace data collection.");
2414 add_com ("tstart", class_trace
, trace_start_command
,
2415 "Start trace data collection.");
2417 add_com ("passcount", class_trace
, trace_pass_command
,
2418 "Set the passcount for a tracepoint.\n\
2419 The trace will end when the tracepoint has been passed 'count' times.\n\
2420 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
2421 if TPNUM is omitted, passcount refers to the last tracepoint defined.");
2423 add_com ("end", class_trace
, end_pseudocom
,
2424 "Ends a list of commands or actions.\n\
2425 Several GDB commands allow you to enter a list of commands or actions.\n\
2426 Entering \"end\" on a line by itself is the normal way to terminate\n\
2428 Note: the \"end\" command cannot be used at the gdb prompt.");
2430 add_com ("while-stepping", class_trace
, while_stepping_pseudocom
,
2431 "Specify single-stepping behavior at a tracepoint.\n\
2432 Argument is number of instructions to trace in single-step mode\n\
2433 following the tracepoint. This command is normally followed by\n\
2434 one or more \"collect\" commands, to specify what to collect\n\
2435 while single-stepping.\n\n\
2436 Note: this command can only be used in a tracepoint \"actions\" list.");
2438 add_com ("collect", class_trace
, collect_pseudocom
,
2439 "Specify one or more data items to be collected at a tracepoint.\n\
2440 Accepts a comma-separated list of (one or more) arguments.\n\
2441 Things that may be collected include registers, variables, plus\n\
2442 the following special arguments:\n\
2443 $regs -- all registers.\n\
2444 $args -- all function arguments.\n\
2445 $locals -- all variables local to the block/function scope.\n\
2446 $(addr,len) -- a literal memory range.\n\
2447 $($reg,addr,len) -- a register-relative literal memory range.\n\n\
2448 Note: this command can only be used in a tracepoint \"actions\" list.");
2450 add_com ("actions", class_trace
, trace_actions_command
,
2451 "Specify the actions to be taken at a tracepoint.\n\
2452 Tracepoint actions may include collecting of specified data, \n\
2453 single-stepping, or enabling/disabling other tracepoints, \n\
2454 depending on target's capabilities.");
2456 add_cmd ("tracepoints", class_trace
, delete_trace_command
,
2457 "Delete specified tracepoints.\n\
2458 Arguments are tracepoint numbers, separated by spaces.\n\
2459 No argument means delete all tracepoints.",
2462 add_cmd ("tracepoints", class_trace
, disable_trace_command
,
2463 "Disable specified tracepoints.\n\
2464 Arguments are tracepoint numbers, separated by spaces.\n\
2465 No argument means disable all tracepoints.",
2468 add_cmd ("tracepoints", class_trace
, enable_trace_command
,
2469 "Enable specified tracepoints.\n\
2470 Arguments are tracepoint numbers, separated by spaces.\n\
2471 No argument means enable all tracepoints.",
2474 add_com ("trace", class_trace
, trace_command
,
2475 "Set a tracepoint at a specified line or function or address.\n\
2476 Argument may be a line number, function name, or '*' plus an address.\n\
2477 For a line number or function, trace at the start of its code.\n\
2478 If an address is specified, trace at that exact address.\n\n\
2479 Do \"help tracepoints\" for info on other tracepoint commands.");
2481 add_com_alias ("tp", "trace", class_alias
, 0);
2482 add_com_alias ("tr", "trace", class_alias
, 1);
2483 add_com_alias ("tra", "trace", class_alias
, 1);
2484 add_com_alias ("trac", "trace", class_alias
, 1);