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 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);
39 #include "completer.h"
41 #include "dictionary.h"
43 #include "user-regs.h"
51 /* readline include files */
52 #include "readline/readline.h"
53 #include "readline/history.h"
55 /* readline defines this. */
62 /* Maximum length of an agent aexpression.
63 This accounts for the fact that packets are limited to 400 bytes
64 (which includes everything -- including the checksum), and assumes
65 the worst case of maximum length for each of the pieces of a
68 NOTE: expressions get mem2hex'ed otherwise this would be twice as
69 large. (400 - 31)/2 == 184 */
70 #define MAX_AGENT_EXPR_LEN 184
72 /* A hook used to notify the UI of tracepoint operations. */
74 void (*deprecated_trace_find_hook
) (char *arg
, int from_tty
);
75 void (*deprecated_trace_start_stop_hook
) (int start
, int from_tty
);
77 extern void (*deprecated_readline_begin_hook
) (char *, ...);
78 extern char *(*deprecated_readline_hook
) (char *);
79 extern void (*deprecated_readline_end_hook
) (void);
81 /* GDB commands implemented in other modules:
84 extern void output_command (char *, int);
89 This module defines the following debugger commands:
90 trace : set a tracepoint on a function, line, or address.
91 info trace : list all debugger-defined tracepoints.
92 delete trace : delete one or more tracepoints.
93 enable trace : enable one or more tracepoints.
94 disable trace : disable one or more tracepoints.
95 actions : specify actions to be taken at a tracepoint.
96 passcount : specify a pass count for a tracepoint.
97 tstart : start a trace experiment.
98 tstop : stop a trace experiment.
99 tstatus : query the status of a trace experiment.
100 tfind : find a trace frame in the trace buffer.
101 tdump : print everything collected at the current tracepoint.
102 save-tracepoints : write tracepoint setup into a file.
104 This module defines the following user-visible debugger variables:
105 $trace_frame : sequence number of trace frame currently being debugged.
106 $trace_line : source line of trace frame currently being debugged.
107 $trace_file : source file of trace frame currently being debugged.
108 $tracepoint : tracepoint number of trace frame currently being debugged.
112 /* ======= Important global variables: ======= */
114 /* Number of last traceframe collected. */
115 static int traceframe_number
;
117 /* Tracepoint for last traceframe collected. */
118 static int tracepoint_number
;
120 /* Symbol for function for last traceframe collected */
121 static struct symbol
*traceframe_fun
;
123 /* Symtab and line for last traceframe collected */
124 static struct symtab_and_line traceframe_sal
;
126 /* Tracing command lists */
127 static struct cmd_list_element
*tfindlist
;
129 /* ======= Important command functions: ======= */
130 static void trace_actions_command (char *, int);
131 static void trace_start_command (char *, int);
132 static void trace_stop_command (char *, int);
133 static void trace_status_command (char *, int);
134 static void trace_find_command (char *, int);
135 static void trace_find_pc_command (char *, int);
136 static void trace_find_tracepoint_command (char *, int);
137 static void trace_find_line_command (char *, int);
138 static void trace_find_range_command (char *, int);
139 static void trace_find_outside_command (char *, int);
140 static void tracepoint_save_command (char *, int);
141 static void trace_dump_command (char *, int);
143 /* support routines */
145 struct collection_list
;
146 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
147 static char *mem2hex (gdb_byte
*, char *, int);
148 static void add_register (struct collection_list
*collection
,
150 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
151 static void free_actions_list (char **actions_list
);
152 static void free_actions_list_cleanup_wrapper (void *);
154 extern void _initialize_tracepoint (void);
156 /* Utility: returns true if "target remote" */
158 target_is_remote (void)
160 if (current_target
.to_shortname
&&
161 (strcmp (current_target
.to_shortname
, "remote") == 0
162 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
168 /* Utility: generate error from an incoming stub packet. */
170 trace_error (char *buf
)
173 return; /* not an error msg */
176 case '1': /* malformed packet error */
177 if (*++buf
== '0') /* general case: */
178 error (_("tracepoint.c: error in outgoing packet."));
180 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
181 strtol (buf
, NULL
, 16));
183 error (_("trace API error 0x%s."), ++buf
);
185 error (_("Target returns error code '%s'."), buf
);
189 /* Utility: wait for reply from stub, while accepting "O" packets. */
191 remote_get_noisy_reply (char **buf_p
,
194 do /* Loop on reply from remote stub. */
197 QUIT
; /* allow user to bail out with ^C */
198 getpkt (buf_p
, sizeof_buf
, 0);
201 error (_("Target does not support this command."));
202 else if (buf
[0] == 'E')
204 else if (buf
[0] == 'O' &&
206 remote_console_output (buf
+ 1); /* 'O' message from stub */
208 return buf
; /* here's the actual reply */
213 /* Set traceframe number to NUM. */
215 set_traceframe_num (int num
)
217 traceframe_number
= num
;
218 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
221 /* Set tracepoint number to NUM. */
223 set_tracepoint_num (int num
)
225 tracepoint_number
= num
;
226 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
229 /* Set externally visible debug variables for querying/printing
230 the traceframe context (line, function, file) */
233 set_traceframe_context (struct frame_info
*trace_frame
)
237 if (trace_frame
== NULL
) /* Cease debugging any trace buffers. */
240 traceframe_sal
.pc
= traceframe_sal
.line
= 0;
241 traceframe_sal
.symtab
= NULL
;
242 clear_internalvar (lookup_internalvar ("trace_func"));
243 clear_internalvar (lookup_internalvar ("trace_file"));
244 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
248 /* Save as globals for internal use. */
249 trace_pc
= get_frame_pc (trace_frame
);
250 traceframe_sal
= find_pc_line (trace_pc
, 0);
251 traceframe_fun
= find_pc_function (trace_pc
);
253 /* Save linenumber as "$trace_line", a debugger variable visible to
255 set_internalvar_integer (lookup_internalvar ("trace_line"),
256 traceframe_sal
.line
);
258 /* Save func name as "$trace_func", a debugger variable visible to
260 if (traceframe_fun
== NULL
261 || SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
262 clear_internalvar (lookup_internalvar ("trace_func"));
264 set_internalvar_string (lookup_internalvar ("trace_func"),
265 SYMBOL_LINKAGE_NAME (traceframe_fun
));
267 /* Save file name as "$trace_file", a debugger variable visible to
269 if (traceframe_sal
.symtab
== NULL
270 || traceframe_sal
.symtab
->filename
== NULL
)
271 clear_internalvar (lookup_internalvar ("trace_file"));
273 set_internalvar_string (lookup_internalvar ("trace_file"),
274 traceframe_sal
.symtab
->filename
);
277 /* ACTIONS functions: */
279 /* Prototypes for action-parsing utility commands */
280 static void read_actions (struct breakpoint
*);
282 /* The three functions:
283 collect_pseudocommand,
284 while_stepping_pseudocommand, and
285 end_actions_pseudocommand
286 are placeholders for "commands" that are actually ONLY to be used
287 within a tracepoint action list. If the actual function is ever called,
288 it means that somebody issued the "command" at the top level,
289 which is always an error. */
292 end_actions_pseudocommand (char *args
, int from_tty
)
294 error (_("This command cannot be used at the top level."));
298 while_stepping_pseudocommand (char *args
, int from_tty
)
300 error (_("This command can only be used in a tracepoint actions list."));
304 collect_pseudocommand (char *args
, int from_tty
)
306 error (_("This command can only be used in a tracepoint actions list."));
309 /* Enter a list of actions for a tracepoint. */
311 trace_actions_command (char *args
, int from_tty
)
313 struct breakpoint
*t
;
315 char *end_msg
= "End with a line saying just \"end\".";
317 t
= get_tracepoint_by_number (&args
, 0, 1);
320 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
325 if (deprecated_readline_begin_hook
)
326 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
327 else if (input_from_terminal_p ())
328 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
332 t
->step_count
= 0; /* read_actions may set this */
335 if (deprecated_readline_end_hook
)
336 (*deprecated_readline_end_hook
) ();
337 /* tracepoints_changed () */
339 /* else just return */
342 /* worker function */
344 read_actions (struct breakpoint
*t
)
347 char *prompt1
= "> ", *prompt2
= " > ";
348 char *prompt
= prompt1
;
349 enum actionline_type linetype
;
350 extern FILE *instream
;
351 struct action_line
*next
= NULL
, *temp
;
352 struct cleanup
*old_chain
;
354 /* Control-C quits instantly if typed while in this loop
355 since it should not wait until the user types a newline. */
357 /* FIXME: kettenis/20010823: Something is wrong here. In this file
358 STOP_SIGNAL is never defined. So this code has been left out, at
359 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
360 leads to compilation failures since the variable job_control
361 isn't declared. Leave this alone for now. */
364 signal (STOP_SIGNAL
, handle_stop_sig
);
366 old_chain
= make_cleanup_free_actions (t
);
369 /* Make sure that all output has been output. Some machines may
370 let you get away with leaving out some of the gdb_flush, but
373 gdb_flush (gdb_stdout
);
374 gdb_flush (gdb_stderr
);
376 if (deprecated_readline_hook
&& instream
== NULL
)
377 line
= (*deprecated_readline_hook
) (prompt
);
378 else if (instream
== stdin
&& ISATTY (instream
))
380 line
= gdb_readline_wrapper (prompt
);
381 if (line
&& *line
) /* add it to command history */
385 line
= gdb_readline (0);
389 line
= xstrdup ("end");
390 printf_filtered ("end\n");
393 linetype
= validate_actionline (&line
, t
);
394 if (linetype
== BADLINE
)
395 continue; /* already warned -- collect another line */
397 temp
= xmalloc (sizeof (struct action_line
));
401 if (next
== NULL
) /* first action for this tracepoint? */
402 t
->actions
= next
= temp
;
409 if (linetype
== STEPPING
) /* begin "while-stepping" */
411 if (prompt
== prompt2
)
413 warning (_("Already processing 'while-stepping'"));
417 prompt
= prompt2
; /* change prompt for stepping actions */
419 else if (linetype
== END
)
421 if (prompt
== prompt2
)
423 prompt
= prompt1
; /* end of single-stepping actions */
426 { /* end of actions */
427 if (t
->actions
->next
== NULL
)
429 /* An "end" all by itself with no other actions
430 means this tracepoint has no actions.
431 Discard empty list. */
440 signal (STOP_SIGNAL
, SIG_DFL
);
443 discard_cleanups (old_chain
);
446 /* worker function */
448 validate_actionline (char **line
, struct breakpoint
*t
)
450 struct cmd_list_element
*c
;
451 struct expression
*exp
= NULL
;
452 struct cleanup
*old_chain
= NULL
;
455 /* if EOF is typed, *line is NULL */
459 for (p
= *line
; isspace ((int) *p
);)
462 /* Symbol lookup etc. */
463 if (*p
== '\0') /* empty line: just prompt for another line. */
466 if (*p
== '#') /* comment line */
469 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
472 warning (_("'%s' is not an action that I know, or is ambiguous."),
477 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
479 struct agent_expr
*aexpr
;
480 struct agent_reqs areqs
;
483 { /* repeat over a comma-separated list */
484 QUIT
; /* allow user to bail out with ^C */
485 while (isspace ((int) *p
))
488 if (*p
== '$') /* look for special pseudo-symbols */
490 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
491 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
492 (0 == strncasecmp ("loc", p
+ 1, 3)))
497 /* else fall thru, treat p as an expression and parse it! */
499 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
500 old_chain
= make_cleanup (free_current_contents
, &exp
);
502 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
504 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
506 warning (_("constant %s (value %ld) will not be collected."),
507 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
508 SYMBOL_VALUE (exp
->elts
[2].symbol
));
511 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
513 warning (_("%s is optimized away and cannot be collected."),
514 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
519 /* We have something to collect, make sure that the expr to
520 bytecode translator can handle it and that it's not too
522 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
523 make_cleanup_free_agent_expr (aexpr
);
525 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
526 error (_("expression too complicated, try simplifying"));
528 ax_reqs (aexpr
, &areqs
);
529 (void) make_cleanup (xfree
, areqs
.reg_mask
);
531 if (areqs
.flaw
!= agent_flaw_none
)
532 error (_("malformed expression"));
534 if (areqs
.min_height
< 0)
535 error (_("gdb: Internal error: expression has min height < 0"));
537 if (areqs
.max_height
> 20)
538 error (_("expression too complicated, try simplifying"));
540 do_cleanups (old_chain
);
542 while (p
&& *p
++ == ',');
545 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
547 char *steparg
; /* in case warning is necessary */
549 while (isspace ((int) *p
))
554 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
556 warning (_("'%s': bad step-count; command ignored."), *line
);
561 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
565 warning (_("'%s' is not a supported tracepoint action."), *line
);
570 /* worker function */
572 free_actions (struct breakpoint
*t
)
574 struct action_line
*line
, *next
;
576 for (line
= t
->actions
; line
; line
= next
)
580 xfree (line
->action
);
587 do_free_actions_cleanup (void *t
)
592 static struct cleanup
*
593 make_cleanup_free_actions (struct breakpoint
*t
)
595 return make_cleanup (do_free_actions_cleanup
, t
);
599 memrange_absolute
= -1
604 int type
; /* memrange_absolute for absolute memory range,
605 else basereg number */
606 bfd_signed_vma start
;
610 struct collection_list
612 unsigned char regs_mask
[32]; /* room for up to 256 regs */
615 struct memrange
*list
;
616 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
618 struct agent_expr
**aexpr_list
;
621 tracepoint_list
, stepping_list
;
623 /* MEMRANGE functions: */
625 static int memrange_cmp (const void *, const void *);
627 /* compare memranges for qsort */
629 memrange_cmp (const void *va
, const void *vb
)
631 const struct memrange
*a
= va
, *b
= vb
;
633 if (a
->type
< b
->type
)
635 if (a
->type
> b
->type
)
637 if (a
->type
== memrange_absolute
)
639 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
641 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
646 if (a
->start
< b
->start
)
648 if (a
->start
> b
->start
)
654 /* Sort the memrange list using qsort, and merge adjacent memranges. */
656 memrange_sortmerge (struct collection_list
*memranges
)
660 qsort (memranges
->list
, memranges
->next_memrange
,
661 sizeof (struct memrange
), memrange_cmp
);
662 if (memranges
->next_memrange
> 0)
664 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
666 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
667 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
670 /* memrange b starts before memrange a ends; merge them. */
671 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
672 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
673 continue; /* next b, same a */
677 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
678 sizeof (struct memrange
));
680 memranges
->next_memrange
= a
+ 1;
684 /* Add a register to a collection list. */
686 add_register (struct collection_list
*collection
, unsigned int regno
)
689 printf_filtered ("collect register %d\n", regno
);
690 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
691 error (_("Internal: register number %d too large for tracepoint"),
693 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
696 /* Add a memrange to a collection list */
698 add_memrange (struct collection_list
*memranges
,
699 int type
, bfd_signed_vma base
,
704 printf_filtered ("(%d,", type
);
706 printf_filtered (",%ld)\n", len
);
709 /* type: memrange_absolute == memory, other n == basereg */
710 memranges
->list
[memranges
->next_memrange
].type
= type
;
711 /* base: addr if memory, offset if reg relative. */
712 memranges
->list
[memranges
->next_memrange
].start
= base
;
713 /* len: we actually save end (base + len) for convenience */
714 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
715 memranges
->next_memrange
++;
716 if (memranges
->next_memrange
>= memranges
->listsize
)
718 memranges
->listsize
*= 2;
719 memranges
->list
= xrealloc (memranges
->list
,
720 memranges
->listsize
);
723 if (type
!= memrange_absolute
) /* Better collect the base register! */
724 add_register (memranges
, type
);
727 /* Add a symbol to a collection list. */
729 collect_symbol (struct collection_list
*collect
,
731 struct gdbarch
*gdbarch
,
732 long frame_regno
, long frame_offset
,
737 bfd_signed_vma offset
;
739 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
740 switch (SYMBOL_CLASS (sym
))
743 printf_filtered ("%s: don't know symbol class %d\n",
744 SYMBOL_PRINT_NAME (sym
),
748 printf_filtered ("constant %s (value %ld) will not be collected.\n",
749 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
752 offset
= SYMBOL_VALUE_ADDRESS (sym
);
757 sprintf_vma (tmp
, offset
);
758 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
759 SYMBOL_PRINT_NAME (sym
), len
,
762 add_memrange (collect
, memrange_absolute
, offset
, len
);
765 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
767 printf_filtered ("LOC_REG[parm] %s: ",
768 SYMBOL_PRINT_NAME (sym
));
769 add_register (collect
, reg
);
770 /* Check for doubles stored in two registers. */
771 /* FIXME: how about larger types stored in 3 or more regs? */
772 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
773 len
> register_size (gdbarch
, reg
))
774 add_register (collect
, reg
+ 1);
777 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
778 printf_filtered (" (will not collect %s)\n",
779 SYMBOL_PRINT_NAME (sym
));
783 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
786 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
787 SYMBOL_PRINT_NAME (sym
), len
);
789 printf_filtered (" from frame ptr reg %d\n", reg
);
791 add_memrange (collect
, reg
, offset
, len
);
793 case LOC_REGPARM_ADDR
:
794 reg
= SYMBOL_VALUE (sym
);
798 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
799 SYMBOL_PRINT_NAME (sym
), len
);
801 printf_filtered (" from reg %d\n", reg
);
803 add_memrange (collect
, reg
, offset
, len
);
807 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
810 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
811 SYMBOL_PRINT_NAME (sym
), len
);
813 printf_filtered (" from frame ptr reg %d\n", reg
);
815 add_memrange (collect
, reg
, offset
, len
);
818 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
819 SYMBOL_PRINT_NAME (sym
));
821 case LOC_OPTIMIZED_OUT
:
822 printf_filtered ("%s has been optimized out of existence.\n",
823 SYMBOL_PRINT_NAME (sym
));
828 struct agent_expr
*aexpr
;
829 struct cleanup
*old_chain1
= NULL
;
830 struct agent_reqs areqs
;
832 aexpr
= gen_trace_for_var (scope
, sym
);
834 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
836 ax_reqs (aexpr
, &areqs
);
837 if (areqs
.flaw
!= agent_flaw_none
)
838 error (_("malformed expression"));
840 if (areqs
.min_height
< 0)
841 error (_("gdb: Internal error: expression has min height < 0"));
842 if (areqs
.max_height
> 20)
843 error (_("expression too complicated, try simplifying"));
845 discard_cleanups (old_chain1
);
846 add_aexpr (collect
, aexpr
);
848 /* take care of the registers */
849 if (areqs
.reg_mask_len
> 0)
853 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
855 QUIT
; /* allow user to bail out with ^C */
856 if (areqs
.reg_mask
[ndx1
] != 0)
858 /* assume chars have 8 bits */
859 for (ndx2
= 0; ndx2
< 8; ndx2
++)
860 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
861 /* it's used -- record it */
862 add_register (collect
,
872 /* Add all locals (or args) symbols to collection list */
874 add_local_symbols (struct collection_list
*collect
,
875 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
876 long frame_regno
, long frame_offset
, int type
)
880 struct dict_iterator iter
;
883 block
= block_for_pc (pc
);
886 QUIT
; /* allow user to bail out with ^C */
887 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
889 if (SYMBOL_IS_ARGUMENT (sym
)
890 ? type
== 'A' /* collecting Arguments */
891 : type
== 'L') /* collecting Locals */
894 collect_symbol (collect
, sym
, gdbarch
,
895 frame_regno
, frame_offset
, pc
);
898 if (BLOCK_FUNCTION (block
))
901 block
= BLOCK_SUPERBLOCK (block
);
904 warning (_("No %s found in scope."),
905 type
== 'L' ? "locals" : "args");
908 /* worker function */
910 clear_collection_list (struct collection_list
*list
)
914 list
->next_memrange
= 0;
915 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
917 free_agent_expr (list
->aexpr_list
[ndx
]);
918 list
->aexpr_list
[ndx
] = NULL
;
920 list
->next_aexpr_elt
= 0;
921 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
924 /* reduce a collection list to string form (for gdb protocol) */
926 stringify_collection_list (struct collection_list
*list
, char *string
)
936 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
937 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
939 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
940 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
942 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
945 printf_filtered ("\nCollecting registers (mask): 0x");
950 QUIT
; /* allow user to bail out with ^C */
952 printf_filtered ("%02X", list
->regs_mask
[i
]);
953 sprintf (end
, "%02X", list
->regs_mask
[i
]);
956 (*str_list
)[ndx
] = xstrdup (temp_buf
);
960 printf_filtered ("\n");
961 if (list
->next_memrange
> 0 && info_verbose
)
962 printf_filtered ("Collecting memranges: \n");
963 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
965 QUIT
; /* allow user to bail out with ^C */
966 sprintf_vma (tmp2
, list
->list
[i
].start
);
969 printf_filtered ("(%d, %s, %ld)\n",
972 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
974 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
976 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
983 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
985 /* The "%X" conversion specifier expects an unsigned argument,
986 so passing -1 (memrange_absolute) to it directly gives you
987 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
989 if (list
->list
[i
].type
== memrange_absolute
)
990 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
992 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
995 count
+= strlen (end
);
996 end
= temp_buf
+ count
;
999 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
1001 QUIT
; /* allow user to bail out with ^C */
1002 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
1004 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1009 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
1010 end
+= 10; /* 'X' + 8 hex digits + ',' */
1013 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
1014 end
, list
->aexpr_list
[i
]->len
);
1015 count
+= 2 * list
->aexpr_list
[i
]->len
;
1020 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1025 (*str_list
)[ndx
] = NULL
;
1037 free_actions_list_cleanup_wrapper (void *al
)
1039 free_actions_list (al
);
1043 free_actions_list (char **actions_list
)
1047 if (actions_list
== 0)
1050 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1051 xfree (actions_list
[ndx
]);
1053 xfree (actions_list
);
1056 /* Render all actions into gdb protocol. */
1058 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1059 char ***stepping_actions
)
1061 static char tdp_buff
[2048], step_buff
[2048];
1063 struct expression
*exp
= NULL
;
1064 struct action_line
*action
;
1066 struct value
*tempval
;
1067 struct collection_list
*collect
;
1068 struct cmd_list_element
*cmd
;
1069 struct agent_expr
*aexpr
;
1071 LONGEST frame_offset
;
1074 clear_collection_list (&tracepoint_list
);
1075 clear_collection_list (&stepping_list
);
1076 collect
= &tracepoint_list
;
1078 *tdp_actions
= NULL
;
1079 *stepping_actions
= NULL
;
1081 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1082 t
->loc
->address
, &frame_reg
, &frame_offset
);
1084 for (action
= t
->actions
; action
; action
= action
->next
)
1086 QUIT
; /* allow user to bail out with ^C */
1087 action_exp
= action
->action
;
1088 while (isspace ((int) *action_exp
))
1091 if (*action_exp
== '#') /* comment line */
1094 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1096 error (_("Bad action list item: %s"), action_exp
);
1098 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1101 { /* repeat over a comma-separated list */
1102 QUIT
; /* allow user to bail out with ^C */
1103 while (isspace ((int) *action_exp
))
1106 if (0 == strncasecmp ("$reg", action_exp
, 4))
1108 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1109 add_register (collect
, i
);
1110 action_exp
= strchr (action_exp
, ','); /* more? */
1112 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1114 add_local_symbols (collect
,
1120 action_exp
= strchr (action_exp
, ','); /* more? */
1122 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1124 add_local_symbols (collect
,
1130 action_exp
= strchr (action_exp
, ','); /* more? */
1134 unsigned long addr
, len
;
1135 struct cleanup
*old_chain
= NULL
;
1136 struct cleanup
*old_chain1
= NULL
;
1137 struct agent_reqs areqs
;
1139 exp
= parse_exp_1 (&action_exp
,
1140 block_for_pc (t
->loc
->address
), 1);
1141 old_chain
= make_cleanup (free_current_contents
, &exp
);
1143 switch (exp
->elts
[0].opcode
)
1147 const char *name
= &exp
->elts
[2].string
;
1149 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1150 name
, strlen (name
));
1152 internal_error (__FILE__
, __LINE__
,
1153 _("Register $%s not available"),
1156 printf_filtered ("OP_REGISTER: ");
1157 add_register (collect
, i
);
1162 /* safe because we know it's a simple expression */
1163 tempval
= evaluate_expression (exp
);
1164 addr
= value_address (tempval
);
1165 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1166 add_memrange (collect
, memrange_absolute
, addr
, len
);
1170 collect_symbol (collect
,
1171 exp
->elts
[2].symbol
,
1178 default: /* full-fledged expression */
1179 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1181 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1183 ax_reqs (aexpr
, &areqs
);
1184 if (areqs
.flaw
!= agent_flaw_none
)
1185 error (_("malformed expression"));
1187 if (areqs
.min_height
< 0)
1188 error (_("gdb: Internal error: expression has min height < 0"));
1189 if (areqs
.max_height
> 20)
1190 error (_("expression too complicated, try simplifying"));
1192 discard_cleanups (old_chain1
);
1193 add_aexpr (collect
, aexpr
);
1195 /* take care of the registers */
1196 if (areqs
.reg_mask_len
> 0)
1201 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1203 QUIT
; /* allow user to bail out with ^C */
1204 if (areqs
.reg_mask
[ndx1
] != 0)
1206 /* assume chars have 8 bits */
1207 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1208 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1209 /* it's used -- record it */
1210 add_register (collect
,
1217 do_cleanups (old_chain
);
1220 while (action_exp
&& *action_exp
++ == ',');
1222 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1224 collect
= &stepping_list
;
1226 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1228 if (collect
== &stepping_list
) /* end stepping actions */
1229 collect
= &tracepoint_list
;
1231 break; /* end tracepoint actions */
1234 memrange_sortmerge (&tracepoint_list
);
1235 memrange_sortmerge (&stepping_list
);
1237 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1239 *stepping_actions
= stringify_collection_list (&stepping_list
,
1244 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1246 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1248 collect
->aexpr_list
=
1249 xrealloc (collect
->aexpr_list
,
1250 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1251 collect
->aexpr_listsize
*= 2;
1253 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1254 collect
->next_aexpr_elt
++;
1257 static char *target_buf
;
1258 static long target_buf_size
;
1260 /* Set "transparent" memory ranges
1262 Allow trace mechanism to treat text-like sections
1263 (and perhaps all read-only sections) transparently,
1264 i.e. don't reject memory requests from these address ranges
1265 just because they haven't been collected. */
1268 remote_set_transparent_ranges (void)
1276 return; /* No information to give. */
1278 strcpy (target_buf
, "QTro");
1279 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1281 char tmp1
[40], tmp2
[40];
1283 if ((s
->flags
& SEC_LOAD
) == 0 ||
1284 /* (s->flags & SEC_CODE) == 0 || */
1285 (s
->flags
& SEC_READONLY
) == 0)
1290 size
= bfd_get_section_size (s
);
1291 sprintf_vma (tmp1
, lma
);
1292 sprintf_vma (tmp2
, lma
+ size
);
1293 sprintf (target_buf
+ strlen (target_buf
),
1294 ":%s,%s", tmp1
, tmp2
);
1298 putpkt (target_buf
);
1299 getpkt (&target_buf
, &target_buf_size
, 0);
1305 Tell target to clear any previous trace experiment.
1306 Walk the list of tracepoints, and send them (and their actions)
1307 to the target. If no errors,
1308 Tell target to start a new trace experiment. */
1310 void download_tracepoint (struct breakpoint
*t
);
1313 trace_start_command (char *args
, int from_tty
)
1315 VEC(breakpoint_p
) *tp_vec
= NULL
;
1317 struct breakpoint
*t
;
1319 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1321 if (target_is_remote ())
1324 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1325 if (strcmp (target_buf
, "OK"))
1326 error (_("Target does not support this command."));
1328 tp_vec
= all_tracepoints ();
1329 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1331 download_tracepoint (t
);
1333 VEC_free (breakpoint_p
, tp_vec
);
1335 /* Tell target to treat text-like sections as transparent. */
1336 remote_set_transparent_ranges ();
1337 /* Now insert traps and begin collecting data. */
1339 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1340 if (strcmp (target_buf
, "OK"))
1341 error (_("Bogus reply from target: %s"), target_buf
);
1342 set_traceframe_num (-1); /* All old traceframes invalidated. */
1343 set_tracepoint_num (-1);
1344 set_traceframe_context (NULL
);
1345 trace_running_p
= 1;
1346 if (deprecated_trace_start_stop_hook
)
1347 deprecated_trace_start_stop_hook (1, from_tty
);
1351 error (_("Trace can only be run on remote targets."));
1354 /* Send the definition of a single tracepoint to the target. */
1357 download_tracepoint (struct breakpoint
*t
)
1362 char **stepping_actions
;
1364 struct cleanup
*old_chain
= NULL
;
1365 struct agent_expr
*aexpr
;
1366 struct cleanup
*aexpr_chain
= NULL
;
1368 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1369 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1371 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1372 t
->step_count
, t
->pass_count
);
1373 /* If the tracepoint has a conditional, make it into an agent
1374 expression and append to the definition. */
1377 /* Only test support at download time, we may not know target
1378 capabilities at definition time. */
1379 if (remote_supports_cond_tracepoints ())
1381 aexpr
= gen_eval_for_expr (t
->loc
->address
, t
->loc
->cond
);
1382 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
1383 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
1384 mem2hex (aexpr
->buf
, buf
+ strlen (buf
), aexpr
->len
);
1385 do_cleanups (aexpr_chain
);
1388 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t
->number
);
1394 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1395 if (strcmp (target_buf
, "OK"))
1396 error (_("Target does not support tracepoints."));
1401 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1402 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1404 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1406 /* do_single_steps (t); */
1409 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1411 QUIT
; /* allow user to bail out with ^C */
1412 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1413 t
->number
, tmp
, /* address */
1415 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1418 remote_get_noisy_reply (&target_buf
,
1420 if (strcmp (target_buf
, "OK"))
1421 error (_("Error on target while setting tracepoints."));
1424 if (stepping_actions
)
1426 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1428 QUIT
; /* allow user to bail out with ^C */
1429 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1430 t
->number
, tmp
, /* address */
1431 ((ndx
== 0) ? "S" : ""),
1432 stepping_actions
[ndx
],
1433 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1435 remote_get_noisy_reply (&target_buf
,
1437 if (strcmp (target_buf
, "OK"))
1438 error (_("Error on target while setting tracepoints."));
1441 do_cleanups (old_chain
);
1446 trace_stop_command (char *args
, int from_tty
)
1448 if (target_is_remote ())
1451 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1452 if (strcmp (target_buf
, "OK"))
1453 error (_("Bogus reply from target: %s"), target_buf
);
1454 trace_running_p
= 0;
1455 if (deprecated_trace_start_stop_hook
)
1456 deprecated_trace_start_stop_hook (0, from_tty
);
1459 error (_("Trace can only be run on remote targets."));
1462 unsigned long trace_running_p
;
1464 /* tstatus command */
1466 trace_status_command (char *args
, int from_tty
)
1468 if (target_is_remote ())
1470 putpkt ("qTStatus");
1471 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1473 if (target_buf
[0] != 'T' ||
1474 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1475 error (_("Bogus reply from target: %s"), target_buf
);
1477 /* exported for use by the GUI */
1478 trace_running_p
= (target_buf
[1] == '1');
1481 error (_("Trace can only be run on remote targets."));
1484 /* Worker function for the various flavors of the tfind command. */
1486 finish_tfind_command (char **msg
,
1490 int target_frameno
= -1, target_tracept
= -1;
1491 struct frame_id old_frame_id
;
1494 old_frame_id
= get_frame_id (get_current_frame ());
1497 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1499 while (reply
&& *reply
)
1503 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1505 /* A request for a non-existant trace frame has failed.
1506 Our response will be different, depending on FROM_TTY:
1508 If FROM_TTY is true, meaning that this command was
1509 typed interactively by the user, then give an error
1510 and DO NOT change the state of traceframe_number etc.
1512 However if FROM_TTY is false, meaning that we're either
1513 in a script, a loop, or a user-defined command, then
1514 DON'T give an error, but DO change the state of
1515 traceframe_number etc. to invalid.
1517 The rationalle is that if you typed the command, you
1518 might just have committed a typo or something, and you'd
1519 like to NOT lose your current debugging state. However
1520 if you're in a user-defined command or especially in a
1521 loop, then you need a way to detect that the command
1522 failed WITHOUT aborting. This allows you to write
1523 scripts that search thru the trace buffer until the end,
1524 and then continue on to do something else. */
1527 error (_("Target failed to find requested trace frame."));
1531 printf_filtered ("End of trace buffer.\n");
1532 /* The following will not recurse, since it's
1534 trace_find_command ("-1", from_tty
);
1535 reply
= NULL
; /* Break out of loop
1536 (avoid recursive nonsense). */
1541 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1542 error (_("Target failed to find requested trace frame."));
1544 case 'O': /* "OK"? */
1545 if (reply
[1] == 'K' && reply
[2] == '\0')
1548 error (_("Bogus reply from target: %s"), reply
);
1551 error (_("Bogus reply from target: %s"), reply
);
1554 reinit_frame_cache ();
1555 registers_changed ();
1556 set_traceframe_num (target_frameno
);
1557 set_tracepoint_num (target_tracept
);
1558 if (target_frameno
== -1)
1559 set_traceframe_context (NULL
);
1561 set_traceframe_context (get_current_frame ());
1565 enum print_what print_what
;
1567 /* NOTE: in immitation of the step command, try to determine
1568 whether we have made a transition from one function to
1569 another. If so, we'll print the "stack frame" (ie. the new
1570 function and it's arguments) -- otherwise we'll just show the
1573 if (frame_id_eq (old_frame_id
,
1574 get_frame_id (get_current_frame ())))
1575 print_what
= SRC_LINE
;
1577 print_what
= SRC_AND_LOC
;
1579 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1584 /* trace_find_command takes a trace frame number n,
1585 sends "QTFrame:<n>" to the target,
1586 and accepts a reply that may contain several optional pieces
1587 of information: a frame number, a tracepoint number, and an
1588 indication of whether this is a trap frame or a stepping frame.
1590 The minimal response is just "OK" (which indicates that the
1591 target does not give us a frame number or a tracepoint number).
1592 Instead of that, the target may send us a string containing
1594 F<hexnum> (gives the selected frame number)
1595 T<hexnum> (gives the selected tracepoint number)
1600 trace_find_command (char *args
, int from_tty
)
1601 { /* this should only be called with a numeric argument */
1604 if (target_is_remote ())
1606 if (deprecated_trace_find_hook
)
1607 deprecated_trace_find_hook (args
, from_tty
);
1609 if (args
== 0 || *args
== 0)
1610 { /* TFIND with no args means find NEXT trace frame. */
1611 if (traceframe_number
== -1)
1612 frameno
= 0; /* "next" is first one */
1614 frameno
= traceframe_number
+ 1;
1616 else if (0 == strcmp (args
, "-"))
1618 if (traceframe_number
== -1)
1619 error (_("not debugging trace buffer"));
1620 else if (from_tty
&& traceframe_number
== 0)
1621 error (_("already at start of trace buffer"));
1623 frameno
= traceframe_number
- 1;
1626 frameno
= parse_and_eval_long (args
);
1629 error (_("invalid input (%d is less than zero)"), frameno
);
1631 sprintf (target_buf
, "QTFrame:%x", frameno
);
1632 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1635 error (_("Trace can only be run on remote targets."));
1640 trace_find_end_command (char *args
, int from_tty
)
1642 trace_find_command ("-1", from_tty
);
1647 trace_find_none_command (char *args
, int from_tty
)
1649 trace_find_command ("-1", from_tty
);
1654 trace_find_start_command (char *args
, int from_tty
)
1656 trace_find_command ("0", from_tty
);
1659 /* tfind pc command */
1661 trace_find_pc_command (char *args
, int from_tty
)
1666 if (target_is_remote ())
1668 if (args
== 0 || *args
== 0)
1669 pc
= regcache_read_pc (get_current_regcache ());
1671 pc
= parse_and_eval_address (args
);
1673 sprintf_vma (tmp
, pc
);
1674 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
1675 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1678 error (_("Trace can only be run on remote targets."));
1681 /* tfind tracepoint command */
1683 trace_find_tracepoint_command (char *args
, int from_tty
)
1687 if (target_is_remote ())
1689 if (args
== 0 || *args
== 0)
1691 if (tracepoint_number
== -1)
1692 error (_("No current tracepoint -- please supply an argument."));
1694 tdp
= tracepoint_number
; /* default is current TDP */
1697 tdp
= parse_and_eval_long (args
);
1699 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1700 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1703 error (_("Trace can only be run on remote targets."));
1706 /* TFIND LINE command:
1708 This command will take a sourceline for argument, just like BREAK
1709 or TRACE (ie. anything that "decode_line_1" can handle).
1711 With no argument, this command will find the next trace frame
1712 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1715 trace_find_line_command (char *args
, int from_tty
)
1717 static CORE_ADDR start_pc
, end_pc
;
1718 struct symtabs_and_lines sals
;
1719 struct symtab_and_line sal
;
1720 struct cleanup
*old_chain
;
1721 char startpc_str
[40], endpc_str
[40];
1723 if (target_is_remote ())
1725 if (args
== 0 || *args
== 0)
1727 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1729 sals
.sals
= (struct symtab_and_line
*)
1730 xmalloc (sizeof (struct symtab_and_line
));
1735 sals
= decode_line_spec (args
, 1);
1739 old_chain
= make_cleanup (xfree
, sals
.sals
);
1740 if (sal
.symtab
== 0)
1742 struct gdbarch
*gdbarch
= get_current_arch ();
1744 printf_filtered ("TFIND: No line number information available");
1747 /* This is useful for "info line *0x7f34". If we can't
1748 tell the user about a source line, at least let them
1749 have the symbolic address. */
1750 printf_filtered (" for address ");
1752 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
1753 printf_filtered (";\n -- will attempt to find by PC. \n");
1757 printf_filtered (".\n");
1758 return; /* No line, no PC; what can we do? */
1761 else if (sal
.line
> 0
1762 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1764 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
1766 if (start_pc
== end_pc
)
1768 printf_filtered ("Line %d of \"%s\"",
1769 sal
.line
, sal
.symtab
->filename
);
1771 printf_filtered (" is at address ");
1772 print_address (gdbarch
, start_pc
, gdb_stdout
);
1774 printf_filtered (" but contains no code.\n");
1775 sal
= find_pc_line (start_pc
, 0);
1777 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1779 printf_filtered ("Attempting to find line %d instead.\n",
1782 error (_("Cannot find a good line."));
1786 /* Is there any case in which we get here, and have an address
1787 which the user would want to see? If we have debugging
1788 symbols and no line numbers? */
1789 error (_("Line number %d is out of range for \"%s\"."),
1790 sal
.line
, sal
.symtab
->filename
);
1792 sprintf_vma (startpc_str
, start_pc
);
1793 sprintf_vma (endpc_str
, end_pc
- 1);
1794 /* Find within range of stated line. */
1796 sprintf (target_buf
, "QTFrame:range:%s:%s",
1797 startpc_str
, endpc_str
);
1798 /* Find OUTSIDE OF range of CURRENT line. */
1800 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1801 startpc_str
, endpc_str
);
1802 finish_tfind_command (&target_buf
, &target_buf_size
,
1804 do_cleanups (old_chain
);
1807 error (_("Trace can only be run on remote targets."));
1810 /* tfind range command */
1812 trace_find_range_command (char *args
, int from_tty
)
1814 static CORE_ADDR start
, stop
;
1815 char start_str
[40], stop_str
[40];
1818 if (target_is_remote ())
1820 if (args
== 0 || *args
== 0)
1821 { /* XXX FIXME: what should default behavior be? */
1822 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1826 if (0 != (tmp
= strchr (args
, ',')))
1828 *tmp
++ = '\0'; /* terminate start address */
1829 while (isspace ((int) *tmp
))
1831 start
= parse_and_eval_address (args
);
1832 stop
= parse_and_eval_address (tmp
);
1835 { /* no explicit end address? */
1836 start
= parse_and_eval_address (args
);
1837 stop
= start
+ 1; /* ??? */
1840 sprintf_vma (start_str
, start
);
1841 sprintf_vma (stop_str
, stop
);
1842 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1843 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1846 error (_("Trace can only be run on remote targets."));
1849 /* tfind outside command */
1851 trace_find_outside_command (char *args
, int from_tty
)
1853 CORE_ADDR start
, stop
;
1854 char start_str
[40], stop_str
[40];
1857 if (target_is_remote ())
1859 if (args
== 0 || *args
== 0)
1860 { /* XXX FIXME: what should default behavior be? */
1861 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1865 if (0 != (tmp
= strchr (args
, ',')))
1867 *tmp
++ = '\0'; /* terminate start address */
1868 while (isspace ((int) *tmp
))
1870 start
= parse_and_eval_address (args
);
1871 stop
= parse_and_eval_address (tmp
);
1874 { /* no explicit end address? */
1875 start
= parse_and_eval_address (args
);
1876 stop
= start
+ 1; /* ??? */
1879 sprintf_vma (start_str
, start
);
1880 sprintf_vma (stop_str
, stop
);
1881 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1882 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1885 error (_("Trace can only be run on remote targets."));
1888 /* info scope command: list the locals for a scope. */
1890 scope_info (char *args
, int from_tty
)
1892 struct symtabs_and_lines sals
;
1894 struct minimal_symbol
*msym
;
1895 struct block
*block
;
1896 char **canonical
, *symname
, *save_args
= args
;
1897 struct dict_iterator iter
;
1899 struct gdbarch
*gdbarch
;
1902 if (args
== 0 || *args
== 0)
1903 error (_("requires an argument (function, line or *addr) to define a scope"));
1905 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1906 if (sals
.nelts
== 0)
1907 return; /* presumably decode_line_1 has already warned */
1909 /* Resolve line numbers to PC */
1910 resolve_sal_pc (&sals
.sals
[0]);
1911 block
= block_for_pc (sals
.sals
[0].pc
);
1915 QUIT
; /* allow user to bail out with ^C */
1916 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1918 QUIT
; /* allow user to bail out with ^C */
1920 printf_filtered ("Scope for %s:\n", save_args
);
1923 symname
= SYMBOL_PRINT_NAME (sym
);
1924 if (symname
== NULL
|| *symname
== '\0')
1925 continue; /* probably botched, certainly useless */
1927 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
1929 printf_filtered ("Symbol %s is ", symname
);
1930 switch (SYMBOL_CLASS (sym
))
1933 case LOC_UNDEF
: /* messed up symbol? */
1934 printf_filtered ("a bogus symbol, class %d.\n",
1935 SYMBOL_CLASS (sym
));
1936 count
--; /* don't count this one */
1939 printf_filtered ("a constant with value %ld (0x%lx)",
1940 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
1942 case LOC_CONST_BYTES
:
1943 printf_filtered ("constant bytes: ");
1944 if (SYMBOL_TYPE (sym
))
1945 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
1946 fprintf_filtered (gdb_stdout
, " %02x",
1947 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
1950 printf_filtered ("in static storage at address ");
1951 printf_filtered ("%s", paddress (gdbarch
,
1952 SYMBOL_VALUE_ADDRESS (sym
)));
1955 /* GDBARCH is the architecture associated with the objfile
1956 the symbol is defined in; the target architecture may be
1957 different, and may provide additional registers. However,
1958 we do not know the target architecture at this point.
1959 We assume the objfile architecture will contain all the
1960 standard registers that occur in debug info in that
1962 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1964 if (SYMBOL_IS_ARGUMENT (sym
))
1965 printf_filtered ("an argument in register $%s",
1966 gdbarch_register_name (gdbarch
, regno
));
1968 printf_filtered ("a local variable in register $%s",
1969 gdbarch_register_name (gdbarch
, regno
));
1972 printf_filtered ("an argument at stack/frame offset %ld",
1973 SYMBOL_VALUE (sym
));
1976 printf_filtered ("a local variable at frame offset %ld",
1977 SYMBOL_VALUE (sym
));
1980 printf_filtered ("a reference argument at offset %ld",
1981 SYMBOL_VALUE (sym
));
1983 case LOC_REGPARM_ADDR
:
1984 /* Note comment at LOC_REGISTER. */
1985 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1986 printf_filtered ("the address of an argument, in register $%s",
1987 gdbarch_register_name (gdbarch
, regno
));
1990 printf_filtered ("a typedef.\n");
1993 printf_filtered ("a label at address ");
1994 printf_filtered ("%s", paddress (gdbarch
,
1995 SYMBOL_VALUE_ADDRESS (sym
)));
1998 printf_filtered ("a function at address ");
1999 printf_filtered ("%s",
2000 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
2002 case LOC_UNRESOLVED
:
2003 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
2006 printf_filtered ("Unresolved Static");
2009 printf_filtered ("static storage at address ");
2010 printf_filtered ("%s",
2011 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
2014 case LOC_OPTIMIZED_OUT
:
2015 printf_filtered ("optimized out.\n");
2018 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
2021 if (SYMBOL_TYPE (sym
))
2022 printf_filtered (", length %d.\n",
2023 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
2025 if (BLOCK_FUNCTION (block
))
2028 block
= BLOCK_SUPERBLOCK (block
);
2031 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2035 /* worker function (cleanup) */
2037 replace_comma (void *data
)
2045 trace_dump_command (char *args
, int from_tty
)
2047 struct regcache
*regcache
;
2048 struct gdbarch
*gdbarch
;
2049 struct breakpoint
*t
;
2050 struct action_line
*action
;
2051 char *action_exp
, *next_comma
;
2052 struct cleanup
*old_cleanups
;
2053 int stepping_actions
= 0;
2054 int stepping_frame
= 0;
2056 if (!target_is_remote ())
2058 error (_("Trace can only be run on remote targets."));
2062 if (tracepoint_number
== -1)
2064 warning (_("No current trace frame."));
2068 t
= get_tracepoint (tracepoint_number
);
2071 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2074 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2076 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2077 tracepoint_number
, traceframe_number
);
2079 /* The current frame is a trap frame if the frame PC is equal
2080 to the tracepoint PC. If not, then the current frame was
2081 collected during single-stepping. */
2083 regcache
= get_current_regcache ();
2084 gdbarch
= get_regcache_arch (regcache
);
2086 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2087 - gdbarch_decr_pc_after_break (gdbarch
)));
2089 for (action
= t
->actions
; action
; action
= action
->next
)
2091 struct cmd_list_element
*cmd
;
2093 QUIT
; /* allow user to bail out with ^C */
2094 action_exp
= action
->action
;
2095 while (isspace ((int) *action_exp
))
2098 /* The collection actions to be done while stepping are
2099 bracketed by the commands "while-stepping" and "end". */
2101 if (*action_exp
== '#') /* comment line */
2104 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2106 error (_("Bad action list item: %s"), action_exp
);
2108 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2109 stepping_actions
= 1;
2110 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2111 stepping_actions
= 0;
2112 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2114 /* Display the collected data.
2115 For the trap frame, display only what was collected at
2116 the trap. Likewise for stepping frames, display only
2117 what was collected while stepping. This means that the
2118 two boolean variables, STEPPING_FRAME and
2119 STEPPING_ACTIONS should be equal. */
2120 if (stepping_frame
== stepping_actions
)
2123 { /* repeat over a comma-separated list */
2124 QUIT
; /* allow user to bail out with ^C */
2125 if (*action_exp
== ',')
2127 while (isspace ((int) *action_exp
))
2130 next_comma
= strchr (action_exp
, ',');
2132 if (0 == strncasecmp (action_exp
, "$reg", 4))
2133 registers_info (NULL
, from_tty
);
2134 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2135 locals_info (NULL
, from_tty
);
2136 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2137 args_info (NULL
, from_tty
);
2142 make_cleanup (replace_comma
, next_comma
);
2145 printf_filtered ("%s = ", action_exp
);
2146 output_command (action_exp
, from_tty
);
2147 printf_filtered ("\n");
2151 action_exp
= next_comma
;
2153 while (action_exp
&& *action_exp
== ',');
2157 discard_cleanups (old_cleanups
);
2160 /* Convert the memory pointed to by mem into hex, placing result in buf.
2161 * Return a pointer to the last char put in buf (null)
2162 * "stolen" from sparc-stub.c
2165 static const char hexchars
[] = "0123456789abcdef";
2168 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2176 *buf
++ = hexchars
[ch
>> 4];
2177 *buf
++ = hexchars
[ch
& 0xf];
2186 get_traceframe_number (void)
2188 return traceframe_number
;
2192 /* module initialization */
2194 _initialize_tracepoint (void)
2196 struct cmd_list_element
*c
;
2198 traceframe_number
= -1;
2199 tracepoint_number
= -1;
2201 if (tracepoint_list
.list
== NULL
)
2203 tracepoint_list
.listsize
= 128;
2204 tracepoint_list
.list
= xmalloc
2205 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2207 if (tracepoint_list
.aexpr_list
== NULL
)
2209 tracepoint_list
.aexpr_listsize
= 128;
2210 tracepoint_list
.aexpr_list
= xmalloc
2211 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2214 if (stepping_list
.list
== NULL
)
2216 stepping_list
.listsize
= 128;
2217 stepping_list
.list
= xmalloc
2218 (stepping_list
.listsize
* sizeof (struct memrange
));
2221 if (stepping_list
.aexpr_list
== NULL
)
2223 stepping_list
.aexpr_listsize
= 128;
2224 stepping_list
.aexpr_list
= xmalloc
2225 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2228 add_info ("scope", scope_info
,
2229 _("List the variables local to a scope"));
2231 add_cmd ("tracepoints", class_trace
, NULL
,
2232 _("Tracing of program execution without stopping the program."),
2235 add_com ("tdump", class_trace
, trace_dump_command
,
2236 _("Print everything collected at the current tracepoint."));
2238 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2239 Select a trace frame;\n\
2240 No argument means forward by one frame; '-' means backward by one frame."),
2241 &tfindlist
, "tfind ", 1, &cmdlist
);
2243 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2244 Select a trace frame whose PC is outside the given range.\n\
2245 Usage: tfind outside addr1, addr2"),
2248 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2249 Select a trace frame whose PC is in the given range.\n\
2250 Usage: tfind range addr1,addr2"),
2253 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2254 Select a trace frame by source line.\n\
2255 Argument can be a line number (with optional source file), \n\
2256 a function name, or '*' followed by an address.\n\
2257 Default argument is 'the next source line that was traced'."),
2260 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2261 Select a trace frame by tracepoint number.\n\
2262 Default is the tracepoint for the current trace frame."),
2265 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2266 Select a trace frame by PC.\n\
2267 Default is the current PC, or the PC of the current trace frame."),
2270 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2271 Synonym for 'none'.\n\
2272 De-select any trace frame and resume 'live' debugging."),
2275 add_cmd ("none", class_trace
, trace_find_none_command
,
2276 _("De-select any trace frame and resume 'live' debugging."),
2279 add_cmd ("start", class_trace
, trace_find_start_command
,
2280 _("Select the first trace frame in the trace buffer."),
2283 add_com ("tstatus", class_trace
, trace_status_command
,
2284 _("Display the status of the current trace data collection."));
2286 add_com ("tstop", class_trace
, trace_stop_command
,
2287 _("Stop trace data collection."));
2289 add_com ("tstart", class_trace
, trace_start_command
,
2290 _("Start trace data collection."));
2292 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2293 Ends a list of commands or actions.\n\
2294 Several GDB commands allow you to enter a list of commands or actions.\n\
2295 Entering \"end\" on a line by itself is the normal way to terminate\n\
2297 Note: the \"end\" command cannot be used at the gdb prompt."));
2299 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2300 Specify single-stepping behavior at a tracepoint.\n\
2301 Argument is number of instructions to trace in single-step mode\n\
2302 following the tracepoint. This command is normally followed by\n\
2303 one or more \"collect\" commands, to specify what to collect\n\
2304 while single-stepping.\n\n\
2305 Note: this command can only be used in a tracepoint \"actions\" list."));
2307 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2308 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2310 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2311 Specify one or more data items to be collected at a tracepoint.\n\
2312 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2313 collect all data (variables, registers) referenced by that expression.\n\
2314 Also accepts the following special arguments:\n\
2315 $regs -- all registers.\n\
2316 $args -- all function arguments.\n\
2317 $locals -- all variables local to the block/function scope.\n\
2318 Note: this command can only be used in a tracepoint \"actions\" list."));
2320 add_com ("actions", class_trace
, trace_actions_command
, _("\
2321 Specify the actions to be taken at a tracepoint.\n\
2322 Tracepoint actions may include collecting of specified data, \n\
2323 single-stepping, or enabling/disabling other tracepoints, \n\
2324 depending on target's capabilities."));
2326 target_buf_size
= 2048;
2327 target_buf
= xmalloc (target_buf_size
);