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