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