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