* target.h (struct section_table): Rename to ...
[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 (lookup_internalvar ("trace_frame"),
212 value_from_longest (builtin_type_int32, (LONGEST) num));
213 }
214
215 /* Set tracepoint number to NUM. */
216 static void
217 set_tracepoint_num (int num)
218 {
219 tracepoint_number = num;
220 set_internalvar (lookup_internalvar ("tracepoint"),
221 value_from_longest (builtin_type_int32, (LONGEST) num));
222 }
223
224 /* Set externally visible debug variables for querying/printing
225 the traceframe context (line, function, file) */
226
227 static void
228 set_traceframe_context (struct frame_info *trace_frame)
229 {
230 CORE_ADDR trace_pc;
231
232 static struct type *func_string, *file_string;
233 static struct type *func_range, *file_range;
234 struct value *func_val;
235 struct value *file_val;
236 int len;
237
238 if (trace_frame == NULL) /* Cease debugging any trace buffers. */
239 {
240 traceframe_fun = 0;
241 traceframe_sal.pc = traceframe_sal.line = 0;
242 traceframe_sal.symtab = NULL;
243 set_internalvar (lookup_internalvar ("trace_func"),
244 allocate_value (builtin_type_void));
245 set_internalvar (lookup_internalvar ("trace_file"),
246 allocate_value (builtin_type_void));
247 set_internalvar (lookup_internalvar ("trace_line"),
248 value_from_longest (builtin_type_int32,
249 (LONGEST) - 1));
250 return;
251 }
252
253 /* Save as globals for internal use. */
254 trace_pc = get_frame_pc (trace_frame);
255 traceframe_sal = find_pc_line (trace_pc, 0);
256 traceframe_fun = find_pc_function (trace_pc);
257
258 /* Save linenumber as "$trace_line", a debugger variable visible to
259 users. */
260 set_internalvar (lookup_internalvar ("trace_line"),
261 value_from_longest (builtin_type_int32,
262 (LONGEST) traceframe_sal.line));
263
264 /* Save func name as "$trace_func", a debugger variable visible to
265 users. */
266 if (traceframe_fun == NULL ||
267 SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
268 set_internalvar (lookup_internalvar ("trace_func"),
269 allocate_value (builtin_type_void));
270 else
271 {
272 len = strlen (SYMBOL_LINKAGE_NAME (traceframe_fun));
273 func_range = create_range_type (func_range,
274 builtin_type_int32, 0, len - 1);
275 func_string = create_array_type (func_string,
276 builtin_type_true_char, func_range);
277 func_val = allocate_value (func_string);
278 deprecated_set_value_type (func_val, func_string);
279 memcpy (value_contents_raw (func_val),
280 SYMBOL_LINKAGE_NAME (traceframe_fun),
281 len);
282 deprecated_set_value_modifiable (func_val, 0);
283 set_internalvar (lookup_internalvar ("trace_func"), func_val);
284 }
285
286 /* Save file name as "$trace_file", a debugger variable visible to
287 users. */
288 if (traceframe_sal.symtab == NULL ||
289 traceframe_sal.symtab->filename == NULL)
290 set_internalvar (lookup_internalvar ("trace_file"),
291 allocate_value (builtin_type_void));
292 else
293 {
294 len = strlen (traceframe_sal.symtab->filename);
295 file_range = create_range_type (file_range,
296 builtin_type_int32, 0, len - 1);
297 file_string = create_array_type (file_string,
298 builtin_type_true_char, file_range);
299 file_val = allocate_value (file_string);
300 deprecated_set_value_type (file_val, file_string);
301 memcpy (value_contents_raw (file_val),
302 traceframe_sal.symtab->filename,
303 len);
304 deprecated_set_value_modifiable (file_val, 0);
305 set_internalvar (lookup_internalvar ("trace_file"), file_val);
306 }
307 }
308
309 /* ACTIONS functions: */
310
311 /* Prototypes for action-parsing utility commands */
312 static void read_actions (struct breakpoint *);
313
314 /* The three functions:
315 collect_pseudocommand,
316 while_stepping_pseudocommand, and
317 end_actions_pseudocommand
318 are placeholders for "commands" that are actually ONLY to be used
319 within a tracepoint action list. If the actual function is ever called,
320 it means that somebody issued the "command" at the top level,
321 which is always an error. */
322
323 void
324 end_actions_pseudocommand (char *args, int from_tty)
325 {
326 error (_("This command cannot be used at the top level."));
327 }
328
329 void
330 while_stepping_pseudocommand (char *args, int from_tty)
331 {
332 error (_("This command can only be used in a tracepoint actions list."));
333 }
334
335 static void
336 collect_pseudocommand (char *args, int from_tty)
337 {
338 error (_("This command can only be used in a tracepoint actions list."));
339 }
340
341 /* Enter a list of actions for a tracepoint. */
342 static void
343 trace_actions_command (char *args, int from_tty)
344 {
345 struct breakpoint *t;
346 char tmpbuf[128];
347 char *end_msg = "End with a line saying just \"end\".";
348
349 t = get_tracepoint_by_number (&args, 0, 1);
350 if (t)
351 {
352 sprintf (tmpbuf, "Enter actions for tracepoint %d, one per line.",
353 t->number);
354
355 if (from_tty)
356 {
357 if (deprecated_readline_begin_hook)
358 (*deprecated_readline_begin_hook) ("%s %s\n", tmpbuf, end_msg);
359 else if (input_from_terminal_p ())
360 printf_filtered ("%s\n%s\n", tmpbuf, end_msg);
361 }
362
363 free_actions (t);
364 t->step_count = 0; /* read_actions may set this */
365 read_actions (t);
366
367 if (deprecated_readline_end_hook)
368 (*deprecated_readline_end_hook) ();
369 /* tracepoints_changed () */
370 }
371 /* else just return */
372 }
373
374 /* worker function */
375 static void
376 read_actions (struct breakpoint *t)
377 {
378 char *line;
379 char *prompt1 = "> ", *prompt2 = " > ";
380 char *prompt = prompt1;
381 enum actionline_type linetype;
382 extern FILE *instream;
383 struct action_line *next = NULL, *temp;
384 struct cleanup *old_chain;
385
386 /* Control-C quits instantly if typed while in this loop
387 since it should not wait until the user types a newline. */
388 immediate_quit++;
389 /* FIXME: kettenis/20010823: Something is wrong here. In this file
390 STOP_SIGNAL is never defined. So this code has been left out, at
391 least for quite a while now. Replacing STOP_SIGNAL with SIGTSTP
392 leads to compilation failures since the variable job_control
393 isn't declared. Leave this alone for now. */
394 #ifdef STOP_SIGNAL
395 if (job_control)
396 signal (STOP_SIGNAL, handle_stop_sig);
397 #endif
398 old_chain = make_cleanup_free_actions (t);
399 while (1)
400 {
401 /* Make sure that all output has been output. Some machines may
402 let you get away with leaving out some of the gdb_flush, but
403 not all. */
404 wrap_here ("");
405 gdb_flush (gdb_stdout);
406 gdb_flush (gdb_stderr);
407
408 if (deprecated_readline_hook && instream == NULL)
409 line = (*deprecated_readline_hook) (prompt);
410 else if (instream == stdin && ISATTY (instream))
411 {
412 line = gdb_readline_wrapper (prompt);
413 if (line && *line) /* add it to command history */
414 add_history (line);
415 }
416 else
417 line = gdb_readline (0);
418
419 if (!line)
420 {
421 line = xstrdup ("end");
422 printf_filtered ("end\n");
423 }
424
425 linetype = validate_actionline (&line, t);
426 if (linetype == BADLINE)
427 continue; /* already warned -- collect another line */
428
429 temp = xmalloc (sizeof (struct action_line));
430 temp->next = NULL;
431 temp->action = line;
432
433 if (next == NULL) /* first action for this tracepoint? */
434 t->actions = next = temp;
435 else
436 {
437 next->next = temp;
438 next = temp;
439 }
440
441 if (linetype == STEPPING) /* begin "while-stepping" */
442 {
443 if (prompt == prompt2)
444 {
445 warning (_("Already processing 'while-stepping'"));
446 continue;
447 }
448 else
449 prompt = prompt2; /* change prompt for stepping actions */
450 }
451 else if (linetype == END)
452 {
453 if (prompt == prompt2)
454 {
455 prompt = prompt1; /* end of single-stepping actions */
456 }
457 else
458 { /* end of actions */
459 if (t->actions->next == NULL)
460 {
461 /* An "end" all by itself with no other actions
462 means this tracepoint has no actions.
463 Discard empty list. */
464 free_actions (t);
465 }
466 break;
467 }
468 }
469 }
470 #ifdef STOP_SIGNAL
471 if (job_control)
472 signal (STOP_SIGNAL, SIG_DFL);
473 #endif
474 immediate_quit--;
475 discard_cleanups (old_chain);
476 }
477
478 /* worker function */
479 enum actionline_type
480 validate_actionline (char **line, struct breakpoint *t)
481 {
482 struct cmd_list_element *c;
483 struct expression *exp = NULL;
484 struct cleanup *old_chain = NULL;
485 char *p;
486
487 /* if EOF is typed, *line is NULL */
488 if (*line == NULL)
489 return END;
490
491 for (p = *line; isspace ((int) *p);)
492 p++;
493
494 /* Symbol lookup etc. */
495 if (*p == '\0') /* empty line: just prompt for another line. */
496 return BADLINE;
497
498 if (*p == '#') /* comment line */
499 return GENERIC;
500
501 c = lookup_cmd (&p, cmdlist, "", -1, 1);
502 if (c == 0)
503 {
504 warning (_("'%s' is not an action that I know, or is ambiguous."),
505 p);
506 return BADLINE;
507 }
508
509 if (cmd_cfunc_eq (c, collect_pseudocommand))
510 {
511 struct agent_expr *aexpr;
512 struct agent_reqs areqs;
513
514 do
515 { /* repeat over a comma-separated list */
516 QUIT; /* allow user to bail out with ^C */
517 while (isspace ((int) *p))
518 p++;
519
520 if (*p == '$') /* look for special pseudo-symbols */
521 {
522 if ((0 == strncasecmp ("reg", p + 1, 3)) ||
523 (0 == strncasecmp ("arg", p + 1, 3)) ||
524 (0 == strncasecmp ("loc", p + 1, 3)))
525 {
526 p = strchr (p, ',');
527 continue;
528 }
529 /* else fall thru, treat p as an expression and parse it! */
530 }
531 exp = parse_exp_1 (&p, block_for_pc (t->loc->address), 1);
532 old_chain = make_cleanup (free_current_contents, &exp);
533
534 if (exp->elts[0].opcode == OP_VAR_VALUE)
535 {
536 if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
537 {
538 warning (_("constant %s (value %ld) will not be collected."),
539 SYMBOL_PRINT_NAME (exp->elts[2].symbol),
540 SYMBOL_VALUE (exp->elts[2].symbol));
541 return BADLINE;
542 }
543 else if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_OPTIMIZED_OUT)
544 {
545 warning (_("%s is optimized away and cannot be collected."),
546 SYMBOL_PRINT_NAME (exp->elts[2].symbol));
547 return BADLINE;
548 }
549 }
550
551 /* We have something to collect, make sure that the expr to
552 bytecode translator can handle it and that it's not too
553 long. */
554 aexpr = gen_trace_for_expr (t->loc->address, exp);
555 make_cleanup_free_agent_expr (aexpr);
556
557 if (aexpr->len > MAX_AGENT_EXPR_LEN)
558 error (_("expression too complicated, try simplifying"));
559
560 ax_reqs (aexpr, &areqs);
561 (void) make_cleanup (xfree, areqs.reg_mask);
562
563 if (areqs.flaw != agent_flaw_none)
564 error (_("malformed expression"));
565
566 if (areqs.min_height < 0)
567 error (_("gdb: Internal error: expression has min height < 0"));
568
569 if (areqs.max_height > 20)
570 error (_("expression too complicated, try simplifying"));
571
572 do_cleanups (old_chain);
573 }
574 while (p && *p++ == ',');
575 return GENERIC;
576 }
577 else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
578 {
579 char *steparg; /* in case warning is necessary */
580
581 while (isspace ((int) *p))
582 p++;
583 steparg = p;
584
585 if (*p == '\0' ||
586 (t->step_count = strtol (p, &p, 0)) == 0)
587 {
588 warning (_("'%s': bad step-count; command ignored."), *line);
589 return BADLINE;
590 }
591 return STEPPING;
592 }
593 else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
594 return END;
595 else
596 {
597 warning (_("'%s' is not a supported tracepoint action."), *line);
598 return BADLINE;
599 }
600 }
601
602 /* worker function */
603 void
604 free_actions (struct breakpoint *t)
605 {
606 struct action_line *line, *next;
607
608 for (line = t->actions; line; line = next)
609 {
610 next = line->next;
611 if (line->action)
612 xfree (line->action);
613 xfree (line);
614 }
615 t->actions = NULL;
616 }
617
618 static void
619 do_free_actions_cleanup (void *t)
620 {
621 free_actions (t);
622 }
623
624 static struct cleanup *
625 make_cleanup_free_actions (struct breakpoint *t)
626 {
627 return make_cleanup (do_free_actions_cleanup, t);
628 }
629
630 enum {
631 memrange_absolute = -1
632 };
633
634 struct memrange
635 {
636 int type; /* memrange_absolute for absolute memory range,
637 else basereg number */
638 bfd_signed_vma start;
639 bfd_signed_vma end;
640 };
641
642 struct collection_list
643 {
644 unsigned char regs_mask[32]; /* room for up to 256 regs */
645 long listsize;
646 long next_memrange;
647 struct memrange *list;
648 long aexpr_listsize; /* size of array pointed to by expr_list elt */
649 long next_aexpr_elt;
650 struct agent_expr **aexpr_list;
651
652 }
653 tracepoint_list, stepping_list;
654
655 /* MEMRANGE functions: */
656
657 static int memrange_cmp (const void *, const void *);
658
659 /* compare memranges for qsort */
660 static int
661 memrange_cmp (const void *va, const void *vb)
662 {
663 const struct memrange *a = va, *b = vb;
664
665 if (a->type < b->type)
666 return -1;
667 if (a->type > b->type)
668 return 1;
669 if (a->type == memrange_absolute)
670 {
671 if ((bfd_vma) a->start < (bfd_vma) b->start)
672 return -1;
673 if ((bfd_vma) a->start > (bfd_vma) b->start)
674 return 1;
675 }
676 else
677 {
678 if (a->start < b->start)
679 return -1;
680 if (a->start > b->start)
681 return 1;
682 }
683 return 0;
684 }
685
686 /* Sort the memrange list using qsort, and merge adjacent memranges. */
687 static void
688 memrange_sortmerge (struct collection_list *memranges)
689 {
690 int a, b;
691
692 qsort (memranges->list, memranges->next_memrange,
693 sizeof (struct memrange), memrange_cmp);
694 if (memranges->next_memrange > 0)
695 {
696 for (a = 0, b = 1; b < memranges->next_memrange; b++)
697 {
698 if (memranges->list[a].type == memranges->list[b].type &&
699 memranges->list[b].start - memranges->list[a].end <=
700 MAX_REGISTER_SIZE)
701 {
702 /* memrange b starts before memrange a ends; merge them. */
703 if (memranges->list[b].end > memranges->list[a].end)
704 memranges->list[a].end = memranges->list[b].end;
705 continue; /* next b, same a */
706 }
707 a++; /* next a */
708 if (a != b)
709 memcpy (&memranges->list[a], &memranges->list[b],
710 sizeof (struct memrange));
711 }
712 memranges->next_memrange = a + 1;
713 }
714 }
715
716 /* Add a register to a collection list. */
717 static void
718 add_register (struct collection_list *collection, unsigned int regno)
719 {
720 if (info_verbose)
721 printf_filtered ("collect register %d\n", regno);
722 if (regno >= (8 * sizeof (collection->regs_mask)))
723 error (_("Internal: register number %d too large for tracepoint"),
724 regno);
725 collection->regs_mask[regno / 8] |= 1 << (regno % 8);
726 }
727
728 /* Add a memrange to a collection list */
729 static void
730 add_memrange (struct collection_list *memranges,
731 int type, bfd_signed_vma base,
732 unsigned long len)
733 {
734 if (info_verbose)
735 {
736 printf_filtered ("(%d,", type);
737 printf_vma (base);
738 printf_filtered (",%ld)\n", len);
739 }
740
741 /* type: memrange_absolute == memory, other n == basereg */
742 memranges->list[memranges->next_memrange].type = type;
743 /* base: addr if memory, offset if reg relative. */
744 memranges->list[memranges->next_memrange].start = base;
745 /* len: we actually save end (base + len) for convenience */
746 memranges->list[memranges->next_memrange].end = base + len;
747 memranges->next_memrange++;
748 if (memranges->next_memrange >= memranges->listsize)
749 {
750 memranges->listsize *= 2;
751 memranges->list = xrealloc (memranges->list,
752 memranges->listsize);
753 }
754
755 if (type != memrange_absolute) /* Better collect the base register! */
756 add_register (memranges, type);
757 }
758
759 /* Add a symbol to a collection list. */
760 static void
761 collect_symbol (struct collection_list *collect,
762 struct symbol *sym,
763 long frame_regno, long frame_offset)
764 {
765 unsigned long len;
766 unsigned int reg;
767 bfd_signed_vma offset;
768
769 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
770 switch (SYMBOL_CLASS (sym))
771 {
772 default:
773 printf_filtered ("%s: don't know symbol class %d\n",
774 SYMBOL_PRINT_NAME (sym),
775 SYMBOL_CLASS (sym));
776 break;
777 case LOC_CONST:
778 printf_filtered ("constant %s (value %ld) will not be collected.\n",
779 SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE (sym));
780 break;
781 case LOC_STATIC:
782 offset = SYMBOL_VALUE_ADDRESS (sym);
783 if (info_verbose)
784 {
785 char tmp[40];
786
787 sprintf_vma (tmp, offset);
788 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
789 SYMBOL_PRINT_NAME (sym), len,
790 tmp /* address */);
791 }
792 add_memrange (collect, memrange_absolute, offset, len);
793 break;
794 case LOC_REGISTER:
795 reg = SYMBOL_VALUE (sym);
796 if (info_verbose)
797 printf_filtered ("LOC_REG[parm] %s: ",
798 SYMBOL_PRINT_NAME (sym));
799 add_register (collect, reg);
800 /* Check for doubles stored in two registers. */
801 /* FIXME: how about larger types stored in 3 or more regs? */
802 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
803 len > register_size (current_gdbarch, reg))
804 add_register (collect, reg + 1);
805 break;
806 case LOC_REF_ARG:
807 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
808 printf_filtered (" (will not collect %s)\n",
809 SYMBOL_PRINT_NAME (sym));
810 break;
811 case LOC_ARG:
812 reg = frame_regno;
813 offset = frame_offset + SYMBOL_VALUE (sym);
814 if (info_verbose)
815 {
816 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
817 SYMBOL_PRINT_NAME (sym), len);
818 printf_vma (offset);
819 printf_filtered (" from frame ptr reg %d\n", reg);
820 }
821 add_memrange (collect, reg, offset, len);
822 break;
823 case LOC_REGPARM_ADDR:
824 reg = SYMBOL_VALUE (sym);
825 offset = 0;
826 if (info_verbose)
827 {
828 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
829 SYMBOL_PRINT_NAME (sym), len);
830 printf_vma (offset);
831 printf_filtered (" from reg %d\n", reg);
832 }
833 add_memrange (collect, reg, offset, len);
834 break;
835 case LOC_LOCAL:
836 reg = frame_regno;
837 offset = frame_offset + SYMBOL_VALUE (sym);
838 if (info_verbose)
839 {
840 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
841 SYMBOL_PRINT_NAME (sym), len);
842 printf_vma (offset);
843 printf_filtered (" from frame ptr reg %d\n", reg);
844 }
845 add_memrange (collect, reg, offset, len);
846 break;
847 case LOC_UNRESOLVED:
848 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
849 SYMBOL_PRINT_NAME (sym));
850 break;
851 case LOC_OPTIMIZED_OUT:
852 printf_filtered ("%s has been optimized out of existence.\n",
853 SYMBOL_PRINT_NAME (sym));
854 break;
855 }
856 }
857
858 /* Add all locals (or args) symbols to collection list */
859 static void
860 add_local_symbols (struct collection_list *collect, CORE_ADDR pc,
861 long frame_regno, long frame_offset, int type)
862 {
863 struct symbol *sym;
864 struct block *block;
865 struct dict_iterator iter;
866 int count = 0;
867
868 block = block_for_pc (pc);
869 while (block != 0)
870 {
871 QUIT; /* allow user to bail out with ^C */
872 ALL_BLOCK_SYMBOLS (block, iter, sym)
873 {
874 if (SYMBOL_IS_ARGUMENT (sym)
875 ? type == 'A' /* collecting Arguments */
876 : type == 'L') /* collecting Locals */
877 {
878 count++;
879 collect_symbol (collect, sym, frame_regno,
880 frame_offset);
881 }
882 }
883 if (BLOCK_FUNCTION (block))
884 break;
885 else
886 block = BLOCK_SUPERBLOCK (block);
887 }
888 if (count == 0)
889 warning (_("No %s found in scope."),
890 type == 'L' ? "locals" : "args");
891 }
892
893 /* worker function */
894 static void
895 clear_collection_list (struct collection_list *list)
896 {
897 int ndx;
898
899 list->next_memrange = 0;
900 for (ndx = 0; ndx < list->next_aexpr_elt; ndx++)
901 {
902 free_agent_expr (list->aexpr_list[ndx]);
903 list->aexpr_list[ndx] = NULL;
904 }
905 list->next_aexpr_elt = 0;
906 memset (list->regs_mask, 0, sizeof (list->regs_mask));
907 }
908
909 /* reduce a collection list to string form (for gdb protocol) */
910 static char **
911 stringify_collection_list (struct collection_list *list, char *string)
912 {
913 char temp_buf[2048];
914 char tmp2[40];
915 int count;
916 int ndx = 0;
917 char *(*str_list)[];
918 char *end;
919 long i;
920
921 count = 1 + list->next_memrange + list->next_aexpr_elt + 1;
922 str_list = (char *(*)[]) xmalloc (count * sizeof (char *));
923
924 for (i = sizeof (list->regs_mask) - 1; i > 0; i--)
925 if (list->regs_mask[i] != 0) /* skip leading zeroes in regs_mask */
926 break;
927 if (list->regs_mask[i] != 0) /* prepare to send regs_mask to the stub */
928 {
929 if (info_verbose)
930 printf_filtered ("\nCollecting registers (mask): 0x");
931 end = temp_buf;
932 *end++ = 'R';
933 for (; i >= 0; i--)
934 {
935 QUIT; /* allow user to bail out with ^C */
936 if (info_verbose)
937 printf_filtered ("%02X", list->regs_mask[i]);
938 sprintf (end, "%02X", list->regs_mask[i]);
939 end += 2;
940 }
941 (*str_list)[ndx] = savestring (temp_buf, end - temp_buf);
942 ndx++;
943 }
944 if (info_verbose)
945 printf_filtered ("\n");
946 if (list->next_memrange > 0 && info_verbose)
947 printf_filtered ("Collecting memranges: \n");
948 for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++)
949 {
950 QUIT; /* allow user to bail out with ^C */
951 sprintf_vma (tmp2, list->list[i].start);
952 if (info_verbose)
953 {
954 printf_filtered ("(%d, %s, %ld)\n",
955 list->list[i].type,
956 tmp2,
957 (long) (list->list[i].end - list->list[i].start));
958 }
959 if (count + 27 > MAX_AGENT_EXPR_LEN)
960 {
961 (*str_list)[ndx] = savestring (temp_buf, count);
962 ndx++;
963 count = 0;
964 end = temp_buf;
965 }
966
967 {
968 bfd_signed_vma length = list->list[i].end - list->list[i].start;
969
970 /* The "%X" conversion specifier expects an unsigned argument,
971 so passing -1 (memrange_absolute) to it directly gives you
972 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
973 Special-case it. */
974 if (list->list[i].type == memrange_absolute)
975 sprintf (end, "M-1,%s,%lX", tmp2, (long) length);
976 else
977 sprintf (end, "M%X,%s,%lX", list->list[i].type, tmp2, (long) length);
978 }
979
980 count += strlen (end);
981 end = temp_buf + count;
982 }
983
984 for (i = 0; i < list->next_aexpr_elt; i++)
985 {
986 QUIT; /* allow user to bail out with ^C */
987 if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN)
988 {
989 (*str_list)[ndx] = savestring (temp_buf, count);
990 ndx++;
991 count = 0;
992 end = temp_buf;
993 }
994 sprintf (end, "X%08X,", list->aexpr_list[i]->len);
995 end += 10; /* 'X' + 8 hex digits + ',' */
996 count += 10;
997
998 end = mem2hex (list->aexpr_list[i]->buf,
999 end, list->aexpr_list[i]->len);
1000 count += 2 * list->aexpr_list[i]->len;
1001 }
1002
1003 if (count != 0)
1004 {
1005 (*str_list)[ndx] = savestring (temp_buf, count);
1006 ndx++;
1007 count = 0;
1008 end = temp_buf;
1009 }
1010 (*str_list)[ndx] = NULL;
1011
1012 if (ndx == 0)
1013 {
1014 xfree (str_list);
1015 return NULL;
1016 }
1017 else
1018 return *str_list;
1019 }
1020
1021 static void
1022 free_actions_list_cleanup_wrapper (void *al)
1023 {
1024 free_actions_list (al);
1025 }
1026
1027 static void
1028 free_actions_list (char **actions_list)
1029 {
1030 int ndx;
1031
1032 if (actions_list == 0)
1033 return;
1034
1035 for (ndx = 0; actions_list[ndx]; ndx++)
1036 xfree (actions_list[ndx]);
1037
1038 xfree (actions_list);
1039 }
1040
1041 /* Render all actions into gdb protocol. */
1042 static void
1043 encode_actions (struct breakpoint *t, char ***tdp_actions,
1044 char ***stepping_actions)
1045 {
1046 static char tdp_buff[2048], step_buff[2048];
1047 char *action_exp;
1048 struct expression *exp = NULL;
1049 struct action_line *action;
1050 int i;
1051 struct value *tempval;
1052 struct collection_list *collect;
1053 struct cmd_list_element *cmd;
1054 struct agent_expr *aexpr;
1055 int frame_reg;
1056 LONGEST frame_offset;
1057
1058
1059 clear_collection_list (&tracepoint_list);
1060 clear_collection_list (&stepping_list);
1061 collect = &tracepoint_list;
1062
1063 *tdp_actions = NULL;
1064 *stepping_actions = NULL;
1065
1066 gdbarch_virtual_frame_pointer (current_gdbarch,
1067 t->loc->address, &frame_reg, &frame_offset);
1068
1069 for (action = t->actions; action; action = action->next)
1070 {
1071 QUIT; /* allow user to bail out with ^C */
1072 action_exp = action->action;
1073 while (isspace ((int) *action_exp))
1074 action_exp++;
1075
1076 if (*action_exp == '#') /* comment line */
1077 return;
1078
1079 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
1080 if (cmd == 0)
1081 error (_("Bad action list item: %s"), action_exp);
1082
1083 if (cmd_cfunc_eq (cmd, collect_pseudocommand))
1084 {
1085 do
1086 { /* repeat over a comma-separated list */
1087 QUIT; /* allow user to bail out with ^C */
1088 while (isspace ((int) *action_exp))
1089 action_exp++;
1090
1091 if (0 == strncasecmp ("$reg", action_exp, 4))
1092 {
1093 for (i = 0; i < gdbarch_num_regs (current_gdbarch); i++)
1094 add_register (collect, i);
1095 action_exp = strchr (action_exp, ','); /* more? */
1096 }
1097 else if (0 == strncasecmp ("$arg", action_exp, 4))
1098 {
1099 add_local_symbols (collect,
1100 t->loc->address,
1101 frame_reg,
1102 frame_offset,
1103 'A');
1104 action_exp = strchr (action_exp, ','); /* more? */
1105 }
1106 else if (0 == strncasecmp ("$loc", action_exp, 4))
1107 {
1108 add_local_symbols (collect,
1109 t->loc->address,
1110 frame_reg,
1111 frame_offset,
1112 'L');
1113 action_exp = strchr (action_exp, ','); /* more? */
1114 }
1115 else
1116 {
1117 unsigned long addr, len;
1118 struct cleanup *old_chain = NULL;
1119 struct cleanup *old_chain1 = NULL;
1120 struct agent_reqs areqs;
1121
1122 exp = parse_exp_1 (&action_exp,
1123 block_for_pc (t->loc->address), 1);
1124 old_chain = make_cleanup (free_current_contents, &exp);
1125
1126 switch (exp->elts[0].opcode)
1127 {
1128 case OP_REGISTER:
1129 {
1130 const char *name = &exp->elts[2].string;
1131
1132 i = user_reg_map_name_to_regnum (current_gdbarch,
1133 name, strlen (name));
1134 if (i == -1)
1135 internal_error (__FILE__, __LINE__,
1136 _("Register $%s not available"),
1137 name);
1138 if (info_verbose)
1139 printf_filtered ("OP_REGISTER: ");
1140 add_register (collect, i);
1141 break;
1142 }
1143
1144 case UNOP_MEMVAL:
1145 /* safe because we know it's a simple expression */
1146 tempval = evaluate_expression (exp);
1147 addr = VALUE_ADDRESS (tempval) + value_offset (tempval);
1148 len = TYPE_LENGTH (check_typedef (exp->elts[1].type));
1149 add_memrange (collect, memrange_absolute, addr, len);
1150 break;
1151
1152 case OP_VAR_VALUE:
1153 collect_symbol (collect,
1154 exp->elts[2].symbol,
1155 frame_reg,
1156 frame_offset);
1157 break;
1158
1159 default: /* full-fledged expression */
1160 aexpr = gen_trace_for_expr (t->loc->address, exp);
1161
1162 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1163
1164 ax_reqs (aexpr, &areqs);
1165 if (areqs.flaw != agent_flaw_none)
1166 error (_("malformed expression"));
1167
1168 if (areqs.min_height < 0)
1169 error (_("gdb: Internal error: expression has min height < 0"));
1170 if (areqs.max_height > 20)
1171 error (_("expression too complicated, try simplifying"));
1172
1173 discard_cleanups (old_chain1);
1174 add_aexpr (collect, aexpr);
1175
1176 /* take care of the registers */
1177 if (areqs.reg_mask_len > 0)
1178 {
1179 int ndx1;
1180 int ndx2;
1181
1182 for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++)
1183 {
1184 QUIT; /* allow user to bail out with ^C */
1185 if (areqs.reg_mask[ndx1] != 0)
1186 {
1187 /* assume chars have 8 bits */
1188 for (ndx2 = 0; ndx2 < 8; ndx2++)
1189 if (areqs.reg_mask[ndx1] & (1 << ndx2))
1190 /* it's used -- record it */
1191 add_register (collect,
1192 ndx1 * 8 + ndx2);
1193 }
1194 }
1195 }
1196 break;
1197 } /* switch */
1198 do_cleanups (old_chain);
1199 } /* do */
1200 }
1201 while (action_exp && *action_exp++ == ',');
1202 } /* if */
1203 else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
1204 {
1205 collect = &stepping_list;
1206 }
1207 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
1208 {
1209 if (collect == &stepping_list) /* end stepping actions */
1210 collect = &tracepoint_list;
1211 else
1212 break; /* end tracepoint actions */
1213 }
1214 } /* for */
1215 memrange_sortmerge (&tracepoint_list);
1216 memrange_sortmerge (&stepping_list);
1217
1218 *tdp_actions = stringify_collection_list (&tracepoint_list,
1219 tdp_buff);
1220 *stepping_actions = stringify_collection_list (&stepping_list,
1221 step_buff);
1222 }
1223
1224 static void
1225 add_aexpr (struct collection_list *collect, struct agent_expr *aexpr)
1226 {
1227 if (collect->next_aexpr_elt >= collect->aexpr_listsize)
1228 {
1229 collect->aexpr_list =
1230 xrealloc (collect->aexpr_list,
1231 2 * collect->aexpr_listsize * sizeof (struct agent_expr *));
1232 collect->aexpr_listsize *= 2;
1233 }
1234 collect->aexpr_list[collect->next_aexpr_elt] = aexpr;
1235 collect->next_aexpr_elt++;
1236 }
1237
1238 static char *target_buf;
1239 static long target_buf_size;
1240
1241 /* Set "transparent" memory ranges
1242
1243 Allow trace mechanism to treat text-like sections
1244 (and perhaps all read-only sections) transparently,
1245 i.e. don't reject memory requests from these address ranges
1246 just because they haven't been collected. */
1247
1248 static void
1249 remote_set_transparent_ranges (void)
1250 {
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.076941 seconds and 4 git commands to generate.