Clean up tracepoint.h/c:collection_list
[deliverable/binutils-gdb.git] / gdb / tracepoint.c
1 /* Tracing functionality for remote targets in custom GDB protocol
2
3 Copyright (C) 1997-2016 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "arch-utils.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 "target-dcache.h"
30 #include "language.h"
31 #include "inferior.h"
32 #include "breakpoint.h"
33 #include "tracepoint.h"
34 #include "linespec.h"
35 #include "regcache.h"
36 #include "completer.h"
37 #include "block.h"
38 #include "dictionary.h"
39 #include "observer.h"
40 #include "user-regs.h"
41 #include "valprint.h"
42 #include "gdbcore.h"
43 #include "objfiles.h"
44 #include "filenames.h"
45 #include "gdbthread.h"
46 #include "stack.h"
47 #include "remote.h"
48 #include "source.h"
49 #include "ax.h"
50 #include "ax-gdb.h"
51 #include "memrange.h"
52 #include "cli/cli-utils.h"
53 #include "probe.h"
54 #include "ctf.h"
55 #include "filestuff.h"
56 #include "rsp-low.h"
57 #include "tracefile.h"
58 #include "location.h"
59 #include <algorithm>
60
61 /* readline include files */
62 #include "readline/readline.h"
63 #include "readline/history.h"
64
65 /* readline defines this. */
66 #undef savestring
67
68 #include <unistd.h>
69
70 /* Maximum length of an agent aexpression.
71 This accounts for the fact that packets are limited to 400 bytes
72 (which includes everything -- including the checksum), and assumes
73 the worst case of maximum length for each of the pieces of a
74 continuation packet.
75
76 NOTE: expressions get mem2hex'ed otherwise this would be twice as
77 large. (400 - 31)/2 == 184 */
78 #define MAX_AGENT_EXPR_LEN 184
79
80 /* A hook used to notify the UI of tracepoint operations. */
81
82 void (*deprecated_trace_find_hook) (char *arg, int from_tty);
83 void (*deprecated_trace_start_stop_hook) (int start, int from_tty);
84
85 /*
86 Tracepoint.c:
87
88 This module defines the following debugger commands:
89 trace : set a tracepoint on a function, line, or address.
90 info trace : list all debugger-defined tracepoints.
91 delete trace : delete one or more tracepoints.
92 enable trace : enable one or more tracepoints.
93 disable trace : disable one or more tracepoints.
94 actions : specify actions to be taken at a tracepoint.
95 passcount : specify a pass count for a tracepoint.
96 tstart : start a trace experiment.
97 tstop : stop a trace experiment.
98 tstatus : query the status of a trace experiment.
99 tfind : find a trace frame in the trace buffer.
100 tdump : print everything collected at the current tracepoint.
101 save-tracepoints : write tracepoint setup into a file.
102
103 This module defines the following user-visible debugger variables:
104 $trace_frame : sequence number of trace frame currently being debugged.
105 $trace_line : source line of trace frame currently being debugged.
106 $trace_file : source file of trace frame currently being debugged.
107 $tracepoint : tracepoint number of trace frame currently being debugged.
108 */
109
110
111 /* ======= Important global variables: ======= */
112
113 /* The list of all trace state variables. We don't retain pointers to
114 any of these for any reason - API is by name or number only - so it
115 works to have a vector of objects. */
116
117 typedef struct trace_state_variable tsv_s;
118 DEF_VEC_O(tsv_s);
119
120 static VEC(tsv_s) *tvariables;
121
122 /* The next integer to assign to a variable. */
123
124 static int next_tsv_number = 1;
125
126 /* Number of last traceframe collected. */
127 static int traceframe_number;
128
129 /* Tracepoint for last traceframe collected. */
130 static int tracepoint_number;
131
132 /* The traceframe info of the current traceframe. NULL if we haven't
133 yet attempted to fetch it, or if the target does not support
134 fetching this object, or if we're not inspecting a traceframe
135 presently. */
136 static struct traceframe_info *traceframe_info;
137
138 /* Tracing command lists. */
139 static struct cmd_list_element *tfindlist;
140
141 /* List of expressions to collect by default at each tracepoint hit. */
142 char *default_collect = "";
143
144 static int disconnected_tracing;
145
146 /* This variable controls whether we ask the target for a linear or
147 circular trace buffer. */
148
149 static int circular_trace_buffer;
150
151 /* This variable is the requested trace buffer size, or -1 to indicate
152 that we don't care and leave it up to the target to set a size. */
153
154 static int trace_buffer_size = -1;
155
156 /* Textual notes applying to the current and/or future trace runs. */
157
158 char *trace_user = NULL;
159
160 /* Textual notes applying to the current and/or future trace runs. */
161
162 char *trace_notes = NULL;
163
164 /* Textual notes applying to the stopping of a trace. */
165
166 char *trace_stop_notes = NULL;
167
168 /* ======= Important command functions: ======= */
169 static void trace_actions_command (char *, int);
170 static void trace_start_command (char *, int);
171 static void trace_stop_command (char *, int);
172 static void trace_status_command (char *, int);
173 static void trace_find_command (char *, int);
174 static void trace_find_pc_command (char *, int);
175 static void trace_find_tracepoint_command (char *, int);
176 static void trace_find_line_command (char *, int);
177 static void trace_find_range_command (char *, int);
178 static void trace_find_outside_command (char *, int);
179 static void trace_dump_command (char *, int);
180
181 /* support routines */
182
183 struct collection_list;
184 static char *mem2hex (gdb_byte *, char *, int);
185
186 static struct command_line *
187 all_tracepoint_actions_and_cleanup (struct breakpoint *t);
188
189 extern void _initialize_tracepoint (void);
190
191 static struct trace_status trace_status;
192
193 const char *stop_reason_names[] = {
194 "tunknown",
195 "tnotrun",
196 "tstop",
197 "tfull",
198 "tdisconnected",
199 "tpasscount",
200 "terror"
201 };
202
203 struct trace_status *
204 current_trace_status (void)
205 {
206 return &trace_status;
207 }
208
209 /* Destroy INFO. */
210
211 static void
212 free_traceframe_info (struct traceframe_info *info)
213 {
214 if (info != NULL)
215 {
216 VEC_free (mem_range_s, info->memory);
217 VEC_free (int, info->tvars);
218
219 xfree (info);
220 }
221 }
222
223 /* Free and clear the traceframe info cache of the current
224 traceframe. */
225
226 static void
227 clear_traceframe_info (void)
228 {
229 free_traceframe_info (traceframe_info);
230 traceframe_info = NULL;
231 }
232
233 /* Set traceframe number to NUM. */
234 static void
235 set_traceframe_num (int num)
236 {
237 traceframe_number = num;
238 set_internalvar_integer (lookup_internalvar ("trace_frame"), num);
239 }
240
241 /* Set tracepoint number to NUM. */
242 static void
243 set_tracepoint_num (int num)
244 {
245 tracepoint_number = num;
246 set_internalvar_integer (lookup_internalvar ("tracepoint"), num);
247 }
248
249 /* Set externally visible debug variables for querying/printing
250 the traceframe context (line, function, file). */
251
252 static void
253 set_traceframe_context (struct frame_info *trace_frame)
254 {
255 CORE_ADDR trace_pc;
256 struct symbol *traceframe_fun;
257 struct symtab_and_line traceframe_sal;
258
259 /* Save as globals for internal use. */
260 if (trace_frame != NULL
261 && get_frame_pc_if_available (trace_frame, &trace_pc))
262 {
263 traceframe_sal = find_pc_line (trace_pc, 0);
264 traceframe_fun = find_pc_function (trace_pc);
265
266 /* Save linenumber as "$trace_line", a debugger variable visible to
267 users. */
268 set_internalvar_integer (lookup_internalvar ("trace_line"),
269 traceframe_sal.line);
270 }
271 else
272 {
273 init_sal (&traceframe_sal);
274 traceframe_fun = NULL;
275 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
276 }
277
278 /* Save func name as "$trace_func", a debugger variable visible to
279 users. */
280 if (traceframe_fun == NULL
281 || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
282 clear_internalvar (lookup_internalvar ("trace_func"));
283 else
284 set_internalvar_string (lookup_internalvar ("trace_func"),
285 SYMBOL_LINKAGE_NAME (traceframe_fun));
286
287 /* Save file name as "$trace_file", a debugger variable visible to
288 users. */
289 if (traceframe_sal.symtab == NULL)
290 clear_internalvar (lookup_internalvar ("trace_file"));
291 else
292 set_internalvar_string (lookup_internalvar ("trace_file"),
293 symtab_to_filename_for_display (traceframe_sal.symtab));
294 }
295
296 /* Create a new trace state variable with the given name. */
297
298 struct trace_state_variable *
299 create_trace_state_variable (const char *name)
300 {
301 struct trace_state_variable tsv;
302
303 memset (&tsv, 0, sizeof (tsv));
304 tsv.name = xstrdup (name);
305 tsv.number = next_tsv_number++;
306 return VEC_safe_push (tsv_s, tvariables, &tsv);
307 }
308
309 /* Look for a trace state variable of the given name. */
310
311 struct trace_state_variable *
312 find_trace_state_variable (const char *name)
313 {
314 struct trace_state_variable *tsv;
315 int ix;
316
317 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
318 if (strcmp (name, tsv->name) == 0)
319 return tsv;
320
321 return NULL;
322 }
323
324 /* Look for a trace state variable of the given number. Return NULL if
325 not found. */
326
327 struct trace_state_variable *
328 find_trace_state_variable_by_number (int number)
329 {
330 struct trace_state_variable *tsv;
331 int ix;
332
333 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
334 if (tsv->number == number)
335 return tsv;
336
337 return NULL;
338 }
339
340 static void
341 delete_trace_state_variable (const char *name)
342 {
343 struct trace_state_variable *tsv;
344 int ix;
345
346 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
347 if (strcmp (name, tsv->name) == 0)
348 {
349 observer_notify_tsv_deleted (tsv);
350
351 xfree ((void *)tsv->name);
352 VEC_unordered_remove (tsv_s, tvariables, ix);
353
354 return;
355 }
356
357 warning (_("No trace variable named \"$%s\", not deleting"), name);
358 }
359
360 /* Throws an error if NAME is not valid syntax for a trace state
361 variable's name. */
362
363 void
364 validate_trace_state_variable_name (const char *name)
365 {
366 const char *p;
367
368 if (*name == '\0')
369 error (_("Must supply a non-empty variable name"));
370
371 /* All digits in the name is reserved for value history
372 references. */
373 for (p = name; isdigit (*p); p++)
374 ;
375 if (*p == '\0')
376 error (_("$%s is not a valid trace state variable name"), name);
377
378 for (p = name; isalnum (*p) || *p == '_'; p++)
379 ;
380 if (*p != '\0')
381 error (_("$%s is not a valid trace state variable name"), name);
382 }
383
384 /* The 'tvariable' command collects a name and optional expression to
385 evaluate into an initial value. */
386
387 static void
388 trace_variable_command (char *args, int from_tty)
389 {
390 struct cleanup *old_chain;
391 LONGEST initval = 0;
392 struct trace_state_variable *tsv;
393 char *name, *p;
394
395 if (!args || !*args)
396 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
397
398 /* Only allow two syntaxes; "$name" and "$name=value". */
399 p = skip_spaces (args);
400
401 if (*p++ != '$')
402 error (_("Name of trace variable should start with '$'"));
403
404 name = p;
405 while (isalnum (*p) || *p == '_')
406 p++;
407 name = savestring (name, p - name);
408 old_chain = make_cleanup (xfree, name);
409
410 p = skip_spaces (p);
411 if (*p != '=' && *p != '\0')
412 error (_("Syntax must be $NAME [ = EXPR ]"));
413
414 validate_trace_state_variable_name (name);
415
416 if (*p == '=')
417 initval = value_as_long (parse_and_eval (++p));
418
419 /* If the variable already exists, just change its initial value. */
420 tsv = find_trace_state_variable (name);
421 if (tsv)
422 {
423 if (tsv->initial_value != initval)
424 {
425 tsv->initial_value = initval;
426 observer_notify_tsv_modified (tsv);
427 }
428 printf_filtered (_("Trace state variable $%s "
429 "now has initial value %s.\n"),
430 tsv->name, plongest (tsv->initial_value));
431 do_cleanups (old_chain);
432 return;
433 }
434
435 /* Create a new variable. */
436 tsv = create_trace_state_variable (name);
437 tsv->initial_value = initval;
438
439 observer_notify_tsv_created (tsv);
440
441 printf_filtered (_("Trace state variable $%s "
442 "created, with initial value %s.\n"),
443 tsv->name, plongest (tsv->initial_value));
444
445 do_cleanups (old_chain);
446 }
447
448 static void
449 delete_trace_variable_command (char *args, int from_tty)
450 {
451 int ix;
452 char **argv;
453 struct cleanup *back_to;
454
455 if (args == NULL)
456 {
457 if (query (_("Delete all trace state variables? ")))
458 VEC_free (tsv_s, tvariables);
459 dont_repeat ();
460 observer_notify_tsv_deleted (NULL);
461 return;
462 }
463
464 argv = gdb_buildargv (args);
465 back_to = make_cleanup_freeargv (argv);
466
467 for (ix = 0; argv[ix] != NULL; ix++)
468 {
469 if (*argv[ix] == '$')
470 delete_trace_state_variable (argv[ix] + 1);
471 else
472 warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv[ix]);
473 }
474
475 do_cleanups (back_to);
476
477 dont_repeat ();
478 }
479
480 void
481 tvariables_info_1 (void)
482 {
483 struct trace_state_variable *tsv;
484 int ix;
485 int count = 0;
486 struct cleanup *back_to;
487 struct ui_out *uiout = current_uiout;
488
489 if (VEC_length (tsv_s, tvariables) == 0 && !ui_out_is_mi_like_p (uiout))
490 {
491 printf_filtered (_("No trace state variables.\n"));
492 return;
493 }
494
495 /* Try to acquire values from the target. */
496 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix, ++count)
497 tsv->value_known = target_get_trace_state_variable_value (tsv->number,
498 &(tsv->value));
499
500 back_to = make_cleanup_ui_out_table_begin_end (uiout, 3,
501 count, "trace-variables");
502 ui_out_table_header (uiout, 15, ui_left, "name", "Name");
503 ui_out_table_header (uiout, 11, ui_left, "initial", "Initial");
504 ui_out_table_header (uiout, 11, ui_left, "current", "Current");
505
506 ui_out_table_body (uiout);
507
508 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
509 {
510 struct cleanup *back_to2;
511 char *c;
512 char *name;
513
514 back_to2 = make_cleanup_ui_out_tuple_begin_end (uiout, "variable");
515
516 name = concat ("$", tsv->name, (char *) NULL);
517 make_cleanup (xfree, name);
518 ui_out_field_string (uiout, "name", name);
519 ui_out_field_string (uiout, "initial", plongest (tsv->initial_value));
520
521 if (tsv->value_known)
522 c = plongest (tsv->value);
523 else if (ui_out_is_mi_like_p (uiout))
524 /* For MI, we prefer not to use magic string constants, but rather
525 omit the field completely. The difference between unknown and
526 undefined does not seem important enough to represent. */
527 c = NULL;
528 else if (current_trace_status ()->running || traceframe_number >= 0)
529 /* The value is/was defined, but we don't have it. */
530 c = "<unknown>";
531 else
532 /* It is not meaningful to ask about the value. */
533 c = "<undefined>";
534 if (c)
535 ui_out_field_string (uiout, "current", c);
536 ui_out_text (uiout, "\n");
537
538 do_cleanups (back_to2);
539 }
540
541 do_cleanups (back_to);
542 }
543
544 /* List all the trace state variables. */
545
546 static void
547 tvariables_info (char *args, int from_tty)
548 {
549 tvariables_info_1 ();
550 }
551
552 /* Stash definitions of tsvs into the given file. */
553
554 void
555 save_trace_state_variables (struct ui_file *fp)
556 {
557 struct trace_state_variable *tsv;
558 int ix;
559
560 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
561 {
562 fprintf_unfiltered (fp, "tvariable $%s", tsv->name);
563 if (tsv->initial_value)
564 fprintf_unfiltered (fp, " = %s", plongest (tsv->initial_value));
565 fprintf_unfiltered (fp, "\n");
566 }
567 }
568
569 /* ACTIONS functions: */
570
571 /* The three functions:
572 collect_pseudocommand,
573 while_stepping_pseudocommand, and
574 end_actions_pseudocommand
575 are placeholders for "commands" that are actually ONLY to be used
576 within a tracepoint action list. If the actual function is ever called,
577 it means that somebody issued the "command" at the top level,
578 which is always an error. */
579
580 static void
581 end_actions_pseudocommand (char *args, int from_tty)
582 {
583 error (_("This command cannot be used at the top level."));
584 }
585
586 static void
587 while_stepping_pseudocommand (char *args, int from_tty)
588 {
589 error (_("This command can only be used in a tracepoint actions list."));
590 }
591
592 static void
593 collect_pseudocommand (char *args, int from_tty)
594 {
595 error (_("This command can only be used in a tracepoint actions list."));
596 }
597
598 static void
599 teval_pseudocommand (char *args, int from_tty)
600 {
601 error (_("This command can only be used in a tracepoint actions list."));
602 }
603
604 /* Parse any collection options, such as /s for strings. */
605
606 const char *
607 decode_agent_options (const char *exp, int *trace_string)
608 {
609 struct value_print_options opts;
610
611 *trace_string = 0;
612
613 if (*exp != '/')
614 return exp;
615
616 /* Call this to borrow the print elements default for collection
617 size. */
618 get_user_print_options (&opts);
619
620 exp++;
621 if (*exp == 's')
622 {
623 if (target_supports_string_tracing ())
624 {
625 /* Allow an optional decimal number giving an explicit maximum
626 string length, defaulting it to the "print elements" value;
627 so "collect/s80 mystr" gets at most 80 bytes of string. */
628 *trace_string = opts.print_max;
629 exp++;
630 if (*exp >= '0' && *exp <= '9')
631 *trace_string = atoi (exp);
632 while (*exp >= '0' && *exp <= '9')
633 exp++;
634 }
635 else
636 error (_("Target does not support \"/s\" option for string tracing."));
637 }
638 else
639 error (_("Undefined collection format \"%c\"."), *exp);
640
641 exp = skip_spaces_const (exp);
642
643 return exp;
644 }
645
646 /* Enter a list of actions for a tracepoint. */
647 static void
648 trace_actions_command (char *args, int from_tty)
649 {
650 struct tracepoint *t;
651 struct command_line *l;
652
653 t = get_tracepoint_by_number (&args, NULL);
654 if (t)
655 {
656 char *tmpbuf =
657 xstrprintf ("Enter actions for tracepoint %d, one per line.",
658 t->base.number);
659 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
660
661 l = read_command_lines (tmpbuf, from_tty, 1,
662 check_tracepoint_command, t);
663 do_cleanups (cleanups);
664 breakpoint_set_commands (&t->base, l);
665 }
666 /* else just return */
667 }
668
669 /* Report the results of checking the agent expression, as errors or
670 internal errors. */
671
672 static void
673 report_agent_reqs_errors (struct agent_expr *aexpr)
674 {
675 /* All of the "flaws" are serious bytecode generation issues that
676 should never occur. */
677 if (aexpr->flaw != agent_flaw_none)
678 internal_error (__FILE__, __LINE__, _("expression is malformed"));
679
680 /* If analysis shows a stack underflow, GDB must have done something
681 badly wrong in its bytecode generation. */
682 if (aexpr->min_height < 0)
683 internal_error (__FILE__, __LINE__,
684 _("expression has min height < 0"));
685
686 /* Issue this error if the stack is predicted to get too deep. The
687 limit is rather arbitrary; a better scheme might be for the
688 target to report how much stack it will have available. The
689 depth roughly corresponds to parenthesization, so a limit of 20
690 amounts to 20 levels of expression nesting, which is actually
691 a pretty big hairy expression. */
692 if (aexpr->max_height > 20)
693 error (_("Expression is too complicated."));
694 }
695
696 /* worker function */
697 void
698 validate_actionline (const char *line, struct breakpoint *b)
699 {
700 struct cmd_list_element *c;
701 struct cleanup *old_chain = NULL;
702 const char *tmp_p;
703 const char *p;
704 struct bp_location *loc;
705 struct agent_expr *aexpr;
706 struct tracepoint *t = (struct tracepoint *) b;
707
708 /* If EOF is typed, *line is NULL. */
709 if (line == NULL)
710 return;
711
712 p = skip_spaces_const (line);
713
714 /* Symbol lookup etc. */
715 if (*p == '\0') /* empty line: just prompt for another line. */
716 return;
717
718 if (*p == '#') /* comment line */
719 return;
720
721 c = lookup_cmd (&p, cmdlist, "", -1, 1);
722 if (c == 0)
723 error (_("`%s' is not a tracepoint action, or is ambiguous."), p);
724
725 if (cmd_cfunc_eq (c, collect_pseudocommand))
726 {
727 int trace_string = 0;
728
729 if (*p == '/')
730 p = decode_agent_options (p, &trace_string);
731
732 do
733 { /* Repeat over a comma-separated list. */
734 QUIT; /* Allow user to bail out with ^C. */
735 p = skip_spaces_const (p);
736
737 if (*p == '$') /* Look for special pseudo-symbols. */
738 {
739 if (0 == strncasecmp ("reg", p + 1, 3)
740 || 0 == strncasecmp ("arg", p + 1, 3)
741 || 0 == strncasecmp ("loc", p + 1, 3)
742 || 0 == strncasecmp ("_ret", p + 1, 4)
743 || 0 == strncasecmp ("_sdata", p + 1, 6))
744 {
745 p = strchr (p, ',');
746 continue;
747 }
748 /* else fall thru, treat p as an expression and parse it! */
749 }
750 tmp_p = p;
751 for (loc = t->base.loc; loc; loc = loc->next)
752 {
753 p = tmp_p;
754 expression_up exp = parse_exp_1 (&p, loc->address,
755 block_for_pc (loc->address), 1);
756
757 if (exp->elts[0].opcode == OP_VAR_VALUE)
758 {
759 if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
760 {
761 error (_("constant `%s' (value %s) "
762 "will not be collected."),
763 SYMBOL_PRINT_NAME (exp->elts[2].symbol),
764 plongest (SYMBOL_VALUE (exp->elts[2].symbol)));
765 }
766 else if (SYMBOL_CLASS (exp->elts[2].symbol)
767 == LOC_OPTIMIZED_OUT)
768 {
769 error (_("`%s' is optimized away "
770 "and cannot be collected."),
771 SYMBOL_PRINT_NAME (exp->elts[2].symbol));
772 }
773 }
774
775 /* We have something to collect, make sure that the expr to
776 bytecode translator can handle it and that it's not too
777 long. */
778 aexpr = gen_trace_for_expr (loc->address, exp.get (), trace_string);
779 old_chain = make_cleanup_free_agent_expr (aexpr);
780
781 if (aexpr->len > MAX_AGENT_EXPR_LEN)
782 error (_("Expression is too complicated."));
783
784 ax_reqs (aexpr);
785
786 report_agent_reqs_errors (aexpr);
787
788 do_cleanups (old_chain);
789 }
790 }
791 while (p && *p++ == ',');
792 }
793
794 else if (cmd_cfunc_eq (c, teval_pseudocommand))
795 {
796 do
797 { /* Repeat over a comma-separated list. */
798 QUIT; /* Allow user to bail out with ^C. */
799 p = skip_spaces_const (p);
800
801 tmp_p = p;
802 for (loc = t->base.loc; loc; loc = loc->next)
803 {
804 p = tmp_p;
805
806 /* Only expressions are allowed for this action. */
807 expression_up exp = parse_exp_1 (&p, loc->address,
808 block_for_pc (loc->address), 1);
809
810 /* We have something to evaluate, make sure that the expr to
811 bytecode translator can handle it and that it's not too
812 long. */
813 aexpr = gen_eval_for_expr (loc->address, exp.get ());
814 old_chain = make_cleanup_free_agent_expr (aexpr);
815
816 if (aexpr->len > MAX_AGENT_EXPR_LEN)
817 error (_("Expression is too complicated."));
818
819 ax_reqs (aexpr);
820 report_agent_reqs_errors (aexpr);
821
822 do_cleanups (old_chain);
823 }
824 }
825 while (p && *p++ == ',');
826 }
827
828 else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
829 {
830 char *endp;
831
832 p = skip_spaces_const (p);
833 t->step_count = strtol (p, &endp, 0);
834 if (endp == p || t->step_count == 0)
835 error (_("while-stepping step count `%s' is malformed."), line);
836 p = endp;
837 }
838
839 else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
840 ;
841
842 else
843 error (_("`%s' is not a supported tracepoint action."), line);
844 }
845
846 enum {
847 memrange_absolute = -1
848 };
849
850 /* MEMRANGE functions: */
851
852 /* Compare memranges for std::sort. */
853
854 static bool
855 memrange_comp (const memrange &a, const memrange &b)
856 {
857 if (a.type == b.type)
858 {
859 if (a.type == memrange_absolute)
860 return (bfd_vma) a.start < (bfd_vma) b.start;
861 else
862 return a.start < b.start;
863 }
864
865 return a.type < b.type;
866 }
867
868 /* Sort the memrange list using std::sort, and merge adjacent memranges. */
869
870 static void
871 memrange_sortmerge (std::vector<memrange> &memranges)
872 {
873 if (!memranges.empty ())
874 {
875 int a, b;
876
877 std::sort (memranges.begin (), memranges.end (), memrange_comp);
878
879 for (a = 0, b = 1; b < memranges.size (); b++)
880 {
881 /* If memrange b overlaps or is adjacent to memrange a,
882 merge them. */
883 if (memranges[a].type == memranges[b].type
884 && memranges[b].start <= memranges[a].end)
885 {
886 if (memranges[b].end > memranges[a].end)
887 memranges[a].end = memranges[b].end;
888 continue; /* next b, same a */
889 }
890 a++; /* next a */
891 if (a != b)
892 memranges[a] = memranges[b];
893 }
894 memranges.resize (a + 1);
895 }
896 }
897
898 /* Add a register to a collection list. */
899
900 void
901 collection_list::add_register (unsigned int regno)
902 {
903 if (info_verbose)
904 printf_filtered ("collect register %d\n", regno);
905 if (regno >= (8 * sizeof (m_regs_mask)))
906 error (_("Internal: register number %d too large for tracepoint"),
907 regno);
908 m_regs_mask[regno / 8] |= 1 << (regno % 8);
909 }
910
911 /* Add a memrange to a collection list. */
912
913 void
914 collection_list::add_memrange (int type, bfd_signed_vma base,
915 unsigned long len)
916 {
917 if (info_verbose)
918 {
919 printf_filtered ("(%d,", type);
920 printf_vma (base);
921 printf_filtered (",%ld)\n", len);
922 }
923
924 /* type: memrange_absolute == memory, other n == basereg */
925 /* base: addr if memory, offset if reg relative. */
926 /* len: we actually save end (base + len) for convenience */
927 m_memranges.push_back (memrange (type, base, base + len));
928
929 if (type != memrange_absolute) /* Better collect the base register! */
930 add_register (type);
931 }
932
933 /* Add a symbol to a collection list. */
934
935 void
936 collection_list::collect_symbol (struct symbol *sym,
937 struct gdbarch *gdbarch,
938 long frame_regno, long frame_offset,
939 CORE_ADDR scope,
940 int trace_string)
941 {
942 unsigned long len;
943 unsigned int reg;
944 bfd_signed_vma offset;
945 int treat_as_expr = 0;
946
947 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
948 switch (SYMBOL_CLASS (sym))
949 {
950 default:
951 printf_filtered ("%s: don't know symbol class %d\n",
952 SYMBOL_PRINT_NAME (sym),
953 SYMBOL_CLASS (sym));
954 break;
955 case LOC_CONST:
956 printf_filtered ("constant %s (value %s) will not be collected.\n",
957 SYMBOL_PRINT_NAME (sym), plongest (SYMBOL_VALUE (sym)));
958 break;
959 case LOC_STATIC:
960 offset = SYMBOL_VALUE_ADDRESS (sym);
961 if (info_verbose)
962 {
963 char tmp[40];
964
965 sprintf_vma (tmp, offset);
966 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
967 SYMBOL_PRINT_NAME (sym), len,
968 tmp /* address */);
969 }
970 /* A struct may be a C++ class with static fields, go to general
971 expression handling. */
972 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
973 treat_as_expr = 1;
974 else
975 add_memrange (memrange_absolute, offset, len);
976 break;
977 case LOC_REGISTER:
978 reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
979 if (info_verbose)
980 printf_filtered ("LOC_REG[parm] %s: ",
981 SYMBOL_PRINT_NAME (sym));
982 add_register (reg);
983 /* Check for doubles stored in two registers. */
984 /* FIXME: how about larger types stored in 3 or more regs? */
985 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
986 len > register_size (gdbarch, reg))
987 add_register (reg + 1);
988 break;
989 case LOC_REF_ARG:
990 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
991 printf_filtered (" (will not collect %s)\n",
992 SYMBOL_PRINT_NAME (sym));
993 break;
994 case LOC_ARG:
995 reg = frame_regno;
996 offset = frame_offset + SYMBOL_VALUE (sym);
997 if (info_verbose)
998 {
999 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1000 SYMBOL_PRINT_NAME (sym), len);
1001 printf_vma (offset);
1002 printf_filtered (" from frame ptr reg %d\n", reg);
1003 }
1004 add_memrange (reg, offset, len);
1005 break;
1006 case LOC_REGPARM_ADDR:
1007 reg = SYMBOL_VALUE (sym);
1008 offset = 0;
1009 if (info_verbose)
1010 {
1011 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset ",
1012 SYMBOL_PRINT_NAME (sym), len);
1013 printf_vma (offset);
1014 printf_filtered (" from reg %d\n", reg);
1015 }
1016 add_memrange (reg, offset, len);
1017 break;
1018 case LOC_LOCAL:
1019 reg = frame_regno;
1020 offset = frame_offset + SYMBOL_VALUE (sym);
1021 if (info_verbose)
1022 {
1023 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset ",
1024 SYMBOL_PRINT_NAME (sym), len);
1025 printf_vma (offset);
1026 printf_filtered (" from frame ptr reg %d\n", reg);
1027 }
1028 add_memrange (reg, offset, len);
1029 break;
1030
1031 case LOC_UNRESOLVED:
1032 treat_as_expr = 1;
1033 break;
1034
1035 case LOC_OPTIMIZED_OUT:
1036 printf_filtered ("%s has been optimized out of existence.\n",
1037 SYMBOL_PRINT_NAME (sym));
1038 break;
1039
1040 case LOC_COMPUTED:
1041 treat_as_expr = 1;
1042 break;
1043 }
1044
1045 /* Expressions are the most general case. */
1046 if (treat_as_expr)
1047 {
1048 struct agent_expr *aexpr;
1049 struct cleanup *old_chain1 = NULL;
1050
1051 aexpr = gen_trace_for_var (scope, gdbarch, sym, trace_string);
1052
1053 /* It can happen that the symbol is recorded as a computed
1054 location, but it's been optimized away and doesn't actually
1055 have a location expression. */
1056 if (!aexpr)
1057 {
1058 printf_filtered ("%s has been optimized out of existence.\n",
1059 SYMBOL_PRINT_NAME (sym));
1060 return;
1061 }
1062
1063 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1064
1065 ax_reqs (aexpr);
1066
1067 report_agent_reqs_errors (aexpr);
1068
1069 discard_cleanups (old_chain1);
1070 add_aexpr (aexpr);
1071
1072 /* Take care of the registers. */
1073 if (aexpr->reg_mask_len > 0)
1074 {
1075 int ndx1, ndx2;
1076
1077 for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1078 {
1079 QUIT; /* Allow user to bail out with ^C. */
1080 if (aexpr->reg_mask[ndx1] != 0)
1081 {
1082 /* Assume chars have 8 bits. */
1083 for (ndx2 = 0; ndx2 < 8; ndx2++)
1084 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1085 /* It's used -- record it. */
1086 add_register (ndx1 * 8 + ndx2);
1087 }
1088 }
1089 }
1090 }
1091 }
1092
1093 /* Data to be passed around in the calls to the locals and args
1094 iterators. */
1095
1096 struct add_local_symbols_data
1097 {
1098 struct collection_list *collect;
1099 struct gdbarch *gdbarch;
1100 CORE_ADDR pc;
1101 long frame_regno;
1102 long frame_offset;
1103 int count;
1104 int trace_string;
1105 };
1106
1107 /* The callback for the locals and args iterators. */
1108
1109 static void
1110 do_collect_symbol (const char *print_name,
1111 struct symbol *sym,
1112 void *cb_data)
1113 {
1114 struct add_local_symbols_data *p = (struct add_local_symbols_data *) cb_data;
1115
1116 p->collect->collect_symbol (sym, p->gdbarch, p->frame_regno,
1117 p->frame_offset, p->pc, p->trace_string);
1118 p->count++;
1119
1120 p->collect->add_wholly_collected (print_name);
1121 }
1122
1123 void
1124 collection_list::add_wholly_collected (const char *print_name)
1125 {
1126 m_wholly_collected.push_back (print_name);
1127 }
1128
1129 /* Add all locals (or args) symbols to collection list. */
1130
1131 void
1132 collection_list::add_local_symbols (struct gdbarch *gdbarch, CORE_ADDR pc,
1133 long frame_regno, long frame_offset, int type,
1134 int trace_string)
1135 {
1136 const struct block *block;
1137 struct add_local_symbols_data cb_data;
1138
1139 cb_data.collect = this;
1140 cb_data.gdbarch = gdbarch;
1141 cb_data.pc = pc;
1142 cb_data.frame_regno = frame_regno;
1143 cb_data.frame_offset = frame_offset;
1144 cb_data.count = 0;
1145 cb_data.trace_string = trace_string;
1146
1147 if (type == 'L')
1148 {
1149 block = block_for_pc (pc);
1150 if (block == NULL)
1151 {
1152 warning (_("Can't collect locals; "
1153 "no symbol table info available.\n"));
1154 return;
1155 }
1156
1157 iterate_over_block_local_vars (block, do_collect_symbol, &cb_data);
1158 if (cb_data.count == 0)
1159 warning (_("No locals found in scope."));
1160 }
1161 else
1162 {
1163 pc = get_pc_function_start (pc);
1164 block = block_for_pc (pc);
1165 if (block == NULL)
1166 {
1167 warning (_("Can't collect args; no symbol table info available."));
1168 return;
1169 }
1170
1171 iterate_over_block_arg_vars (block, do_collect_symbol, &cb_data);
1172 if (cb_data.count == 0)
1173 warning (_("No args found in scope."));
1174 }
1175 }
1176
1177 void
1178 collection_list::add_static_trace_data ()
1179 {
1180 if (info_verbose)
1181 printf_filtered ("collect static trace data\n");
1182 m_strace_data = true;
1183 }
1184
1185 collection_list::collection_list ()
1186 : m_regs_mask (),
1187 m_strace_data (false)
1188 {
1189 m_memranges.reserve (128);
1190 m_aexprs.reserve (128);
1191 }
1192
1193 collection_list::~collection_list ()
1194 {
1195 for (int ndx = 0; ndx < m_aexprs.size (); ndx++)
1196 free_agent_expr (m_aexprs[ndx]);
1197 }
1198
1199 /* Reduce a collection list to string form (for gdb protocol). */
1200
1201 char **
1202 collection_list::stringify ()
1203 {
1204 char temp_buf[2048];
1205 char tmp2[40];
1206 int count;
1207 int ndx = 0;
1208 char *(*str_list)[];
1209 char *end;
1210 long i;
1211
1212 count = 1 + 1 + m_memranges.size () + m_aexprs.size () + 1;
1213 str_list = (char *(*)[]) xmalloc (count * sizeof (char *));
1214
1215 if (m_strace_data)
1216 {
1217 if (info_verbose)
1218 printf_filtered ("\nCollecting static trace data\n");
1219 end = temp_buf;
1220 *end++ = 'L';
1221 (*str_list)[ndx] = savestring (temp_buf, end - temp_buf);
1222 ndx++;
1223 }
1224
1225 for (i = sizeof (m_regs_mask) - 1; i > 0; i--)
1226 if (m_regs_mask[i] != 0) /* Skip leading zeroes in regs_mask. */
1227 break;
1228 if (m_regs_mask[i] != 0) /* Prepare to send regs_mask to the stub. */
1229 {
1230 if (info_verbose)
1231 printf_filtered ("\nCollecting registers (mask): 0x");
1232 end = temp_buf;
1233 *end++ = 'R';
1234 for (; i >= 0; i--)
1235 {
1236 QUIT; /* Allow user to bail out with ^C. */
1237 if (info_verbose)
1238 printf_filtered ("%02X", m_regs_mask[i]);
1239 sprintf (end, "%02X", m_regs_mask[i]);
1240 end += 2;
1241 }
1242 (*str_list)[ndx] = xstrdup (temp_buf);
1243 ndx++;
1244 }
1245 if (info_verbose)
1246 printf_filtered ("\n");
1247 if (!m_memranges.empty () && info_verbose)
1248 printf_filtered ("Collecting memranges: \n");
1249 for (i = 0, count = 0, end = temp_buf; i < m_memranges.size (); i++)
1250 {
1251 QUIT; /* Allow user to bail out with ^C. */
1252 sprintf_vma (tmp2, m_memranges[i].start);
1253 if (info_verbose)
1254 {
1255 printf_filtered ("(%d, %s, %ld)\n",
1256 m_memranges[i].type,
1257 tmp2,
1258 (long) (m_memranges[i].end
1259 - m_memranges[i].start));
1260 }
1261 if (count + 27 > MAX_AGENT_EXPR_LEN)
1262 {
1263 (*str_list)[ndx] = savestring (temp_buf, count);
1264 ndx++;
1265 count = 0;
1266 end = temp_buf;
1267 }
1268
1269 {
1270 bfd_signed_vma length
1271 = m_memranges[i].end - m_memranges[i].start;
1272
1273 /* The "%X" conversion specifier expects an unsigned argument,
1274 so passing -1 (memrange_absolute) to it directly gives you
1275 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1276 Special-case it. */
1277 if (m_memranges[i].type == memrange_absolute)
1278 sprintf (end, "M-1,%s,%lX", tmp2, (long) length);
1279 else
1280 sprintf (end, "M%X,%s,%lX", m_memranges[i].type, tmp2, (long) length);
1281 }
1282
1283 count += strlen (end);
1284 end = temp_buf + count;
1285 }
1286
1287 for (i = 0; i < m_aexprs.size (); i++)
1288 {
1289 QUIT; /* Allow user to bail out with ^C. */
1290 if ((count + 10 + 2 * m_aexprs[i]->len) > MAX_AGENT_EXPR_LEN)
1291 {
1292 (*str_list)[ndx] = savestring (temp_buf, count);
1293 ndx++;
1294 count = 0;
1295 end = temp_buf;
1296 }
1297 sprintf (end, "X%08X,", m_aexprs[i]->len);
1298 end += 10; /* 'X' + 8 hex digits + ',' */
1299 count += 10;
1300
1301 end = mem2hex (m_aexprs[i]->buf, end, m_aexprs[i]->len);
1302 count += 2 * m_aexprs[i]->len;
1303 }
1304
1305 if (count != 0)
1306 {
1307 (*str_list)[ndx] = savestring (temp_buf, count);
1308 ndx++;
1309 count = 0;
1310 end = temp_buf;
1311 }
1312 (*str_list)[ndx] = NULL;
1313
1314 if (ndx == 0)
1315 {
1316 xfree (str_list);
1317 return NULL;
1318 }
1319 else
1320 return *str_list;
1321 }
1322
1323 /* Add the printed expression EXP to *LIST. */
1324
1325 void
1326 collection_list::append_exp (struct expression *exp)
1327 {
1328 struct ui_file *tmp_stream = mem_fileopen ();
1329
1330 print_expression (exp, tmp_stream);
1331
1332 m_computed.push_back (ui_file_as_string (tmp_stream));
1333 ui_file_delete (tmp_stream);
1334 }
1335
1336 void
1337 collection_list::finish ()
1338 {
1339 memrange_sortmerge (m_memranges);
1340 }
1341
1342 static void
1343 encode_actions_1 (struct command_line *action,
1344 struct bp_location *tloc,
1345 int frame_reg,
1346 LONGEST frame_offset,
1347 struct collection_list *collect,
1348 struct collection_list *stepping_list)
1349 {
1350 const char *action_exp;
1351 int i;
1352 struct value *tempval;
1353 struct cmd_list_element *cmd;
1354 struct agent_expr *aexpr;
1355
1356 for (; action; action = action->next)
1357 {
1358 QUIT; /* Allow user to bail out with ^C. */
1359 action_exp = action->line;
1360 action_exp = skip_spaces_const (action_exp);
1361
1362 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
1363 if (cmd == 0)
1364 error (_("Bad action list item: %s"), action_exp);
1365
1366 if (cmd_cfunc_eq (cmd, collect_pseudocommand))
1367 {
1368 int trace_string = 0;
1369
1370 if (*action_exp == '/')
1371 action_exp = decode_agent_options (action_exp, &trace_string);
1372
1373 do
1374 { /* Repeat over a comma-separated list. */
1375 QUIT; /* Allow user to bail out with ^C. */
1376 action_exp = skip_spaces_const (action_exp);
1377
1378 if (0 == strncasecmp ("$reg", action_exp, 4))
1379 {
1380 for (i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++)
1381 collect->add_register (i);
1382 action_exp = strchr (action_exp, ','); /* more? */
1383 }
1384 else if (0 == strncasecmp ("$arg", action_exp, 4))
1385 {
1386 collect->add_local_symbols (target_gdbarch (),
1387 tloc->address,
1388 frame_reg,
1389 frame_offset,
1390 'A',
1391 trace_string);
1392 action_exp = strchr (action_exp, ','); /* more? */
1393 }
1394 else if (0 == strncasecmp ("$loc", action_exp, 4))
1395 {
1396 collect->add_local_symbols (target_gdbarch (),
1397 tloc->address,
1398 frame_reg,
1399 frame_offset,
1400 'L',
1401 trace_string);
1402 action_exp = strchr (action_exp, ','); /* more? */
1403 }
1404 else if (0 == strncasecmp ("$_ret", action_exp, 5))
1405 {
1406 struct cleanup *old_chain1 = NULL;
1407
1408 aexpr = gen_trace_for_return_address (tloc->address,
1409 target_gdbarch (),
1410 trace_string);
1411
1412 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1413
1414 ax_reqs (aexpr);
1415 report_agent_reqs_errors (aexpr);
1416
1417 discard_cleanups (old_chain1);
1418 collect->add_aexpr (aexpr);
1419
1420 /* take care of the registers */
1421 if (aexpr->reg_mask_len > 0)
1422 {
1423 int ndx1, ndx2;
1424
1425 for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1426 {
1427 QUIT; /* allow user to bail out with ^C */
1428 if (aexpr->reg_mask[ndx1] != 0)
1429 {
1430 /* assume chars have 8 bits */
1431 for (ndx2 = 0; ndx2 < 8; ndx2++)
1432 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1433 {
1434 /* It's used -- record it. */
1435 collect->add_register (ndx1 * 8 + ndx2);
1436 }
1437 }
1438 }
1439 }
1440
1441 action_exp = strchr (action_exp, ','); /* more? */
1442 }
1443 else if (0 == strncasecmp ("$_sdata", action_exp, 7))
1444 {
1445 collect->add_static_trace_data ();
1446 action_exp = strchr (action_exp, ','); /* more? */
1447 }
1448 else
1449 {
1450 unsigned long addr;
1451 struct cleanup *old_chain1 = NULL;
1452
1453 expression_up exp = parse_exp_1 (&action_exp, tloc->address,
1454 block_for_pc (tloc->address),
1455 1);
1456
1457 switch (exp->elts[0].opcode)
1458 {
1459 case OP_REGISTER:
1460 {
1461 const char *name = &exp->elts[2].string;
1462
1463 i = user_reg_map_name_to_regnum (target_gdbarch (),
1464 name, strlen (name));
1465 if (i == -1)
1466 internal_error (__FILE__, __LINE__,
1467 _("Register $%s not available"),
1468 name);
1469 if (info_verbose)
1470 printf_filtered ("OP_REGISTER: ");
1471 collect->add_register (i);
1472 break;
1473 }
1474
1475 case UNOP_MEMVAL:
1476 /* Safe because we know it's a simple expression. */
1477 tempval = evaluate_expression (exp.get ());
1478 addr = value_address (tempval);
1479 /* Initialize the TYPE_LENGTH if it is a typedef. */
1480 check_typedef (exp->elts[1].type);
1481 collect->add_memrange (memrange_absolute, addr,
1482 TYPE_LENGTH (exp->elts[1].type));
1483 collect->append_exp (exp.get ());
1484 break;
1485
1486 case OP_VAR_VALUE:
1487 {
1488 struct symbol *sym = exp->elts[2].symbol;
1489 char_ptr name = (char_ptr) SYMBOL_NATURAL_NAME (sym);
1490
1491 collect->collect_symbol (exp->elts[2].symbol,
1492 target_gdbarch (),
1493 frame_reg,
1494 frame_offset,
1495 tloc->address,
1496 trace_string);
1497 collect->add_wholly_collected (name);
1498 }
1499 break;
1500
1501 default: /* Full-fledged expression. */
1502 aexpr = gen_trace_for_expr (tloc->address, exp.get (),
1503 trace_string);
1504
1505 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1506
1507 ax_reqs (aexpr);
1508
1509 report_agent_reqs_errors (aexpr);
1510
1511 discard_cleanups (old_chain1);
1512 collect->add_aexpr (aexpr);
1513
1514 /* Take care of the registers. */
1515 if (aexpr->reg_mask_len > 0)
1516 {
1517 int ndx1;
1518 int ndx2;
1519
1520 for (ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
1521 {
1522 QUIT; /* Allow user to bail out with ^C. */
1523 if (aexpr->reg_mask[ndx1] != 0)
1524 {
1525 /* Assume chars have 8 bits. */
1526 for (ndx2 = 0; ndx2 < 8; ndx2++)
1527 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1528 {
1529 /* It's used -- record it. */
1530 collect->add_register (ndx1 * 8 + ndx2);
1531 }
1532 }
1533 }
1534 }
1535
1536 collect->append_exp (exp.get ());
1537 break;
1538 } /* switch */
1539 } /* do */
1540 }
1541 while (action_exp && *action_exp++ == ',');
1542 } /* if */
1543 else if (cmd_cfunc_eq (cmd, teval_pseudocommand))
1544 {
1545 do
1546 { /* Repeat over a comma-separated list. */
1547 QUIT; /* Allow user to bail out with ^C. */
1548 action_exp = skip_spaces_const (action_exp);
1549
1550 {
1551 struct cleanup *old_chain1 = NULL;
1552
1553 expression_up exp = parse_exp_1 (&action_exp, tloc->address,
1554 block_for_pc (tloc->address),
1555 1);
1556
1557 aexpr = gen_eval_for_expr (tloc->address, exp.get ());
1558 old_chain1 = make_cleanup_free_agent_expr (aexpr);
1559
1560 ax_reqs (aexpr);
1561 report_agent_reqs_errors (aexpr);
1562
1563 discard_cleanups (old_chain1);
1564 /* Even though we're not officially collecting, add
1565 to the collect list anyway. */
1566 collect->add_aexpr (aexpr);
1567 } /* do */
1568 }
1569 while (action_exp && *action_exp++ == ',');
1570 } /* if */
1571 else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
1572 {
1573 /* We check against nested while-stepping when setting
1574 breakpoint action, so no way to run into nested
1575 here. */
1576 gdb_assert (stepping_list);
1577
1578 encode_actions_1 (action->body_list[0], tloc, frame_reg,
1579 frame_offset, stepping_list, NULL);
1580 }
1581 else
1582 error (_("Invalid tracepoint command '%s'"), action->line);
1583 } /* for */
1584 }
1585
1586 /* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST
1587 and STEPPING_LIST. */
1588
1589 void
1590 encode_actions (struct bp_location *tloc,
1591 struct collection_list *tracepoint_list,
1592 struct collection_list *stepping_list)
1593 {
1594 struct command_line *actions;
1595 int frame_reg;
1596 LONGEST frame_offset;
1597
1598 gdbarch_virtual_frame_pointer (tloc->gdbarch,
1599 tloc->address, &frame_reg, &frame_offset);
1600
1601 actions = all_tracepoint_actions_and_cleanup (tloc->owner);
1602
1603 encode_actions_1 (actions, tloc, frame_reg, frame_offset,
1604 tracepoint_list, stepping_list);
1605
1606 tracepoint_list->finish ();
1607 stepping_list->finish ();
1608 }
1609
1610 /* Render all actions into gdb protocol. */
1611
1612 void
1613 encode_actions_rsp (struct bp_location *tloc, char ***tdp_actions,
1614 char ***stepping_actions)
1615 {
1616 struct collection_list tracepoint_list, stepping_list;
1617
1618 *tdp_actions = NULL;
1619 *stepping_actions = NULL;
1620
1621 encode_actions (tloc, &tracepoint_list, &stepping_list);
1622
1623 *tdp_actions = tracepoint_list.stringify ();
1624 *stepping_actions = stepping_list.stringify ();
1625 }
1626
1627 void
1628 collection_list::add_aexpr (struct agent_expr *aexpr)
1629 {
1630 m_aexprs.push_back (aexpr);
1631 }
1632
1633 static void
1634 process_tracepoint_on_disconnect (void)
1635 {
1636 VEC(breakpoint_p) *tp_vec = NULL;
1637 int ix;
1638 struct breakpoint *b;
1639 int has_pending_p = 0;
1640
1641 /* Check whether we still have pending tracepoint. If we have, warn the
1642 user that pending tracepoint will no longer work. */
1643 tp_vec = all_tracepoints ();
1644 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1645 {
1646 if (b->loc == NULL)
1647 {
1648 has_pending_p = 1;
1649 break;
1650 }
1651 else
1652 {
1653 struct bp_location *loc1;
1654
1655 for (loc1 = b->loc; loc1; loc1 = loc1->next)
1656 {
1657 if (loc1->shlib_disabled)
1658 {
1659 has_pending_p = 1;
1660 break;
1661 }
1662 }
1663
1664 if (has_pending_p)
1665 break;
1666 }
1667 }
1668 VEC_free (breakpoint_p, tp_vec);
1669
1670 if (has_pending_p)
1671 warning (_("Pending tracepoints will not be resolved while"
1672 " GDB is disconnected\n"));
1673 }
1674
1675 /* Reset local state of tracing. */
1676
1677 void
1678 trace_reset_local_state (void)
1679 {
1680 set_traceframe_num (-1);
1681 set_tracepoint_num (-1);
1682 set_traceframe_context (NULL);
1683 clear_traceframe_info ();
1684 }
1685
1686 void
1687 start_tracing (char *notes)
1688 {
1689 VEC(breakpoint_p) *tp_vec = NULL;
1690 int ix;
1691 struct breakpoint *b;
1692 struct trace_state_variable *tsv;
1693 int any_enabled = 0, num_to_download = 0;
1694 int ret;
1695
1696 tp_vec = all_tracepoints ();
1697
1698 /* No point in tracing without any tracepoints... */
1699 if (VEC_length (breakpoint_p, tp_vec) == 0)
1700 {
1701 VEC_free (breakpoint_p, tp_vec);
1702 error (_("No tracepoints defined, not starting trace"));
1703 }
1704
1705 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1706 {
1707 if (b->enable_state == bp_enabled)
1708 any_enabled = 1;
1709
1710 if ((b->type == bp_fast_tracepoint
1711 ? may_insert_fast_tracepoints
1712 : may_insert_tracepoints))
1713 ++num_to_download;
1714 else
1715 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
1716 (b->type == bp_fast_tracepoint ? "fast " : ""), b->number);
1717 }
1718
1719 if (!any_enabled)
1720 {
1721 if (target_supports_enable_disable_tracepoint ())
1722 warning (_("No tracepoints enabled"));
1723 else
1724 {
1725 /* No point in tracing with only disabled tracepoints that
1726 cannot be re-enabled. */
1727 VEC_free (breakpoint_p, tp_vec);
1728 error (_("No tracepoints enabled, not starting trace"));
1729 }
1730 }
1731
1732 if (num_to_download <= 0)
1733 {
1734 VEC_free (breakpoint_p, tp_vec);
1735 error (_("No tracepoints that may be downloaded, not starting trace"));
1736 }
1737
1738 target_trace_init ();
1739
1740 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1741 {
1742 struct tracepoint *t = (struct tracepoint *) b;
1743 struct bp_location *loc;
1744 int bp_location_downloaded = 0;
1745
1746 /* Clear `inserted' flag. */
1747 for (loc = b->loc; loc; loc = loc->next)
1748 loc->inserted = 0;
1749
1750 if ((b->type == bp_fast_tracepoint
1751 ? !may_insert_fast_tracepoints
1752 : !may_insert_tracepoints))
1753 continue;
1754
1755 t->number_on_target = 0;
1756
1757 for (loc = b->loc; loc; loc = loc->next)
1758 {
1759 /* Since tracepoint locations are never duplicated, `inserted'
1760 flag should be zero. */
1761 gdb_assert (!loc->inserted);
1762
1763 target_download_tracepoint (loc);
1764
1765 loc->inserted = 1;
1766 bp_location_downloaded = 1;
1767 }
1768
1769 t->number_on_target = b->number;
1770
1771 for (loc = b->loc; loc; loc = loc->next)
1772 if (loc->probe.probe != NULL
1773 && loc->probe.probe->pops->set_semaphore != NULL)
1774 loc->probe.probe->pops->set_semaphore (loc->probe.probe,
1775 loc->probe.objfile,
1776 loc->gdbarch);
1777
1778 if (bp_location_downloaded)
1779 observer_notify_breakpoint_modified (b);
1780 }
1781 VEC_free (breakpoint_p, tp_vec);
1782
1783 /* Send down all the trace state variables too. */
1784 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
1785 {
1786 target_download_trace_state_variable (tsv);
1787 }
1788
1789 /* Tell target to treat text-like sections as transparent. */
1790 target_trace_set_readonly_regions ();
1791 /* Set some mode flags. */
1792 target_set_disconnected_tracing (disconnected_tracing);
1793 target_set_circular_trace_buffer (circular_trace_buffer);
1794 target_set_trace_buffer_size (trace_buffer_size);
1795
1796 if (!notes)
1797 notes = trace_notes;
1798 ret = target_set_trace_notes (trace_user, notes, NULL);
1799
1800 if (!ret && (trace_user || notes))
1801 warning (_("Target does not support trace user/notes, info ignored"));
1802
1803 /* Now insert traps and begin collecting data. */
1804 target_trace_start ();
1805
1806 /* Reset our local state. */
1807 trace_reset_local_state ();
1808 current_trace_status()->running = 1;
1809 }
1810
1811 /* The tstart command requests the target to start a new trace run.
1812 The command passes any arguments it has to the target verbatim, as
1813 an optional "trace note". This is useful as for instance a warning
1814 to other users if the trace runs disconnected, and you don't want
1815 anybody else messing with the target. */
1816
1817 static void
1818 trace_start_command (char *args, int from_tty)
1819 {
1820 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1821
1822 if (current_trace_status ()->running)
1823 {
1824 if (from_tty
1825 && !query (_("A trace is running already. Start a new run? ")))
1826 error (_("New trace run not started."));
1827 }
1828
1829 start_tracing (args);
1830 }
1831
1832 /* The tstop command stops the tracing run. The command passes any
1833 supplied arguments to the target verbatim as a "stop note"; if the
1834 target supports trace notes, then it will be reported back as part
1835 of the trace run's status. */
1836
1837 static void
1838 trace_stop_command (char *args, int from_tty)
1839 {
1840 if (!current_trace_status ()->running)
1841 error (_("Trace is not running."));
1842
1843 stop_tracing (args);
1844 }
1845
1846 void
1847 stop_tracing (char *note)
1848 {
1849 int ret;
1850 VEC(breakpoint_p) *tp_vec = NULL;
1851 int ix;
1852 struct breakpoint *t;
1853
1854 target_trace_stop ();
1855
1856 tp_vec = all_tracepoints ();
1857 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
1858 {
1859 struct bp_location *loc;
1860
1861 if ((t->type == bp_fast_tracepoint
1862 ? !may_insert_fast_tracepoints
1863 : !may_insert_tracepoints))
1864 continue;
1865
1866 for (loc = t->loc; loc; loc = loc->next)
1867 {
1868 /* GDB can be totally absent in some disconnected trace scenarios,
1869 but we don't really care if this semaphore goes out of sync.
1870 That's why we are decrementing it here, but not taking care
1871 in other places. */
1872 if (loc->probe.probe != NULL
1873 && loc->probe.probe->pops->clear_semaphore != NULL)
1874 loc->probe.probe->pops->clear_semaphore (loc->probe.probe,
1875 loc->probe.objfile,
1876 loc->gdbarch);
1877 }
1878 }
1879
1880 VEC_free (breakpoint_p, tp_vec);
1881
1882 if (!note)
1883 note = trace_stop_notes;
1884 ret = target_set_trace_notes (NULL, NULL, note);
1885
1886 if (!ret && note)
1887 warning (_("Target does not support trace notes, note ignored"));
1888
1889 /* Should change in response to reply? */
1890 current_trace_status ()->running = 0;
1891 }
1892
1893 /* tstatus command */
1894 static void
1895 trace_status_command (char *args, int from_tty)
1896 {
1897 struct trace_status *ts = current_trace_status ();
1898 int status, ix;
1899 VEC(breakpoint_p) *tp_vec = NULL;
1900 struct breakpoint *t;
1901
1902 status = target_get_trace_status (ts);
1903
1904 if (status == -1)
1905 {
1906 if (ts->filename != NULL)
1907 printf_filtered (_("Using a trace file.\n"));
1908 else
1909 {
1910 printf_filtered (_("Trace can not be run on this target.\n"));
1911 return;
1912 }
1913 }
1914
1915 if (!ts->running_known)
1916 {
1917 printf_filtered (_("Run/stop status is unknown.\n"));
1918 }
1919 else if (ts->running)
1920 {
1921 printf_filtered (_("Trace is running on the target.\n"));
1922 }
1923 else
1924 {
1925 switch (ts->stop_reason)
1926 {
1927 case trace_never_run:
1928 printf_filtered (_("No trace has been run on the target.\n"));
1929 break;
1930 case tstop_command:
1931 if (ts->stop_desc)
1932 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1933 ts->stop_desc);
1934 else
1935 printf_filtered (_("Trace stopped by a tstop command.\n"));
1936 break;
1937 case trace_buffer_full:
1938 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1939 break;
1940 case trace_disconnected:
1941 printf_filtered (_("Trace stopped because of disconnection.\n"));
1942 break;
1943 case tracepoint_passcount:
1944 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1945 ts->stopping_tracepoint);
1946 break;
1947 case tracepoint_error:
1948 if (ts->stopping_tracepoint)
1949 printf_filtered (_("Trace stopped by an "
1950 "error (%s, tracepoint %d).\n"),
1951 ts->stop_desc, ts->stopping_tracepoint);
1952 else
1953 printf_filtered (_("Trace stopped by an error (%s).\n"),
1954 ts->stop_desc);
1955 break;
1956 case trace_stop_reason_unknown:
1957 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1958 break;
1959 default:
1960 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1961 ts->stop_reason);
1962 break;
1963 }
1964 }
1965
1966 if (ts->traceframes_created >= 0
1967 && ts->traceframe_count != ts->traceframes_created)
1968 {
1969 printf_filtered (_("Buffer contains %d trace "
1970 "frames (of %d created total).\n"),
1971 ts->traceframe_count, ts->traceframes_created);
1972 }
1973 else if (ts->traceframe_count >= 0)
1974 {
1975 printf_filtered (_("Collected %d trace frames.\n"),
1976 ts->traceframe_count);
1977 }
1978
1979 if (ts->buffer_free >= 0)
1980 {
1981 if (ts->buffer_size >= 0)
1982 {
1983 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1984 ts->buffer_free, ts->buffer_size);
1985 if (ts->buffer_size > 0)
1986 printf_filtered (_(" (%d%% full)"),
1987 ((int) ((((long long) (ts->buffer_size
1988 - ts->buffer_free)) * 100)
1989 / ts->buffer_size)));
1990 printf_filtered (_(".\n"));
1991 }
1992 else
1993 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1994 ts->buffer_free);
1995 }
1996
1997 if (ts->disconnected_tracing)
1998 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1999 else
2000 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
2001
2002 if (ts->circular_buffer)
2003 printf_filtered (_("Trace buffer is circular.\n"));
2004
2005 if (ts->user_name && strlen (ts->user_name) > 0)
2006 printf_filtered (_("Trace user is %s.\n"), ts->user_name);
2007
2008 if (ts->notes && strlen (ts->notes) > 0)
2009 printf_filtered (_("Trace notes: %s.\n"), ts->notes);
2010
2011 /* Now report on what we're doing with tfind. */
2012 if (traceframe_number >= 0)
2013 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
2014 traceframe_number, tracepoint_number);
2015 else
2016 printf_filtered (_("Not looking at any trace frame.\n"));
2017
2018 /* Report start/stop times if supplied. */
2019 if (ts->start_time)
2020 {
2021 if (ts->stop_time)
2022 {
2023 LONGEST run_time = ts->stop_time - ts->start_time;
2024
2025 /* Reporting a run time is more readable than two long numbers. */
2026 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
2027 (long int) (ts->start_time / 1000000),
2028 (long int) (ts->start_time % 1000000),
2029 (long int) (run_time / 1000000),
2030 (long int) (run_time % 1000000));
2031 }
2032 else
2033 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
2034 (long int) (ts->start_time / 1000000),
2035 (long int) (ts->start_time % 1000000));
2036 }
2037 else if (ts->stop_time)
2038 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
2039 (long int) (ts->stop_time / 1000000),
2040 (long int) (ts->stop_time % 1000000));
2041
2042 /* Now report any per-tracepoint status available. */
2043 tp_vec = all_tracepoints ();
2044
2045 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
2046 target_get_tracepoint_status (t, NULL);
2047
2048 VEC_free (breakpoint_p, tp_vec);
2049 }
2050
2051 /* Report the trace status to uiout, in a way suitable for MI, and not
2052 suitable for CLI. If ON_STOP is true, suppress a few fields that
2053 are not meaningful in the -trace-stop response.
2054
2055 The implementation is essentially parallel to trace_status_command, but
2056 merging them will result in unreadable code. */
2057 void
2058 trace_status_mi (int on_stop)
2059 {
2060 struct ui_out *uiout = current_uiout;
2061 struct trace_status *ts = current_trace_status ();
2062 int status;
2063
2064 status = target_get_trace_status (ts);
2065
2066 if (status == -1 && ts->filename == NULL)
2067 {
2068 ui_out_field_string (uiout, "supported", "0");
2069 return;
2070 }
2071
2072 if (ts->filename != NULL)
2073 ui_out_field_string (uiout, "supported", "file");
2074 else if (!on_stop)
2075 ui_out_field_string (uiout, "supported", "1");
2076
2077 if (ts->filename != NULL)
2078 ui_out_field_string (uiout, "trace-file", ts->filename);
2079
2080 gdb_assert (ts->running_known);
2081
2082 if (ts->running)
2083 {
2084 ui_out_field_string (uiout, "running", "1");
2085
2086 /* Unlike CLI, do not show the state of 'disconnected-tracing' variable.
2087 Given that the frontend gets the status either on -trace-stop, or from
2088 -trace-status after re-connection, it does not seem like this
2089 information is necessary for anything. It is not necessary for either
2090 figuring the vital state of the target nor for navigation of trace
2091 frames. If the frontend wants to show the current state is some
2092 configure dialog, it can request the value when such dialog is
2093 invoked by the user. */
2094 }
2095 else
2096 {
2097 char *stop_reason = NULL;
2098 int stopping_tracepoint = -1;
2099
2100 if (!on_stop)
2101 ui_out_field_string (uiout, "running", "0");
2102
2103 if (ts->stop_reason != trace_stop_reason_unknown)
2104 {
2105 switch (ts->stop_reason)
2106 {
2107 case tstop_command:
2108 stop_reason = "request";
2109 break;
2110 case trace_buffer_full:
2111 stop_reason = "overflow";
2112 break;
2113 case trace_disconnected:
2114 stop_reason = "disconnection";
2115 break;
2116 case tracepoint_passcount:
2117 stop_reason = "passcount";
2118 stopping_tracepoint = ts->stopping_tracepoint;
2119 break;
2120 case tracepoint_error:
2121 stop_reason = "error";
2122 stopping_tracepoint = ts->stopping_tracepoint;
2123 break;
2124 }
2125
2126 if (stop_reason)
2127 {
2128 ui_out_field_string (uiout, "stop-reason", stop_reason);
2129 if (stopping_tracepoint != -1)
2130 ui_out_field_int (uiout, "stopping-tracepoint",
2131 stopping_tracepoint);
2132 if (ts->stop_reason == tracepoint_error)
2133 ui_out_field_string (uiout, "error-description",
2134 ts->stop_desc);
2135 }
2136 }
2137 }
2138
2139 if (ts->traceframe_count != -1)
2140 ui_out_field_int (uiout, "frames", ts->traceframe_count);
2141 if (ts->traceframes_created != -1)
2142 ui_out_field_int (uiout, "frames-created", ts->traceframes_created);
2143 if (ts->buffer_size != -1)
2144 ui_out_field_int (uiout, "buffer-size", ts->buffer_size);
2145 if (ts->buffer_free != -1)
2146 ui_out_field_int (uiout, "buffer-free", ts->buffer_free);
2147
2148 ui_out_field_int (uiout, "disconnected", ts->disconnected_tracing);
2149 ui_out_field_int (uiout, "circular", ts->circular_buffer);
2150
2151 ui_out_field_string (uiout, "user-name", ts->user_name);
2152 ui_out_field_string (uiout, "notes", ts->notes);
2153
2154 {
2155 char buf[100];
2156
2157 xsnprintf (buf, sizeof buf, "%ld.%06ld",
2158 (long int) (ts->start_time / 1000000),
2159 (long int) (ts->start_time % 1000000));
2160 ui_out_field_string (uiout, "start-time", buf);
2161 xsnprintf (buf, sizeof buf, "%ld.%06ld",
2162 (long int) (ts->stop_time / 1000000),
2163 (long int) (ts->stop_time % 1000000));
2164 ui_out_field_string (uiout, "stop-time", buf);
2165 }
2166 }
2167
2168 /* Check if a trace run is ongoing. If so, and FROM_TTY, query the
2169 user if she really wants to detach. */
2170
2171 void
2172 query_if_trace_running (int from_tty)
2173 {
2174 if (!from_tty)
2175 return;
2176
2177 /* It can happen that the target that was tracing went away on its
2178 own, and we didn't notice. Get a status update, and if the
2179 current target doesn't even do tracing, then assume it's not
2180 running anymore. */
2181 if (target_get_trace_status (current_trace_status ()) < 0)
2182 current_trace_status ()->running = 0;
2183
2184 /* If running interactively, give the user the option to cancel and
2185 then decide what to do differently with the run. Scripts are
2186 just going to disconnect and let the target deal with it,
2187 according to how it's been instructed previously via
2188 disconnected-tracing. */
2189 if (current_trace_status ()->running)
2190 {
2191 process_tracepoint_on_disconnect ();
2192
2193 if (current_trace_status ()->disconnected_tracing)
2194 {
2195 if (!query (_("Trace is running and will "
2196 "continue after detach; detach anyway? ")))
2197 error (_("Not confirmed."));
2198 }
2199 else
2200 {
2201 if (!query (_("Trace is running but will "
2202 "stop on detach; detach anyway? ")))
2203 error (_("Not confirmed."));
2204 }
2205 }
2206 }
2207
2208 /* This function handles the details of what to do about an ongoing
2209 tracing run if the user has asked to detach or otherwise disconnect
2210 from the target. */
2211
2212 void
2213 disconnect_tracing (void)
2214 {
2215 /* Also we want to be out of tfind mode, otherwise things can get
2216 confusing upon reconnection. Just use these calls instead of
2217 full tfind_1 behavior because we're in the middle of detaching,
2218 and there's no point to updating current stack frame etc. */
2219 trace_reset_local_state ();
2220 }
2221
2222 /* Worker function for the various flavors of the tfind command. */
2223 void
2224 tfind_1 (enum trace_find_type type, int num,
2225 CORE_ADDR addr1, CORE_ADDR addr2,
2226 int from_tty)
2227 {
2228 int target_frameno = -1, target_tracept = -1;
2229 struct frame_id old_frame_id = null_frame_id;
2230 struct tracepoint *tp;
2231 struct ui_out *uiout = current_uiout;
2232
2233 /* Only try to get the current stack frame if we have a chance of
2234 succeeding. In particular, if we're trying to get a first trace
2235 frame while all threads are running, it's not going to succeed,
2236 so leave it with a default value and let the frame comparison
2237 below (correctly) decide to print out the source location of the
2238 trace frame. */
2239 if (!(type == tfind_number && num == -1)
2240 && (has_stack_frames () || traceframe_number >= 0))
2241 old_frame_id = get_frame_id (get_current_frame ());
2242
2243 target_frameno = target_trace_find (type, num, addr1, addr2,
2244 &target_tracept);
2245
2246 if (type == tfind_number
2247 && num == -1
2248 && target_frameno == -1)
2249 {
2250 /* We told the target to get out of tfind mode, and it did. */
2251 }
2252 else if (target_frameno == -1)
2253 {
2254 /* A request for a non-existent trace frame has failed.
2255 Our response will be different, depending on FROM_TTY:
2256
2257 If FROM_TTY is true, meaning that this command was
2258 typed interactively by the user, then give an error
2259 and DO NOT change the state of traceframe_number etc.
2260
2261 However if FROM_TTY is false, meaning that we're either
2262 in a script, a loop, or a user-defined command, then
2263 DON'T give an error, but DO change the state of
2264 traceframe_number etc. to invalid.
2265
2266 The rationalle is that if you typed the command, you
2267 might just have committed a typo or something, and you'd
2268 like to NOT lose your current debugging state. However
2269 if you're in a user-defined command or especially in a
2270 loop, then you need a way to detect that the command
2271 failed WITHOUT aborting. This allows you to write
2272 scripts that search thru the trace buffer until the end,
2273 and then continue on to do something else. */
2274
2275 if (from_tty)
2276 error (_("Target failed to find requested trace frame."));
2277 else
2278 {
2279 if (info_verbose)
2280 printf_filtered ("End of trace buffer.\n");
2281 #if 0 /* dubious now? */
2282 /* The following will not recurse, since it's
2283 special-cased. */
2284 trace_find_command ("-1", from_tty);
2285 #endif
2286 }
2287 }
2288
2289 tp = get_tracepoint_by_number_on_target (target_tracept);
2290
2291 reinit_frame_cache ();
2292 target_dcache_invalidate ();
2293
2294 set_tracepoint_num (tp ? tp->base.number : target_tracept);
2295
2296 if (target_frameno != get_traceframe_number ())
2297 observer_notify_traceframe_changed (target_frameno, tracepoint_number);
2298
2299 set_current_traceframe (target_frameno);
2300
2301 if (target_frameno == -1)
2302 set_traceframe_context (NULL);
2303 else
2304 set_traceframe_context (get_current_frame ());
2305
2306 if (traceframe_number >= 0)
2307 {
2308 /* Use different branches for MI and CLI to make CLI messages
2309 i18n-eable. */
2310 if (ui_out_is_mi_like_p (uiout))
2311 {
2312 ui_out_field_string (uiout, "found", "1");
2313 ui_out_field_int (uiout, "tracepoint", tracepoint_number);
2314 ui_out_field_int (uiout, "traceframe", traceframe_number);
2315 }
2316 else
2317 {
2318 printf_unfiltered (_("Found trace frame %d, tracepoint %d\n"),
2319 traceframe_number, tracepoint_number);
2320 }
2321 }
2322 else
2323 {
2324 if (ui_out_is_mi_like_p (uiout))
2325 ui_out_field_string (uiout, "found", "0");
2326 else if (type == tfind_number && num == -1)
2327 printf_unfiltered (_("No longer looking at any trace frame\n"));
2328 else /* This case may never occur, check. */
2329 printf_unfiltered (_("No trace frame found\n"));
2330 }
2331
2332 /* If we're in nonstop mode and getting out of looking at trace
2333 frames, there won't be any current frame to go back to and
2334 display. */
2335 if (from_tty
2336 && (has_stack_frames () || traceframe_number >= 0))
2337 {
2338 enum print_what print_what;
2339
2340 /* NOTE: in imitation of the step command, try to determine
2341 whether we have made a transition from one function to
2342 another. If so, we'll print the "stack frame" (ie. the new
2343 function and it's arguments) -- otherwise we'll just show the
2344 new source line. */
2345
2346 if (frame_id_eq (old_frame_id,
2347 get_frame_id (get_current_frame ())))
2348 print_what = SRC_LINE;
2349 else
2350 print_what = SRC_AND_LOC;
2351
2352 print_stack_frame (get_selected_frame (NULL), 1, print_what, 1);
2353 do_displays ();
2354 }
2355 }
2356
2357 /* Error on looking at traceframes while trace is running. */
2358
2359 void
2360 check_trace_running (struct trace_status *status)
2361 {
2362 if (status->running && status->filename == NULL)
2363 error (_("May not look at trace frames while trace is running."));
2364 }
2365
2366 /* trace_find_command takes a trace frame number n,
2367 sends "QTFrame:<n>" to the target,
2368 and accepts a reply that may contain several optional pieces
2369 of information: a frame number, a tracepoint number, and an
2370 indication of whether this is a trap frame or a stepping frame.
2371
2372 The minimal response is just "OK" (which indicates that the
2373 target does not give us a frame number or a tracepoint number).
2374 Instead of that, the target may send us a string containing
2375 any combination of:
2376 F<hexnum> (gives the selected frame number)
2377 T<hexnum> (gives the selected tracepoint number)
2378 */
2379
2380 /* tfind command */
2381 static void
2382 trace_find_command (char *args, int from_tty)
2383 { /* This should only be called with a numeric argument. */
2384 int frameno = -1;
2385
2386 check_trace_running (current_trace_status ());
2387
2388 if (args == 0 || *args == 0)
2389 { /* TFIND with no args means find NEXT trace frame. */
2390 if (traceframe_number == -1)
2391 frameno = 0; /* "next" is first one. */
2392 else
2393 frameno = traceframe_number + 1;
2394 }
2395 else if (0 == strcmp (args, "-"))
2396 {
2397 if (traceframe_number == -1)
2398 error (_("not debugging trace buffer"));
2399 else if (from_tty && traceframe_number == 0)
2400 error (_("already at start of trace buffer"));
2401
2402 frameno = traceframe_number - 1;
2403 }
2404 /* A hack to work around eval's need for fp to have been collected. */
2405 else if (0 == strcmp (args, "-1"))
2406 frameno = -1;
2407 else
2408 frameno = parse_and_eval_long (args);
2409
2410 if (frameno < -1)
2411 error (_("invalid input (%d is less than zero)"), frameno);
2412
2413 tfind_1 (tfind_number, frameno, 0, 0, from_tty);
2414 }
2415
2416 /* tfind end */
2417 static void
2418 trace_find_end_command (char *args, int from_tty)
2419 {
2420 trace_find_command ("-1", from_tty);
2421 }
2422
2423 /* tfind start */
2424 static void
2425 trace_find_start_command (char *args, int from_tty)
2426 {
2427 trace_find_command ("0", from_tty);
2428 }
2429
2430 /* tfind pc command */
2431 static void
2432 trace_find_pc_command (char *args, int from_tty)
2433 {
2434 CORE_ADDR pc;
2435
2436 check_trace_running (current_trace_status ());
2437
2438 if (args == 0 || *args == 0)
2439 pc = regcache_read_pc (get_current_regcache ());
2440 else
2441 pc = parse_and_eval_address (args);
2442
2443 tfind_1 (tfind_pc, 0, pc, 0, from_tty);
2444 }
2445
2446 /* tfind tracepoint command */
2447 static void
2448 trace_find_tracepoint_command (char *args, int from_tty)
2449 {
2450 int tdp;
2451 struct tracepoint *tp;
2452
2453 check_trace_running (current_trace_status ());
2454
2455 if (args == 0 || *args == 0)
2456 {
2457 if (tracepoint_number == -1)
2458 error (_("No current tracepoint -- please supply an argument."));
2459 else
2460 tdp = tracepoint_number; /* Default is current TDP. */
2461 }
2462 else
2463 tdp = parse_and_eval_long (args);
2464
2465 /* If we have the tracepoint on hand, use the number that the
2466 target knows about (which may be different if we disconnected
2467 and reconnected). */
2468 tp = get_tracepoint (tdp);
2469 if (tp)
2470 tdp = tp->number_on_target;
2471
2472 tfind_1 (tfind_tp, tdp, 0, 0, from_tty);
2473 }
2474
2475 /* TFIND LINE command:
2476
2477 This command will take a sourceline for argument, just like BREAK
2478 or TRACE (ie. anything that "decode_line_1" can handle).
2479
2480 With no argument, this command will find the next trace frame
2481 corresponding to a source line OTHER THAN THE CURRENT ONE. */
2482
2483 static void
2484 trace_find_line_command (char *args, int from_tty)
2485 {
2486 static CORE_ADDR start_pc, end_pc;
2487 struct symtabs_and_lines sals;
2488 struct symtab_and_line sal;
2489 struct cleanup *old_chain;
2490
2491 check_trace_running (current_trace_status ());
2492
2493 if (args == 0 || *args == 0)
2494 {
2495 sal = find_pc_line (get_frame_pc (get_current_frame ()), 0);
2496 sals.nelts = 1;
2497 sals.sals = XNEW (struct symtab_and_line);
2498 sals.sals[0] = sal;
2499 }
2500 else
2501 {
2502 sals = decode_line_with_current_source (args, DECODE_LINE_FUNFIRSTLINE);
2503 sal = sals.sals[0];
2504 }
2505
2506 old_chain = make_cleanup (xfree, sals.sals);
2507 if (sal.symtab == 0)
2508 error (_("No line number information available."));
2509
2510 if (sal.line > 0 && find_line_pc_range (sal, &start_pc, &end_pc))
2511 {
2512 if (start_pc == end_pc)
2513 {
2514 printf_filtered ("Line %d of \"%s\"",
2515 sal.line,
2516 symtab_to_filename_for_display (sal.symtab));
2517 wrap_here (" ");
2518 printf_filtered (" is at address ");
2519 print_address (get_current_arch (), start_pc, gdb_stdout);
2520 wrap_here (" ");
2521 printf_filtered (" but contains no code.\n");
2522 sal = find_pc_line (start_pc, 0);
2523 if (sal.line > 0
2524 && find_line_pc_range (sal, &start_pc, &end_pc)
2525 && start_pc != end_pc)
2526 printf_filtered ("Attempting to find line %d instead.\n",
2527 sal.line);
2528 else
2529 error (_("Cannot find a good line."));
2530 }
2531 }
2532 else
2533 /* Is there any case in which we get here, and have an address
2534 which the user would want to see? If we have debugging
2535 symbols and no line numbers? */
2536 error (_("Line number %d is out of range for \"%s\"."),
2537 sal.line, symtab_to_filename_for_display (sal.symtab));
2538
2539 /* Find within range of stated line. */
2540 if (args && *args)
2541 tfind_1 (tfind_range, 0, start_pc, end_pc - 1, from_tty);
2542 else
2543 tfind_1 (tfind_outside, 0, start_pc, end_pc - 1, from_tty);
2544 do_cleanups (old_chain);
2545 }
2546
2547 /* tfind range command */
2548 static void
2549 trace_find_range_command (char *args, int from_tty)
2550 {
2551 static CORE_ADDR start, stop;
2552 char *tmp;
2553
2554 check_trace_running (current_trace_status ());
2555
2556 if (args == 0 || *args == 0)
2557 { /* XXX FIXME: what should default behavior be? */
2558 printf_filtered ("Usage: tfind range <startaddr>,<endaddr>\n");
2559 return;
2560 }
2561
2562 if (0 != (tmp = strchr (args, ',')))
2563 {
2564 *tmp++ = '\0'; /* Terminate start address. */
2565 tmp = skip_spaces (tmp);
2566 start = parse_and_eval_address (args);
2567 stop = parse_and_eval_address (tmp);
2568 }
2569 else
2570 { /* No explicit end address? */
2571 start = parse_and_eval_address (args);
2572 stop = start + 1; /* ??? */
2573 }
2574
2575 tfind_1 (tfind_range, 0, start, stop, from_tty);
2576 }
2577
2578 /* tfind outside command */
2579 static void
2580 trace_find_outside_command (char *args, int from_tty)
2581 {
2582 CORE_ADDR start, stop;
2583 char *tmp;
2584
2585 if (current_trace_status ()->running
2586 && current_trace_status ()->filename == NULL)
2587 error (_("May not look at trace frames while trace is running."));
2588
2589 if (args == 0 || *args == 0)
2590 { /* XXX FIXME: what should default behavior be? */
2591 printf_filtered ("Usage: tfind outside <startaddr>,<endaddr>\n");
2592 return;
2593 }
2594
2595 if (0 != (tmp = strchr (args, ',')))
2596 {
2597 *tmp++ = '\0'; /* Terminate start address. */
2598 tmp = skip_spaces (tmp);
2599 start = parse_and_eval_address (args);
2600 stop = parse_and_eval_address (tmp);
2601 }
2602 else
2603 { /* No explicit end address? */
2604 start = parse_and_eval_address (args);
2605 stop = start + 1; /* ??? */
2606 }
2607
2608 tfind_1 (tfind_outside, 0, start, stop, from_tty);
2609 }
2610
2611 /* info scope command: list the locals for a scope. */
2612 static void
2613 scope_info (char *args, int from_tty)
2614 {
2615 struct symtabs_and_lines sals;
2616 struct symbol *sym;
2617 struct bound_minimal_symbol msym;
2618 const struct block *block;
2619 const char *symname;
2620 char *save_args = args;
2621 struct block_iterator iter;
2622 int j, count = 0;
2623 struct gdbarch *gdbarch;
2624 int regno;
2625 struct event_location *location;
2626 struct cleanup *back_to;
2627
2628 if (args == 0 || *args == 0)
2629 error (_("requires an argument (function, "
2630 "line or *addr) to define a scope"));
2631
2632 location = string_to_event_location (&args, current_language);
2633 back_to = make_cleanup_delete_event_location (location);
2634 sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, NULL, 0);
2635 if (sals.nelts == 0)
2636 {
2637 /* Presumably decode_line_1 has already warned. */
2638 do_cleanups (back_to);
2639 return;
2640 }
2641
2642 /* Resolve line numbers to PC. */
2643 resolve_sal_pc (&sals.sals[0]);
2644 block = block_for_pc (sals.sals[0].pc);
2645
2646 while (block != 0)
2647 {
2648 QUIT; /* Allow user to bail out with ^C. */
2649 ALL_BLOCK_SYMBOLS (block, iter, sym)
2650 {
2651 QUIT; /* Allow user to bail out with ^C. */
2652 if (count == 0)
2653 printf_filtered ("Scope for %s:\n", save_args);
2654 count++;
2655
2656 symname = SYMBOL_PRINT_NAME (sym);
2657 if (symname == NULL || *symname == '\0')
2658 continue; /* Probably botched, certainly useless. */
2659
2660 gdbarch = symbol_arch (sym);
2661
2662 printf_filtered ("Symbol %s is ", symname);
2663
2664 if (SYMBOL_COMPUTED_OPS (sym) != NULL)
2665 SYMBOL_COMPUTED_OPS (sym)->describe_location (sym,
2666 BLOCK_START (block),
2667 gdb_stdout);
2668 else
2669 {
2670 switch (SYMBOL_CLASS (sym))
2671 {
2672 default:
2673 case LOC_UNDEF: /* Messed up symbol? */
2674 printf_filtered ("a bogus symbol, class %d.\n",
2675 SYMBOL_CLASS (sym));
2676 count--; /* Don't count this one. */
2677 continue;
2678 case LOC_CONST:
2679 printf_filtered ("a constant with value %s (%s)",
2680 plongest (SYMBOL_VALUE (sym)),
2681 hex_string (SYMBOL_VALUE (sym)));
2682 break;
2683 case LOC_CONST_BYTES:
2684 printf_filtered ("constant bytes: ");
2685 if (SYMBOL_TYPE (sym))
2686 for (j = 0; j < TYPE_LENGTH (SYMBOL_TYPE (sym)); j++)
2687 fprintf_filtered (gdb_stdout, " %02x",
2688 (unsigned) SYMBOL_VALUE_BYTES (sym)[j]);
2689 break;
2690 case LOC_STATIC:
2691 printf_filtered ("in static storage at address ");
2692 printf_filtered ("%s", paddress (gdbarch,
2693 SYMBOL_VALUE_ADDRESS (sym)));
2694 break;
2695 case LOC_REGISTER:
2696 /* GDBARCH is the architecture associated with the objfile
2697 the symbol is defined in; the target architecture may be
2698 different, and may provide additional registers. However,
2699 we do not know the target architecture at this point.
2700 We assume the objfile architecture will contain all the
2701 standard registers that occur in debug info in that
2702 objfile. */
2703 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym,
2704 gdbarch);
2705
2706 if (SYMBOL_IS_ARGUMENT (sym))
2707 printf_filtered ("an argument in register $%s",
2708 gdbarch_register_name (gdbarch, regno));
2709 else
2710 printf_filtered ("a local variable in register $%s",
2711 gdbarch_register_name (gdbarch, regno));
2712 break;
2713 case LOC_ARG:
2714 printf_filtered ("an argument at stack/frame offset %s",
2715 plongest (SYMBOL_VALUE (sym)));
2716 break;
2717 case LOC_LOCAL:
2718 printf_filtered ("a local variable at frame offset %s",
2719 plongest (SYMBOL_VALUE (sym)));
2720 break;
2721 case LOC_REF_ARG:
2722 printf_filtered ("a reference argument at offset %s",
2723 plongest (SYMBOL_VALUE (sym)));
2724 break;
2725 case LOC_REGPARM_ADDR:
2726 /* Note comment at LOC_REGISTER. */
2727 regno = SYMBOL_REGISTER_OPS (sym)->register_number (sym,
2728 gdbarch);
2729 printf_filtered ("the address of an argument, in register $%s",
2730 gdbarch_register_name (gdbarch, regno));
2731 break;
2732 case LOC_TYPEDEF:
2733 printf_filtered ("a typedef.\n");
2734 continue;
2735 case LOC_LABEL:
2736 printf_filtered ("a label at address ");
2737 printf_filtered ("%s", paddress (gdbarch,
2738 SYMBOL_VALUE_ADDRESS (sym)));
2739 break;
2740 case LOC_BLOCK:
2741 printf_filtered ("a function at address ");
2742 printf_filtered ("%s",
2743 paddress (gdbarch, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
2744 break;
2745 case LOC_UNRESOLVED:
2746 msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
2747 NULL, NULL);
2748 if (msym.minsym == NULL)
2749 printf_filtered ("Unresolved Static");
2750 else
2751 {
2752 printf_filtered ("static storage at address ");
2753 printf_filtered ("%s",
2754 paddress (gdbarch,
2755 BMSYMBOL_VALUE_ADDRESS (msym)));
2756 }
2757 break;
2758 case LOC_OPTIMIZED_OUT:
2759 printf_filtered ("optimized out.\n");
2760 continue;
2761 case LOC_COMPUTED:
2762 gdb_assert_not_reached (_("LOC_COMPUTED variable missing a method"));
2763 }
2764 }
2765 if (SYMBOL_TYPE (sym))
2766 printf_filtered (", length %d.\n",
2767 TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym))));
2768 }
2769 if (BLOCK_FUNCTION (block))
2770 break;
2771 else
2772 block = BLOCK_SUPERBLOCK (block);
2773 }
2774 if (count <= 0)
2775 printf_filtered ("Scope for %s contains no locals or arguments.\n",
2776 save_args);
2777 do_cleanups (back_to);
2778 }
2779
2780 /* Helper for trace_dump_command. Dump the action list starting at
2781 ACTION. STEPPING_ACTIONS is true if we're iterating over the
2782 actions of the body of a while-stepping action. STEPPING_FRAME is
2783 set if the current traceframe was determined to be a while-stepping
2784 traceframe. */
2785
2786 static void
2787 trace_dump_actions (struct command_line *action,
2788 int stepping_actions, int stepping_frame,
2789 int from_tty)
2790 {
2791 const char *action_exp, *next_comma;
2792
2793 for (; action != NULL; action = action->next)
2794 {
2795 struct cmd_list_element *cmd;
2796
2797 QUIT; /* Allow user to bail out with ^C. */
2798 action_exp = action->line;
2799 action_exp = skip_spaces_const (action_exp);
2800
2801 /* The collection actions to be done while stepping are
2802 bracketed by the commands "while-stepping" and "end". */
2803
2804 if (*action_exp == '#') /* comment line */
2805 continue;
2806
2807 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
2808 if (cmd == 0)
2809 error (_("Bad action list item: %s"), action_exp);
2810
2811 if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
2812 {
2813 int i;
2814
2815 for (i = 0; i < action->body_count; ++i)
2816 trace_dump_actions (action->body_list[i],
2817 1, stepping_frame, from_tty);
2818 }
2819 else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
2820 {
2821 /* Display the collected data.
2822 For the trap frame, display only what was collected at
2823 the trap. Likewise for stepping frames, display only
2824 what was collected while stepping. This means that the
2825 two boolean variables, STEPPING_FRAME and
2826 STEPPING_ACTIONS should be equal. */
2827 if (stepping_frame == stepping_actions)
2828 {
2829 char *cmd = NULL;
2830 struct cleanup *old_chain
2831 = make_cleanup (free_current_contents, &cmd);
2832 int trace_string = 0;
2833
2834 if (*action_exp == '/')
2835 action_exp = decode_agent_options (action_exp, &trace_string);
2836
2837 do
2838 { /* Repeat over a comma-separated list. */
2839 QUIT; /* Allow user to bail out with ^C. */
2840 if (*action_exp == ',')
2841 action_exp++;
2842 action_exp = skip_spaces_const (action_exp);
2843
2844 next_comma = strchr (action_exp, ',');
2845
2846 if (0 == strncasecmp (action_exp, "$reg", 4))
2847 registers_info (NULL, from_tty);
2848 else if (0 == strncasecmp (action_exp, "$_ret", 5))
2849 ;
2850 else if (0 == strncasecmp (action_exp, "$loc", 4))
2851 locals_info (NULL, from_tty);
2852 else if (0 == strncasecmp (action_exp, "$arg", 4))
2853 args_info (NULL, from_tty);
2854 else
2855 { /* variable */
2856 if (next_comma != NULL)
2857 {
2858 size_t len = next_comma - action_exp;
2859
2860 cmd = (char *) xrealloc (cmd, len + 1);
2861 memcpy (cmd, action_exp, len);
2862 cmd[len] = 0;
2863 }
2864 else
2865 {
2866 size_t len = strlen (action_exp);
2867
2868 cmd = (char *) xrealloc (cmd, len + 1);
2869 memcpy (cmd, action_exp, len + 1);
2870 }
2871
2872 printf_filtered ("%s = ", cmd);
2873 output_command_const (cmd, from_tty);
2874 printf_filtered ("\n");
2875 }
2876 action_exp = next_comma;
2877 }
2878 while (action_exp && *action_exp == ',');
2879
2880 do_cleanups (old_chain);
2881 }
2882 }
2883 }
2884 }
2885
2886 /* Return bp_location of the tracepoint associated with the current
2887 traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe
2888 is a stepping traceframe. */
2889
2890 struct bp_location *
2891 get_traceframe_location (int *stepping_frame_p)
2892 {
2893 struct tracepoint *t;
2894 struct bp_location *tloc;
2895 struct regcache *regcache;
2896
2897 if (tracepoint_number == -1)
2898 error (_("No current trace frame."));
2899
2900 t = get_tracepoint (tracepoint_number);
2901
2902 if (t == NULL)
2903 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2904 tracepoint_number);
2905
2906 /* The current frame is a trap frame if the frame PC is equal to the
2907 tracepoint PC. If not, then the current frame was collected
2908 during single-stepping. */
2909 regcache = get_current_regcache ();
2910
2911 /* If the traceframe's address matches any of the tracepoint's
2912 locations, assume it is a direct hit rather than a while-stepping
2913 frame. (FIXME this is not reliable, should record each frame's
2914 type.) */
2915 for (tloc = t->base.loc; tloc; tloc = tloc->next)
2916 if (tloc->address == regcache_read_pc (regcache))
2917 {
2918 *stepping_frame_p = 0;
2919 return tloc;
2920 }
2921
2922 /* If this is a stepping frame, we don't know which location
2923 triggered. The first is as good (or bad) a guess as any... */
2924 *stepping_frame_p = 1;
2925 return t->base.loc;
2926 }
2927
2928 /* Return all the actions, including default collect, of a tracepoint
2929 T. It constructs cleanups into the chain, and leaves the caller to
2930 handle them (call do_cleanups). */
2931
2932 static struct command_line *
2933 all_tracepoint_actions_and_cleanup (struct breakpoint *t)
2934 {
2935 struct command_line *actions;
2936
2937 actions = breakpoint_commands (t);
2938
2939 /* If there are default expressions to collect, make up a collect
2940 action and prepend to the action list to encode. Note that since
2941 validation is per-tracepoint (local var "xyz" might be valid for
2942 one tracepoint and not another, etc), we make up the action on
2943 the fly, and don't cache it. */
2944 if (*default_collect)
2945 {
2946 struct command_line *default_collect_action;
2947 char *default_collect_line;
2948
2949 default_collect_line = xstrprintf ("collect %s", default_collect);
2950 make_cleanup (xfree, default_collect_line);
2951
2952 validate_actionline (default_collect_line, t);
2953 default_collect_action = XNEW (struct command_line);
2954 make_cleanup (xfree, default_collect_action);
2955 default_collect_action->next = actions;
2956 default_collect_action->line = default_collect_line;
2957 actions = default_collect_action;
2958 }
2959
2960 return actions;
2961 }
2962
2963 /* The tdump command. */
2964
2965 static void
2966 trace_dump_command (char *args, int from_tty)
2967 {
2968 int stepping_frame = 0;
2969 struct bp_location *loc;
2970 struct cleanup *old_chain;
2971 struct command_line *actions;
2972
2973 /* This throws an error is not inspecting a trace frame. */
2974 loc = get_traceframe_location (&stepping_frame);
2975
2976 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2977 tracepoint_number, traceframe_number);
2978
2979 /* This command only makes sense for the current frame, not the
2980 selected frame. */
2981 old_chain = make_cleanup_restore_current_thread ();
2982 select_frame (get_current_frame ());
2983
2984 actions = all_tracepoint_actions_and_cleanup (loc->owner);
2985
2986 trace_dump_actions (actions, 0, stepping_frame, from_tty);
2987
2988 do_cleanups (old_chain);
2989 }
2990
2991 /* Encode a piece of a tracepoint's source-level definition in a form
2992 that is suitable for both protocol and saving in files. */
2993 /* This version does not do multiple encodes for long strings; it should
2994 return an offset to the next piece to encode. FIXME */
2995
2996 extern int
2997 encode_source_string (int tpnum, ULONGEST addr,
2998 char *srctype, const char *src, char *buf, int buf_size)
2999 {
3000 if (80 + strlen (srctype) > buf_size)
3001 error (_("Buffer too small for source encoding"));
3002 sprintf (buf, "%x:%s:%s:%x:%x:",
3003 tpnum, phex_nz (addr, sizeof (addr)),
3004 srctype, 0, (int) strlen (src));
3005 if (strlen (buf) + strlen (src) * 2 >= buf_size)
3006 error (_("Source string too long for buffer"));
3007 bin2hex ((gdb_byte *) src, buf + strlen (buf), strlen (src));
3008 return -1;
3009 }
3010
3011 /* Tell the target what to do with an ongoing tracing run if GDB
3012 disconnects for some reason. */
3013
3014 static void
3015 set_disconnected_tracing (char *args, int from_tty,
3016 struct cmd_list_element *c)
3017 {
3018 target_set_disconnected_tracing (disconnected_tracing);
3019 }
3020
3021 static void
3022 set_circular_trace_buffer (char *args, int from_tty,
3023 struct cmd_list_element *c)
3024 {
3025 target_set_circular_trace_buffer (circular_trace_buffer);
3026 }
3027
3028 static void
3029 set_trace_buffer_size (char *args, int from_tty,
3030 struct cmd_list_element *c)
3031 {
3032 target_set_trace_buffer_size (trace_buffer_size);
3033 }
3034
3035 static void
3036 set_trace_user (char *args, int from_tty,
3037 struct cmd_list_element *c)
3038 {
3039 int ret;
3040
3041 ret = target_set_trace_notes (trace_user, NULL, NULL);
3042
3043 if (!ret)
3044 warning (_("Target does not support trace notes, user ignored"));
3045 }
3046
3047 static void
3048 set_trace_notes (char *args, int from_tty,
3049 struct cmd_list_element *c)
3050 {
3051 int ret;
3052
3053 ret = target_set_trace_notes (NULL, trace_notes, NULL);
3054
3055 if (!ret)
3056 warning (_("Target does not support trace notes, note ignored"));
3057 }
3058
3059 static void
3060 set_trace_stop_notes (char *args, int from_tty,
3061 struct cmd_list_element *c)
3062 {
3063 int ret;
3064
3065 ret = target_set_trace_notes (NULL, NULL, trace_stop_notes);
3066
3067 if (!ret)
3068 warning (_("Target does not support trace notes, stop note ignored"));
3069 }
3070
3071 /* Convert the memory pointed to by mem into hex, placing result in buf.
3072 * Return a pointer to the last char put in buf (null)
3073 * "stolen" from sparc-stub.c
3074 */
3075
3076 static const char hexchars[] = "0123456789abcdef";
3077
3078 static char *
3079 mem2hex (gdb_byte *mem, char *buf, int count)
3080 {
3081 gdb_byte ch;
3082
3083 while (count-- > 0)
3084 {
3085 ch = *mem++;
3086
3087 *buf++ = hexchars[ch >> 4];
3088 *buf++ = hexchars[ch & 0xf];
3089 }
3090
3091 *buf = 0;
3092
3093 return buf;
3094 }
3095
3096 int
3097 get_traceframe_number (void)
3098 {
3099 return traceframe_number;
3100 }
3101
3102 int
3103 get_tracepoint_number (void)
3104 {
3105 return tracepoint_number;
3106 }
3107
3108 /* Make the traceframe NUM be the current trace frame. Does nothing
3109 if NUM is already current. */
3110
3111 void
3112 set_current_traceframe (int num)
3113 {
3114 int newnum;
3115
3116 if (traceframe_number == num)
3117 {
3118 /* Nothing to do. */
3119 return;
3120 }
3121
3122 newnum = target_trace_find (tfind_number, num, 0, 0, NULL);
3123
3124 if (newnum != num)
3125 warning (_("could not change traceframe"));
3126
3127 set_traceframe_num (newnum);
3128
3129 /* Changing the traceframe changes our view of registers and of the
3130 frame chain. */
3131 registers_changed ();
3132
3133 clear_traceframe_info ();
3134 }
3135
3136 /* A cleanup used when switching away and back from tfind mode. */
3137
3138 struct current_traceframe_cleanup
3139 {
3140 /* The traceframe we were inspecting. */
3141 int traceframe_number;
3142 };
3143
3144 static void
3145 do_restore_current_traceframe_cleanup (void *arg)
3146 {
3147 struct current_traceframe_cleanup *old
3148 = (struct current_traceframe_cleanup *) arg;
3149
3150 set_current_traceframe (old->traceframe_number);
3151 }
3152
3153 static void
3154 restore_current_traceframe_cleanup_dtor (void *arg)
3155 {
3156 struct current_traceframe_cleanup *old
3157 = (struct current_traceframe_cleanup *) arg;
3158
3159 xfree (old);
3160 }
3161
3162 struct cleanup *
3163 make_cleanup_restore_current_traceframe (void)
3164 {
3165 struct current_traceframe_cleanup *old =
3166 XNEW (struct current_traceframe_cleanup);
3167
3168 old->traceframe_number = traceframe_number;
3169
3170 return make_cleanup_dtor (do_restore_current_traceframe_cleanup, old,
3171 restore_current_traceframe_cleanup_dtor);
3172 }
3173
3174 /* Given a number and address, return an uploaded tracepoint with that
3175 number, creating if necessary. */
3176
3177 struct uploaded_tp *
3178 get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp)
3179 {
3180 struct uploaded_tp *utp;
3181
3182 for (utp = *utpp; utp; utp = utp->next)
3183 if (utp->number == num && utp->addr == addr)
3184 return utp;
3185
3186 utp = XCNEW (struct uploaded_tp);
3187 utp->number = num;
3188 utp->addr = addr;
3189 utp->actions = NULL;
3190 utp->step_actions = NULL;
3191 utp->cmd_strings = NULL;
3192 utp->next = *utpp;
3193 *utpp = utp;
3194
3195 return utp;
3196 }
3197
3198 void
3199 free_uploaded_tps (struct uploaded_tp **utpp)
3200 {
3201 struct uploaded_tp *next_one;
3202
3203 while (*utpp)
3204 {
3205 next_one = (*utpp)->next;
3206 xfree (*utpp);
3207 *utpp = next_one;
3208 }
3209 }
3210
3211 /* Given a number and address, return an uploaded tracepoint with that
3212 number, creating if necessary. */
3213
3214 struct uploaded_tsv *
3215 get_uploaded_tsv (int num, struct uploaded_tsv **utsvp)
3216 {
3217 struct uploaded_tsv *utsv;
3218
3219 for (utsv = *utsvp; utsv; utsv = utsv->next)
3220 if (utsv->number == num)
3221 return utsv;
3222
3223 utsv = XCNEW (struct uploaded_tsv);
3224 utsv->number = num;
3225 utsv->next = *utsvp;
3226 *utsvp = utsv;
3227
3228 return utsv;
3229 }
3230
3231 void
3232 free_uploaded_tsvs (struct uploaded_tsv **utsvp)
3233 {
3234 struct uploaded_tsv *next_one;
3235
3236 while (*utsvp)
3237 {
3238 next_one = (*utsvp)->next;
3239 xfree (*utsvp);
3240 *utsvp = next_one;
3241 }
3242 }
3243
3244 /* FIXME this function is heuristic and will miss the cases where the
3245 conditional is semantically identical but differs in whitespace,
3246 such as "x == 0" vs "x==0". */
3247
3248 static int
3249 cond_string_is_same (char *str1, char *str2)
3250 {
3251 if (str1 == NULL || str2 == NULL)
3252 return (str1 == str2);
3253
3254 return (strcmp (str1, str2) == 0);
3255 }
3256
3257 /* Look for an existing tracepoint that seems similar enough to the
3258 uploaded one. Enablement isn't compared, because the user can
3259 toggle that freely, and may have done so in anticipation of the
3260 next trace run. Return the location of matched tracepoint. */
3261
3262 static struct bp_location *
3263 find_matching_tracepoint_location (struct uploaded_tp *utp)
3264 {
3265 VEC(breakpoint_p) *tp_vec = all_tracepoints ();
3266 int ix;
3267 struct breakpoint *b;
3268 struct bp_location *loc;
3269
3270 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
3271 {
3272 struct tracepoint *t = (struct tracepoint *) b;
3273
3274 if (b->type == utp->type
3275 && t->step_count == utp->step
3276 && t->pass_count == utp->pass
3277 && cond_string_is_same (t->base.cond_string, utp->cond_string)
3278 /* FIXME also test actions. */
3279 )
3280 {
3281 /* Scan the locations for an address match. */
3282 for (loc = b->loc; loc; loc = loc->next)
3283 {
3284 if (loc->address == utp->addr)
3285 return loc;
3286 }
3287 }
3288 }
3289 return NULL;
3290 }
3291
3292 /* Given a list of tracepoints uploaded from a target, attempt to
3293 match them up with existing tracepoints, and create new ones if not
3294 found. */
3295
3296 void
3297 merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps)
3298 {
3299 struct uploaded_tp *utp;
3300 /* A set of tracepoints which are modified. */
3301 VEC(breakpoint_p) *modified_tp = NULL;
3302 int ix;
3303 struct breakpoint *b;
3304
3305 /* Look for GDB tracepoints that match up with our uploaded versions. */
3306 for (utp = *uploaded_tps; utp; utp = utp->next)
3307 {
3308 struct bp_location *loc;
3309 struct tracepoint *t;
3310
3311 loc = find_matching_tracepoint_location (utp);
3312 if (loc)
3313 {
3314 int found = 0;
3315
3316 /* Mark this location as already inserted. */
3317 loc->inserted = 1;
3318 t = (struct tracepoint *) loc->owner;
3319 printf_filtered (_("Assuming tracepoint %d is same "
3320 "as target's tracepoint %d at %s.\n"),
3321 loc->owner->number, utp->number,
3322 paddress (loc->gdbarch, utp->addr));
3323
3324 /* The tracepoint LOC->owner was modified (the location LOC
3325 was marked as inserted in the target). Save it in
3326 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3327 observers will be notified later once for each tracepoint
3328 saved in MODIFIED_TP. */
3329 for (ix = 0;
3330 VEC_iterate (breakpoint_p, modified_tp, ix, b);
3331 ix++)
3332 if (b == loc->owner)
3333 {
3334 found = 1;
3335 break;
3336 }
3337 if (!found)
3338 VEC_safe_push (breakpoint_p, modified_tp, loc->owner);
3339 }
3340 else
3341 {
3342 t = create_tracepoint_from_upload (utp);
3343 if (t)
3344 printf_filtered (_("Created tracepoint %d for "
3345 "target's tracepoint %d at %s.\n"),
3346 t->base.number, utp->number,
3347 paddress (get_current_arch (), utp->addr));
3348 else
3349 printf_filtered (_("Failed to create tracepoint for target's "
3350 "tracepoint %d at %s, skipping it.\n"),
3351 utp->number,
3352 paddress (get_current_arch (), utp->addr));
3353 }
3354 /* Whether found or created, record the number used by the
3355 target, to help with mapping target tracepoints back to their
3356 counterparts here. */
3357 if (t)
3358 t->number_on_target = utp->number;
3359 }
3360
3361 /* Notify 'breakpoint-modified' observer that at least one of B's
3362 locations was changed. */
3363 for (ix = 0; VEC_iterate (breakpoint_p, modified_tp, ix, b); ix++)
3364 observer_notify_breakpoint_modified (b);
3365
3366 VEC_free (breakpoint_p, modified_tp);
3367 free_uploaded_tps (uploaded_tps);
3368 }
3369
3370 /* Trace state variables don't have much to identify them beyond their
3371 name, so just use that to detect matches. */
3372
3373 static struct trace_state_variable *
3374 find_matching_tsv (struct uploaded_tsv *utsv)
3375 {
3376 if (!utsv->name)
3377 return NULL;
3378
3379 return find_trace_state_variable (utsv->name);
3380 }
3381
3382 static struct trace_state_variable *
3383 create_tsv_from_upload (struct uploaded_tsv *utsv)
3384 {
3385 const char *namebase;
3386 char *buf;
3387 int try_num = 0;
3388 struct trace_state_variable *tsv;
3389 struct cleanup *old_chain;
3390
3391 if (utsv->name)
3392 {
3393 namebase = utsv->name;
3394 buf = xstrprintf ("%s", namebase);
3395 }
3396 else
3397 {
3398 namebase = "__tsv";
3399 buf = xstrprintf ("%s_%d", namebase, try_num++);
3400 }
3401
3402 /* Fish for a name that is not in use. */
3403 /* (should check against all internal vars?) */
3404 while (find_trace_state_variable (buf))
3405 {
3406 xfree (buf);
3407 buf = xstrprintf ("%s_%d", namebase, try_num++);
3408 }
3409
3410 old_chain = make_cleanup (xfree, buf);
3411
3412 /* We have an available name, create the variable. */
3413 tsv = create_trace_state_variable (buf);
3414 tsv->initial_value = utsv->initial_value;
3415 tsv->builtin = utsv->builtin;
3416
3417 observer_notify_tsv_created (tsv);
3418
3419 do_cleanups (old_chain);
3420
3421 return tsv;
3422 }
3423
3424 /* Given a list of uploaded trace state variables, try to match them
3425 up with existing variables, or create additional ones. */
3426
3427 void
3428 merge_uploaded_trace_state_variables (struct uploaded_tsv **uploaded_tsvs)
3429 {
3430 int ix;
3431 struct uploaded_tsv *utsv;
3432 struct trace_state_variable *tsv;
3433 int highest;
3434
3435 /* Most likely some numbers will have to be reassigned as part of
3436 the merge, so clear them all in anticipation. */
3437 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3438 tsv->number = 0;
3439
3440 for (utsv = *uploaded_tsvs; utsv; utsv = utsv->next)
3441 {
3442 tsv = find_matching_tsv (utsv);
3443 if (tsv)
3444 {
3445 if (info_verbose)
3446 printf_filtered (_("Assuming trace state variable $%s "
3447 "is same as target's variable %d.\n"),
3448 tsv->name, utsv->number);
3449 }
3450 else
3451 {
3452 tsv = create_tsv_from_upload (utsv);
3453 if (info_verbose)
3454 printf_filtered (_("Created trace state variable "
3455 "$%s for target's variable %d.\n"),
3456 tsv->name, utsv->number);
3457 }
3458 /* Give precedence to numberings that come from the target. */
3459 if (tsv)
3460 tsv->number = utsv->number;
3461 }
3462
3463 /* Renumber everything that didn't get a target-assigned number. */
3464 highest = 0;
3465 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3466 if (tsv->number > highest)
3467 highest = tsv->number;
3468
3469 ++highest;
3470 for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
3471 if (tsv->number == 0)
3472 tsv->number = highest++;
3473
3474 free_uploaded_tsvs (uploaded_tsvs);
3475 }
3476
3477 /* Parse the part of trace status syntax that is shared between
3478 the remote protocol and the trace file reader. */
3479
3480 void
3481 parse_trace_status (char *line, struct trace_status *ts)
3482 {
3483 char *p = line, *p1, *p2, *p3, *p_temp;
3484 int end;
3485 ULONGEST val;
3486
3487 ts->running_known = 1;
3488 ts->running = (*p++ == '1');
3489 ts->stop_reason = trace_stop_reason_unknown;
3490 xfree (ts->stop_desc);
3491 ts->stop_desc = NULL;
3492 ts->traceframe_count = -1;
3493 ts->traceframes_created = -1;
3494 ts->buffer_free = -1;
3495 ts->buffer_size = -1;
3496 ts->disconnected_tracing = 0;
3497 ts->circular_buffer = 0;
3498 xfree (ts->user_name);
3499 ts->user_name = NULL;
3500 xfree (ts->notes);
3501 ts->notes = NULL;
3502 ts->start_time = ts->stop_time = 0;
3503
3504 while (*p++)
3505 {
3506 p1 = strchr (p, ':');
3507 if (p1 == NULL)
3508 error (_("Malformed trace status, at %s\n\
3509 Status line: '%s'\n"), p, line);
3510 p3 = strchr (p, ';');
3511 if (p3 == NULL)
3512 p3 = p + strlen (p);
3513 if (strncmp (p, stop_reason_names[trace_buffer_full], p1 - p) == 0)
3514 {
3515 p = unpack_varlen_hex (++p1, &val);
3516 ts->stop_reason = trace_buffer_full;
3517 }
3518 else if (strncmp (p, stop_reason_names[trace_never_run], p1 - p) == 0)
3519 {
3520 p = unpack_varlen_hex (++p1, &val);
3521 ts->stop_reason = trace_never_run;
3522 }
3523 else if (strncmp (p, stop_reason_names[tracepoint_passcount],
3524 p1 - p) == 0)
3525 {
3526 p = unpack_varlen_hex (++p1, &val);
3527 ts->stop_reason = tracepoint_passcount;
3528 ts->stopping_tracepoint = val;
3529 }
3530 else if (strncmp (p, stop_reason_names[tstop_command], p1 - p) == 0)
3531 {
3532 p2 = strchr (++p1, ':');
3533 if (!p2 || p2 > p3)
3534 {
3535 /*older style*/
3536 p2 = p1;
3537 }
3538 else if (p2 != p1)
3539 {
3540 ts->stop_desc = (char *) xmalloc (strlen (line));
3541 end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2);
3542 ts->stop_desc[end] = '\0';
3543 }
3544 else
3545 ts->stop_desc = xstrdup ("");
3546
3547 p = unpack_varlen_hex (++p2, &val);
3548 ts->stop_reason = tstop_command;
3549 }
3550 else if (strncmp (p, stop_reason_names[trace_disconnected], p1 - p) == 0)
3551 {
3552 p = unpack_varlen_hex (++p1, &val);
3553 ts->stop_reason = trace_disconnected;
3554 }
3555 else if (strncmp (p, stop_reason_names[tracepoint_error], p1 - p) == 0)
3556 {
3557 p2 = strchr (++p1, ':');
3558 if (p2 != p1)
3559 {
3560 ts->stop_desc = (char *) xmalloc ((p2 - p1) / 2 + 1);
3561 end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2);
3562 ts->stop_desc[end] = '\0';
3563 }
3564 else
3565 ts->stop_desc = xstrdup ("");
3566
3567 p = unpack_varlen_hex (++p2, &val);
3568 ts->stopping_tracepoint = val;
3569 ts->stop_reason = tracepoint_error;
3570 }
3571 else if (strncmp (p, "tframes", p1 - p) == 0)
3572 {
3573 p = unpack_varlen_hex (++p1, &val);
3574 ts->traceframe_count = val;
3575 }
3576 else if (strncmp (p, "tcreated", p1 - p) == 0)
3577 {
3578 p = unpack_varlen_hex (++p1, &val);
3579 ts->traceframes_created = val;
3580 }
3581 else if (strncmp (p, "tfree", p1 - p) == 0)
3582 {
3583 p = unpack_varlen_hex (++p1, &val);
3584 ts->buffer_free = val;
3585 }
3586 else if (strncmp (p, "tsize", p1 - p) == 0)
3587 {
3588 p = unpack_varlen_hex (++p1, &val);
3589 ts->buffer_size = val;
3590 }
3591 else if (strncmp (p, "disconn", p1 - p) == 0)
3592 {
3593 p = unpack_varlen_hex (++p1, &val);
3594 ts->disconnected_tracing = val;
3595 }
3596 else if (strncmp (p, "circular", p1 - p) == 0)
3597 {
3598 p = unpack_varlen_hex (++p1, &val);
3599 ts->circular_buffer = val;
3600 }
3601 else if (strncmp (p, "starttime", p1 - p) == 0)
3602 {
3603 p = unpack_varlen_hex (++p1, &val);
3604 ts->start_time = val;
3605 }
3606 else if (strncmp (p, "stoptime", p1 - p) == 0)
3607 {
3608 p = unpack_varlen_hex (++p1, &val);
3609 ts->stop_time = val;
3610 }
3611 else if (strncmp (p, "username", p1 - p) == 0)
3612 {
3613 ++p1;
3614 ts->user_name = (char *) xmalloc (strlen (p) / 2);
3615 end = hex2bin (p1, (gdb_byte *) ts->user_name, (p3 - p1) / 2);
3616 ts->user_name[end] = '\0';
3617 p = p3;
3618 }
3619 else if (strncmp (p, "notes", p1 - p) == 0)
3620 {
3621 ++p1;
3622 ts->notes = (char *) xmalloc (strlen (p) / 2);
3623 end = hex2bin (p1, (gdb_byte *) ts->notes, (p3 - p1) / 2);
3624 ts->notes[end] = '\0';
3625 p = p3;
3626 }
3627 else
3628 {
3629 /* Silently skip unknown optional info. */
3630 p_temp = strchr (p1 + 1, ';');
3631 if (p_temp)
3632 p = p_temp;
3633 else
3634 /* Must be at the end. */
3635 break;
3636 }
3637 }
3638 }
3639
3640 void
3641 parse_tracepoint_status (char *p, struct breakpoint *bp,
3642 struct uploaded_tp *utp)
3643 {
3644 ULONGEST uval;
3645 struct tracepoint *tp = (struct tracepoint *) bp;
3646
3647 p = unpack_varlen_hex (p, &uval);
3648 if (tp)
3649 tp->base.hit_count += uval;
3650 else
3651 utp->hit_count += uval;
3652 p = unpack_varlen_hex (p + 1, &uval);
3653 if (tp)
3654 tp->traceframe_usage += uval;
3655 else
3656 utp->traceframe_usage += uval;
3657 /* Ignore any extra, allowing for future extensions. */
3658 }
3659
3660 /* Given a line of text defining a part of a tracepoint, parse it into
3661 an "uploaded tracepoint". */
3662
3663 void
3664 parse_tracepoint_definition (char *line, struct uploaded_tp **utpp)
3665 {
3666 char *p;
3667 char piece;
3668 ULONGEST num, addr, step, pass, orig_size, xlen, start;
3669 int enabled, end;
3670 enum bptype type;
3671 char *cond, *srctype, *buf;
3672 struct uploaded_tp *utp = NULL;
3673
3674 p = line;
3675 /* Both tracepoint and action definitions start with the same number
3676 and address sequence. */
3677 piece = *p++;
3678 p = unpack_varlen_hex (p, &num);
3679 p++; /* skip a colon */
3680 p = unpack_varlen_hex (p, &addr);
3681 p++; /* skip a colon */
3682 if (piece == 'T')
3683 {
3684 enabled = (*p++ == 'E');
3685 p++; /* skip a colon */
3686 p = unpack_varlen_hex (p, &step);
3687 p++; /* skip a colon */
3688 p = unpack_varlen_hex (p, &pass);
3689 type = bp_tracepoint;
3690 cond = NULL;
3691 /* Thumb through optional fields. */
3692 while (*p == ':')
3693 {
3694 p++; /* skip a colon */
3695 if (*p == 'F')
3696 {
3697 type = bp_fast_tracepoint;
3698 p++;
3699 p = unpack_varlen_hex (p, &orig_size);
3700 }
3701 else if (*p == 'S')
3702 {
3703 type = bp_static_tracepoint;
3704 p++;
3705 }
3706 else if (*p == 'X')
3707 {
3708 p++;
3709 p = unpack_varlen_hex (p, &xlen);
3710 p++; /* skip a comma */
3711 cond = (char *) xmalloc (2 * xlen + 1);
3712 strncpy (cond, p, 2 * xlen);
3713 cond[2 * xlen] = '\0';
3714 p += 2 * xlen;
3715 }
3716 else
3717 warning (_("Unrecognized char '%c' in tracepoint "
3718 "definition, skipping rest"), *p);
3719 }
3720 utp = get_uploaded_tp (num, addr, utpp);
3721 utp->type = type;
3722 utp->enabled = enabled;
3723 utp->step = step;
3724 utp->pass = pass;
3725 utp->cond = cond;
3726 }
3727 else if (piece == 'A')
3728 {
3729 utp = get_uploaded_tp (num, addr, utpp);
3730 VEC_safe_push (char_ptr, utp->actions, xstrdup (p));
3731 }
3732 else if (piece == 'S')
3733 {
3734 utp = get_uploaded_tp (num, addr, utpp);
3735 VEC_safe_push (char_ptr, utp->step_actions, xstrdup (p));
3736 }
3737 else if (piece == 'Z')
3738 {
3739 /* Parse a chunk of source form definition. */
3740 utp = get_uploaded_tp (num, addr, utpp);
3741 srctype = p;
3742 p = strchr (p, ':');
3743 p++; /* skip a colon */
3744 p = unpack_varlen_hex (p, &start);
3745 p++; /* skip a colon */
3746 p = unpack_varlen_hex (p, &xlen);
3747 p++; /* skip a colon */
3748
3749 buf = (char *) alloca (strlen (line));
3750
3751 end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
3752 buf[end] = '\0';
3753
3754 if (startswith (srctype, "at:"))
3755 utp->at_string = xstrdup (buf);
3756 else if (startswith (srctype, "cond:"))
3757 utp->cond_string = xstrdup (buf);
3758 else if (startswith (srctype, "cmd:"))
3759 VEC_safe_push (char_ptr, utp->cmd_strings, xstrdup (buf));
3760 }
3761 else if (piece == 'V')
3762 {
3763 utp = get_uploaded_tp (num, addr, utpp);
3764
3765 parse_tracepoint_status (p, NULL, utp);
3766 }
3767 else
3768 {
3769 /* Don't error out, the target might be sending us optional
3770 info that we don't care about. */
3771 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece);
3772 }
3773 }
3774
3775 /* Convert a textual description of a trace state variable into an
3776 uploaded object. */
3777
3778 void
3779 parse_tsv_definition (char *line, struct uploaded_tsv **utsvp)
3780 {
3781 char *p, *buf;
3782 ULONGEST num, initval, builtin;
3783 int end;
3784 struct uploaded_tsv *utsv = NULL;
3785
3786 buf = (char *) alloca (strlen (line));
3787
3788 p = line;
3789 p = unpack_varlen_hex (p, &num);
3790 p++; /* skip a colon */
3791 p = unpack_varlen_hex (p, &initval);
3792 p++; /* skip a colon */
3793 p = unpack_varlen_hex (p, &builtin);
3794 p++; /* skip a colon */
3795 end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
3796 buf[end] = '\0';
3797
3798 utsv = get_uploaded_tsv (num, utsvp);
3799 utsv->initial_value = initval;
3800 utsv->builtin = builtin;
3801 utsv->name = xstrdup (buf);
3802 }
3803
3804 void
3805 free_current_marker (void *arg)
3806 {
3807 struct static_tracepoint_marker **marker_p
3808 = (struct static_tracepoint_marker **) arg;
3809
3810 if (*marker_p != NULL)
3811 {
3812 release_static_tracepoint_marker (*marker_p);
3813 xfree (*marker_p);
3814 }
3815 else
3816 *marker_p = NULL;
3817 }
3818
3819 /* Given a line of text defining a static tracepoint marker, parse it
3820 into a "static tracepoint marker" object. Throws an error is
3821 parsing fails. If PP is non-null, it points to one past the end of
3822 the parsed marker definition. */
3823
3824 void
3825 parse_static_tracepoint_marker_definition (char *line, char **pp,
3826 struct static_tracepoint_marker *marker)
3827 {
3828 char *p, *endp;
3829 ULONGEST addr;
3830 int end;
3831
3832 p = line;
3833 p = unpack_varlen_hex (p, &addr);
3834 p++; /* skip a colon */
3835
3836 marker->gdbarch = target_gdbarch ();
3837 marker->address = (CORE_ADDR) addr;
3838
3839 endp = strchr (p, ':');
3840 if (endp == NULL)
3841 error (_("bad marker definition: %s"), line);
3842
3843 marker->str_id = (char *) xmalloc (endp - p + 1);
3844 end = hex2bin (p, (gdb_byte *) marker->str_id, (endp - p + 1) / 2);
3845 marker->str_id[end] = '\0';
3846
3847 p += 2 * end;
3848 p++; /* skip a colon */
3849
3850 marker->extra = (char *) xmalloc (strlen (p) + 1);
3851 end = hex2bin (p, (gdb_byte *) marker->extra, strlen (p) / 2);
3852 marker->extra[end] = '\0';
3853
3854 if (pp)
3855 *pp = p;
3856 }
3857
3858 /* Release a static tracepoint marker's contents. Note that the
3859 object itself isn't released here. There objects are usually on
3860 the stack. */
3861
3862 void
3863 release_static_tracepoint_marker (struct static_tracepoint_marker *marker)
3864 {
3865 xfree (marker->str_id);
3866 marker->str_id = NULL;
3867 }
3868
3869 /* Print MARKER to gdb_stdout. */
3870
3871 static void
3872 print_one_static_tracepoint_marker (int count,
3873 struct static_tracepoint_marker *marker)
3874 {
3875 struct symbol *sym;
3876
3877 char wrap_indent[80];
3878 char extra_field_indent[80];
3879 struct ui_out *uiout = current_uiout;
3880 struct cleanup *bkpt_chain;
3881 VEC(breakpoint_p) *tracepoints;
3882
3883 struct symtab_and_line sal;
3884
3885 init_sal (&sal);
3886
3887 sal.pc = marker->address;
3888
3889 tracepoints = static_tracepoints_here (marker->address);
3890
3891 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "marker");
3892
3893 /* A counter field to help readability. This is not a stable
3894 identifier! */
3895 ui_out_field_int (uiout, "count", count);
3896
3897 ui_out_field_string (uiout, "marker-id", marker->str_id);
3898
3899 ui_out_field_fmt (uiout, "enabled", "%c",
3900 !VEC_empty (breakpoint_p, tracepoints) ? 'y' : 'n');
3901 ui_out_spaces (uiout, 2);
3902
3903 strcpy (wrap_indent, " ");
3904
3905 if (gdbarch_addr_bit (marker->gdbarch) <= 32)
3906 strcat (wrap_indent, " ");
3907 else
3908 strcat (wrap_indent, " ");
3909
3910 strcpy (extra_field_indent, " ");
3911
3912 ui_out_field_core_addr (uiout, "addr", marker->gdbarch, marker->address);
3913
3914 sal = find_pc_line (marker->address, 0);
3915 sym = find_pc_sect_function (marker->address, NULL);
3916 if (sym)
3917 {
3918 ui_out_text (uiout, "in ");
3919 ui_out_field_string (uiout, "func",
3920 SYMBOL_PRINT_NAME (sym));
3921 ui_out_wrap_hint (uiout, wrap_indent);
3922 ui_out_text (uiout, " at ");
3923 }
3924 else
3925 ui_out_field_skip (uiout, "func");
3926
3927 if (sal.symtab != NULL)
3928 {
3929 ui_out_field_string (uiout, "file",
3930 symtab_to_filename_for_display (sal.symtab));
3931 ui_out_text (uiout, ":");
3932
3933 if (ui_out_is_mi_like_p (uiout))
3934 {
3935 const char *fullname = symtab_to_fullname (sal.symtab);
3936
3937 ui_out_field_string (uiout, "fullname", fullname);
3938 }
3939 else
3940 ui_out_field_skip (uiout, "fullname");
3941
3942 ui_out_field_int (uiout, "line", sal.line);
3943 }
3944 else
3945 {
3946 ui_out_field_skip (uiout, "fullname");
3947 ui_out_field_skip (uiout, "line");
3948 }
3949
3950 ui_out_text (uiout, "\n");
3951 ui_out_text (uiout, extra_field_indent);
3952 ui_out_text (uiout, _("Data: \""));
3953 ui_out_field_string (uiout, "extra-data", marker->extra);
3954 ui_out_text (uiout, "\"\n");
3955
3956 if (!VEC_empty (breakpoint_p, tracepoints))
3957 {
3958 struct cleanup *cleanup_chain;
3959 int ix;
3960 struct breakpoint *b;
3961
3962 cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout,
3963 "tracepoints-at");
3964
3965 ui_out_text (uiout, extra_field_indent);
3966 ui_out_text (uiout, _("Probed by static tracepoints: "));
3967 for (ix = 0; VEC_iterate(breakpoint_p, tracepoints, ix, b); ix++)
3968 {
3969 if (ix > 0)
3970 ui_out_text (uiout, ", ");
3971 ui_out_text (uiout, "#");
3972 ui_out_field_int (uiout, "tracepoint-id", b->number);
3973 }
3974
3975 do_cleanups (cleanup_chain);
3976
3977 if (ui_out_is_mi_like_p (uiout))
3978 ui_out_field_int (uiout, "number-of-tracepoints",
3979 VEC_length(breakpoint_p, tracepoints));
3980 else
3981 ui_out_text (uiout, "\n");
3982 }
3983 VEC_free (breakpoint_p, tracepoints);
3984
3985 do_cleanups (bkpt_chain);
3986 }
3987
3988 static void
3989 info_static_tracepoint_markers_command (char *arg, int from_tty)
3990 {
3991 VEC(static_tracepoint_marker_p) *markers;
3992 struct cleanup *old_chain;
3993 struct static_tracepoint_marker *marker;
3994 struct ui_out *uiout = current_uiout;
3995 int i;
3996
3997 /* We don't have to check target_can_use_agent and agent's capability on
3998 static tracepoint here, in order to be compatible with older GDBserver.
3999 We don't check USE_AGENT is true or not, because static tracepoints
4000 don't work without in-process agent, so we don't bother users to type
4001 `set agent on' when to use static tracepoint. */
4002
4003 old_chain
4004 = make_cleanup_ui_out_table_begin_end (uiout, 5, -1,
4005 "StaticTracepointMarkersTable");
4006
4007 ui_out_table_header (uiout, 7, ui_left, "counter", "Cnt");
4008
4009 ui_out_table_header (uiout, 40, ui_left, "marker-id", "ID");
4010
4011 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb");
4012 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
4013 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");
4014 else
4015 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");
4016 ui_out_table_header (uiout, 40, ui_noalign, "what", "What");
4017
4018 ui_out_table_body (uiout);
4019
4020 markers = target_static_tracepoint_markers_by_strid (NULL);
4021 make_cleanup (VEC_cleanup (static_tracepoint_marker_p), &markers);
4022
4023 for (i = 0;
4024 VEC_iterate (static_tracepoint_marker_p,
4025 markers, i, marker);
4026 i++)
4027 {
4028 print_one_static_tracepoint_marker (i + 1, marker);
4029 release_static_tracepoint_marker (marker);
4030 }
4031
4032 do_cleanups (old_chain);
4033 }
4034
4035 /* The $_sdata convenience variable is a bit special. We don't know
4036 for sure type of the value until we actually have a chance to fetch
4037 the data --- the size of the object depends on what has been
4038 collected. We solve this by making $_sdata be an internalvar that
4039 creates a new value on access. */
4040
4041 /* Return a new value with the correct type for the sdata object of
4042 the current trace frame. Return a void value if there's no object
4043 available. */
4044
4045 static struct value *
4046 sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var,
4047 void *ignore)
4048 {
4049 LONGEST size;
4050 gdb_byte *buf;
4051
4052 /* We need to read the whole object before we know its size. */
4053 size = target_read_alloc (&current_target,
4054 TARGET_OBJECT_STATIC_TRACE_DATA,
4055 NULL, &buf);
4056 if (size >= 0)
4057 {
4058 struct value *v;
4059 struct type *type;
4060
4061 type = init_vector_type (builtin_type (gdbarch)->builtin_true_char,
4062 size);
4063 v = allocate_value (type);
4064 memcpy (value_contents_raw (v), buf, size);
4065 xfree (buf);
4066 return v;
4067 }
4068 else
4069 return allocate_value (builtin_type (gdbarch)->builtin_void);
4070 }
4071
4072 #if !defined(HAVE_LIBEXPAT)
4073
4074 struct traceframe_info *
4075 parse_traceframe_info (const char *tframe_info)
4076 {
4077 static int have_warned;
4078
4079 if (!have_warned)
4080 {
4081 have_warned = 1;
4082 warning (_("Can not parse XML trace frame info; XML support "
4083 "was disabled at compile time"));
4084 }
4085
4086 return NULL;
4087 }
4088
4089 #else /* HAVE_LIBEXPAT */
4090
4091 #include "xml-support.h"
4092
4093 /* Handle the start of a <memory> element. */
4094
4095 static void
4096 traceframe_info_start_memory (struct gdb_xml_parser *parser,
4097 const struct gdb_xml_element *element,
4098 void *user_data, VEC(gdb_xml_value_s) *attributes)
4099 {
4100 struct traceframe_info *info = (struct traceframe_info *) user_data;
4101 struct mem_range *r = VEC_safe_push (mem_range_s, info->memory, NULL);
4102 ULONGEST *start_p, *length_p;
4103
4104 start_p
4105 = (ULONGEST *) xml_find_attribute (attributes, "start")->value;
4106 length_p
4107 = (ULONGEST *) xml_find_attribute (attributes, "length")->value;
4108
4109 r->start = *start_p;
4110 r->length = *length_p;
4111 }
4112
4113 /* Handle the start of a <tvar> element. */
4114
4115 static void
4116 traceframe_info_start_tvar (struct gdb_xml_parser *parser,
4117 const struct gdb_xml_element *element,
4118 void *user_data,
4119 VEC(gdb_xml_value_s) *attributes)
4120 {
4121 struct traceframe_info *info = (struct traceframe_info *) user_data;
4122 const char *id_attrib
4123 = (const char *) xml_find_attribute (attributes, "id")->value;
4124 int id = gdb_xml_parse_ulongest (parser, id_attrib);
4125
4126 VEC_safe_push (int, info->tvars, id);
4127 }
4128
4129 /* Discard the constructed trace frame info (if an error occurs). */
4130
4131 static void
4132 free_result (void *p)
4133 {
4134 struct traceframe_info *result = (struct traceframe_info *) p;
4135
4136 free_traceframe_info (result);
4137 }
4138
4139 /* The allowed elements and attributes for an XML memory map. */
4140
4141 static const struct gdb_xml_attribute memory_attributes[] = {
4142 { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
4143 { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
4144 { NULL, GDB_XML_AF_NONE, NULL, NULL }
4145 };
4146
4147 static const struct gdb_xml_attribute tvar_attributes[] = {
4148 { "id", GDB_XML_AF_NONE, NULL, NULL },
4149 { NULL, GDB_XML_AF_NONE, NULL, NULL }
4150 };
4151
4152 static const struct gdb_xml_element traceframe_info_children[] = {
4153 { "memory", memory_attributes, NULL,
4154 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
4155 traceframe_info_start_memory, NULL },
4156 { "tvar", tvar_attributes, NULL,
4157 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
4158 traceframe_info_start_tvar, NULL },
4159 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
4160 };
4161
4162 static const struct gdb_xml_element traceframe_info_elements[] = {
4163 { "traceframe-info", NULL, traceframe_info_children, GDB_XML_EF_NONE,
4164 NULL, NULL },
4165 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
4166 };
4167
4168 /* Parse a traceframe-info XML document. */
4169
4170 struct traceframe_info *
4171 parse_traceframe_info (const char *tframe_info)
4172 {
4173 struct traceframe_info *result;
4174 struct cleanup *back_to;
4175
4176 result = XCNEW (struct traceframe_info);
4177 back_to = make_cleanup (free_result, result);
4178
4179 if (gdb_xml_parse_quick (_("trace frame info"),
4180 "traceframe-info.dtd", traceframe_info_elements,
4181 tframe_info, result) == 0)
4182 {
4183 /* Parsed successfully, keep the result. */
4184 discard_cleanups (back_to);
4185
4186 return result;
4187 }
4188
4189 do_cleanups (back_to);
4190 return NULL;
4191 }
4192
4193 #endif /* HAVE_LIBEXPAT */
4194
4195 /* Returns the traceframe_info object for the current traceframe.
4196 This is where we avoid re-fetching the object from the target if we
4197 already have it cached. */
4198
4199 struct traceframe_info *
4200 get_traceframe_info (void)
4201 {
4202 if (traceframe_info == NULL)
4203 traceframe_info = target_traceframe_info ();
4204
4205 return traceframe_info;
4206 }
4207
4208 /* If the target supports the query, return in RESULT the set of
4209 collected memory in the current traceframe, found within the LEN
4210 bytes range starting at MEMADDR. Returns true if the target
4211 supports the query, otherwise returns false, and RESULT is left
4212 undefined. */
4213
4214 int
4215 traceframe_available_memory (VEC(mem_range_s) **result,
4216 CORE_ADDR memaddr, ULONGEST len)
4217 {
4218 struct traceframe_info *info = get_traceframe_info ();
4219
4220 if (info != NULL)
4221 {
4222 struct mem_range *r;
4223 int i;
4224
4225 *result = NULL;
4226
4227 for (i = 0; VEC_iterate (mem_range_s, info->memory, i, r); i++)
4228 if (mem_ranges_overlap (r->start, r->length, memaddr, len))
4229 {
4230 ULONGEST lo1, hi1, lo2, hi2;
4231 struct mem_range *nr;
4232
4233 lo1 = memaddr;
4234 hi1 = memaddr + len;
4235
4236 lo2 = r->start;
4237 hi2 = r->start + r->length;
4238
4239 nr = VEC_safe_push (mem_range_s, *result, NULL);
4240
4241 nr->start = std::max (lo1, lo2);
4242 nr->length = std::min (hi1, hi2) - nr->start;
4243 }
4244
4245 normalize_mem_ranges (*result);
4246 return 1;
4247 }
4248
4249 return 0;
4250 }
4251
4252 /* Implementation of `sdata' variable. */
4253
4254 static const struct internalvar_funcs sdata_funcs =
4255 {
4256 sdata_make_value,
4257 NULL,
4258 NULL
4259 };
4260
4261 /* module initialization */
4262 void
4263 _initialize_tracepoint (void)
4264 {
4265 struct cmd_list_element *c;
4266
4267 /* Explicitly create without lookup, since that tries to create a
4268 value with a void typed value, and when we get here, gdbarch
4269 isn't initialized yet. At this point, we're quite sure there
4270 isn't another convenience variable of the same name. */
4271 create_internalvar_type_lazy ("_sdata", &sdata_funcs, NULL);
4272
4273 traceframe_number = -1;
4274 tracepoint_number = -1;
4275
4276 add_info ("scope", scope_info,
4277 _("List the variables local to a scope"));
4278
4279 add_cmd ("tracepoints", class_trace, NULL,
4280 _("Tracing of program execution without stopping the program."),
4281 &cmdlist);
4282
4283 add_com ("tdump", class_trace, trace_dump_command,
4284 _("Print everything collected at the current tracepoint."));
4285
4286 c = add_com ("tvariable", class_trace, trace_variable_command,_("\
4287 Define a trace state variable.\n\
4288 Argument is a $-prefixed name, optionally followed\n\
4289 by '=' and an expression that sets the initial value\n\
4290 at the start of tracing."));
4291 set_cmd_completer (c, expression_completer);
4292
4293 add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\
4294 Delete one or more trace state variables.\n\
4295 Arguments are the names of the variables to delete.\n\
4296 If no arguments are supplied, delete all variables."), &deletelist);
4297 /* FIXME add a trace variable completer. */
4298
4299 add_info ("tvariables", tvariables_info, _("\
4300 Status of trace state variables and their values.\n\
4301 "));
4302
4303 add_info ("static-tracepoint-markers",
4304 info_static_tracepoint_markers_command, _("\
4305 List target static tracepoints markers.\n\
4306 "));
4307
4308 add_prefix_cmd ("tfind", class_trace, trace_find_command, _("\
4309 Select a trace frame;\n\
4310 No argument means forward by one frame; '-' means backward by one frame."),
4311 &tfindlist, "tfind ", 1, &cmdlist);
4312
4313 add_cmd ("outside", class_trace, trace_find_outside_command, _("\
4314 Select a trace frame whose PC is outside the given range (exclusive).\n\
4315 Usage: tfind outside addr1, addr2"),
4316 &tfindlist);
4317
4318 add_cmd ("range", class_trace, trace_find_range_command, _("\
4319 Select a trace frame whose PC is in the given range (inclusive).\n\
4320 Usage: tfind range addr1,addr2"),
4321 &tfindlist);
4322
4323 add_cmd ("line", class_trace, trace_find_line_command, _("\
4324 Select a trace frame by source line.\n\
4325 Argument can be a line number (with optional source file),\n\
4326 a function name, or '*' followed by an address.\n\
4327 Default argument is 'the next source line that was traced'."),
4328 &tfindlist);
4329
4330 add_cmd ("tracepoint", class_trace, trace_find_tracepoint_command, _("\
4331 Select a trace frame by tracepoint number.\n\
4332 Default is the tracepoint for the current trace frame."),
4333 &tfindlist);
4334
4335 add_cmd ("pc", class_trace, trace_find_pc_command, _("\
4336 Select a trace frame by PC.\n\
4337 Default is the current PC, or the PC of the current trace frame."),
4338 &tfindlist);
4339
4340 add_cmd ("end", class_trace, trace_find_end_command, _("\
4341 De-select any trace frame and resume 'live' debugging."),
4342 &tfindlist);
4343
4344 add_alias_cmd ("none", "end", class_trace, 0, &tfindlist);
4345
4346 add_cmd ("start", class_trace, trace_find_start_command,
4347 _("Select the first trace frame in the trace buffer."),
4348 &tfindlist);
4349
4350 add_com ("tstatus", class_trace, trace_status_command,
4351 _("Display the status of the current trace data collection."));
4352
4353 add_com ("tstop", class_trace, trace_stop_command, _("\
4354 Stop trace data collection.\n\
4355 Usage: tstop [ <notes> ... ]\n\
4356 Any arguments supplied are recorded with the trace as a stop reason and\n\
4357 reported by tstatus (if the target supports trace notes)."));
4358
4359 add_com ("tstart", class_trace, trace_start_command, _("\
4360 Start trace data collection.\n\
4361 Usage: tstart [ <notes> ... ]\n\
4362 Any arguments supplied are recorded with the trace as a note and\n\
4363 reported by tstatus (if the target supports trace notes)."));
4364
4365 add_com ("end", class_trace, end_actions_pseudocommand, _("\
4366 Ends a list of commands or actions.\n\
4367 Several GDB commands allow you to enter a list of commands or actions.\n\
4368 Entering \"end\" on a line by itself is the normal way to terminate\n\
4369 such a list.\n\n\
4370 Note: the \"end\" command cannot be used at the gdb prompt."));
4371
4372 add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\
4373 Specify single-stepping behavior at a tracepoint.\n\
4374 Argument is number of instructions to trace in single-step mode\n\
4375 following the tracepoint. This command is normally followed by\n\
4376 one or more \"collect\" commands, to specify what to collect\n\
4377 while single-stepping.\n\n\
4378 Note: this command can only be used in a tracepoint \"actions\" list."));
4379
4380 add_com_alias ("ws", "while-stepping", class_alias, 0);
4381 add_com_alias ("stepping", "while-stepping", class_alias, 0);
4382
4383 add_com ("collect", class_trace, collect_pseudocommand, _("\
4384 Specify one or more data items to be collected at a tracepoint.\n\
4385 Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4386 collect all data (variables, registers) referenced by that expression.\n\
4387 Also accepts the following special arguments:\n\
4388 $regs -- all registers.\n\
4389 $args -- all function arguments.\n\
4390 $locals -- all variables local to the block/function scope.\n\
4391 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
4392 Note: this command can only be used in a tracepoint \"actions\" list."));
4393
4394 add_com ("teval", class_trace, teval_pseudocommand, _("\
4395 Specify one or more expressions to be evaluated at a tracepoint.\n\
4396 Accepts a comma-separated list of (one or more) expressions.\n\
4397 The result of each evaluation will be discarded.\n\
4398 Note: this command can only be used in a tracepoint \"actions\" list."));
4399
4400 add_com ("actions", class_trace, trace_actions_command, _("\
4401 Specify the actions to be taken at a tracepoint.\n\
4402 Tracepoint actions may include collecting of specified data,\n\
4403 single-stepping, or enabling/disabling other tracepoints,\n\
4404 depending on target's capabilities."));
4405
4406 default_collect = xstrdup ("");
4407 add_setshow_string_cmd ("default-collect", class_trace,
4408 &default_collect, _("\
4409 Set the list of expressions to collect by default"), _("\
4410 Show the list of expressions to collect by default"), NULL,
4411 NULL, NULL,
4412 &setlist, &showlist);
4413
4414 add_setshow_boolean_cmd ("disconnected-tracing", no_class,
4415 &disconnected_tracing, _("\
4416 Set whether tracing continues after GDB disconnects."), _("\
4417 Show whether tracing continues after GDB disconnects."), _("\
4418 Use this to continue a tracing run even if GDB disconnects\n\
4419 or detaches from the target. You can reconnect later and look at\n\
4420 trace data collected in the meantime."),
4421 set_disconnected_tracing,
4422 NULL,
4423 &setlist,
4424 &showlist);
4425
4426 add_setshow_boolean_cmd ("circular-trace-buffer", no_class,
4427 &circular_trace_buffer, _("\
4428 Set target's use of circular trace buffer."), _("\
4429 Show target's use of circular trace buffer."), _("\
4430 Use this to make the trace buffer into a circular buffer,\n\
4431 which will discard traceframes (oldest first) instead of filling\n\
4432 up and stopping the trace run."),
4433 set_circular_trace_buffer,
4434 NULL,
4435 &setlist,
4436 &showlist);
4437
4438 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class,
4439 &trace_buffer_size, _("\
4440 Set requested size of trace buffer."), _("\
4441 Show requested size of trace buffer."), _("\
4442 Use this to choose a size for the trace buffer. Some targets\n\
4443 may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
4444 disables any attempt to set the buffer size and lets the target choose."),
4445 set_trace_buffer_size, NULL,
4446 &setlist, &showlist);
4447
4448 add_setshow_string_cmd ("trace-user", class_trace,
4449 &trace_user, _("\
4450 Set the user name to use for current and future trace runs"), _("\
4451 Show the user name to use for current and future trace runs"), NULL,
4452 set_trace_user, NULL,
4453 &setlist, &showlist);
4454
4455 add_setshow_string_cmd ("trace-notes", class_trace,
4456 &trace_notes, _("\
4457 Set notes string to use for current and future trace runs"), _("\
4458 Show the notes string to use for current and future trace runs"), NULL,
4459 set_trace_notes, NULL,
4460 &setlist, &showlist);
4461
4462 add_setshow_string_cmd ("trace-stop-notes", class_trace,
4463 &trace_stop_notes, _("\
4464 Set notes string to use for future tstop commands"), _("\
4465 Show the notes string to use for future tstop commands"), NULL,
4466 set_trace_stop_notes, NULL,
4467 &setlist, &showlist);
4468 }
This page took 0.149712 seconds and 5 git commands to generate.