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