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 (CORE_ADDR trace_pc)
229 static struct type *func_string, *file_string;
230 static struct type *func_range, *file_range;
231 struct value *func_val;
232 struct value *file_val;
235 if (trace_pc == -1) /* Cease debugging any trace buffers. */
238 traceframe_sal.pc = traceframe_sal.line = 0;
239 traceframe_sal.symtab = NULL;
240 set_internalvar (lookup_internalvar ("trace_func"),
241 allocate_value (builtin_type_void));
242 set_internalvar (lookup_internalvar ("trace_file"),
243 allocate_value (builtin_type_void));
244 set_internalvar (lookup_internalvar ("trace_line"),
245 value_from_longest (builtin_type_int32,
250 /* Save as globals for internal use. */
251 traceframe_sal = find_pc_line (trace_pc, 0);
252 traceframe_fun = find_pc_function (trace_pc);
254 /* Save linenumber as "$trace_line", a debugger variable visible to
256 set_internalvar (lookup_internalvar ("trace_line"),
257 value_from_longest (builtin_type_int32,
258 (LONGEST) traceframe_sal.line));
260 /* Save func name as "$trace_func", a debugger variable visible to
262 if (traceframe_fun == NULL ||
263 SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
264 set_internalvar (lookup_internalvar ("trace_func"),
265 allocate_value (builtin_type_void));
268 len = strlen (SYMBOL_LINKAGE_NAME (traceframe_fun));
269 func_range = create_range_type (func_range,
270 builtin_type_int32, 0, len - 1);
271 func_string = create_array_type (func_string,
272 builtin_type_true_char, func_range);
273 func_val = allocate_value (func_string);
274 deprecated_set_value_type (func_val, func_string);
275 memcpy (value_contents_raw (func_val),
276 SYMBOL_LINKAGE_NAME (traceframe_fun),
278 deprecated_set_value_modifiable (func_val, 0);
279 set_internalvar (lookup_internalvar ("trace_func"), func_val);
282 /* Save file name as "$trace_file", a debugger variable visible to
284 if (traceframe_sal.symtab == NULL ||
285 traceframe_sal.symtab->filename == NULL)
286 set_internalvar (lookup_internalvar ("trace_file"),
287 allocate_value (builtin_type_void));
290 len = strlen (traceframe_sal.symtab->filename);
291 file_range = create_range_type (file_range,
292 builtin_type_int32, 0, len - 1);
293 file_string = create_array_type (file_string,
294 builtin_type_true_char, file_range);
295 file_val = allocate_value (file_string);
296 deprecated_set_value_type (file_val, file_string);
297 memcpy (value_contents_raw (file_val),
298 traceframe_sal.symtab->filename,
300 deprecated_set_value_modifiable (file_val, 0);
301 set_internalvar (lookup_internalvar ("trace_file"), file_val);
305 /* ACTIONS functions: */
307 /* Prototypes for action-parsing utility commands */
308 static void read_actions (struct breakpoint *);
310 /* The three functions:
311 collect_pseudocommand,
312 while_stepping_pseudocommand, and
313 end_actions_pseudocommand
314 are placeholders for "commands" that are actually ONLY to be used
315 within a tracepoint action list. If the actual function is ever called,
316 it means that somebody issued the "command" at the top level,
317 which is always an error. */
320 end_actions_pseudocommand (char *args, int from_tty)
322 error (_("This command cannot be used at the top level."));
326 while_stepping_pseudocommand (char *args, int from_tty)
328 error (_("This command can only be used in a tracepoint actions list."));
332 collect_pseudocommand (char *args, int from_tty)
334 error (_("This command can only be used in a tracepoint actions list."));
337 /* Enter a list of actions for a tracepoint. */
339 trace_actions_command (char *args, int from_tty)
341 struct breakpoint *t;
343 char *end_msg = "End with a line saying just \"end\".";
345 t = get_tracepoint_by_number (&args, 0, 1);
348 sprintf (tmpbuf, "Enter actions for tracepoint %d, one per line.",
353 if (deprecated_readline_begin_hook)
354 (*deprecated_readline_begin_hook) ("%s %s\n", tmpbuf, end_msg);
355 else if (input_from_terminal_p ())
356 printf_filtered ("%s\n%s\n", tmpbuf, end_msg);
360 t->step_count = 0; /* read_actions may set this */
363 if (deprecated_readline_end_hook)
364 (*deprecated_readline_end_hook) ();
365 /* tracepoints_changed () */
367 /* else just return */
370 /* worker function */
372 read_actions (struct breakpoint *t)
375 char *prompt1 = "> ", *prompt2 = " > ";
376 char *prompt = prompt1;
377 enum actionline_type linetype;
378 extern FILE *instream;
379 struct action_line *next = NULL, *temp;
380 struct cleanup *old_chain;
382 /* Control-C quits instantly if typed while in this loop
383 since it should not wait until the user types a newline. */
385 /* FIXME: kettenis/20010823: Something is wrong here. In this file
386 STOP_SIGNAL is never defined. So this code has been left out, at
387 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
388 leads to compilation failures since the variable job_control
389 isn't declared. Leave this alone for now. */
392 signal (STOP_SIGNAL, handle_stop_sig);
394 old_chain = make_cleanup_free_actions (t);
397 /* Make sure that all output has been output. Some machines may
398 let you get away with leaving out some of the gdb_flush, but
401 gdb_flush (gdb_stdout);
402 gdb_flush (gdb_stderr);
404 if (deprecated_readline_hook && instream == NULL)
405 line = (*deprecated_readline_hook) (prompt);
406 else if (instream == stdin && ISATTY (instream))
408 line = gdb_readline_wrapper (prompt);
409 if (line && *line) /* add it to command history */
413 line = gdb_readline (0);
417 line = xstrdup ("end");
418 printf_filtered ("end\n");
421 linetype = validate_actionline (&line, t);
422 if (linetype == BADLINE)
423 continue; /* already warned -- collect another line */
425 temp = xmalloc (sizeof (struct action_line));
429 if (next == NULL) /* first action for this tracepoint? */
430 t->actions = next = temp;
437 if (linetype == STEPPING) /* begin "while-stepping" */
439 if (prompt == prompt2)
441 warning (_("Already processing 'while-stepping'"));
445 prompt = prompt2; /* change prompt for stepping actions */
447 else if (linetype == END)
449 if (prompt == prompt2)
451 prompt = prompt1; /* end of single-stepping actions */
454 { /* end of actions */
455 if (t->actions->next == NULL)
457 /* An "end" all by itself with no other actions
458 means this tracepoint has no actions.
459 Discard empty list. */
468 signal (STOP_SIGNAL, SIG_DFL);
471 discard_cleanups (old_chain);
474 /* worker function */
476 validate_actionline (char **line, struct breakpoint *t)
478 struct cmd_list_element *c;
479 struct expression *exp = NULL;
480 struct cleanup *old_chain = NULL;
483 /* if EOF is typed, *line is NULL */
487 for (p = *line; isspace ((int) *p);)
490 /* Symbol lookup etc. */
491 if (*p == '\0') /* empty line: just prompt for another line. */
494 if (*p == '#') /* comment line */
497 c = lookup_cmd (&p, cmdlist, "", -1, 1);
500 warning (_("'%s' is not an action that I know, or is ambiguous."),
505 if (cmd_cfunc_eq (c, collect_pseudocommand))
507 struct agent_expr *aexpr;
508 struct agent_reqs areqs;
511 { /* repeat over a comma-separated list */
512 QUIT; /* allow user to bail out with ^C */
513 while (isspace ((int) *p))
516 if (*p == '$') /* look for special pseudo-symbols */
518 if ((0 == strncasecmp ("reg", p + 1, 3)) ||
519 (0 == strncasecmp ("arg", p + 1, 3)) ||
520 (0 == strncasecmp ("loc", p + 1, 3)))
525 /* else fall thru, treat p as an expression and parse it! */
527 exp = parse_exp_1 (&p, block_for_pc (t->loc->address), 1);
528 old_chain = make_cleanup (free_current_contents, &exp);
530 if (exp->elts[0].opcode == OP_VAR_VALUE)
532 if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
534 warning (_("constant %s (value %ld) will not be collected."),
535 SYMBOL_PRINT_NAME (exp->elts[2].symbol),
536 SYMBOL_VALUE (exp->elts[2].symbol));
539 else if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_OPTIMIZED_OUT)
541 warning (_("%s is optimized away and cannot be collected."),
542 SYMBOL_PRINT_NAME (exp->elts[2].symbol));
547 /* We have something to collect, make sure that the expr to
548 bytecode translator can handle it and that it's not too
550 aexpr = gen_trace_for_expr (t->loc->address, exp);
551 make_cleanup_free_agent_expr (aexpr);
553 if (aexpr->len > MAX_AGENT_EXPR_LEN)
554 error (_("expression too complicated, try simplifying"));
556 ax_reqs (aexpr, &areqs);
557 (void) make_cleanup (xfree, areqs.reg_mask);
559 if (areqs.flaw != agent_flaw_none)
560 error (_("malformed expression"));
562 if (areqs.min_height < 0)
563 error (_("gdb: Internal error: expression has min height < 0"));
565 if (areqs.max_height > 20)
566 error (_("expression too complicated, try simplifying"));
568 do_cleanups (old_chain);
570 while (p && *p++ == ',');
573 else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
575 char *steparg; /* in case warning is necessary */
577 while (isspace ((int) *p))
582 (t->step_count = strtol (p, &p, 0)) == 0)
584 warning (_("'%s': bad step-count; command ignored."), *line);
589 else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
593 warning (_("'%s' is not a supported tracepoint action."), *line);
598 /* worker function */
600 free_actions (struct breakpoint *t)
602 struct action_line *line, *next;
604 for (line = t->actions; line; line = next)
608 xfree (line->action);
615 do_free_actions_cleanup (void *t)
620 static struct cleanup *
621 make_cleanup_free_actions (struct breakpoint *t)
623 return make_cleanup (do_free_actions_cleanup, t);
627 memrange_absolute = -1
632 int type; /* memrange_absolute for absolute memory range,
633 else basereg number */
634 bfd_signed_vma start;
638 struct collection_list
640 unsigned char regs_mask[32]; /* room for up to 256 regs */
643 struct memrange *list;
644 long aexpr_listsize; /* size of array pointed to by expr_list elt */
646 struct agent_expr **aexpr_list;
649 tracepoint_list, stepping_list;
651 /* MEMRANGE functions: */
653 static int memrange_cmp (const void *, const void *);
655 /* compare memranges for qsort */
657 memrange_cmp (const void *va, const void *vb)
659 const struct memrange *a = va, *b = vb;
661 if (a->type < b->type)
663 if (a->type > b->type)
665 if (a->type == memrange_absolute)
667 if ((bfd_vma) a->start < (bfd_vma) b->start)
669 if ((bfd_vma) a->start > (bfd_vma) b->start)
674 if (a->start < b->start)
676 if (a->start > b->start)
682 /* Sort the memrange list using qsort, and merge adjacent memranges. */
684 memrange_sortmerge (struct collection_list *memranges)
688 qsort (memranges->list, memranges->next_memrange,
689 sizeof (struct memrange), memrange_cmp);
690 if (memranges->next_memrange > 0)
692 for (a = 0, b = 1; b < memranges->next_memrange; b++)
694 if (memranges->list[a].type == memranges->list[b].type &&
695 memranges->list[b].start - memranges->list[a].end <=
698 /* memrange b starts before memrange a ends; merge them. */
699 if (memranges->list[b].end > memranges->list[a].end)
700 memranges->list[a].end = memranges->list[b].end;
701 continue; /* next b, same a */
705 memcpy (&memranges->list[a], &memranges->list[b],
706 sizeof (struct memrange));
708 memranges->next_memrange = a + 1;
712 /* Add a register to a collection list. */
714 add_register (struct collection_list *collection, unsigned int regno)
717 printf_filtered ("collect register %d\n", regno);
718 if (regno >= (8 * sizeof (collection->regs_mask)))
719 error (_("Internal: register number %d too large for tracepoint"),
721 collection->regs_mask[regno / 8] |= 1 << (regno % 8);
724 /* Add a memrange to a collection list */
726 add_memrange (struct collection_list *memranges,
727 int type, bfd_signed_vma base,
732 printf_filtered ("(%d,", type);
734 printf_filtered (",%ld)\n", len);
737 /* type: memrange_absolute == memory, other n == basereg */
738 memranges->list[memranges->next_memrange].type = type;
739 /* base: addr if memory, offset if reg relative. */
740 memranges->list[memranges->next_memrange].start = base;
741 /* len: we actually save end (base + len) for convenience */
742 memranges->list[memranges->next_memrange].end = base + len;
743 memranges->next_memrange++;
744 if (memranges->next_memrange >= memranges->listsize)
746 memranges->listsize *= 2;
747 memranges->list = xrealloc (memranges->list,
748 memranges->listsize);
751 if (type != memrange_absolute) /* Better collect the base register! */
752 add_register (memranges, type);
755 /* Add a symbol to a collection list. */
757 collect_symbol (struct collection_list *collect,
759 long frame_regno, long frame_offset)
763 bfd_signed_vma offset;
765 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
766 switch (SYMBOL_CLASS (sym))
769 printf_filtered ("%s: don't know symbol class %d\n",
770 SYMBOL_PRINT_NAME (sym),
774 printf_filtered ("constant %s (value %ld) will not be collected.\n",
775 SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE (sym));
778 offset = SYMBOL_VALUE_ADDRESS (sym);
783 sprintf_vma (tmp, offset);
784 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
785 SYMBOL_PRINT_NAME (sym), len,
788 add_memrange (collect, memrange_absolute, offset, len);
791 reg = SYMBOL_VALUE (sym);
793 printf_filtered ("LOC_REG[parm] %s: ",
794 SYMBOL_PRINT_NAME (sym));
795 add_register (collect, reg);
796 /* Check for doubles stored in two registers. */
797 /* FIXME: how about larger types stored in 3 or more regs? */
798 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
799 len > register_size (current_gdbarch, reg))
800 add_register (collect, reg + 1);
803 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
804 printf_filtered (" (will not collect %s)\n",
805 SYMBOL_PRINT_NAME (sym));
809 offset = frame_offset + SYMBOL_VALUE (sym);
812 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
813 SYMBOL_PRINT_NAME (sym), len);
815 printf_filtered (" from frame ptr reg %d\n", reg);
817 add_memrange (collect, reg, offset, len);
819 case LOC_REGPARM_ADDR:
820 reg = SYMBOL_VALUE (sym);
824 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
825 SYMBOL_PRINT_NAME (sym), len);
827 printf_filtered (" from reg %d\n", reg);
829 add_memrange (collect, reg, offset, len);
833 offset = frame_offset + SYMBOL_VALUE (sym);
836 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
837 SYMBOL_PRINT_NAME (sym), len);
839 printf_filtered (" from frame ptr reg %d\n", reg);
841 add_memrange (collect, reg, offset, len);
844 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
845 SYMBOL_PRINT_NAME (sym));
847 case LOC_OPTIMIZED_OUT:
848 printf_filtered ("%s has been optimized out of existence.\n",
849 SYMBOL_PRINT_NAME (sym));
854 /* Add all locals (or args) symbols to collection list */
856 add_local_symbols (struct collection_list *collect, CORE_ADDR pc,
857 long frame_regno, long frame_offset, int type)
861 struct dict_iterator iter;
864 block = block_for_pc (pc);
867 QUIT; /* allow user to bail out with ^C */
868 ALL_BLOCK_SYMBOLS (block, iter, sym)
870 if (SYMBOL_IS_ARGUMENT (sym)
871 ? type == 'A' /* collecting Arguments */
872 : type == 'L') /* collecting Locals */
875 collect_symbol (collect, sym, frame_regno,
879 if (BLOCK_FUNCTION (block))
882 block = BLOCK_SUPERBLOCK (block);
885 warning (_("No %s found in scope."),
886 type == 'L' ? "locals" : "args");
889 /* worker function */
891 clear_collection_list (struct collection_list *list)
895 list->next_memrange = 0;
896 for (ndx = 0; ndx < list->next_aexpr_elt; ndx++)
898 free_agent_expr (list->aexpr_list[ndx]);
899 list->aexpr_list[ndx] = NULL;
901 list->next_aexpr_elt = 0;
902 memset (list->regs_mask, 0, sizeof (list->regs_mask));
905 /* reduce a collection list to string form (for gdb protocol) */
907 stringify_collection_list (struct collection_list *list, char *string)
917 count = 1 + list->next_memrange + list->next_aexpr_elt + 1;
918 str_list = (char *(*)[]) xmalloc (count * sizeof (char *));
920 for (i = sizeof (list->regs_mask) - 1; i > 0; i--)
921 if (list->regs_mask[i] != 0) /* skip leading zeroes in regs_mask */
923 if (list->regs_mask[i] != 0) /* prepare to send regs_mask to the stub */
926 printf_filtered ("\nCollecting registers (mask): 0x");
931 QUIT; /* allow user to bail out with ^C */
933 printf_filtered ("%02X", list->regs_mask[i]);
934 sprintf (end, "%02X", list->regs_mask[i]);
937 (*str_list)[ndx] = savestring (temp_buf, end - temp_buf);
941 printf_filtered ("\n");
942 if (list->next_memrange > 0 && info_verbose)
943 printf_filtered ("Collecting memranges: \n");
944 for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++)
946 QUIT; /* allow user to bail out with ^C */
947 sprintf_vma (tmp2, list->list[i].start);
950 printf_filtered ("(%d, %s, %ld)\n",
953 (long) (list->list[i].end - list->list[i].start));
955 if (count + 27 > MAX_AGENT_EXPR_LEN)
957 (*str_list)[ndx] = savestring (temp_buf, count);
964 bfd_signed_vma length = list->list[i].end - list->list[i].start;
966 /* The "%X" conversion specifier expects an unsigned argument,
967 so passing -1 (memrange_absolute) to it directly gives you
968 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
970 if (list->list[i].type == memrange_absolute)
971 sprintf (end, "M-1,%s,%lX", tmp2, (long) length);
973 sprintf (end, "M%X,%s,%lX", list->list[i].type, tmp2, (long) length);
976 count += strlen (end);
977 end = temp_buf + count;
980 for (i = 0; i < list->next_aexpr_elt; i++)
982 QUIT; /* allow user to bail out with ^C */
983 if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN)
985 (*str_list)[ndx] = savestring (temp_buf, count);
990 sprintf (end, "X%08X,", list->aexpr_list[i]->len);
991 end += 10; /* 'X' + 8 hex digits + ',' */
994 end = mem2hex (list->aexpr_list[i]->buf,
995 end, list->aexpr_list[i]->len);
996 count += 2 * list->aexpr_list[i]->len;
1001 (*str_list)[ndx] = savestring (temp_buf, count);
1006 (*str_list)[ndx] = NULL;
1018 free_actions_list_cleanup_wrapper (void *al)
1020 free_actions_list (al);
1024 free_actions_list (char **actions_list)
1028 if (actions_list == 0)
1031 for (ndx = 0; actions_list[ndx]; ndx++)
1032 xfree (actions_list[ndx]);
1034 xfree (actions_list);
1037 /* Render all actions into gdb protocol. */
1039 encode_actions (struct breakpoint *t, char ***tdp_actions,
1040 char ***stepping_actions)
1042 static char tdp_buff[2048], step_buff[2048];
1044 struct expression *exp = NULL;
1045 struct action_line *action;
1047 struct value *tempval;
1048 struct collection_list *collect;
1049 struct cmd_list_element *cmd;
1050 struct agent_expr *aexpr;
1052 LONGEST frame_offset;
1055 clear_collection_list (&tracepoint_list);
1056 clear_collection_list (&stepping_list);
1057 collect = &tracepoint_list;
1059 *tdp_actions = NULL;
1060 *stepping_actions = NULL;
1062 gdbarch_virtual_frame_pointer (current_gdbarch,
1063 t->loc->address, &frame_reg, &frame_offset);
1065 for (action = t->actions; action; action = action->next)
1067 QUIT; /* allow user to bail out with ^C */
1068 action_exp = action->action;
1069 while (isspace ((int) *action_exp))
1072 if (*action_exp == '#') /* comment line */
1075 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
1077 error (_("Bad action list item: %s"), action_exp);
1079 if (cmd_cfunc_eq (cmd, collect_pseudocommand))
1082 { /* repeat over a comma-separated list */
1083 QUIT; /* allow user to bail out with ^C */
1084 while (isspace ((int) *action_exp))
1087 if (0 == strncasecmp ("$reg", action_exp, 4))
1089 for (i = 0; i < gdbarch_num_regs (current_gdbarch); i++)
1090 add_register (collect, i);
1091 action_exp = strchr (action_exp, ','); /* more? */
1093 else if (0 == strncasecmp ("$arg", action_exp, 4))
1095 add_local_symbols (collect,
1100 action_exp = strchr (action_exp, ','); /* more? */
1102 else if (0 == strncasecmp ("$loc", action_exp, 4))
1104 add_local_symbols (collect,
1109 action_exp = strchr (action_exp, ','); /* more? */
1113 unsigned long addr, len;
1114 struct cleanup *old_chain = NULL;
1115 struct cleanup *old_chain1 = NULL;
1116 struct agent_reqs areqs;
1118 exp = parse_exp_1 (&action_exp,
1119 block_for_pc (t->loc->address), 1);
1120 old_chain = make_cleanup (free_current_contents, &exp);
1122 switch (exp->elts[0].opcode)
1126 const char *name = &exp->elts[2].string;
1128 i = user_reg_map_name_to_regnum (current_gdbarch,
1129 name, strlen (name));
1131 internal_error (__FILE__, __LINE__,
1132 _("Register $%s not available"),
1135 printf_filtered ("OP_REGISTER: ");
1136 add_register (collect, i);
1141 /* safe because we know it's a simple expression */
1142 tempval = evaluate_expression (exp);
1143 addr = VALUE_ADDRESS (tempval) + value_offset (tempval);
1144 len = TYPE_LENGTH (check_typedef (exp->elts[1].type));
1145 add_memrange (collect, memrange_absolute, addr, len);
1149 collect_symbol (collect,
1150 exp->elts[2].symbol,
1155 default: /* full-fledged expression */
1156 aexpr = gen_trace_for_expr (t->loc->address, exp);
1158 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1160 ax_reqs (aexpr, &areqs);
1161 if (areqs.flaw != agent_flaw_none)
1162 error (_("malformed expression"));
1164 if (areqs.min_height < 0)
1165 error (_("gdb: Internal error: expression has min height < 0"));
1166 if (areqs.max_height > 20)
1167 error (_("expression too complicated, try simplifying"));
1169 discard_cleanups (old_chain1);
1170 add_aexpr (collect, aexpr);
1172 /* take care of the registers */
1173 if (areqs.reg_mask_len > 0)
1178 for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++)
1180 QUIT; /* allow user to bail out with ^C */
1181 if (areqs.reg_mask[ndx1] != 0)
1183 /* assume chars have 8 bits */
1184 for (ndx2 = 0; ndx2 < 8; ndx2++)
1185 if (areqs.reg_mask[ndx1] & (1 << ndx2))
1186 /* it's used -- record it */
1187 add_register (collect,
1194 do_cleanups (old_chain);
1197 while (action_exp && *action_exp++ == ',');
1199 else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
1201 collect = &stepping_list;
1203 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
1205 if (collect == &stepping_list) /* end stepping actions */
1206 collect = &tracepoint_list;
1208 break; /* end tracepoint actions */
1211 memrange_sortmerge (&tracepoint_list);
1212 memrange_sortmerge (&stepping_list);
1214 *tdp_actions = stringify_collection_list (&tracepoint_list,
1216 *stepping_actions = stringify_collection_list (&stepping_list,
1221 add_aexpr (struct collection_list *collect, struct agent_expr *aexpr)
1223 if (collect->next_aexpr_elt >= collect->aexpr_listsize)
1225 collect->aexpr_list =
1226 xrealloc (collect->aexpr_list,
1227 2 * collect->aexpr_listsize * sizeof (struct agent_expr *));
1228 collect->aexpr_listsize *= 2;
1230 collect->aexpr_list[collect->next_aexpr_elt] = aexpr;
1231 collect->next_aexpr_elt++;
1234 static char *target_buf;
1235 static long target_buf_size;
1237 /* Set "transparent" memory ranges
1239 Allow trace mechanism to treat text-like sections
1240 (and perhaps all read-only sections) transparently,
1241 i.e. don't reject memory requests from these address ranges
1242 just because they haven't been collected. */
1245 remote_set_transparent_ranges (void)
1247 extern bfd *exec_bfd;
1254 return; /* No information to give. */
1256 strcpy (target_buf, "QTro");
1257 for (s = exec_bfd->sections; s; s = s->next)
1259 char tmp1[40], tmp2[40];
1261 if ((s->flags & SEC_LOAD) == 0 ||
1262 /* (s->flags & SEC_CODE) == 0 || */
1263 (s->flags & SEC_READONLY) == 0)
1268 size = bfd_get_section_size (s);
1269 sprintf_vma (tmp1, lma);
1270 sprintf_vma (tmp2, lma + size);
1271 sprintf (target_buf + strlen (target_buf),
1272 ":%s,%s", tmp1, tmp2);
1276 putpkt (target_buf);
1277 getpkt (&target_buf, &target_buf_size, 0);
1283 Tell target to clear any previous trace experiment.
1284 Walk the list of tracepoints, and send them (and their actions)
1285 to the target. If no errors,
1286 Tell target to start a new trace experiment. */
1288 void download_tracepoint (struct breakpoint *t);
1291 trace_start_command (char *args, int from_tty)
1293 VEC(breakpoint_p) *tp_vec = NULL;
1295 struct breakpoint *t;
1297 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1299 if (target_is_remote ())
1302 remote_get_noisy_reply (&target_buf, &target_buf_size);
1303 if (strcmp (target_buf, "OK"))
1304 error (_("Target does not support this command."));
1306 tp_vec = all_tracepoints ();
1307 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
1309 download_tracepoint (t);
1311 VEC_free (breakpoint_p, tp_vec);
1313 /* Tell target to treat text-like sections as transparent. */
1314 remote_set_transparent_ranges ();
1315 /* Now insert traps and begin collecting data. */
1317 remote_get_noisy_reply (&target_buf, &target_buf_size);
1318 if (strcmp (target_buf, "OK"))
1319 error (_("Bogus reply from target: %s"), target_buf);
1320 set_traceframe_num (-1); /* All old traceframes invalidated. */
1321 set_tracepoint_num (-1);
1322 set_traceframe_context (-1);
1323 trace_running_p = 1;
1324 if (deprecated_trace_start_stop_hook)
1325 deprecated_trace_start_stop_hook (1, from_tty);
1329 error (_("Trace can only be run on remote targets."));
1332 /* Send the definition of a single tracepoint to the target. */
1335 download_tracepoint (struct breakpoint *t)
1340 char **stepping_actions;
1342 struct cleanup *old_chain = NULL;
1344 sprintf_vma (tmp, (t->loc ? t->loc->address : 0));
1345 sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", t->number,
1347 (t->enable_state == bp_enabled ? 'E' : 'D'),
1348 t->step_count, t->pass_count);
1353 remote_get_noisy_reply (&target_buf, &target_buf_size);
1354 if (strcmp (target_buf, "OK"))
1355 error (_("Target does not support tracepoints."));
1360 encode_actions (t, &tdp_actions, &stepping_actions);
1361 old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
1363 (void) make_cleanup (free_actions_list_cleanup_wrapper, stepping_actions);
1365 /* do_single_steps (t); */
1368 for (ndx = 0; tdp_actions[ndx]; ndx++)
1370 QUIT; /* allow user to bail out with ^C */
1371 sprintf (buf, "QTDP:-%x:%s:%s%c",
1372 t->number, tmp, /* address */
1374 ((tdp_actions[ndx + 1] || stepping_actions)
1377 remote_get_noisy_reply (&target_buf,
1379 if (strcmp (target_buf, "OK"))
1380 error (_("Error on target while setting tracepoints."));
1383 if (stepping_actions)
1385 for (ndx = 0; stepping_actions[ndx]; ndx++)
1387 QUIT; /* allow user to bail out with ^C */
1388 sprintf (buf, "QTDP:-%x:%s:%s%s%s",
1389 t->number, tmp, /* address */
1390 ((ndx == 0) ? "S" : ""),
1391 stepping_actions[ndx],
1392 (stepping_actions[ndx + 1] ? "-" : ""));
1394 remote_get_noisy_reply (&target_buf,
1396 if (strcmp (target_buf, "OK"))
1397 error (_("Error on target while setting tracepoints."));
1400 do_cleanups (old_chain);
1405 trace_stop_command (char *args, int from_tty)
1407 if (target_is_remote ())
1410 remote_get_noisy_reply (&target_buf, &target_buf_size);
1411 if (strcmp (target_buf, "OK"))
1412 error (_("Bogus reply from target: %s"), target_buf);
1413 trace_running_p = 0;
1414 if (deprecated_trace_start_stop_hook)
1415 deprecated_trace_start_stop_hook (0, from_tty);
1418 error (_("Trace can only be run on remote targets."));
1421 unsigned long trace_running_p;
1423 /* tstatus command */
1425 trace_status_command (char *args, int from_tty)
1427 if (target_is_remote ())
1429 putpkt ("qTStatus");
1430 remote_get_noisy_reply (&target_buf, &target_buf_size);
1432 if (target_buf[0] != 'T' ||
1433 (target_buf[1] != '0' && target_buf[1] != '1'))
1434 error (_("Bogus reply from target: %s"), target_buf);
1436 /* exported for use by the GUI */
1437 trace_running_p = (target_buf[1] == '1');
1440 error (_("Trace can only be run on remote targets."));
1443 /* Worker function for the various flavors of the tfind command. */
1445 finish_tfind_command (char **msg,
1449 int target_frameno = -1, target_tracept = -1;
1450 CORE_ADDR old_frame_addr;
1451 struct symbol *old_func;
1454 old_frame_addr = get_frame_base (get_current_frame ());
1455 old_func = find_pc_function (read_pc ());
1458 reply = remote_get_noisy_reply (msg, sizeof_msg);
1460 while (reply && *reply)
1464 if ((target_frameno = (int) strtol (++reply, &reply, 16)) == -1)
1466 /* A request for a non-existant trace frame has failed.
1467 Our response will be different, depending on FROM_TTY:
1469 If FROM_TTY is true, meaning that this command was
1470 typed interactively by the user, then give an error
1471 and DO NOT change the state of traceframe_number etc.
1473 However if FROM_TTY is false, meaning that we're either
1474 in a script, a loop, or a user-defined command, then
1475 DON'T give an error, but DO change the state of
1476 traceframe_number etc. to invalid.
1478 The rationalle is that if you typed the command, you
1479 might just have committed a typo or something, and you'd
1480 like to NOT lose your current debugging state. However
1481 if you're in a user-defined command or especially in a
1482 loop, then you need a way to detect that the command
1483 failed WITHOUT aborting. This allows you to write
1484 scripts that search thru the trace buffer until the end,
1485 and then continue on to do something else. */
1488 error (_("Target failed to find requested trace frame."));
1492 printf_filtered ("End of trace buffer.\n");
1493 /* The following will not recurse, since it's
1495 trace_find_command ("-1", from_tty);
1496 reply = NULL; /* Break out of loop
1497 (avoid recursive nonsense). */
1502 if ((target_tracept = (int) strtol (++reply, &reply, 16)) == -1)
1503 error (_("Target failed to find requested trace frame."));
1505 case 'O': /* "OK"? */
1506 if (reply[1] == 'K' && reply[2] == '\0')
1509 error (_("Bogus reply from target: %s"), reply);
1512 error (_("Bogus reply from target: %s"), reply);
1515 reinit_frame_cache ();
1516 registers_changed ();
1517 set_traceframe_num (target_frameno);
1518 set_tracepoint_num (target_tracept);
1519 if (target_frameno == -1)
1520 set_traceframe_context (-1);
1522 set_traceframe_context (read_pc ());
1526 enum print_what print_what;
1528 /* NOTE: in immitation of the step command, try to determine
1529 whether we have made a transition from one function to
1530 another. If so, we'll print the "stack frame" (ie. the new
1531 function and it's arguments) -- otherwise we'll just show the
1534 This determination is made by checking (1) whether the
1535 current function has changed, and (2) whether the current FP
1536 has changed. Hack: if the FP wasn't collected, either at the
1537 current or the previous frame, assume that the FP has NOT
1540 if (old_func == find_pc_function (read_pc ()) &&
1541 (old_frame_addr == 0 ||
1542 get_frame_base (get_current_frame ()) == 0 ||
1543 old_frame_addr == get_frame_base (get_current_frame ())))
1544 print_what = SRC_LINE;
1546 print_what = SRC_AND_LOC;
1548 print_stack_frame (get_selected_frame (NULL), 1, print_what);
1553 /* trace_find_command takes a trace frame number n,
1554 sends "QTFrame:<n>" to the target,
1555 and accepts a reply that may contain several optional pieces
1556 of information: a frame number, a tracepoint number, and an
1557 indication of whether this is a trap frame or a stepping frame.
1559 The minimal response is just "OK" (which indicates that the
1560 target does not give us a frame number or a tracepoint number).
1561 Instead of that, the target may send us a string containing
1563 F<hexnum> (gives the selected frame number)
1564 T<hexnum> (gives the selected tracepoint number)
1569 trace_find_command (char *args, int from_tty)
1570 { /* this should only be called with a numeric argument */
1573 if (target_is_remote ())
1575 if (deprecated_trace_find_hook)
1576 deprecated_trace_find_hook (args, from_tty);
1578 if (args == 0 || *args == 0)
1579 { /* TFIND with no args means find NEXT trace frame. */
1580 if (traceframe_number == -1)
1581 frameno = 0; /* "next" is first one */
1583 frameno = traceframe_number + 1;
1585 else if (0 == strcmp (args, "-"))
1587 if (traceframe_number == -1)
1588 error (_("not debugging trace buffer"));
1589 else if (from_tty && traceframe_number == 0)
1590 error (_("already at start of trace buffer"));
1592 frameno = traceframe_number - 1;
1595 frameno = parse_and_eval_long (args);
1598 error (_("invalid input (%d is less than zero)"), frameno);
1600 sprintf (target_buf, "QTFrame:%x", frameno);
1601 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1604 error (_("Trace can only be run on remote targets."));
1609 trace_find_end_command (char *args, int from_tty)
1611 trace_find_command ("-1", from_tty);
1616 trace_find_none_command (char *args, int from_tty)
1618 trace_find_command ("-1", from_tty);
1623 trace_find_start_command (char *args, int from_tty)
1625 trace_find_command ("0", from_tty);
1628 /* tfind pc command */
1630 trace_find_pc_command (char *args, int from_tty)
1635 if (target_is_remote ())
1637 if (args == 0 || *args == 0)
1638 pc = read_pc (); /* default is current pc */
1640 pc = parse_and_eval_address (args);
1642 sprintf_vma (tmp, pc);
1643 sprintf (target_buf, "QTFrame:pc:%s", tmp);
1644 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1647 error (_("Trace can only be run on remote targets."));
1650 /* tfind tracepoint command */
1652 trace_find_tracepoint_command (char *args, int from_tty)
1656 if (target_is_remote ())
1658 if (args == 0 || *args == 0)
1660 if (tracepoint_number == -1)
1661 error (_("No current tracepoint -- please supply an argument."));
1663 tdp = tracepoint_number; /* default is current TDP */
1666 tdp = parse_and_eval_long (args);
1668 sprintf (target_buf, "QTFrame:tdp:%x", tdp);
1669 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1672 error (_("Trace can only be run on remote targets."));
1675 /* TFIND LINE command:
1677 This command will take a sourceline for argument, just like BREAK
1678 or TRACE (ie. anything that "decode_line_1" can handle).
1680 With no argument, this command will find the next trace frame
1681 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1684 trace_find_line_command (char *args, int from_tty)
1686 static CORE_ADDR start_pc, end_pc;
1687 struct symtabs_and_lines sals;
1688 struct symtab_and_line sal;
1689 struct cleanup *old_chain;
1690 char startpc_str[40], endpc_str[40];
1692 if (target_is_remote ())
1694 if (args == 0 || *args == 0)
1696 sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
1698 sals.sals = (struct symtab_and_line *)
1699 xmalloc (sizeof (struct symtab_and_line));
1704 sals = decode_line_spec (args, 1);
1708 old_chain = make_cleanup (xfree, sals.sals);
1709 if (sal.symtab == 0)
1711 printf_filtered ("TFIND: No line number information available");
1714 /* This is useful for "info line *0x7f34". If we can't
1715 tell the user about a source line, at least let them
1716 have the symbolic address. */
1717 printf_filtered (" for address ");
1719 print_address (sal.pc, gdb_stdout);
1720 printf_filtered (";\n -- will attempt to find by PC. \n");
1724 printf_filtered (".\n");
1725 return; /* No line, no PC; what can we do? */
1728 else if (sal.line > 0
1729 && find_line_pc_range (sal, &start_pc, &end_pc))
1731 if (start_pc == end_pc)
1733 printf_filtered ("Line %d of \"%s\"",
1734 sal.line, sal.symtab->filename);
1736 printf_filtered (" is at address ");
1737 print_address (start_pc, gdb_stdout);
1739 printf_filtered (" but contains no code.\n");
1740 sal = find_pc_line (start_pc, 0);
1742 find_line_pc_range (sal, &start_pc, &end_pc) &&
1744 printf_filtered ("Attempting to find line %d instead.\n",
1747 error (_("Cannot find a good line."));
1751 /* Is there any case in which we get here, and have an address
1752 which the user would want to see? If we have debugging
1753 symbols and no line numbers? */
1754 error (_("Line number %d is out of range for \"%s\"."),
1755 sal.line, sal.symtab->filename);
1757 sprintf_vma (startpc_str, start_pc);
1758 sprintf_vma (endpc_str, end_pc - 1);
1759 /* Find within range of stated line. */
1761 sprintf (target_buf, "QTFrame:range:%s:%s",
1762 startpc_str, endpc_str);
1763 /* Find OUTSIDE OF range of CURRENT line. */
1765 sprintf (target_buf, "QTFrame:outside:%s:%s",
1766 startpc_str, endpc_str);
1767 finish_tfind_command (&target_buf, &target_buf_size,
1769 do_cleanups (old_chain);
1772 error (_("Trace can only be run on remote targets."));
1775 /* tfind range command */
1777 trace_find_range_command (char *args, int from_tty)
1779 static CORE_ADDR start, stop;
1780 char start_str[40], stop_str[40];
1783 if (target_is_remote ())
1785 if (args == 0 || *args == 0)
1786 { /* XXX FIXME: what should default behavior be? */
1787 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1791 if (0 != (tmp = strchr (args, ',')))
1793 *tmp++ = '\0'; /* terminate start address */
1794 while (isspace ((int) *tmp))
1796 start = parse_and_eval_address (args);
1797 stop = parse_and_eval_address (tmp);
1800 { /* no explicit end address? */
1801 start = parse_and_eval_address (args);
1802 stop = start + 1; /* ??? */
1805 sprintf_vma (start_str, start);
1806 sprintf_vma (stop_str, stop);
1807 sprintf (target_buf, "QTFrame:range:%s:%s", start_str, stop_str);
1808 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1811 error (_("Trace can only be run on remote targets."));
1814 /* tfind outside command */
1816 trace_find_outside_command (char *args, int from_tty)
1818 CORE_ADDR start, stop;
1819 char start_str[40], stop_str[40];
1822 if (target_is_remote ())
1824 if (args == 0 || *args == 0)
1825 { /* XXX FIXME: what should default behavior be? */
1826 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1830 if (0 != (tmp = strchr (args, ',')))
1832 *tmp++ = '\0'; /* terminate start address */
1833 while (isspace ((int) *tmp))
1835 start = parse_and_eval_address (args);
1836 stop = parse_and_eval_address (tmp);
1839 { /* no explicit end address? */
1840 start = parse_and_eval_address (args);
1841 stop = start + 1; /* ??? */
1844 sprintf_vma (start_str, start);
1845 sprintf_vma (stop_str, stop);
1846 sprintf (target_buf, "QTFrame:outside:%s:%s", start_str, stop_str);
1847 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1850 error (_("Trace can only be run on remote targets."));
1853 /* info scope command: list the locals for a scope. */
1855 scope_info (char *args, int from_tty)
1857 struct symtabs_and_lines sals;
1859 struct minimal_symbol *msym;
1860 struct block *block;
1861 char **canonical, *symname, *save_args = args;
1862 struct dict_iterator iter;
1865 if (args == 0 || *args == 0)
1866 error (_("requires an argument (function, line or *addr) to define a scope"));
1868 sals = decode_line_1 (&args, 1, NULL, 0, &canonical, NULL);
1869 if (sals.nelts == 0)
1870 return; /* presumably decode_line_1 has already warned */
1872 /* Resolve line numbers to PC */
1873 resolve_sal_pc (&sals.sals[0]);
1874 block = block_for_pc (sals.sals[0].pc);
1878 QUIT; /* allow user to bail out with ^C */
1879 ALL_BLOCK_SYMBOLS (block, iter, sym)
1881 QUIT; /* allow user to bail out with ^C */
1883 printf_filtered ("Scope for %s:\n", save_args);
1886 symname = SYMBOL_PRINT_NAME (sym);
1887 if (symname == NULL || *symname == '\0')
1888 continue; /* probably botched, certainly useless */
1890 printf_filtered ("Symbol %s is ", symname);
1891 switch (SYMBOL_CLASS (sym))
1894 case LOC_UNDEF: /* messed up symbol? */
1895 printf_filtered ("a bogus symbol, class %d.\n",
1896 SYMBOL_CLASS (sym));
1897 count--; /* don't count this one */
1900 printf_filtered ("a constant with value %ld (0x%lx)",
1901 SYMBOL_VALUE (sym), SYMBOL_VALUE (sym));
1903 case LOC_CONST_BYTES:
1904 printf_filtered ("constant bytes: ");
1905 if (SYMBOL_TYPE (sym))
1906 for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++)
1907 fprintf_filtered (gdb_stdout, " %02x",
1908 (unsigned) SYMBOL_VALUE_BYTES (sym)[j]);
1911 printf_filtered ("in static storage at address ");
1912 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym)));
1915 if (SYMBOL_IS_ARGUMENT (sym))
1916 printf_filtered ("an argument in register $%s",
1917 gdbarch_register_name
1918 (current_gdbarch, SYMBOL_VALUE (sym)));
1920 printf_filtered ("a local variable in register $%s",
1921 gdbarch_register_name
1922 (current_gdbarch, SYMBOL_VALUE (sym)));
1925 printf_filtered ("an argument at stack/frame offset %ld",
1926 SYMBOL_VALUE (sym));
1929 printf_filtered ("a local variable at frame offset %ld",
1930 SYMBOL_VALUE (sym));
1933 printf_filtered ("a reference argument at offset %ld",
1934 SYMBOL_VALUE (sym));
1936 case LOC_REGPARM_ADDR:
1937 printf_filtered ("the address of an argument, in register $%s",
1938 gdbarch_register_name
1939 (current_gdbarch, SYMBOL_VALUE (sym)));
1942 printf_filtered ("a typedef.\n");
1945 printf_filtered ("a label at address ");
1946 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (sym)));
1949 printf_filtered ("a function at address ");
1950 printf_filtered ("%s", paddress (BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
1952 case LOC_UNRESOLVED:
1953 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
1956 printf_filtered ("Unresolved Static");
1959 printf_filtered ("static storage at address ");
1960 printf_filtered ("%s", paddress (SYMBOL_VALUE_ADDRESS (msym)));
1963 case LOC_OPTIMIZED_OUT:
1964 printf_filtered ("optimized out.\n");
1967 SYMBOL_OPS (sym)->describe_location (sym, gdb_stdout);
1970 if (SYMBOL_TYPE (sym))
1971 printf_filtered (", length %d.\n",
1972 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
1974 if (BLOCK_FUNCTION (block))
1977 block = BLOCK_SUPERBLOCK (block);
1980 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1984 /* worker function (cleanup) */
1986 replace_comma (void *data)
1994 trace_dump_command (char *args, int from_tty)
1996 struct regcache *regcache;
1997 struct gdbarch *gdbarch;
1998 struct breakpoint *t;
1999 struct action_line *action;
2000 char *action_exp, *next_comma;
2001 struct cleanup *old_cleanups;
2002 int stepping_actions = 0;
2003 int stepping_frame = 0;
2005 if (!target_is_remote ())
2007 error (_("Trace can only be run on remote targets."));
2011 if (tracepoint_number == -1)
2013 warning (_("No current trace frame."));
2017 t = get_tracepoint (tracepoint_number);
2020 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2023 old_cleanups = make_cleanup (null_cleanup, NULL);
2025 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2026 tracepoint_number, traceframe_number);
2028 /* The current frame is a trap frame if the frame PC is equal
2029 to the tracepoint PC. If not, then the current frame was
2030 collected during single-stepping. */
2032 regcache = get_current_regcache ();
2033 gdbarch = get_regcache_arch (regcache);
2035 stepping_frame = (t->loc->address != (regcache_read_pc (regcache)
2036 - gdbarch_decr_pc_after_break (gdbarch)));
2038 for (action = t->actions; action; action = action->next)
2040 struct cmd_list_element *cmd;
2042 QUIT; /* allow user to bail out with ^C */
2043 action_exp = action->action;
2044 while (isspace ((int) *action_exp))
2047 /* The collection actions to be done while stepping are
2048 bracketed by the commands "while-stepping" and "end". */
2050 if (*action_exp == '#') /* comment line */
2053 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
2055 error (_("Bad action list item: %s"), action_exp);
2057 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
2058 stepping_actions = 1;
2059 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
2060 stepping_actions = 0;
2061 else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
2063 /* Display the collected data.
2064 For the trap frame, display only what was collected at
2065 the trap. Likewise for stepping frames, display only
2066 what was collected while stepping. This means that the
2067 two boolean variables, STEPPING_FRAME and
2068 STEPPING_ACTIONS should be equal. */
2069 if (stepping_frame == stepping_actions)
2072 { /* repeat over a comma-separated list */
2073 QUIT; /* allow user to bail out with ^C */
2074 if (*action_exp == ',')
2076 while (isspace ((int) *action_exp))
2079 next_comma = strchr (action_exp, ',');
2081 if (0 == strncasecmp (action_exp, "$reg", 4))
2082 registers_info (NULL, from_tty);
2083 else if (0 == strncasecmp (action_exp, "$loc", 4))
2084 locals_info (NULL, from_tty);
2085 else if (0 == strncasecmp (action_exp, "$arg", 4))
2086 args_info (NULL, from_tty);
2091 make_cleanup (replace_comma, next_comma);
2094 printf_filtered ("%s = ", action_exp);
2095 output_command (action_exp, from_tty);
2096 printf_filtered ("\n");
2100 action_exp = next_comma;
2102 while (action_exp && *action_exp == ',');
2106 discard_cleanups (old_cleanups);
2109 /* Convert the memory pointed to by mem into hex, placing result in buf.
2110 * Return a pointer to the last char put in buf (null)
2111 * "stolen" from sparc-stub.c
2114 static const char hexchars[] = "0123456789abcdef";
2117 mem2hex (gdb_byte *mem, char *buf, int count)
2125 *buf++ = hexchars[ch >> 4];
2126 *buf++ = hexchars[ch & 0xf];
2135 get_traceframe_number (void)
2137 return traceframe_number;
2141 /* module initialization */
2143 _initialize_tracepoint (void)
2145 struct cmd_list_element *c;
2147 traceframe_number = -1;
2148 tracepoint_number = -1;
2150 if (tracepoint_list.list == NULL)
2152 tracepoint_list.listsize = 128;
2153 tracepoint_list.list = xmalloc
2154 (tracepoint_list.listsize * sizeof (struct memrange));
2156 if (tracepoint_list.aexpr_list == NULL)
2158 tracepoint_list.aexpr_listsize = 128;
2159 tracepoint_list.aexpr_list = xmalloc
2160 (tracepoint_list.aexpr_listsize * sizeof (struct agent_expr *));
2163 if (stepping_list.list == NULL)
2165 stepping_list.listsize = 128;
2166 stepping_list.list = xmalloc
2167 (stepping_list.listsize * sizeof (struct memrange));
2170 if (stepping_list.aexpr_list == NULL)
2172 stepping_list.aexpr_listsize = 128;
2173 stepping_list.aexpr_list = xmalloc
2174 (stepping_list.aexpr_listsize * sizeof (struct agent_expr *));
2177 add_info ("scope", scope_info,
2178 _("List the variables local to a scope"));
2180 add_cmd ("tracepoints", class_trace, NULL,
2181 _("Tracing of program execution without stopping the program."),
2184 add_com ("tdump", class_trace, trace_dump_command,
2185 _("Print everything collected at the current tracepoint."));
2187 add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\
2188 Select a trace frame;\n\
2189 No argument means forward by one frame; '-' means backward by one frame."),
2190 &tfindlist, "tfind ", 1, &cmdlist);
2192 add_cmd ("outside", class_trace, trace_find_outside_command, _("\
2193 Select a trace frame whose PC is outside the given range.\n\
2194 Usage: tfind outside addr1, addr2"),
2197 add_cmd ("range", class_trace, trace_find_range_command, _("\
2198 Select a trace frame whose PC is in the given range.\n\
2199 Usage: tfind range addr1,addr2"),
2202 add_cmd ("line", class_trace, trace_find_line_command, _("\
2203 Select a trace frame by source line.\n\
2204 Argument can be a line number (with optional source file), \n\
2205 a function name, or '*' followed by an address.\n\
2206 Default argument is 'the next source line that was traced'."),
2209 add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, _("\
2210 Select a trace frame by tracepoint number.\n\
2211 Default is the tracepoint for the current trace frame."),
2214 add_cmd ("pc", class_trace, trace_find_pc_command, _("\
2215 Select a trace frame by PC.\n\
2216 Default is the current PC, or the PC of the current trace frame."),
2219 add_cmd ("end", class_trace, trace_find_end_command, _("\
2220 Synonym for 'none'.\n\
2221 De-select any trace frame and resume 'live' debugging."),
2224 add_cmd ("none", class_trace, trace_find_none_command,
2225 _("De-select any trace frame and resume 'live' debugging."),
2228 add_cmd ("start", class_trace, trace_find_start_command,
2229 _("Select the first trace frame in the trace buffer."),
2232 add_com ("tstatus", class_trace, trace_status_command,
2233 _("Display the status of the current trace data collection."));
2235 add_com ("tstop", class_trace, trace_stop_command,
2236 _("Stop trace data collection."));
2238 add_com ("tstart", class_trace, trace_start_command,
2239 _("Start trace data collection."));
2241 add_com ("end", class_trace, end_actions_pseudocommand, _("\
2242 Ends a list of commands or actions.\n\
2243 Several GDB commands allow you to enter a list of commands or actions.\n\
2244 Entering \"end\" on a line by itself is the normal way to terminate\n\
2246 Note: the \"end\" command cannot be used at the gdb prompt."));
2248 add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\
2249 Specify single-stepping behavior at a tracepoint.\n\
2250 Argument is number of instructions to trace in single-step mode\n\
2251 following the tracepoint. This command is normally followed by\n\
2252 one or more \"collect\" commands, to specify what to collect\n\
2253 while single-stepping.\n\n\
2254 Note: this command can only be used in a tracepoint \"actions\" list."));
2256 add_com_alias ("ws", "while-stepping", class_alias, 0);
2257 add_com_alias ("stepping", "while-stepping", class_alias, 0);
2259 add_com ("collect", class_trace, collect_pseudocommand, _("\
2260 Specify one or more data items to be collected at a tracepoint.\n\
2261 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2262 collect all data (variables, registers) referenced by that expression.\n\
2263 Also accepts the following special arguments:\n\
2264 $regs -- all registers.\n\
2265 $args -- all function arguments.\n\
2266 $locals -- all variables local to the block/function scope.\n\
2267 Note: this command can only be used in a tracepoint \"actions\" list."));
2269 add_com ("actions", class_trace, trace_actions_command, _("\
2270 Specify the actions to be taken at a tracepoint.\n\
2271 Tracepoint actions may include collecting of specified data, \n\
2272 single-stepping, or enabling/disabling other tracepoints, \n\
2273 depending on target's capabilities."));
2275 target_buf_size = 2048;
2276 target_buf = xmalloc (target_buf_size);