1 /* Tracing functionality for remote targets in custom GDB protocol
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
26 #include "expression.h"
31 #include "gdb_string.h"
33 #include "breakpoint.h"
34 #include "tracepoint.h"
36 extern int remote_supports_cond_tracepoints (void);
37 extern int remote_supports_fast_tracepoints (void);
38 extern char *unpack_varlen_hex (char *buff
, ULONGEST
*result
);
41 #include "completer.h"
43 #include "dictionary.h"
45 #include "user-regs.h"
53 /* readline include files */
54 #include "readline/readline.h"
55 #include "readline/history.h"
57 /* readline defines this. */
64 extern void stop_tracing ();
66 /* Maximum length of an agent aexpression.
67 This accounts for the fact that packets are limited to 400 bytes
68 (which includes everything -- including the checksum), and assumes
69 the worst case of maximum length for each of the pieces of a
72 NOTE: expressions get mem2hex'ed otherwise this would be twice as
73 large. (400 - 31)/2 == 184 */
74 #define MAX_AGENT_EXPR_LEN 184
76 /* A hook used to notify the UI of tracepoint operations. */
78 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
79 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
81 extern void (*deprecated_readline_begin_hook
) (char *, ...);
82 extern char *(*deprecated_readline_hook
) (char *);
83 extern void (*deprecated_readline_end_hook
) (void);
85 /* GDB commands implemented in other modules:
88 extern void output_command (char *, int);
93 This module defines the following debugger commands:
94 trace : set a tracepoint on a function, line, or address.
95 info trace : list all debugger-defined tracepoints.
96 delete trace : delete one or more tracepoints.
97 enable trace : enable one or more tracepoints.
98 disable trace : disable one or more tracepoints.
99 actions : specify actions to be taken at a tracepoint.
100 passcount : specify a pass count for a tracepoint.
101 tstart : start a trace experiment.
102 tstop : stop a trace experiment.
103 tstatus : query the status of a trace experiment.
104 tfind : find a trace frame in the trace buffer.
105 tdump : print everything collected at the current tracepoint.
106 save-tracepoints : write tracepoint setup into a file.
108 This module defines the following user-visible debugger variables:
109 $trace_frame : sequence number of trace frame currently being debugged.
110 $trace_line : source line of trace frame currently being debugged.
111 $trace_file : source file of trace frame currently being debugged.
112 $tracepoint : tracepoint number of trace frame currently being debugged.
116 /* ======= Important global variables: ======= */
118 /* The list of all trace state variables. We don't retain pointers to
119 any of these for any reason - API is by name or number only - so it
120 works to have a vector of objects. */
122 typedef struct trace_state_variable tsv_s
;
125 static VEC(tsv_s
) *tvariables
;
127 /* The next integer to assign to a variable. */
129 static int next_tsv_number
= 1;
131 /* Number of last traceframe collected. */
132 static int traceframe_number
;
134 /* Tracepoint for last traceframe collected. */
135 static int tracepoint_number
;
137 /* Symbol for function for last traceframe collected */
138 static struct symbol
*traceframe_fun
;
140 /* Symtab and line for last traceframe collected */
141 static struct symtab_and_line traceframe_sal
;
143 /* Tracing command lists */
144 static struct cmd_list_element
*tfindlist
;
146 /* List of expressions to collect by default at each tracepoint hit. */
147 static char *default_collect
= "";
149 static int disconnected_tracing
;
151 static char *target_buf
;
152 static long target_buf_size
;
154 /* ======= Important command functions: ======= */
155 static void trace_actions_command (char *, int);
156 static void trace_start_command (char *, int);
157 static void trace_stop_command (char *, int);
158 static void trace_status_command (char *, int);
159 static void trace_find_command (char *, int);
160 static void trace_find_pc_command (char *, int);
161 static void trace_find_tracepoint_command (char *, int);
162 static void trace_find_line_command (char *, int);
163 static void trace_find_range_command (char *, int);
164 static void trace_find_outside_command (char *, int);
165 static void tracepoint_save_command (char *, int);
166 static void trace_dump_command (char *, int);
168 /* support routines */
170 struct collection_list
;
171 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
172 static char *mem2hex (gdb_byte
*, char *, int);
173 static void add_register (struct collection_list
*collection
,
175 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
176 static void free_actions_list (char **actions_list
);
177 static void free_actions_list_cleanup_wrapper (void *);
179 extern void send_disconnected_tracing_value (int value
);
181 extern void _initialize_tracepoint (void);
183 /* Utility: returns true if "target remote" */
185 target_is_remote (void)
187 if (current_target
.to_shortname
&&
188 (strcmp (current_target
.to_shortname
, "remote") == 0
189 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
195 /* Utility: generate error from an incoming stub packet. */
197 trace_error (char *buf
)
200 return; /* not an error msg */
203 case '1': /* malformed packet error */
204 if (*++buf
== '0') /* general case: */
205 error (_("tracepoint.c: error in outgoing packet."));
207 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
208 strtol (buf
, NULL
, 16));
210 error (_("trace API error 0x%s."), ++buf
);
212 error (_("Target returns error code '%s'."), buf
);
216 /* Utility: wait for reply from stub, while accepting "O" packets. */
218 remote_get_noisy_reply (char **buf_p
,
221 do /* Loop on reply from remote stub. */
224 QUIT
; /* allow user to bail out with ^C */
225 getpkt (buf_p
, sizeof_buf
, 0);
228 error (_("Target does not support this command."));
229 else if (buf
[0] == 'E')
231 else if (buf
[0] == 'O' &&
233 remote_console_output (buf
+ 1); /* 'O' message from stub */
235 return buf
; /* here's the actual reply */
240 /* Set traceframe number to NUM. */
242 set_traceframe_num (int num
)
244 traceframe_number
= num
;
245 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
248 /* Set tracepoint number to NUM. */
250 set_tracepoint_num (int num
)
252 tracepoint_number
= num
;
253 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
256 /* Set externally visible debug variables for querying/printing
257 the traceframe context (line, function, file) */
260 set_traceframe_context (struct frame_info
*trace_frame
)
264 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
267 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
268 traceframe_sal
.symtab
= NULL
;
269 clear_internalvar (lookup_internalvar ("trace_func"));
270 clear_internalvar (lookup_internalvar ("trace_file"));
271 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
275 /* Save as globals for internal use. */
276 trace_pc
= get_frame_pc (trace_frame
);
277 traceframe_sal
= find_pc_line (trace_pc
, 0);
278 traceframe_fun
= find_pc_function (trace_pc
);
280 /* Save linenumber as "$trace_line", a debugger variable visible to
282 set_internalvar_integer (lookup_internalvar ("trace_line"),
283 traceframe_sal
.line
);
285 /* Save func name as "$trace_func", a debugger variable visible to
287 if (traceframe_fun
== NULL
288 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
289 clear_internalvar (lookup_internalvar ("trace_func"));
291 set_internalvar_string (lookup_internalvar ("trace_func"),
292 SYMBOL_LINKAGE_NAME (traceframe_fun
));
294 /* Save file name as "$trace_file", a debugger variable visible to
296 if (traceframe_sal
.symtab
== NULL
297 || traceframe_sal
.symtab
->filename
== NULL
)
298 clear_internalvar (lookup_internalvar ("trace_file"));
300 set_internalvar_string (lookup_internalvar ("trace_file"),
301 traceframe_sal
.symtab
->filename
);
304 /* Create a new trace state variable with the given name. */
306 struct trace_state_variable
*
307 create_trace_state_variable (const char *name
)
309 struct trace_state_variable tsv
;
311 memset (&tsv
, 0, sizeof (tsv
));
313 tsv
.number
= next_tsv_number
++;
314 return VEC_safe_push (tsv_s
, tvariables
, &tsv
);
317 /* Look for a trace state variable of the given name. */
319 struct trace_state_variable
*
320 find_trace_state_variable (const char *name
)
322 struct trace_state_variable
*tsv
;
325 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
326 if (strcmp (name
, tsv
->name
) == 0)
333 delete_trace_state_variable (const char *name
)
335 struct trace_state_variable
*tsv
;
338 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
339 if (strcmp (name
, tsv
->name
) == 0)
341 VEC_unordered_remove (tsv_s
, tvariables
, ix
);
345 warning (_("No trace variable named \"$%s\", not deleting"), name
);
348 /* The 'tvariable' command collects a name and optional expression to
349 evaluate into an initial value. */
352 trace_variable_command (char *args
, int from_tty
)
354 struct expression
*expr
;
355 struct cleanup
*old_chain
;
356 struct internalvar
*intvar
= NULL
;
358 struct trace_state_variable
*tsv
;
361 error_no_arg (_("trace state variable name"));
363 /* All the possible valid arguments are expressions. */
364 expr
= parse_expression (args
);
365 old_chain
= make_cleanup (free_current_contents
, &expr
);
367 if (expr
->nelts
== 0)
368 error (_("No expression?"));
370 /* Only allow two syntaxes; "$name" and "$name=value". */
371 if (expr
->elts
[0].opcode
== OP_INTERNALVAR
)
373 intvar
= expr
->elts
[1].internalvar
;
375 else if (expr
->elts
[0].opcode
== BINOP_ASSIGN
376 && expr
->elts
[1].opcode
== OP_INTERNALVAR
)
378 intvar
= expr
->elts
[2].internalvar
;
379 initval
= value_as_long (evaluate_subexpression_type (expr
, 4));
382 error (_("Syntax must be $NAME [ = EXPR ]"));
385 error (_("No name given"));
387 if (strlen (internalvar_name (intvar
)) <= 0)
388 error (_("Must supply a non-empty variable name"));
390 /* If the variable already exists, just change its initial value. */
391 tsv
= find_trace_state_variable (internalvar_name (intvar
));
394 tsv
->initial_value
= initval
;
395 printf_filtered (_("Trace state variable $%s now has initial value %s.\n"),
396 tsv
->name
, plongest (tsv
->initial_value
));
400 /* Create a new variable. */
401 tsv
= create_trace_state_variable (internalvar_name (intvar
));
402 tsv
->initial_value
= initval
;
404 printf_filtered (_("Trace state variable $%s created, with initial value %s.\n"),
405 tsv
->name
, plongest (tsv
->initial_value
));
407 do_cleanups (old_chain
);
411 delete_trace_variable_command (char *args
, int from_tty
)
415 struct cleanup
*back_to
;
416 struct trace_state_variable
*tsv
;
420 if (query (_("Delete all trace state variables? ")))
421 VEC_free (tsv_s
, tvariables
);
426 argv
= gdb_buildargv (args
);
427 back_to
= make_cleanup_freeargv (argv
);
429 for (i
= 0; argv
[i
] != NULL
; i
++)
432 delete_trace_state_variable (argv
[i
] + 1);
434 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv
[i
]);
437 do_cleanups (back_to
);
442 /* List all the trace state variables. */
445 tvariables_info (char *args
, int from_tty
)
447 struct trace_state_variable
*tsv
;
452 if (target_is_remote ())
456 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
458 /* We don't know anything about the value until we get a
460 tsv
->value_known
= 0;
461 sprintf (buf
, "qTV:%x", tsv
->number
);
463 reply
= remote_get_noisy_reply (&target_buf
, &target_buf_size
);
468 unpack_varlen_hex (reply
+ 1, &tval
);
469 tsv
->value
= (LONGEST
) tval
;
470 tsv
->value_known
= 1;
472 /* FIXME say anything about oddball replies? */
477 if (VEC_length (tsv_s
, tvariables
) == 0)
479 printf_filtered (_("No trace state variables.\n"));
483 printf_filtered (_("Name\t\t Initial\tCurrent\n"));
485 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
487 printf_filtered ("$%s", tsv
->name
);
488 print_spaces_filtered (17 - strlen (tsv
->name
), gdb_stdout
);
489 printf_filtered ("%s ", plongest (tsv
->initial_value
));
490 print_spaces_filtered (11 - strlen (plongest (tsv
->initial_value
)), gdb_stdout
);
491 if (tsv
->value_known
)
492 printf_filtered (" %s", plongest (tsv
->value
));
493 else if (trace_running_p
|| traceframe_number
>= 0)
494 /* The value is/was defined, but we don't have it. */
495 printf_filtered (_(" <unknown>"));
497 /* It is not meaningful to ask about the value. */
498 printf_filtered (_(" <undefined>"));
499 printf_filtered ("\n");
503 /* ACTIONS functions: */
505 /* Prototypes for action-parsing utility commands */
506 static void read_actions (struct breakpoint
*);
508 /* The three functions:
509 collect_pseudocommand,
510 while_stepping_pseudocommand, and
511 end_actions_pseudocommand
512 are placeholders for "commands" that are actually ONLY to be used
513 within a tracepoint action list. If the actual function is ever called,
514 it means that somebody issued the "command" at the top level,
515 which is always an error. */
518 end_actions_pseudocommand (char *args
, int from_tty
)
520 error (_("This command cannot be used at the top level."));
524 while_stepping_pseudocommand (char *args
, int from_tty
)
526 error (_("This command can only be used in a tracepoint actions list."));
530 collect_pseudocommand (char *args
, int from_tty
)
532 error (_("This command can only be used in a tracepoint actions list."));
536 teval_pseudocommand (char *args
, int from_tty
)
538 error (_("This command can only be used in a tracepoint actions list."));
541 /* Enter a list of actions for a tracepoint. */
543 trace_actions_command (char *args
, int from_tty
)
545 struct breakpoint
*t
;
547 char *end_msg
= "End with a line saying just \"end\".";
549 t
= get_tracepoint_by_number (&args
, 0, 1);
552 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
557 if (deprecated_readline_begin_hook
)
558 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
559 else if (input_from_terminal_p ())
560 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
564 t
->step_count
= 0; /* read_actions may set this */
567 if (deprecated_readline_end_hook
)
568 (*deprecated_readline_end_hook
) ();
569 /* tracepoints_changed () */
571 /* else just return */
574 /* worker function */
576 read_actions (struct breakpoint
*t
)
579 char *prompt1
= "> ", *prompt2
= " > ";
580 char *prompt
= prompt1
;
581 enum actionline_type linetype
;
582 extern FILE *instream
;
583 struct action_line
*next
= NULL
, *temp
;
584 struct cleanup
*old_chain
;
586 /* Control-C quits instantly if typed while in this loop
587 since it should not wait until the user types a newline. */
589 /* FIXME: kettenis/20010823: Something is wrong here. In this file
590 STOP_SIGNAL is never defined. So this code has been left out, at
591 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
592 leads to compilation failures since the variable job_control
593 isn't declared. Leave this alone for now. */
596 signal (STOP_SIGNAL
, handle_stop_sig
);
598 old_chain
= make_cleanup_free_actions (t
);
601 /* Make sure that all output has been output. Some machines may
602 let you get away with leaving out some of the gdb_flush, but
605 gdb_flush (gdb_stdout
);
606 gdb_flush (gdb_stderr
);
608 if (deprecated_readline_hook
&& instream
== NULL
)
609 line
= (*deprecated_readline_hook
) (prompt
);
610 else if (instream
== stdin
&& ISATTY (instream
))
612 line
= gdb_readline_wrapper (prompt
);
613 if (line
&& *line
) /* add it to command history */
617 line
= gdb_readline (0);
621 line
= xstrdup ("end");
622 printf_filtered ("end\n");
625 linetype
= validate_actionline (&line
, t
);
626 if (linetype
== BADLINE
)
627 continue; /* already warned -- collect another line */
629 temp
= xmalloc (sizeof (struct action_line
));
633 if (next
== NULL
) /* first action for this tracepoint? */
634 t
->actions
= next
= temp
;
641 if (linetype
== STEPPING
) /* begin "while-stepping" */
643 if (prompt
== prompt2
)
645 warning (_("Already processing 'while-stepping'"));
649 prompt
= prompt2
; /* change prompt for stepping actions */
651 else if (linetype
== END
)
653 if (prompt
== prompt2
)
655 prompt
= prompt1
; /* end of single-stepping actions */
658 { /* end of actions */
659 if (t
->actions
->next
== NULL
)
661 /* An "end" all by itself with no other actions
662 means this tracepoint has no actions.
663 Discard empty list. */
672 signal (STOP_SIGNAL
, SIG_DFL
);
675 discard_cleanups (old_chain
);
678 /* worker function */
680 validate_actionline (char **line
, struct breakpoint
*t
)
682 struct cmd_list_element
*c
;
683 struct expression
*exp
= NULL
;
684 struct cleanup
*old_chain
= NULL
;
687 /* if EOF is typed, *line is NULL */
691 for (p
= *line
; isspace ((int) *p
);)
694 /* Symbol lookup etc. */
695 if (*p
== '\0') /* empty line: just prompt for another line. */
698 if (*p
== '#') /* comment line */
701 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
704 warning (_("'%s' is not an action that I know, or is ambiguous."),
709 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
711 struct agent_expr
*aexpr
;
712 struct agent_reqs areqs
;
715 { /* repeat over a comma-separated list */
716 QUIT
; /* allow user to bail out with ^C */
717 while (isspace ((int) *p
))
720 if (*p
== '$') /* look for special pseudo-symbols */
722 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
723 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
724 (0 == strncasecmp ("loc", p
+ 1, 3)))
729 /* else fall thru, treat p as an expression and parse it! */
731 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
732 old_chain
= make_cleanup (free_current_contents
, &exp
);
734 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
736 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
738 warning (_("constant %s (value %ld) will not be collected."),
739 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
740 SYMBOL_VALUE (exp
->elts
[2].symbol
));
743 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
745 warning (_("%s is optimized away and cannot be collected."),
746 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
751 /* We have something to collect, make sure that the expr to
752 bytecode translator can handle it and that it's not too
754 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
755 make_cleanup_free_agent_expr (aexpr
);
757 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
758 error (_("expression too complicated, try simplifying"));
760 ax_reqs (aexpr
, &areqs
);
761 (void) make_cleanup (xfree
, areqs
.reg_mask
);
763 if (areqs
.flaw
!= agent_flaw_none
)
764 error (_("malformed expression"));
766 if (areqs
.min_height
< 0)
767 error (_("gdb: Internal error: expression has min height < 0"));
769 if (areqs
.max_height
> 20)
770 error (_("expression too complicated, try simplifying"));
772 do_cleanups (old_chain
);
774 while (p
&& *p
++ == ',');
777 else if (cmd_cfunc_eq (c
, teval_pseudocommand
))
779 struct agent_expr
*aexpr
;
782 { /* repeat over a comma-separated list */
783 QUIT
; /* allow user to bail out with ^C */
784 while (isspace ((int) *p
))
787 /* Only expressions are allowed for this action. */
788 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
789 old_chain
= make_cleanup (free_current_contents
, &exp
);
791 /* We have something to evaluate, make sure that the expr to
792 bytecode translator can handle it and that it's not too
794 aexpr
= gen_eval_for_expr (t
->loc
->address
, exp
);
795 make_cleanup_free_agent_expr (aexpr
);
797 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
798 error (_("expression too complicated, try simplifying"));
800 do_cleanups (old_chain
);
802 while (p
&& *p
++ == ',');
805 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
807 char *steparg
; /* in case warning is necessary */
809 while (isspace ((int) *p
))
814 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
816 warning (_("'%s': bad step-count; command ignored."), *line
);
821 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
825 warning (_("'%s' is not a supported tracepoint action."), *line
);
830 /* worker function */
832 free_actions (struct breakpoint
*t
)
834 struct action_line
*line
, *next
;
836 for (line
= t
->actions
; line
; line
= next
)
840 xfree (line
->action
);
847 do_free_actions_cleanup (void *t
)
852 static struct cleanup
*
853 make_cleanup_free_actions (struct breakpoint
*t
)
855 return make_cleanup (do_free_actions_cleanup
, t
);
859 memrange_absolute
= -1
864 int type
; /* memrange_absolute for absolute memory range,
865 else basereg number */
866 bfd_signed_vma start
;
870 struct collection_list
872 unsigned char regs_mask
[32]; /* room for up to 256 regs */
875 struct memrange
*list
;
876 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
878 struct agent_expr
**aexpr_list
;
881 tracepoint_list
, stepping_list
;
883 /* MEMRANGE functions: */
885 static int memrange_cmp (const void *, const void *);
887 /* compare memranges for qsort */
889 memrange_cmp (const void *va
, const void *vb
)
891 const struct memrange
*a
= va
, *b
= vb
;
893 if (a
->type
< b
->type
)
895 if (a
->type
> b
->type
)
897 if (a
->type
== memrange_absolute
)
899 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
901 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
906 if (a
->start
< b
->start
)
908 if (a
->start
> b
->start
)
914 /* Sort the memrange list using qsort, and merge adjacent memranges. */
916 memrange_sortmerge (struct collection_list
*memranges
)
920 qsort (memranges
->list
, memranges
->next_memrange
,
921 sizeof (struct memrange
), memrange_cmp
);
922 if (memranges
->next_memrange
> 0)
924 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
926 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
927 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
930 /* memrange b starts before memrange a ends; merge them. */
931 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
932 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
933 continue; /* next b, same a */
937 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
938 sizeof (struct memrange
));
940 memranges
->next_memrange
= a
+ 1;
944 /* Add a register to a collection list. */
946 add_register (struct collection_list
*collection
, unsigned int regno
)
949 printf_filtered ("collect register %d\n", regno
);
950 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
951 error (_("Internal: register number %d too large for tracepoint"),
953 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
956 /* Add a memrange to a collection list */
958 add_memrange (struct collection_list
*memranges
,
959 int type
, bfd_signed_vma base
,
964 printf_filtered ("(%d,", type
);
966 printf_filtered (",%ld)\n", len
);
969 /* type: memrange_absolute == memory, other n == basereg */
970 memranges
->list
[memranges
->next_memrange
].type
= type
;
971 /* base: addr if memory, offset if reg relative. */
972 memranges
->list
[memranges
->next_memrange
].start
= base
;
973 /* len: we actually save end (base + len) for convenience */
974 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
975 memranges
->next_memrange
++;
976 if (memranges
->next_memrange
>= memranges
->listsize
)
978 memranges
->listsize
*= 2;
979 memranges
->list
= xrealloc (memranges
->list
,
980 memranges
->listsize
);
983 if (type
!= memrange_absolute
) /* Better collect the base register! */
984 add_register (memranges
, type
);
987 /* Add a symbol to a collection list. */
989 collect_symbol (struct collection_list
*collect
,
991 struct gdbarch
*gdbarch
,
992 long frame_regno
, long frame_offset
,
997 bfd_signed_vma offset
;
999 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
1000 switch (SYMBOL_CLASS (sym
))
1003 printf_filtered ("%s: don't know symbol class %d\n",
1004 SYMBOL_PRINT_NAME (sym
),
1005 SYMBOL_CLASS (sym
));
1008 printf_filtered ("constant %s (value %ld) will not be collected.\n",
1009 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
1012 offset
= SYMBOL_VALUE_ADDRESS (sym
);
1017 sprintf_vma (tmp
, offset
);
1018 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
1019 SYMBOL_PRINT_NAME (sym
), len
,
1022 add_memrange (collect
, memrange_absolute
, offset
, len
);
1025 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1027 printf_filtered ("LOC_REG[parm] %s: ",
1028 SYMBOL_PRINT_NAME (sym
));
1029 add_register (collect
, reg
);
1030 /* Check for doubles stored in two registers. */
1031 /* FIXME: how about larger types stored in 3 or more regs? */
1032 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
1033 len
> register_size (gdbarch
, reg
))
1034 add_register (collect
, reg
+ 1);
1037 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
1038 printf_filtered (" (will not collect %s)\n",
1039 SYMBOL_PRINT_NAME (sym
));
1043 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1046 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1047 SYMBOL_PRINT_NAME (sym
), len
);
1048 printf_vma (offset
);
1049 printf_filtered (" from frame ptr reg %d\n", reg
);
1051 add_memrange (collect
, reg
, offset
, len
);
1053 case LOC_REGPARM_ADDR
:
1054 reg
= SYMBOL_VALUE (sym
);
1058 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1059 SYMBOL_PRINT_NAME (sym
), len
);
1060 printf_vma (offset
);
1061 printf_filtered (" from reg %d\n", reg
);
1063 add_memrange (collect
, reg
, offset
, len
);
1067 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
1070 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1071 SYMBOL_PRINT_NAME (sym
), len
);
1072 printf_vma (offset
);
1073 printf_filtered (" from frame ptr reg %d\n", reg
);
1075 add_memrange (collect
, reg
, offset
, len
);
1077 case LOC_UNRESOLVED
:
1078 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
1079 SYMBOL_PRINT_NAME (sym
));
1081 case LOC_OPTIMIZED_OUT
:
1082 printf_filtered ("%s has been optimized out of existence.\n",
1083 SYMBOL_PRINT_NAME (sym
));
1088 struct agent_expr
*aexpr
;
1089 struct cleanup
*old_chain1
= NULL
;
1090 struct agent_reqs areqs
;
1092 aexpr
= gen_trace_for_var (scope
, sym
);
1094 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1096 ax_reqs (aexpr
, &areqs
);
1097 if (areqs
.flaw
!= agent_flaw_none
)
1098 error (_("malformed expression"));
1100 if (areqs
.min_height
< 0)
1101 error (_("gdb: Internal error: expression has min height < 0"));
1102 if (areqs
.max_height
> 20)
1103 error (_("expression too complicated, try simplifying"));
1105 discard_cleanups (old_chain1
);
1106 add_aexpr (collect
, aexpr
);
1108 /* take care of the registers */
1109 if (areqs
.reg_mask_len
> 0)
1113 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1115 QUIT
; /* allow user to bail out with ^C */
1116 if (areqs
.reg_mask
[ndx1
] != 0)
1118 /* assume chars have 8 bits */
1119 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1120 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1121 /* it's used -- record it */
1122 add_register (collect
,
1132 /* Add all locals (or args) symbols to collection list */
1134 add_local_symbols (struct collection_list
*collect
,
1135 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
1136 long frame_regno
, long frame_offset
, int type
)
1139 struct block
*block
;
1140 struct dict_iterator iter
;
1143 block
= block_for_pc (pc
);
1146 QUIT
; /* allow user to bail out with ^C */
1147 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1149 if (SYMBOL_IS_ARGUMENT (sym
)
1150 ? type
== 'A' /* collecting Arguments */
1151 : type
== 'L') /* collecting Locals */
1154 collect_symbol (collect
, sym
, gdbarch
,
1155 frame_regno
, frame_offset
, pc
);
1158 if (BLOCK_FUNCTION (block
))
1161 block
= BLOCK_SUPERBLOCK (block
);
1164 warning (_("No %s found in scope."),
1165 type
== 'L' ? "locals" : "args");
1168 /* worker function */
1170 clear_collection_list (struct collection_list
*list
)
1174 list
->next_memrange
= 0;
1175 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
1177 free_agent_expr (list
->aexpr_list
[ndx
]);
1178 list
->aexpr_list
[ndx
] = NULL
;
1180 list
->next_aexpr_elt
= 0;
1181 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
1184 /* reduce a collection list to string form (for gdb protocol) */
1186 stringify_collection_list (struct collection_list
*list
, char *string
)
1188 char temp_buf
[2048];
1192 char *(*str_list
)[];
1196 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
1197 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
1199 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
1200 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
1202 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
1205 printf_filtered ("\nCollecting registers (mask): 0x");
1210 QUIT
; /* allow user to bail out with ^C */
1212 printf_filtered ("%02X", list
->regs_mask
[i
]);
1213 sprintf (end
, "%02X", list
->regs_mask
[i
]);
1216 (*str_list
)[ndx
] = xstrdup (temp_buf
);
1220 printf_filtered ("\n");
1221 if (list
->next_memrange
> 0 && info_verbose
)
1222 printf_filtered ("Collecting memranges: \n");
1223 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
1225 QUIT
; /* allow user to bail out with ^C */
1226 sprintf_vma (tmp2
, list
->list
[i
].start
);
1229 printf_filtered ("(%d, %s, %ld)\n",
1232 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
1234 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
1236 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1243 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
1245 /* The "%X" conversion specifier expects an unsigned argument,
1246 so passing -1 (memrange_absolute) to it directly gives you
1247 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1249 if (list
->list
[i
].type
== memrange_absolute
)
1250 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
1252 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
1255 count
+= strlen (end
);
1256 end
= temp_buf
+ count
;
1259 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1261 QUIT
; /* allow user to bail out with ^C */
1262 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1264 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1269 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1270 end
+= 10; /* 'X' + 8 hex digits + ',' */
1273 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1274 end
, list
->aexpr_list
[i
]->len
);
1275 count
+= 2 * list
->aexpr_list
[i
]->len
;
1280 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1285 (*str_list
)[ndx
] = NULL
;
1297 free_actions_list_cleanup_wrapper (void *al
)
1299 free_actions_list (al
);
1303 free_actions_list (char **actions_list
)
1307 if (actions_list
== 0)
1310 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1311 xfree (actions_list
[ndx
]);
1313 xfree (actions_list
);
1316 /* Render all actions into gdb protocol. */
1318 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1319 char ***stepping_actions
)
1321 static char tdp_buff
[2048], step_buff
[2048];
1323 struct expression
*exp
= NULL
;
1324 struct action_line
*action
;
1326 struct value
*tempval
;
1327 struct collection_list
*collect
;
1328 struct cmd_list_element
*cmd
;
1329 struct agent_expr
*aexpr
;
1331 LONGEST frame_offset
;
1332 char *default_collect_line
= NULL
;
1333 struct action_line
*default_collect_action
= NULL
;
1335 clear_collection_list (&tracepoint_list
);
1336 clear_collection_list (&stepping_list
);
1337 collect
= &tracepoint_list
;
1339 *tdp_actions
= NULL
;
1340 *stepping_actions
= NULL
;
1342 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1343 t
->loc
->address
, &frame_reg
, &frame_offset
);
1345 action
= t
->actions
;
1347 /* If there are default expressions to collect, make up a collect
1348 action and prepend to the action list to encode. Note that since
1349 validation is per-tracepoint (local var "xyz" might be valid for
1350 one tracepoint and not another, etc), we make up the action on
1351 the fly, and don't cache it. */
1352 if (*default_collect
)
1355 enum actionline_type linetype
;
1357 default_collect_line
= xmalloc (12 + strlen (default_collect
));
1358 sprintf (default_collect_line
, "collect %s", default_collect
);
1359 line
= default_collect_line
;
1360 linetype
= validate_actionline (&line
, t
);
1361 if (linetype
!= BADLINE
)
1363 default_collect_action
= xmalloc (sizeof (struct action_line
));
1364 default_collect_action
->next
= t
->actions
;
1365 default_collect_action
->action
= line
;
1366 action
= default_collect_action
;
1370 for (; action
; action
= action
->next
)
1372 QUIT
; /* allow user to bail out with ^C */
1373 action_exp
= action
->action
;
1374 while (isspace ((int) *action_exp
))
1377 if (*action_exp
== '#') /* comment line */
1380 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1382 error (_("Bad action list item: %s"), action_exp
);
1384 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1387 { /* repeat over a comma-separated list */
1388 QUIT
; /* allow user to bail out with ^C */
1389 while (isspace ((int) *action_exp
))
1392 if (0 == strncasecmp ("$reg", action_exp
, 4))
1394 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1395 add_register (collect
, i
);
1396 action_exp
= strchr (action_exp
, ','); /* more? */
1398 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1400 add_local_symbols (collect
,
1406 action_exp
= strchr (action_exp
, ','); /* more? */
1408 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1410 add_local_symbols (collect
,
1416 action_exp
= strchr (action_exp
, ','); /* more? */
1420 unsigned long addr
, len
;
1421 struct cleanup
*old_chain
= NULL
;
1422 struct cleanup
*old_chain1
= NULL
;
1423 struct agent_reqs areqs
;
1425 exp
= parse_exp_1 (&action_exp
,
1426 block_for_pc (t
->loc
->address
), 1);
1427 old_chain
= make_cleanup (free_current_contents
, &exp
);
1429 switch (exp
->elts
[0].opcode
)
1433 const char *name
= &exp
->elts
[2].string
;
1435 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1436 name
, strlen (name
));
1438 internal_error (__FILE__
, __LINE__
,
1439 _("Register $%s not available"),
1442 printf_filtered ("OP_REGISTER: ");
1443 add_register (collect
, i
);
1448 /* safe because we know it's a simple expression */
1449 tempval
= evaluate_expression (exp
);
1450 addr
= value_address (tempval
);
1451 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1452 add_memrange (collect
, memrange_absolute
, addr
, len
);
1456 collect_symbol (collect
,
1457 exp
->elts
[2].symbol
,
1464 default: /* full-fledged expression */
1465 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1467 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1469 ax_reqs (aexpr
, &areqs
);
1470 if (areqs
.flaw
!= agent_flaw_none
)
1471 error (_("malformed expression"));
1473 if (areqs
.min_height
< 0)
1474 error (_("gdb: Internal error: expression has min height < 0"));
1475 if (areqs
.max_height
> 20)
1476 error (_("expression too complicated, try simplifying"));
1478 discard_cleanups (old_chain1
);
1479 add_aexpr (collect
, aexpr
);
1481 /* take care of the registers */
1482 if (areqs
.reg_mask_len
> 0)
1487 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1489 QUIT
; /* allow user to bail out with ^C */
1490 if (areqs
.reg_mask
[ndx1
] != 0)
1492 /* assume chars have 8 bits */
1493 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1494 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1495 /* it's used -- record it */
1496 add_register (collect
,
1503 do_cleanups (old_chain
);
1506 while (action_exp
&& *action_exp
++ == ',');
1508 else if (cmd_cfunc_eq (cmd
, teval_pseudocommand
))
1511 { /* repeat over a comma-separated list */
1512 QUIT
; /* allow user to bail out with ^C */
1513 while (isspace ((int) *action_exp
))
1517 unsigned long addr
, len
;
1518 struct cleanup
*old_chain
= NULL
;
1519 struct cleanup
*old_chain1
= NULL
;
1520 struct agent_reqs areqs
;
1522 exp
= parse_exp_1 (&action_exp
,
1523 block_for_pc (t
->loc
->address
), 1);
1524 old_chain
= make_cleanup (free_current_contents
, &exp
);
1526 aexpr
= gen_eval_for_expr (t
->loc
->address
, exp
);
1527 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1529 ax_reqs (aexpr
, &areqs
);
1530 if (areqs
.flaw
!= agent_flaw_none
)
1531 error (_("malformed expression"));
1533 if (areqs
.min_height
< 0)
1534 error (_("gdb: Internal error: expression has min height < 0"));
1535 if (areqs
.max_height
> 20)
1536 error (_("expression too complicated, try simplifying"));
1538 discard_cleanups (old_chain1
);
1539 /* Even though we're not officially collecting, add
1540 to the collect list anyway. */
1541 add_aexpr (collect
, aexpr
);
1543 do_cleanups (old_chain
);
1546 while (action_exp
&& *action_exp
++ == ',');
1548 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1550 collect
= &stepping_list
;
1552 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1554 if (collect
== &stepping_list
) /* end stepping actions */
1555 collect
= &tracepoint_list
;
1557 break; /* end tracepoint actions */
1560 memrange_sortmerge (&tracepoint_list
);
1561 memrange_sortmerge (&stepping_list
);
1563 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1565 *stepping_actions
= stringify_collection_list (&stepping_list
,
1568 xfree (default_collect_line
);
1569 xfree (default_collect_action
);
1573 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1575 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1577 collect
->aexpr_list
=
1578 xrealloc (collect
->aexpr_list
,
1579 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1580 collect
->aexpr_listsize
*= 2;
1582 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1583 collect
->next_aexpr_elt
++;
1586 /* Set "transparent" memory ranges
1588 Allow trace mechanism to treat text-like sections
1589 (and perhaps all read-only sections) transparently,
1590 i.e. don't reject memory requests from these address ranges
1591 just because they haven't been collected. */
1594 remote_set_transparent_ranges (void)
1602 return; /* No information to give. */
1604 strcpy (target_buf
, "QTro");
1605 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1607 char tmp1
[40], tmp2
[40];
1609 if ((s
->flags
& SEC_LOAD
) == 0 ||
1610 /* (s->flags & SEC_CODE) == 0 || */
1611 (s
->flags
& SEC_READONLY
) == 0)
1616 size
= bfd_get_section_size (s
);
1617 sprintf_vma (tmp1
, lma
);
1618 sprintf_vma (tmp2
, lma
+ size
);
1619 sprintf (target_buf
+ strlen (target_buf
),
1620 ":%s,%s", tmp1
, tmp2
);
1624 putpkt (target_buf
);
1625 getpkt (&target_buf
, &target_buf_size
, 0);
1631 Tell target to clear any previous trace experiment.
1632 Walk the list of tracepoints, and send them (and their actions)
1633 to the target. If no errors,
1634 Tell target to start a new trace experiment. */
1636 int download_tracepoint (struct breakpoint
*t
);
1639 trace_start_command (char *args
, int from_tty
)
1642 VEC(breakpoint_p
) *tp_vec
= NULL
;
1644 struct breakpoint
*t
;
1645 struct trace_state_variable
*tsv
;
1646 int any_downloaded
= 0;
1648 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1650 if (target_is_remote ())
1653 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1654 if (strcmp (target_buf
, "OK"))
1655 error (_("Target does not support this command."));
1657 tp_vec
= all_tracepoints ();
1658 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1660 t
->number_on_target
= 0;
1661 if (download_tracepoint (t
))
1663 t
->number_on_target
= t
->number
;
1667 VEC_free (breakpoint_p
, tp_vec
);
1669 /* No point in tracing without any tracepoints... */
1670 if (!any_downloaded
)
1671 error ("No tracepoints downloaded, not starting trace");
1673 /* Init any trace state variables that start with nonzero values. */
1675 for (ix
= 0; VEC_iterate (tsv_s
, tvariables
, ix
, tsv
); ++ix
)
1677 if (tsv
->initial_value
!= 0)
1679 sprintf (buf
, "QTDV:%x:%s",
1680 tsv
->number
, phex ((ULONGEST
) tsv
->initial_value
, 8));
1682 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1686 /* Tell target to treat text-like sections as transparent. */
1687 remote_set_transparent_ranges ();
1688 /* Now insert traps and begin collecting data. */
1690 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1691 if (strcmp (target_buf
, "OK"))
1692 error (_("Bogus reply from target: %s"), target_buf
);
1693 set_traceframe_num (-1); /* All old traceframes invalidated. */
1694 set_tracepoint_num (-1);
1695 set_traceframe_context (NULL
);
1696 trace_running_p
= 1;
1697 if (deprecated_trace_start_stop_hook
)
1698 deprecated_trace_start_stop_hook (1, from_tty
);
1702 error (_("Trace can only be run on remote targets."));
1705 /* Send the definition of a single tracepoint to the target. Return 1
1706 if successful, 0 if not. */
1709 download_tracepoint (struct breakpoint
*t
)
1715 char **stepping_actions
;
1717 struct cleanup
*old_chain
= NULL
;
1718 struct agent_expr
*aexpr
;
1719 struct cleanup
*aexpr_chain
= NULL
;
1721 tpaddr
= t
->loc
->address
;
1722 sprintf_vma (tmp
, (t
->loc
? tpaddr
: 0));
1723 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1725 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1726 t
->step_count
, t
->pass_count
);
1727 /* Fast tracepoints are mostly handled by the target, but we can
1728 tell the target how big of an instruction block should be moved
1730 if (t
->type
== bp_fast_tracepoint
)
1732 /* Only test for support at download time; we may not know
1733 target capabilities at definition time. */
1734 if (remote_supports_fast_tracepoints ())
1738 if (gdbarch_fast_tracepoint_valid_at (get_current_arch (),
1739 tpaddr
, &isize
, NULL
))
1740 sprintf (buf
+ strlen (buf
), ":F%x", isize
);
1742 /* If it passed validation at definition but fails now,
1743 something is very wrong. */
1744 internal_error (__FILE__
, __LINE__
,
1745 "Fast tracepoint not valid during download");
1748 /* Fast tracepoints are functionally identical to regular
1749 tracepoints, so don't take lack of support as a reason to
1750 give up on the trace run. */
1751 warning (_("Target does not support fast tracepoints, downloading %d as regular tracepoint"), t
->number
);
1753 /* If the tracepoint has a conditional, make it into an agent
1754 expression and append to the definition. */
1757 /* Only test support at download time, we may not know target
1758 capabilities at definition time. */
1759 if (remote_supports_cond_tracepoints ())
1761 aexpr
= gen_eval_for_expr (t
->loc
->address
, t
->loc
->cond
);
1762 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
1763 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
1764 mem2hex (aexpr
->buf
, buf
+ strlen (buf
), aexpr
->len
);
1765 do_cleanups (aexpr_chain
);
1768 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t
->number
);
1771 if (t
->actions
|| *default_collect
)
1774 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1775 if (strcmp (target_buf
, "OK"))
1776 error (_("Target does not support tracepoints."));
1778 if (!t
->actions
&& !*default_collect
)
1781 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1782 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1784 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1786 /* do_single_steps (t); */
1789 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1791 QUIT
; /* allow user to bail out with ^C */
1792 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1793 t
->number
, tmp
, /* address */
1795 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1798 remote_get_noisy_reply (&target_buf
,
1800 if (strcmp (target_buf
, "OK"))
1801 error (_("Error on target while setting tracepoints."));
1804 if (stepping_actions
)
1806 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1808 QUIT
; /* allow user to bail out with ^C */
1809 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1810 t
->number
, tmp
, /* address */
1811 ((ndx
== 0) ? "S" : ""),
1812 stepping_actions
[ndx
],
1813 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1815 remote_get_noisy_reply (&target_buf
,
1817 if (strcmp (target_buf
, "OK"))
1818 error (_("Error on target while setting tracepoints."));
1821 do_cleanups (old_chain
);
1827 trace_stop_command (char *args
, int from_tty
)
1829 if (target_is_remote ())
1832 if (deprecated_trace_start_stop_hook
)
1833 deprecated_trace_start_stop_hook (0, from_tty
);
1836 error (_("Trace can only be run on remote targets."));
1843 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1844 if (strcmp (target_buf
, "OK"))
1845 error (_("Bogus reply from target: %s"), target_buf
);
1846 trace_running_p
= 0;
1849 unsigned long trace_running_p
;
1854 putpkt ("qTStatus");
1855 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1857 if (target_buf
[0] != 'T' ||
1858 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1859 error (_("Bogus trace status reply from target: %s"), target_buf
);
1861 /* exported for use by the GUI */
1862 trace_running_p
= (target_buf
[1] == '1');
1865 /* tstatus command */
1867 trace_status_command (char *args
, int from_tty
)
1869 if (target_is_remote ())
1871 get_trace_status ();
1873 if (trace_running_p
)
1875 printf_filtered (_("Trace is running on the target.\n"));
1876 if (disconnected_tracing
)
1877 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1879 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1882 printf_filtered (_("Trace is not running on the target.\n"));
1884 if (traceframe_number
>= 0)
1885 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1886 traceframe_number
, tracepoint_number
);
1888 printf_filtered (_("Not looking at any trace frame.\n"));
1892 error (_("Trace can only be run on remote targets."));
1896 disconnect_or_stop_tracing (int from_tty
)
1898 if (trace_running_p
&& from_tty
)
1900 int cont
= query (_("Trace is running. Continue tracing after detach? "));
1901 /* Note that we send the query result without affecting the
1902 user's setting of disconnected_tracing, so that the answer is
1904 send_disconnected_tracing_value (cont
);
1906 /* Also ensure that we do the equivalent of a tstop command if
1907 tracing is not to continue after the detach. */
1913 /* Worker function for the various flavors of the tfind command. */
1915 finish_tfind_command (char **msg
,
1919 int target_frameno
= -1, target_tracept
= -1;
1920 struct frame_id old_frame_id
;
1922 struct breakpoint
*tp
;
1924 old_frame_id
= get_frame_id (get_current_frame ());
1927 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1929 while (reply
&& *reply
)
1933 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1935 /* A request for a non-existant trace frame has failed.
1936 Our response will be different, depending on FROM_TTY:
1938 If FROM_TTY is true, meaning that this command was
1939 typed interactively by the user, then give an error
1940 and DO NOT change the state of traceframe_number etc.
1942 However if FROM_TTY is false, meaning that we're either
1943 in a script, a loop, or a user-defined command, then
1944 DON'T give an error, but DO change the state of
1945 traceframe_number etc. to invalid.
1947 The rationalle is that if you typed the command, you
1948 might just have committed a typo or something, and you'd
1949 like to NOT lose your current debugging state. However
1950 if you're in a user-defined command or especially in a
1951 loop, then you need a way to detect that the command
1952 failed WITHOUT aborting. This allows you to write
1953 scripts that search thru the trace buffer until the end,
1954 and then continue on to do something else. */
1957 error (_("Target failed to find requested trace frame."));
1961 printf_filtered ("End of trace buffer.\n");
1962 /* The following will not recurse, since it's
1964 trace_find_command ("-1", from_tty
);
1965 reply
= NULL
; /* Break out of loop
1966 (avoid recursive nonsense). */
1971 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1972 error (_("Target failed to find requested trace frame."));
1974 case 'O': /* "OK"? */
1975 if (reply
[1] == 'K' && reply
[2] == '\0')
1978 error (_("Bogus reply from target: %s"), reply
);
1981 error (_("Bogus reply from target: %s"), reply
);
1984 tp
= get_tracepoint_by_number_on_target (target_tracept
);
1986 reinit_frame_cache ();
1987 registers_changed ();
1988 set_traceframe_num (target_frameno
);
1989 set_tracepoint_num (tp
? tp
->number
: target_tracept
);
1990 if (target_frameno
== -1)
1991 set_traceframe_context (NULL
);
1993 set_traceframe_context (get_current_frame ());
1997 enum print_what print_what
;
1999 /* NOTE: in immitation of the step command, try to determine
2000 whether we have made a transition from one function to
2001 another. If so, we'll print the "stack frame" (ie. the new
2002 function and it's arguments) -- otherwise we'll just show the
2005 if (frame_id_eq (old_frame_id
,
2006 get_frame_id (get_current_frame ())))
2007 print_what
= SRC_LINE
;
2009 print_what
= SRC_AND_LOC
;
2011 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
2016 /* trace_find_command takes a trace frame number n,
2017 sends "QTFrame:<n>" to the target,
2018 and accepts a reply that may contain several optional pieces
2019 of information: a frame number, a tracepoint number, and an
2020 indication of whether this is a trap frame or a stepping frame.
2022 The minimal response is just "OK" (which indicates that the
2023 target does not give us a frame number or a tracepoint number).
2024 Instead of that, the target may send us a string containing
2026 F<hexnum> (gives the selected frame number)
2027 T<hexnum> (gives the selected tracepoint number)
2032 trace_find_command (char *args
, int from_tty
)
2033 { /* this should only be called with a numeric argument */
2036 if (target_is_remote ())
2038 if (trace_running_p
)
2039 error ("May not look at trace frames while trace is running.");
2041 if (deprecated_trace_find_hook
)
2042 deprecated_trace_find_hook (args
, from_tty
);
2044 if (args
== 0 || *args
== 0)
2045 { /* TFIND with no args means find NEXT trace frame. */
2046 if (traceframe_number
== -1)
2047 frameno
= 0; /* "next" is first one */
2049 frameno
= traceframe_number
+ 1;
2051 else if (0 == strcmp (args
, "-"))
2053 if (traceframe_number
== -1)
2054 error (_("not debugging trace buffer"));
2055 else if (from_tty
&& traceframe_number
== 0)
2056 error (_("already at start of trace buffer"));
2058 frameno
= traceframe_number
- 1;
2061 frameno
= parse_and_eval_long (args
);
2064 error (_("invalid input (%d is less than zero)"), frameno
);
2066 sprintf (target_buf
, "QTFrame:%x", frameno
);
2067 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2070 error (_("Trace can only be run on remote targets."));
2075 trace_find_end_command (char *args
, int from_tty
)
2077 trace_find_command ("-1", from_tty
);
2082 trace_find_none_command (char *args
, int from_tty
)
2084 trace_find_command ("-1", from_tty
);
2089 trace_find_start_command (char *args
, int from_tty
)
2091 trace_find_command ("0", from_tty
);
2094 /* tfind pc command */
2096 trace_find_pc_command (char *args
, int from_tty
)
2101 if (target_is_remote ())
2103 if (trace_running_p
)
2104 error ("May not look at trace frames while trace is running.");
2106 if (args
== 0 || *args
== 0)
2107 pc
= regcache_read_pc (get_current_regcache ());
2109 pc
= parse_and_eval_address (args
);
2111 sprintf_vma (tmp
, pc
);
2112 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
2113 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2116 error (_("Trace can only be run on remote targets."));
2119 /* tfind tracepoint command */
2121 trace_find_tracepoint_command (char *args
, int from_tty
)
2124 struct breakpoint
*tp
;
2126 if (target_is_remote ())
2128 if (trace_running_p
)
2129 error ("May not look at trace frames while trace is running.");
2131 if (args
== 0 || *args
== 0)
2133 if (tracepoint_number
== -1)
2134 error (_("No current tracepoint -- please supply an argument."));
2136 tdp
= tracepoint_number
; /* default is current TDP */
2139 tdp
= parse_and_eval_long (args
);
2141 /* If we have the tracepoint on hand, use the number that the
2142 target knows about (which may be different if we disconnected
2143 and reconnected). */
2144 tp
= get_tracepoint (tdp
);
2146 tdp
= tp
->number_on_target
;
2148 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
2149 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2152 error (_("Trace can only be run on remote targets."));
2155 /* TFIND LINE command:
2157 This command will take a sourceline for argument, just like BREAK
2158 or TRACE (ie. anything that "decode_line_1" can handle).
2160 With no argument, this command will find the next trace frame
2161 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2164 trace_find_line_command (char *args
, int from_tty
)
2166 static CORE_ADDR start_pc
, end_pc
;
2167 struct symtabs_and_lines sals
;
2168 struct symtab_and_line sal
;
2169 struct cleanup
*old_chain
;
2170 char startpc_str
[40], endpc_str
[40];
2172 if (target_is_remote ())
2174 if (trace_running_p
)
2175 error ("May not look at trace frames while trace is running.");
2177 if (args
== 0 || *args
== 0)
2179 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
2181 sals
.sals
= (struct symtab_and_line
*)
2182 xmalloc (sizeof (struct symtab_and_line
));
2187 sals
= decode_line_spec (args
, 1);
2191 old_chain
= make_cleanup (xfree
, sals
.sals
);
2192 if (sal
.symtab
== 0)
2194 struct gdbarch
*gdbarch
= get_current_arch ();
2196 printf_filtered ("TFIND: No line number information available");
2199 /* This is useful for "info line *0x7f34". If we can't
2200 tell the user about a source line, at least let them
2201 have the symbolic address. */
2202 printf_filtered (" for address ");
2204 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
2205 printf_filtered (";\n -- will attempt to find by PC. \n");
2209 printf_filtered (".\n");
2210 return; /* No line, no PC; what can we do? */
2213 else if (sal
.line
> 0
2214 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
2216 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
2218 if (start_pc
== end_pc
)
2220 printf_filtered ("Line %d of \"%s\"",
2221 sal
.line
, sal
.symtab
->filename
);
2223 printf_filtered (" is at address ");
2224 print_address (gdbarch
, start_pc
, gdb_stdout
);
2226 printf_filtered (" but contains no code.\n");
2227 sal
= find_pc_line (start_pc
, 0);
2229 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
2231 printf_filtered ("Attempting to find line %d instead.\n",
2234 error (_("Cannot find a good line."));
2238 /* Is there any case in which we get here, and have an address
2239 which the user would want to see? If we have debugging
2240 symbols and no line numbers? */
2241 error (_("Line number %d is out of range for \"%s\"."),
2242 sal
.line
, sal
.symtab
->filename
);
2244 sprintf_vma (startpc_str
, start_pc
);
2245 sprintf_vma (endpc_str
, end_pc
- 1);
2246 /* Find within range of stated line. */
2248 sprintf (target_buf
, "QTFrame:range:%s:%s",
2249 startpc_str
, endpc_str
);
2250 /* Find OUTSIDE OF range of CURRENT line. */
2252 sprintf (target_buf
, "QTFrame:outside:%s:%s",
2253 startpc_str
, endpc_str
);
2254 finish_tfind_command (&target_buf
, &target_buf_size
,
2256 do_cleanups (old_chain
);
2259 error (_("Trace can only be run on remote targets."));
2262 /* tfind range command */
2264 trace_find_range_command (char *args
, int from_tty
)
2266 static CORE_ADDR start
, stop
;
2267 char start_str
[40], stop_str
[40];
2270 if (target_is_remote ())
2272 if (trace_running_p
)
2273 error ("May not look at trace frames while trace is running.");
2275 if (args
== 0 || *args
== 0)
2276 { /* XXX FIXME: what should default behavior be? */
2277 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2281 if (0 != (tmp
= strchr (args
, ',')))
2283 *tmp
++ = '\0'; /* terminate start address */
2284 while (isspace ((int) *tmp
))
2286 start
= parse_and_eval_address (args
);
2287 stop
= parse_and_eval_address (tmp
);
2290 { /* no explicit end address? */
2291 start
= parse_and_eval_address (args
);
2292 stop
= start
+ 1; /* ??? */
2295 sprintf_vma (start_str
, start
);
2296 sprintf_vma (stop_str
, stop
);
2297 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
2298 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2301 error (_("Trace can only be run on remote targets."));
2304 /* tfind outside command */
2306 trace_find_outside_command (char *args
, int from_tty
)
2308 CORE_ADDR start
, stop
;
2309 char start_str
[40], stop_str
[40];
2312 if (target_is_remote ())
2314 if (trace_running_p
)
2315 error ("May not look at trace frames while trace is running.");
2317 if (args
== 0 || *args
== 0)
2318 { /* XXX FIXME: what should default behavior be? */
2319 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2323 if (0 != (tmp
= strchr (args
, ',')))
2325 *tmp
++ = '\0'; /* terminate start address */
2326 while (isspace ((int) *tmp
))
2328 start
= parse_and_eval_address (args
);
2329 stop
= parse_and_eval_address (tmp
);
2332 { /* no explicit end address? */
2333 start
= parse_and_eval_address (args
);
2334 stop
= start
+ 1; /* ??? */
2337 sprintf_vma (start_str
, start
);
2338 sprintf_vma (stop_str
, stop
);
2339 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
2340 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
2343 error (_("Trace can only be run on remote targets."));
2346 /* info scope command: list the locals for a scope. */
2348 scope_info (char *args
, int from_tty
)
2350 struct symtabs_and_lines sals
;
2352 struct minimal_symbol
*msym
;
2353 struct block
*block
;
2354 char **canonical
, *symname
, *save_args
= args
;
2355 struct dict_iterator iter
;
2357 struct gdbarch
*gdbarch
;
2360 if (args
== 0 || *args
== 0)
2361 error (_("requires an argument (function, line or *addr) to define a scope"));
2363 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
2364 if (sals
.nelts
== 0)
2365 return; /* presumably decode_line_1 has already warned */
2367 /* Resolve line numbers to PC */
2368 resolve_sal_pc (&sals
.sals
[0]);
2369 block
= block_for_pc (sals
.sals
[0].pc
);
2373 QUIT
; /* allow user to bail out with ^C */
2374 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
2376 QUIT
; /* allow user to bail out with ^C */
2378 printf_filtered ("Scope for %s:\n", save_args
);
2381 symname
= SYMBOL_PRINT_NAME (sym
);
2382 if (symname
== NULL
|| *symname
== '\0')
2383 continue; /* probably botched, certainly useless */
2385 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
2387 printf_filtered ("Symbol %s is ", symname
);
2388 switch (SYMBOL_CLASS (sym
))
2391 case LOC_UNDEF
: /* messed up symbol? */
2392 printf_filtered ("a bogus symbol, class %d.\n",
2393 SYMBOL_CLASS (sym
));
2394 count
--; /* don't count this one */
2397 printf_filtered ("a constant with value %ld (0x%lx)",
2398 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
2400 case LOC_CONST_BYTES
:
2401 printf_filtered ("constant bytes: ");
2402 if (SYMBOL_TYPE (sym
))
2403 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
2404 fprintf_filtered (gdb_stdout
, " %02x",
2405 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
2408 printf_filtered ("in static storage at address ");
2409 printf_filtered ("%s", paddress (gdbarch
,
2410 SYMBOL_VALUE_ADDRESS (sym
)));
2413 /* GDBARCH is the architecture associated with the objfile
2414 the symbol is defined in; the target architecture may be
2415 different, and may provide additional registers. However,
2416 we do not know the target architecture at this point.
2417 We assume the objfile architecture will contain all the
2418 standard registers that occur in debug info in that
2420 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2422 if (SYMBOL_IS_ARGUMENT (sym
))
2423 printf_filtered ("an argument in register $%s",
2424 gdbarch_register_name (gdbarch
, regno
));
2426 printf_filtered ("a local variable in register $%s",
2427 gdbarch_register_name (gdbarch
, regno
));
2430 printf_filtered ("an argument at stack/frame offset %ld",
2431 SYMBOL_VALUE (sym
));
2434 printf_filtered ("a local variable at frame offset %ld",
2435 SYMBOL_VALUE (sym
));
2438 printf_filtered ("a reference argument at offset %ld",
2439 SYMBOL_VALUE (sym
));
2441 case LOC_REGPARM_ADDR
:
2442 /* Note comment at LOC_REGISTER. */
2443 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
2444 printf_filtered ("the address of an argument, in register $%s",
2445 gdbarch_register_name (gdbarch
, regno
));
2448 printf_filtered ("a typedef.\n");
2451 printf_filtered ("a label at address ");
2452 printf_filtered ("%s", paddress (gdbarch
,
2453 SYMBOL_VALUE_ADDRESS (sym
)));
2456 printf_filtered ("a function at address ");
2457 printf_filtered ("%s",
2458 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2460 case LOC_UNRESOLVED
:
2461 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2464 printf_filtered ("Unresolved Static");
2467 printf_filtered ("static storage at address ");
2468 printf_filtered ("%s",
2469 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
2472 case LOC_OPTIMIZED_OUT
:
2473 printf_filtered ("optimized out.\n");
2476 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
2479 if (SYMBOL_TYPE (sym
))
2480 printf_filtered (", length %d.\n",
2481 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2483 if (BLOCK_FUNCTION (block
))
2486 block
= BLOCK_SUPERBLOCK (block
);
2489 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2493 /* worker function (cleanup) */
2495 replace_comma (void *data
)
2503 trace_dump_command (char *args
, int from_tty
)
2505 struct regcache
*regcache
;
2506 struct gdbarch
*gdbarch
;
2507 struct breakpoint
*t
;
2508 struct action_line
*action
;
2509 char *action_exp
, *next_comma
;
2510 struct cleanup
*old_cleanups
;
2511 int stepping_actions
= 0;
2512 int stepping_frame
= 0;
2514 if (!target_is_remote ())
2516 error (_("Trace can only be run on remote targets."));
2520 if (tracepoint_number
== -1)
2522 warning (_("No current trace frame."));
2526 t
= get_tracepoint (tracepoint_number
);
2529 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2532 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2534 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2535 tracepoint_number
, traceframe_number
);
2537 /* The current frame is a trap frame if the frame PC is equal
2538 to the tracepoint PC. If not, then the current frame was
2539 collected during single-stepping. */
2541 regcache
= get_current_regcache ();
2542 gdbarch
= get_regcache_arch (regcache
);
2544 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2545 - gdbarch_decr_pc_after_break (gdbarch
)));
2547 for (action
= t
->actions
; action
; action
= action
->next
)
2549 struct cmd_list_element
*cmd
;
2551 QUIT
; /* allow user to bail out with ^C */
2552 action_exp
= action
->action
;
2553 while (isspace ((int) *action_exp
))
2556 /* The collection actions to be done while stepping are
2557 bracketed by the commands "while-stepping" and "end". */
2559 if (*action_exp
== '#') /* comment line */
2562 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2564 error (_("Bad action list item: %s"), action_exp
);
2566 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2567 stepping_actions
= 1;
2568 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2569 stepping_actions
= 0;
2570 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2572 /* Display the collected data.
2573 For the trap frame, display only what was collected at
2574 the trap. Likewise for stepping frames, display only
2575 what was collected while stepping. This means that the
2576 two boolean variables, STEPPING_FRAME and
2577 STEPPING_ACTIONS should be equal. */
2578 if (stepping_frame
== stepping_actions
)
2581 { /* repeat over a comma-separated list */
2582 QUIT
; /* allow user to bail out with ^C */
2583 if (*action_exp
== ',')
2585 while (isspace ((int) *action_exp
))
2588 next_comma
= strchr (action_exp
, ',');
2590 if (0 == strncasecmp (action_exp
, "$reg", 4))
2591 registers_info (NULL
, from_tty
);
2592 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2593 locals_info (NULL
, from_tty
);
2594 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2595 args_info (NULL
, from_tty
);
2600 make_cleanup (replace_comma
, next_comma
);
2603 printf_filtered ("%s = ", action_exp
);
2604 output_command (action_exp
, from_tty
);
2605 printf_filtered ("\n");
2609 action_exp
= next_comma
;
2611 while (action_exp
&& *action_exp
== ',');
2615 discard_cleanups (old_cleanups
);
2618 /* Tell the target what to do with an ongoing tracing run if GDB
2619 disconnects for some reason. */
2622 send_disconnected_tracing_value (int value
)
2626 /* No need to do anything special if target not active. */
2627 if (!target_is_remote ())
2630 sprintf (buf
, "QTDisconnected:%x", value
);
2632 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
2633 if (strcmp (target_buf
, "OK"))
2634 error (_("Target does not support this command."));
2638 set_disconnected_tracing (char *args
, int from_tty
,
2639 struct cmd_list_element
*c
)
2641 send_disconnected_tracing_value (disconnected_tracing
);
2644 /* Convert the memory pointed to by mem into hex, placing result in buf.
2645 * Return a pointer to the last char put in buf (null)
2646 * "stolen" from sparc-stub.c
2649 static const char hexchars
[] = "0123456789abcdef";
2652 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2660 *buf
++ = hexchars
[ch
>> 4];
2661 *buf
++ = hexchars
[ch
& 0xf];
2670 get_traceframe_number (void)
2672 return traceframe_number
;
2675 /* module initialization */
2677 _initialize_tracepoint (void)
2679 struct cmd_list_element
*c
;
2681 traceframe_number
= -1;
2682 tracepoint_number
= -1;
2684 if (tracepoint_list
.list
== NULL
)
2686 tracepoint_list
.listsize
= 128;
2687 tracepoint_list
.list
= xmalloc
2688 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2690 if (tracepoint_list
.aexpr_list
== NULL
)
2692 tracepoint_list
.aexpr_listsize
= 128;
2693 tracepoint_list
.aexpr_list
= xmalloc
2694 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2697 if (stepping_list
.list
== NULL
)
2699 stepping_list
.listsize
= 128;
2700 stepping_list
.list
= xmalloc
2701 (stepping_list
.listsize
* sizeof (struct memrange
));
2704 if (stepping_list
.aexpr_list
== NULL
)
2706 stepping_list
.aexpr_listsize
= 128;
2707 stepping_list
.aexpr_list
= xmalloc
2708 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2711 add_info ("scope", scope_info
,
2712 _("List the variables local to a scope"));
2714 add_cmd ("tracepoints", class_trace
, NULL
,
2715 _("Tracing of program execution without stopping the program."),
2718 add_com ("tdump", class_trace
, trace_dump_command
,
2719 _("Print everything collected at the current tracepoint."));
2721 c
= add_com ("tvariable", class_trace
, trace_variable_command
,_("\
2722 Define a trace state variable.\n\
2723 Argument is a $-prefixed name, optionally followed\n\
2724 by '=' and an expression that sets the initial value\n\
2725 at the start of tracing."));
2726 set_cmd_completer (c
, expression_completer
);
2728 add_cmd ("tvariable", class_trace
, delete_trace_variable_command
, _("\
2729 Delete one or more trace state variables.\n\
2730 Arguments are the names of the variables to delete.\n\
2731 If no arguments are supplied, delete all variables."), &deletelist
);
2732 /* FIXME add a trace variable completer */
2734 add_info ("tvariables", tvariables_info
, _("\
2735 Status of trace state variables and their values.\n\
2738 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2739 Select a trace frame;\n\
2740 No argument means forward by one frame; '-' means backward by one frame."),
2741 &tfindlist
, "tfind ", 1, &cmdlist
);
2743 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2744 Select a trace frame whose PC is outside the given range.\n\
2745 Usage: tfind outside addr1, addr2"),
2748 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2749 Select a trace frame whose PC is in the given range.\n\
2750 Usage: tfind range addr1,addr2"),
2753 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2754 Select a trace frame by source line.\n\
2755 Argument can be a line number (with optional source file), \n\
2756 a function name, or '*' followed by an address.\n\
2757 Default argument is 'the next source line that was traced'."),
2760 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2761 Select a trace frame by tracepoint number.\n\
2762 Default is the tracepoint for the current trace frame."),
2765 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2766 Select a trace frame by PC.\n\
2767 Default is the current PC, or the PC of the current trace frame."),
2770 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2771 Synonym for 'none'.\n\
2772 De-select any trace frame and resume 'live' debugging."),
2775 add_cmd ("none", class_trace
, trace_find_none_command
,
2776 _("De-select any trace frame and resume 'live' debugging."),
2779 add_cmd ("start", class_trace
, trace_find_start_command
,
2780 _("Select the first trace frame in the trace buffer."),
2783 add_com ("tstatus", class_trace
, trace_status_command
,
2784 _("Display the status of the current trace data collection."));
2786 add_com ("tstop", class_trace
, trace_stop_command
,
2787 _("Stop trace data collection."));
2789 add_com ("tstart", class_trace
, trace_start_command
,
2790 _("Start trace data collection."));
2792 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2793 Ends a list of commands or actions.\n\
2794 Several GDB commands allow you to enter a list of commands or actions.\n\
2795 Entering \"end\" on a line by itself is the normal way to terminate\n\
2797 Note: the \"end\" command cannot be used at the gdb prompt."));
2799 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2800 Specify single-stepping behavior at a tracepoint.\n\
2801 Argument is number of instructions to trace in single-step mode\n\
2802 following the tracepoint. This command is normally followed by\n\
2803 one or more \"collect\" commands, to specify what to collect\n\
2804 while single-stepping.\n\n\
2805 Note: this command can only be used in a tracepoint \"actions\" list."));
2807 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2808 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2810 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2811 Specify one or more data items to be collected at a tracepoint.\n\
2812 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2813 collect all data (variables, registers) referenced by that expression.\n\
2814 Also accepts the following special arguments:\n\
2815 $regs -- all registers.\n\
2816 $args -- all function arguments.\n\
2817 $locals -- all variables local to the block/function scope.\n\
2818 Note: this command can only be used in a tracepoint \"actions\" list."));
2820 add_com ("teval", class_trace
, teval_pseudocommand
, _("\
2821 Specify one or more expressions to be evaluated at a tracepoint.\n\
2822 Accepts a comma-separated list of (one or more) expressions.\n\
2823 The result of each evaluation will be discarded.\n\
2824 Note: this command can only be used in a tracepoint \"actions\" list."));
2826 add_com ("actions", class_trace
, trace_actions_command
, _("\
2827 Specify the actions to be taken at a tracepoint.\n\
2828 Tracepoint actions may include collecting of specified data, \n\
2829 single-stepping, or enabling/disabling other tracepoints, \n\
2830 depending on target's capabilities."));
2832 default_collect
= xstrdup ("");
2833 add_setshow_string_cmd ("default-collect", class_trace
,
2834 &default_collect
, _("\
2835 Set the list of expressions to collect by default"), _("\
2836 Show the list of expressions to collect by default"), NULL
,
2838 &setlist
, &showlist
);
2840 add_setshow_boolean_cmd ("disconnected-tracing", no_class
,
2841 &disconnected_tracing
, _("\
2842 Set whether tracing continues after GDB disconnects."), _("\
2843 Show whether tracing continues after GDB disconnects."), _("\
2844 Use this to continue a tracing run even if GDB disconnects\n\
2845 or detaches from the target. You can reconnect later and look at\n\
2846 trace data collected in the meantime."),
2847 set_disconnected_tracing
,
2852 target_buf_size
= 2048;
2853 target_buf
= xmalloc (target_buf_size
);