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