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