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