1 /* Tracing functionality for remote targets in custom GDB protocol
2 Copyright 1997 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "tracepoint.h"
25 #include "expression.h"
30 #include "gdb_string.h"
32 /* readline include files */
36 /* readline defines this. */
43 extern int info_verbose;
45 /* If this definition isn't overridden by the header files, assume
46 that isatty and fileno exist on this system. */
48 #define ISATTY(FP) (isatty (fileno (FP)))
51 /* Chain of all tracepoints defined. */
52 struct tracepoint *tracepoint_chain;
54 /* Number of last tracepoint made. */
55 static int tracepoint_count;
57 /* Number of last traceframe collected. */
58 static int traceframe_number;
60 /* Tracepoint for last traceframe collected. */
61 static int tracepoint_number;
63 /* Symbol for function for last traceframe collected */
64 static struct symbol *traceframe_fun;
66 /* Symtab and line for last traceframe collected */
67 static struct symtab_and_line traceframe_sal;
69 /* Utility: returns true if "target remote" */
73 if (current_target.to_shortname &&
74 strcmp (current_target.to_shortname, "remote") == 0)
80 /* Utility: generate error from an incoming stub packet. */
86 return; /* not an error msg */
89 case '1': /* malformed packet error */
90 if (*++buf == '0') /* general case: */
91 error ("tracepoint.c: error in outgoing packet.");
93 error ("tracepoint.c: error in outgoing packet at field #%d.",
94 strtol (buf, NULL, 16));
96 error ("trace API error 0x%s.", ++buf);
98 error ("Target returns error code '%s'.", buf);
102 /* Obsolete: collect regs from a trace frame */
104 trace_receive_regs (buf)
108 char regbuf[MAX_REGISTER_RAW_SIZE], *tmp, *p = buf;
112 regno = strtol (p, &tmp, 16);
113 if (p == tmp || *tmp++ != ':')
114 error ("tracepoint.c: malformed 'R' packet");
117 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
119 if (p[0] == 0 || p[1] == 0)
120 warning ("Remote reply is too short: %s", buf);
121 regbuf[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
126 error ("tracepoint.c: malformed 'R' packet");
128 supply_register (regno, regbuf);
132 /* Utility: wait for reply from stub, while accepting "O" packets */
134 remote_get_noisy_reply (buf)
137 do /* loop on reply from remote stub */
141 error ("Target does not support this command.");
142 else if (buf[0] == 'E')
144 else if (buf[0] == 'R')
146 flush_cached_frames ();
147 registers_changed ();
148 select_frame (get_current_frame (), 0);
149 trace_receive_regs (buf);
151 else if (buf[0] == 'O' &&
153 remote_console_output (buf + 1); /* 'O' message from stub */
155 return buf; /* here's the actual reply */
159 /* Set tracepoint count to NUM. */
161 set_tracepoint_count (num)
164 tracepoint_count = num;
165 set_internalvar (lookup_internalvar ("tpnum"),
166 value_from_longest (builtin_type_int, (LONGEST) num));
169 /* Set traceframe number to NUM. */
171 set_traceframe_num (num)
174 traceframe_number = num;
175 set_internalvar (lookup_internalvar ("trace_frame"),
176 value_from_longest (builtin_type_int, (LONGEST) num));
179 /* Set tracepoint number to NUM. */
181 set_tracepoint_num (num)
184 tracepoint_number = num;
185 set_internalvar (lookup_internalvar ("tracepoint"),
186 value_from_longest (builtin_type_int, (LONGEST) num));
189 /* Set externally visible debug variables for querying/printing
190 the traceframe context (line, function, file) */
193 set_traceframe_context (trace_pc)
196 static struct type *func_string, *file_string;
197 static struct type *func_range, *file_range;
198 static value_ptr func_val, file_val;
199 static struct type *charstar;
202 if (charstar == (struct type *) NULL)
203 charstar = lookup_pointer_type (builtin_type_char);
205 if (trace_pc == -1) /* cease debugging any trace buffers */
208 traceframe_sal.pc = traceframe_sal.line = 0;
209 traceframe_sal.symtab = NULL;
210 set_internalvar (lookup_internalvar ("trace_func"),
211 value_from_longest (charstar, (LONGEST) 0));
212 set_internalvar (lookup_internalvar ("trace_file"),
213 value_from_longest (charstar, (LONGEST) 0));
214 set_internalvar (lookup_internalvar ("trace_line"),
215 value_from_longest (builtin_type_int, (LONGEST) -1));
219 /* save as globals for internal use */
220 traceframe_sal = find_pc_line (trace_pc, 0);
221 traceframe_fun = find_pc_function (trace_pc);
223 /* save linenumber as "$trace_line", a debugger variable visible to users */
224 set_internalvar (lookup_internalvar ("trace_line"),
225 value_from_longest (builtin_type_int,
226 (LONGEST) traceframe_sal.line));
228 /* save func name as "$trace_func", a debugger variable visible to users */
229 if (traceframe_fun == NULL ||
230 SYMBOL_NAME (traceframe_fun) == NULL)
231 set_internalvar (lookup_internalvar ("trace_func"),
232 value_from_longest (charstar, (LONGEST) 0));
235 len = strlen (SYMBOL_NAME (traceframe_fun));
236 func_range = create_range_type (func_range,
237 builtin_type_int, 0, len - 1);
238 func_string = create_array_type (func_string,
239 builtin_type_char, func_range);
240 func_val = allocate_value (func_string);
241 VALUE_TYPE (func_val) = func_string;
242 memcpy (VALUE_CONTENTS_RAW (func_val),
243 SYMBOL_NAME (traceframe_fun),
245 func_val->modifiable = 0;
246 set_internalvar (lookup_internalvar ("trace_func"), func_val);
249 /* save file name as "$trace_file", a debugger variable visible to users */
250 if (traceframe_sal.symtab == NULL ||
251 traceframe_sal.symtab->filename == NULL)
252 set_internalvar (lookup_internalvar ("trace_file"),
253 value_from_longest (charstar, (LONGEST) 0));
256 len = strlen (traceframe_sal.symtab->filename);
257 file_range = create_range_type (file_range,
258 builtin_type_int, 0, len - 1);
259 file_string = create_array_type (file_string,
260 builtin_type_char, file_range);
261 file_val = allocate_value (file_string);
262 VALUE_TYPE (file_val) = file_string;
263 memcpy (VALUE_CONTENTS_RAW (file_val),
264 traceframe_sal.symtab->filename,
266 file_val->modifiable = 0;
267 set_internalvar (lookup_internalvar ("trace_file"), file_val);
271 /* Low level routine to set a tracepoint.
272 Returns the tracepoint object so caller can set other things.
273 Does not set the tracepoint number!
274 Does not print anything.
276 ==> This routine should not be called if there is a chance of later
277 error(); otherwise it leaves a bogus tracepoint on the chain. Validate
278 your arguments BEFORE calling this routine! */
280 static struct tracepoint *
281 set_raw_tracepoint (sal)
282 struct symtab_and_line sal;
284 register struct tracepoint *t, *tc;
285 struct cleanup *old_chain;
287 t = (struct tracepoint *) xmalloc (sizeof (struct tracepoint));
288 old_chain = make_cleanup (free, t);
289 memset (t, 0, sizeof (*t));
291 if (sal.symtab == NULL)
292 t->source_file = NULL;
297 t->source_file = (char *) xmalloc (strlen (sal.symtab->filename) +
298 strlen (sal.symtab->dirname) + 2);
300 strcpy (t->source_file, sal.symtab->dirname);
303 if (*p != '/') /* Will this work on Windows? */
304 strcat (t->source_file, "/");
305 strcat (t->source_file, sal.symtab->filename);
308 t->language = current_language->la_language;
309 t->input_radix = input_radix;
310 t->line_number = sal.line;
311 t->enabled = enabled;
316 /* Add this tracepoint to the end of the chain
317 so that a list of tracepoints will come out in order
318 of increasing numbers. */
320 tc = tracepoint_chain;
322 tracepoint_chain = t;
329 discard_cleanups (old_chain);
334 trace_command (arg, from_tty)
338 char **canonical = (char **)NULL;
339 struct symtabs_and_lines sals;
340 struct symtab_and_line sal;
341 struct tracepoint *t;
342 char *addr_start = 0, *addr_end = 0, *cond_start = 0, *cond_end = 0;
346 error ("trace command requires an argument");
348 if (from_tty && info_verbose)
349 printf_filtered ("TRACE %s\n", arg);
357 sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical);
360 return; /* ??? Presumably decode_line_1 has already warned? */
362 /* Resolve all line numbers to PC's */
363 for (i = 0; i < sals.nelts; i++)
364 resolve_sal_pc (&sals.sals[i]);
366 /* Now set all the tracepoints. */
367 for (i = 0; i < sals.nelts; i++)
371 t = set_raw_tracepoint (sal);
372 set_tracepoint_count (tracepoint_count + 1);
373 t->number = tracepoint_count;
375 /* If a canonical line spec is needed use that instead of the
377 if (canonical != (char **)NULL && canonical[i] != NULL)
378 t->addr_string = canonical[i];
380 t->addr_string = savestring (addr_start, addr_end - addr_start);
382 t->cond_string = savestring (cond_start, cond_end - cond_start);
384 /* Let the UI know of any additions */
385 if (create_tracepoint_hook)
386 create_tracepoint_hook (t);
391 printf_filtered ("Multiple tracepoints were set.\n");
392 printf_filtered ("Use the \"delete\" command to delete unwanted tracepoints.\n");
397 tracepoints_info (tpnum_exp, from_tty)
401 struct tracepoint *t;
402 struct action_line *action;
403 int found_a_tracepoint = 0;
404 char wrap_indent[80];
408 char *i1 = "\t", *i2 = "\t ";
409 char *indent, *actionline;;
413 tpnum = parse_and_eval_address (tpnum_exp);
416 if (tpnum == -1 || tpnum == t->number)
418 extern int addressprint; /* print machine addresses? */
420 if (!found_a_tracepoint++)
422 printf_filtered ("Num Enb ");
424 printf_filtered ("Address ");
425 printf_filtered ("PassC StepC What\n");
427 strcpy (wrap_indent, " ");
429 strcat (wrap_indent, " ");
431 printf_filtered ("%-3d %-3s ", t->number,
432 t->enabled == enabled ? "y" : "n");
434 printf_filtered ("%s ",
435 local_hex_string_custom ((unsigned long) t->address,
437 printf_filtered ("%-5d %-5d ", t->pass_count, t->step_count);
441 sym = find_pc_function (t->address);
444 fputs_filtered ("in ", gdb_stdout);
445 fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout);
446 wrap_here (wrap_indent);
447 fputs_filtered (" at ", gdb_stdout);
449 fputs_filtered (t->source_file, gdb_stdout);
450 printf_filtered (":%d", t->line_number);
453 print_address_symbolic (t->address, gdb_stdout, demangle, " ");
455 printf_filtered ("\n");
458 printf_filtered (" Actions for tracepoint %d: \n", t->number);
460 for (action = t->actions; action; action = action->next)
463 actionline = action->action;
464 while (isspace(*actionline))
467 printf_filtered ("%s%s\n", indent, actionline);
468 if (0 == strncasecmp (actionline, "while-stepping", 14))
470 else if (0 == strncasecmp (actionline, "end", 3))
473 printf_filtered ("\t%s\n", action->action);
478 if (!found_a_tracepoint)
481 printf_filtered ("No tracepoints.\n");
483 printf_filtered ("No tracepoint number %d.\n", tpnum);
487 /* Optimization: the code to parse an enable, disable, or delete TP command
488 is virtually identical except for whether it performs an enable, disable,
489 or delete. Therefore I've combined them into one function with an opcode.
491 enum tracepoint_opcode
498 /* This function implements enable, disable and delete. */
500 tracepoint_operation (t, from_tty, opcode)
501 struct tracepoint *t;
503 enum tracepoint_opcode opcode;
505 struct tracepoint *t2;
506 struct action_line *action, *next;
510 t->enabled = enabled;
513 t->enabled = disabled;
516 if (tracepoint_chain == t)
517 tracepoint_chain = t->next;
526 /* Let the UI know of any deletions */
527 if (delete_tracepoint_hook)
528 delete_tracepoint_hook (t);
531 free (t->cond_string);
533 free (t->addr_string);
535 free (t->source_file);
536 for (action = t->actions; action; action = next)
540 free (action->action);
548 /* Utility: parse a tracepoint number and look it up in the list. */
550 get_tracepoint_by_number (arg)
553 struct tracepoint *t;
559 error ("Bad tracepoint argument");
561 if (*arg == 0 || **arg == 0) /* empty arg means refer to last tp */
562 tpnum = tracepoint_count;
563 else if (**arg == '$') /* handle convenience variable */
565 /* Make a copy of the name, so we can null-terminate it
566 to pass to lookup_internalvar(). */
568 while (isalnum(*end) || *end == '_')
570 copy = (char *) alloca (end - *arg);
571 strncpy (copy, *arg + 1, (end - *arg - 1));
572 copy[end - *arg - 1] = '\0';
575 val = value_of_internalvar (lookup_internalvar (copy));
576 if (TYPE_CODE( VALUE_TYPE (val)) != TYPE_CODE_INT)
577 error ("Convenience variable must have integral type.");
578 tpnum = (int) value_as_long (val);
580 else /* handle tracepoint number */
582 tpnum = strtol (*arg, arg, 10);
585 if (t->number == tpnum)
589 warning ("No tracepoint number %d.\n", tpnum);
593 /* Utility: parse a list of tracepoint numbers, and call a func for each. */
595 map_args_over_tracepoints (args, from_tty, opcode)
598 enum tracepoint_opcode opcode;
600 struct tracepoint *t;
604 if (args == 0 || *args == 0) /* do them all */
606 tracepoint_operation (t, from_tty, opcode);
610 if (t = get_tracepoint_by_number (&args))
611 tracepoint_operation (t, from_tty, opcode);
612 while (*args == ' ' || *args == '\t')
618 enable_trace_command (args, from_tty)
623 map_args_over_tracepoints (args, from_tty, enable);
627 disable_trace_command (args, from_tty)
632 map_args_over_tracepoints (args, from_tty, disable);
636 delete_trace_command (args, from_tty)
642 if (!query ("Delete all tracepoints? "))
645 map_args_over_tracepoints (args, from_tty, delete);
649 trace_pass_command (args, from_tty)
653 struct tracepoint *t1 = (struct tracepoint *) -1, *t2;
656 if (args == 0 || *args == 0)
657 error ("PASS command requires an argument (count + optional TP num)");
659 count = strtoul (args, &args, 10); /* count comes first, then TP num */
661 while (*args && isspace (*args))
664 if (*args && strncasecmp (args, "all", 3) == 0)
665 args += 3; /* skip special argument "all" */
667 t1 = get_tracepoint_by_number (&args);
670 return; /* error, bad tracepoint number */
673 if (t1 == (struct tracepoint *) -1 || t1 == t2)
675 t2->pass_count = count;
677 printf_filtered ("Setting tracepoint %d's passcount to %d\n",
682 /* ACTIONS ACTIONS ACTIONS */
684 static void read_actions PARAMS((struct tracepoint *));
685 static void free_actions PARAMS((struct tracepoint *));
686 static int validate_actionline PARAMS((char *, struct tracepoint *));
689 end_pseudocom (args, from_tty)
691 error ("This command cannot be used at the top level.");
695 while_stepping_pseudocom (args, from_tty)
697 error ("This command can only be used in a tracepoint actions list.");
701 collect_pseudocom (args, from_tty)
703 error ("This command can only be used in a tracepoint actions list.");
707 trace_actions_command (args, from_tty)
711 struct tracepoint *t;
714 if (t = get_tracepoint_by_number (&args))
717 printf_filtered ("Enter actions for tracepoint %d, one per line.\n",
721 /* tracepoints_changed () */
723 /* else error, just return; */
736 struct tracepoint *t;
739 char *prompt1 = "> ", *prompt2 = " > ";
740 char *prompt = prompt1;
741 enum actionline_type linetype;
742 extern FILE *instream;
743 struct action_line *next = NULL, *temp;
744 struct cleanup *old_chain;
746 /* Control-C quits instantly if typed while in this loop
747 since it should not wait until the user types a newline. */
751 signal (STOP_SIGNAL, stop_sig);
753 old_chain = make_cleanup (free_actions, (void *) t);
756 /* Make sure that all output has been output. Some machines may let
757 you get away with leaving out some of the gdb_flush, but not all. */
759 gdb_flush (gdb_stdout);
760 gdb_flush (gdb_stderr);
761 if (instream == stdin && ISATTY (instream))
762 line = readline (prompt);
764 line = gdb_readline (0);
766 linetype = validate_actionline (line, t);
767 if (linetype == BADLINE)
768 continue; /* already warned -- collect another line */
770 temp = xmalloc (sizeof (struct action_line));
774 if (next == NULL) /* first action for this tracepoint? */
775 t->actions = next = temp;
782 if (linetype == STEPPING) /* begin "while-stepping" */
783 if (prompt == prompt2)
785 warning ("Already processing 'while-stepping'");
789 prompt = prompt2; /* change prompt for stepping actions */
790 else if (linetype == END)
791 if (prompt == prompt2)
792 prompt = prompt1; /* end of single-stepping actions */
794 break; /* end of actions */
798 signal (STOP_SIGNAL, SIG_DFL);
801 discard_cleanups (old_chain);
805 parse_and_eval_memrange (arg, addr, typecode, offset, size)
808 long *typecode, *size;
809 bfd_signed_vma *offset;
812 struct expression *exp;
814 if (*arg++ != '$' || *arg++ != '(')
815 error ("Internal: bad argument to validate_memrange: %s", start);
817 if (*arg == '$') /* register for relative memrange? */
819 exp = parse_exp_1 (&arg, block_for_pc (addr), 1);
820 if (exp->elts[0].opcode != OP_REGISTER)
821 error ("Bad register operand for memrange: %s", start);
823 error ("missing comma for memrange: %s", start);
824 *typecode = exp->elts[1].longconst;
830 /* While attractive, this fails for a number of reasons:
831 1) parse_and_eval_address does not deal with trailing commas,
833 2) There is no safeguard against the user trying to use
834 an out-of-scope variable in an address expression (for instance).
835 2.5) If you are going to allow semi-arbitrary expressions, you
836 would need to explain which expressions are allowed, and
837 which are not (which would provoke endless questions).
838 3) If you are going to allow semi-arbitrary expressions in the
839 offset and size fields, then the leading "$" of a register
840 name no longer disambiguates the typecode field.
843 *offset = parse_and_eval_address (arg);
844 if ((arg = strchr (arg, ',')) == NULL)
845 error ("missing comma for memrange: %s", start);
849 *size = parse_and_eval_address (arg);
850 if ((arg = strchr (arg, ')')) == NULL)
851 error ("missing close-parenthesis for memrange: %s", start);
856 /* This, on the other hand, doesn't work because "-1" is an
857 expression, not an OP_LONG! Fall back to using strtol for now. */
859 exp = parse_exp_1 (&arg, block_for_pc (addr), 1);
860 if (exp->elts[0].opcode != OP_LONG)
861 error ("Bad offset operand for memrange: %s", start);
862 *offset = exp->elts[2].longconst;
865 error ("missing comma for memrange: %s", start);
867 exp = parse_exp_1 (&arg, block_for_pc (addr), 1);
868 if (exp->elts[0].opcode != OP_LONG)
869 error ("Bad size operand for memrange: %s", start);
870 *size = exp->elts[2].longconst;
873 error ("invalid size in memrange: %s", start);
876 error ("missing close-parenthesis for memrange: %s", start);
878 *offset = strtol (arg, &arg, 0);
880 error ("missing comma for memrange: %s", start);
881 *size = strtol (arg, &arg, 0);
883 error ("invalid size in memrange: %s", start);
885 error ("missing close-parenthesis for memrange: %s", start);
889 printf_filtered ("Collecting memrange: (0x%x,0x%x,0x%x)\n",
890 *typecode, *offset, *size);
895 static enum actionline_type
896 validate_actionline (line, t)
898 struct tracepoint *t;
901 struct expression *exp;
902 value_ptr temp, temp2;
904 for (p = line; isspace (*p); )
907 /* symbol lookup etc. */
908 if (*p == '\0') /* empty line: just prompt for another line. */
910 else if (0 == strncasecmp (p, "collect", 7))
913 do { /* repeat over a comma-separated list */
917 if (*p == '$') /* look for special pseudo-symbols */
920 bfd_signed_vma offset;
922 if ((0 == strncasecmp ("reg", p + 1, 3)) ||
923 (0 == strncasecmp ("arg", p + 1, 3)) ||
924 (0 == strncasecmp ("loc", p + 1, 3)))
927 else if (p[1] == '(') /* literal memrange */
928 p = parse_and_eval_memrange (p, t->address,
929 &typecode, &offset, &size);
933 exp = parse_exp_1 (&p, block_for_pc (t->address), 1);
935 if (exp->elts[0].opcode != OP_VAR_VALUE &&
936 /*exp->elts[0].opcode != OP_LONG && */
937 /*exp->elts[0].opcode != UNOP_CAST && */
938 exp->elts[0].opcode != OP_REGISTER)
940 warning ("collect: enter variable name or register.\n");
943 if (exp->elts[0].opcode == OP_VAR_VALUE)
944 if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
946 warning ("%s is constant (value %d): will not be collected.",
947 SYMBOL_NAME (exp->elts[2].symbol),
948 SYMBOL_VALUE (exp->elts[2].symbol));
951 else if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_OPTIMIZED_OUT)
953 warning ("%s is optimized away and cannot be collected.",
954 SYMBOL_NAME (exp->elts[2].symbol));
958 } while (p && *p++ == ',');
961 else if (0 == strncasecmp (p, "while-stepping", 14))
963 char *steparg; /* in case warning is necessary */
972 t->step_count = strtol (p, &p, 0);
973 if (t->step_count == 0)
975 warning ("'%s' evaluates to zero -- command ignored.");
983 else if (0 == strncasecmp (p, "end", 3))
987 warning ("'%s' is not a supported tracepoint action.", p);
994 struct tracepoint *t;
996 struct action_line *line, *next;
998 for (line = t->actions; line; line = next)
1007 int type; /* 0 for absolute memory range, else basereg number */
1008 bfd_signed_vma start;
1012 struct collection_list {
1013 unsigned char regs_mask[8]; /* room for up to 256 regs */
1016 struct memrange *list;
1017 } tracepoint_list, stepping_list;
1021 struct memrange *a, *b;
1023 if (a->type < b->type) return -1;
1024 if (a->type > b->type) return 1;
1027 if ((bfd_vma) a->start < (bfd_vma) b->start) return -1;
1028 if ((bfd_vma) a->start > (bfd_vma) b->start) return 1;
1032 if (a->start < b->start) return -1;
1033 if (a->start > b->start) return 1;
1039 memrange_sortmerge (memranges)
1040 struct collection_list *memranges;
1044 qsort (memranges->list, memranges->next_memrange,
1045 sizeof (struct memrange), memrange_cmp);
1046 if (memranges->next_memrange > 0)
1048 for (a = 0, b = 1; b < memranges->next_memrange; b++)
1050 if (memranges->list[a].type == memranges->list[b].type &&
1051 memranges->list[b].start - memranges->list[a].end <=
1052 MAX_REGISTER_VIRTUAL_SIZE)
1054 memranges->list[a].end = memranges->list[b].end;
1055 continue; /* next b, same a */
1059 memcpy (&memranges->list[a], &memranges->list[b],
1060 sizeof (struct memrange));
1062 memranges->next_memrange = a + 1;
1067 add_register (collection, regno)
1068 struct collection_list *collection;
1069 unsigned long regno;
1072 printf_filtered ("collect register %d\n", regno);
1073 if (regno > (8 * sizeof (collection->regs_mask)))
1074 error ("Internal: register number %d too large for tracepoint",
1076 collection->regs_mask [regno / 8] |= 1 << (regno % 8);
1080 add_memrange (memranges, type, base, len)
1081 struct collection_list *memranges;
1083 bfd_signed_vma base;
1087 printf_filtered ("(%d,0x%x,%d)\n", type, base, len);
1088 /* type: 0 == memory, n == basereg */
1089 memranges->list[memranges->next_memrange].type = type;
1090 /* base: addr if memory, offset if reg relative. */
1091 memranges->list[memranges->next_memrange].start = base;
1092 /* len: we actually save end (base + len) for convenience */
1093 memranges->list[memranges->next_memrange].end = base + len;
1094 memranges->next_memrange++;
1095 if (memranges->next_memrange >= memranges->listsize)
1097 memranges->listsize *= 2;
1098 memranges->list = xrealloc (memranges->list,
1099 memranges->listsize);
1102 if (type != 0) /* better collect the base register! */
1103 add_register (memranges, type);
1107 collect_symbol (collect, sym)
1108 struct collection_list *collect;
1113 bfd_signed_vma offset;
1115 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
1116 switch (SYMBOL_CLASS (sym)) {
1118 printf_filtered ("%s: don't know symbol class %d\n",
1119 SYMBOL_NAME (sym), SYMBOL_CLASS (sym));
1122 printf_filtered ("%s is constant, value is %d: will not be collected.\n",
1123 SYMBOL_NAME (sym), SYMBOL_VALUE (sym));
1126 offset = SYMBOL_VALUE_ADDRESS (sym);
1128 printf_filtered ("LOC_STATIC %s: collect %d bytes "
1130 SYMBOL_NAME (sym), len, offset);
1131 add_memrange (collect, 0, offset, len); /* 0 == memory */
1135 reg = SYMBOL_VALUE (sym);
1137 printf_filtered ("LOC_REG[parm] %s: ", SYMBOL_NAME (sym));
1138 add_register (collect, reg);
1142 printf_filtered ("Sorry, don't know how to do LOC_ARGs yet.\n");
1143 printf_filtered (" (will not collect %s)\n",
1146 case LOC_REGPARM_ADDR:
1147 reg = SYMBOL_VALUE (sym);
1151 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %d bytes at offset %d from reg %d\n",
1152 SYMBOL_NAME (sym), len, offset, reg);
1154 add_memrange (collect, reg, offset, len);
1158 offset = SYMBOL_VALUE (sym);
1162 printf_filtered ("LOC_LOCAL %s: Collect %d bytes at offset %d from frame ptr reg %d\n",
1163 SYMBOL_NAME (sym), len, offset, reg);
1165 add_memrange (collect, reg, offset, len);
1168 case LOC_BASEREG_ARG:
1169 reg = SYMBOL_BASEREG (sym);
1170 offset = SYMBOL_VALUE (sym);
1173 printf_filtered ("LOC_BASEREG %s: collect %d bytes at offset %d from basereg %d\n",
1174 SYMBOL_NAME (sym), len, offset, reg);
1176 add_memrange (collect, reg, offset, len);
1178 case LOC_UNRESOLVED:
1179 printf_filtered ("Don't know LOC_UNRESOLVED %s\n", SYMBOL_NAME (sym));
1181 case LOC_OPTIMIZED_OUT:
1182 printf_filtered ("%s has been optimized out of existance.\n",
1189 add_local_symbols (collect, pc, type)
1190 struct collection_list *collect;
1195 struct block *block;
1196 int i, nsyms, count = 0;
1198 block = block_for_pc (pc);
1201 nsyms = BLOCK_NSYMS (block);
1202 for (i = 0; i < nsyms; i++)
1204 sym = BLOCK_SYM (block, i);
1205 switch (SYMBOL_CLASS (sym)) {
1210 if (type == 'L') /* collecting Locals */
1213 collect_symbol (collect, sym);
1220 case LOC_REGPARM_ADDR:
1221 case LOC_BASEREG_ARG:
1222 if (type == 'A') /* collecting Arguments */
1225 collect_symbol (collect, sym);
1229 if (BLOCK_FUNCTION (block))
1232 block = BLOCK_SUPERBLOCK (block);
1235 warning ("No %s found in scope.", type == 'L' ? "locals" : "args");
1239 clear_collection_list (list)
1240 struct collection_list *list;
1242 list->next_memrange = 0;
1243 memset (list->regs_mask, 0, sizeof (list->regs_mask));
1247 stringify_collection_list (list, string)
1248 struct collection_list *list;
1254 for (i = sizeof (list->regs_mask) - 1; i > 0; i--)
1255 if (list->regs_mask[i] != 0) /* skip leading zeroes in regs_mask */
1257 if (list->regs_mask[i] != 0) /* prepare to send regs_mask to the stub */
1260 printf_filtered ("\nCollecting registers (mask): 0x");
1265 printf_filtered ("%02X", list->regs_mask[i]);
1266 sprintf (end, "%02X", list->regs_mask[i]);
1271 printf_filtered ("\n");
1272 if (list->next_memrange > 0 && info_verbose)
1273 printf_filtered ("Collecting memranges: \n");
1274 for (i = 0; i < list->next_memrange; i++)
1277 printf_filtered ("(%d, 0x%x, %d)\n",
1279 list->list[i].start,
1280 list->list[i].end - list->list[i].start);
1281 sprintf (end, "M%X,%X,%X",
1283 list->list[i].start,
1284 list->list[i].end - list->list[i].start);
1285 end += strlen (end);
1294 encode_actions (t, tdp_actions, step_count, stepping_actions)
1295 struct tracepoint *t;
1297 unsigned long *step_count;
1298 char **stepping_actions;
1300 struct expression *exp;
1301 static char tdp_buff[2048], step_buff[2048];
1302 struct action_line *action;
1304 bfd_signed_vma offset;
1306 struct collection_list *collect;
1308 clear_collection_list (&tracepoint_list);
1309 clear_collection_list (&stepping_list);
1310 collect = &tracepoint_list;
1312 *tdp_actions = NULL;
1313 *stepping_actions = NULL;
1315 for (action = t->actions; action; action = action->next)
1317 action_exp = action->action;
1318 while (isspace (*action_exp))
1321 if (0 == strncasecmp (action_exp, "collect", 7))
1323 action_exp = action_exp + 7;
1324 do { /* repeat over a comma-separated list */
1325 while (isspace (*action_exp))
1328 if (0 == strncasecmp ("$reg", action_exp, 4))
1330 for (i = 0; i < NUM_REGS; i++)
1331 add_register (collect, i);
1332 action_exp = strchr (action_exp, ','); /* more? */
1334 else if (0 == strncasecmp ("$arg", action_exp, 4))
1336 add_local_symbols (collect, t->address, 'A');
1337 action_exp = strchr (action_exp, ','); /* more? */
1339 else if (0 == strncasecmp ("$loc", action_exp, 4))
1341 add_local_symbols (collect, t->address, 'L');
1342 action_exp = strchr (action_exp, ','); /* more? */
1344 else if (action_exp[0] == '$' &&
1345 action_exp[1] == '(') /* literal memrange */
1347 long typecode, size;
1348 bfd_signed_vma offset;
1350 action_exp = parse_and_eval_memrange (action_exp,
1355 add_memrange (collect, typecode, offset, size);
1359 unsigned long addr, len;
1361 exp = parse_exp_1 (&action_exp, block_for_pc (t->address), 1);
1362 switch (exp->elts[0].opcode) {
1364 i = exp->elts[1].longconst;
1366 printf_filtered ("OP_REGISTER: ");
1367 add_register (collect, i);
1370 collect_symbol (collect, exp->elts[2].symbol);
1374 addr = exp->elts[2].longconst;
1375 if (*action_exp == ':')
1377 exp = parse_exp_1 (&action_exp,
1378 block_for_pc (t->address),
1380 if (exp->elts[0].opcode == OP_LONG)
1381 len = exp->elts[2].longconst;
1383 error ("length field requires a literal long const");
1388 add_memrange (collect, 0, addr, len);
1393 } while (action_exp && *action_exp++ == ',');
1395 else if (0 == strncasecmp (action_exp, "while-stepping", 14))
1397 collect = &stepping_list;
1399 else if (0 == strncasecmp (action_exp, "end", 3))
1401 if (collect == &stepping_list) /* end stepping actions */
1402 collect = &tracepoint_list;
1404 break; /* end tracepoint actions */
1407 memrange_sortmerge (&tracepoint_list);
1408 memrange_sortmerge (&stepping_list);
1410 *tdp_actions = stringify_collection_list (&tracepoint_list, &tdp_buff);
1411 *stepping_actions = stringify_collection_list (&stepping_list, &step_buff);
1414 static char target_buf[2048];
1417 trace_start_command (args, from_tty)
1420 { /* STUB_COMM MOSTLY_IMPLEMENTED */
1421 struct tracepoint *t;
1424 char *stepping_actions;
1425 unsigned long step_count;
1427 dont_repeat (); /* like "run", dangerous to repeat accidentally */
1429 if (target_is_remote ())
1432 remote_get_noisy_reply (target_buf);
1433 if (strcmp (target_buf, "OK"))
1434 error ("Target does not support this command.");
1438 int ss_count; /* if actions include singlestepping */
1439 int disable_mask; /* ??? */
1440 int enable_mask; /* ??? */
1442 sprintf (buf, "QTDP:%x:%x:%c:%x:%x", t->number, t->address,
1443 t->enabled == enabled ? 'E' : 'D',
1444 t->step_count, t->pass_count);
1447 encode_actions (t, &tdp_actions, &step_count, &stepping_actions);
1448 /* do_single_steps (t); */
1451 if (strlen (buf) + strlen (tdp_actions) >= sizeof (buf))
1452 error ("Actions for tracepoint %d too complex; "
1453 "please simplify.", t->number);
1454 strcat (buf, tdp_actions);
1456 if (stepping_actions)
1459 if (strlen (buf) + strlen (stepping_actions) >= sizeof (buf))
1460 error ("Actions for tracepoint %d too complex; "
1461 "please simplify.", t->number);
1462 strcat (buf, stepping_actions);
1466 remote_get_noisy_reply (target_buf);
1467 if (strcmp (target_buf, "OK"))
1468 error ("Target does not support tracepoints.");
1471 remote_get_noisy_reply (target_buf);
1472 if (strcmp (target_buf, "OK"))
1473 error ("Bogus reply from target: %s", target_buf);
1474 set_traceframe_num (-1); /* all old traceframes invalidated */
1475 set_tracepoint_num (-1);
1476 set_traceframe_context(-1);
1479 printf_filtered ("Trace can only be run on remote targets.\n");
1483 trace_stop_command (args, from_tty)
1486 { /* STUB_COMM IS_IMPLEMENTED */
1487 if (target_is_remote ())
1490 remote_get_noisy_reply (target_buf);
1491 if (strcmp (target_buf, "OK"))
1492 error ("Bogus reply from target: %s", target_buf);
1495 error ("Trace can only be run on remote targets.");
1499 trace_status_command (args, from_tty)
1502 { /* STUB_COMM IS_IMPLEMENTED */
1503 if (target_is_remote ())
1505 putpkt ("qTStatus");
1506 remote_get_noisy_reply (target_buf);
1507 if (strcmp (target_buf, "OK"))
1508 error ("Bogus reply from target: %s", target_buf);
1511 error ("Trace can only be run on remote targets.");
1515 trace_buff_command (args, from_tty)
1518 { /* STUB_COMM NOT_IMPLEMENTED */
1519 if (args == 0 || *args == 0)
1520 printf_filtered ("TBUFFER command requires argument (on or off)\n");
1521 else if (strcasecmp (args, "on") == 0)
1522 printf_filtered ("tbuffer overflow on.\n");
1523 else if (strcasecmp (args, "off") == 0)
1524 printf_filtered ("tbuffer overflow off.\n");
1526 printf_filtered ("TBUFFER: unknown argument (use on or off)\n");
1530 trace_limit_command (args, from_tty)
1533 { /* STUB_COMM NOT_IMPLEMENTED */
1534 printf_filtered ("Limit it to what?\n");
1538 finish_tfind_command (reply, from_tty)
1542 int target_frameno = -1, target_tracept = -1;
1544 while (reply && *reply)
1547 if ((target_frameno = strtol (++reply, &reply, 16)) == -1)
1548 error ("Target failed to find requested trace frame.");
1551 if ((target_tracept = strtol (++reply, &reply, 16)) == -1)
1552 error ("Target failed to find requested trace frame.");
1554 case 'O': /* "OK"? */
1555 if (reply[1] == 'K' && reply[2] == '\0')
1558 error ("Bogus reply from target: %s", reply);
1561 error ("Bogus reply from target: %s", reply);
1564 flush_cached_frames ();
1565 registers_changed ();
1566 select_frame (get_current_frame (), 0);
1567 set_traceframe_num (target_frameno);
1568 set_tracepoint_num (target_tracept);
1569 set_traceframe_context ((get_current_frame ())->pc);
1572 print_stack_frame (selected_frame, selected_frame_level, 1);
1575 /* trace_find_command takes a trace frame number n,
1576 sends "QTFrame:<n>" to the target,
1577 and accepts a reply that may contain several optional pieces
1578 of information: a frame number, a tracepoint number, and an
1579 indication of whether this is a trap frame or a stepping frame.
1581 The minimal response is just "OK" (which indicates that the
1582 target does not give us a frame number or a tracepoint number).
1583 Instead of that, the target may send us a string containing
1585 F<hexnum> (gives the selected frame number)
1586 T<hexnum> (gives the selected tracepoint number)
1590 trace_find_command (args, from_tty)
1593 { /* STUB_COMM PART_IMPLEMENTED */
1594 /* this should only be called with a numeric argument */
1596 int target_frameno = -1, target_tracept = -1, target_stepfrm = 0;
1599 if (target_is_remote ())
1601 if (args == 0 || *args == 0)
1602 { /* TFIND with no args means find NEXT trace frame. */
1603 if (traceframe_number == -1)
1604 frameno = 0; /* "next" is first one */
1606 frameno = traceframe_number + 1;
1608 else if (0 == strcmp (args, "-"))
1610 if (traceframe_number == -1)
1611 error ("not debugging trace buffer");
1612 else if (traceframe_number == 0)
1613 error ("already at start of trace buffer");
1615 frameno = traceframe_number - 1;
1618 else if (0 == strcasecmp (args, "start"))
1620 else if (0 == strcasecmp (args, "none") ||
1621 0 == strcasecmp (args, "end"))
1625 frameno = parse_and_eval_address (args);
1627 sprintf (target_buf, "QTFrame:%x", frameno);
1628 putpkt (target_buf);
1629 tmp = remote_get_noisy_reply (target_buf);
1631 if (frameno == -1) /* end trace debugging */
1632 { /* hopefully the stub has complied! */
1633 if (0 != strcmp (tmp, "F-1"))
1634 error ("Bogus response from target: %s", tmp);
1636 flush_cached_frames ();
1637 registers_changed ();
1638 select_frame (get_current_frame (), 0);
1639 set_traceframe_num (-1);
1640 set_tracepoint_num (-1);
1641 set_traceframe_context (-1);
1644 print_stack_frame (selected_frame, selected_frame_level, 1);
1647 finish_tfind_command (tmp, from_tty);
1650 error ("Trace can only be run on remote targets.");
1654 trace_find_end_command (args, from_tty)
1658 trace_find_command ("-1", from_tty);
1662 trace_find_none_command (args, from_tty)
1666 trace_find_command ("-1", from_tty);
1670 trace_find_start_command (args, from_tty)
1674 trace_find_command ("0", from_tty);
1678 trace_find_pc_command (args, from_tty)
1681 { /* STUB_COMM PART_IMPLEMENTED */
1686 if (target_is_remote ())
1688 if (args == 0 || *args == 0)
1689 pc = read_pc (); /* default is current pc */
1691 pc = parse_and_eval_address (args);
1693 sprintf (target_buf, "QTFrame:pc:%x", pc);
1694 putpkt (target_buf);
1695 tmp = remote_get_noisy_reply (target_buf);
1697 finish_tfind_command (tmp, from_tty);
1700 error ("Trace can only be run on remote targets.");
1704 trace_find_tracepoint_command (args, from_tty)
1707 { /* STUB_COMM PART_IMPLEMENTED */
1708 int target_frameno, tdp;
1711 if (target_is_remote ())
1713 if (args == 0 || *args == 0)
1714 if (tracepoint_number == -1)
1715 error ("No current tracepoint -- please supply an argument.");
1717 tdp = tracepoint_number; /* default is current TDP */
1719 tdp = parse_and_eval_address (args);
1721 sprintf (target_buf, "QTFrame:tdp:%x", tdp);
1722 putpkt (target_buf);
1723 tmp = remote_get_noisy_reply (target_buf);
1725 finish_tfind_command (tmp, from_tty);
1728 error ("Trace can only be run on remote targets.");
1731 /* TFIND LINE command:
1733 * This command will take a sourceline for argument, just like BREAK
1734 * or TRACE (ie. anything that "decode_line_1" can handle).
1736 * With no argument, this command will find the next trace frame
1737 * corresponding to a source line OTHER THAN THE CURRENT ONE.
1741 trace_find_line_command (args, from_tty)
1744 { /* STUB_COMM PART_IMPLEMENTED */
1745 static CORE_ADDR start_pc, end_pc;
1746 struct symtabs_and_lines sals;
1747 struct symtab_and_line sal;
1750 struct cleanup *old_chain;
1752 if (target_is_remote ())
1754 if (args == 0 || *args == 0)
1756 sal = find_pc_line ((get_current_frame ())->pc, 0);
1758 sals.sals = (struct symtab_and_line *)
1759 xmalloc (sizeof (struct symtab_and_line));
1764 sals = decode_line_spec (args, 1);
1768 old_chain = make_cleanup (free, sals.sals);
1769 if (sal.symtab == 0)
1771 printf_filtered ("TFIND: No line number information available");
1774 /* This is useful for "info line *0x7f34". If we can't tell the
1775 user about a source line, at least let them have the symbolic
1777 printf_filtered (" for address ");
1779 print_address (sal.pc, gdb_stdout);
1780 printf_filtered (";\n -- will attempt to find by PC. \n");
1784 printf_filtered (".\n");
1785 return; /* no line, no PC; what can we do? */
1788 else if (sal.line > 0
1789 && find_line_pc_range (sal, &start_pc, &end_pc))
1791 if (start_pc == end_pc)
1793 printf_filtered ("Line %d of \"%s\"",
1794 sal.line, sal.symtab->filename);
1796 printf_filtered (" is at address ");
1797 print_address (start_pc, gdb_stdout);
1799 printf_filtered (" but contains no code.\n");
1800 sal = find_pc_line (start_pc, 0);
1802 find_line_pc_range (sal, &start_pc, &end_pc) &&
1804 printf_filtered ("Attempting to find line %d instead.\n",
1807 error ("Cannot find a good line.");
1811 /* Is there any case in which we get here, and have an address
1812 which the user would want to see? If we have debugging symbols
1813 and no line numbers? */
1814 error ("Line number %d is out of range for \"%s\".\n",
1815 sal.line, sal.symtab->filename);
1817 if (args && *args) /* find within range of stated line */
1818 sprintf (target_buf, "QTFrame:range:%x:%x", start_pc, end_pc - 1);
1819 else /* find OUTSIDE OF range of CURRENT line */
1820 sprintf (target_buf, "QTFrame:outside:%x:%x", start_pc, end_pc - 1);
1821 putpkt (target_buf);
1822 tmp = remote_get_noisy_reply (target_buf);
1824 finish_tfind_command (tmp, from_tty);
1825 do_cleanups (old_chain);
1828 error ("Trace can only be run on remote targets.");
1832 trace_find_range_command (args, from_tty)
1835 { /* STUB_COMM PART_IMPLEMENTED */
1836 static CORE_ADDR start, stop;
1840 if (target_is_remote ())
1842 if (args == 0 || *args == 0)
1843 { /* XXX FIXME: what should default behavior be? */
1844 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1848 if (0 != (tmp = strchr (args, ',' )))
1850 *tmp++ = '\0'; /* terminate start address */
1851 while (isspace (*tmp))
1853 start = parse_and_eval_address (args);
1854 stop = parse_and_eval_address (tmp);
1857 { /* no explicit end address? */
1858 start = parse_and_eval_address (args);
1859 stop = start + 1; /* ??? */
1862 sprintf (target_buf, "QTFrame:range:%x:%x", start, stop);
1863 putpkt (target_buf);
1864 tmp = remote_get_noisy_reply (target_buf);
1866 finish_tfind_command (tmp, from_tty);
1869 error ("Trace can only be run on remote targets.");
1873 trace_find_outside_command (args, from_tty)
1876 { /* STUB_COMM PART_IMPLEMENTED */
1877 CORE_ADDR start, stop;
1881 if (target_is_remote ())
1883 if (args == 0 || *args == 0)
1884 { /* XXX FIXME: what should default behavior be? */
1885 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1889 if (0 != (tmp = strchr (args, ',' )))
1891 *tmp++ = '\0'; /* terminate start address */
1892 while (isspace (*tmp))
1894 start = parse_and_eval_address (args);
1895 stop = parse_and_eval_address (tmp);
1898 { /* no explicit end address? */
1899 start = parse_and_eval_address (args);
1900 stop = start + 1; /* ??? */
1903 sprintf (target_buf, "QTFrame:outside:%x:%x", start, stop);
1904 putpkt (target_buf);
1905 tmp = remote_get_noisy_reply (target_buf);
1907 finish_tfind_command (tmp, from_tty);
1910 error ("Trace can only be run on remote targets.");
1914 tracepoint_save_command (args, from_tty)
1918 struct tracepoint *tp;
1919 struct action_line *line;
1921 char *i1 = " ", *i2 = " ";
1922 char *indent, *actionline;
1924 if (args == 0 || *args == 0)
1925 error ("Argument required (file name in which to save tracepoints");
1927 if (tracepoint_chain == 0)
1929 warning ("save-tracepoints: no tracepoints to save.\n");
1933 if (!(fp = fopen (args, "w")))
1934 error ("Unable to open file '%s' for saving tracepoints");
1936 ALL_TRACEPOINTS (tp)
1938 if (tp->addr_string)
1939 fprintf (fp, "trace %s\n", tp->addr_string);
1941 fprintf (fp, "trace *0x%x\n", tp->address);
1944 fprintf (fp, " passcount %d\n", tp->pass_count);
1948 fprintf (fp, " actions\n");
1950 for (line = tp->actions; line; line = line->next)
1952 actionline = line->action;
1953 while (isspace(*actionline))
1956 fprintf (fp, "%s%s\n", indent, actionline);
1957 if (0 == strncasecmp (actionline, "while-stepping", 14))
1959 else if (0 == strncasecmp (actionline, "end", 3))
1966 printf_filtered ("Tracepoints saved to file '%s'.\n", args);
1971 scope_info (args, from_tty)
1975 struct symtab_and_line sal;
1976 struct symtabs_and_lines sals;
1978 struct minimal_symbol *msym;
1979 struct block *block;
1980 char **canonical, *symname, *save_args = args;
1981 int i, nsyms, count = 0;
1983 if (args == 0 || *args == 0)
1984 error ("requires an argument (function, line or *addr) to define a scope");
1986 sals = decode_line_1 (&args, 1, NULL, 0, &canonical);
1987 if (sals.nelts == 0)
1988 return; /* presumably decode_line_1 has already warned */
1990 /* Resolve line numbers to PC */
1991 resolve_sal_pc (&sals.sals[0]);
1992 block = block_for_pc (sals.sals[0].pc);
1996 nsyms = BLOCK_NSYMS (block);
1997 for (i = 0; i < nsyms; i++)
2000 printf_filtered ("Scope for %s:\n", save_args);
2002 sym = BLOCK_SYM (block, i);
2003 symname = SYMBOL_NAME (sym);
2004 if (symname == NULL || *symname == '\0')
2005 continue; /* probably botched, certainly useless */
2007 printf_filtered ("Symbol %s is ", symname);
2008 switch (SYMBOL_CLASS (sym)) {
2010 case LOC_UNDEF: /* messed up symbol? */
2011 printf_filtered ("a bogus symbol, class %d.\n",
2012 SYMBOL_CLASS (sym));
2013 count--; /* don't count this one */
2016 printf_filtered ("a constant with value %d (0x%x)",
2017 SYMBOL_VALUE (sym), SYMBOL_VALUE (sym));
2019 case LOC_CONST_BYTES:
2020 printf_filtered ("constant bytes: ");
2021 if (SYMBOL_TYPE (sym))
2022 for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (sym)); i++)
2023 fprintf_filtered (gdb_stdout, " %02x",
2024 (unsigned) SYMBOL_VALUE_BYTES (sym) [i]);
2027 printf_filtered ("in static storage at address ");
2028 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, gdb_stdout);
2031 printf_filtered ("a local variable in register $%s",
2032 reg_names [SYMBOL_VALUE (sym)]);
2036 printf_filtered ("an argument at stack/frame offset %ld",
2037 SYMBOL_VALUE (sym));
2040 printf_filtered ("a local variable at frame offset %ld",
2041 SYMBOL_VALUE (sym));
2044 printf_filtered ("a reference argument at offset %ld",
2045 SYMBOL_VALUE (sym));
2048 printf_filtered ("an argument in register $%s",
2049 reg_names[SYMBOL_VALUE (sym)]);
2051 case LOC_REGPARM_ADDR:
2052 printf_filtered ("the address of an argument, in register $%s",
2053 reg_names[SYMBOL_VALUE (sym)]);
2056 printf_filtered ("a typedef.\n");
2059 printf_filtered ("a label at address ");
2060 print_address_numeric (SYMBOL_VALUE_ADDRESS (sym), 1, gdb_stdout);
2063 printf_filtered ("a function at address ");
2064 print_address_numeric (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), 1,
2068 printf_filtered ("a variable at offset %d from register $%s",
2070 reg_names [SYMBOL_BASEREG (sym)]);
2072 case LOC_BASEREG_ARG:
2073 printf_filtered ("an argument at offset %d from register $%s",
2075 reg_names [SYMBOL_BASEREG (sym)]);
2077 case LOC_UNRESOLVED:
2078 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, NULL);
2080 printf_filtered ("Unresolved Static");
2083 printf_filtered ("static storage at address ");
2084 print_address_numeric (SYMBOL_VALUE_ADDRESS (msym), 1,
2088 case LOC_OPTIMIZED_OUT:
2089 printf_filtered ("optimized out.\n");
2092 if (SYMBOL_TYPE (sym))
2093 printf_filtered (", length %d.\n",
2094 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
2096 if (BLOCK_FUNCTION (block))
2099 block = BLOCK_SUPERBLOCK (block);
2102 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2107 replace_comma (comma)
2114 trace_dump_command (args, from_tty)
2118 struct tracepoint *t;
2119 struct action_line *action;
2120 char *action_exp, *next_comma;
2121 struct cleanup *old_cleanups;
2122 int stepping_actions = 0;
2123 int stepping_frame = 0;
2125 if (tracepoint_number == -1)
2127 warning ("No current trace frame.");
2132 if (t->number == tracepoint_number)
2136 error ("No known tracepoint matches 'current' tracepoint #%d.",
2139 old_cleanups = make_cleanup (null_cleanup, NULL);
2141 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2142 tracepoint_number, traceframe_number);
2144 /* The current frame is a trap frame if the frame PC is equal
2145 to the tracepoint PC. If not, then the current frame was
2146 collected during single-stepping. */
2148 stepping_frame = (t->address != read_pc());
2150 for (action = t->actions; action; action = action->next)
2152 action_exp = action->action;
2153 while (isspace (*action_exp))
2156 /* The collection actions to be done while stepping are
2157 bracketed by the commands "while-stepping" and "end". */
2159 if (0 == strncasecmp (action_exp, "while-stepping", 14))
2160 stepping_actions = 1;
2161 else if (0 == strncasecmp (action_exp, "end", 3))
2162 stepping_actions = 0;
2163 else if (0 == strncasecmp (action_exp, "collect", 7))
2165 /* Display the collected data.
2166 For the trap frame, display only what was collected at the trap.
2167 Likewise for stepping frames, display only what was collected
2168 while stepping. This means that the two boolean variables,
2169 STEPPING_FRAME and STEPPING_ACTIONS should be equal. */
2170 if (stepping_frame == stepping_actions)
2173 do { /* repeat over a comma-separated list */
2175 if (*action_exp == ',')
2177 while (isspace (*action_exp))
2180 next_comma = strchr (action_exp, ',');
2183 make_cleanup (replace_comma, next_comma);
2187 if (0 == strncasecmp (action_exp, "$reg", 4))
2188 registers_info (NULL, from_tty);
2189 else if (0 == strncasecmp (action_exp, "$loc", 4))
2190 locals_info (NULL, from_tty);
2191 else if (0 == strncasecmp (action_exp, "$arg", 4))
2192 args_info (NULL, from_tty);
2195 printf_filtered ("%s = ", action_exp);
2196 output_command (action_exp, from_tty);
2197 printf_filtered ("\n");
2201 action_exp = next_comma;
2202 } while (action_exp && *action_exp == ',');
2206 discard_cleanups (old_cleanups);
2211 static struct cmd_list_element *tfindlist;
2212 static struct cmd_list_element *tracelist;
2215 _initialize_tracepoint ()
2217 tracepoint_chain = 0;
2218 tracepoint_count = 0;
2219 traceframe_number = -1;
2220 tracepoint_number = -1;
2222 set_internalvar (lookup_internalvar ("tpnum"),
2223 value_from_longest (builtin_type_int, (LONGEST) 0));
2224 set_internalvar (lookup_internalvar ("trace_frame"),
2225 value_from_longest (builtin_type_int, (LONGEST) 0));
2227 if (tracepoint_list.list == NULL)
2229 tracepoint_list.listsize = 128;
2230 tracepoint_list.list = xmalloc
2231 (tracepoint_list.listsize * sizeof (struct memrange));
2233 if (stepping_list.list == NULL)
2235 stepping_list.listsize = 128;
2236 stepping_list.list = xmalloc
2237 (stepping_list.listsize * sizeof (struct memrange));
2240 add_info ("scope", scope_info,
2241 "List the variables local to a scope");
2243 add_cmd ("tracepoints", class_trace, NO_FUNCTION,
2244 "Tracing of program execution without stopping the program.",
2247 add_info ("tracepoints", tracepoints_info,
2248 "Status of tracepoints, or tracepoint number NUMBER.\n\
2249 Convenience variable \"$tpnum\" contains the number of the\n\
2250 last tracepoint set.");
2252 add_info_alias ("tp", "tracepoints", 1);
2254 add_com ("save-tracepoints", class_trace, tracepoint_save_command,
2255 "Save current tracepoint definitions as a script.\n\
2256 Use the 'source' command in another debug session to restore them.");
2258 add_com ("tdump", class_trace, trace_dump_command,
2259 "Print everything collected at the current tracepoint.");
2261 add_prefix_cmd ("tfind", class_trace, trace_find_command,
2262 "Select a trace frame;\n\
2263 No argument means forward by one frame; '-' meand backward by one frame.",
2264 &tfindlist, "tfind ", 1, &cmdlist);
2266 add_cmd ("outside", class_trace, trace_find_outside_command,
2267 "Select a trace frame whose PC is outside the given \
2268 range.\nUsage: tfind outside addr1, addr2",
2271 add_cmd ("range", class_trace, trace_find_range_command,
2272 "Select a trace frame whose PC is in the given range.\n\
2273 Usage: tfind range addr1,addr2",
2276 add_cmd ("line", class_trace, trace_find_line_command,
2277 "Select a trace frame by source line.\n\
2278 Argument can be a line number (with optional source file), \n\
2279 a function name, or '*' followed by an address.\n\
2280 Default argument is 'the next source line that was traced'.",
2283 add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command,
2284 "Select a trace frame by tracepoint number.\n\
2285 Default is the tracepoint for the current trace frame.",
2288 add_cmd ("pc", class_trace, trace_find_pc_command,
2289 "Select a trace frame by PC.\n\
2290 Default is the current PC, or the PC of the current trace frame.",
2293 add_cmd ("end", class_trace, trace_find_end_command,
2294 "Synonym for 'none'.\n\
2295 De-select any trace frame and resume 'live' debugging.",
2298 add_cmd ("none", class_trace, trace_find_none_command,
2299 "De-select any trace frame and resume 'live' debugging.",
2302 add_cmd ("start", class_trace, trace_find_start_command,
2303 "Select the first trace frame in the trace buffer.",
2306 add_com ("tstatus", class_trace, trace_status_command,
2307 "Display the status of the current trace data collection.");
2309 add_com ("tstop", class_trace, trace_stop_command,
2310 "Stop trace data collection.");
2312 add_com ("tstart", class_trace, trace_start_command,
2313 "Start trace data collection.");
2315 add_com ("passcount", class_trace, trace_pass_command,
2316 "Set the passcount for a tracepoint.\n\
2317 The trace will end when the tracepoint has been passed 'count' times.\n\
2318 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\
2319 if TPNUM is omitted, passcount refers to the last tracepoint defined.");
2321 add_com ("end", class_trace, end_pseudocom,
2322 "Ends a list of commands or actions.\n\
2323 Several GDB commands allow you to enter a list of commands or actions.\n\
2324 Entering \"end\" on a line by itself is the normal way to terminate\n\
2326 Note: the \"end\" command cannot be used at the gdb prompt.");
2328 add_com ("while-stepping", class_trace, while_stepping_pseudocom,
2329 "Specify single-stepping behavior at a tracepoint.\n\
2330 Argument is number of instructions to trace in single-step mode\n\
2331 following the tracepoint. This command is normally followed by\n\
2332 one or more \"collect\" commands, to specify what to collect\n\
2333 while single-stepping.\n\n\
2334 Note: this command can only be used in a tracepoint \"actions\" list.");
2336 add_com ("collect", class_trace, collect_pseudocom,
2337 "Specify one or more data items to be collected at a tracepoint.\n\
2338 Accepts a comma-separated list of (one or more) arguments.\n\
2339 Things that may be collected include registers, variables, plus\n\
2340 the following special arguments:\n\
2341 $regs -- all registers.\n\
2342 $args -- all function arguments.\n\
2343 $locals -- all variables local to the block/function scope.\n\
2344 $(addr,len) -- a literal memory range.\n\
2345 $($reg,addr,len) -- a register-relative literal memory range.\n\n\
2346 Note: this command can only be used in a tracepoint \"actions\" list.");
2348 add_com ("actions", class_trace, trace_actions_command,
2349 "Specify the actions to be taken at a tracepoint.\n\
2350 Tracepoint actions may include collecting of specified data, \n\
2351 single-stepping, or enabling/disabling other tracepoints, \n\
2352 depending on target's capabilities.");
2354 add_cmd ("tracepoints", class_trace, delete_trace_command,
2355 "Delete specified tracepoints.\n\
2356 Arguments are tracepoint numbers, separated by spaces.\n\
2357 No argument means delete all tracepoints.",
2360 add_cmd ("tracepoints", class_trace, disable_trace_command,
2361 "Disable specified tracepoints.\n\
2362 Arguments are tracepoint numbers, separated by spaces.\n\
2363 No argument means disable all tracepoints.",
2366 add_cmd ("tracepoints", class_trace, enable_trace_command,
2367 "Enable specified tracepoints.\n\
2368 Arguments are tracepoint numbers, separated by spaces.\n\
2369 No argument means enable all tracepoints.",
2372 add_com ("trace", class_trace, trace_command,
2373 "Set a tracepoint at a specified line or function or address.\n\
2374 Argument may be a line number, function name, or '*' plus an address.\n\
2375 For a line number or function, trace at the start of its code.\n\
2376 If an address is specified, trace at that exact address.\n\n\
2377 Do \"help tracepoints\" for info on other tracepoint commands.");
2379 add_com_alias ("tp", "trace", class_alias, 0);
2380 add_com_alias ("tr", "trace", class_alias, 1);
2381 add_com_alias ("tra", "trace", class_alias, 1);
2382 add_com_alias ("trac", "trace", class_alias, 1);