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