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