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