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/>. */
25 #include "expression.h"
30 #include "gdb_string.h"
32 #include "breakpoint.h"
33 #include "tracepoint.h"
37 #include "completer.h"
39 #include "dictionary.h"
41 #include "user-regs.h"
49 /* readline include files */
50 #include "readline/readline.h"
51 #include "readline/history.h"
53 /* readline defines this. */
60 /* Maximum length of an agent aexpression.
61 This accounts for the fact that packets are limited to 400 bytes
62 (which includes everything -- including the checksum), and assumes
63 the worst case of maximum length for each of the pieces of a
66 NOTE: expressions get mem2hex'ed otherwise this would be twice as
67 large. (400 - 31)/2 == 184 */
68 #define MAX_AGENT_EXPR_LEN 184
71 extern void (*deprecated_readline_begin_hook
) (char *, ...);
72 extern char *(*deprecated_readline_hook
) (char *);
73 extern void (*deprecated_readline_end_hook
) (void);
75 /* GDB commands implemented in other modules:
78 extern void output_command (char *, int);
83 This module defines the following debugger commands:
84 trace : set a tracepoint on a function, line, or address.
85 info trace : list all debugger-defined tracepoints.
86 delete trace : delete one or more tracepoints.
87 enable trace : enable one or more tracepoints.
88 disable trace : disable one or more tracepoints.
89 actions : specify actions to be taken at a tracepoint.
90 passcount : specify a pass count for a tracepoint.
91 tstart : start a trace experiment.
92 tstop : stop a trace experiment.
93 tstatus : query the status of a trace experiment.
94 tfind : find a trace frame in the trace buffer.
95 tdump : print everything collected at the current tracepoint.
96 save-tracepoints : write tracepoint setup into a file.
98 This module defines the following user-visible debugger variables:
99 $trace_frame : sequence number of trace frame currently being debugged.
100 $trace_line : source line of trace frame currently being debugged.
101 $trace_file : source file of trace frame currently being debugged.
102 $tracepoint : tracepoint number of trace frame currently being debugged.
106 /* ======= Important global variables: ======= */
108 /* Number of last traceframe collected. */
109 static int traceframe_number
;
111 /* Tracepoint for last traceframe collected. */
112 static int tracepoint_number
;
114 /* Symbol for function for last traceframe collected */
115 static struct symbol
*traceframe_fun
;
117 /* Symtab and line for last traceframe collected */
118 static struct symtab_and_line traceframe_sal
;
120 /* Tracing command lists */
121 static struct cmd_list_element
*tfindlist
;
123 /* ======= Important command functions: ======= */
124 static void trace_actions_command (char *, int);
125 static void trace_start_command (char *, int);
126 static void trace_stop_command (char *, int);
127 static void trace_status_command (char *, int);
128 static void trace_find_command (char *, int);
129 static void trace_find_pc_command (char *, int);
130 static void trace_find_tracepoint_command (char *, int);
131 static void trace_find_line_command (char *, int);
132 static void trace_find_range_command (char *, int);
133 static void trace_find_outside_command (char *, int);
134 static void tracepoint_save_command (char *, int);
135 static void trace_dump_command (char *, int);
137 /* support routines */
139 struct collection_list
;
140 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
141 static char *mem2hex (gdb_byte
*, char *, int);
142 static void add_register (struct collection_list
*collection
,
144 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
145 static void free_actions_list (char **actions_list
);
146 static void free_actions_list_cleanup_wrapper (void *);
148 extern void _initialize_tracepoint (void);
150 /* Utility: returns true if "target remote" */
152 target_is_remote (void)
154 if (current_target
.to_shortname
&&
155 (strcmp (current_target
.to_shortname
, "remote") == 0
156 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
162 /* Utility: generate error from an incoming stub packet. */
164 trace_error (char *buf
)
167 return; /* not an error msg */
170 case '1': /* malformed packet error */
171 if (*++buf
== '0') /* general case: */
172 error (_("tracepoint.c: error in outgoing packet."));
174 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
175 strtol (buf
, NULL
, 16));
177 error (_("trace API error 0x%s."), ++buf
);
179 error (_("Target returns error code '%s'."), buf
);
183 /* Utility: wait for reply from stub, while accepting "O" packets. */
185 remote_get_noisy_reply (char **buf_p
,
188 do /* Loop on reply from remote stub. */
191 QUIT
; /* allow user to bail out with ^C */
192 getpkt (buf_p
, sizeof_buf
, 0);
195 error (_("Target does not support this command."));
196 else if (buf
[0] == 'E')
198 else if (buf
[0] == 'O' &&
200 remote_console_output (buf
+ 1); /* 'O' message from stub */
202 return buf
; /* here's the actual reply */
207 /* Set traceframe number to NUM. */
209 set_traceframe_num (int num
)
211 traceframe_number
= num
;
212 set_internalvar_integer (lookup_internalvar ("trace_frame"), num
);
215 /* Set tracepoint number to NUM. */
217 set_tracepoint_num (int num
)
219 tracepoint_number
= num
;
220 set_internalvar_integer (lookup_internalvar ("tracepoint"), num
);
223 /* Set externally visible debug variables for querying/printing
224 the traceframe context (line, function, file) */
227 set_traceframe_context (struct frame_info
*trace_frame
)
231 static struct type
*func_string
, *file_string
;
232 static struct type
*func_range
, *file_range
;
233 struct value
*func_val
;
234 struct value
*file_val
;
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"));
265 len
= strlen (SYMBOL_LINKAGE_NAME (traceframe_fun
));
266 func_range
= create_range_type (func_range
,
267 builtin_type_int32
, 0, len
- 1);
268 func_string
= create_array_type (func_string
,
269 builtin_type_true_char
, func_range
);
270 func_val
= allocate_value (func_string
);
271 deprecated_set_value_type (func_val
, func_string
);
272 memcpy (value_contents_raw (func_val
),
273 SYMBOL_LINKAGE_NAME (traceframe_fun
),
275 deprecated_set_value_modifiable (func_val
, 0);
276 set_internalvar (lookup_internalvar ("trace_func"), func_val
);
279 /* Save file name as "$trace_file", a debugger variable visible to
281 if (traceframe_sal
.symtab
== NULL
282 || traceframe_sal
.symtab
->filename
== NULL
)
283 clear_internalvar (lookup_internalvar ("trace_file"));
286 len
= strlen (traceframe_sal
.symtab
->filename
);
287 file_range
= create_range_type (file_range
,
288 builtin_type_int32
, 0, len
- 1);
289 file_string
= create_array_type (file_string
,
290 builtin_type_true_char
, file_range
);
291 file_val
= allocate_value (file_string
);
292 deprecated_set_value_type (file_val
, file_string
);
293 memcpy (value_contents_raw (file_val
),
294 traceframe_sal
.symtab
->filename
,
296 deprecated_set_value_modifiable (file_val
, 0);
297 set_internalvar (lookup_internalvar ("trace_file"), file_val
);
301 /* ACTIONS functions: */
303 /* Prototypes for action-parsing utility commands */
304 static void read_actions (struct breakpoint
*);
306 /* The three functions:
307 collect_pseudocommand,
308 while_stepping_pseudocommand, and
309 end_actions_pseudocommand
310 are placeholders for "commands" that are actually ONLY to be used
311 within a tracepoint action list. If the actual function is ever called,
312 it means that somebody issued the "command" at the top level,
313 which is always an error. */
316 end_actions_pseudocommand (char *args
, int from_tty
)
318 error (_("This command cannot be used at the top level."));
322 while_stepping_pseudocommand (char *args
, int from_tty
)
324 error (_("This command can only be used in a tracepoint actions list."));
328 collect_pseudocommand (char *args
, int from_tty
)
330 error (_("This command can only be used in a tracepoint actions list."));
333 /* Enter a list of actions for a tracepoint. */
335 trace_actions_command (char *args
, int from_tty
)
337 struct breakpoint
*t
;
339 char *end_msg
= "End with a line saying just \"end\".";
341 t
= get_tracepoint_by_number (&args
, 0, 1);
344 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
349 if (deprecated_readline_begin_hook
)
350 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
351 else if (input_from_terminal_p ())
352 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
356 t
->step_count
= 0; /* read_actions may set this */
359 if (deprecated_readline_end_hook
)
360 (*deprecated_readline_end_hook
) ();
361 /* tracepoints_changed () */
363 /* else just return */
366 /* worker function */
368 read_actions (struct breakpoint
*t
)
371 char *prompt1
= "> ", *prompt2
= " > ";
372 char *prompt
= prompt1
;
373 enum actionline_type linetype
;
374 extern FILE *instream
;
375 struct action_line
*next
= NULL
, *temp
;
376 struct cleanup
*old_chain
;
378 /* Control-C quits instantly if typed while in this loop
379 since it should not wait until the user types a newline. */
381 /* FIXME: kettenis/20010823: Something is wrong here. In this file
382 STOP_SIGNAL is never defined. So this code has been left out, at
383 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
384 leads to compilation failures since the variable job_control
385 isn't declared. Leave this alone for now. */
388 signal (STOP_SIGNAL
, handle_stop_sig
);
390 old_chain
= make_cleanup_free_actions (t
);
393 /* Make sure that all output has been output. Some machines may
394 let you get away with leaving out some of the gdb_flush, but
397 gdb_flush (gdb_stdout
);
398 gdb_flush (gdb_stderr
);
400 if (deprecated_readline_hook
&& instream
== NULL
)
401 line
= (*deprecated_readline_hook
) (prompt
);
402 else if (instream
== stdin
&& ISATTY (instream
))
404 line
= gdb_readline_wrapper (prompt
);
405 if (line
&& *line
) /* add it to command history */
409 line
= gdb_readline (0);
413 line
= xstrdup ("end");
414 printf_filtered ("end\n");
417 linetype
= validate_actionline (&line
, t
);
418 if (linetype
== BADLINE
)
419 continue; /* already warned -- collect another line */
421 temp
= xmalloc (sizeof (struct action_line
));
425 if (next
== NULL
) /* first action for this tracepoint? */
426 t
->actions
= next
= temp
;
433 if (linetype
== STEPPING
) /* begin "while-stepping" */
435 if (prompt
== prompt2
)
437 warning (_("Already processing 'while-stepping'"));
441 prompt
= prompt2
; /* change prompt for stepping actions */
443 else if (linetype
== END
)
445 if (prompt
== prompt2
)
447 prompt
= prompt1
; /* end of single-stepping actions */
450 { /* end of actions */
451 if (t
->actions
->next
== NULL
)
453 /* An "end" all by itself with no other actions
454 means this tracepoint has no actions.
455 Discard empty list. */
464 signal (STOP_SIGNAL
, SIG_DFL
);
467 discard_cleanups (old_chain
);
470 /* worker function */
472 validate_actionline (char **line
, struct breakpoint
*t
)
474 struct cmd_list_element
*c
;
475 struct expression
*exp
= NULL
;
476 struct cleanup
*old_chain
= NULL
;
479 /* if EOF is typed, *line is NULL */
483 for (p
= *line
; isspace ((int) *p
);)
486 /* Symbol lookup etc. */
487 if (*p
== '\0') /* empty line: just prompt for another line. */
490 if (*p
== '#') /* comment line */
493 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
496 warning (_("'%s' is not an action that I know, or is ambiguous."),
501 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
503 struct agent_expr
*aexpr
;
504 struct agent_reqs areqs
;
507 { /* repeat over a comma-separated list */
508 QUIT
; /* allow user to bail out with ^C */
509 while (isspace ((int) *p
))
512 if (*p
== '$') /* look for special pseudo-symbols */
514 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
515 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
516 (0 == strncasecmp ("loc", p
+ 1, 3)))
521 /* else fall thru, treat p as an expression and parse it! */
523 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
524 old_chain
= make_cleanup (free_current_contents
, &exp
);
526 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
528 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
530 warning (_("constant %s (value %ld) will not be collected."),
531 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
532 SYMBOL_VALUE (exp
->elts
[2].symbol
));
535 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
537 warning (_("%s is optimized away and cannot be collected."),
538 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
543 /* We have something to collect, make sure that the expr to
544 bytecode translator can handle it and that it's not too
546 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
547 make_cleanup_free_agent_expr (aexpr
);
549 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
550 error (_("expression too complicated, try simplifying"));
552 ax_reqs (aexpr
, &areqs
);
553 (void) make_cleanup (xfree
, areqs
.reg_mask
);
555 if (areqs
.flaw
!= agent_flaw_none
)
556 error (_("malformed expression"));
558 if (areqs
.min_height
< 0)
559 error (_("gdb: Internal error: expression has min height < 0"));
561 if (areqs
.max_height
> 20)
562 error (_("expression too complicated, try simplifying"));
564 do_cleanups (old_chain
);
566 while (p
&& *p
++ == ',');
569 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
571 char *steparg
; /* in case warning is necessary */
573 while (isspace ((int) *p
))
578 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
580 warning (_("'%s': bad step-count; command ignored."), *line
);
585 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
589 warning (_("'%s' is not a supported tracepoint action."), *line
);
594 /* worker function */
596 free_actions (struct breakpoint
*t
)
598 struct action_line
*line
, *next
;
600 for (line
= t
->actions
; line
; line
= next
)
604 xfree (line
->action
);
611 do_free_actions_cleanup (void *t
)
616 static struct cleanup
*
617 make_cleanup_free_actions (struct breakpoint
*t
)
619 return make_cleanup (do_free_actions_cleanup
, t
);
623 memrange_absolute
= -1
628 int type
; /* memrange_absolute for absolute memory range,
629 else basereg number */
630 bfd_signed_vma start
;
634 struct collection_list
636 unsigned char regs_mask
[32]; /* room for up to 256 regs */
639 struct memrange
*list
;
640 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
642 struct agent_expr
**aexpr_list
;
645 tracepoint_list
, stepping_list
;
647 /* MEMRANGE functions: */
649 static int memrange_cmp (const void *, const void *);
651 /* compare memranges for qsort */
653 memrange_cmp (const void *va
, const void *vb
)
655 const struct memrange
*a
= va
, *b
= vb
;
657 if (a
->type
< b
->type
)
659 if (a
->type
> b
->type
)
661 if (a
->type
== memrange_absolute
)
663 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
665 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
670 if (a
->start
< b
->start
)
672 if (a
->start
> b
->start
)
678 /* Sort the memrange list using qsort, and merge adjacent memranges. */
680 memrange_sortmerge (struct collection_list
*memranges
)
684 qsort (memranges
->list
, memranges
->next_memrange
,
685 sizeof (struct memrange
), memrange_cmp
);
686 if (memranges
->next_memrange
> 0)
688 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
690 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
691 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
694 /* memrange b starts before memrange a ends; merge them. */
695 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
696 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
697 continue; /* next b, same a */
701 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
702 sizeof (struct memrange
));
704 memranges
->next_memrange
= a
+ 1;
708 /* Add a register to a collection list. */
710 add_register (struct collection_list
*collection
, unsigned int regno
)
713 printf_filtered ("collect register %d\n", regno
);
714 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
715 error (_("Internal: register number %d too large for tracepoint"),
717 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
720 /* Add a memrange to a collection list */
722 add_memrange (struct collection_list
*memranges
,
723 int type
, bfd_signed_vma base
,
728 printf_filtered ("(%d,", type
);
730 printf_filtered (",%ld)\n", len
);
733 /* type: memrange_absolute == memory, other n == basereg */
734 memranges
->list
[memranges
->next_memrange
].type
= type
;
735 /* base: addr if memory, offset if reg relative. */
736 memranges
->list
[memranges
->next_memrange
].start
= base
;
737 /* len: we actually save end (base + len) for convenience */
738 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
739 memranges
->next_memrange
++;
740 if (memranges
->next_memrange
>= memranges
->listsize
)
742 memranges
->listsize
*= 2;
743 memranges
->list
= xrealloc (memranges
->list
,
744 memranges
->listsize
);
747 if (type
!= memrange_absolute
) /* Better collect the base register! */
748 add_register (memranges
, type
);
751 /* Add a symbol to a collection list. */
753 collect_symbol (struct collection_list
*collect
,
755 long frame_regno
, long frame_offset
)
759 bfd_signed_vma offset
;
761 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
762 switch (SYMBOL_CLASS (sym
))
765 printf_filtered ("%s: don't know symbol class %d\n",
766 SYMBOL_PRINT_NAME (sym
),
770 printf_filtered ("constant %s (value %ld) will not be collected.\n",
771 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
774 offset
= SYMBOL_VALUE_ADDRESS (sym
);
779 sprintf_vma (tmp
, offset
);
780 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
781 SYMBOL_PRINT_NAME (sym
), len
,
784 add_memrange (collect
, memrange_absolute
, offset
, len
);
787 reg
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, current_gdbarch
);
789 printf_filtered ("LOC_REG[parm] %s: ",
790 SYMBOL_PRINT_NAME (sym
));
791 add_register (collect
, reg
);
792 /* Check for doubles stored in two registers. */
793 /* FIXME: how about larger types stored in 3 or more regs? */
794 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
795 len
> register_size (current_gdbarch
, reg
))
796 add_register (collect
, reg
+ 1);
799 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
800 printf_filtered (" (will not collect %s)\n",
801 SYMBOL_PRINT_NAME (sym
));
805 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
808 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
809 SYMBOL_PRINT_NAME (sym
), len
);
811 printf_filtered (" from frame ptr reg %d\n", reg
);
813 add_memrange (collect
, reg
, offset
, len
);
815 case LOC_REGPARM_ADDR
:
816 reg
= SYMBOL_VALUE (sym
);
820 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
821 SYMBOL_PRINT_NAME (sym
), len
);
823 printf_filtered (" from reg %d\n", reg
);
825 add_memrange (collect
, reg
, offset
, len
);
829 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
832 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
833 SYMBOL_PRINT_NAME (sym
), len
);
835 printf_filtered (" from frame ptr reg %d\n", reg
);
837 add_memrange (collect
, reg
, offset
, len
);
840 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
841 SYMBOL_PRINT_NAME (sym
));
843 case LOC_OPTIMIZED_OUT
:
844 printf_filtered ("%s has been optimized out of existence.\n",
845 SYMBOL_PRINT_NAME (sym
));
850 /* Add all locals (or args) symbols to collection list */
852 add_local_symbols (struct collection_list
*collect
, CORE_ADDR pc
,
853 long frame_regno
, long frame_offset
, int type
)
857 struct dict_iterator iter
;
860 block
= block_for_pc (pc
);
863 QUIT
; /* allow user to bail out with ^C */
864 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
866 if (SYMBOL_IS_ARGUMENT (sym
)
867 ? type
== 'A' /* collecting Arguments */
868 : type
== 'L') /* collecting Locals */
871 collect_symbol (collect
, sym
, frame_regno
,
875 if (BLOCK_FUNCTION (block
))
878 block
= BLOCK_SUPERBLOCK (block
);
881 warning (_("No %s found in scope."),
882 type
== 'L' ? "locals" : "args");
885 /* worker function */
887 clear_collection_list (struct collection_list
*list
)
891 list
->next_memrange
= 0;
892 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
894 free_agent_expr (list
->aexpr_list
[ndx
]);
895 list
->aexpr_list
[ndx
] = NULL
;
897 list
->next_aexpr_elt
= 0;
898 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
901 /* reduce a collection list to string form (for gdb protocol) */
903 stringify_collection_list (struct collection_list
*list
, char *string
)
913 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
914 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
916 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
917 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
919 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
922 printf_filtered ("\nCollecting registers (mask): 0x");
927 QUIT
; /* allow user to bail out with ^C */
929 printf_filtered ("%02X", list
->regs_mask
[i
]);
930 sprintf (end
, "%02X", list
->regs_mask
[i
]);
933 (*str_list
)[ndx
] = xstrdup (temp_buf
);
937 printf_filtered ("\n");
938 if (list
->next_memrange
> 0 && info_verbose
)
939 printf_filtered ("Collecting memranges: \n");
940 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
942 QUIT
; /* allow user to bail out with ^C */
943 sprintf_vma (tmp2
, list
->list
[i
].start
);
946 printf_filtered ("(%d, %s, %ld)\n",
949 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
951 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
953 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
960 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
962 /* The "%X" conversion specifier expects an unsigned argument,
963 so passing -1 (memrange_absolute) to it directly gives you
964 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
966 if (list
->list
[i
].type
== memrange_absolute
)
967 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
969 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
972 count
+= strlen (end
);
973 end
= temp_buf
+ count
;
976 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
978 QUIT
; /* allow user to bail out with ^C */
979 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
981 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
986 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
987 end
+= 10; /* 'X' + 8 hex digits + ',' */
990 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
991 end
, list
->aexpr_list
[i
]->len
);
992 count
+= 2 * list
->aexpr_list
[i
]->len
;
997 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1002 (*str_list
)[ndx
] = NULL
;
1014 free_actions_list_cleanup_wrapper (void *al
)
1016 free_actions_list (al
);
1020 free_actions_list (char **actions_list
)
1024 if (actions_list
== 0)
1027 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1028 xfree (actions_list
[ndx
]);
1030 xfree (actions_list
);
1033 /* Render all actions into gdb protocol. */
1035 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1036 char ***stepping_actions
)
1038 static char tdp_buff
[2048], step_buff
[2048];
1040 struct expression
*exp
= NULL
;
1041 struct action_line
*action
;
1043 struct value
*tempval
;
1044 struct collection_list
*collect
;
1045 struct cmd_list_element
*cmd
;
1046 struct agent_expr
*aexpr
;
1048 LONGEST frame_offset
;
1051 clear_collection_list (&tracepoint_list
);
1052 clear_collection_list (&stepping_list
);
1053 collect
= &tracepoint_list
;
1055 *tdp_actions
= NULL
;
1056 *stepping_actions
= NULL
;
1058 gdbarch_virtual_frame_pointer (current_gdbarch
,
1059 t
->loc
->address
, &frame_reg
, &frame_offset
);
1061 for (action
= t
->actions
; action
; action
= action
->next
)
1063 QUIT
; /* allow user to bail out with ^C */
1064 action_exp
= action
->action
;
1065 while (isspace ((int) *action_exp
))
1068 if (*action_exp
== '#') /* comment line */
1071 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1073 error (_("Bad action list item: %s"), action_exp
);
1075 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1078 { /* repeat over a comma-separated list */
1079 QUIT
; /* allow user to bail out with ^C */
1080 while (isspace ((int) *action_exp
))
1083 if (0 == strncasecmp ("$reg", action_exp
, 4))
1085 for (i
= 0; i
< gdbarch_num_regs (current_gdbarch
); i
++)
1086 add_register (collect
, i
);
1087 action_exp
= strchr (action_exp
, ','); /* more? */
1089 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1091 add_local_symbols (collect
,
1096 action_exp
= strchr (action_exp
, ','); /* more? */
1098 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1100 add_local_symbols (collect
,
1105 action_exp
= strchr (action_exp
, ','); /* more? */
1109 unsigned long addr
, len
;
1110 struct cleanup
*old_chain
= NULL
;
1111 struct cleanup
*old_chain1
= NULL
;
1112 struct agent_reqs areqs
;
1114 exp
= parse_exp_1 (&action_exp
,
1115 block_for_pc (t
->loc
->address
), 1);
1116 old_chain
= make_cleanup (free_current_contents
, &exp
);
1118 switch (exp
->elts
[0].opcode
)
1122 const char *name
= &exp
->elts
[2].string
;
1124 i
= user_reg_map_name_to_regnum (current_gdbarch
,
1125 name
, strlen (name
));
1127 internal_error (__FILE__
, __LINE__
,
1128 _("Register $%s not available"),
1131 printf_filtered ("OP_REGISTER: ");
1132 add_register (collect
, i
);
1137 /* safe because we know it's a simple expression */
1138 tempval
= evaluate_expression (exp
);
1139 addr
= value_address (tempval
);
1140 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1141 add_memrange (collect
, memrange_absolute
, addr
, len
);
1145 collect_symbol (collect
,
1146 exp
->elts
[2].symbol
,
1151 default: /* full-fledged expression */
1152 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1154 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1156 ax_reqs (aexpr
, &areqs
);
1157 if (areqs
.flaw
!= agent_flaw_none
)
1158 error (_("malformed expression"));
1160 if (areqs
.min_height
< 0)
1161 error (_("gdb: Internal error: expression has min height < 0"));
1162 if (areqs
.max_height
> 20)
1163 error (_("expression too complicated, try simplifying"));
1165 discard_cleanups (old_chain1
);
1166 add_aexpr (collect
, aexpr
);
1168 /* take care of the registers */
1169 if (areqs
.reg_mask_len
> 0)
1174 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1176 QUIT
; /* allow user to bail out with ^C */
1177 if (areqs
.reg_mask
[ndx1
] != 0)
1179 /* assume chars have 8 bits */
1180 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1181 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1182 /* it's used -- record it */
1183 add_register (collect
,
1190 do_cleanups (old_chain
);
1193 while (action_exp
&& *action_exp
++ == ',');
1195 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1197 collect
= &stepping_list
;
1199 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1201 if (collect
== &stepping_list
) /* end stepping actions */
1202 collect
= &tracepoint_list
;
1204 break; /* end tracepoint actions */
1207 memrange_sortmerge (&tracepoint_list
);
1208 memrange_sortmerge (&stepping_list
);
1210 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1212 *stepping_actions
= stringify_collection_list (&stepping_list
,
1217 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1219 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1221 collect
->aexpr_list
=
1222 xrealloc (collect
->aexpr_list
,
1223 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1224 collect
->aexpr_listsize
*= 2;
1226 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1227 collect
->next_aexpr_elt
++;
1230 static char *target_buf
;
1231 static long target_buf_size
;
1233 /* Set "transparent" memory ranges
1235 Allow trace mechanism to treat text-like sections
1236 (and perhaps all read-only sections) transparently,
1237 i.e. don't reject memory requests from these address ranges
1238 just because they haven't been collected. */
1241 remote_set_transparent_ranges (void)
1249 return; /* No information to give. */
1251 strcpy (target_buf
, "QTro");
1252 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1254 char tmp1
[40], tmp2
[40];
1256 if ((s
->flags
& SEC_LOAD
) == 0 ||
1257 /* (s->flags & SEC_CODE) == 0 || */
1258 (s
->flags
& SEC_READONLY
) == 0)
1263 size
= bfd_get_section_size (s
);
1264 sprintf_vma (tmp1
, lma
);
1265 sprintf_vma (tmp2
, lma
+ size
);
1266 sprintf (target_buf
+ strlen (target_buf
),
1267 ":%s,%s", tmp1
, tmp2
);
1271 putpkt (target_buf
);
1272 getpkt (&target_buf
, &target_buf_size
, 0);
1278 Tell target to clear any previous trace experiment.
1279 Walk the list of tracepoints, and send them (and their actions)
1280 to the target. If no errors,
1281 Tell target to start a new trace experiment. */
1283 void download_tracepoint (struct breakpoint
*t
);
1286 trace_start_command (char *args
, int from_tty
)
1288 VEC(breakpoint_p
) *tp_vec
= NULL
;
1290 struct breakpoint
*t
;
1292 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1294 if (target_is_remote ())
1297 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1298 if (strcmp (target_buf
, "OK"))
1299 error (_("Target does not support this command."));
1301 tp_vec
= all_tracepoints ();
1302 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1304 download_tracepoint (t
);
1306 VEC_free (breakpoint_p
, tp_vec
);
1308 /* Tell target to treat text-like sections as transparent. */
1309 remote_set_transparent_ranges ();
1310 /* Now insert traps and begin collecting data. */
1312 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1313 if (strcmp (target_buf
, "OK"))
1314 error (_("Bogus reply from target: %s"), target_buf
);
1315 set_traceframe_num (-1); /* All old traceframes invalidated. */
1316 set_tracepoint_num (-1);
1317 set_traceframe_context (NULL
);
1318 trace_running_p
= 1;
1319 if (deprecated_trace_start_stop_hook
)
1320 deprecated_trace_start_stop_hook (1, from_tty
);
1324 error (_("Trace can only be run on remote targets."));
1327 /* Send the definition of a single tracepoint to the target. */
1330 download_tracepoint (struct breakpoint
*t
)
1335 char **stepping_actions
;
1337 struct cleanup
*old_chain
= NULL
;
1339 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1340 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1342 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1343 t
->step_count
, t
->pass_count
);
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 printf_filtered ("TFIND: No line number information available");
1699 /* This is useful for "info line *0x7f34". If we can't
1700 tell the user about a source line, at least let them
1701 have the symbolic address. */
1702 printf_filtered (" for address ");
1704 print_address (sal
.pc
, gdb_stdout
);
1705 printf_filtered (";\n -- will attempt to find by PC. \n");
1709 printf_filtered (".\n");
1710 return; /* No line, no PC; what can we do? */
1713 else if (sal
.line
> 0
1714 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1716 if (start_pc
== end_pc
)
1718 printf_filtered ("Line %d of \"%s\"",
1719 sal
.line
, sal
.symtab
->filename
);
1721 printf_filtered (" is at address ");
1722 print_address (start_pc
, gdb_stdout
);
1724 printf_filtered (" but contains no code.\n");
1725 sal
= find_pc_line (start_pc
, 0);
1727 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1729 printf_filtered ("Attempting to find line %d instead.\n",
1732 error (_("Cannot find a good line."));
1736 /* Is there any case in which we get here, and have an address
1737 which the user would want to see? If we have debugging
1738 symbols and no line numbers? */
1739 error (_("Line number %d is out of range for \"%s\"."),
1740 sal
.line
, sal
.symtab
->filename
);
1742 sprintf_vma (startpc_str
, start_pc
);
1743 sprintf_vma (endpc_str
, end_pc
- 1);
1744 /* Find within range of stated line. */
1746 sprintf (target_buf
, "QTFrame:range:%s:%s",
1747 startpc_str
, endpc_str
);
1748 /* Find OUTSIDE OF range of CURRENT line. */
1750 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1751 startpc_str
, endpc_str
);
1752 finish_tfind_command (&target_buf
, &target_buf_size
,
1754 do_cleanups (old_chain
);
1757 error (_("Trace can only be run on remote targets."));
1760 /* tfind range command */
1762 trace_find_range_command (char *args
, int from_tty
)
1764 static CORE_ADDR start
, stop
;
1765 char start_str
[40], stop_str
[40];
1768 if (target_is_remote ())
1770 if (args
== 0 || *args
== 0)
1771 { /* XXX FIXME: what should default behavior be? */
1772 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1776 if (0 != (tmp
= strchr (args
, ',')))
1778 *tmp
++ = '\0'; /* terminate start address */
1779 while (isspace ((int) *tmp
))
1781 start
= parse_and_eval_address (args
);
1782 stop
= parse_and_eval_address (tmp
);
1785 { /* no explicit end address? */
1786 start
= parse_and_eval_address (args
);
1787 stop
= start
+ 1; /* ??? */
1790 sprintf_vma (start_str
, start
);
1791 sprintf_vma (stop_str
, stop
);
1792 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1793 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1796 error (_("Trace can only be run on remote targets."));
1799 /* tfind outside command */
1801 trace_find_outside_command (char *args
, int from_tty
)
1803 CORE_ADDR start
, stop
;
1804 char start_str
[40], stop_str
[40];
1807 if (target_is_remote ())
1809 if (args
== 0 || *args
== 0)
1810 { /* XXX FIXME: what should default behavior be? */
1811 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1815 if (0 != (tmp
= strchr (args
, ',')))
1817 *tmp
++ = '\0'; /* terminate start address */
1818 while (isspace ((int) *tmp
))
1820 start
= parse_and_eval_address (args
);
1821 stop
= parse_and_eval_address (tmp
);
1824 { /* no explicit end address? */
1825 start
= parse_and_eval_address (args
);
1826 stop
= start
+ 1; /* ??? */
1829 sprintf_vma (start_str
, start
);
1830 sprintf_vma (stop_str
, stop
);
1831 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1832 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1835 error (_("Trace can only be run on remote targets."));
1838 /* info scope command: list the locals for a scope. */
1840 scope_info (char *args
, int from_tty
)
1842 struct symtabs_and_lines sals
;
1844 struct minimal_symbol
*msym
;
1845 struct block
*block
;
1846 char **canonical
, *symname
, *save_args
= args
;
1847 struct dict_iterator iter
;
1849 struct gdbarch
*gdbarch
;
1852 if (args
== 0 || *args
== 0)
1853 error (_("requires an argument (function, line or *addr) to define a scope"));
1855 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1856 if (sals
.nelts
== 0)
1857 return; /* presumably decode_line_1 has already warned */
1859 /* Resolve line numbers to PC */
1860 resolve_sal_pc (&sals
.sals
[0]);
1861 block
= block_for_pc (sals
.sals
[0].pc
);
1865 QUIT
; /* allow user to bail out with ^C */
1866 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1868 QUIT
; /* allow user to bail out with ^C */
1870 printf_filtered ("Scope for %s:\n", save_args
);
1873 symname
= SYMBOL_PRINT_NAME (sym
);
1874 if (symname
== NULL
|| *symname
== '\0')
1875 continue; /* probably botched, certainly useless */
1877 gdbarch
= get_objfile_arch (SYMBOL_SYMTAB (sym
)->objfile
);
1879 printf_filtered ("Symbol %s is ", symname
);
1880 switch (SYMBOL_CLASS (sym
))
1883 case LOC_UNDEF
: /* messed up symbol? */
1884 printf_filtered ("a bogus symbol, class %d.\n",
1885 SYMBOL_CLASS (sym
));
1886 count
--; /* don't count this one */
1889 printf_filtered ("a constant with value %ld (0x%lx)",
1890 SYMBOL_VALUE (sym
), SYMBOL_VALUE (sym
));
1892 case LOC_CONST_BYTES
:
1893 printf_filtered ("constant bytes: ");
1894 if (SYMBOL_TYPE (sym
))
1895 for (j
= 0; j
< TYPE_LENGTH (SYMBOL_TYPE (sym
)); j
++)
1896 fprintf_filtered (gdb_stdout
, " %02x",
1897 (unsigned) SYMBOL_VALUE_BYTES (sym
)[j
]);
1900 printf_filtered ("in static storage at address ");
1901 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1904 /* GDBARCH is the architecture associated with the objfile
1905 the symbol is defined in; the target architecture may be
1906 different, and may provide additional registers. However,
1907 we do not know the target architecture at this point.
1908 We assume the objfile architecture will contain all the
1909 standard registers that occur in debug info in that
1911 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1913 if (SYMBOL_IS_ARGUMENT (sym
))
1914 printf_filtered ("an argument in register $%s",
1915 gdbarch_register_name (gdbarch
, regno
));
1917 printf_filtered ("a local variable in register $%s",
1918 gdbarch_register_name (gdbarch
, regno
));
1921 printf_filtered ("an argument at stack/frame offset %ld",
1922 SYMBOL_VALUE (sym
));
1925 printf_filtered ("a local variable at frame offset %ld",
1926 SYMBOL_VALUE (sym
));
1929 printf_filtered ("a reference argument at offset %ld",
1930 SYMBOL_VALUE (sym
));
1932 case LOC_REGPARM_ADDR
:
1933 /* Note comment at LOC_REGISTER. */
1934 regno
= SYMBOL_REGISTER_OPS (sym
)->register_number (sym
, gdbarch
);
1935 printf_filtered ("the address of an argument, in register $%s",
1936 gdbarch_register_name (gdbarch
, regno
));
1939 printf_filtered ("a typedef.\n");
1942 printf_filtered ("a label at address ");
1943 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1946 printf_filtered ("a function at address ");
1947 printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
1949 case LOC_UNRESOLVED
:
1950 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1953 printf_filtered ("Unresolved Static");
1956 printf_filtered ("static storage at address ");
1957 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym
)));
1960 case LOC_OPTIMIZED_OUT
:
1961 printf_filtered ("optimized out.\n");
1964 SYMBOL_COMPUTED_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1967 if (SYMBOL_TYPE (sym
))
1968 printf_filtered (", length %d.\n",
1969 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
1971 if (BLOCK_FUNCTION (block
))
1974 block
= BLOCK_SUPERBLOCK (block
);
1977 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1981 /* worker function (cleanup) */
1983 replace_comma (void *data
)
1991 trace_dump_command (char *args
, int from_tty
)
1993 struct regcache
*regcache
;
1994 struct gdbarch
*gdbarch
;
1995 struct breakpoint
*t
;
1996 struct action_line
*action
;
1997 char *action_exp
, *next_comma
;
1998 struct cleanup
*old_cleanups
;
1999 int stepping_actions
= 0;
2000 int stepping_frame
= 0;
2002 if (!target_is_remote ())
2004 error (_("Trace can only be run on remote targets."));
2008 if (tracepoint_number
== -1)
2010 warning (_("No current trace frame."));
2014 t
= get_tracepoint (tracepoint_number
);
2017 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2020 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2022 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2023 tracepoint_number
, traceframe_number
);
2025 /* The current frame is a trap frame if the frame PC is equal
2026 to the tracepoint PC. If not, then the current frame was
2027 collected during single-stepping. */
2029 regcache
= get_current_regcache ();
2030 gdbarch
= get_regcache_arch (regcache
);
2032 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2033 - gdbarch_decr_pc_after_break (gdbarch
)));
2035 for (action
= t
->actions
; action
; action
= action
->next
)
2037 struct cmd_list_element
*cmd
;
2039 QUIT
; /* allow user to bail out with ^C */
2040 action_exp
= action
->action
;
2041 while (isspace ((int) *action_exp
))
2044 /* The collection actions to be done while stepping are
2045 bracketed by the commands "while-stepping" and "end". */
2047 if (*action_exp
== '#') /* comment line */
2050 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2052 error (_("Bad action list item: %s"), action_exp
);
2054 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2055 stepping_actions
= 1;
2056 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2057 stepping_actions
= 0;
2058 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2060 /* Display the collected data.
2061 For the trap frame, display only what was collected at
2062 the trap. Likewise for stepping frames, display only
2063 what was collected while stepping. This means that the
2064 two boolean variables, STEPPING_FRAME and
2065 STEPPING_ACTIONS should be equal. */
2066 if (stepping_frame
== stepping_actions
)
2069 { /* repeat over a comma-separated list */
2070 QUIT
; /* allow user to bail out with ^C */
2071 if (*action_exp
== ',')
2073 while (isspace ((int) *action_exp
))
2076 next_comma
= strchr (action_exp
, ',');
2078 if (0 == strncasecmp (action_exp
, "$reg", 4))
2079 registers_info (NULL
, from_tty
);
2080 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2081 locals_info (NULL
, from_tty
);
2082 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2083 args_info (NULL
, from_tty
);
2088 make_cleanup (replace_comma
, next_comma
);
2091 printf_filtered ("%s = ", action_exp
);
2092 output_command (action_exp
, from_tty
);
2093 printf_filtered ("\n");
2097 action_exp
= next_comma
;
2099 while (action_exp
&& *action_exp
== ',');
2103 discard_cleanups (old_cleanups
);
2106 /* Convert the memory pointed to by mem into hex, placing result in buf.
2107 * Return a pointer to the last char put in buf (null)
2108 * "stolen" from sparc-stub.c
2111 static const char hexchars
[] = "0123456789abcdef";
2114 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2122 *buf
++ = hexchars
[ch
>> 4];
2123 *buf
++ = hexchars
[ch
& 0xf];
2132 get_traceframe_number (void)
2134 return traceframe_number
;
2138 /* module initialization */
2140 _initialize_tracepoint (void)
2142 struct cmd_list_element
*c
;
2144 traceframe_number
= -1;
2145 tracepoint_number
= -1;
2147 if (tracepoint_list
.list
== NULL
)
2149 tracepoint_list
.listsize
= 128;
2150 tracepoint_list
.list
= xmalloc
2151 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2153 if (tracepoint_list
.aexpr_list
== NULL
)
2155 tracepoint_list
.aexpr_listsize
= 128;
2156 tracepoint_list
.aexpr_list
= xmalloc
2157 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2160 if (stepping_list
.list
== NULL
)
2162 stepping_list
.listsize
= 128;
2163 stepping_list
.list
= xmalloc
2164 (stepping_list
.listsize
* sizeof (struct memrange
));
2167 if (stepping_list
.aexpr_list
== NULL
)
2169 stepping_list
.aexpr_listsize
= 128;
2170 stepping_list
.aexpr_list
= xmalloc
2171 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2174 add_info ("scope", scope_info
,
2175 _("List the variables local to a scope"));
2177 add_cmd ("tracepoints", class_trace
, NULL
,
2178 _("Tracing of program execution without stopping the program."),
2181 add_com ("tdump", class_trace
, trace_dump_command
,
2182 _("Print everything collected at the current tracepoint."));
2184 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2185 Select a trace frame;\n\
2186 No argument means forward by one frame; '-' means backward by one frame."),
2187 &tfindlist
, "tfind ", 1, &cmdlist
);
2189 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2190 Select a trace frame whose PC is outside the given range.\n\
2191 Usage: tfind outside addr1, addr2"),
2194 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2195 Select a trace frame whose PC is in the given range.\n\
2196 Usage: tfind range addr1,addr2"),
2199 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2200 Select a trace frame by source line.\n\
2201 Argument can be a line number (with optional source file), \n\
2202 a function name, or '*' followed by an address.\n\
2203 Default argument is 'the next source line that was traced'."),
2206 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2207 Select a trace frame by tracepoint number.\n\
2208 Default is the tracepoint for the current trace frame."),
2211 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2212 Select a trace frame by PC.\n\
2213 Default is the current PC, or the PC of the current trace frame."),
2216 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2217 Synonym for 'none'.\n\
2218 De-select any trace frame and resume 'live' debugging."),
2221 add_cmd ("none", class_trace
, trace_find_none_command
,
2222 _("De-select any trace frame and resume 'live' debugging."),
2225 add_cmd ("start", class_trace
, trace_find_start_command
,
2226 _("Select the first trace frame in the trace buffer."),
2229 add_com ("tstatus", class_trace
, trace_status_command
,
2230 _("Display the status of the current trace data collection."));
2232 add_com ("tstop", class_trace
, trace_stop_command
,
2233 _("Stop trace data collection."));
2235 add_com ("tstart", class_trace
, trace_start_command
,
2236 _("Start trace data collection."));
2238 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2239 Ends a list of commands or actions.\n\
2240 Several GDB commands allow you to enter a list of commands or actions.\n\
2241 Entering \"end\" on a line by itself is the normal way to terminate\n\
2243 Note: the \"end\" command cannot be used at the gdb prompt."));
2245 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2246 Specify single-stepping behavior at a tracepoint.\n\
2247 Argument is number of instructions to trace in single-step mode\n\
2248 following the tracepoint. This command is normally followed by\n\
2249 one or more \"collect\" commands, to specify what to collect\n\
2250 while single-stepping.\n\n\
2251 Note: this command can only be used in a tracepoint \"actions\" list."));
2253 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2254 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2256 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2257 Specify one or more data items to be collected at a tracepoint.\n\
2258 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2259 collect all data (variables, registers) referenced by that expression.\n\
2260 Also accepts the following special arguments:\n\
2261 $regs -- all registers.\n\
2262 $args -- all function arguments.\n\
2263 $locals -- all variables local to the block/function scope.\n\
2264 Note: this command can only be used in a tracepoint \"actions\" list."));
2266 add_com ("actions", class_trace
, trace_actions_command
, _("\
2267 Specify the actions to be taken at a tracepoint.\n\
2268 Tracepoint actions may include collecting of specified data, \n\
2269 single-stepping, or enabling/disabling other tracepoints, \n\
2270 depending on target's capabilities."));
2272 target_buf_size
= 2048;
2273 target_buf
= xmalloc (target_buf_size
);