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"
47 /* readline include files */
48 #include "readline/readline.h"
49 #include "readline/history.h"
51 /* readline defines this. */
58 /* Maximum length of an agent aexpression.
59 This accounts for the fact that packets are limited to 400 bytes
60 (which includes everything -- including the checksum), and assumes
61 the worst case of maximum length for each of the pieces of a
64 NOTE: expressions get mem2hex'ed otherwise this would be twice as
65 large. (400 - 31)/2 == 184 */
66 #define MAX_AGENT_EXPR_LEN 184
69 extern void (*deprecated_readline_begin_hook
) (char *, ...);
70 extern char *(*deprecated_readline_hook
) (char *);
71 extern void (*deprecated_readline_end_hook
) (void);
73 /* GDB commands implemented in other modules:
76 extern void output_command (char *, int);
81 This module defines the following debugger commands:
82 trace : set a tracepoint on a function, line, or address.
83 info trace : list all debugger-defined tracepoints.
84 delete trace : delete one or more tracepoints.
85 enable trace : enable one or more tracepoints.
86 disable trace : disable one or more tracepoints.
87 actions : specify actions to be taken at a tracepoint.
88 passcount : specify a pass count for a tracepoint.
89 tstart : start a trace experiment.
90 tstop : stop a trace experiment.
91 tstatus : query the status of a trace experiment.
92 tfind : find a trace frame in the trace buffer.
93 tdump : print everything collected at the current tracepoint.
94 save-tracepoints : write tracepoint setup into a file.
96 This module defines the following user-visible debugger variables:
97 $trace_frame : sequence number of trace frame currently being debugged.
98 $trace_line : source line of trace frame currently being debugged.
99 $trace_file : source file of trace frame currently being debugged.
100 $tracepoint : tracepoint number of trace frame currently being debugged.
104 /* ======= Important global variables: ======= */
106 /* Number of last traceframe collected. */
107 static int traceframe_number
;
109 /* Tracepoint for last traceframe collected. */
110 static int tracepoint_number
;
112 /* Symbol for function for last traceframe collected */
113 static struct symbol
*traceframe_fun
;
115 /* Symtab and line for last traceframe collected */
116 static struct symtab_and_line traceframe_sal
;
118 /* Tracing command lists */
119 static struct cmd_list_element
*tfindlist
;
121 /* ======= Important command functions: ======= */
122 static void trace_actions_command (char *, int);
123 static void trace_start_command (char *, int);
124 static void trace_stop_command (char *, int);
125 static void trace_status_command (char *, int);
126 static void trace_find_command (char *, int);
127 static void trace_find_pc_command (char *, int);
128 static void trace_find_tracepoint_command (char *, int);
129 static void trace_find_line_command (char *, int);
130 static void trace_find_range_command (char *, int);
131 static void trace_find_outside_command (char *, int);
132 static void tracepoint_save_command (char *, int);
133 static void trace_dump_command (char *, int);
135 /* support routines */
137 struct collection_list
;
138 static void add_aexpr (struct collection_list
*, struct agent_expr
*);
139 static char *mem2hex (gdb_byte
*, char *, int);
140 static void add_register (struct collection_list
*collection
,
142 static struct cleanup
*make_cleanup_free_actions (struct breakpoint
*t
);
143 static void free_actions_list (char **actions_list
);
144 static void free_actions_list_cleanup_wrapper (void *);
146 extern void _initialize_tracepoint (void);
148 /* Utility: returns true if "target remote" */
150 target_is_remote (void)
152 if (current_target
.to_shortname
&&
153 (strcmp (current_target
.to_shortname
, "remote") == 0
154 || strcmp (current_target
.to_shortname
, "extended-remote") == 0))
160 /* Utility: generate error from an incoming stub packet. */
162 trace_error (char *buf
)
165 return; /* not an error msg */
168 case '1': /* malformed packet error */
169 if (*++buf
== '0') /* general case: */
170 error (_("tracepoint.c: error in outgoing packet."));
172 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
173 strtol (buf
, NULL
, 16));
175 error (_("trace API error 0x%s."), ++buf
);
177 error (_("Target returns error code '%s'."), buf
);
181 /* Utility: wait for reply from stub, while accepting "O" packets. */
183 remote_get_noisy_reply (char **buf_p
,
186 do /* Loop on reply from remote stub. */
189 QUIT
; /* allow user to bail out with ^C */
190 getpkt (buf_p
, sizeof_buf
, 0);
193 error (_("Target does not support this command."));
194 else if (buf
[0] == 'E')
196 else if (buf
[0] == 'O' &&
198 remote_console_output (buf
+ 1); /* 'O' message from stub */
200 return buf
; /* here's the actual reply */
205 /* Set traceframe number to NUM. */
207 set_traceframe_num (int num
)
209 traceframe_number
= num
;
210 set_internalvar (lookup_internalvar ("trace_frame"),
211 value_from_longest (builtin_type_int32
, (LONGEST
) num
));
214 /* Set tracepoint number to NUM. */
216 set_tracepoint_num (int num
)
218 tracepoint_number
= num
;
219 set_internalvar (lookup_internalvar ("tracepoint"),
220 value_from_longest (builtin_type_int32
, (LONGEST
) 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 set_internalvar (lookup_internalvar ("trace_func"),
243 allocate_value (builtin_type_void
));
244 set_internalvar (lookup_internalvar ("trace_file"),
245 allocate_value (builtin_type_void
));
246 set_internalvar (lookup_internalvar ("trace_line"),
247 value_from_longest (builtin_type_int32
,
252 /* Save as globals for internal use. */
253 trace_pc
= get_frame_pc (trace_frame
);
254 traceframe_sal
= find_pc_line (trace_pc
, 0);
255 traceframe_fun
= find_pc_function (trace_pc
);
257 /* Save linenumber as "$trace_line", a debugger variable visible to
259 set_internalvar (lookup_internalvar ("trace_line"),
260 value_from_longest (builtin_type_int32
,
261 (LONGEST
) traceframe_sal
.line
));
263 /* Save func name as "$trace_func", a debugger variable visible to
265 if (traceframe_fun
== NULL
||
266 SYMBOL_LINKAGE_NAME (traceframe_fun
) == NULL
)
267 set_internalvar (lookup_internalvar ("trace_func"),
268 allocate_value (builtin_type_void
));
271 len
= strlen (SYMBOL_LINKAGE_NAME (traceframe_fun
));
272 func_range
= create_range_type (func_range
,
273 builtin_type_int32
, 0, len
- 1);
274 func_string
= create_array_type (func_string
,
275 builtin_type_true_char
, func_range
);
276 func_val
= allocate_value (func_string
);
277 deprecated_set_value_type (func_val
, func_string
);
278 memcpy (value_contents_raw (func_val
),
279 SYMBOL_LINKAGE_NAME (traceframe_fun
),
281 deprecated_set_value_modifiable (func_val
, 0);
282 set_internalvar (lookup_internalvar ("trace_func"), func_val
);
285 /* Save file name as "$trace_file", a debugger variable visible to
287 if (traceframe_sal
.symtab
== NULL
||
288 traceframe_sal
.symtab
->filename
== NULL
)
289 set_internalvar (lookup_internalvar ("trace_file"),
290 allocate_value (builtin_type_void
));
293 len
= strlen (traceframe_sal
.symtab
->filename
);
294 file_range
= create_range_type (file_range
,
295 builtin_type_int32
, 0, len
- 1);
296 file_string
= create_array_type (file_string
,
297 builtin_type_true_char
, file_range
);
298 file_val
= allocate_value (file_string
);
299 deprecated_set_value_type (file_val
, file_string
);
300 memcpy (value_contents_raw (file_val
),
301 traceframe_sal
.symtab
->filename
,
303 deprecated_set_value_modifiable (file_val
, 0);
304 set_internalvar (lookup_internalvar ("trace_file"), file_val
);
308 /* ACTIONS functions: */
310 /* Prototypes for action-parsing utility commands */
311 static void read_actions (struct breakpoint
*);
313 /* The three functions:
314 collect_pseudocommand,
315 while_stepping_pseudocommand, and
316 end_actions_pseudocommand
317 are placeholders for "commands" that are actually ONLY to be used
318 within a tracepoint action list. If the actual function is ever called,
319 it means that somebody issued the "command" at the top level,
320 which is always an error. */
323 end_actions_pseudocommand (char *args
, int from_tty
)
325 error (_("This command cannot be used at the top level."));
329 while_stepping_pseudocommand (char *args
, int from_tty
)
331 error (_("This command can only be used in a tracepoint actions list."));
335 collect_pseudocommand (char *args
, int from_tty
)
337 error (_("This command can only be used in a tracepoint actions list."));
340 /* Enter a list of actions for a tracepoint. */
342 trace_actions_command (char *args
, int from_tty
)
344 struct breakpoint
*t
;
346 char *end_msg
= "End with a line saying just \"end\".";
348 t
= get_tracepoint_by_number (&args
, 0, 1);
351 sprintf (tmpbuf
, "Enter actions for tracepoint %d, one per line.",
356 if (deprecated_readline_begin_hook
)
357 (*deprecated_readline_begin_hook
) ("%s %s\n", tmpbuf
, end_msg
);
358 else if (input_from_terminal_p ())
359 printf_filtered ("%s\n%s\n", tmpbuf
, end_msg
);
363 t
->step_count
= 0; /* read_actions may set this */
366 if (deprecated_readline_end_hook
)
367 (*deprecated_readline_end_hook
) ();
368 /* tracepoints_changed () */
370 /* else just return */
373 /* worker function */
375 read_actions (struct breakpoint
*t
)
378 char *prompt1
= "> ", *prompt2
= " > ";
379 char *prompt
= prompt1
;
380 enum actionline_type linetype
;
381 extern FILE *instream
;
382 struct action_line
*next
= NULL
, *temp
;
383 struct cleanup
*old_chain
;
385 /* Control-C quits instantly if typed while in this loop
386 since it should not wait until the user types a newline. */
388 /* FIXME: kettenis/20010823: Something is wrong here. In this file
389 STOP_SIGNAL is never defined. So this code has been left out, at
390 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
391 leads to compilation failures since the variable job_control
392 isn't declared. Leave this alone for now. */
395 signal (STOP_SIGNAL
, handle_stop_sig
);
397 old_chain
= make_cleanup_free_actions (t
);
400 /* Make sure that all output has been output. Some machines may
401 let you get away with leaving out some of the gdb_flush, but
404 gdb_flush (gdb_stdout
);
405 gdb_flush (gdb_stderr
);
407 if (deprecated_readline_hook
&& instream
== NULL
)
408 line
= (*deprecated_readline_hook
) (prompt
);
409 else if (instream
== stdin
&& ISATTY (instream
))
411 line
= gdb_readline_wrapper (prompt
);
412 if (line
&& *line
) /* add it to command history */
416 line
= gdb_readline (0);
420 line
= xstrdup ("end");
421 printf_filtered ("end\n");
424 linetype
= validate_actionline (&line
, t
);
425 if (linetype
== BADLINE
)
426 continue; /* already warned -- collect another line */
428 temp
= xmalloc (sizeof (struct action_line
));
432 if (next
== NULL
) /* first action for this tracepoint? */
433 t
->actions
= next
= temp
;
440 if (linetype
== STEPPING
) /* begin "while-stepping" */
442 if (prompt
== prompt2
)
444 warning (_("Already processing 'while-stepping'"));
448 prompt
= prompt2
; /* change prompt for stepping actions */
450 else if (linetype
== END
)
452 if (prompt
== prompt2
)
454 prompt
= prompt1
; /* end of single-stepping actions */
457 { /* end of actions */
458 if (t
->actions
->next
== NULL
)
460 /* An "end" all by itself with no other actions
461 means this tracepoint has no actions.
462 Discard empty list. */
471 signal (STOP_SIGNAL
, SIG_DFL
);
474 discard_cleanups (old_chain
);
477 /* worker function */
479 validate_actionline (char **line
, struct breakpoint
*t
)
481 struct cmd_list_element
*c
;
482 struct expression
*exp
= NULL
;
483 struct cleanup
*old_chain
= NULL
;
486 /* if EOF is typed, *line is NULL */
490 for (p
= *line
; isspace ((int) *p
);)
493 /* Symbol lookup etc. */
494 if (*p
== '\0') /* empty line: just prompt for another line. */
497 if (*p
== '#') /* comment line */
500 c
= lookup_cmd (&p
, cmdlist
, "", -1, 1);
503 warning (_("'%s' is not an action that I know, or is ambiguous."),
508 if (cmd_cfunc_eq (c
, collect_pseudocommand
))
510 struct agent_expr
*aexpr
;
511 struct agent_reqs areqs
;
514 { /* repeat over a comma-separated list */
515 QUIT
; /* allow user to bail out with ^C */
516 while (isspace ((int) *p
))
519 if (*p
== '$') /* look for special pseudo-symbols */
521 if ((0 == strncasecmp ("reg", p
+ 1, 3)) ||
522 (0 == strncasecmp ("arg", p
+ 1, 3)) ||
523 (0 == strncasecmp ("loc", p
+ 1, 3)))
528 /* else fall thru, treat p as an expression and parse it! */
530 exp
= parse_exp_1 (&p
, block_for_pc (t
->loc
->address
), 1);
531 old_chain
= make_cleanup (free_current_contents
, &exp
);
533 if (exp
->elts
[0].opcode
== OP_VAR_VALUE
)
535 if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_CONST
)
537 warning (_("constant %s (value %ld) will not be collected."),
538 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
),
539 SYMBOL_VALUE (exp
->elts
[2].symbol
));
542 else if (SYMBOL_CLASS (exp
->elts
[2].symbol
) == LOC_OPTIMIZED_OUT
)
544 warning (_("%s is optimized away and cannot be collected."),
545 SYMBOL_PRINT_NAME (exp
->elts
[2].symbol
));
550 /* We have something to collect, make sure that the expr to
551 bytecode translator can handle it and that it's not too
553 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
554 make_cleanup_free_agent_expr (aexpr
);
556 if (aexpr
->len
> MAX_AGENT_EXPR_LEN
)
557 error (_("expression too complicated, try simplifying"));
559 ax_reqs (aexpr
, &areqs
);
560 (void) make_cleanup (xfree
, areqs
.reg_mask
);
562 if (areqs
.flaw
!= agent_flaw_none
)
563 error (_("malformed expression"));
565 if (areqs
.min_height
< 0)
566 error (_("gdb: Internal error: expression has min height < 0"));
568 if (areqs
.max_height
> 20)
569 error (_("expression too complicated, try simplifying"));
571 do_cleanups (old_chain
);
573 while (p
&& *p
++ == ',');
576 else if (cmd_cfunc_eq (c
, while_stepping_pseudocommand
))
578 char *steparg
; /* in case warning is necessary */
580 while (isspace ((int) *p
))
585 (t
->step_count
= strtol (p
, &p
, 0)) == 0)
587 warning (_("'%s': bad step-count; command ignored."), *line
);
592 else if (cmd_cfunc_eq (c
, end_actions_pseudocommand
))
596 warning (_("'%s' is not a supported tracepoint action."), *line
);
601 /* worker function */
603 free_actions (struct breakpoint
*t
)
605 struct action_line
*line
, *next
;
607 for (line
= t
->actions
; line
; line
= next
)
611 xfree (line
->action
);
618 do_free_actions_cleanup (void *t
)
623 static struct cleanup
*
624 make_cleanup_free_actions (struct breakpoint
*t
)
626 return make_cleanup (do_free_actions_cleanup
, t
);
630 memrange_absolute
= -1
635 int type
; /* memrange_absolute for absolute memory range,
636 else basereg number */
637 bfd_signed_vma start
;
641 struct collection_list
643 unsigned char regs_mask
[32]; /* room for up to 256 regs */
646 struct memrange
*list
;
647 long aexpr_listsize
; /* size of array pointed to by expr_list elt */
649 struct agent_expr
**aexpr_list
;
652 tracepoint_list
, stepping_list
;
654 /* MEMRANGE functions: */
656 static int memrange_cmp (const void *, const void *);
658 /* compare memranges for qsort */
660 memrange_cmp (const void *va
, const void *vb
)
662 const struct memrange
*a
= va
, *b
= vb
;
664 if (a
->type
< b
->type
)
666 if (a
->type
> b
->type
)
668 if (a
->type
== memrange_absolute
)
670 if ((bfd_vma
) a
->start
< (bfd_vma
) b
->start
)
672 if ((bfd_vma
) a
->start
> (bfd_vma
) b
->start
)
677 if (a
->start
< b
->start
)
679 if (a
->start
> b
->start
)
685 /* Sort the memrange list using qsort, and merge adjacent memranges. */
687 memrange_sortmerge (struct collection_list
*memranges
)
691 qsort (memranges
->list
, memranges
->next_memrange
,
692 sizeof (struct memrange
), memrange_cmp
);
693 if (memranges
->next_memrange
> 0)
695 for (a
= 0, b
= 1; b
< memranges
->next_memrange
; b
++)
697 if (memranges
->list
[a
].type
== memranges
->list
[b
].type
&&
698 memranges
->list
[b
].start
- memranges
->list
[a
].end
<=
701 /* memrange b starts before memrange a ends; merge them. */
702 if (memranges
->list
[b
].end
> memranges
->list
[a
].end
)
703 memranges
->list
[a
].end
= memranges
->list
[b
].end
;
704 continue; /* next b, same a */
708 memcpy (&memranges
->list
[a
], &memranges
->list
[b
],
709 sizeof (struct memrange
));
711 memranges
->next_memrange
= a
+ 1;
715 /* Add a register to a collection list. */
717 add_register (struct collection_list
*collection
, unsigned int regno
)
720 printf_filtered ("collect register %d\n", regno
);
721 if (regno
>= (8 * sizeof (collection
->regs_mask
)))
722 error (_("Internal: register number %d too large for tracepoint"),
724 collection
->regs_mask
[regno
/ 8] |= 1 << (regno
% 8);
727 /* Add a memrange to a collection list */
729 add_memrange (struct collection_list
*memranges
,
730 int type
, bfd_signed_vma base
,
735 printf_filtered ("(%d,", type
);
737 printf_filtered (",%ld)\n", len
);
740 /* type: memrange_absolute == memory, other n == basereg */
741 memranges
->list
[memranges
->next_memrange
].type
= type
;
742 /* base: addr if memory, offset if reg relative. */
743 memranges
->list
[memranges
->next_memrange
].start
= base
;
744 /* len: we actually save end (base + len) for convenience */
745 memranges
->list
[memranges
->next_memrange
].end
= base
+ len
;
746 memranges
->next_memrange
++;
747 if (memranges
->next_memrange
>= memranges
->listsize
)
749 memranges
->listsize
*= 2;
750 memranges
->list
= xrealloc (memranges
->list
,
751 memranges
->listsize
);
754 if (type
!= memrange_absolute
) /* Better collect the base register! */
755 add_register (memranges
, type
);
758 /* Add a symbol to a collection list. */
760 collect_symbol (struct collection_list
*collect
,
762 long frame_regno
, long frame_offset
)
766 bfd_signed_vma offset
;
768 len
= TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
)));
769 switch (SYMBOL_CLASS (sym
))
772 printf_filtered ("%s: don't know symbol class %d\n",
773 SYMBOL_PRINT_NAME (sym
),
777 printf_filtered ("constant %s (value %ld) will not be collected.\n",
778 SYMBOL_PRINT_NAME (sym
), SYMBOL_VALUE (sym
));
781 offset
= SYMBOL_VALUE_ADDRESS (sym
);
786 sprintf_vma (tmp
, offset
);
787 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
788 SYMBOL_PRINT_NAME (sym
), len
,
791 add_memrange (collect
, memrange_absolute
, offset
, len
);
794 reg
= SYMBOL_VALUE (sym
);
796 printf_filtered ("LOC_REG[parm] %s: ",
797 SYMBOL_PRINT_NAME (sym
));
798 add_register (collect
, reg
);
799 /* Check for doubles stored in two registers. */
800 /* FIXME: how about larger types stored in 3 or more regs? */
801 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FLT
&&
802 len
> register_size (current_gdbarch
, reg
))
803 add_register (collect
, reg
+ 1);
806 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
807 printf_filtered (" (will not collect %s)\n",
808 SYMBOL_PRINT_NAME (sym
));
812 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
815 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
816 SYMBOL_PRINT_NAME (sym
), len
);
818 printf_filtered (" from frame ptr reg %d\n", reg
);
820 add_memrange (collect
, reg
, offset
, len
);
822 case LOC_REGPARM_ADDR
:
823 reg
= SYMBOL_VALUE (sym
);
827 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
828 SYMBOL_PRINT_NAME (sym
), len
);
830 printf_filtered (" from reg %d\n", reg
);
832 add_memrange (collect
, reg
, offset
, len
);
836 offset
= frame_offset
+ SYMBOL_VALUE (sym
);
839 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
840 SYMBOL_PRINT_NAME (sym
), len
);
842 printf_filtered (" from frame ptr reg %d\n", reg
);
844 add_memrange (collect
, reg
, offset
, len
);
847 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
848 SYMBOL_PRINT_NAME (sym
));
850 case LOC_OPTIMIZED_OUT
:
851 printf_filtered ("%s has been optimized out of existence.\n",
852 SYMBOL_PRINT_NAME (sym
));
857 /* Add all locals (or args) symbols to collection list */
859 add_local_symbols (struct collection_list
*collect
, CORE_ADDR pc
,
860 long frame_regno
, long frame_offset
, int type
)
864 struct dict_iterator iter
;
867 block
= block_for_pc (pc
);
870 QUIT
; /* allow user to bail out with ^C */
871 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
873 if (SYMBOL_IS_ARGUMENT (sym
)
874 ? type
== 'A' /* collecting Arguments */
875 : type
== 'L') /* collecting Locals */
878 collect_symbol (collect
, sym
, frame_regno
,
882 if (BLOCK_FUNCTION (block
))
885 block
= BLOCK_SUPERBLOCK (block
);
888 warning (_("No %s found in scope."),
889 type
== 'L' ? "locals" : "args");
892 /* worker function */
894 clear_collection_list (struct collection_list
*list
)
898 list
->next_memrange
= 0;
899 for (ndx
= 0; ndx
< list
->next_aexpr_elt
; ndx
++)
901 free_agent_expr (list
->aexpr_list
[ndx
]);
902 list
->aexpr_list
[ndx
] = NULL
;
904 list
->next_aexpr_elt
= 0;
905 memset (list
->regs_mask
, 0, sizeof (list
->regs_mask
));
908 /* reduce a collection list to string form (for gdb protocol) */
910 stringify_collection_list (struct collection_list
*list
, char *string
)
920 count
= 1 + list
->next_memrange
+ list
->next_aexpr_elt
+ 1;
921 str_list
= (char *(*)[]) xmalloc (count
* sizeof (char *));
923 for (i
= sizeof (list
->regs_mask
) - 1; i
> 0; i
--)
924 if (list
->regs_mask
[i
] != 0) /* skip leading zeroes in regs_mask */
926 if (list
->regs_mask
[i
] != 0) /* prepare to send regs_mask to the stub */
929 printf_filtered ("\nCollecting registers (mask): 0x");
934 QUIT
; /* allow user to bail out with ^C */
936 printf_filtered ("%02X", list
->regs_mask
[i
]);
937 sprintf (end
, "%02X", list
->regs_mask
[i
]);
940 (*str_list
)[ndx
] = savestring (temp_buf
, end
- temp_buf
);
944 printf_filtered ("\n");
945 if (list
->next_memrange
> 0 && info_verbose
)
946 printf_filtered ("Collecting memranges: \n");
947 for (i
= 0, count
= 0, end
= temp_buf
; i
< list
->next_memrange
; i
++)
949 QUIT
; /* allow user to bail out with ^C */
950 sprintf_vma (tmp2
, list
->list
[i
].start
);
953 printf_filtered ("(%d, %s, %ld)\n",
956 (long) (list
->list
[i
].end
- list
->list
[i
].start
));
958 if (count
+ 27 > MAX_AGENT_EXPR_LEN
)
960 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
967 bfd_signed_vma length
= list
->list
[i
].end
- list
->list
[i
].start
;
969 /* The "%X" conversion specifier expects an unsigned argument,
970 so passing -1 (memrange_absolute) to it directly gives you
971 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
973 if (list
->list
[i
].type
== memrange_absolute
)
974 sprintf (end
, "M-1,%s,%lX", tmp2
, (long) length
);
976 sprintf (end
, "M%X,%s,%lX", list
->list
[i
].type
, tmp2
, (long) length
);
979 count
+= strlen (end
);
980 end
= temp_buf
+ count
;
983 for (i
= 0; i
< list
->next_aexpr_elt
; i
++)
985 QUIT
; /* allow user to bail out with ^C */
986 if ((count
+ 10 + 2 * list
->aexpr_list
[i
]->len
) > MAX_AGENT_EXPR_LEN
)
988 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
993 sprintf (end
, "X%08X,", list
->aexpr_list
[i
]->len
);
994 end
+= 10; /* 'X' + 8 hex digits + ',' */
997 end
= mem2hex (list
->aexpr_list
[i
]->buf
,
998 end
, list
->aexpr_list
[i
]->len
);
999 count
+= 2 * list
->aexpr_list
[i
]->len
;
1004 (*str_list
)[ndx
] = savestring (temp_buf
, count
);
1009 (*str_list
)[ndx
] = NULL
;
1021 free_actions_list_cleanup_wrapper (void *al
)
1023 free_actions_list (al
);
1027 free_actions_list (char **actions_list
)
1031 if (actions_list
== 0)
1034 for (ndx
= 0; actions_list
[ndx
]; ndx
++)
1035 xfree (actions_list
[ndx
]);
1037 xfree (actions_list
);
1040 /* Render all actions into gdb protocol. */
1042 encode_actions (struct breakpoint
*t
, char ***tdp_actions
,
1043 char ***stepping_actions
)
1045 static char tdp_buff
[2048], step_buff
[2048];
1047 struct expression
*exp
= NULL
;
1048 struct action_line
*action
;
1050 struct value
*tempval
;
1051 struct collection_list
*collect
;
1052 struct cmd_list_element
*cmd
;
1053 struct agent_expr
*aexpr
;
1055 LONGEST frame_offset
;
1058 clear_collection_list (&tracepoint_list
);
1059 clear_collection_list (&stepping_list
);
1060 collect
= &tracepoint_list
;
1062 *tdp_actions
= NULL
;
1063 *stepping_actions
= NULL
;
1065 gdbarch_virtual_frame_pointer (current_gdbarch
,
1066 t
->loc
->address
, &frame_reg
, &frame_offset
);
1068 for (action
= t
->actions
; action
; action
= action
->next
)
1070 QUIT
; /* allow user to bail out with ^C */
1071 action_exp
= action
->action
;
1072 while (isspace ((int) *action_exp
))
1075 if (*action_exp
== '#') /* comment line */
1078 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
1080 error (_("Bad action list item: %s"), action_exp
);
1082 if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
1085 { /* repeat over a comma-separated list */
1086 QUIT
; /* allow user to bail out with ^C */
1087 while (isspace ((int) *action_exp
))
1090 if (0 == strncasecmp ("$reg", action_exp
, 4))
1092 for (i
= 0; i
< gdbarch_num_regs (current_gdbarch
); i
++)
1093 add_register (collect
, i
);
1094 action_exp
= strchr (action_exp
, ','); /* more? */
1096 else if (0 == strncasecmp ("$arg", action_exp
, 4))
1098 add_local_symbols (collect
,
1103 action_exp
= strchr (action_exp
, ','); /* more? */
1105 else if (0 == strncasecmp ("$loc", action_exp
, 4))
1107 add_local_symbols (collect
,
1112 action_exp
= strchr (action_exp
, ','); /* more? */
1116 unsigned long addr
, len
;
1117 struct cleanup
*old_chain
= NULL
;
1118 struct cleanup
*old_chain1
= NULL
;
1119 struct agent_reqs areqs
;
1121 exp
= parse_exp_1 (&action_exp
,
1122 block_for_pc (t
->loc
->address
), 1);
1123 old_chain
= make_cleanup (free_current_contents
, &exp
);
1125 switch (exp
->elts
[0].opcode
)
1129 const char *name
= &exp
->elts
[2].string
;
1131 i
= user_reg_map_name_to_regnum (current_gdbarch
,
1132 name
, strlen (name
));
1134 internal_error (__FILE__
, __LINE__
,
1135 _("Register $%s not available"),
1138 printf_filtered ("OP_REGISTER: ");
1139 add_register (collect
, i
);
1144 /* safe because we know it's a simple expression */
1145 tempval
= evaluate_expression (exp
);
1146 addr
= VALUE_ADDRESS (tempval
) + value_offset (tempval
);
1147 len
= TYPE_LENGTH (check_typedef (exp
->elts
[1].type
));
1148 add_memrange (collect
, memrange_absolute
, addr
, len
);
1152 collect_symbol (collect
,
1153 exp
->elts
[2].symbol
,
1158 default: /* full-fledged expression */
1159 aexpr
= gen_trace_for_expr (t
->loc
->address
, exp
);
1161 old_chain1
= make_cleanup_free_agent_expr (aexpr
);
1163 ax_reqs (aexpr
, &areqs
);
1164 if (areqs
.flaw
!= agent_flaw_none
)
1165 error (_("malformed expression"));
1167 if (areqs
.min_height
< 0)
1168 error (_("gdb: Internal error: expression has min height < 0"));
1169 if (areqs
.max_height
> 20)
1170 error (_("expression too complicated, try simplifying"));
1172 discard_cleanups (old_chain1
);
1173 add_aexpr (collect
, aexpr
);
1175 /* take care of the registers */
1176 if (areqs
.reg_mask_len
> 0)
1181 for (ndx1
= 0; ndx1
< areqs
.reg_mask_len
; ndx1
++)
1183 QUIT
; /* allow user to bail out with ^C */
1184 if (areqs
.reg_mask
[ndx1
] != 0)
1186 /* assume chars have 8 bits */
1187 for (ndx2
= 0; ndx2
< 8; ndx2
++)
1188 if (areqs
.reg_mask
[ndx1
] & (1 << ndx2
))
1189 /* it's used -- record it */
1190 add_register (collect
,
1197 do_cleanups (old_chain
);
1200 while (action_exp
&& *action_exp
++ == ',');
1202 else if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
1204 collect
= &stepping_list
;
1206 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
1208 if (collect
== &stepping_list
) /* end stepping actions */
1209 collect
= &tracepoint_list
;
1211 break; /* end tracepoint actions */
1214 memrange_sortmerge (&tracepoint_list
);
1215 memrange_sortmerge (&stepping_list
);
1217 *tdp_actions
= stringify_collection_list (&tracepoint_list
,
1219 *stepping_actions
= stringify_collection_list (&stepping_list
,
1224 add_aexpr (struct collection_list
*collect
, struct agent_expr
*aexpr
)
1226 if (collect
->next_aexpr_elt
>= collect
->aexpr_listsize
)
1228 collect
->aexpr_list
=
1229 xrealloc (collect
->aexpr_list
,
1230 2 * collect
->aexpr_listsize
* sizeof (struct agent_expr
*));
1231 collect
->aexpr_listsize
*= 2;
1233 collect
->aexpr_list
[collect
->next_aexpr_elt
] = aexpr
;
1234 collect
->next_aexpr_elt
++;
1237 static char *target_buf
;
1238 static long target_buf_size
;
1240 /* Set "transparent" memory ranges
1242 Allow trace mechanism to treat text-like sections
1243 (and perhaps all read-only sections) transparently,
1244 i.e. don't reject memory requests from these address ranges
1245 just because they haven't been collected. */
1248 remote_set_transparent_ranges (void)
1250 extern bfd
*exec_bfd
;
1257 return; /* No information to give. */
1259 strcpy (target_buf
, "QTro");
1260 for (s
= exec_bfd
->sections
; s
; s
= s
->next
)
1262 char tmp1
[40], tmp2
[40];
1264 if ((s
->flags
& SEC_LOAD
) == 0 ||
1265 /* (s->flags & SEC_CODE) == 0 || */
1266 (s
->flags
& SEC_READONLY
) == 0)
1271 size
= bfd_get_section_size (s
);
1272 sprintf_vma (tmp1
, lma
);
1273 sprintf_vma (tmp2
, lma
+ size
);
1274 sprintf (target_buf
+ strlen (target_buf
),
1275 ":%s,%s", tmp1
, tmp2
);
1279 putpkt (target_buf
);
1280 getpkt (&target_buf
, &target_buf_size
, 0);
1286 Tell target to clear any previous trace experiment.
1287 Walk the list of tracepoints, and send them (and their actions)
1288 to the target. If no errors,
1289 Tell target to start a new trace experiment. */
1291 void download_tracepoint (struct breakpoint
*t
);
1294 trace_start_command (char *args
, int from_tty
)
1296 VEC(breakpoint_p
) *tp_vec
= NULL
;
1298 struct breakpoint
*t
;
1300 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1302 if (target_is_remote ())
1305 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1306 if (strcmp (target_buf
, "OK"))
1307 error (_("Target does not support this command."));
1309 tp_vec
= all_tracepoints ();
1310 for (ix
= 0; VEC_iterate (breakpoint_p
, tp_vec
, ix
, t
); ix
++)
1312 download_tracepoint (t
);
1314 VEC_free (breakpoint_p
, tp_vec
);
1316 /* Tell target to treat text-like sections as transparent. */
1317 remote_set_transparent_ranges ();
1318 /* Now insert traps and begin collecting data. */
1320 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1321 if (strcmp (target_buf
, "OK"))
1322 error (_("Bogus reply from target: %s"), target_buf
);
1323 set_traceframe_num (-1); /* All old traceframes invalidated. */
1324 set_tracepoint_num (-1);
1325 set_traceframe_context (NULL
);
1326 trace_running_p
= 1;
1327 if (deprecated_trace_start_stop_hook
)
1328 deprecated_trace_start_stop_hook (1, from_tty
);
1332 error (_("Trace can only be run on remote targets."));
1335 /* Send the definition of a single tracepoint to the target. */
1338 download_tracepoint (struct breakpoint
*t
)
1343 char **stepping_actions
;
1345 struct cleanup
*old_chain
= NULL
;
1347 sprintf_vma (tmp
, (t
->loc
? t
->loc
->address
: 0));
1348 sprintf (buf
, "QTDP:%x:%s:%c:%lx:%x", t
->number
,
1350 (t
->enable_state
== bp_enabled
? 'E' : 'D'),
1351 t
->step_count
, t
->pass_count
);
1356 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1357 if (strcmp (target_buf
, "OK"))
1358 error (_("Target does not support tracepoints."));
1363 encode_actions (t
, &tdp_actions
, &stepping_actions
);
1364 old_chain
= make_cleanup (free_actions_list_cleanup_wrapper
,
1366 (void) make_cleanup (free_actions_list_cleanup_wrapper
, stepping_actions
);
1368 /* do_single_steps (t); */
1371 for (ndx
= 0; tdp_actions
[ndx
]; ndx
++)
1373 QUIT
; /* allow user to bail out with ^C */
1374 sprintf (buf
, "QTDP:-%x:%s:%s%c",
1375 t
->number
, tmp
, /* address */
1377 ((tdp_actions
[ndx
+ 1] || stepping_actions
)
1380 remote_get_noisy_reply (&target_buf
,
1382 if (strcmp (target_buf
, "OK"))
1383 error (_("Error on target while setting tracepoints."));
1386 if (stepping_actions
)
1388 for (ndx
= 0; stepping_actions
[ndx
]; ndx
++)
1390 QUIT
; /* allow user to bail out with ^C */
1391 sprintf (buf
, "QTDP:-%x:%s:%s%s%s",
1392 t
->number
, tmp
, /* address */
1393 ((ndx
== 0) ? "S" : ""),
1394 stepping_actions
[ndx
],
1395 (stepping_actions
[ndx
+ 1] ? "-" : ""));
1397 remote_get_noisy_reply (&target_buf
,
1399 if (strcmp (target_buf
, "OK"))
1400 error (_("Error on target while setting tracepoints."));
1403 do_cleanups (old_chain
);
1408 trace_stop_command (char *args
, int from_tty
)
1410 if (target_is_remote ())
1413 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1414 if (strcmp (target_buf
, "OK"))
1415 error (_("Bogus reply from target: %s"), target_buf
);
1416 trace_running_p
= 0;
1417 if (deprecated_trace_start_stop_hook
)
1418 deprecated_trace_start_stop_hook (0, from_tty
);
1421 error (_("Trace can only be run on remote targets."));
1424 unsigned long trace_running_p
;
1426 /* tstatus command */
1428 trace_status_command (char *args
, int from_tty
)
1430 if (target_is_remote ())
1432 putpkt ("qTStatus");
1433 remote_get_noisy_reply (&target_buf
, &target_buf_size
);
1435 if (target_buf
[0] != 'T' ||
1436 (target_buf
[1] != '0' && target_buf
[1] != '1'))
1437 error (_("Bogus reply from target: %s"), target_buf
);
1439 /* exported for use by the GUI */
1440 trace_running_p
= (target_buf
[1] == '1');
1443 error (_("Trace can only be run on remote targets."));
1446 /* Worker function for the various flavors of the tfind command. */
1448 finish_tfind_command (char **msg
,
1452 int target_frameno
= -1, target_tracept
= -1;
1453 struct frame_id old_frame_id
;
1456 old_frame_id
= get_frame_id (get_current_frame ());
1459 reply
= remote_get_noisy_reply (msg
, sizeof_msg
);
1461 while (reply
&& *reply
)
1465 if ((target_frameno
= (int) strtol (++reply
, &reply
, 16)) == -1)
1467 /* A request for a non-existant trace frame has failed.
1468 Our response will be different, depending on FROM_TTY:
1470 If FROM_TTY is true, meaning that this command was
1471 typed interactively by the user, then give an error
1472 and DO NOT change the state of traceframe_number etc.
1474 However if FROM_TTY is false, meaning that we're either
1475 in a script, a loop, or a user-defined command, then
1476 DON'T give an error, but DO change the state of
1477 traceframe_number etc. to invalid.
1479 The rationalle is that if you typed the command, you
1480 might just have committed a typo or something, and you'd
1481 like to NOT lose your current debugging state. However
1482 if you're in a user-defined command or especially in a
1483 loop, then you need a way to detect that the command
1484 failed WITHOUT aborting. This allows you to write
1485 scripts that search thru the trace buffer until the end,
1486 and then continue on to do something else. */
1489 error (_("Target failed to find requested trace frame."));
1493 printf_filtered ("End of trace buffer.\n");
1494 /* The following will not recurse, since it's
1496 trace_find_command ("-1", from_tty
);
1497 reply
= NULL
; /* Break out of loop
1498 (avoid recursive nonsense). */
1503 if ((target_tracept
= (int) strtol (++reply
, &reply
, 16)) == -1)
1504 error (_("Target failed to find requested trace frame."));
1506 case 'O': /* "OK"? */
1507 if (reply
[1] == 'K' && reply
[2] == '\0')
1510 error (_("Bogus reply from target: %s"), reply
);
1513 error (_("Bogus reply from target: %s"), reply
);
1516 reinit_frame_cache ();
1517 registers_changed ();
1518 set_traceframe_num (target_frameno
);
1519 set_tracepoint_num (target_tracept
);
1520 if (target_frameno
== -1)
1521 set_traceframe_context (NULL
);
1523 set_traceframe_context (get_current_frame ());
1527 enum print_what print_what
;
1529 /* NOTE: in immitation of the step command, try to determine
1530 whether we have made a transition from one function to
1531 another. If so, we'll print the "stack frame" (ie. the new
1532 function and it's arguments) -- otherwise we'll just show the
1535 if (frame_id_eq (old_frame_id
,
1536 get_frame_id (get_current_frame ())))
1537 print_what
= SRC_LINE
;
1539 print_what
= SRC_AND_LOC
;
1541 print_stack_frame (get_selected_frame (NULL
), 1, print_what
);
1546 /* trace_find_command takes a trace frame number n,
1547 sends "QTFrame:<n>" to the target,
1548 and accepts a reply that may contain several optional pieces
1549 of information: a frame number, a tracepoint number, and an
1550 indication of whether this is a trap frame or a stepping frame.
1552 The minimal response is just "OK" (which indicates that the
1553 target does not give us a frame number or a tracepoint number).
1554 Instead of that, the target may send us a string containing
1556 F<hexnum> (gives the selected frame number)
1557 T<hexnum> (gives the selected tracepoint number)
1562 trace_find_command (char *args
, int from_tty
)
1563 { /* this should only be called with a numeric argument */
1566 if (target_is_remote ())
1568 if (deprecated_trace_find_hook
)
1569 deprecated_trace_find_hook (args
, from_tty
);
1571 if (args
== 0 || *args
== 0)
1572 { /* TFIND with no args means find NEXT trace frame. */
1573 if (traceframe_number
== -1)
1574 frameno
= 0; /* "next" is first one */
1576 frameno
= traceframe_number
+ 1;
1578 else if (0 == strcmp (args
, "-"))
1580 if (traceframe_number
== -1)
1581 error (_("not debugging trace buffer"));
1582 else if (from_tty
&& traceframe_number
== 0)
1583 error (_("already at start of trace buffer"));
1585 frameno
= traceframe_number
- 1;
1588 frameno
= parse_and_eval_long (args
);
1591 error (_("invalid input (%d is less than zero)"), frameno
);
1593 sprintf (target_buf
, "QTFrame:%x", frameno
);
1594 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1597 error (_("Trace can only be run on remote targets."));
1602 trace_find_end_command (char *args
, int from_tty
)
1604 trace_find_command ("-1", from_tty
);
1609 trace_find_none_command (char *args
, int from_tty
)
1611 trace_find_command ("-1", from_tty
);
1616 trace_find_start_command (char *args
, int from_tty
)
1618 trace_find_command ("0", from_tty
);
1621 /* tfind pc command */
1623 trace_find_pc_command (char *args
, int from_tty
)
1628 if (target_is_remote ())
1630 if (args
== 0 || *args
== 0)
1631 pc
= regcache_read_pc (get_current_regcache ());
1633 pc
= parse_and_eval_address (args
);
1635 sprintf_vma (tmp
, pc
);
1636 sprintf (target_buf
, "QTFrame:pc:%s", tmp
);
1637 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1640 error (_("Trace can only be run on remote targets."));
1643 /* tfind tracepoint command */
1645 trace_find_tracepoint_command (char *args
, int from_tty
)
1649 if (target_is_remote ())
1651 if (args
== 0 || *args
== 0)
1653 if (tracepoint_number
== -1)
1654 error (_("No current tracepoint -- please supply an argument."));
1656 tdp
= tracepoint_number
; /* default is current TDP */
1659 tdp
= parse_and_eval_long (args
);
1661 sprintf (target_buf
, "QTFrame:tdp:%x", tdp
);
1662 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1665 error (_("Trace can only be run on remote targets."));
1668 /* TFIND LINE command:
1670 This command will take a sourceline for argument, just like BREAK
1671 or TRACE (ie. anything that "decode_line_1" can handle).
1673 With no argument, this command will find the next trace frame
1674 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1677 trace_find_line_command (char *args
, int from_tty
)
1679 static CORE_ADDR start_pc
, end_pc
;
1680 struct symtabs_and_lines sals
;
1681 struct symtab_and_line sal
;
1682 struct cleanup
*old_chain
;
1683 char startpc_str
[40], endpc_str
[40];
1685 if (target_is_remote ())
1687 if (args
== 0 || *args
== 0)
1689 sal
= find_pc_line (get_frame_pc (get_current_frame ()), 0);
1691 sals
.sals
= (struct symtab_and_line
*)
1692 xmalloc (sizeof (struct symtab_and_line
));
1697 sals
= decode_line_spec (args
, 1);
1701 old_chain
= make_cleanup (xfree
, sals
.sals
);
1702 if (sal
.symtab
== 0)
1704 printf_filtered ("TFIND: No line number information available");
1707 /* This is useful for "info line *0x7f34". If we can't
1708 tell the user about a source line, at least let them
1709 have the symbolic address. */
1710 printf_filtered (" for address ");
1712 print_address (sal
.pc
, gdb_stdout
);
1713 printf_filtered (";\n -- will attempt to find by PC. \n");
1717 printf_filtered (".\n");
1718 return; /* No line, no PC; what can we do? */
1721 else if (sal
.line
> 0
1722 && find_line_pc_range (sal
, &start_pc
, &end_pc
))
1724 if (start_pc
== end_pc
)
1726 printf_filtered ("Line %d of \"%s\"",
1727 sal
.line
, sal
.symtab
->filename
);
1729 printf_filtered (" is at address ");
1730 print_address (start_pc
, gdb_stdout
);
1732 printf_filtered (" but contains no code.\n");
1733 sal
= find_pc_line (start_pc
, 0);
1735 find_line_pc_range (sal
, &start_pc
, &end_pc
) &&
1737 printf_filtered ("Attempting to find line %d instead.\n",
1740 error (_("Cannot find a good line."));
1744 /* Is there any case in which we get here, and have an address
1745 which the user would want to see? If we have debugging
1746 symbols and no line numbers? */
1747 error (_("Line number %d is out of range for \"%s\"."),
1748 sal
.line
, sal
.symtab
->filename
);
1750 sprintf_vma (startpc_str
, start_pc
);
1751 sprintf_vma (endpc_str
, end_pc
- 1);
1752 /* Find within range of stated line. */
1754 sprintf (target_buf
, "QTFrame:range:%s:%s",
1755 startpc_str
, endpc_str
);
1756 /* Find OUTSIDE OF range of CURRENT line. */
1758 sprintf (target_buf
, "QTFrame:outside:%s:%s",
1759 startpc_str
, endpc_str
);
1760 finish_tfind_command (&target_buf
, &target_buf_size
,
1762 do_cleanups (old_chain
);
1765 error (_("Trace can only be run on remote targets."));
1768 /* tfind range command */
1770 trace_find_range_command (char *args
, int from_tty
)
1772 static CORE_ADDR start
, stop
;
1773 char start_str
[40], stop_str
[40];
1776 if (target_is_remote ())
1778 if (args
== 0 || *args
== 0)
1779 { /* XXX FIXME: what should default behavior be? */
1780 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1784 if (0 != (tmp
= strchr (args
, ',')))
1786 *tmp
++ = '\0'; /* terminate start address */
1787 while (isspace ((int) *tmp
))
1789 start
= parse_and_eval_address (args
);
1790 stop
= parse_and_eval_address (tmp
);
1793 { /* no explicit end address? */
1794 start
= parse_and_eval_address (args
);
1795 stop
= start
+ 1; /* ??? */
1798 sprintf_vma (start_str
, start
);
1799 sprintf_vma (stop_str
, stop
);
1800 sprintf (target_buf
, "QTFrame:range:%s:%s", start_str
, stop_str
);
1801 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1804 error (_("Trace can only be run on remote targets."));
1807 /* tfind outside command */
1809 trace_find_outside_command (char *args
, int from_tty
)
1811 CORE_ADDR start
, stop
;
1812 char start_str
[40], stop_str
[40];
1815 if (target_is_remote ())
1817 if (args
== 0 || *args
== 0)
1818 { /* XXX FIXME: what should default behavior be? */
1819 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1823 if (0 != (tmp
= strchr (args
, ',')))
1825 *tmp
++ = '\0'; /* terminate start address */
1826 while (isspace ((int) *tmp
))
1828 start
= parse_and_eval_address (args
);
1829 stop
= parse_and_eval_address (tmp
);
1832 { /* no explicit end address? */
1833 start
= parse_and_eval_address (args
);
1834 stop
= start
+ 1; /* ??? */
1837 sprintf_vma (start_str
, start
);
1838 sprintf_vma (stop_str
, stop
);
1839 sprintf (target_buf
, "QTFrame:outside:%s:%s", start_str
, stop_str
);
1840 finish_tfind_command (&target_buf
, &target_buf_size
, from_tty
);
1843 error (_("Trace can only be run on remote targets."));
1846 /* info scope command: list the locals for a scope. */
1848 scope_info (char *args
, int from_tty
)
1850 struct symtabs_and_lines sals
;
1852 struct minimal_symbol
*msym
;
1853 struct block
*block
;
1854 char **canonical
, *symname
, *save_args
= args
;
1855 struct dict_iterator iter
;
1858 if (args
== 0 || *args
== 0)
1859 error (_("requires an argument (function, line or *addr) to define a scope"));
1861 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
, NULL
);
1862 if (sals
.nelts
== 0)
1863 return; /* presumably decode_line_1 has already warned */
1865 /* Resolve line numbers to PC */
1866 resolve_sal_pc (&sals
.sals
[0]);
1867 block
= block_for_pc (sals
.sals
[0].pc
);
1871 QUIT
; /* allow user to bail out with ^C */
1872 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
1874 QUIT
; /* allow user to bail out with ^C */
1876 printf_filtered ("Scope for %s:\n", save_args
);
1879 symname
= SYMBOL_PRINT_NAME (sym
);
1880 if (symname
== NULL
|| *symname
== '\0')
1881 continue; /* probably botched, certainly useless */
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 (SYMBOL_VALUE_ADDRESS (sym
)));
1908 if (SYMBOL_IS_ARGUMENT (sym
))
1909 printf_filtered ("an argument in register $%s",
1910 gdbarch_register_name
1911 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1913 printf_filtered ("a local variable in register $%s",
1914 gdbarch_register_name
1915 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1918 printf_filtered ("an argument at stack/frame offset %ld",
1919 SYMBOL_VALUE (sym
));
1922 printf_filtered ("a local variable at frame offset %ld",
1923 SYMBOL_VALUE (sym
));
1926 printf_filtered ("a reference argument at offset %ld",
1927 SYMBOL_VALUE (sym
));
1929 case LOC_REGPARM_ADDR
:
1930 printf_filtered ("the address of an argument, in register $%s",
1931 gdbarch_register_name
1932 (current_gdbarch
, SYMBOL_VALUE (sym
)));
1935 printf_filtered ("a typedef.\n");
1938 printf_filtered ("a label at address ");
1939 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym
)));
1942 printf_filtered ("a function at address ");
1943 printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym
))));
1945 case LOC_UNRESOLVED
:
1946 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1949 printf_filtered ("Unresolved Static");
1952 printf_filtered ("static storage at address ");
1953 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym
)));
1956 case LOC_OPTIMIZED_OUT
:
1957 printf_filtered ("optimized out.\n");
1960 SYMBOL_OPS (sym
)->describe_location (sym
, gdb_stdout
);
1963 if (SYMBOL_TYPE (sym
))
1964 printf_filtered (", length %d.\n",
1965 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym
))));
1967 if (BLOCK_FUNCTION (block
))
1970 block
= BLOCK_SUPERBLOCK (block
);
1973 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1977 /* worker function (cleanup) */
1979 replace_comma (void *data
)
1987 trace_dump_command (char *args
, int from_tty
)
1989 struct regcache
*regcache
;
1990 struct gdbarch
*gdbarch
;
1991 struct breakpoint
*t
;
1992 struct action_line
*action
;
1993 char *action_exp
, *next_comma
;
1994 struct cleanup
*old_cleanups
;
1995 int stepping_actions
= 0;
1996 int stepping_frame
= 0;
1998 if (!target_is_remote ())
2000 error (_("Trace can only be run on remote targets."));
2004 if (tracepoint_number
== -1)
2006 warning (_("No current trace frame."));
2010 t
= get_tracepoint (tracepoint_number
);
2013 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2016 old_cleanups
= make_cleanup (null_cleanup
, NULL
);
2018 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2019 tracepoint_number
, traceframe_number
);
2021 /* The current frame is a trap frame if the frame PC is equal
2022 to the tracepoint PC. If not, then the current frame was
2023 collected during single-stepping. */
2025 regcache
= get_current_regcache ();
2026 gdbarch
= get_regcache_arch (regcache
);
2028 stepping_frame
= (t
->loc
->address
!= (regcache_read_pc (regcache
)
2029 - gdbarch_decr_pc_after_break (gdbarch
)));
2031 for (action
= t
->actions
; action
; action
= action
->next
)
2033 struct cmd_list_element
*cmd
;
2035 QUIT
; /* allow user to bail out with ^C */
2036 action_exp
= action
->action
;
2037 while (isspace ((int) *action_exp
))
2040 /* The collection actions to be done while stepping are
2041 bracketed by the commands "while-stepping" and "end". */
2043 if (*action_exp
== '#') /* comment line */
2046 cmd
= lookup_cmd (&action_exp
, cmdlist
, "", -1, 1);
2048 error (_("Bad action list item: %s"), action_exp
);
2050 if (cmd_cfunc_eq (cmd
, while_stepping_pseudocommand
))
2051 stepping_actions
= 1;
2052 else if (cmd_cfunc_eq (cmd
, end_actions_pseudocommand
))
2053 stepping_actions
= 0;
2054 else if (cmd_cfunc_eq (cmd
, collect_pseudocommand
))
2056 /* Display the collected data.
2057 For the trap frame, display only what was collected at
2058 the trap. Likewise for stepping frames, display only
2059 what was collected while stepping. This means that the
2060 two boolean variables, STEPPING_FRAME and
2061 STEPPING_ACTIONS should be equal. */
2062 if (stepping_frame
== stepping_actions
)
2065 { /* repeat over a comma-separated list */
2066 QUIT
; /* allow user to bail out with ^C */
2067 if (*action_exp
== ',')
2069 while (isspace ((int) *action_exp
))
2072 next_comma
= strchr (action_exp
, ',');
2074 if (0 == strncasecmp (action_exp
, "$reg", 4))
2075 registers_info (NULL
, from_tty
);
2076 else if (0 == strncasecmp (action_exp
, "$loc", 4))
2077 locals_info (NULL
, from_tty
);
2078 else if (0 == strncasecmp (action_exp
, "$arg", 4))
2079 args_info (NULL
, from_tty
);
2084 make_cleanup (replace_comma
, next_comma
);
2087 printf_filtered ("%s = ", action_exp
);
2088 output_command (action_exp
, from_tty
);
2089 printf_filtered ("\n");
2093 action_exp
= next_comma
;
2095 while (action_exp
&& *action_exp
== ',');
2099 discard_cleanups (old_cleanups
);
2102 /* Convert the memory pointed to by mem into hex, placing result in buf.
2103 * Return a pointer to the last char put in buf (null)
2104 * "stolen" from sparc-stub.c
2107 static const char hexchars
[] = "0123456789abcdef";
2110 mem2hex (gdb_byte
*mem
, char *buf
, int count
)
2118 *buf
++ = hexchars
[ch
>> 4];
2119 *buf
++ = hexchars
[ch
& 0xf];
2128 get_traceframe_number (void)
2130 return traceframe_number
;
2134 /* module initialization */
2136 _initialize_tracepoint (void)
2138 struct cmd_list_element
*c
;
2140 traceframe_number
= -1;
2141 tracepoint_number
= -1;
2143 if (tracepoint_list
.list
== NULL
)
2145 tracepoint_list
.listsize
= 128;
2146 tracepoint_list
.list
= xmalloc
2147 (tracepoint_list
.listsize
* sizeof (struct memrange
));
2149 if (tracepoint_list
.aexpr_list
== NULL
)
2151 tracepoint_list
.aexpr_listsize
= 128;
2152 tracepoint_list
.aexpr_list
= xmalloc
2153 (tracepoint_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2156 if (stepping_list
.list
== NULL
)
2158 stepping_list
.listsize
= 128;
2159 stepping_list
.list
= xmalloc
2160 (stepping_list
.listsize
* sizeof (struct memrange
));
2163 if (stepping_list
.aexpr_list
== NULL
)
2165 stepping_list
.aexpr_listsize
= 128;
2166 stepping_list
.aexpr_list
= xmalloc
2167 (stepping_list
.aexpr_listsize
* sizeof (struct agent_expr
*));
2170 add_info ("scope", scope_info
,
2171 _("List the variables local to a scope"));
2173 add_cmd ("tracepoints", class_trace
, NULL
,
2174 _("Tracing of program execution without stopping the program."),
2177 add_com ("tdump", class_trace
, trace_dump_command
,
2178 _("Print everything collected at the current tracepoint."));
2180 add_prefix_cmd ("tfind", class_trace
, trace_find_command
, _("\
2181 Select a trace frame;\n\
2182 No argument means forward by one frame; '-' means backward by one frame."),
2183 &tfindlist
, "tfind ", 1, &cmdlist
);
2185 add_cmd ("outside", class_trace
, trace_find_outside_command
, _("\
2186 Select a trace frame whose PC is outside the given range.\n\
2187 Usage: tfind outside addr1, addr2"),
2190 add_cmd ("range", class_trace
, trace_find_range_command
, _("\
2191 Select a trace frame whose PC is in the given range.\n\
2192 Usage: tfind range addr1,addr2"),
2195 add_cmd ("line", class_trace
, trace_find_line_command
, _("\
2196 Select a trace frame by source line.\n\
2197 Argument can be a line number (with optional source file), \n\
2198 a function name, or '*' followed by an address.\n\
2199 Default argument is 'the next source line that was traced'."),
2202 add_cmd ("tracepoint", class_trace
, trace_find_tracepoint_command
, _("\
2203 Select a trace frame by tracepoint number.\n\
2204 Default is the tracepoint for the current trace frame."),
2207 add_cmd ("pc", class_trace
, trace_find_pc_command
, _("\
2208 Select a trace frame by PC.\n\
2209 Default is the current PC, or the PC of the current trace frame."),
2212 add_cmd ("end", class_trace
, trace_find_end_command
, _("\
2213 Synonym for 'none'.\n\
2214 De-select any trace frame and resume 'live' debugging."),
2217 add_cmd ("none", class_trace
, trace_find_none_command
,
2218 _("De-select any trace frame and resume 'live' debugging."),
2221 add_cmd ("start", class_trace
, trace_find_start_command
,
2222 _("Select the first trace frame in the trace buffer."),
2225 add_com ("tstatus", class_trace
, trace_status_command
,
2226 _("Display the status of the current trace data collection."));
2228 add_com ("tstop", class_trace
, trace_stop_command
,
2229 _("Stop trace data collection."));
2231 add_com ("tstart", class_trace
, trace_start_command
,
2232 _("Start trace data collection."));
2234 add_com ("end", class_trace
, end_actions_pseudocommand
, _("\
2235 Ends a list of commands or actions.\n\
2236 Several GDB commands allow you to enter a list of commands or actions.\n\
2237 Entering \"end\" on a line by itself is the normal way to terminate\n\
2239 Note: the \"end\" command cannot be used at the gdb prompt."));
2241 add_com ("while-stepping", class_trace
, while_stepping_pseudocommand
, _("\
2242 Specify single-stepping behavior at a tracepoint.\n\
2243 Argument is number of instructions to trace in single-step mode\n\
2244 following the tracepoint. This command is normally followed by\n\
2245 one or more \"collect\" commands, to specify what to collect\n\
2246 while single-stepping.\n\n\
2247 Note: this command can only be used in a tracepoint \"actions\" list."));
2249 add_com_alias ("ws", "while-stepping", class_alias
, 0);
2250 add_com_alias ("stepping", "while-stepping", class_alias
, 0);
2252 add_com ("collect", class_trace
, collect_pseudocommand
, _("\
2253 Specify one or more data items to be collected at a tracepoint.\n\
2254 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2255 collect all data (variables, registers) referenced by that expression.\n\
2256 Also accepts the following special arguments:\n\
2257 $regs -- all registers.\n\
2258 $args -- all function arguments.\n\
2259 $locals -- all variables local to the block/function scope.\n\
2260 Note: this command can only be used in a tracepoint \"actions\" list."));
2262 add_com ("actions", class_trace
, trace_actions_command
, _("\
2263 Specify the actions to be taken at a tracepoint.\n\
2264 Tracepoint actions may include collecting of specified data, \n\
2265 single-stepping, or enabling/disabling other tracepoints, \n\
2266 depending on target's capabilities."));
2268 target_buf_size
= 2048;
2269 target_buf
= xmalloc (target_buf_size
);