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
)
736 bfd_signed_vma offset
;
738 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
739 switch (SYMBOL_CLASS (sym
))
742 printf_filtered ("%s: don't know symbol class %d\n",
743 SYMBOL_PRINT_NAME (sym
),
747 printf_filtered ("constant %s (value %ld) will not be collected.\n",
748 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
751 offset
= SYMBOL_VALUE_ADDRESS (sym
);
756 sprintf_vma (tmp
, offset
);
757 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
758 SYMBOL_PRINT_NAME (sym
), len
,
761 add_memrange (collect
, memrange_absolute
, offset
, len
);
764 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
766 printf_filtered ("LOC_REG[parm] %s: ",
767 SYMBOL_PRINT_NAME (sym
));
768 add_register (collect
, reg
);
769 /* Check for doubles stored in two registers. */
770 /* FIXME: how about larger types stored in 3 or more regs? */
771 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
772 len
> register_size (gdbarch
, reg
))
773 add_register (collect
, reg
+ 1);
776 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
777 printf_filtered (" (will not collect %s)\n",
778 SYMBOL_PRINT_NAME (sym
));
782 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
785 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
786 SYMBOL_PRINT_NAME (sym
), len
);
788 printf_filtered (" from frame ptr reg %d\n", reg
);
790 add_memrange (collect
, reg
, offset
, len
);
792 case LOC_REGPARM_ADDR
:
793 reg
= SYMBOL_VALUE (sym
);
797 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
798 SYMBOL_PRINT_NAME (sym
), len
);
800 printf_filtered (" from reg %d\n", reg
);
802 add_memrange (collect
, reg
, offset
, len
);
806 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
809 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
810 SYMBOL_PRINT_NAME (sym
), len
);
812 printf_filtered (" from frame ptr reg %d\n", reg
);
814 add_memrange (collect
, reg
, offset
, len
);
817 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
818 SYMBOL_PRINT_NAME (sym
));
820 case LOC_OPTIMIZED_OUT
:
821 printf_filtered ("%s has been optimized out of existence.\n",
822 SYMBOL_PRINT_NAME (sym
));
827 /* Add all locals (or args) symbols to collection list */
829 add_local_symbols (struct collection_list
*collect
,
830 struct gdbarch
*gdbarch
, CORE_ADDR pc
,
831 long frame_regno
, long frame_offset
, int type
)
835 struct dict_iterator iter
;
838 block
= block_for_pc (pc
);
841 QUIT
; /* allow user to bail out with ^C */
842 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
844 if (SYMBOL_IS_ARGUMENT (sym
)
845 ? type
== 'A' /* collecting Arguments */
846 : type
== 'L') /* collecting Locals */
849 collect_symbol (collect
, sym
, gdbarch
,
850 frame_regno
, frame_offset
);
853 if (BLOCK_FUNCTION (block
))
856 block
= BLOCK_SUPERBLOCK (block
);
859 warning (_("No %s found in scope."),
860 type
== 'L' ? "locals" : "args");
863 /* worker function */
865 clear_collection_list (struct collection_list
*list
)
869 list
->next_memrange
= 0;
870 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
872 free_agent_expr (list
->aexpr_list
[ndx
]);
873 list
->aexpr_list
[ndx
] = NULL
;
875 list
->next_aexpr_elt
= 0;
876 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
879 /* reduce a collection list to string form (for gdb protocol) */
881 stringify_collection_list (struct collection_list
*list
, char *string
)
891 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
892 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
894 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
895 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
897 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
900 printf_filtered ("\nCollecting registers (mask): 0x");
905 QUIT
; /* allow user to bail out with ^C */
907 printf_filtered ("%02X", list
->regs_mask
[i
]);
908 sprintf (end
, "%02X", list
->regs_mask
[i
]);
911 (*str_list
)[ndx
] = xstrdup (temp_buf
);
915 printf_filtered ("\n");
916 if (list
->next_memrange
> 0 && info_verbose
)
917 printf_filtered ("Collecting memranges: \n");
918 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
920 QUIT
; /* allow user to bail out with ^C */
921 sprintf_vma (tmp2
, list
->list
[i
].start
);
924 printf_filtered ("(%d, %s, %ld)\n",
927 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
929 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
931 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
938 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
940 /* The "%X" conversion specifier expects an unsigned argument,
941 so passing -1 (memrange_absolute) to it directly gives you
942 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
944 if (list
->list
[i
].type
== memrange_absolute
)
945 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
947 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
950 count
+= strlen (end
);
951 end
= temp_buf
+ count
;
954 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
956 QUIT
; /* allow user to bail out with ^C */
957 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
959 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
964 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
965 end
+= 10; /* 'X' + 8 hex digits + ',' */
968 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
969 end
, list
->aexpr_list
[i
]->len
);
970 count
+= 2 * list
->aexpr_list
[i
]->len
;
975 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
980 (*str_list
)[ndx
] = NULL
;
992 free_actions_list_cleanup_wrapper (void *al
)
994 free_actions_list (al
);
998 free_actions_list (char **actions_list
)
1002 if (actions_list
== 0)
1005 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1006 xfree (actions_list
[ndx
]);
1008 xfree (actions_list
);
1011 /* Render all actions into gdb protocol. */
1013 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1014 char ***stepping_actions
)
1016 static char tdp_buff
[2048], step_buff
[2048];
1018 struct expression
*exp
= NULL
;
1019 struct action_line
*action
;
1021 struct value
*tempval
;
1022 struct collection_list
*collect
;
1023 struct cmd_list_element
*cmd
;
1024 struct agent_expr
*aexpr
;
1026 LONGEST frame_offset
;
1029 clear_collection_list (&tracepoint_list
);
1030 clear_collection_list (&stepping_list
);
1031 collect
= &tracepoint_list
;
1033 *tdp_actions
= NULL
;
1034 *stepping_actions
= NULL
;
1036 gdbarch_virtual_frame_pointer (t
->gdbarch
,
1037 t
->loc
->address
, &frame_reg
, &frame_offset
);
1039 for (action
= t
->actions
; action
; action
= action
->next
)
1041 QUIT
; /* allow user to bail out with ^C */
1042 action_exp
= action
->action
;
1043 while (isspace ((int) *action_exp
))
1046 if (*action_exp
== '#') /* comment line */
1049 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1051 error (_("Bad action list item: %s"), action_exp
);
1053 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1056 { /* repeat over a comma-separated list */
1057 QUIT
; /* allow user to bail out with ^C */
1058 while (isspace ((int) *action_exp
))
1061 if (0 == strncasecmp ("$reg", action_exp
, 4))
1063 for (i
= 0; i
< gdbarch_num_regs (t
->gdbarch
); i
++)
1064 add_register (collect
, i
);
1065 action_exp
= strchr (action_exp
, ','); /* more? */
1067 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1069 add_local_symbols (collect
,
1075 action_exp
= strchr (action_exp
, ','); /* more? */
1077 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1079 add_local_symbols (collect
,
1085 action_exp
= strchr (action_exp
, ','); /* more? */
1089 unsigned long addr
, len
;
1090 struct cleanup
*old_chain
= NULL
;
1091 struct cleanup
*old_chain1
= NULL
;
1092 struct agent_reqs areqs
;
1094 exp
= parse_exp_1 (&action_exp
,
1095 block_for_pc (t
->loc
->address
), 1);
1096 old_chain
= make_cleanup (free_current_contents
, &exp
);
1098 switch (exp
->elts
[0].opcode
)
1102 const char *name
= &exp
->elts
[2].string
;
1104 i
= user_reg_map_name_to_regnum (t
->gdbarch
,
1105 name
, strlen (name
));
1107 internal_error (__FILE__
, __LINE__
,
1108 _("Register $%s not available"),
1111 printf_filtered ("OP_REGISTER: ");
1112 add_register (collect
, i
);
1117 /* safe because we know it's a simple expression */
1118 tempval
= evaluate_expression (exp
);
1119 addr
= value_address (tempval
);
1120 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1121 add_memrange (collect
, memrange_absolute
, addr
, len
);
1125 collect_symbol (collect
,
1126 exp
->elts
[2].symbol
,
1132 default: /* full-fledged expression */
1133 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1135 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1137 ax_reqs (aexpr
, &areqs
);
1138 if (areqs
.flaw
!= agent_flaw_none
)
1139 error (_("malformed expression"));
1141 if (areqs
.min_height
< 0)
1142 error (_("gdb: Internal error: expression has min height < 0"));
1143 if (areqs
.max_height
> 20)
1144 error (_("expression too complicated, try simplifying"));
1146 discard_cleanups (old_chain1
);
1147 add_aexpr (collect
, aexpr
);
1149 /* take care of the registers */
1150 if (areqs
.reg_mask_len
> 0)
1155 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1157 QUIT
; /* allow user to bail out with ^C */
1158 if (areqs
.reg_mask
[ndx1
] != 0)
1160 /* assume chars have 8 bits */
1161 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1162 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1163 /* it's used -- record it */
1164 add_register (collect
,
1171 do_cleanups (old_chain
);
1174 while (action_exp
&& *action_exp
++ == ',');
1176 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1178 collect
= &stepping_list
;
1180 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1182 if (collect
== &stepping_list
) /* end stepping actions */
1183 collect
= &tracepoint_list
;
1185 break; /* end tracepoint actions */
1188 memrange_sortmerge (&tracepoint_list
);
1189 memrange_sortmerge (&stepping_list
);
1191 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1193 *stepping_actions
= stringify_collection_list (&stepping_list
,
1198 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1200 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1202 collect
->aexpr_list
=
1203 xrealloc (collect
->aexpr_list
,
1204 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1205 collect
->aexpr_listsize
*= 2;
1207 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1208 collect
->next_aexpr_elt
++;
1211 static char *target_buf
;
1212 static long target_buf_size
;
1214 /* Set "transparent" memory ranges
1216 Allow trace mechanism to treat text-like sections
1217 (and perhaps all read-only sections) transparently,
1218 i.e. don't reject memory requests from these address ranges
1219 just because they haven't been collected. */
1222 remote_set_transparent_ranges (void)
1230 return; /* No information to give. */
1232 strcpy (target_buf
, "QTro");
1233 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1235 char tmp1
[40], tmp2
[40];
1237 if ((s
->flags
& SEC_LOAD
) == 0 ||
1238 /* (s->flags & SEC_CODE) == 0 || */
1239 (s
->flags
& SEC_READONLY
) == 0)
1244 size
= bfd_get_section_size (s
);
1245 sprintf_vma (tmp1
, lma
);
1246 sprintf_vma (tmp2
, lma
+ size
);
1247 sprintf (target_buf
+ strlen (target_buf
),
1248 ":%s,%s", tmp1
, tmp2
);
1252 putpkt (target_buf
);
1253 getpkt (&target_buf
, &target_buf_size
, 0);
1259 Tell target to clear any previous trace experiment.
1260 Walk the list of tracepoints, and send them (and their actions)
1261 to the target. If no errors,
1262 Tell target to start a new trace experiment. */
1264 void download_tracepoint (struct breakpoint
*t
);
1267 trace_start_command (char *args
, int from_tty
)
1269 VEC(breakpoint_p
) *tp_vec
= NULL
;
1271 struct breakpoint
*t
;
1273 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1275 if (target_is_remote ())
1278 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1279 if (strcmp (target_buf
, "OK"))
1280 error (_("Target does not support this command."));
1282 tp_vec
= all_tracepoints ();
1283 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1285 download_tracepoint (t
);
1287 VEC_free (breakpoint_p
, tp_vec
);
1289 /* Tell target to treat text-like sections as transparent. */
1290 remote_set_transparent_ranges ();
1291 /* Now insert traps and begin collecting data. */
1293 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1294 if (strcmp (target_buf
, "OK"))
1295 error (_("Bogus reply from target: %s"), target_buf
);
1296 set_traceframe_num (-1); /* All old traceframes invalidated. */
1297 set_tracepoint_num (-1);
1298 set_traceframe_context (NULL
);
1299 trace_running_p
= 1;
1300 if (deprecated_trace_start_stop_hook
)
1301 deprecated_trace_start_stop_hook (1, from_tty
);
1305 error (_("Trace can only be run on remote targets."));
1308 /* Send the definition of a single tracepoint to the target. */
1311 download_tracepoint (struct breakpoint
*t
)
1316 char **stepping_actions
;
1318 struct cleanup
*old_chain
= NULL
;
1319 struct agent_expr
*aexpr
;
1320 struct cleanup
*aexpr_chain
= NULL
;
1322 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1323 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1325 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1326 t
->step_count
, t
->pass_count
);
1327 /* If the tracepoint has a conditional, make it into an agent
1328 expression and append to the definition. */
1331 /* Only test support at download time, we may not know target
1332 capabilities at definition time. */
1333 if (remote_supports_cond_tracepoints ())
1335 aexpr
= gen_eval_for_expr (t
->loc
->address
, t
->loc
->cond
);
1336 aexpr_chain
= make_cleanup_free_agent_expr (aexpr
);
1337 sprintf (buf
+ strlen (buf
), ":X%x,", aexpr
->len
);
1338 mem2hex (aexpr
->buf
, buf
+ strlen (buf
), aexpr
->len
);
1339 do_cleanups (aexpr_chain
);
1342 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t
->number
);
1348 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1349 if (strcmp (target_buf
, "OK"))
1350 error (_("Target does not support tracepoints."));
1355 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1356 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1358 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1360 /* do_single_steps (t); */
1363 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1365 QUIT
; /* allow user to bail out with ^C */
1366 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1367 t
->number
, tmp
, /* address */
1369 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1372 remote_get_noisy_reply (&target_buf
,
1374 if (strcmp (target_buf
, "OK"))
1375 error (_("Error on target while setting tracepoints."));
1378 if (stepping_actions
)
1380 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1382 QUIT
; /* allow user to bail out with ^C */
1383 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1384 t
->number
, tmp
, /* address */
1385 ((ndx
== 0) ? "S" : ""),
1386 stepping_actions
[ndx
],
1387 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1389 remote_get_noisy_reply (&target_buf
,
1391 if (strcmp (target_buf
, "OK"))
1392 error (_("Error on target while setting tracepoints."));
1395 do_cleanups (old_chain
);
1400 trace_stop_command (char *args
, int from_tty
)
1402 if (target_is_remote ())
1405 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1406 if (strcmp (target_buf
, "OK"))
1407 error (_("Bogus reply from target: %s"), target_buf
);
1408 trace_running_p
= 0;
1409 if (deprecated_trace_start_stop_hook
)
1410 deprecated_trace_start_stop_hook (0, from_tty
);
1413 error (_("Trace can only be run on remote targets."));
1416 unsigned long trace_running_p
;
1418 /* tstatus command */
1420 trace_status_command (char *args
, int from_tty
)
1422 if (target_is_remote ())
1424 putpkt ("qTStatus");
1425 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1427 if (target_buf
[0] != 'T' ||
1428 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1429 error (_("Bogus reply from target: %s"), target_buf
);
1431 /* exported for use by the GUI */
1432 trace_running_p
= (target_buf
[1] == '1');
1435 error (_("Trace can only be run on remote targets."));
1438 /* Worker function for the various flavors of the tfind command. */
1440 finish_tfind_command (char **msg
,
1444 int target_frameno
= -1, target_tracept
= -1;
1445 struct frame_id old_frame_id
;
1448 old_frame_id
= get_frame_id (get_current_frame ());
1451 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1453 while (reply
&& *reply
)
1457 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1459 /* A request for a non-existant trace frame has failed.
1460 Our response will be different, depending on FROM_TTY:
1462 If FROM_TTY is true, meaning that this command was
1463 typed interactively by the user, then give an error
1464 and DO NOT change the state of traceframe_number etc.
1466 However if FROM_TTY is false, meaning that we're either
1467 in a script, a loop, or a user-defined command, then
1468 DON'T give an error, but DO change the state of
1469 traceframe_number etc. to invalid.
1471 The rationalle is that if you typed the command, you
1472 might just have committed a typo or something, and you'd
1473 like to NOT lose your current debugging state. However
1474 if you're in a user-defined command or especially in a
1475 loop, then you need a way to detect that the command
1476 failed WITHOUT aborting. This allows you to write
1477 scripts that search thru the trace buffer until the end,
1478 and then continue on to do something else. */
1481 error (_("Target failed to find requested trace frame."));
1485 printf_filtered ("End of trace buffer.\n");
1486 /* The following will not recurse, since it's
1488 trace_find_command ("-1", from_tty
);
1489 reply
= NULL
; /* Break out of loop
1490 (avoid recursive nonsense). */
1495 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1496 error (_("Target failed to find requested trace frame."));
1498 case 'O': /* "OK"? */
1499 if (reply
[1] == 'K' && reply
[2] == '\0')
1502 error (_("Bogus reply from target: %s"), reply
);
1505 error (_("Bogus reply from target: %s"), reply
);
1508 reinit_frame_cache ();
1509 registers_changed ();
1510 set_traceframe_num (target_frameno
);
1511 set_tracepoint_num (target_tracept
);
1512 if (target_frameno
== -1)
1513 set_traceframe_context (NULL
);
1515 set_traceframe_context (get_current_frame ());
1519 enum print_what print_what
;
1521 /* NOTE: in immitation of the step command, try to determine
1522 whether we have made a transition from one function to
1523 another. If so, we'll print the "stack frame" (ie. the new
1524 function and it's arguments) -- otherwise we'll just show the
1527 if (frame_id_eq (old_frame_id
,
1528 get_frame_id (get_current_frame ())))
1529 print_what
= SRC_LINE
;
1531 print_what
= SRC_AND_LOC
;
1533 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1538 /* trace_find_command takes a trace frame number n,
1539 sends "QTFrame:<n>" to the target,
1540 and accepts a reply that may contain several optional pieces
1541 of information: a frame number, a tracepoint number, and an
1542 indication of whether this is a trap frame or a stepping frame.
1544 The minimal response is just "OK" (which indicates that the
1545 target does not give us a frame number or a tracepoint number).
1546 Instead of that, the target may send us a string containing
1548 F<hexnum> (gives the selected frame number)
1549 T<hexnum> (gives the selected tracepoint number)
1554 trace_find_command (char *args
, int from_tty
)
1555 { /* this should only be called with a numeric argument */
1558 if (target_is_remote ())
1560 if (deprecated_trace_find_hook
)
1561 deprecated_trace_find_hook (args
, from_tty
);
1563 if (args
== 0 || *args
== 0)
1564 { /* TFIND with no args means find NEXT trace frame. */
1565 if (traceframe_number
== -1)
1566 frameno
= 0; /* "next" is first one */
1568 frameno
= traceframe_number
+ 1;
1570 else if (0 == strcmp (args
, "-"))
1572 if (traceframe_number
== -1)
1573 error (_("not debugging trace buffer"));
1574 else if (from_tty
&& traceframe_number
== 0)
1575 error (_("already at start of trace buffer"));
1577 frameno
= traceframe_number
- 1;
1580 frameno
= parse_and_eval_long (args
);
1583 error (_("invalid input (%d is less than zero)"), frameno
);
1585 sprintf (target_buf
, "QTFrame:%x", frameno
);
1586 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1589 error (_("Trace can only be run on remote targets."));
1594 trace_find_end_command (char *args
, int from_tty
)
1596 trace_find_command ("-1", from_tty
);
1601 trace_find_none_command (char *args
, int from_tty
)
1603 trace_find_command ("-1", from_tty
);
1608 trace_find_start_command (char *args
, int from_tty
)
1610 trace_find_command ("0", from_tty
);
1613 /* tfind pc command */
1615 trace_find_pc_command (char *args
, int from_tty
)
1620 if (target_is_remote ())
1622 if (args
== 0 || *args
== 0)
1623 pc
= regcache_read_pc (get_current_regcache ());
1625 pc
= parse_and_eval_address (args
);
1627 sprintf_vma (tmp
, pc
);
1628 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
1629 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1632 error (_("Trace can only be run on remote targets."));
1635 /* tfind tracepoint command */
1637 trace_find_tracepoint_command (char *args
, int from_tty
)
1641 if (target_is_remote ())
1643 if (args
== 0 || *args
== 0)
1645 if (tracepoint_number
== -1)
1646 error (_("No current tracepoint -- please supply an argument."));
1648 tdp
= tracepoint_number
; /* default is current TDP */
1651 tdp
= parse_and_eval_long (args
);
1653 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1654 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1657 error (_("Trace can only be run on remote targets."));
1660 /* TFIND LINE command:
1662 This command will take a sourceline for argument, just like BREAK
1663 or TRACE (ie. anything that "decode_line_1" can handle).
1665 With no argument, this command will find the next trace frame
1666 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1669 trace_find_line_command (char *args
, int from_tty
)
1671 static CORE_ADDR start_pc
, end_pc
;
1672 struct symtabs_and_lines sals
;
1673 struct symtab_and_line sal
;
1674 struct cleanup
*old_chain
;
1675 char startpc_str
[40], endpc_str
[40];
1677 if (target_is_remote ())
1679 if (args
== 0 || *args
== 0)
1681 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1683 sals
.sals
= (struct symtab_and_line
*)
1684 xmalloc (sizeof (struct symtab_and_line
));
1689 sals
= decode_line_spec (args
, 1);
1693 old_chain
= make_cleanup (xfree
, sals
.sals
);
1694 if (sal
.symtab
== 0)
1696 struct gdbarch
*gdbarch
= get_current_arch ();
1698 printf_filtered ("TFIND: No line number information available");
1701 /* This is useful for "info line *0x7f34". If we can't
1702 tell the user about a source line, at least let them
1703 have the symbolic address. */
1704 printf_filtered (" for address ");
1706 print_address (gdbarch
, sal
.pc
, gdb_stdout
);
1707 printf_filtered (";\n -- will attempt to find by PC. \n");
1711 printf_filtered (".\n");
1712 return; /* No line, no PC; what can we do? */
1715 else if (sal
.line
> 0
1716 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1718 struct gdbarch
*gdbarch
= get_objfile_arch (sal
.symtab
->objfile
);
1720 if (start_pc
== end_pc
)
1722 printf_filtered ("Line %d of \"%s\"",
1723 sal
.line
, sal
.symtab
->filename
);
1725 printf_filtered (" is at address ");
1726 print_address (gdbarch
, start_pc
, gdb_stdout
);
1728 printf_filtered (" but contains no code.\n");
1729 sal
= find_pc_line (start_pc
, 0);
1731 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1733 printf_filtered ("Attempting to find line %d instead.\n",
1736 error (_("Cannot find a good line."));
1740 /* Is there any case in which we get here, and have an address
1741 which the user would want to see? If we have debugging
1742 symbols and no line numbers? */
1743 error (_("Line number %d is out of range for \"%s\"."),
1744 sal
.line
, sal
.symtab
->filename
);
1746 sprintf_vma (startpc_str
, start_pc
);
1747 sprintf_vma (endpc_str
, end_pc
- 1);
1748 /* Find within range of stated line. */
1750 sprintf (target_buf
, "QTFrame:range:%s:%s",
1751 startpc_str
, endpc_str
);
1752 /* Find OUTSIDE OF range of CURRENT line. */
1754 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1755 startpc_str
, endpc_str
);
1756 finish_tfind_command (&target_buf
, &target_buf_size
,
1758 do_cleanups (old_chain
);
1761 error (_("Trace can only be run on remote targets."));
1764 /* tfind range command */
1766 trace_find_range_command (char *args
, int from_tty
)
1768 static CORE_ADDR start
, stop
;
1769 char start_str
[40], stop_str
[40];
1772 if (target_is_remote ())
1774 if (args
== 0 || *args
== 0)
1775 { /* XXX FIXME: what should default behavior be? */
1776 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1780 if (0 != (tmp
= strchr (args
, ',')))
1782 *tmp
++ = '\0'; /* terminate start address */
1783 while (isspace ((int) *tmp
))
1785 start
= parse_and_eval_address (args
);
1786 stop
= parse_and_eval_address (tmp
);
1789 { /* no explicit end address? */
1790 start
= parse_and_eval_address (args
);
1791 stop
= start
+ 1; /* ??? */
1794 sprintf_vma (start_str
, start
);
1795 sprintf_vma (stop_str
, stop
);
1796 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1797 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1800 error (_("Trace can only be run on remote targets."));
1803 /* tfind outside command */
1805 trace_find_outside_command (char *args
, int from_tty
)
1807 CORE_ADDR start
, stop
;
1808 char start_str
[40], stop_str
[40];
1811 if (target_is_remote ())
1813 if (args
== 0 || *args
== 0)
1814 { /* XXX FIXME: what should default behavior be? */
1815 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1819 if (0 != (tmp
= strchr (args
, ',')))
1821 *tmp
++ = '\0'; /* terminate start address */
1822 while (isspace ((int) *tmp
))
1824 start
= parse_and_eval_address (args
);
1825 stop
= parse_and_eval_address (tmp
);
1828 { /* no explicit end address? */
1829 start
= parse_and_eval_address (args
);
1830 stop
= start
+ 1; /* ??? */
1833 sprintf_vma (start_str
, start
);
1834 sprintf_vma (stop_str
, stop
);
1835 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1836 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1839 error (_("Trace can only be run on remote targets."));
1842 /* info scope command: list the locals for a scope. */
1844 scope_info (char *args
, int from_tty
)
1846 struct symtabs_and_lines sals
;
1848 struct minimal_symbol
*msym
;
1849 struct block
*block
;
1850 char **canonical
, *symname
, *save_args
= args
;
1851 struct dict_iterator iter
;
1853 struct gdbarch
*gdbarch
;
1856 if (args
== 0 || *args
== 0)
1857 error (_("requires an argument (function, line or *addr) to define a scope"));
1859 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1860 if (sals
.nelts
== 0)
1861 return; /* presumably decode_line_1 has already warned */
1863 /* Resolve line numbers to PC */
1864 resolve_sal_pc (&sals
.sals
[0]);
1865 block
= block_for_pc (sals
.sals
[0].pc
);
1869 QUIT
; /* allow user to bail out with ^C */
1870 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1872 QUIT
; /* allow user to bail out with ^C */
1874 printf_filtered ("Scope for %s:\n", save_args
);
1877 symname
= SYMBOL_PRINT_NAME (sym
);
1878 if (symname
== NULL
|| *symname
== '\0')
1879 continue; /* probably botched, certainly useless */
1881 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
1883 printf_filtered ("Symbol %s is ", symname
);
1884 switch (SYMBOL_CLASS (sym
))
1887 case LOC_UNDEF
: /* messed up symbol? */
1888 printf_filtered ("a bogus symbol, class %d.\n",
1889 SYMBOL_CLASS (sym
));
1890 count
--; /* don't count this one */
1893 printf_filtered ("a constant with value %ld (0x%lx)",
1894 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
1896 case LOC_CONST_BYTES
:
1897 printf_filtered ("constant bytes: ");
1898 if (SYMBOL_TYPE (sym
))
1899 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
1900 fprintf_filtered (gdb_stdout
, " %02x",
1901 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
1904 printf_filtered ("in static storage at address ");
1905 printf_filtered ("%s", paddress (gdbarch
,
1906 SYMBOL_VALUE_ADDRESS (sym
)));
1909 /* GDBARCH is the architecture associated with the objfile
1910 the symbol is defined in; the target architecture may be
1911 different, and may provide additional registers. However,
1912 we do not know the target architecture at this point.
1913 We assume the objfile architecture will contain all the
1914 standard registers that occur in debug info in that
1916 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1918 if (SYMBOL_IS_ARGUMENT (sym
))
1919 printf_filtered ("an argument in register $%s",
1920 gdbarch_register_name (gdbarch
, regno
));
1922 printf_filtered ("a local variable in register $%s",
1923 gdbarch_register_name (gdbarch
, regno
));
1926 printf_filtered ("an argument at stack/frame offset %ld",
1927 SYMBOL_VALUE (sym
));
1930 printf_filtered ("a local variable at frame offset %ld",
1931 SYMBOL_VALUE (sym
));
1934 printf_filtered ("a reference argument at offset %ld",
1935 SYMBOL_VALUE (sym
));
1937 case LOC_REGPARM_ADDR
:
1938 /* Note comment at LOC_REGISTER. */
1939 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1940 printf_filtered ("the address of an argument, in register $%s",
1941 gdbarch_register_name (gdbarch
, regno
));
1944 printf_filtered ("a typedef.\n");
1947 printf_filtered ("a label at address ");
1948 printf_filtered ("%s", paddress (gdbarch
,
1949 SYMBOL_VALUE_ADDRESS (sym
)));
1952 printf_filtered ("a function at address ");
1953 printf_filtered ("%s",
1954 paddress (gdbarch
, BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
1956 case LOC_UNRESOLVED
:
1957 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1960 printf_filtered ("Unresolved Static");
1963 printf_filtered ("static storage at address ");
1964 printf_filtered ("%s",
1965 paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (msym
)));
1968 case LOC_OPTIMIZED_OUT
:
1969 printf_filtered ("optimized out.\n");
1972 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1975 if (SYMBOL_TYPE (sym
))
1976 printf_filtered (", length %d.\n",
1977 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
1979 if (BLOCK_FUNCTION (block
))
1982 block
= BLOCK_SUPERBLOCK (block
);
1985 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1989 /* worker function (cleanup) */
1991 replace_comma (void *data
)
1999 trace_dump_command (char *args
, int from_tty
)
2001 struct regcache
*regcache
;
2002 struct gdbarch
*gdbarch
;
2003 struct breakpoint
*t
;
2004 struct action_line
*action
;
2005 char *action_exp
, *next_comma
;
2006 struct cleanup
*old_cleanups
;
2007 int stepping_actions
= 0;
2008 int stepping_frame
= 0;
2010 if (!target_is_remote ())
2012 error (_("Trace can only be run on remote targets."));
2016 if (tracepoint_number
== -1)
2018 warning (_("No current trace frame."));
2022 t
= get_tracepoint (tracepoint_number
);
2025 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2028 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2030 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2031 tracepoint_number
, traceframe_number
);
2033 /* The current frame is a trap frame if the frame PC is equal
2034 to the tracepoint PC. If not, then the current frame was
2035 collected during single-stepping. */
2037 regcache
= get_current_regcache ();
2038 gdbarch
= get_regcache_arch (regcache
);
2040 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2041 - gdbarch_decr_pc_after_break (gdbarch
)));
2043 for (action
= t
->actions
; action
; action
= action
->next
)
2045 struct cmd_list_element
*cmd
;
2047 QUIT
; /* allow user to bail out with ^C */
2048 action_exp
= action
->action
;
2049 while (isspace ((int) *action_exp
))
2052 /* The collection actions to be done while stepping are
2053 bracketed by the commands "while-stepping" and "end". */
2055 if (*action_exp
== '#') /* comment line */
2058 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2060 error (_("Bad action list item: %s"), action_exp
);
2062 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2063 stepping_actions
= 1;
2064 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2065 stepping_actions
= 0;
2066 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2068 /* Display the collected data.
2069 For the trap frame, display only what was collected at
2070 the trap. Likewise for stepping frames, display only
2071 what was collected while stepping. This means that the
2072 two boolean variables, STEPPING_FRAME and
2073 STEPPING_ACTIONS should be equal. */
2074 if (stepping_frame
== stepping_actions
)
2077 { /* repeat over a comma-separated list */
2078 QUIT
; /* allow user to bail out with ^C */
2079 if (*action_exp
== ',')
2081 while (isspace ((int) *action_exp
))
2084 next_comma
= strchr (action_exp
, ',');
2086 if (0 == strncasecmp (action_exp
, "$reg", 4))
2087 registers_info (NULL
, from_tty
);
2088 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2089 locals_info (NULL
, from_tty
);
2090 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2091 args_info (NULL
, from_tty
);
2096 make_cleanup (replace_comma
, next_comma
);
2099 printf_filtered ("%s = ", action_exp
);
2100 output_command (action_exp
, from_tty
);
2101 printf_filtered ("\n");
2105 action_exp
= next_comma
;
2107 while (action_exp
&& *action_exp
== ',');
2111 discard_cleanups (old_cleanups
);
2114 /* Convert the memory pointed to by mem into hex, placing result in buf.
2115 * Return a pointer to the last char put in buf (null)
2116 * "stolen" from sparc-stub.c
2119 static const char hexchars
[] = "0123456789abcdef";
2122 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2130 *buf
++ = hexchars
[ch
>> 4];
2131 *buf
++ = hexchars
[ch
& 0xf];
2140 get_traceframe_number (void)
2142 return traceframe_number
;
2146 /* module initialization */
2148 _initialize_tracepoint (void)
2150 struct cmd_list_element
*c
;
2152 traceframe_number
= -1;
2153 tracepoint_number
= -1;
2155 if (tracepoint_list
.list
== NULL
)
2157 tracepoint_list
.listsize
= 128;
2158 tracepoint_list
.list
= xmalloc
2159 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2161 if (tracepoint_list
.aexpr_list
== NULL
)
2163 tracepoint_list
.aexpr_listsize
= 128;
2164 tracepoint_list
.aexpr_list
= xmalloc
2165 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2168 if (stepping_list
.list
== NULL
)
2170 stepping_list
.listsize
= 128;
2171 stepping_list
.list
= xmalloc
2172 (stepping_list
.listsize
* sizeof (struct memrange
));
2175 if (stepping_list
.aexpr_list
== NULL
)
2177 stepping_list
.aexpr_listsize
= 128;
2178 stepping_list
.aexpr_list
= xmalloc
2179 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2182 add_info ("scope", scope_info
,
2183 _("List the variables local to a scope"));
2185 add_cmd ("tracepoints", class_trace
, NULL
,
2186 _("Tracing of program execution without stopping the program."),
2189 add_com ("tdump", class_trace
, trace_dump_command
,
2190 _("Print everything collected at the current tracepoint."));
2192 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2193 Select a trace frame;\n\
2194 No argument means forward by one frame; '-' means backward by one frame."),
2195 &tfindlist
, "tfind ", 1, &cmdlist
);
2197 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2198 Select a trace frame whose PC is outside the given range.\n\
2199 Usage: tfind outside addr1, addr2"),
2202 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2203 Select a trace frame whose PC is in the given range.\n\
2204 Usage: tfind range addr1,addr2"),
2207 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2208 Select a trace frame by source line.\n\
2209 Argument can be a line number (with optional source file), \n\
2210 a function name, or '*' followed by an address.\n\
2211 Default argument is 'the next source line that was traced'."),
2214 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2215 Select a trace frame by tracepoint number.\n\
2216 Default is the tracepoint for the current trace frame."),
2219 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2220 Select a trace frame by PC.\n\
2221 Default is the current PC, or the PC of the current trace frame."),
2224 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2225 Synonym for 'none'.\n\
2226 De-select any trace frame and resume 'live' debugging."),
2229 add_cmd ("none", class_trace
, trace_find_none_command
,
2230 _("De-select any trace frame and resume 'live' debugging."),
2233 add_cmd ("start", class_trace
, trace_find_start_command
,
2234 _("Select the first trace frame in the trace buffer."),
2237 add_com ("tstatus", class_trace
, trace_status_command
,
2238 _("Display the status of the current trace data collection."));
2240 add_com ("tstop", class_trace
, trace_stop_command
,
2241 _("Stop trace data collection."));
2243 add_com ("tstart", class_trace
, trace_start_command
,
2244 _("Start trace data collection."));
2246 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2247 Ends a list of commands or actions.\n\
2248 Several GDB commands allow you to enter a list of commands or actions.\n\
2249 Entering \"end\" on a line by itself is the normal way to terminate\n\
2251 Note: the \"end\" command cannot be used at the gdb prompt."));
2253 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2254 Specify single-stepping behavior at a tracepoint.\n\
2255 Argument is number of instructions to trace in single-step mode\n\
2256 following the tracepoint. This command is normally followed by\n\
2257 one or more \"collect\" commands, to specify what to collect\n\
2258 while single-stepping.\n\n\
2259 Note: this command can only be used in a tracepoint \"actions\" list."));
2261 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2262 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2264 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2265 Specify one or more data items to be collected at a tracepoint.\n\
2266 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2267 collect all data (variables, registers) referenced by that expression.\n\
2268 Also accepts the following special arguments:\n\
2269 $regs -- all registers.\n\
2270 $args -- all function arguments.\n\
2271 $locals -- all variables local to the block/function scope.\n\
2272 Note: this command can only be used in a tracepoint \"actions\" list."));
2274 add_com ("actions", class_trace
, trace_actions_command
, _("\
2275 Specify the actions to be taken at a tracepoint.\n\
2276 Tracepoint actions may include collecting of specified data, \n\
2277 single-stepping, or enabling/disabling other tracepoints, \n\
2278 depending on target's capabilities."));
2280 target_buf_size
= 2048;
2281 target_buf
= xmalloc (target_buf_size
);