]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/tracepoint.c
* win32-low.c (win32_add_one_solib): If the dll name is
[thirdparty/binutils-gdb.git] / gdb / tracepoint.c
1 /* Tracing functionality for remote targets in custom GDB protocol
2
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007, 2008, 2009 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
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.
12
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.
17
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/>. */
20
21 #include "defs.h"
22 #include "arch-utils.h"
23 #include "symtab.h"
24 #include "frame.h"
25 #include "gdbtypes.h"
26 #include "expression.h"
27 #include "gdbcmd.h"
28 #include "value.h"
29 #include "target.h"
30 #include "language.h"
31 #include "gdb_string.h"
32 #include "inferior.h"
33 #include "breakpoint.h"
34 #include "tracepoint.h"
35 #include "remote.h"
36 extern int remote_supports_cond_tracepoints (void);
37 #include "linespec.h"
38 #include "regcache.h"
39 #include "completer.h"
40 #include "block.h"
41 #include "dictionary.h"
42 #include "observer.h"
43 #include "user-regs.h"
44 #include "valprint.h"
45 #include "gdbcore.h"
46 #include "objfiles.h"
47
48 #include "ax.h"
49 #include "ax-gdb.h"
50
51 /* readline include files */
52 #include "readline/readline.h"
53 #include "readline/history.h"
54
55 /* readline defines this. */
56 #undef savestring
57
58 #ifdef HAVE_UNISTD_H
59 #include <unistd.h>
60 #endif
61
62 /* Maximum length of an agent aexpression.
63 This accounts for the fact that packets are limited to 400 bytes
64 (which includes everything -- including the checksum), and assumes
65 the worst case of maximum length for each of the pieces of a
66 continuation packet.
67
68 NOTE: expressions get mem2hex'ed otherwise this would be twice as
69 large. (400 - 31)/2 == 184 */
70 #define MAX_AGENT_EXPR_LEN 184
71
72
73 extern void (*deprecated_readline_begin_hook) (char *, ...);
74 extern char *(*deprecated_readline_hook) (char *);
75 extern void (*deprecated_readline_end_hook) (void);
76
77 /* GDB commands implemented in other modules:
78 */
79
80 extern void output_command (char *, int);
81
82 /*
83 Tracepoint.c:
84
85 This module defines the following debugger commands:
86 trace : set a tracepoint on a function, line, or address.
87 info trace : list all debugger-defined tracepoints.
88 delete trace : delete one or more tracepoints.
89 enable trace : enable one or more tracepoints.
90 disable trace : disable one or more tracepoints.
91 actions : specify actions to be taken at a tracepoint.
92 passcount : specify a pass count for a tracepoint.
93 tstart : start a trace experiment.
94 tstop : stop a trace experiment.
95 tstatus : query the status of a trace experiment.
96 tfind : find a trace frame in the trace buffer.
97 tdump : print everything collected at the current tracepoint.
98 save-tracepoints : write tracepoint setup into a file.
99
100 This module defines the following user-visible debugger variables:
101 $trace_frame : sequence number of trace frame currently being debugged.
102 $trace_line : source line of trace frame currently being debugged.
103 $trace_file : source file of trace frame currently being debugged.
104 $tracepoint : tracepoint number of trace frame currently being debugged.
105 */
106
107
108 /* ======= Important global variables: ======= */
109
110 /* Number of last traceframe collected. */
111 static int traceframe_number;
112
113 /* Tracepoint for last traceframe collected. */
114 static int tracepoint_number;
115
116 /* Symbol for function for last traceframe collected */
117 static struct symbol *traceframe_fun;
118
119 /* Symtab and line for last traceframe collected */
120 static struct symtab_and_line traceframe_sal;
121
122 /* Tracing command lists */
123 static struct cmd_list_element *tfindlist;
124
125 /* ======= Important command functions: ======= */
126 static void trace_actions_command (char *, int);
127 static void trace_start_command (char *, int);
128 static void trace_stop_command (char *, int);
129 static void trace_status_command (char *, int);
130 static void trace_find_command (char *, int);
131 static void trace_find_pc_command (char *, int);
132 static void trace_find_tracepoint_command (char *, int);
133 static void trace_find_line_command (char *, int);
134 static void trace_find_range_command (char *, int);
135 static void trace_find_outside_command (char *, int);
136 static void tracepoint_save_command (char *, int);
137 static void trace_dump_command (char *, int);
138
139 /* support routines */
140
141 struct collection_list;
142 static void add_aexpr (struct collection_list *, struct agent_expr *);
143 static char *mem2hex (gdb_byte *, char *, int);
144 static void add_register (struct collection_list *collection,
145 unsigned int regno);
146 static struct cleanup *make_cleanup_free_actions (struct breakpoint *t);
147 static void free_actions_list (char **actions_list);
148 static void free_actions_list_cleanup_wrapper (void *);
149
150 extern void _initialize_tracepoint (void);
151
152 /* Utility: returns true if "target remote" */
153 static int
154 target_is_remote (void)
155 {
156 if (current_target.to_shortname &&
157 (strcmp (current_target.to_shortname, "remote") == 0
158 || strcmp (current_target.to_shortname, "extended-remote") == 0))
159 return 1;
160 else
161 return 0;
162 }
163
164 /* Utility: generate error from an incoming stub packet. */
165 static void
166 trace_error (char *buf)
167 {
168 if (*buf++ != 'E')
169 return; /* not an error msg */
170 switch (*buf)
171 {
172 case '1': /* malformed packet error */
173 if (*++buf == '0') /* general case: */
174 error (_("tracepoint.c: error in outgoing packet."));
175 else
176 error (_("tracepoint.c: error in outgoing packet at field #%ld."),
177 strtol (buf, NULL, 16));
178 case '2':
179 error (_("trace API error 0x%s."), ++buf);
180 default:
181 error (_("Target returns error code '%s'."), buf);
182 }
183 }
184
185 /* Utility: wait for reply from stub, while accepting "O" packets. */
186 static char *
187 remote_get_noisy_reply (char **buf_p,
188 long *sizeof_buf)
189 {
190 do /* Loop on reply from remote stub. */
191 {
192 char *buf;
193 QUIT; /* allow user to bail out with ^C */
194 getpkt (buf_p, sizeof_buf, 0);
195 buf = *buf_p;
196 if (buf[0] == 0)
197 error (_("Target does not support this command."));
198 else if (buf[0] == 'E')
199 trace_error (buf);
200 else if (buf[0] == 'O' &&
201 buf[1] != 'K')
202 remote_console_output (buf + 1); /* 'O' message from stub */
203 else
204 return buf; /* here's the actual reply */
205 }
206 while (1);
207 }
208
209 /* Set traceframe number to NUM. */
210 static void
211 set_traceframe_num (int num)
212 {
213 traceframe_number = num;
214 set_internalvar_integer (lookup_internalvar ("trace_frame"), num);
215 }
216
217 /* Set tracepoint number to NUM. */
218 static void
219 set_tracepoint_num (int num)
220 {
221 tracepoint_number = num;
222 set_internalvar_integer (lookup_internalvar ("tracepoint"), num);
223 }
224
225 /* Set externally visible debug variables for querying/printing
226 the traceframe context (line, function, file) */
227
228 static void
229 set_traceframe_context (struct frame_info *trace_frame)
230 {
231 CORE_ADDR trace_pc;
232
233 if (trace_frame == NULL) /* Cease debugging any trace buffers. */
234 {
235 traceframe_fun = 0;
236 traceframe_sal.pc = traceframe_sal.line = 0;
237 traceframe_sal.symtab = NULL;
238 clear_internalvar (lookup_internalvar ("trace_func"));
239 clear_internalvar (lookup_internalvar ("trace_file"));
240 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
241 return;
242 }
243
244 /* Save as globals for internal use. */
245 trace_pc = get_frame_pc (trace_frame);
246 traceframe_sal = find_pc_line (trace_pc, 0);
247 traceframe_fun = find_pc_function (trace_pc);
248
249 /* Save linenumber as "$trace_line", a debugger variable visible to
250 users. */
251 set_internalvar_integer (lookup_internalvar ("trace_line"),
252 traceframe_sal.line);
253
254 /* Save func name as "$trace_func", a debugger variable visible to
255 users. */
256 if (traceframe_fun == NULL
257 || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
258 clear_internalvar (lookup_internalvar ("trace_func"));
259 else
260 set_internalvar_string (lookup_internalvar ("trace_func"),
261 SYMBOL_LINKAGE_NAME (traceframe_fun));
262
263 /* Save file name as "$trace_file", a debugger variable visible to
264 users. */
265 if (traceframe_sal.symtab == NULL
266 || traceframe_sal.symtab->filename == NULL)
267 clear_internalvar (lookup_internalvar ("trace_file"));
268 else
269 set_internalvar_string (lookup_internalvar ("trace_file"),
270 traceframe_sal.symtab->filename);
271 }
272
273 /* ACTIONS functions: */
274
275 /* Prototypes for action-parsing utility commands */
276 static void read_actions (struct breakpoint *);
277
278 /* The three functions:
279 collect_pseudocommand,
280 while_stepping_pseudocommand, and
281 end_actions_pseudocommand
282 are placeholders for "commands" that are actually ONLY to be used
283 within a tracepoint action list. If the actual function is ever called,
284 it means that somebody issued the "command" at the top level,
285 which is always an error. */
286
287 void
288 end_actions_pseudocommand (char *args, int from_tty)
289 {
290 error (_("This command cannot be used at the top level."));
291 }
292
293 void
294 while_stepping_pseudocommand (char *args, int from_tty)
295 {
296 error (_("This command can only be used in a tracepoint actions list."));
297 }
298
299 static void
300 collect_pseudocommand (char *args, int from_tty)
301 {
302 error (_("This command can only be used in a tracepoint actions list."));
303 }
304
305 /* Enter a list of actions for a tracepoint. */
306 static void
307 trace_actions_command (char *args, int from_tty)
308 {
309 struct breakpoint *t;
310 char tmpbuf[128];
311 char *end_msg = "End with a line saying just \"end\".";
312
313 t = get_tracepoint_by_number (&args, 0, 1);
314 if (t)
315 {
316 sprintf (tmpbuf, "Enter actions for tracepoint %d, one per line.",
317 t->number);
318
319 if (from_tty)
320 {
321 if (deprecated_readline_begin_hook)
322 (*deprecated_readline_begin_hook) ("%s %s\n", tmpbuf, end_msg);
323 else if (input_from_terminal_p ())
324 printf_filtered ("%s\n%s\n", tmpbuf, end_msg);
325 }
326
327 free_actions (t);
328 t->step_count = 0; /* read_actions may set this */
329 read_actions (t);
330
331 if (deprecated_readline_end_hook)
332 (*deprecated_readline_end_hook) ();
333 /* tracepoints_changed () */
334 }
335 /* else just return */
336 }
337
338 /* worker function */
339 static void
340 read_actions (struct breakpoint *t)
341 {
342 char *line;
343 char *prompt1 = "> ", *prompt2 = " > ";
344 char *prompt = prompt1;
345 enum actionline_type linetype;
346 extern FILE *instream;
347 struct action_line *next = NULL, *temp;
348 struct cleanup *old_chain;
349
350 /* Control-C quits instantly if typed while in this loop
351 since it should not wait until the user types a newline. */
352 immediate_quit++;
353 /* FIXME: kettenis/20010823: Something is wrong here. In this file
354 STOP_SIGNAL is never defined. So this code has been left out, at
355 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
356 leads to compilation failures since the variable job_control
357 isn't declared. Leave this alone for now. */
358 #ifdef STOP_SIGNAL
359 if (job_control)
360 signal (STOP_SIGNAL, handle_stop_sig);
361 #endif
362 old_chain = make_cleanup_free_actions (t);
363 while (1)
364 {
365 /* Make sure that all output has been output. Some machines may
366 let you get away with leaving out some of the gdb_flush, but
367 not all. */
368 wrap_here ("");
369 gdb_flush (gdb_stdout);
370 gdb_flush (gdb_stderr);
371
372 if (deprecated_readline_hook && instream == NULL)
373 line = (*deprecated_readline_hook) (prompt);
374 else if (instream == stdin && ISATTY (instream))
375 {
376 line = gdb_readline_wrapper (prompt);
377 if (line && *line) /* add it to command history */
378 add_history (line);
379 }
380 else
381 line = gdb_readline (0);
382
383 if (!line)
384 {
385 line = xstrdup ("end");
386 printf_filtered ("end\n");
387 }
388
389 linetype = validate_actionline (&line, t);
390 if (linetype == BADLINE)
391 continue; /* already warned -- collect another line */
392
393 temp = xmalloc (sizeof (struct action_line));
394 temp->next = NULL;
395 temp->action = line;
396
397 if (next == NULL) /* first action for this tracepoint? */
398 t->actions = next = temp;
399 else
400 {
401 next->next = temp;
402 next = temp;
403 }
404
405 if (linetype == STEPPING) /* begin "while-stepping" */
406 {
407 if (prompt == prompt2)
408 {
409 warning (_("Already processing 'while-stepping'"));
410 continue;
411 }
412 else
413 prompt = prompt2; /* change prompt for stepping actions */
414 }
415 else if (linetype == END)
416 {
417 if (prompt == prompt2)
418 {
419 prompt = prompt1; /* end of single-stepping actions */
420 }
421 else
422 { /* end of actions */
423 if (t->actions->next == NULL)
424 {
425 /* An "end" all by itself with no other actions
426 means this tracepoint has no actions.
427 Discard empty list. */
428 free_actions (t);
429 }
430 break;
431 }
432 }
433 }
434 #ifdef STOP_SIGNAL
435 if (job_control)
436 signal (STOP_SIGNAL, SIG_DFL);
437 #endif
438 immediate_quit--;
439 discard_cleanups (old_chain);
440 }
441
442 /* worker function */
443 enum actionline_type
444 validate_actionline (char **line, struct breakpoint *t)
445 {
446 struct cmd_list_element *c;
447 struct expression *exp = NULL;
448 struct cleanup *old_chain = NULL;
449 char *p;
450
451 /* if EOF is typed, *line is NULL */
452 if (*line == NULL)
453 return END;
454
455 for (p = *line; isspace ((int) *p);)
456 p++;
457
458 /* Symbol lookup etc. */
459 if (*p == '\0') /* empty line: just prompt for another line. */
460 return BADLINE;
461
462 if (*p == '#') /* comment line */
463 return GENERIC;
464
465 c = lookup_cmd (&p, cmdlist, "", -1, 1);
466 if (c == 0)
467 {
468 warning (_("'%s' is not an action that I know, or is ambiguous."),
469 p);
470 return BADLINE;
471 }
472
473 if (cmd_cfunc_eq (c, collect_pseudocommand))
474 {
475 struct agent_expr *aexpr;
476 struct agent_reqs areqs;
477
478 do
479 { /* repeat over a comma-separated list */
480 QUIT; /* allow user to bail out with ^C */
481 while (isspace ((int) *p))
482 p++;
483
484 if (*p == '$') /* look for special pseudo-symbols */
485 {
486 if ((0 == strncasecmp ("reg", p + 1, 3)) ||
487 (0 == strncasecmp ("arg", p + 1, 3)) ||
488 (0 == strncasecmp ("loc", p + 1, 3)))
489 {
490 p = strchr (p, ',');
491 continue;
492 }
493 /* else fall thru, treat p as an expression and parse it! */
494 }
495 exp = parse_exp_1 (&p, block_for_pc (t->loc->address), 1);
496 old_chain = make_cleanup (free_current_contents, &exp);
497
498 if (exp->elts[0].opcode == OP_VAR_VALUE)
499 {
500 if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
501 {
502 warning (_("constant %s (value %ld) will not be collected."),
503 SYMBOL_PRINT_NAME (exp->elts[2].symbol),
504 SYMBOL_VALUE (exp->elts[2].symbol));
505 return BADLINE;
506 }
507 else if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_OPTIMIZED_OUT)
508 {
509 warning (_("%s is optimized away and cannot be collected."),
510 SYMBOL_PRINT_NAME (exp->elts[2].symbol));
511 return BADLINE;
512 }
513 }
514
515 /* We have something to collect, make sure that the expr to
516 bytecode translator can handle it and that it's not too
517 long. */
518 aexpr = gen_trace_for_expr (t->loc->address, exp);
519 make_cleanup_free_agent_expr (aexpr);
520
521 if (aexpr->len > MAX_AGENT_EXPR_LEN)
522 error (_("expression too complicated, try simplifying"));
523
524 ax_reqs (aexpr, &areqs);
525 (void) make_cleanup (xfree, areqs.reg_mask);
526
527 if (areqs.flaw != agent_flaw_none)
528 error (_("malformed expression"));
529
530 if (areqs.min_height < 0)
531 error (_("gdb: Internal error: expression has min height < 0"));
532
533 if (areqs.max_height > 20)
534 error (_("expression too complicated, try simplifying"));
535
536 do_cleanups (old_chain);
537 }
538 while (p && *p++ == ',');
539 return GENERIC;
540 }
541 else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
542 {
543 char *steparg; /* in case warning is necessary */
544
545 while (isspace ((int) *p))
546 p++;
547 steparg = p;
548
549 if (*p == '\0' ||
550 (t->step_count = strtol (p, &p, 0)) == 0)
551 {
552 warning (_("'%s': bad step-count; command ignored."), *line);
553 return BADLINE;
554 }
555 return STEPPING;
556 }
557 else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
558 return END;
559 else
560 {
561 warning (_("'%s' is not a supported tracepoint action."), *line);
562 return BADLINE;
563 }
564 }
565
566 /* worker function */
567 void
568 free_actions (struct breakpoint *t)
569 {
570 struct action_line *line, *next;
571
572 for (line = t->actions; line; line = next)
573 {
574 next = line->next;
575 if (line->action)
576 xfree (line->action);
577 xfree (line);
578 }
579 t->actions = NULL;
580 }
581
582 static void
583 do_free_actions_cleanup (void *t)
584 {
585 free_actions (t);
586 }
587
588 static struct cleanup *
589 make_cleanup_free_actions (struct breakpoint *t)
590 {
591 return make_cleanup (do_free_actions_cleanup, t);
592 }
593
594 enum {
595 memrange_absolute = -1
596 };
597
598 struct memrange
599 {
600 int type; /* memrange_absolute for absolute memory range,
601 else basereg number */
602 bfd_signed_vma start;
603 bfd_signed_vma end;
604 };
605
606 struct collection_list
607 {
608 unsigned char regs_mask[32]; /* room for up to 256 regs */
609 long listsize;
610 long next_memrange;
611 struct memrange *list;
612 long aexpr_listsize; /* size of array pointed to by expr_list elt */
613 long next_aexpr_elt;
614 struct agent_expr **aexpr_list;
615
616 }
617 tracepoint_list, stepping_list;
618
619 /* MEMRANGE functions: */
620
621 static int memrange_cmp (const void *, const void *);
622
623 /* compare memranges for qsort */
624 static int
625 memrange_cmp (const void *va, const void *vb)
626 {
627 const struct memrange *a = va, *b = vb;
628
629 if (a->type < b->type)
630 return -1;
631 if (a->type > b->type)
632 return 1;
633 if (a->type == memrange_absolute)
634 {
635 if ((bfd_vma) a->start < (bfd_vma) b->start)
636 return -1;
637 if ((bfd_vma) a->start > (bfd_vma) b->start)
638 return 1;
639 }
640 else
641 {
642 if (a->start < b->start)
643 return -1;
644 if (a->start > b->start)
645 return 1;
646 }
647 return 0;
648 }
649
650 /* Sort the memrange list using qsort, and merge adjacent memranges. */
651 static void
652 memrange_sortmerge (struct collection_list *memranges)
653 {
654 int a, b;
655
656 qsort (memranges->list, memranges->next_memrange,
657 sizeof (struct memrange), memrange_cmp);
658 if (memranges->next_memrange > 0)
659 {
660 for (a = 0, b = 1; b < memranges->next_memrange; b++)
661 {
662 if (memranges->list[a].type == memranges->list[b].type &&
663 memranges->list[b].start - memranges->list[a].end <=
664 MAX_REGISTER_SIZE)
665 {
666 /* memrange b starts before memrange a ends; merge them. */
667 if (memranges->list[b].end > memranges->list[a].end)
668 memranges->list[a].end = memranges->list[b].end;
669 continue; /* next b, same a */
670 }
671 a++; /* next a */
672 if (a != b)
673 memcpy (&memranges->list[a], &memranges->list[b],
674 sizeof (struct memrange));
675 }
676 memranges->next_memrange = a + 1;
677 }
678 }
679
680 /* Add a register to a collection list. */
681 static void
682 add_register (struct collection_list *collection, unsigned int regno)
683 {
684 if (info_verbose)
685 printf_filtered ("collect register %d\n", regno);
686 if (regno >= (8 * sizeof (collection->regs_mask)))
687 error (_("Internal: register number %d too large for tracepoint"),
688 regno);
689 collection->regs_mask[regno / 8] |= 1 << (regno % 8);
690 }
691
692 /* Add a memrange to a collection list */
693 static void
694 add_memrange (struct collection_list *memranges,
695 int type, bfd_signed_vma base,
696 unsigned long len)
697 {
698 if (info_verbose)
699 {
700 printf_filtered ("(%d,", type);
701 printf_vma (base);
702 printf_filtered (",%ld)\n", len);
703 }
704
705 /* type: memrange_absolute == memory, other n == basereg */
706 memranges->list[memranges->next_memrange].type = type;
707 /* base: addr if memory, offset if reg relative. */
708 memranges->list[memranges->next_memrange].start = base;
709 /* len: we actually save end (base + len) for convenience */
710 memranges->list[memranges->next_memrange].end = base + len;
711 memranges->next_memrange++;
712 if (memranges->next_memrange >= memranges->listsize)
713 {
714 memranges->listsize *= 2;
715 memranges->list = xrealloc (memranges->list,
716 memranges->listsize);
717 }
718
719 if (type != memrange_absolute) /* Better collect the base register! */
720 add_register (memranges, type);
721 }
722
723 /* Add a symbol to a collection list. */
724 static void
725 collect_symbol (struct collection_list *collect,
726 struct symbol *sym,
727 struct gdbarch *gdbarch,
728 long frame_regno, long frame_offset)
729 {
730 unsigned long len;
731 unsigned int reg;
732 bfd_signed_vma offset;
733
734 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
735 switch (SYMBOL_CLASS (sym))
736 {
737 default:
738 printf_filtered ("%s: don't know symbol class %d\n",
739 SYMBOL_PRINT_NAME (sym),
740 SYMBOL_CLASS (sym));
741 break;
742 case LOC_CONST:
743 printf_filtered ("constant %s (value %ld) will not be collected.\n",
744 SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE (sym));
745 break;
746 case LOC_STATIC:
747 offset = SYMBOL_VALUE_ADDRESS (sym);
748 if (info_verbose)
749 {
750 char tmp[40];
751
752 sprintf_vma (tmp, offset);
753 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
754 SYMBOL_PRINT_NAME (sym), len,
755 tmp /* address */);
756 }
757 add_memrange (collect, memrange_absolute, offset, len);
758 break;
759 case LOC_REGISTER:
760 reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
761 if (info_verbose)
762 printf_filtered ("LOC_REG[parm] %s: ",
763 SYMBOL_PRINT_NAME (sym));
764 add_register (collect, reg);
765 /* Check for doubles stored in two registers. */
766 /* FIXME: how about larger types stored in 3 or more regs? */
767 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
768 len > register_size (gdbarch, reg))
769 add_register (collect, reg + 1);
770 break;
771 case LOC_REF_ARG:
772 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
773 printf_filtered (" (will not collect %s)\n",
774 SYMBOL_PRINT_NAME (sym));
775 break;
776 case LOC_ARG:
777 reg = frame_regno;
778 offset = frame_offset + SYMBOL_VALUE (sym);
779 if (info_verbose)
780 {
781 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
782 SYMBOL_PRINT_NAME (sym), len);
783 printf_vma (offset);
784 printf_filtered (" from frame ptr reg %d\n", reg);
785 }
786 add_memrange (collect, reg, offset, len);
787 break;
788 case LOC_REGPARM_ADDR:
789 reg = SYMBOL_VALUE (sym);
790 offset = 0;
791 if (info_verbose)
792 {
793 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
794 SYMBOL_PRINT_NAME (sym), len);
795 printf_vma (offset);
796 printf_filtered (" from reg %d\n", reg);
797 }
798 add_memrange (collect, reg, offset, len);
799 break;
800 case LOC_LOCAL:
801 reg = frame_regno;
802 offset = frame_offset + SYMBOL_VALUE (sym);
803 if (info_verbose)
804 {
805 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
806 SYMBOL_PRINT_NAME (sym), len);
807 printf_vma (offset);
808 printf_filtered (" from frame ptr reg %d\n", reg);
809 }
810 add_memrange (collect, reg, offset, len);
811 break;
812 case LOC_UNRESOLVED:
813 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
814 SYMBOL_PRINT_NAME (sym));
815 break;
816 case LOC_OPTIMIZED_OUT:
817 printf_filtered ("%s has been optimized out of existence.\n",
818 SYMBOL_PRINT_NAME (sym));
819 break;
820 }
821 }
822
823 /* Add all locals (or args) symbols to collection list */
824 static void
825 add_local_symbols (struct collection_list *collect,
826 struct gdbarch *gdbarch, CORE_ADDR pc,
827 long frame_regno, long frame_offset, int type)
828 {
829 struct symbol *sym;
830 struct block *block;
831 struct dict_iterator iter;
832 int count = 0;
833
834 block = block_for_pc (pc);
835 while (block != 0)
836 {
837 QUIT; /* allow user to bail out with ^C */
838 ALL_BLOCK_SYMBOLS (block, iter, sym)
839 {
840 if (SYMBOL_IS_ARGUMENT (sym)
841 ? type == 'A' /* collecting Arguments */
842 : type == 'L') /* collecting Locals */
843 {
844 count++;
845 collect_symbol (collect, sym, gdbarch,
846 frame_regno, frame_offset);
847 }
848 }
849 if (BLOCK_FUNCTION (block))
850 break;
851 else
852 block = BLOCK_SUPERBLOCK (block);
853 }
854 if (count == 0)
855 warning (_("No %s found in scope."),
856 type == 'L' ? "locals" : "args");
857 }
858
859 /* worker function */
860 static void
861 clear_collection_list (struct collection_list *list)
862 {
863 int ndx;
864
865 list->next_memrange = 0;
866 for (ndx = 0; ndx < list->next_aexpr_elt; ndx++)
867 {
868 free_agent_expr (list->aexpr_list[ndx]);
869 list->aexpr_list[ndx] = NULL;
870 }
871 list->next_aexpr_elt = 0;
872 memset (list->regs_mask, 0, sizeof (list->regs_mask));
873 }
874
875 /* reduce a collection list to string form (for gdb protocol) */
876 static char **
877 stringify_collection_list (struct collection_list *list, char *string)
878 {
879 char temp_buf[2048];
880 char tmp2[40];
881 int count;
882 int ndx = 0;
883 char *(*str_list)[];
884 char *end;
885 long i;
886
887 count = 1 + list->next_memrange + list->next_aexpr_elt + 1;
888 str_list = (char *(*)[]) xmalloc (count * sizeof (char *));
889
890 for (i = sizeof (list->regs_mask) - 1; i > 0; i--)
891 if (list->regs_mask[i] != 0) /* skip leading zeroes in regs_mask */
892 break;
893 if (list->regs_mask[i] != 0) /* prepare to send regs_mask to the stub */
894 {
895 if (info_verbose)
896 printf_filtered ("\nCollecting registers (mask): 0x");
897 end = temp_buf;
898 *end++ = 'R';
899 for (; i >= 0; i--)
900 {
901 QUIT; /* allow user to bail out with ^C */
902 if (info_verbose)
903 printf_filtered ("%02X", list->regs_mask[i]);
904 sprintf (end, "%02X", list->regs_mask[i]);
905 end += 2;
906 }
907 (*str_list)[ndx] = xstrdup (temp_buf);
908 ndx++;
909 }
910 if (info_verbose)
911 printf_filtered ("\n");
912 if (list->next_memrange > 0 && info_verbose)
913 printf_filtered ("Collecting memranges: \n");
914 for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++)
915 {
916 QUIT; /* allow user to bail out with ^C */
917 sprintf_vma (tmp2, list->list[i].start);
918 if (info_verbose)
919 {
920 printf_filtered ("(%d, %s, %ld)\n",
921 list->list[i].type,
922 tmp2,
923 (long) (list->list[i].end - list->list[i].start));
924 }
925 if (count + 27 > MAX_AGENT_EXPR_LEN)
926 {
927 (*str_list)[ndx] = savestring (temp_buf, count);
928 ndx++;
929 count = 0;
930 end = temp_buf;
931 }
932
933 {
934 bfd_signed_vma length = list->list[i].end - list->list[i].start;
935
936 /* The "%X" conversion specifier expects an unsigned argument,
937 so passing -1 (memrange_absolute) to it directly gives you
938 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
939 Special-case it. */
940 if (list->list[i].type == memrange_absolute)
941 sprintf (end, "M-1,%s,%lX", tmp2, (long) length);
942 else
943 sprintf (end, "M%X,%s,%lX", list->list[i].type, tmp2, (long) length);
944 }
945
946 count += strlen (end);
947 end = temp_buf + count;
948 }
949
950 for (i = 0; i < list->next_aexpr_elt; i++)
951 {
952 QUIT; /* allow user to bail out with ^C */
953 if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN)
954 {
955 (*str_list)[ndx] = savestring (temp_buf, count);
956 ndx++;
957 count = 0;
958 end = temp_buf;
959 }
960 sprintf (end, "X%08X,", list->aexpr_list[i]->len);
961 end += 10; /* 'X' + 8 hex digits + ',' */
962 count += 10;
963
964 end = mem2hex (list->aexpr_list[i]->buf,
965 end, list->aexpr_list[i]->len);
966 count += 2 * list->aexpr_list[i]->len;
967 }
968
969 if (count != 0)
970 {
971 (*str_list)[ndx] = savestring (temp_buf, count);
972 ndx++;
973 count = 0;
974 end = temp_buf;
975 }
976 (*str_list)[ndx] = NULL;
977
978 if (ndx == 0)
979 {
980 xfree (str_list);
981 return NULL;
982 }
983 else
984 return *str_list;
985 }
986
987 static void
988 free_actions_list_cleanup_wrapper (void *al)
989 {
990 free_actions_list (al);
991 }
992
993 static void
994 free_actions_list (char **actions_list)
995 {
996 int ndx;
997
998 if (actions_list == 0)
999 return;
1000
1001 for (ndx = 0; actions_list[ndx]; ndx++)
1002 xfree (actions_list[ndx]);
1003
1004 xfree (actions_list);
1005 }
1006
1007 /* Render all actions into gdb protocol. */
1008 static void
1009 encode_actions (struct breakpoint *t, char ***tdp_actions,
1010 char ***stepping_actions)
1011 {
1012 static char tdp_buff[2048], step_buff[2048];
1013 char *action_exp;
1014 struct expression *exp = NULL;
1015 struct action_line *action;
1016 int i;
1017 struct value *tempval;
1018 struct collection_list *collect;
1019 struct cmd_list_element *cmd;
1020 struct agent_expr *aexpr;
1021 int frame_reg;
1022 LONGEST frame_offset;
1023
1024
1025 clear_collection_list (&tracepoint_list);
1026 clear_collection_list (&stepping_list);
1027 collect = &tracepoint_list;
1028
1029 *tdp_actions = NULL;
1030 *stepping_actions = NULL;
1031
1032 gdbarch_virtual_frame_pointer (t->gdbarch,
1033 t->loc->address, &frame_reg, &frame_offset);
1034
1035 for (action = t->actions; action; action = action->next)
1036 {
1037 QUIT; /* allow user to bail out with ^C */
1038 action_exp = action->action;
1039 while (isspace ((int) *action_exp))
1040 action_exp++;
1041
1042 if (*action_exp == '#') /* comment line */
1043 return;
1044
1045 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
1046 if (cmd == 0)
1047 error (_("Bad action list item: %s"), action_exp);
1048
1049 if (cmd_cfunc_eq (cmd, collect_pseudocommand))
1050 {
1051 do
1052 { /* repeat over a comma-separated list */
1053 QUIT; /* allow user to bail out with ^C */
1054 while (isspace ((int) *action_exp))
1055 action_exp++;
1056
1057 if (0 == strncasecmp ("$reg", action_exp, 4))
1058 {
1059 for (i = 0; i < gdbarch_num_regs (t->gdbarch); i++)
1060 add_register (collect, i);
1061 action_exp = strchr (action_exp, ','); /* more? */
1062 }
1063 else if (0 == strncasecmp ("$arg", action_exp, 4))
1064 {
1065 add_local_symbols (collect,
1066 t->gdbarch,
1067 t->loc->address,
1068 frame_reg,
1069 frame_offset,
1070 'A');
1071 action_exp = strchr (action_exp, ','); /* more? */
1072 }
1073 else if (0 == strncasecmp ("$loc", action_exp, 4))
1074 {
1075 add_local_symbols (collect,
1076 t->gdbarch,
1077 t->loc->address,
1078 frame_reg,
1079 frame_offset,
1080 'L');
1081 action_exp = strchr (action_exp, ','); /* more? */
1082 }
1083 else
1084 {
1085 unsigned long addr, len;
1086 struct cleanup *old_chain = NULL;
1087 struct cleanup *old_chain1 = NULL;
1088 struct agent_reqs areqs;
1089
1090 exp = parse_exp_1 (&action_exp,
1091 block_for_pc (t->loc->address), 1);
1092 old_chain = make_cleanup (free_current_contents, &exp);
1093
1094 switch (exp->elts[0].opcode)
1095 {
1096 case OP_REGISTER:
1097 {
1098 const char *name = &exp->elts[2].string;
1099
1100 i = user_reg_map_name_to_regnum (t->gdbarch,
1101 name, strlen (name));
1102 if (i == -1)
1103 internal_error (__FILE__, __LINE__,
1104 _("Register $%s not available"),
1105 name);
1106 if (info_verbose)
1107 printf_filtered ("OP_REGISTER: ");
1108 add_register (collect, i);
1109 break;
1110 }
1111
1112 case UNOP_MEMVAL:
1113 /* safe because we know it's a simple expression */
1114 tempval = evaluate_expression (exp);
1115 addr = value_address (tempval);
1116 len = TYPE_LENGTH (check_typedef (exp->elts[1].type));
1117 add_memrange (collect, memrange_absolute, addr, len);
1118 break;
1119
1120 case OP_VAR_VALUE:
1121 collect_symbol (collect,
1122 exp->elts[2].symbol,
1123 t->gdbarch,
1124 frame_reg,
1125 frame_offset);
1126 break;
1127
1128 default: /* full-fledged expression */
1129 aexpr = gen_trace_for_expr (t->loc->address, exp);
1130
1131 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1132
1133 ax_reqs (aexpr, &areqs);
1134 if (areqs.flaw != agent_flaw_none)
1135 error (_("malformed expression"));
1136
1137 if (areqs.min_height < 0)
1138 error (_("gdb: Internal error: expression has min height < 0"));
1139 if (areqs.max_height > 20)
1140 error (_("expression too complicated, try simplifying"));
1141
1142 discard_cleanups (old_chain1);
1143 add_aexpr (collect, aexpr);
1144
1145 /* take care of the registers */
1146 if (areqs.reg_mask_len > 0)
1147 {
1148 int ndx1;
1149 int ndx2;
1150
1151 for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++)
1152 {
1153 QUIT; /* allow user to bail out with ^C */
1154 if (areqs.reg_mask[ndx1] != 0)
1155 {
1156 /* assume chars have 8 bits */
1157 for (ndx2 = 0; ndx2 < 8; ndx2++)
1158 if (areqs.reg_mask[ndx1] & (1 << ndx2))
1159 /* it's used -- record it */
1160 add_register (collect,
1161 ndx1 * 8 + ndx2);
1162 }
1163 }
1164 }
1165 break;
1166 } /* switch */
1167 do_cleanups (old_chain);
1168 } /* do */
1169 }
1170 while (action_exp && *action_exp++ == ',');
1171 } /* if */
1172 else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
1173 {
1174 collect = &stepping_list;
1175 }
1176 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
1177 {
1178 if (collect == &stepping_list) /* end stepping actions */
1179 collect = &tracepoint_list;
1180 else
1181 break; /* end tracepoint actions */
1182 }
1183 } /* for */
1184 memrange_sortmerge (&tracepoint_list);
1185 memrange_sortmerge (&stepping_list);
1186
1187 *tdp_actions = stringify_collection_list (&tracepoint_list,
1188 tdp_buff);
1189 *stepping_actions = stringify_collection_list (&stepping_list,
1190 step_buff);
1191 }
1192
1193 static void
1194 add_aexpr (struct collection_list *collect, struct agent_expr *aexpr)
1195 {
1196 if (collect->next_aexpr_elt >= collect->aexpr_listsize)
1197 {
1198 collect->aexpr_list =
1199 xrealloc (collect->aexpr_list,
1200 2 * collect->aexpr_listsize * sizeof (struct agent_expr *));
1201 collect->aexpr_listsize *= 2;
1202 }
1203 collect->aexpr_list[collect->next_aexpr_elt] = aexpr;
1204 collect->next_aexpr_elt++;
1205 }
1206
1207 static char *target_buf;
1208 static long target_buf_size;
1209
1210 /* Set "transparent" memory ranges
1211
1212 Allow trace mechanism to treat text-like sections
1213 (and perhaps all read-only sections) transparently,
1214 i.e. don't reject memory requests from these address ranges
1215 just because they haven't been collected. */
1216
1217 static void
1218 remote_set_transparent_ranges (void)
1219 {
1220 asection *s;
1221 bfd_size_type size;
1222 bfd_vma lma;
1223 int anysecs = 0;
1224
1225 if (!exec_bfd)
1226 return; /* No information to give. */
1227
1228 strcpy (target_buf, "QTro");
1229 for (s = exec_bfd->sections; s; s = s->next)
1230 {
1231 char tmp1[40], tmp2[40];
1232
1233 if ((s->flags & SEC_LOAD) == 0 ||
1234 /* (s->flags & SEC_CODE) == 0 || */
1235 (s->flags & SEC_READONLY) == 0)
1236 continue;
1237
1238 anysecs = 1;
1239 lma = s->lma;
1240 size = bfd_get_section_size (s);
1241 sprintf_vma (tmp1, lma);
1242 sprintf_vma (tmp2, lma + size);
1243 sprintf (target_buf + strlen (target_buf),
1244 ":%s,%s", tmp1, tmp2);
1245 }
1246 if (anysecs)
1247 {
1248 putpkt (target_buf);
1249 getpkt (&target_buf, &target_buf_size, 0);
1250 }
1251 }
1252
1253 /* tstart command:
1254
1255 Tell target to clear any previous trace experiment.
1256 Walk the list of tracepoints, and send them (and their actions)
1257 to the target. If no errors,
1258 Tell target to start a new trace experiment. */
1259
1260 void download_tracepoint (struct breakpoint *t);
1261
1262 static void
1263 trace_start_command (char *args, int from_tty)
1264 {
1265 VEC(breakpoint_p) *tp_vec = NULL;
1266 int ix;
1267 struct breakpoint *t;
1268
1269 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1270
1271 if (target_is_remote ())
1272 {
1273 putpkt ("QTinit");
1274 remote_get_noisy_reply (&target_buf, &target_buf_size);
1275 if (strcmp (target_buf, "OK"))
1276 error (_("Target does not support this command."));
1277
1278 tp_vec = all_tracepoints ();
1279 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
1280 {
1281 download_tracepoint (t);
1282 }
1283 VEC_free (breakpoint_p, tp_vec);
1284
1285 /* Tell target to treat text-like sections as transparent. */
1286 remote_set_transparent_ranges ();
1287 /* Now insert traps and begin collecting data. */
1288 putpkt ("QTStart");
1289 remote_get_noisy_reply (&target_buf, &target_buf_size);
1290 if (strcmp (target_buf, "OK"))
1291 error (_("Bogus reply from target: %s"), target_buf);
1292 set_traceframe_num (-1); /* All old traceframes invalidated. */
1293 set_tracepoint_num (-1);
1294 set_traceframe_context (NULL);
1295 trace_running_p = 1;
1296 if (deprecated_trace_start_stop_hook)
1297 deprecated_trace_start_stop_hook (1, from_tty);
1298
1299 }
1300 else
1301 error (_("Trace can only be run on remote targets."));
1302 }
1303
1304 /* Send the definition of a single tracepoint to the target. */
1305
1306 void
1307 download_tracepoint (struct breakpoint *t)
1308 {
1309 char tmp[40];
1310 char buf[2048];
1311 char **tdp_actions;
1312 char **stepping_actions;
1313 int ndx;
1314 struct cleanup *old_chain = NULL;
1315 struct agent_expr *aexpr;
1316 struct cleanup *aexpr_chain = NULL;
1317
1318 sprintf_vma (tmp, (t->loc ? t->loc->address : 0));
1319 sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", t->number,
1320 tmp, /* address */
1321 (t->enable_state == bp_enabled ? 'E' : 'D'),
1322 t->step_count, t->pass_count);
1323 /* If the tracepoint has a conditional, make it into an agent
1324 expression and append to the definition. */
1325 if (t->loc->cond)
1326 {
1327 /* Only test support at download time, we may not know target
1328 capabilities at definition time. */
1329 if (remote_supports_cond_tracepoints ())
1330 {
1331 aexpr = gen_eval_for_expr (t->loc->address, t->loc->cond);
1332 aexpr_chain = make_cleanup_free_agent_expr (aexpr);
1333 sprintf (buf + strlen (buf), ":X%x,", aexpr->len);
1334 mem2hex (aexpr->buf, buf + strlen (buf), aexpr->len);
1335 do_cleanups (aexpr_chain);
1336 }
1337 else
1338 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t->number);
1339 }
1340
1341 if (t->actions)
1342 strcat (buf, "-");
1343 putpkt (buf);
1344 remote_get_noisy_reply (&target_buf, &target_buf_size);
1345 if (strcmp (target_buf, "OK"))
1346 error (_("Target does not support tracepoints."));
1347
1348 if (!t->actions)
1349 return;
1350
1351 encode_actions (t, &tdp_actions, &stepping_actions);
1352 old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
1353 tdp_actions);
1354 (void) make_cleanup (free_actions_list_cleanup_wrapper, stepping_actions);
1355
1356 /* do_single_steps (t); */
1357 if (tdp_actions)
1358 {
1359 for (ndx = 0; tdp_actions[ndx]; ndx++)
1360 {
1361 QUIT; /* allow user to bail out with ^C */
1362 sprintf (buf, "QTDP:-%x:%s:%s%c",
1363 t->number, tmp, /* address */
1364 tdp_actions[ndx],
1365 ((tdp_actions[ndx + 1] || stepping_actions)
1366 ? '-' : 0));
1367 putpkt (buf);
1368 remote_get_noisy_reply (&target_buf,
1369 &target_buf_size);
1370 if (strcmp (target_buf, "OK"))
1371 error (_("Error on target while setting tracepoints."));
1372 }
1373 }
1374 if (stepping_actions)
1375 {
1376 for (ndx = 0; stepping_actions[ndx]; ndx++)
1377 {
1378 QUIT; /* allow user to bail out with ^C */
1379 sprintf (buf, "QTDP:-%x:%s:%s%s%s",
1380 t->number, tmp, /* address */
1381 ((ndx == 0) ? "S" : ""),
1382 stepping_actions[ndx],
1383 (stepping_actions[ndx + 1] ? "-" : ""));
1384 putpkt (buf);
1385 remote_get_noisy_reply (&target_buf,
1386 &target_buf_size);
1387 if (strcmp (target_buf, "OK"))
1388 error (_("Error on target while setting tracepoints."));
1389 }
1390 }
1391 do_cleanups (old_chain);
1392 }
1393
1394 /* tstop command */
1395 static void
1396 trace_stop_command (char *args, int from_tty)
1397 {
1398 if (target_is_remote ())
1399 {
1400 putpkt ("QTStop");
1401 remote_get_noisy_reply (&target_buf, &target_buf_size);
1402 if (strcmp (target_buf, "OK"))
1403 error (_("Bogus reply from target: %s"), target_buf);
1404 trace_running_p = 0;
1405 if (deprecated_trace_start_stop_hook)
1406 deprecated_trace_start_stop_hook (0, from_tty);
1407 }
1408 else
1409 error (_("Trace can only be run on remote targets."));
1410 }
1411
1412 unsigned long trace_running_p;
1413
1414 /* tstatus command */
1415 static void
1416 trace_status_command (char *args, int from_tty)
1417 {
1418 if (target_is_remote ())
1419 {
1420 putpkt ("qTStatus");
1421 remote_get_noisy_reply (&target_buf, &target_buf_size);
1422
1423 if (target_buf[0] != 'T' ||
1424 (target_buf[1] != '0' && target_buf[1] != '1'))
1425 error (_("Bogus reply from target: %s"), target_buf);
1426
1427 /* exported for use by the GUI */
1428 trace_running_p = (target_buf[1] == '1');
1429 }
1430 else
1431 error (_("Trace can only be run on remote targets."));
1432 }
1433
1434 /* Worker function for the various flavors of the tfind command. */
1435 static void
1436 finish_tfind_command (char **msg,
1437 long *sizeof_msg,
1438 int from_tty)
1439 {
1440 int target_frameno = -1, target_tracept = -1;
1441 struct frame_id old_frame_id;
1442 char *reply;
1443
1444 old_frame_id = get_frame_id (get_current_frame ());
1445
1446 putpkt (*msg);
1447 reply = remote_get_noisy_reply (msg, sizeof_msg);
1448
1449 while (reply && *reply)
1450 switch (*reply)
1451 {
1452 case 'F':
1453 if ((target_frameno = (int) strtol (++reply, &reply, 16)) == -1)
1454 {
1455 /* A request for a non-existant trace frame has failed.
1456 Our response will be different, depending on FROM_TTY:
1457
1458 If FROM_TTY is true, meaning that this command was
1459 typed interactively by the user, then give an error
1460 and DO NOT change the state of traceframe_number etc.
1461
1462 However if FROM_TTY is false, meaning that we're either
1463 in a script, a loop, or a user-defined command, then
1464 DON'T give an error, but DO change the state of
1465 traceframe_number etc. to invalid.
1466
1467 The rationalle is that if you typed the command, you
1468 might just have committed a typo or something, and you'd
1469 like to NOT lose your current debugging state. However
1470 if you're in a user-defined command or especially in a
1471 loop, then you need a way to detect that the command
1472 failed WITHOUT aborting. This allows you to write
1473 scripts that search thru the trace buffer until the end,
1474 and then continue on to do something else. */
1475
1476 if (from_tty)
1477 error (_("Target failed to find requested trace frame."));
1478 else
1479 {
1480 if (info_verbose)
1481 printf_filtered ("End of trace buffer.\n");
1482 /* The following will not recurse, since it's
1483 special-cased. */
1484 trace_find_command ("-1", from_tty);
1485 reply = NULL; /* Break out of loop
1486 (avoid recursive nonsense). */
1487 }
1488 }
1489 break;
1490 case 'T':
1491 if ((target_tracept = (int) strtol (++reply, &reply, 16)) == -1)
1492 error (_("Target failed to find requested trace frame."));
1493 break;
1494 case 'O': /* "OK"? */
1495 if (reply[1] == 'K' && reply[2] == '\0')
1496 reply += 2;
1497 else
1498 error (_("Bogus reply from target: %s"), reply);
1499 break;
1500 default:
1501 error (_("Bogus reply from target: %s"), reply);
1502 }
1503
1504 reinit_frame_cache ();
1505 registers_changed ();
1506 set_traceframe_num (target_frameno);
1507 set_tracepoint_num (target_tracept);
1508 if (target_frameno == -1)
1509 set_traceframe_context (NULL);
1510 else
1511 set_traceframe_context (get_current_frame ());
1512
1513 if (from_tty)
1514 {
1515 enum print_what print_what;
1516
1517 /* NOTE: in immitation of the step command, try to determine
1518 whether we have made a transition from one function to
1519 another. If so, we'll print the "stack frame" (ie. the new
1520 function and it's arguments) -- otherwise we'll just show the
1521 new source line. */
1522
1523 if (frame_id_eq (old_frame_id,
1524 get_frame_id (get_current_frame ())))
1525 print_what = SRC_LINE;
1526 else
1527 print_what = SRC_AND_LOC;
1528
1529 print_stack_frame (get_selected_frame (NULL), 1, print_what);
1530 do_displays ();
1531 }
1532 }
1533
1534 /* trace_find_command takes a trace frame number n,
1535 sends "QTFrame:<n>" to the target,
1536 and accepts a reply that may contain several optional pieces
1537 of information: a frame number, a tracepoint number, and an
1538 indication of whether this is a trap frame or a stepping frame.
1539
1540 The minimal response is just "OK" (which indicates that the
1541 target does not give us a frame number or a tracepoint number).
1542 Instead of that, the target may send us a string containing
1543 any combination of:
1544 F<hexnum> (gives the selected frame number)
1545 T<hexnum> (gives the selected tracepoint number)
1546 */
1547
1548 /* tfind command */
1549 static void
1550 trace_find_command (char *args, int from_tty)
1551 { /* this should only be called with a numeric argument */
1552 int frameno = -1;
1553
1554 if (target_is_remote ())
1555 {
1556 if (deprecated_trace_find_hook)
1557 deprecated_trace_find_hook (args, from_tty);
1558
1559 if (args == 0 || *args == 0)
1560 { /* TFIND with no args means find NEXT trace frame. */
1561 if (traceframe_number == -1)
1562 frameno = 0; /* "next" is first one */
1563 else
1564 frameno = traceframe_number + 1;
1565 }
1566 else if (0 == strcmp (args, "-"))
1567 {
1568 if (traceframe_number == -1)
1569 error (_("not debugging trace buffer"));
1570 else if (from_tty && traceframe_number == 0)
1571 error (_("already at start of trace buffer"));
1572
1573 frameno = traceframe_number - 1;
1574 }
1575 else
1576 frameno = parse_and_eval_long (args);
1577
1578 if (frameno < -1)
1579 error (_("invalid input (%d is less than zero)"), frameno);
1580
1581 sprintf (target_buf, "QTFrame:%x", frameno);
1582 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1583 }
1584 else
1585 error (_("Trace can only be run on remote targets."));
1586 }
1587
1588 /* tfind end */
1589 static void
1590 trace_find_end_command (char *args, int from_tty)
1591 {
1592 trace_find_command ("-1", from_tty);
1593 }
1594
1595 /* tfind none */
1596 static void
1597 trace_find_none_command (char *args, int from_tty)
1598 {
1599 trace_find_command ("-1", from_tty);
1600 }
1601
1602 /* tfind start */
1603 static void
1604 trace_find_start_command (char *args, int from_tty)
1605 {
1606 trace_find_command ("0", from_tty);
1607 }
1608
1609 /* tfind pc command */
1610 static void
1611 trace_find_pc_command (char *args, int from_tty)
1612 {
1613 CORE_ADDR pc;
1614 char tmp[40];
1615
1616 if (target_is_remote ())
1617 {
1618 if (args == 0 || *args == 0)
1619 pc = regcache_read_pc (get_current_regcache ());
1620 else
1621 pc = parse_and_eval_address (args);
1622
1623 sprintf_vma (tmp, pc);
1624 sprintf (target_buf, "QTFrame:pc:%s", tmp);
1625 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1626 }
1627 else
1628 error (_("Trace can only be run on remote targets."));
1629 }
1630
1631 /* tfind tracepoint command */
1632 static void
1633 trace_find_tracepoint_command (char *args, int from_tty)
1634 {
1635 int tdp;
1636
1637 if (target_is_remote ())
1638 {
1639 if (args == 0 || *args == 0)
1640 {
1641 if (tracepoint_number == -1)
1642 error (_("No current tracepoint -- please supply an argument."));
1643 else
1644 tdp = tracepoint_number; /* default is current TDP */
1645 }
1646 else
1647 tdp = parse_and_eval_long (args);
1648
1649 sprintf (target_buf, "QTFrame:tdp:%x", tdp);
1650 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1651 }
1652 else
1653 error (_("Trace can only be run on remote targets."));
1654 }
1655
1656 /* TFIND LINE command:
1657
1658 This command will take a sourceline for argument, just like BREAK
1659 or TRACE (ie. anything that "decode_line_1" can handle).
1660
1661 With no argument, this command will find the next trace frame
1662 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1663
1664 static void
1665 trace_find_line_command (char *args, int from_tty)
1666 {
1667 static CORE_ADDR start_pc, end_pc;
1668 struct symtabs_and_lines sals;
1669 struct symtab_and_line sal;
1670 struct cleanup *old_chain;
1671 char startpc_str[40], endpc_str[40];
1672
1673 if (target_is_remote ())
1674 {
1675 if (args == 0 || *args == 0)
1676 {
1677 sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
1678 sals.nelts = 1;
1679 sals.sals = (struct symtab_and_line *)
1680 xmalloc (sizeof (struct symtab_and_line));
1681 sals.sals[0] = sal;
1682 }
1683 else
1684 {
1685 sals = decode_line_spec (args, 1);
1686 sal = sals.sals[0];
1687 }
1688
1689 old_chain = make_cleanup (xfree, sals.sals);
1690 if (sal.symtab == 0)
1691 {
1692 struct gdbarch *gdbarch = get_current_arch ();
1693
1694 printf_filtered ("TFIND: No line number information available");
1695 if (sal.pc != 0)
1696 {
1697 /* This is useful for "info line *0x7f34". If we can't
1698 tell the user about a source line, at least let them
1699 have the symbolic address. */
1700 printf_filtered (" for address ");
1701 wrap_here (" ");
1702 print_address (gdbarch, sal.pc, gdb_stdout);
1703 printf_filtered (";\n -- will attempt to find by PC. \n");
1704 }
1705 else
1706 {
1707 printf_filtered (".\n");
1708 return; /* No line, no PC; what can we do? */
1709 }
1710 }
1711 else if (sal.line > 0
1712 && find_line_pc_range (sal, &start_pc, &end_pc))
1713 {
1714 struct gdbarch *gdbarch = get_objfile_arch (sal.symtab->objfile);
1715
1716 if (start_pc == end_pc)
1717 {
1718 printf_filtered ("Line %d of \"%s\"",
1719 sal.line, sal.symtab->filename);
1720 wrap_here (" ");
1721 printf_filtered (" is at address ");
1722 print_address (gdbarch, start_pc, gdb_stdout);
1723 wrap_here (" ");
1724 printf_filtered (" but contains no code.\n");
1725 sal = find_pc_line (start_pc, 0);
1726 if (sal.line > 0 &&
1727 find_line_pc_range (sal, &start_pc, &end_pc) &&
1728 start_pc != end_pc)
1729 printf_filtered ("Attempting to find line %d instead.\n",
1730 sal.line);
1731 else
1732 error (_("Cannot find a good line."));
1733 }
1734 }
1735 else
1736 /* Is there any case in which we get here, and have an address
1737 which the user would want to see? If we have debugging
1738 symbols and no line numbers? */
1739 error (_("Line number %d is out of range for \"%s\"."),
1740 sal.line, sal.symtab->filename);
1741
1742 sprintf_vma (startpc_str, start_pc);
1743 sprintf_vma (endpc_str, end_pc - 1);
1744 /* Find within range of stated line. */
1745 if (args && *args)
1746 sprintf (target_buf, "QTFrame:range:%s:%s",
1747 startpc_str, endpc_str);
1748 /* Find OUTSIDE OF range of CURRENT line. */
1749 else
1750 sprintf (target_buf, "QTFrame:outside:%s:%s",
1751 startpc_str, endpc_str);
1752 finish_tfind_command (&target_buf, &target_buf_size,
1753 from_tty);
1754 do_cleanups (old_chain);
1755 }
1756 else
1757 error (_("Trace can only be run on remote targets."));
1758 }
1759
1760 /* tfind range command */
1761 static void
1762 trace_find_range_command (char *args, int from_tty)
1763 {
1764 static CORE_ADDR start, stop;
1765 char start_str[40], stop_str[40];
1766 char *tmp;
1767
1768 if (target_is_remote ())
1769 {
1770 if (args == 0 || *args == 0)
1771 { /* XXX FIXME: what should default behavior be? */
1772 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1773 return;
1774 }
1775
1776 if (0 != (tmp = strchr (args, ',')))
1777 {
1778 *tmp++ = '\0'; /* terminate start address */
1779 while (isspace ((int) *tmp))
1780 tmp++;
1781 start = parse_and_eval_address (args);
1782 stop = parse_and_eval_address (tmp);
1783 }
1784 else
1785 { /* no explicit end address? */
1786 start = parse_and_eval_address (args);
1787 stop = start + 1; /* ??? */
1788 }
1789
1790 sprintf_vma (start_str, start);
1791 sprintf_vma (stop_str, stop);
1792 sprintf (target_buf, "QTFrame:range:%s:%s", start_str, stop_str);
1793 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1794 }
1795 else
1796 error (_("Trace can only be run on remote targets."));
1797 }
1798
1799 /* tfind outside command */
1800 static void
1801 trace_find_outside_command (char *args, int from_tty)
1802 {
1803 CORE_ADDR start, stop;
1804 char start_str[40], stop_str[40];
1805 char *tmp;
1806
1807 if (target_is_remote ())
1808 {
1809 if (args == 0 || *args == 0)
1810 { /* XXX FIXME: what should default behavior be? */
1811 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1812 return;
1813 }
1814
1815 if (0 != (tmp = strchr (args, ',')))
1816 {
1817 *tmp++ = '\0'; /* terminate start address */
1818 while (isspace ((int) *tmp))
1819 tmp++;
1820 start = parse_and_eval_address (args);
1821 stop = parse_and_eval_address (tmp);
1822 }
1823 else
1824 { /* no explicit end address? */
1825 start = parse_and_eval_address (args);
1826 stop = start + 1; /* ??? */
1827 }
1828
1829 sprintf_vma (start_str, start);
1830 sprintf_vma (stop_str, stop);
1831 sprintf (target_buf, "QTFrame:outside:%s:%s", start_str, stop_str);
1832 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1833 }
1834 else
1835 error (_("Trace can only be run on remote targets."));
1836 }
1837
1838 /* info scope command: list the locals for a scope. */
1839 static void
1840 scope_info (char *args, int from_tty)
1841 {
1842 struct symtabs_and_lines sals;
1843 struct symbol *sym;
1844 struct minimal_symbol *msym;
1845 struct block *block;
1846 char **canonical, *symname, *save_args = args;
1847 struct dict_iterator iter;
1848 int j, count = 0;
1849 struct gdbarch *gdbarch;
1850 int regno;
1851
1852 if (args == 0 || *args == 0)
1853 error (_("requires an argument (function, line or *addr) to define a scope"));
1854
1855 sals = decode_line_1 (&args, 1, NULL, 0, &canonical, NULL);
1856 if (sals.nelts == 0)
1857 return; /* presumably decode_line_1 has already warned */
1858
1859 /* Resolve line numbers to PC */
1860 resolve_sal_pc (&sals.sals[0]);
1861 block = block_for_pc (sals.sals[0].pc);
1862
1863 while (block != 0)
1864 {
1865 QUIT; /* allow user to bail out with ^C */
1866 ALL_BLOCK_SYMBOLS (block, iter, sym)
1867 {
1868 QUIT; /* allow user to bail out with ^C */
1869 if (count == 0)
1870 printf_filtered ("Scope for %s:\n", save_args);
1871 count++;
1872
1873 symname = SYMBOL_PRINT_NAME (sym);
1874 if (symname == NULL || *symname == '\0')
1875 continue; /* probably botched, certainly useless */
1876
1877 gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile);
1878
1879 printf_filtered ("Symbol %s is ", symname);
1880 switch (SYMBOL_CLASS (sym))
1881 {
1882 default:
1883 case LOC_UNDEF: /* messed up symbol? */
1884 printf_filtered ("a bogus symbol, class %d.\n",
1885 SYMBOL_CLASS (sym));
1886 count--; /* don't count this one */
1887 continue;
1888 case LOC_CONST:
1889 printf_filtered ("a constant with value %ld (0x%lx)",
1890 SYMBOL_VALUE (sym), SYMBOL_VALUE (sym));
1891 break;
1892 case LOC_CONST_BYTES:
1893 printf_filtered ("constant bytes: ");
1894 if (SYMBOL_TYPE (sym))
1895 for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++)
1896 fprintf_filtered (gdb_stdout, " %02x",
1897 (unsigned) SYMBOL_VALUE_BYTES (sym)[j]);
1898 break;
1899 case LOC_STATIC:
1900 printf_filtered ("in static storage at address ");
1901 printf_filtered ("%s", paddress (gdbarch,
1902 SYMBOL_VALUE_ADDRESS (sym)));
1903 break;
1904 case LOC_REGISTER:
1905 /* GDBARCH is the architecture associated with the objfile
1906 the symbol is defined in; the target architecture may be
1907 different, and may provide additional registers. However,
1908 we do not know the target architecture at this point.
1909 We assume the objfile architecture will contain all the
1910 standard registers that occur in debug info in that
1911 objfile. */
1912 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1913
1914 if (SYMBOL_IS_ARGUMENT (sym))
1915 printf_filtered ("an argument in register $%s",
1916 gdbarch_register_name (gdbarch, regno));
1917 else
1918 printf_filtered ("a local variable in register $%s",
1919 gdbarch_register_name (gdbarch, regno));
1920 break;
1921 case LOC_ARG:
1922 printf_filtered ("an argument at stack/frame offset %ld",
1923 SYMBOL_VALUE (sym));
1924 break;
1925 case LOC_LOCAL:
1926 printf_filtered ("a local variable at frame offset %ld",
1927 SYMBOL_VALUE (sym));
1928 break;
1929 case LOC_REF_ARG:
1930 printf_filtered ("a reference argument at offset %ld",
1931 SYMBOL_VALUE (sym));
1932 break;
1933 case LOC_REGPARM_ADDR:
1934 /* Note comment at LOC_REGISTER. */
1935 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1936 printf_filtered ("the address of an argument, in register $%s",
1937 gdbarch_register_name (gdbarch, regno));
1938 break;
1939 case LOC_TYPEDEF:
1940 printf_filtered ("a typedef.\n");
1941 continue;
1942 case LOC_LABEL:
1943 printf_filtered ("a label at address ");
1944 printf_filtered ("%s", paddress (gdbarch,
1945 SYMBOL_VALUE_ADDRESS (sym)));
1946 break;
1947 case LOC_BLOCK:
1948 printf_filtered ("a function at address ");
1949 printf_filtered ("%s",
1950 paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
1951 break;
1952 case LOC_UNRESOLVED:
1953 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
1954 NULL, NULL);
1955 if (msym == NULL)
1956 printf_filtered ("Unresolved Static");
1957 else
1958 {
1959 printf_filtered ("static storage at address ");
1960 printf_filtered ("%s",
1961 paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym)));
1962 }
1963 break;
1964 case LOC_OPTIMIZED_OUT:
1965 printf_filtered ("optimized out.\n");
1966 continue;
1967 case LOC_COMPUTED:
1968 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, gdb_stdout);
1969 break;
1970 }
1971 if (SYMBOL_TYPE (sym))
1972 printf_filtered (", length %d.\n",
1973 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
1974 }
1975 if (BLOCK_FUNCTION (block))
1976 break;
1977 else
1978 block = BLOCK_SUPERBLOCK (block);
1979 }
1980 if (count <= 0)
1981 printf_filtered ("Scope for %s contains no locals or arguments.\n",
1982 save_args);
1983 }
1984
1985 /* worker function (cleanup) */
1986 static void
1987 replace_comma (void *data)
1988 {
1989 char *comma = data;
1990 *comma = ',';
1991 }
1992
1993 /* tdump command */
1994 static void
1995 trace_dump_command (char *args, int from_tty)
1996 {
1997 struct regcache *regcache;
1998 struct gdbarch *gdbarch;
1999 struct breakpoint *t;
2000 struct action_line *action;
2001 char *action_exp, *next_comma;
2002 struct cleanup *old_cleanups;
2003 int stepping_actions = 0;
2004 int stepping_frame = 0;
2005
2006 if (!target_is_remote ())
2007 {
2008 error (_("Trace can only be run on remote targets."));
2009 return;
2010 }
2011
2012 if (tracepoint_number == -1)
2013 {
2014 warning (_("No current trace frame."));
2015 return;
2016 }
2017
2018 t = get_tracepoint (tracepoint_number);
2019
2020 if (t == NULL)
2021 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2022 tracepoint_number);
2023
2024 old_cleanups = make_cleanup (null_cleanup, NULL);
2025
2026 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2027 tracepoint_number, traceframe_number);
2028
2029 /* The current frame is a trap frame if the frame PC is equal
2030 to the tracepoint PC. If not, then the current frame was
2031 collected during single-stepping. */
2032
2033 regcache = get_current_regcache ();
2034 gdbarch = get_regcache_arch (regcache);
2035
2036 stepping_frame = (t->loc->address != (regcache_read_pc (regcache)
2037 - gdbarch_decr_pc_after_break (gdbarch)));
2038
2039 for (action = t->actions; action; action = action->next)
2040 {
2041 struct cmd_list_element *cmd;
2042
2043 QUIT; /* allow user to bail out with ^C */
2044 action_exp = action->action;
2045 while (isspace ((int) *action_exp))
2046 action_exp++;
2047
2048 /* The collection actions to be done while stepping are
2049 bracketed by the commands "while-stepping" and "end". */
2050
2051 if (*action_exp == '#') /* comment line */
2052 continue;
2053
2054 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
2055 if (cmd == 0)
2056 error (_("Bad action list item: %s"), action_exp);
2057
2058 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
2059 stepping_actions = 1;
2060 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
2061 stepping_actions = 0;
2062 else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
2063 {
2064 /* Display the collected data.
2065 For the trap frame, display only what was collected at
2066 the trap. Likewise for stepping frames, display only
2067 what was collected while stepping. This means that the
2068 two boolean variables, STEPPING_FRAME and
2069 STEPPING_ACTIONS should be equal. */
2070 if (stepping_frame == stepping_actions)
2071 {
2072 do
2073 { /* repeat over a comma-separated list */
2074 QUIT; /* allow user to bail out with ^C */
2075 if (*action_exp == ',')
2076 action_exp++;
2077 while (isspace ((int) *action_exp))
2078 action_exp++;
2079
2080 next_comma = strchr (action_exp, ',');
2081
2082 if (0 == strncasecmp (action_exp, "$reg", 4))
2083 registers_info (NULL, from_tty);
2084 else if (0 == strncasecmp (action_exp, "$loc", 4))
2085 locals_info (NULL, from_tty);
2086 else if (0 == strncasecmp (action_exp, "$arg", 4))
2087 args_info (NULL, from_tty);
2088 else
2089 { /* variable */
2090 if (next_comma)
2091 {
2092 make_cleanup (replace_comma, next_comma);
2093 *next_comma = '\0';
2094 }
2095 printf_filtered ("%s = ", action_exp);
2096 output_command (action_exp, from_tty);
2097 printf_filtered ("\n");
2098 }
2099 if (next_comma)
2100 *next_comma = ',';
2101 action_exp = next_comma;
2102 }
2103 while (action_exp && *action_exp == ',');
2104 }
2105 }
2106 }
2107 discard_cleanups (old_cleanups);
2108 }
2109
2110 /* Convert the memory pointed to by mem into hex, placing result in buf.
2111 * Return a pointer to the last char put in buf (null)
2112 * "stolen" from sparc-stub.c
2113 */
2114
2115 static const char hexchars[] = "0123456789abcdef";
2116
2117 static char *
2118 mem2hex (gdb_byte *mem, char *buf, int count)
2119 {
2120 gdb_byte ch;
2121
2122 while (count-- > 0)
2123 {
2124 ch = *mem++;
2125
2126 *buf++ = hexchars[ch >> 4];
2127 *buf++ = hexchars[ch & 0xf];
2128 }
2129
2130 *buf = 0;
2131
2132 return buf;
2133 }
2134
2135 int
2136 get_traceframe_number (void)
2137 {
2138 return traceframe_number;
2139 }
2140
2141
2142 /* module initialization */
2143 void
2144 _initialize_tracepoint (void)
2145 {
2146 struct cmd_list_element *c;
2147
2148 traceframe_number = -1;
2149 tracepoint_number = -1;
2150
2151 if (tracepoint_list.list == NULL)
2152 {
2153 tracepoint_list.listsize = 128;
2154 tracepoint_list.list = xmalloc
2155 (tracepoint_list.listsize * sizeof (struct memrange));
2156 }
2157 if (tracepoint_list.aexpr_list == NULL)
2158 {
2159 tracepoint_list.aexpr_listsize = 128;
2160 tracepoint_list.aexpr_list = xmalloc
2161 (tracepoint_list.aexpr_listsize * sizeof (struct agent_expr *));
2162 }
2163
2164 if (stepping_list.list == NULL)
2165 {
2166 stepping_list.listsize = 128;
2167 stepping_list.list = xmalloc
2168 (stepping_list.listsize * sizeof (struct memrange));
2169 }
2170
2171 if (stepping_list.aexpr_list == NULL)
2172 {
2173 stepping_list.aexpr_listsize = 128;
2174 stepping_list.aexpr_list = xmalloc
2175 (stepping_list.aexpr_listsize * sizeof (struct agent_expr *));
2176 }
2177
2178 add_info ("scope", scope_info,
2179 _("List the variables local to a scope"));
2180
2181 add_cmd ("tracepoints", class_trace, NULL,
2182 _("Tracing of program execution without stopping the program."),
2183 &cmdlist);
2184
2185 add_com ("tdump", class_trace, trace_dump_command,
2186 _("Print everything collected at the current tracepoint."));
2187
2188 add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\
2189 Select a trace frame;\n\
2190 No argument means forward by one frame; '-' means backward by one frame."),
2191 &tfindlist, "tfind ", 1, &cmdlist);
2192
2193 add_cmd ("outside", class_trace, trace_find_outside_command, _("\
2194 Select a trace frame whose PC is outside the given range.\n\
2195 Usage: tfind outside addr1, addr2"),
2196 &tfindlist);
2197
2198 add_cmd ("range", class_trace, trace_find_range_command, _("\
2199 Select a trace frame whose PC is in the given range.\n\
2200 Usage: tfind range addr1,addr2"),
2201 &tfindlist);
2202
2203 add_cmd ("line", class_trace, trace_find_line_command, _("\
2204 Select a trace frame by source line.\n\
2205 Argument can be a line number (with optional source file), \n\
2206 a function name, or '*' followed by an address.\n\
2207 Default argument is 'the next source line that was traced'."),
2208 &tfindlist);
2209
2210 add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, _("\
2211 Select a trace frame by tracepoint number.\n\
2212 Default is the tracepoint for the current trace frame."),
2213 &tfindlist);
2214
2215 add_cmd ("pc", class_trace, trace_find_pc_command, _("\
2216 Select a trace frame by PC.\n\
2217 Default is the current PC, or the PC of the current trace frame."),
2218 &tfindlist);
2219
2220 add_cmd ("end", class_trace, trace_find_end_command, _("\
2221 Synonym for 'none'.\n\
2222 De-select any trace frame and resume 'live' debugging."),
2223 &tfindlist);
2224
2225 add_cmd ("none", class_trace, trace_find_none_command,
2226 _("De-select any trace frame and resume 'live' debugging."),
2227 &tfindlist);
2228
2229 add_cmd ("start", class_trace, trace_find_start_command,
2230 _("Select the first trace frame in the trace buffer."),
2231 &tfindlist);
2232
2233 add_com ("tstatus", class_trace, trace_status_command,
2234 _("Display the status of the current trace data collection."));
2235
2236 add_com ("tstop", class_trace, trace_stop_command,
2237 _("Stop trace data collection."));
2238
2239 add_com ("tstart", class_trace, trace_start_command,
2240 _("Start trace data collection."));
2241
2242 add_com ("end", class_trace, end_actions_pseudocommand, _("\
2243 Ends a list of commands or actions.\n\
2244 Several GDB commands allow you to enter a list of commands or actions.\n\
2245 Entering \"end\" on a line by itself is the normal way to terminate\n\
2246 such a list.\n\n\
2247 Note: the \"end\" command cannot be used at the gdb prompt."));
2248
2249 add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\
2250 Specify single-stepping behavior at a tracepoint.\n\
2251 Argument is number of instructions to trace in single-step mode\n\
2252 following the tracepoint. This command is normally followed by\n\
2253 one or more \"collect\" commands, to specify what to collect\n\
2254 while single-stepping.\n\n\
2255 Note: this command can only be used in a tracepoint \"actions\" list."));
2256
2257 add_com_alias ("ws", "while-stepping", class_alias, 0);
2258 add_com_alias ("stepping", "while-stepping", class_alias, 0);
2259
2260 add_com ("collect", class_trace, collect_pseudocommand, _("\
2261 Specify one or more data items to be collected at a tracepoint.\n\
2262 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2263 collect all data (variables, registers) referenced by that expression.\n\
2264 Also accepts the following special arguments:\n\
2265 $regs -- all registers.\n\
2266 $args -- all function arguments.\n\
2267 $locals -- all variables local to the block/function scope.\n\
2268 Note: this command can only be used in a tracepoint \"actions\" list."));
2269
2270 add_com ("actions", class_trace, trace_actions_command, _("\
2271 Specify the actions to be taken at a tracepoint.\n\
2272 Tracepoint actions may include collecting of specified data, \n\
2273 single-stepping, or enabling/disabling other tracepoints, \n\
2274 depending on target's capabilities."));
2275
2276 target_buf_size = 2048;
2277 target_buf = xmalloc (target_buf_size);
2278 }