2009-12-23 Stan Shebs <stan@codesourcery.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 CORE_ADDR scope)
734 {
735 unsigned long len;
736 unsigned int reg;
737 bfd_signed_vma offset;
738
739 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
740 switch (SYMBOL_CLASS (sym))
741 {
742 default:
743 printf_filtered ("%s: don't know symbol class %d\n",
744 SYMBOL_PRINT_NAME (sym),
745 SYMBOL_CLASS (sym));
746 break;
747 case LOC_CONST:
748 printf_filtered ("constant %s (value %ld) will not be collected.\n",
749 SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE (sym));
750 break;
751 case LOC_STATIC:
752 offset = SYMBOL_VALUE_ADDRESS (sym);
753 if (info_verbose)
754 {
755 char tmp[40];
756
757 sprintf_vma (tmp, offset);
758 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
759 SYMBOL_PRINT_NAME (sym), len,
760 tmp /* address */);
761 }
762 add_memrange (collect, memrange_absolute, offset, len);
763 break;
764 case LOC_REGISTER:
765 reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
766 if (info_verbose)
767 printf_filtered ("LOC_REG[parm] %s: ",
768 SYMBOL_PRINT_NAME (sym));
769 add_register (collect, reg);
770 /* Check for doubles stored in two registers. */
771 /* FIXME: how about larger types stored in 3 or more regs? */
772 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
773 len > register_size (gdbarch, reg))
774 add_register (collect, reg + 1);
775 break;
776 case LOC_REF_ARG:
777 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
778 printf_filtered (" (will not collect %s)\n",
779 SYMBOL_PRINT_NAME (sym));
780 break;
781 case LOC_ARG:
782 reg = frame_regno;
783 offset = frame_offset + SYMBOL_VALUE (sym);
784 if (info_verbose)
785 {
786 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
787 SYMBOL_PRINT_NAME (sym), len);
788 printf_vma (offset);
789 printf_filtered (" from frame ptr reg %d\n", reg);
790 }
791 add_memrange (collect, reg, offset, len);
792 break;
793 case LOC_REGPARM_ADDR:
794 reg = SYMBOL_VALUE (sym);
795 offset = 0;
796 if (info_verbose)
797 {
798 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
799 SYMBOL_PRINT_NAME (sym), len);
800 printf_vma (offset);
801 printf_filtered (" from reg %d\n", reg);
802 }
803 add_memrange (collect, reg, offset, len);
804 break;
805 case LOC_LOCAL:
806 reg = frame_regno;
807 offset = frame_offset + SYMBOL_VALUE (sym);
808 if (info_verbose)
809 {
810 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
811 SYMBOL_PRINT_NAME (sym), len);
812 printf_vma (offset);
813 printf_filtered (" from frame ptr reg %d\n", reg);
814 }
815 add_memrange (collect, reg, offset, len);
816 break;
817 case LOC_UNRESOLVED:
818 printf_filtered ("Don't know LOC_UNRESOLVED %s\n",
819 SYMBOL_PRINT_NAME (sym));
820 break;
821 case LOC_OPTIMIZED_OUT:
822 printf_filtered ("%s has been optimized out of existence.\n",
823 SYMBOL_PRINT_NAME (sym));
824 break;
825
826 case LOC_COMPUTED:
827 {
828 struct agent_expr *aexpr;
829 struct cleanup *old_chain1 = NULL;
830 struct agent_reqs areqs;
831
832 aexpr = gen_trace_for_var (scope, sym);
833
834 old_chain1 = make_cleanup_free_agent_expr (aexpr);
835
836 ax_reqs (aexpr, &areqs);
837 if (areqs.flaw != agent_flaw_none)
838 error (_("malformed expression"));
839
840 if (areqs.min_height < 0)
841 error (_("gdb: Internal error: expression has min height < 0"));
842 if (areqs.max_height > 20)
843 error (_("expression too complicated, try simplifying"));
844
845 discard_cleanups (old_chain1);
846 add_aexpr (collect, aexpr);
847
848 /* take care of the registers */
849 if (areqs.reg_mask_len > 0)
850 {
851 int ndx1, ndx2;
852
853 for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++)
854 {
855 QUIT; /* allow user to bail out with ^C */
856 if (areqs.reg_mask[ndx1] != 0)
857 {
858 /* assume chars have 8 bits */
859 for (ndx2 = 0; ndx2 < 8; ndx2++)
860 if (areqs.reg_mask[ndx1] & (1 << ndx2))
861 /* it's used -- record it */
862 add_register (collect,
863 ndx1 * 8 + ndx2);
864 }
865 }
866 }
867 }
868 break;
869 }
870 }
871
872 /* Add all locals (or args) symbols to collection list */
873 static void
874 add_local_symbols (struct collection_list *collect,
875 struct gdbarch *gdbarch, CORE_ADDR pc,
876 long frame_regno, long frame_offset, int type)
877 {
878 struct symbol *sym;
879 struct block *block;
880 struct dict_iterator iter;
881 int count = 0;
882
883 block = block_for_pc (pc);
884 while (block != 0)
885 {
886 QUIT; /* allow user to bail out with ^C */
887 ALL_BLOCK_SYMBOLS (block, iter, sym)
888 {
889 if (SYMBOL_IS_ARGUMENT (sym)
890 ? type == 'A' /* collecting Arguments */
891 : type == 'L') /* collecting Locals */
892 {
893 count++;
894 collect_symbol (collect, sym, gdbarch,
895 frame_regno, frame_offset, pc);
896 }
897 }
898 if (BLOCK_FUNCTION (block))
899 break;
900 else
901 block = BLOCK_SUPERBLOCK (block);
902 }
903 if (count == 0)
904 warning (_("No %s found in scope."),
905 type == 'L' ? "locals" : "args");
906 }
907
908 /* worker function */
909 static void
910 clear_collection_list (struct collection_list *list)
911 {
912 int ndx;
913
914 list->next_memrange = 0;
915 for (ndx = 0; ndx < list->next_aexpr_elt; ndx++)
916 {
917 free_agent_expr (list->aexpr_list[ndx]);
918 list->aexpr_list[ndx] = NULL;
919 }
920 list->next_aexpr_elt = 0;
921 memset (list->regs_mask, 0, sizeof (list->regs_mask));
922 }
923
924 /* reduce a collection list to string form (for gdb protocol) */
925 static char **
926 stringify_collection_list (struct collection_list *list, char *string)
927 {
928 char temp_buf[2048];
929 char tmp2[40];
930 int count;
931 int ndx = 0;
932 char *(*str_list)[];
933 char *end;
934 long i;
935
936 count = 1 + list->next_memrange + list->next_aexpr_elt + 1;
937 str_list = (char *(*)[]) xmalloc (count * sizeof (char *));
938
939 for (i = sizeof (list->regs_mask) - 1; i > 0; i--)
940 if (list->regs_mask[i] != 0) /* skip leading zeroes in regs_mask */
941 break;
942 if (list->regs_mask[i] != 0) /* prepare to send regs_mask to the stub */
943 {
944 if (info_verbose)
945 printf_filtered ("\nCollecting registers (mask): 0x");
946 end = temp_buf;
947 *end++ = 'R';
948 for (; i >= 0; i--)
949 {
950 QUIT; /* allow user to bail out with ^C */
951 if (info_verbose)
952 printf_filtered ("%02X", list->regs_mask[i]);
953 sprintf (end, "%02X", list->regs_mask[i]);
954 end += 2;
955 }
956 (*str_list)[ndx] = xstrdup (temp_buf);
957 ndx++;
958 }
959 if (info_verbose)
960 printf_filtered ("\n");
961 if (list->next_memrange > 0 && info_verbose)
962 printf_filtered ("Collecting memranges: \n");
963 for (i = 0, count = 0, end = temp_buf; i < list->next_memrange; i++)
964 {
965 QUIT; /* allow user to bail out with ^C */
966 sprintf_vma (tmp2, list->list[i].start);
967 if (info_verbose)
968 {
969 printf_filtered ("(%d, %s, %ld)\n",
970 list->list[i].type,
971 tmp2,
972 (long) (list->list[i].end - list->list[i].start));
973 }
974 if (count + 27 > MAX_AGENT_EXPR_LEN)
975 {
976 (*str_list)[ndx] = savestring (temp_buf, count);
977 ndx++;
978 count = 0;
979 end = temp_buf;
980 }
981
982 {
983 bfd_signed_vma length = list->list[i].end - list->list[i].start;
984
985 /* The "%X" conversion specifier expects an unsigned argument,
986 so passing -1 (memrange_absolute) to it directly gives you
987 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
988 Special-case it. */
989 if (list->list[i].type == memrange_absolute)
990 sprintf (end, "M-1,%s,%lX", tmp2, (long) length);
991 else
992 sprintf (end, "M%X,%s,%lX", list->list[i].type, tmp2, (long) length);
993 }
994
995 count += strlen (end);
996 end = temp_buf + count;
997 }
998
999 for (i = 0; i < list->next_aexpr_elt; i++)
1000 {
1001 QUIT; /* allow user to bail out with ^C */
1002 if ((count + 10 + 2 * list->aexpr_list[i]->len) > MAX_AGENT_EXPR_LEN)
1003 {
1004 (*str_list)[ndx] = savestring (temp_buf, count);
1005 ndx++;
1006 count = 0;
1007 end = temp_buf;
1008 }
1009 sprintf (end, "X%08X,", list->aexpr_list[i]->len);
1010 end += 10; /* 'X' + 8 hex digits + ',' */
1011 count += 10;
1012
1013 end = mem2hex (list->aexpr_list[i]->buf,
1014 end, list->aexpr_list[i]->len);
1015 count += 2 * list->aexpr_list[i]->len;
1016 }
1017
1018 if (count != 0)
1019 {
1020 (*str_list)[ndx] = savestring (temp_buf, count);
1021 ndx++;
1022 count = 0;
1023 end = temp_buf;
1024 }
1025 (*str_list)[ndx] = NULL;
1026
1027 if (ndx == 0)
1028 {
1029 xfree (str_list);
1030 return NULL;
1031 }
1032 else
1033 return *str_list;
1034 }
1035
1036 static void
1037 free_actions_list_cleanup_wrapper (void *al)
1038 {
1039 free_actions_list (al);
1040 }
1041
1042 static void
1043 free_actions_list (char **actions_list)
1044 {
1045 int ndx;
1046
1047 if (actions_list == 0)
1048 return;
1049
1050 for (ndx = 0; actions_list[ndx]; ndx++)
1051 xfree (actions_list[ndx]);
1052
1053 xfree (actions_list);
1054 }
1055
1056 /* Render all actions into gdb protocol. */
1057 static void
1058 encode_actions (struct breakpoint *t, char ***tdp_actions,
1059 char ***stepping_actions)
1060 {
1061 static char tdp_buff[2048], step_buff[2048];
1062 char *action_exp;
1063 struct expression *exp = NULL;
1064 struct action_line *action;
1065 int i;
1066 struct value *tempval;
1067 struct collection_list *collect;
1068 struct cmd_list_element *cmd;
1069 struct agent_expr *aexpr;
1070 int frame_reg;
1071 LONGEST frame_offset;
1072
1073
1074 clear_collection_list (&tracepoint_list);
1075 clear_collection_list (&stepping_list);
1076 collect = &tracepoint_list;
1077
1078 *tdp_actions = NULL;
1079 *stepping_actions = NULL;
1080
1081 gdbarch_virtual_frame_pointer (t->gdbarch,
1082 t->loc->address, &frame_reg, &frame_offset);
1083
1084 for (action = t->actions; action; action = action->next)
1085 {
1086 QUIT; /* allow user to bail out with ^C */
1087 action_exp = action->action;
1088 while (isspace ((int) *action_exp))
1089 action_exp++;
1090
1091 if (*action_exp == '#') /* comment line */
1092 return;
1093
1094 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
1095 if (cmd == 0)
1096 error (_("Bad action list item: %s"), action_exp);
1097
1098 if (cmd_cfunc_eq (cmd, collect_pseudocommand))
1099 {
1100 do
1101 { /* repeat over a comma-separated list */
1102 QUIT; /* allow user to bail out with ^C */
1103 while (isspace ((int) *action_exp))
1104 action_exp++;
1105
1106 if (0 == strncasecmp ("$reg", action_exp, 4))
1107 {
1108 for (i = 0; i < gdbarch_num_regs (t->gdbarch); i++)
1109 add_register (collect, i);
1110 action_exp = strchr (action_exp, ','); /* more? */
1111 }
1112 else if (0 == strncasecmp ("$arg", action_exp, 4))
1113 {
1114 add_local_symbols (collect,
1115 t->gdbarch,
1116 t->loc->address,
1117 frame_reg,
1118 frame_offset,
1119 'A');
1120 action_exp = strchr (action_exp, ','); /* more? */
1121 }
1122 else if (0 == strncasecmp ("$loc", action_exp, 4))
1123 {
1124 add_local_symbols (collect,
1125 t->gdbarch,
1126 t->loc->address,
1127 frame_reg,
1128 frame_offset,
1129 'L');
1130 action_exp = strchr (action_exp, ','); /* more? */
1131 }
1132 else
1133 {
1134 unsigned long addr, len;
1135 struct cleanup *old_chain = NULL;
1136 struct cleanup *old_chain1 = NULL;
1137 struct agent_reqs areqs;
1138
1139 exp = parse_exp_1 (&action_exp,
1140 block_for_pc (t->loc->address), 1);
1141 old_chain = make_cleanup (free_current_contents, &exp);
1142
1143 switch (exp->elts[0].opcode)
1144 {
1145 case OP_REGISTER:
1146 {
1147 const char *name = &exp->elts[2].string;
1148
1149 i = user_reg_map_name_to_regnum (t->gdbarch,
1150 name, strlen (name));
1151 if (i == -1)
1152 internal_error (__FILE__, __LINE__,
1153 _("Register $%s not available"),
1154 name);
1155 if (info_verbose)
1156 printf_filtered ("OP_REGISTER: ");
1157 add_register (collect, i);
1158 break;
1159 }
1160
1161 case UNOP_MEMVAL:
1162 /* safe because we know it's a simple expression */
1163 tempval = evaluate_expression (exp);
1164 addr = value_address (tempval);
1165 len = TYPE_LENGTH (check_typedef (exp->elts[1].type));
1166 add_memrange (collect, memrange_absolute, addr, len);
1167 break;
1168
1169 case OP_VAR_VALUE:
1170 collect_symbol (collect,
1171 exp->elts[2].symbol,
1172 t->gdbarch,
1173 frame_reg,
1174 frame_offset,
1175 t->loc->address);
1176 break;
1177
1178 default: /* full-fledged expression */
1179 aexpr = gen_trace_for_expr (t->loc->address, exp);
1180
1181 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1182
1183 ax_reqs (aexpr, &areqs);
1184 if (areqs.flaw != agent_flaw_none)
1185 error (_("malformed expression"));
1186
1187 if (areqs.min_height < 0)
1188 error (_("gdb: Internal error: expression has min height < 0"));
1189 if (areqs.max_height > 20)
1190 error (_("expression too complicated, try simplifying"));
1191
1192 discard_cleanups (old_chain1);
1193 add_aexpr (collect, aexpr);
1194
1195 /* take care of the registers */
1196 if (areqs.reg_mask_len > 0)
1197 {
1198 int ndx1;
1199 int ndx2;
1200
1201 for (ndx1 = 0; ndx1 < areqs.reg_mask_len; ndx1++)
1202 {
1203 QUIT; /* allow user to bail out with ^C */
1204 if (areqs.reg_mask[ndx1] != 0)
1205 {
1206 /* assume chars have 8 bits */
1207 for (ndx2 = 0; ndx2 < 8; ndx2++)
1208 if (areqs.reg_mask[ndx1] & (1 << ndx2))
1209 /* it's used -- record it */
1210 add_register (collect,
1211 ndx1 * 8 + ndx2);
1212 }
1213 }
1214 }
1215 break;
1216 } /* switch */
1217 do_cleanups (old_chain);
1218 } /* do */
1219 }
1220 while (action_exp && *action_exp++ == ',');
1221 } /* if */
1222 else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
1223 {
1224 collect = &stepping_list;
1225 }
1226 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
1227 {
1228 if (collect == &stepping_list) /* end stepping actions */
1229 collect = &tracepoint_list;
1230 else
1231 break; /* end tracepoint actions */
1232 }
1233 } /* for */
1234 memrange_sortmerge (&tracepoint_list);
1235 memrange_sortmerge (&stepping_list);
1236
1237 *tdp_actions = stringify_collection_list (&tracepoint_list,
1238 tdp_buff);
1239 *stepping_actions = stringify_collection_list (&stepping_list,
1240 step_buff);
1241 }
1242
1243 static void
1244 add_aexpr (struct collection_list *collect, struct agent_expr *aexpr)
1245 {
1246 if (collect->next_aexpr_elt >= collect->aexpr_listsize)
1247 {
1248 collect->aexpr_list =
1249 xrealloc (collect->aexpr_list,
1250 2 * collect->aexpr_listsize * sizeof (struct agent_expr *));
1251 collect->aexpr_listsize *= 2;
1252 }
1253 collect->aexpr_list[collect->next_aexpr_elt] = aexpr;
1254 collect->next_aexpr_elt++;
1255 }
1256
1257 static char *target_buf;
1258 static long target_buf_size;
1259
1260 /* Set "transparent" memory ranges
1261
1262 Allow trace mechanism to treat text-like sections
1263 (and perhaps all read-only sections) transparently,
1264 i.e. don't reject memory requests from these address ranges
1265 just because they haven't been collected. */
1266
1267 static void
1268 remote_set_transparent_ranges (void)
1269 {
1270 asection *s;
1271 bfd_size_type size;
1272 bfd_vma lma;
1273 int anysecs = 0;
1274
1275 if (!exec_bfd)
1276 return; /* No information to give. */
1277
1278 strcpy (target_buf, "QTro");
1279 for (s = exec_bfd->sections; s; s = s->next)
1280 {
1281 char tmp1[40], tmp2[40];
1282
1283 if ((s->flags & SEC_LOAD) == 0 ||
1284 /* (s->flags & SEC_CODE) == 0 || */
1285 (s->flags & SEC_READONLY) == 0)
1286 continue;
1287
1288 anysecs = 1;
1289 lma = s->lma;
1290 size = bfd_get_section_size (s);
1291 sprintf_vma (tmp1, lma);
1292 sprintf_vma (tmp2, lma + size);
1293 sprintf (target_buf + strlen (target_buf),
1294 ":%s,%s", tmp1, tmp2);
1295 }
1296 if (anysecs)
1297 {
1298 putpkt (target_buf);
1299 getpkt (&target_buf, &target_buf_size, 0);
1300 }
1301 }
1302
1303 /* tstart command:
1304
1305 Tell target to clear any previous trace experiment.
1306 Walk the list of tracepoints, and send them (and their actions)
1307 to the target. If no errors,
1308 Tell target to start a new trace experiment. */
1309
1310 void download_tracepoint (struct breakpoint *t);
1311
1312 static void
1313 trace_start_command (char *args, int from_tty)
1314 {
1315 VEC(breakpoint_p) *tp_vec = NULL;
1316 int ix;
1317 struct breakpoint *t;
1318
1319 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1320
1321 if (target_is_remote ())
1322 {
1323 putpkt ("QTinit");
1324 remote_get_noisy_reply (&target_buf, &target_buf_size);
1325 if (strcmp (target_buf, "OK"))
1326 error (_("Target does not support this command."));
1327
1328 tp_vec = all_tracepoints ();
1329 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
1330 {
1331 download_tracepoint (t);
1332 }
1333 VEC_free (breakpoint_p, tp_vec);
1334
1335 /* Tell target to treat text-like sections as transparent. */
1336 remote_set_transparent_ranges ();
1337 /* Now insert traps and begin collecting data. */
1338 putpkt ("QTStart");
1339 remote_get_noisy_reply (&target_buf, &target_buf_size);
1340 if (strcmp (target_buf, "OK"))
1341 error (_("Bogus reply from target: %s"), target_buf);
1342 set_traceframe_num (-1); /* All old traceframes invalidated. */
1343 set_tracepoint_num (-1);
1344 set_traceframe_context (NULL);
1345 trace_running_p = 1;
1346 if (deprecated_trace_start_stop_hook)
1347 deprecated_trace_start_stop_hook (1, from_tty);
1348
1349 }
1350 else
1351 error (_("Trace can only be run on remote targets."));
1352 }
1353
1354 /* Send the definition of a single tracepoint to the target. */
1355
1356 void
1357 download_tracepoint (struct breakpoint *t)
1358 {
1359 char tmp[40];
1360 char buf[2048];
1361 char **tdp_actions;
1362 char **stepping_actions;
1363 int ndx;
1364 struct cleanup *old_chain = NULL;
1365 struct agent_expr *aexpr;
1366 struct cleanup *aexpr_chain = NULL;
1367
1368 sprintf_vma (tmp, (t->loc ? t->loc->address : 0));
1369 sprintf (buf, "QTDP:%x:%s:%c:%lx:%x", t->number,
1370 tmp, /* address */
1371 (t->enable_state == bp_enabled ? 'E' : 'D'),
1372 t->step_count, t->pass_count);
1373 /* If the tracepoint has a conditional, make it into an agent
1374 expression and append to the definition. */
1375 if (t->loc->cond)
1376 {
1377 /* Only test support at download time, we may not know target
1378 capabilities at definition time. */
1379 if (remote_supports_cond_tracepoints ())
1380 {
1381 aexpr = gen_eval_for_expr (t->loc->address, t->loc->cond);
1382 aexpr_chain = make_cleanup_free_agent_expr (aexpr);
1383 sprintf (buf + strlen (buf), ":X%x,", aexpr->len);
1384 mem2hex (aexpr->buf, buf + strlen (buf), aexpr->len);
1385 do_cleanups (aexpr_chain);
1386 }
1387 else
1388 warning (_("Target does not support conditional tracepoints, ignoring tp %d cond"), t->number);
1389 }
1390
1391 if (t->actions)
1392 strcat (buf, "-");
1393 putpkt (buf);
1394 remote_get_noisy_reply (&target_buf, &target_buf_size);
1395 if (strcmp (target_buf, "OK"))
1396 error (_("Target does not support tracepoints."));
1397
1398 if (!t->actions)
1399 return;
1400
1401 encode_actions (t, &tdp_actions, &stepping_actions);
1402 old_chain = make_cleanup (free_actions_list_cleanup_wrapper,
1403 tdp_actions);
1404 (void) make_cleanup (free_actions_list_cleanup_wrapper, stepping_actions);
1405
1406 /* do_single_steps (t); */
1407 if (tdp_actions)
1408 {
1409 for (ndx = 0; tdp_actions[ndx]; ndx++)
1410 {
1411 QUIT; /* allow user to bail out with ^C */
1412 sprintf (buf, "QTDP:-%x:%s:%s%c",
1413 t->number, tmp, /* address */
1414 tdp_actions[ndx],
1415 ((tdp_actions[ndx + 1] || stepping_actions)
1416 ? '-' : 0));
1417 putpkt (buf);
1418 remote_get_noisy_reply (&target_buf,
1419 &target_buf_size);
1420 if (strcmp (target_buf, "OK"))
1421 error (_("Error on target while setting tracepoints."));
1422 }
1423 }
1424 if (stepping_actions)
1425 {
1426 for (ndx = 0; stepping_actions[ndx]; ndx++)
1427 {
1428 QUIT; /* allow user to bail out with ^C */
1429 sprintf (buf, "QTDP:-%x:%s:%s%s%s",
1430 t->number, tmp, /* address */
1431 ((ndx == 0) ? "S" : ""),
1432 stepping_actions[ndx],
1433 (stepping_actions[ndx + 1] ? "-" : ""));
1434 putpkt (buf);
1435 remote_get_noisy_reply (&target_buf,
1436 &target_buf_size);
1437 if (strcmp (target_buf, "OK"))
1438 error (_("Error on target while setting tracepoints."));
1439 }
1440 }
1441 do_cleanups (old_chain);
1442 }
1443
1444 /* tstop command */
1445 static void
1446 trace_stop_command (char *args, int from_tty)
1447 {
1448 if (target_is_remote ())
1449 {
1450 putpkt ("QTStop");
1451 remote_get_noisy_reply (&target_buf, &target_buf_size);
1452 if (strcmp (target_buf, "OK"))
1453 error (_("Bogus reply from target: %s"), target_buf);
1454 trace_running_p = 0;
1455 if (deprecated_trace_start_stop_hook)
1456 deprecated_trace_start_stop_hook (0, from_tty);
1457 }
1458 else
1459 error (_("Trace can only be run on remote targets."));
1460 }
1461
1462 unsigned long trace_running_p;
1463
1464 /* tstatus command */
1465 static void
1466 trace_status_command (char *args, int from_tty)
1467 {
1468 if (target_is_remote ())
1469 {
1470 putpkt ("qTStatus");
1471 remote_get_noisy_reply (&target_buf, &target_buf_size);
1472
1473 if (target_buf[0] != 'T' ||
1474 (target_buf[1] != '0' && target_buf[1] != '1'))
1475 error (_("Bogus reply from target: %s"), target_buf);
1476
1477 /* exported for use by the GUI */
1478 trace_running_p = (target_buf[1] == '1');
1479 }
1480 else
1481 error (_("Trace can only be run on remote targets."));
1482 }
1483
1484 /* Worker function for the various flavors of the tfind command. */
1485 static void
1486 finish_tfind_command (char **msg,
1487 long *sizeof_msg,
1488 int from_tty)
1489 {
1490 int target_frameno = -1, target_tracept = -1;
1491 struct frame_id old_frame_id;
1492 char *reply;
1493
1494 old_frame_id = get_frame_id (get_current_frame ());
1495
1496 putpkt (*msg);
1497 reply = remote_get_noisy_reply (msg, sizeof_msg);
1498
1499 while (reply && *reply)
1500 switch (*reply)
1501 {
1502 case 'F':
1503 if ((target_frameno = (int) strtol (++reply, &reply, 16)) == -1)
1504 {
1505 /* A request for a non-existant trace frame has failed.
1506 Our response will be different, depending on FROM_TTY:
1507
1508 If FROM_TTY is true, meaning that this command was
1509 typed interactively by the user, then give an error
1510 and DO NOT change the state of traceframe_number etc.
1511
1512 However if FROM_TTY is false, meaning that we're either
1513 in a script, a loop, or a user-defined command, then
1514 DON'T give an error, but DO change the state of
1515 traceframe_number etc. to invalid.
1516
1517 The rationalle is that if you typed the command, you
1518 might just have committed a typo or something, and you'd
1519 like to NOT lose your current debugging state. However
1520 if you're in a user-defined command or especially in a
1521 loop, then you need a way to detect that the command
1522 failed WITHOUT aborting. This allows you to write
1523 scripts that search thru the trace buffer until the end,
1524 and then continue on to do something else. */
1525
1526 if (from_tty)
1527 error (_("Target failed to find requested trace frame."));
1528 else
1529 {
1530 if (info_verbose)
1531 printf_filtered ("End of trace buffer.\n");
1532 /* The following will not recurse, since it's
1533 special-cased. */
1534 trace_find_command ("-1", from_tty);
1535 reply = NULL; /* Break out of loop
1536 (avoid recursive nonsense). */
1537 }
1538 }
1539 break;
1540 case 'T':
1541 if ((target_tracept = (int) strtol (++reply, &reply, 16)) == -1)
1542 error (_("Target failed to find requested trace frame."));
1543 break;
1544 case 'O': /* "OK"? */
1545 if (reply[1] == 'K' && reply[2] == '\0')
1546 reply += 2;
1547 else
1548 error (_("Bogus reply from target: %s"), reply);
1549 break;
1550 default:
1551 error (_("Bogus reply from target: %s"), reply);
1552 }
1553
1554 reinit_frame_cache ();
1555 registers_changed ();
1556 set_traceframe_num (target_frameno);
1557 set_tracepoint_num (target_tracept);
1558 if (target_frameno == -1)
1559 set_traceframe_context (NULL);
1560 else
1561 set_traceframe_context (get_current_frame ());
1562
1563 if (from_tty)
1564 {
1565 enum print_what print_what;
1566
1567 /* NOTE: in immitation of the step command, try to determine
1568 whether we have made a transition from one function to
1569 another. If so, we'll print the "stack frame" (ie. the new
1570 function and it's arguments) -- otherwise we'll just show the
1571 new source line. */
1572
1573 if (frame_id_eq (old_frame_id,
1574 get_frame_id (get_current_frame ())))
1575 print_what = SRC_LINE;
1576 else
1577 print_what = SRC_AND_LOC;
1578
1579 print_stack_frame (get_selected_frame (NULL), 1, print_what);
1580 do_displays ();
1581 }
1582 }
1583
1584 /* trace_find_command takes a trace frame number n,
1585 sends "QTFrame:<n>" to the target,
1586 and accepts a reply that may contain several optional pieces
1587 of information: a frame number, a tracepoint number, and an
1588 indication of whether this is a trap frame or a stepping frame.
1589
1590 The minimal response is just "OK" (which indicates that the
1591 target does not give us a frame number or a tracepoint number).
1592 Instead of that, the target may send us a string containing
1593 any combination of:
1594 F<hexnum> (gives the selected frame number)
1595 T<hexnum> (gives the selected tracepoint number)
1596 */
1597
1598 /* tfind command */
1599 static void
1600 trace_find_command (char *args, int from_tty)
1601 { /* this should only be called with a numeric argument */
1602 int frameno = -1;
1603
1604 if (target_is_remote ())
1605 {
1606 if (deprecated_trace_find_hook)
1607 deprecated_trace_find_hook (args, from_tty);
1608
1609 if (args == 0 || *args == 0)
1610 { /* TFIND with no args means find NEXT trace frame. */
1611 if (traceframe_number == -1)
1612 frameno = 0; /* "next" is first one */
1613 else
1614 frameno = traceframe_number + 1;
1615 }
1616 else if (0 == strcmp (args, "-"))
1617 {
1618 if (traceframe_number == -1)
1619 error (_("not debugging trace buffer"));
1620 else if (from_tty && traceframe_number == 0)
1621 error (_("already at start of trace buffer"));
1622
1623 frameno = traceframe_number - 1;
1624 }
1625 else
1626 frameno = parse_and_eval_long (args);
1627
1628 if (frameno < -1)
1629 error (_("invalid input (%d is less than zero)"), frameno);
1630
1631 sprintf (target_buf, "QTFrame:%x", frameno);
1632 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1633 }
1634 else
1635 error (_("Trace can only be run on remote targets."));
1636 }
1637
1638 /* tfind end */
1639 static void
1640 trace_find_end_command (char *args, int from_tty)
1641 {
1642 trace_find_command ("-1", from_tty);
1643 }
1644
1645 /* tfind none */
1646 static void
1647 trace_find_none_command (char *args, int from_tty)
1648 {
1649 trace_find_command ("-1", from_tty);
1650 }
1651
1652 /* tfind start */
1653 static void
1654 trace_find_start_command (char *args, int from_tty)
1655 {
1656 trace_find_command ("0", from_tty);
1657 }
1658
1659 /* tfind pc command */
1660 static void
1661 trace_find_pc_command (char *args, int from_tty)
1662 {
1663 CORE_ADDR pc;
1664 char tmp[40];
1665
1666 if (target_is_remote ())
1667 {
1668 if (args == 0 || *args == 0)
1669 pc = regcache_read_pc (get_current_regcache ());
1670 else
1671 pc = parse_and_eval_address (args);
1672
1673 sprintf_vma (tmp, pc);
1674 sprintf (target_buf, "QTFrame:pc:%s", tmp);
1675 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1676 }
1677 else
1678 error (_("Trace can only be run on remote targets."));
1679 }
1680
1681 /* tfind tracepoint command */
1682 static void
1683 trace_find_tracepoint_command (char *args, int from_tty)
1684 {
1685 int tdp;
1686
1687 if (target_is_remote ())
1688 {
1689 if (args == 0 || *args == 0)
1690 {
1691 if (tracepoint_number == -1)
1692 error (_("No current tracepoint -- please supply an argument."));
1693 else
1694 tdp = tracepoint_number; /* default is current TDP */
1695 }
1696 else
1697 tdp = parse_and_eval_long (args);
1698
1699 sprintf (target_buf, "QTFrame:tdp:%x", tdp);
1700 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1701 }
1702 else
1703 error (_("Trace can only be run on remote targets."));
1704 }
1705
1706 /* TFIND LINE command:
1707
1708 This command will take a sourceline for argument, just like BREAK
1709 or TRACE (ie. anything that "decode_line_1" can handle).
1710
1711 With no argument, this command will find the next trace frame
1712 corresponding to a source line OTHER THAN THE CURRENT ONE. */
1713
1714 static void
1715 trace_find_line_command (char *args, int from_tty)
1716 {
1717 static CORE_ADDR start_pc, end_pc;
1718 struct symtabs_and_lines sals;
1719 struct symtab_and_line sal;
1720 struct cleanup *old_chain;
1721 char startpc_str[40], endpc_str[40];
1722
1723 if (target_is_remote ())
1724 {
1725 if (args == 0 || *args == 0)
1726 {
1727 sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
1728 sals.nelts = 1;
1729 sals.sals = (struct symtab_and_line *)
1730 xmalloc (sizeof (struct symtab_and_line));
1731 sals.sals[0] = sal;
1732 }
1733 else
1734 {
1735 sals = decode_line_spec (args, 1);
1736 sal = sals.sals[0];
1737 }
1738
1739 old_chain = make_cleanup (xfree, sals.sals);
1740 if (sal.symtab == 0)
1741 {
1742 struct gdbarch *gdbarch = get_current_arch ();
1743
1744 printf_filtered ("TFIND: No line number information available");
1745 if (sal.pc != 0)
1746 {
1747 /* This is useful for "info line *0x7f34". If we can't
1748 tell the user about a source line, at least let them
1749 have the symbolic address. */
1750 printf_filtered (" for address ");
1751 wrap_here (" ");
1752 print_address (gdbarch, sal.pc, gdb_stdout);
1753 printf_filtered (";\n -- will attempt to find by PC. \n");
1754 }
1755 else
1756 {
1757 printf_filtered (".\n");
1758 return; /* No line, no PC; what can we do? */
1759 }
1760 }
1761 else if (sal.line > 0
1762 && find_line_pc_range (sal, &start_pc, &end_pc))
1763 {
1764 struct gdbarch *gdbarch = get_objfile_arch (sal.symtab->objfile);
1765
1766 if (start_pc == end_pc)
1767 {
1768 printf_filtered ("Line %d of \"%s\"",
1769 sal.line, sal.symtab->filename);
1770 wrap_here (" ");
1771 printf_filtered (" is at address ");
1772 print_address (gdbarch, start_pc, gdb_stdout);
1773 wrap_here (" ");
1774 printf_filtered (" but contains no code.\n");
1775 sal = find_pc_line (start_pc, 0);
1776 if (sal.line > 0 &&
1777 find_line_pc_range (sal, &start_pc, &end_pc) &&
1778 start_pc != end_pc)
1779 printf_filtered ("Attempting to find line %d instead.\n",
1780 sal.line);
1781 else
1782 error (_("Cannot find a good line."));
1783 }
1784 }
1785 else
1786 /* Is there any case in which we get here, and have an address
1787 which the user would want to see? If we have debugging
1788 symbols and no line numbers? */
1789 error (_("Line number %d is out of range for \"%s\"."),
1790 sal.line, sal.symtab->filename);
1791
1792 sprintf_vma (startpc_str, start_pc);
1793 sprintf_vma (endpc_str, end_pc - 1);
1794 /* Find within range of stated line. */
1795 if (args && *args)
1796 sprintf (target_buf, "QTFrame:range:%s:%s",
1797 startpc_str, endpc_str);
1798 /* Find OUTSIDE OF range of CURRENT line. */
1799 else
1800 sprintf (target_buf, "QTFrame:outside:%s:%s",
1801 startpc_str, endpc_str);
1802 finish_tfind_command (&target_buf, &target_buf_size,
1803 from_tty);
1804 do_cleanups (old_chain);
1805 }
1806 else
1807 error (_("Trace can only be run on remote targets."));
1808 }
1809
1810 /* tfind range command */
1811 static void
1812 trace_find_range_command (char *args, int from_tty)
1813 {
1814 static CORE_ADDR start, stop;
1815 char start_str[40], stop_str[40];
1816 char *tmp;
1817
1818 if (target_is_remote ())
1819 {
1820 if (args == 0 || *args == 0)
1821 { /* XXX FIXME: what should default behavior be? */
1822 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
1823 return;
1824 }
1825
1826 if (0 != (tmp = strchr (args, ',')))
1827 {
1828 *tmp++ = '\0'; /* terminate start address */
1829 while (isspace ((int) *tmp))
1830 tmp++;
1831 start = parse_and_eval_address (args);
1832 stop = parse_and_eval_address (tmp);
1833 }
1834 else
1835 { /* no explicit end address? */
1836 start = parse_and_eval_address (args);
1837 stop = start + 1; /* ??? */
1838 }
1839
1840 sprintf_vma (start_str, start);
1841 sprintf_vma (stop_str, stop);
1842 sprintf (target_buf, "QTFrame:range:%s:%s", start_str, stop_str);
1843 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1844 }
1845 else
1846 error (_("Trace can only be run on remote targets."));
1847 }
1848
1849 /* tfind outside command */
1850 static void
1851 trace_find_outside_command (char *args, int from_tty)
1852 {
1853 CORE_ADDR start, stop;
1854 char start_str[40], stop_str[40];
1855 char *tmp;
1856
1857 if (target_is_remote ())
1858 {
1859 if (args == 0 || *args == 0)
1860 { /* XXX FIXME: what should default behavior be? */
1861 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
1862 return;
1863 }
1864
1865 if (0 != (tmp = strchr (args, ',')))
1866 {
1867 *tmp++ = '\0'; /* terminate start address */
1868 while (isspace ((int) *tmp))
1869 tmp++;
1870 start = parse_and_eval_address (args);
1871 stop = parse_and_eval_address (tmp);
1872 }
1873 else
1874 { /* no explicit end address? */
1875 start = parse_and_eval_address (args);
1876 stop = start + 1; /* ??? */
1877 }
1878
1879 sprintf_vma (start_str, start);
1880 sprintf_vma (stop_str, stop);
1881 sprintf (target_buf, "QTFrame:outside:%s:%s", start_str, stop_str);
1882 finish_tfind_command (&target_buf, &target_buf_size, from_tty);
1883 }
1884 else
1885 error (_("Trace can only be run on remote targets."));
1886 }
1887
1888 /* info scope command: list the locals for a scope. */
1889 static void
1890 scope_info (char *args, int from_tty)
1891 {
1892 struct symtabs_and_lines sals;
1893 struct symbol *sym;
1894 struct minimal_symbol *msym;
1895 struct block *block;
1896 char **canonical, *symname, *save_args = args;
1897 struct dict_iterator iter;
1898 int j, count = 0;
1899 struct gdbarch *gdbarch;
1900 int regno;
1901
1902 if (args == 0 || *args == 0)
1903 error (_("requires an argument (function, line or *addr) to define a scope"));
1904
1905 sals = decode_line_1 (&args, 1, NULL, 0, &canonical, NULL);
1906 if (sals.nelts == 0)
1907 return; /* presumably decode_line_1 has already warned */
1908
1909 /* Resolve line numbers to PC */
1910 resolve_sal_pc (&sals.sals[0]);
1911 block = block_for_pc (sals.sals[0].pc);
1912
1913 while (block != 0)
1914 {
1915 QUIT; /* allow user to bail out with ^C */
1916 ALL_BLOCK_SYMBOLS (block, iter, sym)
1917 {
1918 QUIT; /* allow user to bail out with ^C */
1919 if (count == 0)
1920 printf_filtered ("Scope for %s:\n", save_args);
1921 count++;
1922
1923 symname = SYMBOL_PRINT_NAME (sym);
1924 if (symname == NULL || *symname == '\0')
1925 continue; /* probably botched, certainly useless */
1926
1927 gdbarch = get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile);
1928
1929 printf_filtered ("Symbol %s is ", symname);
1930 switch (SYMBOL_CLASS (sym))
1931 {
1932 default:
1933 case LOC_UNDEF: /* messed up symbol? */
1934 printf_filtered ("a bogus symbol, class %d.\n",
1935 SYMBOL_CLASS (sym));
1936 count--; /* don't count this one */
1937 continue;
1938 case LOC_CONST:
1939 printf_filtered ("a constant with value %ld (0x%lx)",
1940 SYMBOL_VALUE (sym), SYMBOL_VALUE (sym));
1941 break;
1942 case LOC_CONST_BYTES:
1943 printf_filtered ("constant bytes: ");
1944 if (SYMBOL_TYPE (sym))
1945 for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++)
1946 fprintf_filtered (gdb_stdout, " %02x",
1947 (unsigned) SYMBOL_VALUE_BYTES (sym)[j]);
1948 break;
1949 case LOC_STATIC:
1950 printf_filtered ("in static storage at address ");
1951 printf_filtered ("%s", paddress (gdbarch,
1952 SYMBOL_VALUE_ADDRESS (sym)));
1953 break;
1954 case LOC_REGISTER:
1955 /* GDBARCH is the architecture associated with the objfile
1956 the symbol is defined in; the target architecture may be
1957 different, and may provide additional registers. However,
1958 we do not know the target architecture at this point.
1959 We assume the objfile architecture will contain all the
1960 standard registers that occur in debug info in that
1961 objfile. */
1962 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1963
1964 if (SYMBOL_IS_ARGUMENT (sym))
1965 printf_filtered ("an argument in register $%s",
1966 gdbarch_register_name (gdbarch, regno));
1967 else
1968 printf_filtered ("a local variable in register $%s",
1969 gdbarch_register_name (gdbarch, regno));
1970 break;
1971 case LOC_ARG:
1972 printf_filtered ("an argument at stack/frame offset %ld",
1973 SYMBOL_VALUE (sym));
1974 break;
1975 case LOC_LOCAL:
1976 printf_filtered ("a local variable at frame offset %ld",
1977 SYMBOL_VALUE (sym));
1978 break;
1979 case LOC_REF_ARG:
1980 printf_filtered ("a reference argument at offset %ld",
1981 SYMBOL_VALUE (sym));
1982 break;
1983 case LOC_REGPARM_ADDR:
1984 /* Note comment at LOC_REGISTER. */
1985 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
1986 printf_filtered ("the address of an argument, in register $%s",
1987 gdbarch_register_name (gdbarch, regno));
1988 break;
1989 case LOC_TYPEDEF:
1990 printf_filtered ("a typedef.\n");
1991 continue;
1992 case LOC_LABEL:
1993 printf_filtered ("a label at address ");
1994 printf_filtered ("%s", paddress (gdbarch,
1995 SYMBOL_VALUE_ADDRESS (sym)));
1996 break;
1997 case LOC_BLOCK:
1998 printf_filtered ("a function at address ");
1999 printf_filtered ("%s",
2000 paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
2001 break;
2002 case LOC_UNRESOLVED:
2003 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
2004 NULL, NULL);
2005 if (msym == NULL)
2006 printf_filtered ("Unresolved Static");
2007 else
2008 {
2009 printf_filtered ("static storage at address ");
2010 printf_filtered ("%s",
2011 paddress (gdbarch, SYMBOL_VALUE_ADDRESS (msym)));
2012 }
2013 break;
2014 case LOC_OPTIMIZED_OUT:
2015 printf_filtered ("optimized out.\n");
2016 continue;
2017 case LOC_COMPUTED:
2018 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym, gdb_stdout);
2019 break;
2020 }
2021 if (SYMBOL_TYPE (sym))
2022 printf_filtered (", length %d.\n",
2023 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
2024 }
2025 if (BLOCK_FUNCTION (block))
2026 break;
2027 else
2028 block = BLOCK_SUPERBLOCK (block);
2029 }
2030 if (count <= 0)
2031 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2032 save_args);
2033 }
2034
2035 /* worker function (cleanup) */
2036 static void
2037 replace_comma (void *data)
2038 {
2039 char *comma = data;
2040 *comma = ',';
2041 }
2042
2043 /* tdump command */
2044 static void
2045 trace_dump_command (char *args, int from_tty)
2046 {
2047 struct regcache *regcache;
2048 struct gdbarch *gdbarch;
2049 struct breakpoint *t;
2050 struct action_line *action;
2051 char *action_exp, *next_comma;
2052 struct cleanup *old_cleanups;
2053 int stepping_actions = 0;
2054 int stepping_frame = 0;
2055
2056 if (!target_is_remote ())
2057 {
2058 error (_("Trace can only be run on remote targets."));
2059 return;
2060 }
2061
2062 if (tracepoint_number == -1)
2063 {
2064 warning (_("No current trace frame."));
2065 return;
2066 }
2067
2068 t = get_tracepoint (tracepoint_number);
2069
2070 if (t == NULL)
2071 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2072 tracepoint_number);
2073
2074 old_cleanups = make_cleanup (null_cleanup, NULL);
2075
2076 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2077 tracepoint_number, traceframe_number);
2078
2079 /* The current frame is a trap frame if the frame PC is equal
2080 to the tracepoint PC. If not, then the current frame was
2081 collected during single-stepping. */
2082
2083 regcache = get_current_regcache ();
2084 gdbarch = get_regcache_arch (regcache);
2085
2086 stepping_frame = (t->loc->address != (regcache_read_pc (regcache)
2087 - gdbarch_decr_pc_after_break (gdbarch)));
2088
2089 for (action = t->actions; action; action = action->next)
2090 {
2091 struct cmd_list_element *cmd;
2092
2093 QUIT; /* allow user to bail out with ^C */
2094 action_exp = action->action;
2095 while (isspace ((int) *action_exp))
2096 action_exp++;
2097
2098 /* The collection actions to be done while stepping are
2099 bracketed by the commands "while-stepping" and "end". */
2100
2101 if (*action_exp == '#') /* comment line */
2102 continue;
2103
2104 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
2105 if (cmd == 0)
2106 error (_("Bad action list item: %s"), action_exp);
2107
2108 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
2109 stepping_actions = 1;
2110 else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand))
2111 stepping_actions = 0;
2112 else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
2113 {
2114 /* Display the collected data.
2115 For the trap frame, display only what was collected at
2116 the trap. Likewise for stepping frames, display only
2117 what was collected while stepping. This means that the
2118 two boolean variables, STEPPING_FRAME and
2119 STEPPING_ACTIONS should be equal. */
2120 if (stepping_frame == stepping_actions)
2121 {
2122 do
2123 { /* repeat over a comma-separated list */
2124 QUIT; /* allow user to bail out with ^C */
2125 if (*action_exp == ',')
2126 action_exp++;
2127 while (isspace ((int) *action_exp))
2128 action_exp++;
2129
2130 next_comma = strchr (action_exp, ',');
2131
2132 if (0 == strncasecmp (action_exp, "$reg", 4))
2133 registers_info (NULL, from_tty);
2134 else if (0 == strncasecmp (action_exp, "$loc", 4))
2135 locals_info (NULL, from_tty);
2136 else if (0 == strncasecmp (action_exp, "$arg", 4))
2137 args_info (NULL, from_tty);
2138 else
2139 { /* variable */
2140 if (next_comma)
2141 {
2142 make_cleanup (replace_comma, next_comma);
2143 *next_comma = '\0';
2144 }
2145 printf_filtered ("%s = ", action_exp);
2146 output_command (action_exp, from_tty);
2147 printf_filtered ("\n");
2148 }
2149 if (next_comma)
2150 *next_comma = ',';
2151 action_exp = next_comma;
2152 }
2153 while (action_exp && *action_exp == ',');
2154 }
2155 }
2156 }
2157 discard_cleanups (old_cleanups);
2158 }
2159
2160 /* Convert the memory pointed to by mem into hex, placing result in buf.
2161 * Return a pointer to the last char put in buf (null)
2162 * "stolen" from sparc-stub.c
2163 */
2164
2165 static const char hexchars[] = "0123456789abcdef";
2166
2167 static char *
2168 mem2hex (gdb_byte *mem, char *buf, int count)
2169 {
2170 gdb_byte ch;
2171
2172 while (count-- > 0)
2173 {
2174 ch = *mem++;
2175
2176 *buf++ = hexchars[ch >> 4];
2177 *buf++ = hexchars[ch & 0xf];
2178 }
2179
2180 *buf = 0;
2181
2182 return buf;
2183 }
2184
2185 int
2186 get_traceframe_number (void)
2187 {
2188 return traceframe_number;
2189 }
2190
2191
2192 /* module initialization */
2193 void
2194 _initialize_tracepoint (void)
2195 {
2196 struct cmd_list_element *c;
2197
2198 traceframe_number = -1;
2199 tracepoint_number = -1;
2200
2201 if (tracepoint_list.list == NULL)
2202 {
2203 tracepoint_list.listsize = 128;
2204 tracepoint_list.list = xmalloc
2205 (tracepoint_list.listsize * sizeof (struct memrange));
2206 }
2207 if (tracepoint_list.aexpr_list == NULL)
2208 {
2209 tracepoint_list.aexpr_listsize = 128;
2210 tracepoint_list.aexpr_list = xmalloc
2211 (tracepoint_list.aexpr_listsize * sizeof (struct agent_expr *));
2212 }
2213
2214 if (stepping_list.list == NULL)
2215 {
2216 stepping_list.listsize = 128;
2217 stepping_list.list = xmalloc
2218 (stepping_list.listsize * sizeof (struct memrange));
2219 }
2220
2221 if (stepping_list.aexpr_list == NULL)
2222 {
2223 stepping_list.aexpr_listsize = 128;
2224 stepping_list.aexpr_list = xmalloc
2225 (stepping_list.aexpr_listsize * sizeof (struct agent_expr *));
2226 }
2227
2228 add_info ("scope", scope_info,
2229 _("List the variables local to a scope"));
2230
2231 add_cmd ("tracepoints", class_trace, NULL,
2232 _("Tracing of program execution without stopping the program."),
2233 &cmdlist);
2234
2235 add_com ("tdump", class_trace, trace_dump_command,
2236 _("Print everything collected at the current tracepoint."));
2237
2238 add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\
2239 Select a trace frame;\n\
2240 No argument means forward by one frame; '-' means backward by one frame."),
2241 &tfindlist, "tfind ", 1, &cmdlist);
2242
2243 add_cmd ("outside", class_trace, trace_find_outside_command, _("\
2244 Select a trace frame whose PC is outside the given range.\n\
2245 Usage: tfind outside addr1, addr2"),
2246 &tfindlist);
2247
2248 add_cmd ("range", class_trace, trace_find_range_command, _("\
2249 Select a trace frame whose PC is in the given range.\n\
2250 Usage: tfind range addr1,addr2"),
2251 &tfindlist);
2252
2253 add_cmd ("line", class_trace, trace_find_line_command, _("\
2254 Select a trace frame by source line.\n\
2255 Argument can be a line number (with optional source file), \n\
2256 a function name, or '*' followed by an address.\n\
2257 Default argument is 'the next source line that was traced'."),
2258 &tfindlist);
2259
2260 add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, _("\
2261 Select a trace frame by tracepoint number.\n\
2262 Default is the tracepoint for the current trace frame."),
2263 &tfindlist);
2264
2265 add_cmd ("pc", class_trace, trace_find_pc_command, _("\
2266 Select a trace frame by PC.\n\
2267 Default is the current PC, or the PC of the current trace frame."),
2268 &tfindlist);
2269
2270 add_cmd ("end", class_trace, trace_find_end_command, _("\
2271 Synonym for 'none'.\n\
2272 De-select any trace frame and resume 'live' debugging."),
2273 &tfindlist);
2274
2275 add_cmd ("none", class_trace, trace_find_none_command,
2276 _("De-select any trace frame and resume 'live' debugging."),
2277 &tfindlist);
2278
2279 add_cmd ("start", class_trace, trace_find_start_command,
2280 _("Select the first trace frame in the trace buffer."),
2281 &tfindlist);
2282
2283 add_com ("tstatus", class_trace, trace_status_command,
2284 _("Display the status of the current trace data collection."));
2285
2286 add_com ("tstop", class_trace, trace_stop_command,
2287 _("Stop trace data collection."));
2288
2289 add_com ("tstart", class_trace, trace_start_command,
2290 _("Start trace data collection."));
2291
2292 add_com ("end", class_trace, end_actions_pseudocommand, _("\
2293 Ends a list of commands or actions.\n\
2294 Several GDB commands allow you to enter a list of commands or actions.\n\
2295 Entering \"end\" on a line by itself is the normal way to terminate\n\
2296 such a list.\n\n\
2297 Note: the \"end\" command cannot be used at the gdb prompt."));
2298
2299 add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\
2300 Specify single-stepping behavior at a tracepoint.\n\
2301 Argument is number of instructions to trace in single-step mode\n\
2302 following the tracepoint. This command is normally followed by\n\
2303 one or more \"collect\" commands, to specify what to collect\n\
2304 while single-stepping.\n\n\
2305 Note: this command can only be used in a tracepoint \"actions\" list."));
2306
2307 add_com_alias ("ws", "while-stepping", class_alias, 0);
2308 add_com_alias ("stepping", "while-stepping", class_alias, 0);
2309
2310 add_com ("collect", class_trace, collect_pseudocommand, _("\
2311 Specify one or more data items to be collected at a tracepoint.\n\
2312 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
2313 collect all data (variables, registers) referenced by that expression.\n\
2314 Also accepts the following special arguments:\n\
2315 $regs -- all registers.\n\
2316 $args -- all function arguments.\n\
2317 $locals -- all variables local to the block/function scope.\n\
2318 Note: this command can only be used in a tracepoint \"actions\" list."));
2319
2320 add_com ("actions", class_trace, trace_actions_command, _("\
2321 Specify the actions to be taken at a tracepoint.\n\
2322 Tracepoint actions may include collecting of specified data, \n\
2323 single-stepping, or enabling/disabling other tracepoints, \n\
2324 depending on target's capabilities."));
2325
2326 target_buf_size = 2048;
2327 target_buf = xmalloc (target_buf_size);
2328 }
This page took 0.078537 seconds and 4 git commands to generate.