Allocate cmd_list_element with new
[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
3ca73e0c
YQ
170static struct command_line *
171 all_tracepoint_actions_and_cleanup (struct breakpoint *t);
00bf0b85 172
00bf0b85
SS
173static struct trace_status trace_status;
174
7951c4eb 175const char *stop_reason_names[] = {
00bf0b85
SS
176 "tunknown",
177 "tnotrun",
178 "tstop",
179 "tfull",
180 "tdisconnected",
6c28cbf2
SS
181 "tpasscount",
182 "terror"
00bf0b85
SS
183};
184
185struct trace_status *
eeae04df 186current_trace_status (void)
00bf0b85
SS
187{
188 return &trace_status;
189}
190
7a9dd1b2 191/* Free and clear the traceframe info cache of the current
b3b9301e
PA
192 traceframe. */
193
194static void
195clear_traceframe_info (void)
196{
8d3c73ef 197 current_traceframe_info = NULL;
b3b9301e
PA
198}
199
c906108c
SS
200/* Set traceframe number to NUM. */
201static void
fba45db2 202set_traceframe_num (int num)
c906108c
SS
203{
204 traceframe_number = num;
4fa62494 205 set_internalvar_integer (lookup_internalvar ("trace_frame"), num);
c906108c
SS
206}
207
208/* Set tracepoint number to NUM. */
209static void
fba45db2 210set_tracepoint_num (int num)
c906108c
SS
211{
212 tracepoint_number = num;
4fa62494 213 set_internalvar_integer (lookup_internalvar ("tracepoint"), num);
c906108c
SS
214}
215
216/* Set externally visible debug variables for querying/printing
c378eb4e 217 the traceframe context (line, function, file). */
c906108c
SS
218
219static void
fb14de7b 220set_traceframe_context (struct frame_info *trace_frame)
c906108c 221{
fb14de7b 222 CORE_ADDR trace_pc;
24a00813 223 struct symbol *traceframe_fun;
51abb421 224 symtab_and_line traceframe_sal;
fb14de7b 225
dba09041
PA
226 /* Save as globals for internal use. */
227 if (trace_frame != NULL
228 && get_frame_pc_if_available (trace_frame, &trace_pc))
229 {
230 traceframe_sal = find_pc_line (trace_pc, 0);
231 traceframe_fun = find_pc_function (trace_pc);
232
233 /* Save linenumber as "$trace_line", a debugger variable visible to
234 users. */
235 set_internalvar_integer (lookup_internalvar ("trace_line"),
236 traceframe_sal.line);
237 }
238 else
c906108c 239 {
dba09041 240 traceframe_fun = NULL;
4fa62494 241 set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
c906108c
SS
242 }
243
d183932d
MS
244 /* Save func name as "$trace_func", a debugger variable visible to
245 users. */
4fa62494
UW
246 if (traceframe_fun == NULL
247 || SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
248 clear_internalvar (lookup_internalvar ("trace_func"));
c906108c 249 else
78267919
UW
250 set_internalvar_string (lookup_internalvar ("trace_func"),
251 SYMBOL_LINKAGE_NAME (traceframe_fun));
c906108c 252
d183932d
MS
253 /* Save file name as "$trace_file", a debugger variable visible to
254 users. */
4e04028d 255 if (traceframe_sal.symtab == NULL)
4fa62494 256 clear_internalvar (lookup_internalvar ("trace_file"));
c906108c 257 else
78267919 258 set_internalvar_string (lookup_internalvar ("trace_file"),
05cba821 259 symtab_to_filename_for_display (traceframe_sal.symtab));
c906108c
SS
260}
261
f61e138d
SS
262/* Create a new trace state variable with the given name. */
263
264struct trace_state_variable *
265create_trace_state_variable (const char *name)
266{
c252925c
SM
267 tvariables.emplace_back (name, next_tsv_number++);
268 return &tvariables.back ();
f61e138d
SS
269}
270
271/* Look for a trace state variable of the given name. */
272
273struct trace_state_variable *
274find_trace_state_variable (const char *name)
275{
c252925c
SM
276 for (trace_state_variable &tsv : tvariables)
277 if (tsv.name == name)
278 return &tsv;
f61e138d
SS
279
280 return NULL;
281}
282
dc673c81
YQ
283/* Look for a trace state variable of the given number. Return NULL if
284 not found. */
285
286struct trace_state_variable *
287find_trace_state_variable_by_number (int number)
288{
c252925c
SM
289 for (trace_state_variable &tsv : tvariables)
290 if (tsv.number == number)
291 return &tsv;
dc673c81
YQ
292
293 return NULL;
294}
295
70221824 296static void
f61e138d
SS
297delete_trace_state_variable (const char *name)
298{
c252925c
SM
299 for (auto it = tvariables.begin (); it != tvariables.end (); it++)
300 if (it->name == name)
f61e138d 301 {
c252925c
SM
302 gdb::observers::tsv_deleted.notify (&*it);
303 tvariables.erase (it);
f61e138d
SS
304 return;
305 }
306
307 warning (_("No trace variable named \"$%s\", not deleting"), name);
308}
309
1773c82c
HAQ
310/* Throws an error if NAME is not valid syntax for a trace state
311 variable's name. */
312
313void
314validate_trace_state_variable_name (const char *name)
315{
316 const char *p;
317
318 if (*name == '\0')
319 error (_("Must supply a non-empty variable name"));
320
321 /* All digits in the name is reserved for value history
322 references. */
323 for (p = name; isdigit (*p); p++)
324 ;
325 if (*p == '\0')
326 error (_("$%s is not a valid trace state variable name"), name);
327
328 for (p = name; isalnum (*p) || *p == '_'; p++)
329 ;
330 if (*p != '\0')
331 error (_("$%s is not a valid trace state variable name"), name);
332}
333
f61e138d
SS
334/* The 'tvariable' command collects a name and optional expression to
335 evaluate into an initial value. */
336
70221824 337static void
0b39b52e 338trace_variable_command (const char *args, int from_tty)
f61e138d 339{
f61e138d
SS
340 LONGEST initval = 0;
341 struct trace_state_variable *tsv;
0b39b52e 342 const char *name_start, *p;
f61e138d
SS
343
344 if (!args || !*args)
1773c82c
HAQ
345 error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
346
347 /* Only allow two syntaxes; "$name" and "$name=value". */
348 p = skip_spaces (args);
f61e138d 349
1773c82c
HAQ
350 if (*p++ != '$')
351 error (_("Name of trace variable should start with '$'"));
f61e138d 352
8abcee91 353 name_start = p;
1773c82c
HAQ
354 while (isalnum (*p) || *p == '_')
355 p++;
8abcee91 356 std::string name (name_start, p - name_start);
f61e138d 357
1773c82c
HAQ
358 p = skip_spaces (p);
359 if (*p != '=' && *p != '\0')
f61e138d
SS
360 error (_("Syntax must be $NAME [ = EXPR ]"));
361
8abcee91 362 validate_trace_state_variable_name (name.c_str ());
f61e138d 363
1773c82c
HAQ
364 if (*p == '=')
365 initval = value_as_long (parse_and_eval (++p));
f61e138d
SS
366
367 /* If the variable already exists, just change its initial value. */
8abcee91 368 tsv = find_trace_state_variable (name.c_str ());
f61e138d
SS
369 if (tsv)
370 {
134a2066
YQ
371 if (tsv->initial_value != initval)
372 {
373 tsv->initial_value = initval;
76727919 374 gdb::observers::tsv_modified.notify (tsv);
134a2066 375 }
3e43a32a
MS
376 printf_filtered (_("Trace state variable $%s "
377 "now has initial value %s.\n"),
c252925c 378 tsv->name.c_str (), plongest (tsv->initial_value));
f61e138d
SS
379 return;
380 }
381
382 /* Create a new variable. */
8abcee91 383 tsv = create_trace_state_variable (name.c_str ());
f61e138d
SS
384 tsv->initial_value = initval;
385
76727919 386 gdb::observers::tsv_created.notify (tsv);
bb25a15c 387
3e43a32a
MS
388 printf_filtered (_("Trace state variable $%s "
389 "created, with initial value %s.\n"),
c252925c 390 tsv->name.c_str (), plongest (tsv->initial_value));
f61e138d
SS
391}
392
70221824 393static void
2983f7cb 394delete_trace_variable_command (const char *args, int from_tty)
f61e138d 395{
f61e138d
SS
396 if (args == NULL)
397 {
398 if (query (_("Delete all trace state variables? ")))
c252925c 399 tvariables.clear ();
f61e138d 400 dont_repeat ();
76727919 401 gdb::observers::tsv_deleted.notify (NULL);
f61e138d
SS
402 return;
403 }
404
773a1edc 405 gdb_argv argv (args);
f61e138d 406
773a1edc 407 for (char *arg : argv)
f61e138d 408 {
773a1edc
TT
409 if (*arg == '$')
410 delete_trace_state_variable (arg + 1);
f61e138d 411 else
773a1edc 412 warning (_("Name \"%s\" not prefixed with '$', ignoring"), arg);
f61e138d
SS
413 }
414
f61e138d
SS
415 dont_repeat ();
416}
417
40e1c229
VP
418void
419tvariables_info_1 (void)
f61e138d 420{
79a45e25 421 struct ui_out *uiout = current_uiout;
f61e138d 422
35b1e5cc 423 /* Try to acquire values from the target. */
c252925c
SM
424 for (trace_state_variable &tsv : tvariables)
425 tsv.value_known
426 = target_get_trace_state_variable_value (tsv.number, &tsv.value);
35b1e5cc 427
f3c6abab
TT
428 {
429 ui_out_emit_table table_emitter (uiout, 3, tvariables.size (),
430 "trace-variables");
431 uiout->table_header (15, ui_left, "name", "Name");
432 uiout->table_header (11, ui_left, "initial", "Initial");
433 uiout->table_header (11, ui_left, "current", "Current");
40e1c229 434
f3c6abab 435 uiout->table_body ();
f61e138d 436
f3c6abab
TT
437 for (const trace_state_variable &tsv : tvariables)
438 {
439 const char *c;
440
441 ui_out_emit_tuple tuple_emitter (uiout, "variable");
442
443 uiout->field_string ("name", std::string ("$") + tsv.name);
444 uiout->field_string ("initial", plongest (tsv.initial_value));
445
446 if (tsv.value_known)
447 c = plongest (tsv.value);
448 else if (uiout->is_mi_like_p ())
449 /* For MI, we prefer not to use magic string constants, but rather
450 omit the field completely. The difference between unknown and
451 undefined does not seem important enough to represent. */
452 c = NULL;
453 else if (current_trace_status ()->running || traceframe_number >= 0)
454 /* The value is/was defined, but we don't have it. */
455 c = "<unknown>";
456 else
457 /* It is not meaningful to ask about the value. */
458 c = "<undefined>";
459 if (c)
460 uiout->field_string ("current", c);
461 uiout->text ("\n");
462 }
463 }
464
465 if (tvariables.empty ())
466 uiout->text (_("No trace state variables.\n"));
40e1c229
VP
467}
468
469/* List all the trace state variables. */
470
471static void
1d12d88f 472info_tvariables_command (const char *args, int from_tty)
40e1c229
VP
473{
474 tvariables_info_1 ();
f61e138d
SS
475}
476
8bf6485c
SS
477/* Stash definitions of tsvs into the given file. */
478
479void
480save_trace_state_variables (struct ui_file *fp)
481{
c252925c 482 for (const trace_state_variable &tsv : tvariables)
8bf6485c 483 {
c252925c
SM
484 fprintf_unfiltered (fp, "tvariable $%s", tsv.name.c_str ());
485 if (tsv.initial_value)
486 fprintf_unfiltered (fp, " = %s", plongest (tsv.initial_value));
8bf6485c
SS
487 fprintf_unfiltered (fp, "\n");
488 }
489}
490
c906108c
SS
491/* ACTIONS functions: */
492
c906108c 493/* The three functions:
c5aa993b
JM
494 collect_pseudocommand,
495 while_stepping_pseudocommand, and
496 end_actions_pseudocommand
c906108c
SS
497 are placeholders for "commands" that are actually ONLY to be used
498 within a tracepoint action list. If the actual function is ever called,
499 it means that somebody issued the "command" at the top level,
500 which is always an error. */
501
7b3ae3a6 502static void
0b39b52e 503end_actions_pseudocommand (const char *args, int from_tty)
c906108c 504{
8a3fe4f8 505 error (_("This command cannot be used at the top level."));
c906108c
SS
506}
507
7b3ae3a6 508static void
0b39b52e 509while_stepping_pseudocommand (const char *args, int from_tty)
c906108c 510{
8a3fe4f8 511 error (_("This command can only be used in a tracepoint actions list."));
c906108c
SS
512}
513
514static void
0b39b52e 515collect_pseudocommand (const char *args, int from_tty)
c906108c 516{
8a3fe4f8 517 error (_("This command can only be used in a tracepoint actions list."));
c906108c
SS
518}
519
6da95a67 520static void
0b39b52e 521teval_pseudocommand (const char *args, int from_tty)
6da95a67
SS
522{
523 error (_("This command can only be used in a tracepoint actions list."));
524}
525
3065dfb6
SS
526/* Parse any collection options, such as /s for strings. */
527
6f937416 528const char *
92bc6a20 529decode_agent_options (const char *exp, int *trace_string)
3065dfb6
SS
530{
531 struct value_print_options opts;
532
92bc6a20
TT
533 *trace_string = 0;
534
3065dfb6
SS
535 if (*exp != '/')
536 return exp;
537
538 /* Call this to borrow the print elements default for collection
539 size. */
540 get_user_print_options (&opts);
541
542 exp++;
543 if (*exp == 's')
544 {
545 if (target_supports_string_tracing ())
546 {
547 /* Allow an optional decimal number giving an explicit maximum
548 string length, defaulting it to the "print elements" value;
549 so "collect/s80 mystr" gets at most 80 bytes of string. */
92bc6a20 550 *trace_string = opts.print_max;
3065dfb6
SS
551 exp++;
552 if (*exp >= '0' && *exp <= '9')
92bc6a20 553 *trace_string = atoi (exp);
3065dfb6
SS
554 while (*exp >= '0' && *exp <= '9')
555 exp++;
556 }
557 else
558 error (_("Target does not support \"/s\" option for string tracing."));
559 }
560 else
561 error (_("Undefined collection format \"%c\"."), *exp);
562
f1735a53 563 exp = skip_spaces (exp);
3065dfb6
SS
564
565 return exp;
566}
567
c906108c
SS
568/* Enter a list of actions for a tracepoint. */
569static void
0b39b52e 570actions_command (const char *args, int from_tty)
c906108c 571{
d9b3f62e 572 struct tracepoint *t;
c906108c 573
5fa1d40e 574 t = get_tracepoint_by_number (&args, NULL);
7a292a7a 575 if (t)
c906108c 576 {
93921405
TT
577 std::string tmpbuf =
578 string_printf ("Enter actions for tracepoint %d, one per line.",
c1fc2657 579 t->number);
93921405
TT
580
581 command_line_up l = read_command_lines (&tmpbuf[0], from_tty, 1,
582 check_tracepoint_command, t);
c1fc2657 583 breakpoint_set_commands (t, std::move (l));
c906108c 584 }
5c44784c 585 /* else just return */
c906108c
SS
586}
587
fff87407
SS
588/* Report the results of checking the agent expression, as errors or
589 internal errors. */
590
591static void
35c9c7ba 592report_agent_reqs_errors (struct agent_expr *aexpr)
fff87407
SS
593{
594 /* All of the "flaws" are serious bytecode generation issues that
595 should never occur. */
35c9c7ba 596 if (aexpr->flaw != agent_flaw_none)
fff87407
SS
597 internal_error (__FILE__, __LINE__, _("expression is malformed"));
598
599 /* If analysis shows a stack underflow, GDB must have done something
600 badly wrong in its bytecode generation. */
35c9c7ba 601 if (aexpr->min_height < 0)
fff87407
SS
602 internal_error (__FILE__, __LINE__,
603 _("expression has min height < 0"));
604
605 /* Issue this error if the stack is predicted to get too deep. The
606 limit is rather arbitrary; a better scheme might be for the
607 target to report how much stack it will have available. The
608 depth roughly corresponds to parenthesization, so a limit of 20
609 amounts to 20 levels of expression nesting, which is actually
610 a pretty big hairy expression. */
35c9c7ba 611 if (aexpr->max_height > 20)
fff87407
SS
612 error (_("Expression is too complicated."));
613}
614
c906108c 615/* worker function */
fff87407 616void
6f937416 617validate_actionline (const char *line, struct breakpoint *b)
c906108c
SS
618{
619 struct cmd_list_element *c;
6f937416
PA
620 const char *tmp_p;
621 const char *p;
9355b391 622 struct bp_location *loc;
d9b3f62e 623 struct tracepoint *t = (struct tracepoint *) b;
c906108c 624
c378eb4e 625 /* If EOF is typed, *line is NULL. */
6f937416 626 if (line == NULL)
fff87407 627 return;
15255275 628
f1735a53 629 p = skip_spaces (line);
c906108c 630
d183932d
MS
631 /* Symbol lookup etc. */
632 if (*p == '\0') /* empty line: just prompt for another line. */
fff87407 633 return;
c906108c 634
c5aa993b 635 if (*p == '#') /* comment line */
fff87407 636 return;
c906108c
SS
637
638 c = lookup_cmd (&p, cmdlist, "", -1, 1);
639 if (c == 0)
fff87407 640 error (_("`%s' is not a tracepoint action, or is ambiguous."), p);
c5aa993b 641
bbaca940 642 if (cmd_cfunc_eq (c, collect_pseudocommand))
c906108c 643 {
92bc6a20
TT
644 int trace_string = 0;
645
3065dfb6 646 if (*p == '/')
92bc6a20 647 p = decode_agent_options (p, &trace_string);
3065dfb6 648
c5aa993b 649 do
c378eb4e
MS
650 { /* Repeat over a comma-separated list. */
651 QUIT; /* Allow user to bail out with ^C. */
f1735a53 652 p = skip_spaces (p);
c906108c 653
c378eb4e 654 if (*p == '$') /* Look for special pseudo-symbols. */
c5aa993b 655 {
0fb4aa4b
PA
656 if (0 == strncasecmp ("reg", p + 1, 3)
657 || 0 == strncasecmp ("arg", p + 1, 3)
658 || 0 == strncasecmp ("loc", p + 1, 3)
6710bf39 659 || 0 == strncasecmp ("_ret", p + 1, 4)
0fb4aa4b 660 || 0 == strncasecmp ("_sdata", p + 1, 6))
c5aa993b
JM
661 {
662 p = strchr (p, ',');
663 continue;
664 }
d183932d 665 /* else fall thru, treat p as an expression and parse it! */
c5aa993b 666 }
9355b391 667 tmp_p = p;
c1fc2657 668 for (loc = t->loc; loc; loc = loc->next)
c5aa993b 669 {
6f937416 670 p = tmp_p;
4d01a485
PA
671 expression_up exp = parse_exp_1 (&p, loc->address,
672 block_for_pc (loc->address), 1);
9355b391
SS
673
674 if (exp->elts[0].opcode == OP_VAR_VALUE)
c5aa993b 675 {
9355b391
SS
676 if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
677 {
12df843f 678 error (_("constant `%s' (value %s) "
3e43a32a 679 "will not be collected."),
fff87407 680 SYMBOL_PRINT_NAME (exp->elts[2].symbol),
12df843f 681 plongest (SYMBOL_VALUE (exp->elts[2].symbol)));
9355b391 682 }
3e43a32a
MS
683 else if (SYMBOL_CLASS (exp->elts[2].symbol)
684 == LOC_OPTIMIZED_OUT)
9355b391 685 {
3e43a32a
MS
686 error (_("`%s' is optimized away "
687 "and cannot be collected."),
fff87407 688 SYMBOL_PRINT_NAME (exp->elts[2].symbol));
9355b391 689 }
c5aa993b 690 }
c906108c 691
9355b391
SS
692 /* We have something to collect, make sure that the expr to
693 bytecode translator can handle it and that it's not too
694 long. */
833177a4
PA
695 agent_expr_up aexpr = gen_trace_for_expr (loc->address,
696 exp.get (),
697 trace_string);
c906108c 698
9355b391 699 if (aexpr->len > MAX_AGENT_EXPR_LEN)
fff87407 700 error (_("Expression is too complicated."));
c906108c 701
833177a4 702 ax_reqs (aexpr.get ());
c906108c 703
833177a4 704 report_agent_reqs_errors (aexpr.get ());
9355b391 705 }
c5aa993b
JM
706 }
707 while (p && *p++ == ',');
c906108c 708 }
fff87407 709
6da95a67
SS
710 else if (cmd_cfunc_eq (c, teval_pseudocommand))
711 {
6da95a67 712 do
c378eb4e
MS
713 { /* Repeat over a comma-separated list. */
714 QUIT; /* Allow user to bail out with ^C. */
f1735a53 715 p = skip_spaces (p);
6da95a67 716
9355b391 717 tmp_p = p;
c1fc2657 718 for (loc = t->loc; loc; loc = loc->next)
9355b391 719 {
6f937416 720 p = tmp_p;
bbc13ae3 721
9355b391 722 /* Only expressions are allowed for this action. */
4d01a485
PA
723 expression_up exp = parse_exp_1 (&p, loc->address,
724 block_for_pc (loc->address), 1);
6da95a67 725
9355b391
SS
726 /* We have something to evaluate, make sure that the expr to
727 bytecode translator can handle it and that it's not too
728 long. */
833177a4 729 agent_expr_up aexpr = gen_eval_for_expr (loc->address, exp.get ());
6da95a67 730
9355b391 731 if (aexpr->len > MAX_AGENT_EXPR_LEN)
fff87407
SS
732 error (_("Expression is too complicated."));
733
833177a4
PA
734 ax_reqs (aexpr.get ());
735 report_agent_reqs_errors (aexpr.get ());
9355b391 736 }
6da95a67
SS
737 }
738 while (p && *p++ == ',');
6da95a67 739 }
fff87407 740
bbaca940 741 else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
c906108c 742 {
6f937416 743 char *endp;
c906108c 744
f1735a53 745 p = skip_spaces (p);
6f937416
PA
746 t->step_count = strtol (p, &endp, 0);
747 if (endp == p || t->step_count == 0)
748 error (_("while-stepping step count `%s' is malformed."), line);
749 p = endp;
c906108c 750 }
fff87407 751
bbaca940 752 else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
fff87407
SS
753 ;
754
c906108c 755 else
6f937416 756 error (_("`%s' is not a supported tracepoint action."), line);
74b7792f
AC
757}
758
f50e79a4
JB
759enum {
760 memrange_absolute = -1
761};
762
c906108c
SS
763/* MEMRANGE functions: */
764
1f45808e 765/* Compare memranges for std::sort. */
c906108c 766
1f45808e
PA
767static bool
768memrange_comp (const memrange &a, const memrange &b)
c906108c 769{
1f45808e 770 if (a.type == b.type)
c906108c 771 {
1f45808e
PA
772 if (a.type == memrange_absolute)
773 return (bfd_vma) a.start < (bfd_vma) b.start;
774 else
775 return a.start < b.start;
c906108c 776 }
1f45808e
PA
777
778 return a.type < b.type;
c906108c
SS
779}
780
1f45808e
PA
781/* Sort the memrange list using std::sort, and merge adjacent memranges. */
782
c906108c 783static void
1f45808e 784memrange_sortmerge (std::vector<memrange> &memranges)
c906108c 785{
1f45808e 786 if (!memranges.empty ())
c906108c 787 {
1f45808e
PA
788 int a, b;
789
790 std::sort (memranges.begin (), memranges.end (), memrange_comp);
791
792 for (a = 0, b = 1; b < memranges.size (); b++)
c906108c 793 {
1b28d0b3
PA
794 /* If memrange b overlaps or is adjacent to memrange a,
795 merge them. */
1f45808e
PA
796 if (memranges[a].type == memranges[b].type
797 && memranges[b].start <= memranges[a].end)
c906108c 798 {
1f45808e
PA
799 if (memranges[b].end > memranges[a].end)
800 memranges[a].end = memranges[b].end;
c906108c
SS
801 continue; /* next b, same a */
802 }
803 a++; /* next a */
804 if (a != b)
1f45808e 805 memranges[a] = memranges[b];
c906108c 806 }
1f45808e 807 memranges.resize (a + 1);
c906108c
SS
808 }
809}
810
d183932d 811/* Add a register to a collection list. */
1f45808e
PA
812
813void
814collection_list::add_register (unsigned int regno)
c906108c
SS
815{
816 if (info_verbose)
817 printf_filtered ("collect register %d\n", regno);
1f45808e 818 if (regno >= (8 * sizeof (m_regs_mask)))
8a3fe4f8 819 error (_("Internal: register number %d too large for tracepoint"),
c906108c 820 regno);
1f45808e 821 m_regs_mask[regno / 8] |= 1 << (regno % 8);
c906108c
SS
822}
823
c378eb4e 824/* Add a memrange to a collection list. */
1f45808e
PA
825
826void
19f1935d
PA
827collection_list::add_memrange (struct gdbarch *gdbarch,
828 int type, bfd_signed_vma base,
1f45808e 829 unsigned long len)
c906108c
SS
830{
831 if (info_verbose)
19f1935d 832 printf_filtered ("(%d,%s,%ld)\n", type, paddress (gdbarch, base), len);
104c1213 833
f50e79a4 834 /* type: memrange_absolute == memory, other n == basereg */
d183932d 835 /* base: addr if memory, offset if reg relative. */
c906108c 836 /* len: we actually save end (base + len) for convenience */
7a63494a 837 m_memranges.emplace_back (type, base, base + len);
c906108c 838
3e43a32a 839 if (type != memrange_absolute) /* Better collect the base register! */
1f45808e 840 add_register (type);
c906108c
SS
841}
842
d183932d 843/* Add a symbol to a collection list. */
1f45808e
PA
844
845void
846collection_list::collect_symbol (struct symbol *sym,
847 struct gdbarch *gdbarch,
848 long frame_regno, long frame_offset,
849 CORE_ADDR scope,
850 int trace_string)
c906108c 851{
c5aa993b 852 unsigned long len;
104c1213 853 unsigned int reg;
c906108c 854 bfd_signed_vma offset;
400c6af0 855 int treat_as_expr = 0;
c906108c 856
c5aa993b
JM
857 len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
858 switch (SYMBOL_CLASS (sym))
859 {
860 default:
861 printf_filtered ("%s: don't know symbol class %d\n",
3567439c 862 SYMBOL_PRINT_NAME (sym),
d183932d 863 SYMBOL_CLASS (sym));
c5aa993b
JM
864 break;
865 case LOC_CONST:
12df843f
JK
866 printf_filtered ("constant %s (value %s) will not be collected.\n",
867 SYMBOL_PRINT_NAME (sym), plongest (SYMBOL_VALUE (sym)));
c5aa993b
JM
868 break;
869 case LOC_STATIC:
870 offset = SYMBOL_VALUE_ADDRESS (sym);
871 if (info_verbose)
104c1213 872 {
104c1213 873 printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
3567439c 874 SYMBOL_PRINT_NAME (sym), len,
19f1935d 875 paddress (gdbarch, offset));
104c1213 876 }
400c6af0
SS
877 /* A struct may be a C++ class with static fields, go to general
878 expression handling. */
879 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
880 treat_as_expr = 1;
881 else
19f1935d 882 add_memrange (gdbarch, memrange_absolute, offset, len);
c5aa993b
JM
883 break;
884 case LOC_REGISTER:
a6d9a66e 885 reg = SYMBOL_REGISTER_OPS (sym)->register_number (sym, gdbarch);
c5aa993b 886 if (info_verbose)
d183932d 887 printf_filtered ("LOC_REG[parm] %s: ",
3567439c 888 SYMBOL_PRINT_NAME (sym));
1f45808e 889 add_register (reg);
d183932d
MS
890 /* Check for doubles stored in two registers. */
891 /* FIXME: how about larger types stored in 3 or more regs? */
c5aa993b 892 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FLT &&
a6d9a66e 893 len > register_size (gdbarch, reg))
1f45808e 894 add_register (reg + 1);
c5aa993b
JM
895 break;
896 case LOC_REF_ARG:
897 printf_filtered ("Sorry, don't know how to do LOC_REF_ARG yet.\n");
898 printf_filtered (" (will not collect %s)\n",
3567439c 899 SYMBOL_PRINT_NAME (sym));
c5aa993b
JM
900 break;
901 case LOC_ARG:
902 reg = frame_regno;
903 offset = frame_offset + SYMBOL_VALUE (sym);
904 if (info_verbose)
905 {
19f1935d
PA
906 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
907 " from frame ptr reg %d\n",
908 SYMBOL_PRINT_NAME (sym), len,
909 paddress (gdbarch, offset), reg);
c5aa993b 910 }
19f1935d 911 add_memrange (gdbarch, reg, offset, len);
c5aa993b
JM
912 break;
913 case LOC_REGPARM_ADDR:
914 reg = SYMBOL_VALUE (sym);
915 offset = 0;
916 if (info_verbose)
917 {
19f1935d
PA
918 printf_filtered ("LOC_REGPARM_ADDR %s: Collect %ld bytes at offset %s"
919 " from reg %d\n",
920 SYMBOL_PRINT_NAME (sym), len,
921 paddress (gdbarch, offset), reg);
c5aa993b 922 }
19f1935d 923 add_memrange (gdbarch, reg, offset, len);
c5aa993b
JM
924 break;
925 case LOC_LOCAL:
c5aa993b
JM
926 reg = frame_regno;
927 offset = frame_offset + SYMBOL_VALUE (sym);
928 if (info_verbose)
929 {
19f1935d
PA
930 printf_filtered ("LOC_LOCAL %s: Collect %ld bytes at offset %s"
931 " from frame ptr reg %d\n",
932 SYMBOL_PRINT_NAME (sym), len,
933 paddress (gdbarch, offset), reg);
c5aa993b 934 }
19f1935d 935 add_memrange (gdbarch, reg, offset, len);
c5aa993b 936 break;
a0405854 937
c5aa993b 938 case LOC_UNRESOLVED:
a0405854 939 treat_as_expr = 1;
c5aa993b 940 break;
a0405854 941
c5aa993b 942 case LOC_OPTIMIZED_OUT:
8e1a459b 943 printf_filtered ("%s has been optimized out of existence.\n",
3567439c 944 SYMBOL_PRINT_NAME (sym));
c5aa993b 945 break;
0936ad1d
SS
946
947 case LOC_COMPUTED:
400c6af0 948 treat_as_expr = 1;
0936ad1d 949 break;
c5aa993b 950 }
400c6af0
SS
951
952 /* Expressions are the most general case. */
953 if (treat_as_expr)
954 {
833177a4
PA
955 agent_expr_up aexpr = gen_trace_for_var (scope, gdbarch,
956 sym, trace_string);
400c6af0
SS
957
958 /* It can happen that the symbol is recorded as a computed
959 location, but it's been optimized away and doesn't actually
960 have a location expression. */
961 if (!aexpr)
962 {
963 printf_filtered ("%s has been optimized out of existence.\n",
964 SYMBOL_PRINT_NAME (sym));
965 return;
966 }
967
833177a4 968 ax_reqs (aexpr.get ());
fff87407 969
833177a4 970 report_agent_reqs_errors (aexpr.get ());
400c6af0 971
c378eb4e 972 /* Take care of the registers. */
35c9c7ba 973 if (aexpr->reg_mask_len > 0)
400c6af0 974 {
833177a4 975 for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
400c6af0 976 {
c378eb4e 977 QUIT; /* Allow user to bail out with ^C. */
35c9c7ba 978 if (aexpr->reg_mask[ndx1] != 0)
400c6af0 979 {
c378eb4e 980 /* Assume chars have 8 bits. */
833177a4 981 for (int ndx2 = 0; ndx2 < 8; ndx2++)
35c9c7ba 982 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
c378eb4e 983 /* It's used -- record it. */
1f45808e 984 add_register (ndx1 * 8 + ndx2);
400c6af0
SS
985 }
986 }
987 }
833177a4 988
6c73cd95 989 add_aexpr (std::move (aexpr));
400c6af0 990 }
c906108c
SS
991}
992
2c58c0a9
PA
993/* Data to be passed around in the calls to the locals and args
994 iterators. */
995
996struct add_local_symbols_data
997{
998 struct collection_list *collect;
999 struct gdbarch *gdbarch;
1000 CORE_ADDR pc;
1001 long frame_regno;
1002 long frame_offset;
1003 int count;
92bc6a20 1004 int trace_string;
2c58c0a9
PA
1005};
1006
c378eb4e 1007/* The callback for the locals and args iterators. */
2c58c0a9
PA
1008
1009static void
1010do_collect_symbol (const char *print_name,
1011 struct symbol *sym,
1012 void *cb_data)
1013{
19ba03f4 1014 struct add_local_symbols_data *p = (struct add_local_symbols_data *) cb_data;
2c58c0a9 1015
1f45808e
PA
1016 p->collect->collect_symbol (sym, p->gdbarch, p->frame_regno,
1017 p->frame_offset, p->pc, p->trace_string);
2c58c0a9 1018 p->count++;
dc673c81 1019
1f45808e
PA
1020 p->collect->add_wholly_collected (print_name);
1021}
1022
1023void
1024collection_list::add_wholly_collected (const char *print_name)
1025{
1026 m_wholly_collected.push_back (print_name);
2c58c0a9
PA
1027}
1028
c378eb4e 1029/* Add all locals (or args) symbols to collection list. */
1f45808e
PA
1030
1031void
1032collection_list::add_local_symbols (struct gdbarch *gdbarch, CORE_ADDR pc,
1033 long frame_regno, long frame_offset, int type,
1034 int trace_string)
c906108c 1035{
3977b71f 1036 const struct block *block;
2c58c0a9
PA
1037 struct add_local_symbols_data cb_data;
1038
1f45808e 1039 cb_data.collect = this;
2c58c0a9
PA
1040 cb_data.gdbarch = gdbarch;
1041 cb_data.pc = pc;
1042 cb_data.frame_regno = frame_regno;
1043 cb_data.frame_offset = frame_offset;
1044 cb_data.count = 0;
92bc6a20 1045 cb_data.trace_string = trace_string;
c906108c 1046
2c58c0a9 1047 if (type == 'L')
c906108c 1048 {
2c58c0a9
PA
1049 block = block_for_pc (pc);
1050 if (block == NULL)
c906108c 1051 {
2c58c0a9
PA
1052 warning (_("Can't collect locals; "
1053 "no symbol table info available.\n"));
1054 return;
c906108c 1055 }
2c58c0a9
PA
1056
1057 iterate_over_block_local_vars (block, do_collect_symbol, &cb_data);
1058 if (cb_data.count == 0)
1059 warning (_("No locals found in scope."));
1060 }
1061 else
1062 {
1063 pc = get_pc_function_start (pc);
1064 block = block_for_pc (pc);
1065 if (block == NULL)
1066 {
b37520b6 1067 warning (_("Can't collect args; no symbol table info available."));
2c58c0a9
PA
1068 return;
1069 }
1070
1071 iterate_over_block_arg_vars (block, do_collect_symbol, &cb_data);
1072 if (cb_data.count == 0)
1073 warning (_("No args found in scope."));
c906108c 1074 }
c906108c
SS
1075}
1076
1f45808e
PA
1077void
1078collection_list::add_static_trace_data ()
0fb4aa4b
PA
1079{
1080 if (info_verbose)
1081 printf_filtered ("collect static trace data\n");
1f45808e 1082 m_strace_data = true;
cbfa3b61
YQ
1083}
1084
1f45808e
PA
1085collection_list::collection_list ()
1086 : m_regs_mask (),
1087 m_strace_data (false)
cbfa3b61 1088{
1f45808e
PA
1089 m_memranges.reserve (128);
1090 m_aexprs.reserve (128);
cbfa3b61
YQ
1091}
1092
c378eb4e 1093/* Reduce a collection list to string form (for gdb protocol). */
1f45808e 1094
b44ec619 1095std::vector<std::string>
1f45808e 1096collection_list::stringify ()
c906108c
SS
1097{
1098 char temp_buf[2048];
1099 int count;
c906108c 1100 char *end;
c5aa993b 1101 long i;
b44ec619 1102 std::vector<std::string> str_list;
c906108c 1103
1f45808e 1104 if (m_strace_data)
0fb4aa4b
PA
1105 {
1106 if (info_verbose)
1107 printf_filtered ("\nCollecting static trace data\n");
1108 end = temp_buf;
1109 *end++ = 'L';
b44ec619 1110 str_list.emplace_back (temp_buf, end - temp_buf);
0fb4aa4b
PA
1111 }
1112
1f45808e
PA
1113 for (i = sizeof (m_regs_mask) - 1; i > 0; i--)
1114 if (m_regs_mask[i] != 0) /* Skip leading zeroes in regs_mask. */
c906108c 1115 break;
1f45808e 1116 if (m_regs_mask[i] != 0) /* Prepare to send regs_mask to the stub. */
c906108c
SS
1117 {
1118 if (info_verbose)
1119 printf_filtered ("\nCollecting registers (mask): 0x");
1120 end = temp_buf;
c5aa993b 1121 *end++ = 'R';
c906108c
SS
1122 for (; i >= 0; i--)
1123 {
c378eb4e 1124 QUIT; /* Allow user to bail out with ^C. */
c906108c 1125 if (info_verbose)
1f45808e
PA
1126 printf_filtered ("%02X", m_regs_mask[i]);
1127 sprintf (end, "%02X", m_regs_mask[i]);
c906108c
SS
1128 end += 2;
1129 }
b44ec619 1130 str_list.emplace_back (temp_buf);
c906108c
SS
1131 }
1132 if (info_verbose)
1133 printf_filtered ("\n");
1f45808e 1134 if (!m_memranges.empty () && info_verbose)
c906108c 1135 printf_filtered ("Collecting memranges: \n");
1f45808e 1136 for (i = 0, count = 0, end = temp_buf; i < m_memranges.size (); i++)
c906108c 1137 {
c378eb4e 1138 QUIT; /* Allow user to bail out with ^C. */
c906108c 1139 if (info_verbose)
104c1213
JM
1140 {
1141 printf_filtered ("(%d, %s, %ld)\n",
1f45808e 1142 m_memranges[i].type,
19f1935d
PA
1143 paddress (target_gdbarch (),
1144 m_memranges[i].start),
1f45808e
PA
1145 (long) (m_memranges[i].end
1146 - m_memranges[i].start));
104c1213 1147 }
c906108c
SS
1148 if (count + 27 > MAX_AGENT_EXPR_LEN)
1149 {
b44ec619 1150 str_list.emplace_back (temp_buf, count);
c906108c
SS
1151 count = 0;
1152 end = temp_buf;
1153 }
104c1213 1154
d1948716 1155 {
1f45808e
PA
1156 bfd_signed_vma length
1157 = m_memranges[i].end - m_memranges[i].start;
d1948716
JB
1158
1159 /* The "%X" conversion specifier expects an unsigned argument,
f50e79a4
JB
1160 so passing -1 (memrange_absolute) to it directly gives you
1161 "FFFFFFFF" (or more, depending on sizeof (unsigned)).
1162 Special-case it. */
1f45808e 1163 if (m_memranges[i].type == memrange_absolute)
19f1935d
PA
1164 sprintf (end, "M-1,%s,%lX", phex_nz (m_memranges[i].start, 0),
1165 (long) length);
d1948716 1166 else
19f1935d
PA
1167 sprintf (end, "M%X,%s,%lX", m_memranges[i].type,
1168 phex_nz (m_memranges[i].start, 0), (long) length);
d1948716 1169 }
104c1213 1170
c906108c 1171 count += strlen (end);
3ffbc0a5 1172 end = temp_buf + count;
c906108c
SS
1173 }
1174
1f45808e 1175 for (i = 0; i < m_aexprs.size (); i++)
c906108c 1176 {
c378eb4e 1177 QUIT; /* Allow user to bail out with ^C. */
1f45808e 1178 if ((count + 10 + 2 * m_aexprs[i]->len) > MAX_AGENT_EXPR_LEN)
c906108c 1179 {
b44ec619 1180 str_list.emplace_back (temp_buf, count);
c906108c
SS
1181 count = 0;
1182 end = temp_buf;
1183 }
1f45808e 1184 sprintf (end, "X%08X,", m_aexprs[i]->len);
c906108c
SS
1185 end += 10; /* 'X' + 8 hex digits + ',' */
1186 count += 10;
1187
1f45808e
PA
1188 end = mem2hex (m_aexprs[i]->buf, end, m_aexprs[i]->len);
1189 count += 2 * m_aexprs[i]->len;
c906108c
SS
1190 }
1191
1192 if (count != 0)
1193 {
b44ec619 1194 str_list.emplace_back (temp_buf, count);
c906108c
SS
1195 count = 0;
1196 end = temp_buf;
1197 }
c906108c 1198
b44ec619 1199 return str_list;
c906108c
SS
1200}
1201
dc673c81
YQ
1202/* Add the printed expression EXP to *LIST. */
1203
1f45808e
PA
1204void
1205collection_list::append_exp (struct expression *exp)
dc673c81 1206{
d7e74731 1207 string_file tmp_stream;
dc673c81 1208
d7e74731 1209 print_expression (exp, &tmp_stream);
dc673c81 1210
d7e74731 1211 m_computed.push_back (std::move (tmp_stream.string ()));
dc673c81 1212}
a7bdde9e 1213
1f45808e
PA
1214void
1215collection_list::finish ()
1216{
1217 memrange_sortmerge (m_memranges);
1218}
1219
a7bdde9e
VP
1220static void
1221encode_actions_1 (struct command_line *action,
a7bdde9e
VP
1222 struct bp_location *tloc,
1223 int frame_reg,
1224 LONGEST frame_offset,
1225 struct collection_list *collect,
1226 struct collection_list *stepping_list)
c906108c 1227{
6f937416 1228 const char *action_exp;
104c1213 1229 int i;
f976f6d4 1230 struct value *tempval;
c906108c 1231 struct cmd_list_element *cmd;
236f1d4d
SS
1232
1233 for (; action; action = action->next)
c906108c 1234 {
c378eb4e 1235 QUIT; /* Allow user to bail out with ^C. */
a7bdde9e 1236 action_exp = action->line;
f1735a53 1237 action_exp = skip_spaces (action_exp);
c906108c 1238
c906108c
SS
1239 cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
1240 if (cmd == 0)
8a3fe4f8 1241 error (_("Bad action list item: %s"), action_exp);
c906108c 1242
bbaca940 1243 if (cmd_cfunc_eq (cmd, collect_pseudocommand))
c906108c 1244 {
92bc6a20
TT
1245 int trace_string = 0;
1246
3065dfb6 1247 if (*action_exp == '/')
92bc6a20 1248 action_exp = decode_agent_options (action_exp, &trace_string);
3065dfb6 1249
c5aa993b 1250 do
c378eb4e
MS
1251 { /* Repeat over a comma-separated list. */
1252 QUIT; /* Allow user to bail out with ^C. */
f1735a53 1253 action_exp = skip_spaces (action_exp);
c906108c 1254
c5aa993b
JM
1255 if (0 == strncasecmp ("$reg", action_exp, 4))
1256 {
82e9becd 1257 for (i = 0; i < gdbarch_num_regs (target_gdbarch ()); i++)
1f45808e 1258 collect->add_register (i);
c5aa993b
JM
1259 action_exp = strchr (action_exp, ','); /* more? */
1260 }
1261 else if (0 == strncasecmp ("$arg", action_exp, 4))
1262 {
1f45808e
PA
1263 collect->add_local_symbols (target_gdbarch (),
1264 tloc->address,
1265 frame_reg,
1266 frame_offset,
1267 'A',
1268 trace_string);
c5aa993b
JM
1269 action_exp = strchr (action_exp, ','); /* more? */
1270 }
1271 else if (0 == strncasecmp ("$loc", action_exp, 4))
1272 {
1f45808e
PA
1273 collect->add_local_symbols (target_gdbarch (),
1274 tloc->address,
1275 frame_reg,
1276 frame_offset,
1277 'L',
1278 trace_string);
c5aa993b
JM
1279 action_exp = strchr (action_exp, ','); /* more? */
1280 }
6710bf39
SS
1281 else if (0 == strncasecmp ("$_ret", action_exp, 5))
1282 {
833177a4
PA
1283 agent_expr_up aexpr
1284 = gen_trace_for_return_address (tloc->address,
1285 target_gdbarch (),
1286 trace_string);
6710bf39 1287
833177a4
PA
1288 ax_reqs (aexpr.get ());
1289 report_agent_reqs_errors (aexpr.get ());
6710bf39
SS
1290
1291 /* take care of the registers */
1292 if (aexpr->reg_mask_len > 0)
1293 {
833177a4 1294 for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
6710bf39
SS
1295 {
1296 QUIT; /* allow user to bail out with ^C */
1297 if (aexpr->reg_mask[ndx1] != 0)
1298 {
1299 /* assume chars have 8 bits */
833177a4 1300 for (int ndx2 = 0; ndx2 < 8; ndx2++)
6710bf39 1301 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1f45808e
PA
1302 {
1303 /* It's used -- record it. */
1304 collect->add_register (ndx1 * 8 + ndx2);
1305 }
6710bf39
SS
1306 }
1307 }
1308 }
1309
6c73cd95 1310 collect->add_aexpr (std::move (aexpr));
6710bf39
SS
1311 action_exp = strchr (action_exp, ','); /* more? */
1312 }
0fb4aa4b
PA
1313 else if (0 == strncasecmp ("$_sdata", action_exp, 7))
1314 {
1f45808e 1315 collect->add_static_trace_data ();
0fb4aa4b
PA
1316 action_exp = strchr (action_exp, ','); /* more? */
1317 }
c5aa993b
JM
1318 else
1319 {
744a8059 1320 unsigned long addr;
c5aa993b 1321
4d01a485
PA
1322 expression_up exp = parse_exp_1 (&action_exp, tloc->address,
1323 block_for_pc (tloc->address),
1324 1);
c906108c 1325
c5aa993b
JM
1326 switch (exp->elts[0].opcode)
1327 {
1328 case OP_REGISTER:
67f3407f
DJ
1329 {
1330 const char *name = &exp->elts[2].string;
1331
82e9becd 1332 i = user_reg_map_name_to_regnum (target_gdbarch (),
029a67e4 1333 name, strlen (name));
67f3407f
DJ
1334 if (i == -1)
1335 internal_error (__FILE__, __LINE__,
1336 _("Register $%s not available"),
1337 name);
1338 if (info_verbose)
1339 printf_filtered ("OP_REGISTER: ");
1f45808e 1340 collect->add_register (i);
67f3407f
DJ
1341 break;
1342 }
c5aa993b
JM
1343
1344 case UNOP_MEMVAL:
c378eb4e 1345 /* Safe because we know it's a simple expression. */
4d01a485 1346 tempval = evaluate_expression (exp.get ());
42ae5230 1347 addr = value_address (tempval);
744a8059
SP
1348 /* Initialize the TYPE_LENGTH if it is a typedef. */
1349 check_typedef (exp->elts[1].type);
19f1935d
PA
1350 collect->add_memrange (target_gdbarch (),
1351 memrange_absolute, addr,
1f45808e
PA
1352 TYPE_LENGTH (exp->elts[1].type));
1353 collect->append_exp (exp.get ());
c5aa993b
JM
1354 break;
1355
1356 case OP_VAR_VALUE:
dc673c81
YQ
1357 {
1358 struct symbol *sym = exp->elts[2].symbol;
ec1f2d91 1359 const char *name = SYMBOL_NATURAL_NAME (sym);
dc673c81 1360
1f45808e
PA
1361 collect->collect_symbol (exp->elts[2].symbol,
1362 target_gdbarch (),
1363 frame_reg,
1364 frame_offset,
1365 tloc->address,
1366 trace_string);
1367 collect->add_wholly_collected (name);
dc673c81 1368 }
c5aa993b
JM
1369 break;
1370
c378eb4e 1371 default: /* Full-fledged expression. */
833177a4
PA
1372 agent_expr_up aexpr = gen_trace_for_expr (tloc->address,
1373 exp.get (),
1374 trace_string);
c5aa993b 1375
833177a4 1376 ax_reqs (aexpr.get ());
c5aa993b 1377
833177a4 1378 report_agent_reqs_errors (aexpr.get ());
c5aa993b 1379
c378eb4e 1380 /* Take care of the registers. */
35c9c7ba 1381 if (aexpr->reg_mask_len > 0)
c906108c 1382 {
833177a4 1383 for (int ndx1 = 0; ndx1 < aexpr->reg_mask_len; ndx1++)
c906108c 1384 {
c378eb4e 1385 QUIT; /* Allow user to bail out with ^C. */
35c9c7ba 1386 if (aexpr->reg_mask[ndx1] != 0)
c5aa993b 1387 {
c378eb4e 1388 /* Assume chars have 8 bits. */
833177a4 1389 for (int ndx2 = 0; ndx2 < 8; ndx2++)
35c9c7ba 1390 if (aexpr->reg_mask[ndx1] & (1 << ndx2))
1f45808e
PA
1391 {
1392 /* It's used -- record it. */
1393 collect->add_register (ndx1 * 8 + ndx2);
1394 }
c5aa993b 1395 }
c906108c
SS
1396 }
1397 }
dc673c81 1398
6c73cd95 1399 collect->add_aexpr (std::move (aexpr));
1f45808e 1400 collect->append_exp (exp.get ());
c5aa993b
JM
1401 break;
1402 } /* switch */
c5aa993b
JM
1403 } /* do */
1404 }
1405 while (action_exp && *action_exp++ == ',');
1406 } /* if */
6da95a67
SS
1407 else if (cmd_cfunc_eq (cmd, teval_pseudocommand))
1408 {
1409 do
c378eb4e
MS
1410 { /* Repeat over a comma-separated list. */
1411 QUIT; /* Allow user to bail out with ^C. */
f1735a53 1412 action_exp = skip_spaces (action_exp);
6da95a67
SS
1413
1414 {
4d01a485
PA
1415 expression_up exp = parse_exp_1 (&action_exp, tloc->address,
1416 block_for_pc (tloc->address),
1417 1);
6da95a67 1418
833177a4
PA
1419 agent_expr_up aexpr = gen_eval_for_expr (tloc->address,
1420 exp.get ());
6da95a67 1421
833177a4
PA
1422 ax_reqs (aexpr.get ());
1423 report_agent_reqs_errors (aexpr.get ());
6da95a67 1424
6da95a67
SS
1425 /* Even though we're not officially collecting, add
1426 to the collect list anyway. */
6c73cd95 1427 collect->add_aexpr (std::move (aexpr));
6da95a67
SS
1428 } /* do */
1429 }
1430 while (action_exp && *action_exp++ == ',');
1431 } /* if */
bbaca940 1432 else if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand))
c906108c 1433 {
a7bdde9e
VP
1434 /* We check against nested while-stepping when setting
1435 breakpoint action, so no way to run into nested
1436 here. */
1437 gdb_assert (stepping_list);
1438
23da373a 1439 encode_actions_1 (action->body_list[0], tloc, frame_reg,
2a2287c7 1440 frame_offset, stepping_list, NULL);
c906108c 1441 }
a7bdde9e
VP
1442 else
1443 error (_("Invalid tracepoint command '%s'"), action->line);
1444 } /* for */
1445}
1446
dc673c81 1447/* Encode actions of tracepoint TLOC->owner and fill TRACEPOINT_LIST
1f45808e 1448 and STEPPING_LIST. */
5fbce5df 1449
1f45808e
PA
1450void
1451encode_actions (struct bp_location *tloc,
1452 struct collection_list *tracepoint_list,
1453 struct collection_list *stepping_list)
a7bdde9e 1454{
a7bdde9e 1455 struct command_line *actions;
a7bdde9e
VP
1456 int frame_reg;
1457 LONGEST frame_offset;
cbfa3b61 1458
3e05895e
TT
1459 gdbarch_virtual_frame_pointer (tloc->gdbarch,
1460 tloc->address, &frame_reg, &frame_offset);
a7bdde9e 1461
3ca73e0c 1462 actions = all_tracepoint_actions_and_cleanup (tloc->owner);
a7bdde9e 1463
23da373a 1464 encode_actions_1 (actions, tloc, frame_reg, frame_offset,
dc673c81
YQ
1465 tracepoint_list, stepping_list);
1466
1f45808e
PA
1467 tracepoint_list->finish ();
1468 stepping_list->finish ();
dc673c81
YQ
1469}
1470
1471/* Render all actions into gdb protocol. */
1472
1473void
b44ec619
SM
1474encode_actions_rsp (struct bp_location *tloc,
1475 std::vector<std::string> *tdp_actions,
1476 std::vector<std::string> *stepping_actions)
dc673c81
YQ
1477{
1478 struct collection_list tracepoint_list, stepping_list;
a7bdde9e 1479
1f45808e 1480 encode_actions (tloc, &tracepoint_list, &stepping_list);
236f1d4d 1481
1f45808e
PA
1482 *tdp_actions = tracepoint_list.stringify ();
1483 *stepping_actions = stepping_list.stringify ();
c906108c
SS
1484}
1485
1f45808e 1486void
833177a4 1487collection_list::add_aexpr (agent_expr_up aexpr)
c906108c 1488{
6c73cd95 1489 m_aexprs.push_back (std::move (aexpr));
c906108c
SS
1490}
1491
bfccc43c
YQ
1492static void
1493process_tracepoint_on_disconnect (void)
1494{
1495 VEC(breakpoint_p) *tp_vec = NULL;
1496 int ix;
1497 struct breakpoint *b;
1498 int has_pending_p = 0;
1499
1500 /* Check whether we still have pending tracepoint. If we have, warn the
1501 user that pending tracepoint will no longer work. */
1502 tp_vec = all_tracepoints ();
1503 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
1504 {
1505 if (b->loc == NULL)
1506 {
1507 has_pending_p = 1;
1508 break;
1509 }
1510 else
1511 {
1512 struct bp_location *loc1;
1513
1514 for (loc1 = b->loc; loc1; loc1 = loc1->next)
1515 {
1516 if (loc1->shlib_disabled)
1517 {
1518 has_pending_p = 1;
1519 break;
1520 }
1521 }
1522
1523 if (has_pending_p)
1524 break;
1525 }
1526 }
1527 VEC_free (breakpoint_p, tp_vec);
1528
1529 if (has_pending_p)
1530 warning (_("Pending tracepoints will not be resolved while"
1531 " GDB is disconnected\n"));
1532}
1533
aef525cb
YQ
1534/* Reset local state of tracing. */
1535
1536void
1537trace_reset_local_state (void)
1538{
1539 set_traceframe_num (-1);
1540 set_tracepoint_num (-1);
1541 set_traceframe_context (NULL);
1542 clear_traceframe_info ();
1543}
c5aa993b 1544
f224b49d 1545void
0b39b52e 1546start_tracing (const char *notes)
d183932d 1547{
1042e4c0
SS
1548 VEC(breakpoint_p) *tp_vec = NULL;
1549 int ix;
d9b3f62e 1550 struct breakpoint *b;
f61e138d 1551 struct trace_state_variable *tsv;
d914c394 1552 int any_enabled = 0, num_to_download = 0;
f196051f
SS
1553 int ret;
1554
35b1e5cc 1555 tp_vec = all_tracepoints ();
76a2b958 1556
c378eb4e 1557 /* No point in tracing without any tracepoints... */
76a2b958
SS
1558 if (VEC_length (breakpoint_p, tp_vec) == 0)
1559 {
1560 VEC_free (breakpoint_p, tp_vec);
1561 error (_("No tracepoints defined, not starting trace"));
1562 }
1563
d9b3f62e 1564 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
76a2b958 1565 {
d9b3f62e 1566 if (b->enable_state == bp_enabled)
d914c394
SS
1567 any_enabled = 1;
1568
d9b3f62e 1569 if ((b->type == bp_fast_tracepoint
d914c394
SS
1570 ? may_insert_fast_tracepoints
1571 : may_insert_tracepoints))
1572 ++num_to_download;
1573 else
1574 warning (_("May not insert %stracepoints, skipping tracepoint %d"),
d9b3f62e 1575 (b->type == bp_fast_tracepoint ? "fast " : ""), b->number);
76a2b958
SS
1576 }
1577
76a2b958
SS
1578 if (!any_enabled)
1579 {
d248b706
KY
1580 if (target_supports_enable_disable_tracepoint ())
1581 warning (_("No tracepoints enabled"));
1582 else
1583 {
1584 /* No point in tracing with only disabled tracepoints that
1585 cannot be re-enabled. */
1586 VEC_free (breakpoint_p, tp_vec);
1587 error (_("No tracepoints enabled, not starting trace"));
1588 }
76a2b958
SS
1589 }
1590
d914c394
SS
1591 if (num_to_download <= 0)
1592 {
1593 VEC_free (breakpoint_p, tp_vec);
1594 error (_("No tracepoints that may be downloaded, not starting trace"));
1595 }
1596
76a2b958
SS
1597 target_trace_init ();
1598
d9b3f62e 1599 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
7a697b8d 1600 {
d9b3f62e 1601 struct tracepoint *t = (struct tracepoint *) b;
e8ba3115 1602 struct bp_location *loc;
f2a8bc8a 1603 int bp_location_downloaded = 0;
d9b3f62e 1604
4511b1ba
YQ
1605 /* Clear `inserted' flag. */
1606 for (loc = b->loc; loc; loc = loc->next)
1607 loc->inserted = 0;
1608
d9b3f62e 1609 if ((b->type == bp_fast_tracepoint
d914c394
SS
1610 ? !may_insert_fast_tracepoints
1611 : !may_insert_tracepoints))
1612 continue;
1613
35b1e5cc 1614 t->number_on_target = 0;
e8ba3115
YQ
1615
1616 for (loc = b->loc; loc; loc = loc->next)
1e4d1764
YQ
1617 {
1618 /* Since tracepoint locations are never duplicated, `inserted'
1619 flag should be zero. */
1620 gdb_assert (!loc->inserted);
1621
1622 target_download_tracepoint (loc);
1623
1624 loc->inserted = 1;
f2a8bc8a 1625 bp_location_downloaded = 1;
1e4d1764 1626 }
e8ba3115 1627
d9b3f62e 1628 t->number_on_target = b->number;
55aa24fb
SDJ
1629
1630 for (loc = b->loc; loc; loc = loc->next)
935676c9
SDJ
1631 if (loc->probe.prob != NULL)
1632 loc->probe.prob->set_semaphore (loc->probe.objfile,
1633 loc->gdbarch);
f2a8bc8a
YQ
1634
1635 if (bp_location_downloaded)
76727919 1636 gdb::observers::breakpoint_modified.notify (b);
7a697b8d 1637 }
35b1e5cc 1638 VEC_free (breakpoint_p, tp_vec);
76a2b958 1639
00bf0b85 1640 /* Send down all the trace state variables too. */
c252925c
SM
1641 for (const trace_state_variable &tsv : tvariables)
1642 target_download_trace_state_variable (tsv);
35b1e5cc
SS
1643
1644 /* Tell target to treat text-like sections as transparent. */
1645 target_trace_set_readonly_regions ();
4daf5ac0
SS
1646 /* Set some mode flags. */
1647 target_set_disconnected_tracing (disconnected_tracing);
1648 target_set_circular_trace_buffer (circular_trace_buffer);
f6f899bf 1649 target_set_trace_buffer_size (trace_buffer_size);
1042e4c0 1650
f196051f
SS
1651 if (!notes)
1652 notes = trace_notes;
1653 ret = target_set_trace_notes (trace_user, notes, NULL);
1654
1655 if (!ret && (trace_user || notes))
43011e52 1656 warning (_("Target does not support trace user/notes, info ignored"));
f196051f 1657
35b1e5cc
SS
1658 /* Now insert traps and begin collecting data. */
1659 target_trace_start ();
1042e4c0 1660
35b1e5cc 1661 /* Reset our local state. */
aef525cb 1662 trace_reset_local_state ();
00bf0b85 1663 current_trace_status()->running = 1;
1042e4c0
SS
1664}
1665
f196051f
SS
1666/* The tstart command requests the target to start a new trace run.
1667 The command passes any arguments it has to the target verbatim, as
1668 an optional "trace note". This is useful as for instance a warning
1669 to other users if the trace runs disconnected, and you don't want
1670 anybody else messing with the target. */
f224b49d
VP
1671
1672static void
0b39b52e 1673tstart_command (const char *args, int from_tty)
f224b49d
VP
1674{
1675 dont_repeat (); /* Like "run", dangerous to repeat accidentally. */
1676
615bcdef
SS
1677 if (current_trace_status ()->running)
1678 {
1679 if (from_tty
1680 && !query (_("A trace is running already. Start a new run? ")))
1681 error (_("New trace run not started."));
1682 }
1683
f196051f 1684 start_tracing (args);
f224b49d
VP
1685}
1686
f196051f
SS
1687/* The tstop command stops the tracing run. The command passes any
1688 supplied arguments to the target verbatim as a "stop note"; if the
1689 target supports trace notes, then it will be reported back as part
1690 of the trace run's status. */
1691
c906108c 1692static void
0b39b52e 1693tstop_command (const char *args, int from_tty)
d183932d 1694{
615bcdef
SS
1695 if (!current_trace_status ()->running)
1696 error (_("Trace is not running."));
1697
f196051f 1698 stop_tracing (args);
c906108c
SS
1699}
1700
d5551862 1701void
0b39b52e 1702stop_tracing (const char *note)
d5551862 1703{
f196051f 1704 int ret;
55aa24fb
SDJ
1705 VEC(breakpoint_p) *tp_vec = NULL;
1706 int ix;
1707 struct breakpoint *t;
f196051f 1708
35b1e5cc 1709 target_trace_stop ();
f196051f 1710
55aa24fb
SDJ
1711 tp_vec = all_tracepoints ();
1712 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
1713 {
1714 struct bp_location *loc;
1715
1716 if ((t->type == bp_fast_tracepoint
1717 ? !may_insert_fast_tracepoints
1718 : !may_insert_tracepoints))
1719 continue;
1720
1721 for (loc = t->loc; loc; loc = loc->next)
1722 {
1723 /* GDB can be totally absent in some disconnected trace scenarios,
1724 but we don't really care if this semaphore goes out of sync.
1725 That's why we are decrementing it here, but not taking care
1726 in other places. */
935676c9
SDJ
1727 if (loc->probe.prob != NULL)
1728 loc->probe.prob->clear_semaphore (loc->probe.objfile,
1729 loc->gdbarch);
55aa24fb
SDJ
1730 }
1731 }
1732
1733 VEC_free (breakpoint_p, tp_vec);
1734
f196051f
SS
1735 if (!note)
1736 note = trace_stop_notes;
1737 ret = target_set_trace_notes (NULL, NULL, note);
1738
1739 if (!ret && note)
43011e52 1740 warning (_("Target does not support trace notes, note ignored"));
f196051f 1741
c378eb4e 1742 /* Should change in response to reply? */
00bf0b85 1743 current_trace_status ()->running = 0;
d5551862
SS
1744}
1745
c906108c
SS
1746/* tstatus command */
1747static void
0b39b52e 1748tstatus_command (const char *args, int from_tty)
d183932d 1749{
00bf0b85 1750 struct trace_status *ts = current_trace_status ();
f196051f
SS
1751 int status, ix;
1752 VEC(breakpoint_p) *tp_vec = NULL;
1753 struct breakpoint *t;
35b1e5cc 1754
00bf0b85
SS
1755 status = target_get_trace_status (ts);
1756
1757 if (status == -1)
1758 {
f5911ea1 1759 if (ts->filename != NULL)
00bf0b85
SS
1760 printf_filtered (_("Using a trace file.\n"));
1761 else
1762 {
1763 printf_filtered (_("Trace can not be run on this target.\n"));
1764 return;
1765 }
1766 }
1767
1768 if (!ts->running_known)
1769 {
1770 printf_filtered (_("Run/stop status is unknown.\n"));
1771 }
1772 else if (ts->running)
c906108c 1773 {
35b1e5cc 1774 printf_filtered (_("Trace is running on the target.\n"));
c906108c
SS
1775 }
1776 else
00bf0b85
SS
1777 {
1778 switch (ts->stop_reason)
1779 {
1780 case trace_never_run:
1781 printf_filtered (_("No trace has been run on the target.\n"));
1782 break;
e5a873b7 1783 case trace_stop_command:
f196051f
SS
1784 if (ts->stop_desc)
1785 printf_filtered (_("Trace stopped by a tstop command (%s).\n"),
1786 ts->stop_desc);
1787 else
1788 printf_filtered (_("Trace stopped by a tstop command.\n"));
00bf0b85
SS
1789 break;
1790 case trace_buffer_full:
1791 printf_filtered (_("Trace stopped because the buffer was full.\n"));
1792 break;
1793 case trace_disconnected:
1794 printf_filtered (_("Trace stopped because of disconnection.\n"));
1795 break;
1796 case tracepoint_passcount:
00bf0b85
SS
1797 printf_filtered (_("Trace stopped by tracepoint %d.\n"),
1798 ts->stopping_tracepoint);
1799 break;
6c28cbf2
SS
1800 case tracepoint_error:
1801 if (ts->stopping_tracepoint)
3e43a32a
MS
1802 printf_filtered (_("Trace stopped by an "
1803 "error (%s, tracepoint %d).\n"),
f196051f 1804 ts->stop_desc, ts->stopping_tracepoint);
6c28cbf2
SS
1805 else
1806 printf_filtered (_("Trace stopped by an error (%s).\n"),
f196051f 1807 ts->stop_desc);
6c28cbf2 1808 break;
00bf0b85
SS
1809 case trace_stop_reason_unknown:
1810 printf_filtered (_("Trace stopped for an unknown reason.\n"));
1811 break;
1812 default:
1813 printf_filtered (_("Trace stopped for some other reason (%d).\n"),
1814 ts->stop_reason);
1815 break;
1816 }
1817 }
1818
4daf5ac0
SS
1819 if (ts->traceframes_created >= 0
1820 && ts->traceframe_count != ts->traceframes_created)
1821 {
3e43a32a
MS
1822 printf_filtered (_("Buffer contains %d trace "
1823 "frames (of %d created total).\n"),
4daf5ac0
SS
1824 ts->traceframe_count, ts->traceframes_created);
1825 }
1826 else if (ts->traceframe_count >= 0)
00bf0b85
SS
1827 {
1828 printf_filtered (_("Collected %d trace frames.\n"),
1829 ts->traceframe_count);
1830 }
1831
4daf5ac0 1832 if (ts->buffer_free >= 0)
00bf0b85 1833 {
4daf5ac0
SS
1834 if (ts->buffer_size >= 0)
1835 {
1836 printf_filtered (_("Trace buffer has %d bytes of %d bytes free"),
1837 ts->buffer_free, ts->buffer_size);
1838 if (ts->buffer_size > 0)
1839 printf_filtered (_(" (%d%% full)"),
1840 ((int) ((((long long) (ts->buffer_size
1841 - ts->buffer_free)) * 100)
1842 / ts->buffer_size)));
1843 printf_filtered (_(".\n"));
1844 }
1845 else
1846 printf_filtered (_("Trace buffer has %d bytes free.\n"),
1847 ts->buffer_free);
00bf0b85 1848 }
35b1e5cc 1849
33da3f1c
SS
1850 if (ts->disconnected_tracing)
1851 printf_filtered (_("Trace will continue if GDB disconnects.\n"));
1852 else
1853 printf_filtered (_("Trace will stop if GDB disconnects.\n"));
1854
1855 if (ts->circular_buffer)
1856 printf_filtered (_("Trace buffer is circular.\n"));
1857
f196051f
SS
1858 if (ts->user_name && strlen (ts->user_name) > 0)
1859 printf_filtered (_("Trace user is %s.\n"), ts->user_name);
1860
1861 if (ts->notes && strlen (ts->notes) > 0)
1862 printf_filtered (_("Trace notes: %s.\n"), ts->notes);
1863
00bf0b85 1864 /* Now report on what we're doing with tfind. */
35b1e5cc
SS
1865 if (traceframe_number >= 0)
1866 printf_filtered (_("Looking at trace frame %d, tracepoint %d.\n"),
1867 traceframe_number, tracepoint_number);
1868 else
1869 printf_filtered (_("Not looking at any trace frame.\n"));
f196051f
SS
1870
1871 /* Report start/stop times if supplied. */
1872 if (ts->start_time)
1873 {
1874 if (ts->stop_time)
1875 {
1876 LONGEST run_time = ts->stop_time - ts->start_time;
1877
1878 /* Reporting a run time is more readable than two long numbers. */
1879 printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
f30aa5af
DK
1880 (long int) (ts->start_time / 1000000),
1881 (long int) (ts->start_time % 1000000),
1882 (long int) (run_time / 1000000),
1883 (long int) (run_time % 1000000));
f196051f
SS
1884 }
1885 else
1886 printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
f30aa5af
DK
1887 (long int) (ts->start_time / 1000000),
1888 (long int) (ts->start_time % 1000000));
f196051f
SS
1889 }
1890 else if (ts->stop_time)
1891 printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
f30aa5af
DK
1892 (long int) (ts->stop_time / 1000000),
1893 (long int) (ts->stop_time % 1000000));
f196051f
SS
1894
1895 /* Now report any per-tracepoint status available. */
1896 tp_vec = all_tracepoints ();
1897
1898 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, t); ix++)
1899 target_get_tracepoint_status (t, NULL);
1900
1901 VEC_free (breakpoint_p, tp_vec);
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
PA
2664 {
2665 int i;
2666
2667 for (i = 0; i < action->body_count; ++i)
2668 trace_dump_actions (action->body_list[i],
2669 1, stepping_frame, from_tty);
2670 }
bbaca940 2671 else if (cmd_cfunc_eq (cmd, collect_pseudocommand))
c906108c
SS
2672 {
2673 /* Display the collected data.
d183932d
MS
2674 For the trap frame, display only what was collected at
2675 the trap. Likewise for stepping frames, display only
2676 what was collected while stepping. This means that the
2677 two boolean variables, STEPPING_FRAME and
2678 STEPPING_ACTIONS should be equal. */
c906108c
SS
2679 if (stepping_frame == stepping_actions)
2680 {
6f937416
PA
2681 char *cmd = NULL;
2682 struct cleanup *old_chain
2683 = make_cleanup (free_current_contents, &cmd);
92bc6a20 2684 int trace_string = 0;
6f937416 2685
3065dfb6 2686 if (*action_exp == '/')
92bc6a20 2687 action_exp = decode_agent_options (action_exp, &trace_string);
3065dfb6 2688
c5aa993b 2689 do
c378eb4e
MS
2690 { /* Repeat over a comma-separated list. */
2691 QUIT; /* Allow user to bail out with ^C. */
c5aa993b
JM
2692 if (*action_exp == ',')
2693 action_exp++;
f1735a53 2694 action_exp = skip_spaces (action_exp);
c5aa993b
JM
2695
2696 next_comma = strchr (action_exp, ',');
2697
2698 if (0 == strncasecmp (action_exp, "$reg", 4))
2699 registers_info (NULL, from_tty);
6710bf39
SS
2700 else if (0 == strncasecmp (action_exp, "$_ret", 5))
2701 ;
c5aa993b 2702 else if (0 == strncasecmp (action_exp, "$loc", 4))
11db9430 2703 info_locals_command (NULL, from_tty);
c5aa993b 2704 else if (0 == strncasecmp (action_exp, "$arg", 4))
11db9430 2705 info_args_command (NULL, from_tty);
c5aa993b
JM
2706 else
2707 { /* variable */
6f937416 2708 if (next_comma != NULL)
c5aa993b 2709 {
6f937416
PA
2710 size_t len = next_comma - action_exp;
2711
224c3ddb 2712 cmd = (char *) xrealloc (cmd, len + 1);
6f937416
PA
2713 memcpy (cmd, action_exp, len);
2714 cmd[len] = 0;
2715 }
2716 else
2717 {
2718 size_t len = strlen (action_exp);
2719
224c3ddb 2720 cmd = (char *) xrealloc (cmd, len + 1);
6f937416 2721 memcpy (cmd, action_exp, len + 1);
c5aa993b 2722 }
6f937416
PA
2723
2724 printf_filtered ("%s = ", cmd);
2725 output_command_const (cmd, from_tty);
c5aa993b
JM
2726 printf_filtered ("\n");
2727 }
c5aa993b
JM
2728 action_exp = next_comma;
2729 }
2730 while (action_exp && *action_exp == ',');
6f937416
PA
2731
2732 do_cleanups (old_chain);
c906108c
SS
2733 }
2734 }
2735 }
afd02f27
PA
2736}
2737
ddacd3c8
YQ
2738/* Return bp_location of the tracepoint associated with the current
2739 traceframe. Set *STEPPING_FRAME_P to 1 if the current traceframe
2740 is a stepping traceframe. */
2741
dc673c81 2742struct bp_location *
ddacd3c8
YQ
2743get_traceframe_location (int *stepping_frame_p)
2744{
2745 struct tracepoint *t;
2746 struct bp_location *tloc;
2747 struct regcache *regcache;
2748
2749 if (tracepoint_number == -1)
2750 error (_("No current trace frame."));
2751
2752 t = get_tracepoint (tracepoint_number);
2753
2754 if (t == NULL)
2755 error (_("No known tracepoint matches 'current' tracepoint #%d."),
2756 tracepoint_number);
2757
2758 /* The current frame is a trap frame if the frame PC is equal to the
2759 tracepoint PC. If not, then the current frame was collected
2760 during single-stepping. */
2761 regcache = get_current_regcache ();
2762
2763 /* If the traceframe's address matches any of the tracepoint's
2764 locations, assume it is a direct hit rather than a while-stepping
2765 frame. (FIXME this is not reliable, should record each frame's
2766 type.) */
c1fc2657 2767 for (tloc = t->loc; tloc; tloc = tloc->next)
ddacd3c8
YQ
2768 if (tloc->address == regcache_read_pc (regcache))
2769 {
2770 *stepping_frame_p = 0;
2771 return tloc;
2772 }
2773
2774 /* If this is a stepping frame, we don't know which location
2775 triggered. The first is as good (or bad) a guess as any... */
2776 *stepping_frame_p = 1;
c1fc2657 2777 return t->loc;
ddacd3c8
YQ
2778}
2779
3ca73e0c
YQ
2780/* Return all the actions, including default collect, of a tracepoint
2781 T. It constructs cleanups into the chain, and leaves the caller to
2782 handle them (call do_cleanups). */
2783
2784static struct command_line *
2785all_tracepoint_actions_and_cleanup (struct breakpoint *t)
2786{
2787 struct command_line *actions;
2788
2789 actions = breakpoint_commands (t);
2790
2791 /* If there are default expressions to collect, make up a collect
2792 action and prepend to the action list to encode. Note that since
2793 validation is per-tracepoint (local var "xyz" might be valid for
2794 one tracepoint and not another, etc), we make up the action on
2795 the fly, and don't cache it. */
2796 if (*default_collect)
2797 {
2798 struct command_line *default_collect_action;
2799 char *default_collect_line;
2800
2801 default_collect_line = xstrprintf ("collect %s", default_collect);
2802 make_cleanup (xfree, default_collect_line);
2803
2804 validate_actionline (default_collect_line, t);
8d749320 2805 default_collect_action = XNEW (struct command_line);
3ca73e0c
YQ
2806 make_cleanup (xfree, default_collect_action);
2807 default_collect_action->next = actions;
2808 default_collect_action->line = default_collect_line;
2809 actions = default_collect_action;
2810 }
2811
2812 return actions;
2813}
2814
afd02f27
PA
2815/* The tdump command. */
2816
2817static void
0b39b52e 2818tdump_command (const char *args, int from_tty)
afd02f27 2819{
afd02f27
PA
2820 int stepping_frame = 0;
2821 struct bp_location *loc;
ddacd3c8 2822 struct command_line *actions;
afd02f27 2823
ddacd3c8
YQ
2824 /* This throws an error is not inspecting a trace frame. */
2825 loc = get_traceframe_location (&stepping_frame);
afd02f27
PA
2826
2827 printf_filtered ("Data collected at tracepoint %d, trace frame %d:\n",
2828 tracepoint_number, traceframe_number);
2829
de74e63a
YQ
2830 /* This command only makes sense for the current frame, not the
2831 selected frame. */
5ed8105e
PA
2832 scoped_restore_current_thread restore_thread;
2833
de74e63a
YQ
2834 select_frame (get_current_frame ());
2835
ddacd3c8 2836 actions = all_tracepoint_actions_and_cleanup (loc->owner);
2114d44c
SS
2837
2838 trace_dump_actions (actions, 0, stepping_frame, from_tty);
c906108c
SS
2839}
2840
409873ef
SS
2841/* Encode a piece of a tracepoint's source-level definition in a form
2842 that is suitable for both protocol and saving in files. */
2843/* This version does not do multiple encodes for long strings; it should
2844 return an offset to the next piece to encode. FIXME */
2845
a121b7c1 2846int
409873ef 2847encode_source_string (int tpnum, ULONGEST addr,
a121b7c1
PA
2848 const char *srctype, const char *src,
2849 char *buf, int buf_size)
409873ef
SS
2850{
2851 if (80 + strlen (srctype) > buf_size)
2852 error (_("Buffer too small for source encoding"));
2853 sprintf (buf, "%x:%s:%s:%x:%x:",
3e43a32a
MS
2854 tpnum, phex_nz (addr, sizeof (addr)),
2855 srctype, 0, (int) strlen (src));
409873ef
SS
2856 if (strlen (buf) + strlen (src) * 2 >= buf_size)
2857 error (_("Source string too long for buffer"));
9f1b45b0 2858 bin2hex ((gdb_byte *) src, buf + strlen (buf), strlen (src));
409873ef
SS
2859 return -1;
2860}
2861
d5551862
SS
2862/* Tell the target what to do with an ongoing tracing run if GDB
2863 disconnects for some reason. */
2864
d5551862 2865static void
eb4c3f4a 2866set_disconnected_tracing (const char *args, int from_tty,
d5551862
SS
2867 struct cmd_list_element *c)
2868{
f196051f 2869 target_set_disconnected_tracing (disconnected_tracing);
d5551862
SS
2870}
2871
4daf5ac0 2872static void
eb4c3f4a 2873set_circular_trace_buffer (const char *args, int from_tty,
4daf5ac0
SS
2874 struct cmd_list_element *c)
2875{
2876 target_set_circular_trace_buffer (circular_trace_buffer);
2877}
2878
f6f899bf 2879static void
eb4c3f4a 2880set_trace_buffer_size (const char *args, int from_tty,
f6f899bf
HAQ
2881 struct cmd_list_element *c)
2882{
2883 target_set_trace_buffer_size (trace_buffer_size);
2884}
2885
f196051f 2886static void
eb4c3f4a 2887set_trace_user (const char *args, int from_tty,
f196051f
SS
2888 struct cmd_list_element *c)
2889{
2890 int ret;
2891
2892 ret = target_set_trace_notes (trace_user, NULL, NULL);
2893
2894 if (!ret)
43011e52 2895 warning (_("Target does not support trace notes, user ignored"));
f196051f
SS
2896}
2897
2898static void
eb4c3f4a 2899set_trace_notes (const char *args, int from_tty,
f196051f
SS
2900 struct cmd_list_element *c)
2901{
2902 int ret;
2903
2904 ret = target_set_trace_notes (NULL, trace_notes, NULL);
2905
2906 if (!ret)
43011e52 2907 warning (_("Target does not support trace notes, note ignored"));
f196051f
SS
2908}
2909
2910static void
eb4c3f4a 2911set_trace_stop_notes (const char *args, int from_tty,
f196051f
SS
2912 struct cmd_list_element *c)
2913{
2914 int ret;
2915
2916 ret = target_set_trace_notes (NULL, NULL, trace_stop_notes);
2917
2918 if (!ret)
43011e52 2919 warning (_("Target does not support trace notes, stop note ignored"));
f196051f
SS
2920}
2921
c906108c
SS
2922/* Convert the memory pointed to by mem into hex, placing result in buf.
2923 * Return a pointer to the last char put in buf (null)
2924 * "stolen" from sparc-stub.c
2925 */
2926
c5aa993b 2927static const char hexchars[] = "0123456789abcdef";
c906108c 2928
47b667de
AC
2929static char *
2930mem2hex (gdb_byte *mem, char *buf, int count)
c906108c 2931{
47b667de 2932 gdb_byte ch;
c906108c
SS
2933
2934 while (count-- > 0)
2935 {
2936 ch = *mem++;
2937
2938 *buf++ = hexchars[ch >> 4];
2939 *buf++ = hexchars[ch & 0xf];
2940 }
2941
2942 *buf = 0;
2943
2944 return buf;
2945}
2946
c5aa993b 2947int
fba45db2 2948get_traceframe_number (void)
c906108c 2949{
c5aa993b 2950 return traceframe_number;
c906108c
SS
2951}
2952
393fd4c3
YQ
2953int
2954get_tracepoint_number (void)
2955{
2956 return tracepoint_number;
2957}
2958
06cd862c
PA
2959/* Make the traceframe NUM be the current trace frame. Does nothing
2960 if NUM is already current. */
2961
2962void
e6e4e701 2963set_current_traceframe (int num)
06cd862c
PA
2964{
2965 int newnum;
2966
2967 if (traceframe_number == num)
2968 {
2969 /* Nothing to do. */
2970 return;
2971 }
2972
2973 newnum = target_trace_find (tfind_number, num, 0, 0, NULL);
2974
2975 if (newnum != num)
2976 warning (_("could not change traceframe"));
2977
8d735b87 2978 set_traceframe_num (newnum);
06cd862c
PA
2979
2980 /* Changing the traceframe changes our view of registers and of the
2981 frame chain. */
2982 registers_changed ();
b3b9301e
PA
2983
2984 clear_traceframe_info ();
06cd862c
PA
2985}
2986
6f14adc5
SM
2987scoped_restore_current_traceframe::scoped_restore_current_traceframe ()
2988: m_traceframe_number (traceframe_number)
2989{}
00bf0b85
SS
2990
2991/* Given a number and address, return an uploaded tracepoint with that
2992 number, creating if necessary. */
2993
2994struct uploaded_tp *
2995get_uploaded_tp (int num, ULONGEST addr, struct uploaded_tp **utpp)
2996{
2997 struct uploaded_tp *utp;
2998
2999 for (utp = *utpp; utp; utp = utp->next)
3000 if (utp->number == num && utp->addr == addr)
3001 return utp;
8d749320 3002
a18ba4e4 3003 utp = new uploaded_tp;
00bf0b85
SS
3004 utp->number = num;
3005 utp->addr = addr;
3006 utp->next = *utpp;
3007 *utpp = utp;
8d749320 3008
00bf0b85
SS
3009 return utp;
3010}
3011
7951c4eb 3012void
00bf0b85
SS
3013free_uploaded_tps (struct uploaded_tp **utpp)
3014{
3015 struct uploaded_tp *next_one;
3016
3017 while (*utpp)
3018 {
3019 next_one = (*utpp)->next;
a18ba4e4 3020 delete *utpp;
00bf0b85
SS
3021 *utpp = next_one;
3022 }
3023}
3024
3025/* Given a number and address, return an uploaded tracepoint with that
3026 number, creating if necessary. */
3027
393fd4c3 3028struct uploaded_tsv *
00bf0b85
SS
3029get_uploaded_tsv (int num, struct uploaded_tsv **utsvp)
3030{
3031 struct uploaded_tsv *utsv;
3032
3033 for (utsv = *utsvp; utsv; utsv = utsv->next)
3034 if (utsv->number == num)
3035 return utsv;
8d749320
SM
3036
3037 utsv = XCNEW (struct uploaded_tsv);
00bf0b85
SS
3038 utsv->number = num;
3039 utsv->next = *utsvp;
3040 *utsvp = utsv;
8d749320 3041
00bf0b85
SS
3042 return utsv;
3043}
3044
7951c4eb 3045void
00bf0b85
SS
3046free_uploaded_tsvs (struct uploaded_tsv **utsvp)
3047{
3048 struct uploaded_tsv *next_one;
3049
3050 while (*utsvp)
3051 {
3052 next_one = (*utsvp)->next;
3053 xfree (*utsvp);
3054 *utsvp = next_one;
3055 }
3056}
3057
4e5c165d
HZ
3058/* FIXME this function is heuristic and will miss the cases where the
3059 conditional is semantically identical but differs in whitespace,
3060 such as "x == 0" vs "x==0". */
3061
3062static int
3063cond_string_is_same (char *str1, char *str2)
3064{
3065 if (str1 == NULL || str2 == NULL)
3066 return (str1 == str2);
3067
3068 return (strcmp (str1, str2) == 0);
3069}
3070
00bf0b85
SS
3071/* Look for an existing tracepoint that seems similar enough to the
3072 uploaded one. Enablement isn't compared, because the user can
3073 toggle that freely, and may have done so in anticipation of the
1e4d1764 3074 next trace run. Return the location of matched tracepoint. */
00bf0b85 3075
70221824 3076static struct bp_location *
1e4d1764 3077find_matching_tracepoint_location (struct uploaded_tp *utp)
00bf0b85
SS
3078{
3079 VEC(breakpoint_p) *tp_vec = all_tracepoints ();
3080 int ix;
d9b3f62e 3081 struct breakpoint *b;
00bf0b85
SS
3082 struct bp_location *loc;
3083
d9b3f62e 3084 for (ix = 0; VEC_iterate (breakpoint_p, tp_vec, ix, b); ix++)
00bf0b85 3085 {
d9b3f62e
PA
3086 struct tracepoint *t = (struct tracepoint *) b;
3087
3088 if (b->type == utp->type
00bf0b85
SS
3089 && t->step_count == utp->step
3090 && t->pass_count == utp->pass
c1fc2657 3091 && cond_string_is_same (t->cond_string, utp->cond_string)
4e5c165d 3092 /* FIXME also test actions. */
00bf0b85
SS
3093 )
3094 {
3095 /* Scan the locations for an address match. */
d9b3f62e 3096 for (loc = b->loc; loc; loc = loc->next)
00bf0b85
SS
3097 {
3098 if (loc->address == utp->addr)
1e4d1764 3099 return loc;
00bf0b85
SS
3100 }
3101 }
3102 }
3103 return NULL;
3104}
3105
3106/* Given a list of tracepoints uploaded from a target, attempt to
3107 match them up with existing tracepoints, and create new ones if not
3108 found. */
3109
3110void
3111merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps)
3112{
3113 struct uploaded_tp *utp;
f2a8bc8a
YQ
3114 /* A set of tracepoints which are modified. */
3115 VEC(breakpoint_p) *modified_tp = NULL;
3116 int ix;
3117 struct breakpoint *b;
00bf0b85
SS
3118
3119 /* Look for GDB tracepoints that match up with our uploaded versions. */
3120 for (utp = *uploaded_tps; utp; utp = utp->next)
3121 {
1e4d1764
YQ
3122 struct bp_location *loc;
3123 struct tracepoint *t;
3124
3125 loc = find_matching_tracepoint_location (utp);
3126 if (loc)
3127 {
f2a8bc8a
YQ
3128 int found = 0;
3129
1e4d1764
YQ
3130 /* Mark this location as already inserted. */
3131 loc->inserted = 1;
3132 t = (struct tracepoint *) loc->owner;
3133 printf_filtered (_("Assuming tracepoint %d is same "
3134 "as target's tracepoint %d at %s.\n"),
3135 loc->owner->number, utp->number,
3136 paddress (loc->gdbarch, utp->addr));
f2a8bc8a
YQ
3137
3138 /* The tracepoint LOC->owner was modified (the location LOC
3139 was marked as inserted in the target). Save it in
3140 MODIFIED_TP if not there yet. The 'breakpoint-modified'
3141 observers will be notified later once for each tracepoint
3142 saved in MODIFIED_TP. */
3143 for (ix = 0;
3144 VEC_iterate (breakpoint_p, modified_tp, ix, b);
3145 ix++)
3146 if (b == loc->owner)
3147 {
3148 found = 1;
3149 break;
3150 }
3151 if (!found)
3152 VEC_safe_push (breakpoint_p, modified_tp, loc->owner);
1e4d1764 3153 }
00bf0b85
SS
3154 else
3155 {
3156 t = create_tracepoint_from_upload (utp);
3157 if (t)
3e43a32a
MS
3158 printf_filtered (_("Created tracepoint %d for "
3159 "target's tracepoint %d at %s.\n"),
c1fc2657 3160 t->number, utp->number,
3e43a32a 3161 paddress (get_current_arch (), utp->addr));
00bf0b85 3162 else
3e43a32a
MS
3163 printf_filtered (_("Failed to create tracepoint for target's "
3164 "tracepoint %d at %s, skipping it.\n"),
3165 utp->number,
3166 paddress (get_current_arch (), utp->addr));
00bf0b85
SS
3167 }
3168 /* Whether found or created, record the number used by the
3169 target, to help with mapping target tracepoints back to their
3170 counterparts here. */
3171 if (t)
3172 t->number_on_target = utp->number;
3173 }
3174
f2a8bc8a
YQ
3175 /* Notify 'breakpoint-modified' observer that at least one of B's
3176 locations was changed. */
3177 for (ix = 0; VEC_iterate (breakpoint_p, modified_tp, ix, b); ix++)
76727919 3178 gdb::observers::breakpoint_modified.notify (b);
f2a8bc8a
YQ
3179
3180 VEC_free (breakpoint_p, modified_tp);
00bf0b85
SS
3181 free_uploaded_tps (uploaded_tps);
3182}
3183
3184/* Trace state variables don't have much to identify them beyond their
3185 name, so just use that to detect matches. */
3186
70221824 3187static struct trace_state_variable *
00bf0b85
SS
3188find_matching_tsv (struct uploaded_tsv *utsv)
3189{
3190 if (!utsv->name)
3191 return NULL;
3192
3193 return find_trace_state_variable (utsv->name);
3194}
3195
70221824 3196static struct trace_state_variable *
00bf0b85
SS
3197create_tsv_from_upload (struct uploaded_tsv *utsv)
3198{
3199 const char *namebase;
8abcee91 3200 std::string buf;
00bf0b85
SS
3201 int try_num = 0;
3202 struct trace_state_variable *tsv;
3203
3204 if (utsv->name)
3205 {
3206 namebase = utsv->name;
8abcee91 3207 buf = namebase;
00bf0b85
SS
3208 }
3209 else
3210 {
3211 namebase = "__tsv";
8abcee91 3212 buf = string_printf ("%s_%d", namebase, try_num++);
00bf0b85
SS
3213 }
3214
3215 /* Fish for a name that is not in use. */
c378eb4e 3216 /* (should check against all internal vars?) */
8abcee91
TT
3217 while (find_trace_state_variable (buf.c_str ()))
3218 buf = string_printf ("%s_%d", namebase, try_num++);
00bf0b85
SS
3219
3220 /* We have an available name, create the variable. */
8abcee91 3221 tsv = create_trace_state_variable (buf.c_str ());
00bf0b85
SS
3222 tsv->initial_value = utsv->initial_value;
3223 tsv->builtin = utsv->builtin;
3224
76727919 3225 gdb::observers::tsv_created.notify (tsv);
bb25a15c 3226
00bf0b85
SS
3227 return tsv;
3228}
3229
3230/* Given a list of uploaded trace state variables, try to match them
3231 up with existing variables, or create additional ones. */
3232
3233void
3234merge_uploaded_trace_state_variables (struct uploaded_tsv **uploaded_tsvs)
3235{
3236 int ix;
3237 struct uploaded_tsv *utsv;
3238 struct trace_state_variable *tsv;
3239 int highest;
3240
3241 /* Most likely some numbers will have to be reassigned as part of
3242 the merge, so clear them all in anticipation. */
c252925c
SM
3243 for (trace_state_variable &tsv : tvariables)
3244 tsv.number = 0;
00bf0b85
SS
3245
3246 for (utsv = *uploaded_tsvs; utsv; utsv = utsv->next)
3247 {
3248 tsv = find_matching_tsv (utsv);
3249 if (tsv)
417b5110
DJ
3250 {
3251 if (info_verbose)
3e43a32a
MS
3252 printf_filtered (_("Assuming trace state variable $%s "
3253 "is same as target's variable %d.\n"),
c252925c 3254 tsv->name.c_str (), utsv->number);
417b5110 3255 }
00bf0b85
SS
3256 else
3257 {
3258 tsv = create_tsv_from_upload (utsv);
417b5110 3259 if (info_verbose)
3e43a32a
MS
3260 printf_filtered (_("Created trace state variable "
3261 "$%s for target's variable %d.\n"),
c252925c 3262 tsv->name.c_str (), utsv->number);
00bf0b85
SS
3263 }
3264 /* Give precedence to numberings that come from the target. */
3265 if (tsv)
3266 tsv->number = utsv->number;
3267 }
3268
3269 /* Renumber everything that didn't get a target-assigned number. */
3270 highest = 0;
c252925c
SM
3271 for (const trace_state_variable &tsv : tvariables)
3272 highest = std::max (tsv.number, highest);
00bf0b85
SS
3273
3274 ++highest;
c252925c
SM
3275 for (trace_state_variable &tsv : tvariables)
3276 if (tsv.number == 0)
3277 tsv.number = highest++;
00bf0b85
SS
3278
3279 free_uploaded_tsvs (uploaded_tsvs);
3280}
3281
00bf0b85
SS
3282/* Parse the part of trace status syntax that is shared between
3283 the remote protocol and the trace file reader. */
3284
00bf0b85 3285void
256642e8 3286parse_trace_status (const char *line, struct trace_status *ts)
00bf0b85 3287{
256642e8 3288 const char *p = line, *p1, *p2, *p3, *p_temp;
f196051f 3289 int end;
00bf0b85
SS
3290 ULONGEST val;
3291
3292 ts->running_known = 1;
3293 ts->running = (*p++ == '1');
3294 ts->stop_reason = trace_stop_reason_unknown;
f196051f
SS
3295 xfree (ts->stop_desc);
3296 ts->stop_desc = NULL;
4daf5ac0
SS
3297 ts->traceframe_count = -1;
3298 ts->traceframes_created = -1;
3299 ts->buffer_free = -1;
3300 ts->buffer_size = -1;
33da3f1c
SS
3301 ts->disconnected_tracing = 0;
3302 ts->circular_buffer = 0;
f196051f
SS
3303 xfree (ts->user_name);
3304 ts->user_name = NULL;
3305 xfree (ts->notes);
3306 ts->notes = NULL;
3307 ts->start_time = ts->stop_time = 0;
4daf5ac0 3308
00bf0b85
SS
3309 while (*p++)
3310 {
3311 p1 = strchr (p, ':');
3312 if (p1 == NULL)
3313 error (_("Malformed trace status, at %s\n\
3314Status line: '%s'\n"), p, line);
f196051f
SS
3315 p3 = strchr (p, ';');
3316 if (p3 == NULL)
3317 p3 = p + strlen (p);
00bf0b85
SS
3318 if (strncmp (p, stop_reason_names[trace_buffer_full], p1 - p) == 0)
3319 {
3320 p = unpack_varlen_hex (++p1, &val);
3321 ts->stop_reason = trace_buffer_full;
3322 }
3323 else if (strncmp (p, stop_reason_names[trace_never_run], p1 - p) == 0)
3324 {
3325 p = unpack_varlen_hex (++p1, &val);
3326 ts->stop_reason = trace_never_run;
3327 }
3e43a32a
MS
3328 else if (strncmp (p, stop_reason_names[tracepoint_passcount],
3329 p1 - p) == 0)
00bf0b85
SS
3330 {
3331 p = unpack_varlen_hex (++p1, &val);
3332 ts->stop_reason = tracepoint_passcount;
3333 ts->stopping_tracepoint = val;
3334 }
e5a873b7 3335 else if (strncmp (p, stop_reason_names[trace_stop_command], p1 - p) == 0)
00bf0b85 3336 {
f196051f
SS
3337 p2 = strchr (++p1, ':');
3338 if (!p2 || p2 > p3)
3339 {
3340 /*older style*/
3341 p2 = p1;
3342 }
3343 else if (p2 != p1)
3344 {
224c3ddb 3345 ts->stop_desc = (char *) xmalloc (strlen (line));
bc20a4af 3346 end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2);
f196051f
SS
3347 ts->stop_desc[end] = '\0';
3348 }
3349 else
3350 ts->stop_desc = xstrdup ("");
3351
3352 p = unpack_varlen_hex (++p2, &val);
e5a873b7 3353 ts->stop_reason = trace_stop_command;
00bf0b85 3354 }
33da3f1c
SS
3355 else if (strncmp (p, stop_reason_names[trace_disconnected], p1 - p) == 0)
3356 {
3357 p = unpack_varlen_hex (++p1, &val);
3358 ts->stop_reason = trace_disconnected;
3359 }
6c28cbf2
SS
3360 else if (strncmp (p, stop_reason_names[tracepoint_error], p1 - p) == 0)
3361 {
3362 p2 = strchr (++p1, ':');
3363 if (p2 != p1)
3364 {
224c3ddb 3365 ts->stop_desc = (char *) xmalloc ((p2 - p1) / 2 + 1);
bc20a4af 3366 end = hex2bin (p1, (gdb_byte *) ts->stop_desc, (p2 - p1) / 2);
f196051f 3367 ts->stop_desc[end] = '\0';
6c28cbf2 3368 }
a609a0c8 3369 else
f196051f 3370 ts->stop_desc = xstrdup ("");
a609a0c8 3371
6c28cbf2
SS
3372 p = unpack_varlen_hex (++p2, &val);
3373 ts->stopping_tracepoint = val;
3374 ts->stop_reason = tracepoint_error;
3375 }
4daf5ac0 3376 else if (strncmp (p, "tframes", p1 - p) == 0)
00bf0b85
SS
3377 {
3378 p = unpack_varlen_hex (++p1, &val);
3379 ts->traceframe_count = val;
3380 }
4daf5ac0
SS
3381 else if (strncmp (p, "tcreated", p1 - p) == 0)
3382 {
3383 p = unpack_varlen_hex (++p1, &val);
3384 ts->traceframes_created = val;
3385 }
3386 else if (strncmp (p, "tfree", p1 - p) == 0)
00bf0b85
SS
3387 {
3388 p = unpack_varlen_hex (++p1, &val);
3389 ts->buffer_free = val;
3390 }
4daf5ac0
SS
3391 else if (strncmp (p, "tsize", p1 - p) == 0)
3392 {
3393 p = unpack_varlen_hex (++p1, &val);
3394 ts->buffer_size = val;
3395 }
33da3f1c
SS
3396 else if (strncmp (p, "disconn", p1 - p) == 0)
3397 {
3398 p = unpack_varlen_hex (++p1, &val);
3399 ts->disconnected_tracing = val;
3400 }
3401 else if (strncmp (p, "circular", p1 - p) == 0)
3402 {
3403 p = unpack_varlen_hex (++p1, &val);
3404 ts->circular_buffer = val;
3405 }
f196051f
SS
3406 else if (strncmp (p, "starttime", p1 - p) == 0)
3407 {
3408 p = unpack_varlen_hex (++p1, &val);
3409 ts->start_time = val;
3410 }
3411 else if (strncmp (p, "stoptime", p1 - p) == 0)
3412 {
3413 p = unpack_varlen_hex (++p1, &val);
3414 ts->stop_time = val;
3415 }
3416 else if (strncmp (p, "username", p1 - p) == 0)
3417 {
3418 ++p1;
224c3ddb 3419 ts->user_name = (char *) xmalloc (strlen (p) / 2);
bc20a4af 3420 end = hex2bin (p1, (gdb_byte *) ts->user_name, (p3 - p1) / 2);
f196051f
SS
3421 ts->user_name[end] = '\0';
3422 p = p3;
3423 }
3424 else if (strncmp (p, "notes", p1 - p) == 0)
3425 {
3426 ++p1;
224c3ddb 3427 ts->notes = (char *) xmalloc (strlen (p) / 2);
bc20a4af 3428 end = hex2bin (p1, (gdb_byte *) ts->notes, (p3 - p1) / 2);
f196051f
SS
3429 ts->notes[end] = '\0';
3430 p = p3;
3431 }
00bf0b85
SS
3432 else
3433 {
3434 /* Silently skip unknown optional info. */
3435 p_temp = strchr (p1 + 1, ';');
3436 if (p_temp)
3437 p = p_temp;
3438 else
3439 /* Must be at the end. */
3440 break;
3441 }
3442 }
3443}
3444
f196051f 3445void
256642e8 3446parse_tracepoint_status (const char *p, struct breakpoint *bp,
f196051f
SS
3447 struct uploaded_tp *utp)
3448{
3449 ULONGEST uval;
3450 struct tracepoint *tp = (struct tracepoint *) bp;
3451
3452 p = unpack_varlen_hex (p, &uval);
3453 if (tp)
c1fc2657 3454 tp->hit_count += uval;
f196051f
SS
3455 else
3456 utp->hit_count += uval;
3457 p = unpack_varlen_hex (p + 1, &uval);
3458 if (tp)
3459 tp->traceframe_usage += uval;
3460 else
3461 utp->traceframe_usage += uval;
3462 /* Ignore any extra, allowing for future extensions. */
3463}
3464
409873ef
SS
3465/* Given a line of text defining a part of a tracepoint, parse it into
3466 an "uploaded tracepoint". */
00bf0b85
SS
3467
3468void
256642e8 3469parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
00bf0b85 3470{
256642e8 3471 const char *p;
00bf0b85 3472 char piece;
409873ef 3473 ULONGEST num, addr, step, pass, orig_size, xlen, start;
2a2287c7 3474 int enabled, end;
00bf0b85 3475 enum bptype type;
256642e8
PA
3476 const char *srctype;
3477 char *cond, *buf;
00bf0b85
SS
3478 struct uploaded_tp *utp = NULL;
3479
3480 p = line;
3481 /* Both tracepoint and action definitions start with the same number
3482 and address sequence. */
3483 piece = *p++;
3484 p = unpack_varlen_hex (p, &num);
3485 p++; /* skip a colon */
3486 p = unpack_varlen_hex (p, &addr);
3487 p++; /* skip a colon */
3488 if (piece == 'T')
3489 {
3490 enabled = (*p++ == 'E');
3491 p++; /* skip a colon */
3492 p = unpack_varlen_hex (p, &step);
3493 p++; /* skip a colon */
3494 p = unpack_varlen_hex (p, &pass);
3495 type = bp_tracepoint;
3496 cond = NULL;
3497 /* Thumb through optional fields. */
3498 while (*p == ':')
3499 {
3500 p++; /* skip a colon */
3501 if (*p == 'F')
3502 {
3503 type = bp_fast_tracepoint;
3504 p++;
3505 p = unpack_varlen_hex (p, &orig_size);
3506 }
0fb4aa4b
PA
3507 else if (*p == 'S')
3508 {
3509 type = bp_static_tracepoint;
3510 p++;
3511 }
00bf0b85
SS
3512 else if (*p == 'X')
3513 {
3514 p++;
3515 p = unpack_varlen_hex (p, &xlen);
3516 p++; /* skip a comma */
3517 cond = (char *) xmalloc (2 * xlen + 1);
3518 strncpy (cond, p, 2 * xlen);
3519 cond[2 * xlen] = '\0';
3520 p += 2 * xlen;
3521 }
3522 else
3e43a32a
MS
3523 warning (_("Unrecognized char '%c' in tracepoint "
3524 "definition, skipping rest"), *p);
00bf0b85
SS
3525 }
3526 utp = get_uploaded_tp (num, addr, utpp);
3527 utp->type = type;
3528 utp->enabled = enabled;
3529 utp->step = step;
3530 utp->pass = pass;
3531 utp->cond = cond;
3532 }
3533 else if (piece == 'A')
3534 {
3535 utp = get_uploaded_tp (num, addr, utpp);
a18ba4e4 3536 utp->actions.push_back (xstrdup (p));
00bf0b85
SS
3537 }
3538 else if (piece == 'S')
3539 {
3540 utp = get_uploaded_tp (num, addr, utpp);
a18ba4e4 3541 utp->step_actions.push_back (xstrdup (p));
00bf0b85 3542 }
409873ef
SS
3543 else if (piece == 'Z')
3544 {
3545 /* Parse a chunk of source form definition. */
3546 utp = get_uploaded_tp (num, addr, utpp);
3547 srctype = p;
3548 p = strchr (p, ':');
3549 p++; /* skip a colon */
3550 p = unpack_varlen_hex (p, &start);
3551 p++; /* skip a colon */
3552 p = unpack_varlen_hex (p, &xlen);
3553 p++; /* skip a colon */
3554
224c3ddb 3555 buf = (char *) alloca (strlen (line));
409873ef
SS
3556
3557 end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
3558 buf[end] = '\0';
3559
61012eef 3560 if (startswith (srctype, "at:"))
409873ef 3561 utp->at_string = xstrdup (buf);
61012eef 3562 else if (startswith (srctype, "cond:"))
409873ef 3563 utp->cond_string = xstrdup (buf);
61012eef 3564 else if (startswith (srctype, "cmd:"))
a18ba4e4 3565 utp->cmd_strings.push_back (xstrdup (buf));
409873ef 3566 }
f196051f
SS
3567 else if (piece == 'V')
3568 {
3569 utp = get_uploaded_tp (num, addr, utpp);
3570
3571 parse_tracepoint_status (p, NULL, utp);
3572 }
00bf0b85
SS
3573 else
3574 {
409873ef
SS
3575 /* Don't error out, the target might be sending us optional
3576 info that we don't care about. */
3577 warning (_("Unrecognized tracepoint piece '%c', ignoring"), piece);
00bf0b85
SS
3578 }
3579}
3580
3581/* Convert a textual description of a trace state variable into an
3582 uploaded object. */
3583
3584void
256642e8 3585parse_tsv_definition (const char *line, struct uploaded_tsv **utsvp)
00bf0b85 3586{
256642e8
PA
3587 const char *p;
3588 char *buf;
00bf0b85
SS
3589 ULONGEST num, initval, builtin;
3590 int end;
3591 struct uploaded_tsv *utsv = NULL;
3592
224c3ddb 3593 buf = (char *) alloca (strlen (line));
00bf0b85
SS
3594
3595 p = line;
3596 p = unpack_varlen_hex (p, &num);
3597 p++; /* skip a colon */
3598 p = unpack_varlen_hex (p, &initval);
3599 p++; /* skip a colon */
3600 p = unpack_varlen_hex (p, &builtin);
3601 p++; /* skip a colon */
3602 end = hex2bin (p, (gdb_byte *) buf, strlen (p) / 2);
3603 buf[end] = '\0';
3604
3605 utsv = get_uploaded_tsv (num, utsvp);
3606 utsv->initial_value = initval;
3607 utsv->builtin = builtin;
3608 utsv->name = xstrdup (buf);
3609}
3610
0fb4aa4b
PA
3611/* Given a line of text defining a static tracepoint marker, parse it
3612 into a "static tracepoint marker" object. Throws an error is
3613 parsing fails. If PP is non-null, it points to one past the end of
3614 the parsed marker definition. */
3615
3616void
256642e8 3617parse_static_tracepoint_marker_definition (const char *line, const char **pp,
5d9310c4 3618 static_tracepoint_marker *marker)
0fb4aa4b 3619{
256642e8 3620 const char *p, *endp;
0fb4aa4b 3621 ULONGEST addr;
0fb4aa4b
PA
3622
3623 p = line;
3624 p = unpack_varlen_hex (p, &addr);
3625 p++; /* skip a colon */
3626
f5656ead 3627 marker->gdbarch = target_gdbarch ();
0fb4aa4b
PA
3628 marker->address = (CORE_ADDR) addr;
3629
3630 endp = strchr (p, ':');
3631 if (endp == NULL)
74232302 3632 error (_("bad marker definition: %s"), line);
0fb4aa4b 3633
5d9310c4 3634 marker->str_id = hex2str (p, (endp - p) / 2);
0fb4aa4b 3635
5d9310c4
SM
3636 p = endp;
3637 p++; /* skip a colon */
0fb4aa4b 3638
62c222b6
SM
3639 /* This definition may be followed by another one, separated by a comma. */
3640 int hex_len;
3641 endp = strchr (p, ',');
3642 if (endp != nullptr)
3643 hex_len = endp - p;
3644 else
3645 hex_len = strlen (p);
3646
5d9310c4 3647 marker->extra = hex2str (p, hex_len / 2);
0fb4aa4b 3648
5d9310c4 3649 if (pp != nullptr)
62c222b6 3650 *pp = p + hex_len;
0fb4aa4b
PA
3651}
3652
0fb4aa4b
PA
3653/* Print MARKER to gdb_stdout. */
3654
3655static void
3656print_one_static_tracepoint_marker (int count,
5d9310c4 3657 const static_tracepoint_marker &marker)
0fb4aa4b 3658{
0fb4aa4b
PA
3659 struct symbol *sym;
3660
3661 char wrap_indent[80];
3662 char extra_field_indent[80];
79a45e25 3663 struct ui_out *uiout = current_uiout;
0fb4aa4b
PA
3664 VEC(breakpoint_p) *tracepoints;
3665
51abb421 3666 symtab_and_line sal;
5d9310c4 3667 sal.pc = marker.address;
0fb4aa4b 3668
5d9310c4 3669 tracepoints = static_tracepoints_here (marker.address);
0fb4aa4b 3670
a14a62dd 3671 ui_out_emit_tuple tuple_emitter (uiout, "marker");
0fb4aa4b
PA
3672
3673 /* A counter field to help readability. This is not a stable
3674 identifier! */
112e8700 3675 uiout->field_int ("count", count);
0fb4aa4b 3676
5d9310c4 3677 uiout->field_string ("marker-id", marker.str_id.c_str ());
0fb4aa4b 3678
112e8700 3679 uiout->field_fmt ("enabled", "%c",
0fb4aa4b 3680 !VEC_empty (breakpoint_p, tracepoints) ? 'y' : 'n');
112e8700 3681 uiout->spaces (2);
0fb4aa4b
PA
3682
3683 strcpy (wrap_indent, " ");
3684
5d9310c4 3685 if (gdbarch_addr_bit (marker.gdbarch) <= 32)
0fb4aa4b
PA
3686 strcat (wrap_indent, " ");
3687 else
3688 strcat (wrap_indent, " ");
3689
3690 strcpy (extra_field_indent, " ");
3691
5d9310c4 3692 uiout->field_core_addr ("addr", marker.gdbarch, marker.address);
0fb4aa4b 3693
5d9310c4
SM
3694 sal = find_pc_line (marker.address, 0);
3695 sym = find_pc_sect_function (marker.address, NULL);
0fb4aa4b
PA
3696 if (sym)
3697 {
112e8700
SM
3698 uiout->text ("in ");
3699 uiout->field_string ("func",
0fb4aa4b 3700 SYMBOL_PRINT_NAME (sym));
112e8700
SM
3701 uiout->wrap_hint (wrap_indent);
3702 uiout->text (" at ");
0fb4aa4b
PA
3703 }
3704 else
112e8700 3705 uiout->field_skip ("func");
0fb4aa4b
PA
3706
3707 if (sal.symtab != NULL)
3708 {
112e8700 3709 uiout->field_string ("file",
05cba821 3710 symtab_to_filename_for_display (sal.symtab));
112e8700 3711 uiout->text (":");
0fb4aa4b 3712
112e8700 3713 if (uiout->is_mi_like_p ())
0fb4aa4b 3714 {
0b0865da 3715 const char *fullname = symtab_to_fullname (sal.symtab);
0fb4aa4b 3716
112e8700 3717 uiout->field_string ("fullname", fullname);
0fb4aa4b
PA
3718 }
3719 else
112e8700 3720 uiout->field_skip ("fullname");
0fb4aa4b 3721
112e8700 3722 uiout->field_int ("line", sal.line);
0fb4aa4b
PA
3723 }
3724 else
3725 {
112e8700
SM
3726 uiout->field_skip ("fullname");
3727 uiout->field_skip ("line");
0fb4aa4b
PA
3728 }
3729
112e8700
SM
3730 uiout->text ("\n");
3731 uiout->text (extra_field_indent);
3732 uiout->text (_("Data: \""));
5d9310c4 3733 uiout->field_string ("extra-data", marker.extra.c_str ());
112e8700 3734 uiout->text ("\"\n");
0fb4aa4b
PA
3735
3736 if (!VEC_empty (breakpoint_p, tracepoints))
3737 {
0fb4aa4b
PA
3738 int ix;
3739 struct breakpoint *b;
3740
a14a62dd
TT
3741 {
3742 ui_out_emit_tuple tuple_emitter (uiout, "tracepoints-at");
3743
3744 uiout->text (extra_field_indent);
3745 uiout->text (_("Probed by static tracepoints: "));
3746 for (ix = 0; VEC_iterate(breakpoint_p, tracepoints, ix, b); ix++)
3747 {
3748 if (ix > 0)
3749 uiout->text (", ");
3750 uiout->text ("#");
3751 uiout->field_int ("tracepoint-id", b->number);
3752 }
3753 }
0fb4aa4b 3754
112e8700
SM
3755 if (uiout->is_mi_like_p ())
3756 uiout->field_int ("number-of-tracepoints",
0fb4aa4b
PA
3757 VEC_length(breakpoint_p, tracepoints));
3758 else
112e8700 3759 uiout->text ("\n");
0fb4aa4b
PA
3760 }
3761 VEC_free (breakpoint_p, tracepoints);
0fb4aa4b
PA
3762}
3763
3764static void
1d12d88f 3765info_static_tracepoint_markers_command (const char *arg, int from_tty)
0fb4aa4b 3766{
79a45e25 3767 struct ui_out *uiout = current_uiout;
5d9310c4
SM
3768 std::vector<static_tracepoint_marker> markers
3769 = target_static_tracepoint_markers_by_strid (NULL);
0fb4aa4b 3770
d1feda86
YQ
3771 /* We don't have to check target_can_use_agent and agent's capability on
3772 static tracepoint here, in order to be compatible with older GDBserver.
3773 We don't check USE_AGENT is true or not, because static tracepoints
3774 don't work without in-process agent, so we don't bother users to type
3775 `set agent on' when to use static tracepoint. */
3776
4a2b031d
TT
3777 ui_out_emit_table table_emitter (uiout, 5, -1,
3778 "StaticTracepointMarkersTable");
0fb4aa4b 3779
112e8700 3780 uiout->table_header (7, ui_left, "counter", "Cnt");
0fb4aa4b 3781
112e8700 3782 uiout->table_header (40, ui_left, "marker-id", "ID");
0fb4aa4b 3783
112e8700 3784 uiout->table_header (3, ui_left, "enabled", "Enb");
f5656ead 3785 if (gdbarch_addr_bit (target_gdbarch ()) <= 32)
112e8700 3786 uiout->table_header (10, ui_left, "addr", "Address");
0fb4aa4b 3787 else
112e8700
SM
3788 uiout->table_header (18, ui_left, "addr", "Address");
3789 uiout->table_header (40, ui_noalign, "what", "What");
0fb4aa4b 3790
112e8700 3791 uiout->table_body ();
0fb4aa4b 3792
5d9310c4
SM
3793 for (int i = 0; i < markers.size (); i++)
3794 print_one_static_tracepoint_marker (i + 1, markers[i]);
0fb4aa4b
PA
3795}
3796
3797/* The $_sdata convenience variable is a bit special. We don't know
3798 for sure type of the value until we actually have a chance to fetch
3799 the data --- the size of the object depends on what has been
3800 collected. We solve this by making $_sdata be an internalvar that
3801 creates a new value on access. */
3802
3803/* Return a new value with the correct type for the sdata object of
3804 the current trace frame. Return a void value if there's no object
3805 available. */
3806
3807static struct value *
22d2b532
SDJ
3808sdata_make_value (struct gdbarch *gdbarch, struct internalvar *var,
3809 void *ignore)
0fb4aa4b 3810{
0fb4aa4b 3811 /* We need to read the whole object before we know its size. */
9018be22 3812 gdb::optional<gdb::byte_vector> buf
f6ac5f3d 3813 = target_read_alloc (target_stack, TARGET_OBJECT_STATIC_TRACE_DATA,
9018be22
SM
3814 NULL);
3815 if (buf)
0fb4aa4b
PA
3816 {
3817 struct value *v;
3818 struct type *type;
3819
3820 type = init_vector_type (builtin_type (gdbarch)->builtin_true_char,
9018be22 3821 buf->size ());
0fb4aa4b 3822 v = allocate_value (type);
9018be22 3823 memcpy (value_contents_raw (v), buf->data (), buf->size ());
0fb4aa4b
PA
3824 return v;
3825 }
3826 else
3827 return allocate_value (builtin_type (gdbarch)->builtin_void);
3828}
3829
b3b9301e
PA
3830#if !defined(HAVE_LIBEXPAT)
3831
86766165 3832struct std::unique_ptr<traceframe_info>
b3b9301e
PA
3833parse_traceframe_info (const char *tframe_info)
3834{
3835 static int have_warned;
3836
3837 if (!have_warned)
3838 {
3839 have_warned = 1;
3840 warning (_("Can not parse XML trace frame info; XML support "
3841 "was disabled at compile time"));
3842 }
3843
3844 return NULL;
3845}
3846
3847#else /* HAVE_LIBEXPAT */
3848
3849#include "xml-support.h"
3850
3851/* Handle the start of a <memory> element. */
3852
3853static void
3854traceframe_info_start_memory (struct gdb_xml_parser *parser,
3855 const struct gdb_xml_element *element,
4d0fdd9b
SM
3856 void *user_data,
3857 std::vector<gdb_xml_value> &attributes)
b3b9301e 3858{
19ba03f4 3859 struct traceframe_info *info = (struct traceframe_info *) user_data;
b3b9301e
PA
3860 ULONGEST *start_p, *length_p;
3861
19ba03f4 3862 start_p
4d0fdd9b 3863 = (ULONGEST *) xml_find_attribute (attributes, "start")->value.get ();
19ba03f4 3864 length_p
4d0fdd9b 3865 = (ULONGEST *) xml_find_attribute (attributes, "length")->value.get ();
b3b9301e 3866
4cdd21a8 3867 info->memory.emplace_back (*start_p, *length_p);
b3b9301e
PA
3868}
3869
28a93511
YQ
3870/* Handle the start of a <tvar> element. */
3871
3872static void
3873traceframe_info_start_tvar (struct gdb_xml_parser *parser,
3874 const struct gdb_xml_element *element,
3875 void *user_data,
4d0fdd9b 3876 std::vector<gdb_xml_value> &attributes)
28a93511 3877{
19ba03f4
SM
3878 struct traceframe_info *info = (struct traceframe_info *) user_data;
3879 const char *id_attrib
4d0fdd9b 3880 = (const char *) xml_find_attribute (attributes, "id")->value.get ();
28a93511
YQ
3881 int id = gdb_xml_parse_ulongest (parser, id_attrib);
3882
d0d292a2 3883 info->tvars.push_back (id);
28a93511
YQ
3884}
3885
b3b9301e
PA
3886/* The allowed elements and attributes for an XML memory map. */
3887
3888static const struct gdb_xml_attribute memory_attributes[] = {
3889 { "start", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
3890 { "length", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
3891 { NULL, GDB_XML_AF_NONE, NULL, NULL }
3892};
3893
28a93511
YQ
3894static const struct gdb_xml_attribute tvar_attributes[] = {
3895 { "id", GDB_XML_AF_NONE, NULL, NULL },
3896 { NULL, GDB_XML_AF_NONE, NULL, NULL }
3897};
3898
b3b9301e
PA
3899static const struct gdb_xml_element traceframe_info_children[] = {
3900 { "memory", memory_attributes, NULL,
3901 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
3902 traceframe_info_start_memory, NULL },
28a93511
YQ
3903 { "tvar", tvar_attributes, NULL,
3904 GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL,
3905 traceframe_info_start_tvar, NULL },
b3b9301e
PA
3906 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
3907};
3908
3909static const struct gdb_xml_element traceframe_info_elements[] = {
3910 { "traceframe-info", NULL, traceframe_info_children, GDB_XML_EF_NONE,
3911 NULL, NULL },
3912 { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
3913};
3914
3915/* Parse a traceframe-info XML document. */
3916
2098b393 3917traceframe_info_up
b3b9301e
PA
3918parse_traceframe_info (const char *tframe_info)
3919{
2098b393 3920 traceframe_info_up result (new traceframe_info);
b3b9301e
PA
3921
3922 if (gdb_xml_parse_quick (_("trace frame info"),
3923 "traceframe-info.dtd", traceframe_info_elements,
2098b393
SM
3924 tframe_info, result.get ()) == 0)
3925 return result;
b3b9301e 3926
b3b9301e
PA
3927 return NULL;
3928}
3929
3930#endif /* HAVE_LIBEXPAT */
3931
3932/* Returns the traceframe_info object for the current traceframe.
3933 This is where we avoid re-fetching the object from the target if we
3934 already have it cached. */
3935
dc673c81 3936struct traceframe_info *
b3b9301e
PA
3937get_traceframe_info (void)
3938{
8d3c73ef
SM
3939 if (current_traceframe_info == NULL)
3940 current_traceframe_info = target_traceframe_info ();
b3b9301e 3941
2098b393 3942 return current_traceframe_info.get ();
b3b9301e
PA
3943}
3944
c0f61f9c
PA
3945/* If the target supports the query, return in RESULT the set of
3946 collected memory in the current traceframe, found within the LEN
3947 bytes range starting at MEMADDR. Returns true if the target
3948 supports the query, otherwise returns false, and RESULT is left
3949 undefined. */
2a7498d8
PA
3950
3951int
a79b1bc6 3952traceframe_available_memory (std::vector<mem_range> *result,
2a7498d8
PA
3953 CORE_ADDR memaddr, ULONGEST len)
3954{
3955 struct traceframe_info *info = get_traceframe_info ();
3956
3957 if (info != NULL)
3958 {
a79b1bc6 3959 result->clear ();
2a7498d8 3960
4cdd21a8
SM
3961 for (mem_range &r : info->memory)
3962 if (mem_ranges_overlap (r.start, r.length, memaddr, len))
2a7498d8
PA
3963 {
3964 ULONGEST lo1, hi1, lo2, hi2;
2a7498d8
PA
3965
3966 lo1 = memaddr;
3967 hi1 = memaddr + len;
3968
4cdd21a8
SM
3969 lo2 = r.start;
3970 hi2 = r.start + r.length;
2a7498d8 3971
a79b1bc6
SM
3972 CORE_ADDR start = std::max (lo1, lo2);
3973 int length = std::min (hi1, hi2) - start;
2a7498d8 3974
a79b1bc6 3975 result->emplace_back (start, length);
2a7498d8
PA
3976 }
3977
a79b1bc6 3978 normalize_mem_ranges (result);
2a7498d8
PA
3979 return 1;
3980 }
3981
3982 return 0;
3983}
3984
22d2b532
SDJ
3985/* Implementation of `sdata' variable. */
3986
3987static const struct internalvar_funcs sdata_funcs =
3988{
3989 sdata_make_value,
3990 NULL,
3991 NULL
3992};
3993
c906108c
SS
3994/* module initialization */
3995void
fba45db2 3996_initialize_tracepoint (void)
c906108c 3997{
fa58ee11
EZ
3998 struct cmd_list_element *c;
3999
0fb4aa4b
PA
4000 /* Explicitly create without lookup, since that tries to create a
4001 value with a void typed value, and when we get here, gdbarch
4002 isn't initialized yet. At this point, we're quite sure there
4003 isn't another convenience variable of the same name. */
22d2b532 4004 create_internalvar_type_lazy ("_sdata", &sdata_funcs, NULL);
0fb4aa4b 4005
c906108c
SS
4006 traceframe_number = -1;
4007 tracepoint_number = -1;
4008
11db9430 4009 add_info ("scope", info_scope_command,
1bedd215 4010 _("List the variables local to a scope"));
c906108c 4011
0450cc4c 4012 add_cmd ("tracepoints", class_trace,
1a966eab 4013 _("Tracing of program execution without stopping the program."),
c906108c
SS
4014 &cmdlist);
4015
e5a873b7 4016 add_com ("tdump", class_trace, tdump_command,
1bedd215 4017 _("Print everything collected at the current tracepoint."));
c906108c 4018
f61e138d
SS
4019 c = add_com ("tvariable", class_trace, trace_variable_command,_("\
4020Define a trace state variable.\n\
4021Argument is a $-prefixed name, optionally followed\n\
4022by '=' and an expression that sets the initial value\n\
4023at the start of tracing."));
4024 set_cmd_completer (c, expression_completer);
4025
4026 add_cmd ("tvariable", class_trace, delete_trace_variable_command, _("\
4027Delete one or more trace state variables.\n\
4028Arguments are the names of the variables to delete.\n\
4029If no arguments are supplied, delete all variables."), &deletelist);
c378eb4e 4030 /* FIXME add a trace variable completer. */
f61e138d 4031
11db9430 4032 add_info ("tvariables", info_tvariables_command, _("\
f61e138d 4033Status of trace state variables and their values.\n\
0fb4aa4b
PA
4034"));
4035
4036 add_info ("static-tracepoint-markers",
4037 info_static_tracepoint_markers_command, _("\
4038List target static tracepoints markers.\n\
f61e138d
SS
4039"));
4040
e5a873b7 4041 add_prefix_cmd ("tfind", class_trace, tfind_command, _("\
1bedd215
AC
4042Select a trace frame;\n\
4043No argument means forward by one frame; '-' means backward by one frame."),
c906108c
SS
4044 &tfindlist, "tfind ", 1, &cmdlist);
4045
e5a873b7 4046 add_cmd ("outside", class_trace, tfind_outside_command, _("\
081dfbf7 4047Select a trace frame whose PC is outside the given range (exclusive).\n\
1a966eab 4048Usage: tfind outside addr1, addr2"),
c906108c
SS
4049 &tfindlist);
4050
e5a873b7 4051 add_cmd ("range", class_trace, tfind_range_command, _("\
081dfbf7 4052Select a trace frame whose PC is in the given range (inclusive).\n\
1a966eab 4053Usage: tfind range addr1,addr2"),
c906108c
SS
4054 &tfindlist);
4055
e5a873b7 4056 add_cmd ("line", class_trace, tfind_line_command, _("\
1a966eab 4057Select a trace frame by source line.\n\
cce7e648 4058Argument can be a line number (with optional source file),\n\
c906108c 4059a function name, or '*' followed by an address.\n\
1a966eab 4060Default argument is 'the next source line that was traced'."),
c906108c
SS
4061 &tfindlist);
4062
e5a873b7 4063 add_cmd ("tracepoint", class_trace, tfind_tracepoint_command, _("\
1a966eab
AC
4064Select a trace frame by tracepoint number.\n\
4065Default is the tracepoint for the current trace frame."),
c906108c
SS
4066 &tfindlist);
4067
e5a873b7 4068 add_cmd ("pc", class_trace, tfind_pc_command, _("\
1a966eab
AC
4069Select a trace frame by PC.\n\
4070Default is the current PC, or the PC of the current trace frame."),
c906108c
SS
4071 &tfindlist);
4072
e5a873b7 4073 add_cmd ("end", class_trace, tfind_end_command, _("\
1a966eab 4074De-select any trace frame and resume 'live' debugging."),
c906108c
SS
4075 &tfindlist);
4076
8acc4065 4077 add_alias_cmd ("none", "end", class_trace, 0, &tfindlist);
c906108c 4078
e5a873b7 4079 add_cmd ("start", class_trace, tfind_start_command,
1a966eab 4080 _("Select the first trace frame in the trace buffer."),
c906108c
SS
4081 &tfindlist);
4082
e5a873b7 4083 add_com ("tstatus", class_trace, tstatus_command,
1bedd215 4084 _("Display the status of the current trace data collection."));
c906108c 4085
e5a873b7 4086 add_com ("tstop", class_trace, tstop_command, _("\
f196051f
SS
4087Stop trace data collection.\n\
4088Usage: tstop [ <notes> ... ]\n\
4089Any arguments supplied are recorded with the trace as a stop reason and\n\
4090reported by tstatus (if the target supports trace notes)."));
c906108c 4091
e5a873b7 4092 add_com ("tstart", class_trace, tstart_command, _("\
f196051f
SS
4093Start trace data collection.\n\
4094Usage: tstart [ <notes> ... ]\n\
4095Any arguments supplied are recorded with the trace as a note and\n\
4096reported by tstatus (if the target supports trace notes)."));
c906108c 4097
1bedd215
AC
4098 add_com ("end", class_trace, end_actions_pseudocommand, _("\
4099Ends a list of commands or actions.\n\
c906108c
SS
4100Several GDB commands allow you to enter a list of commands or actions.\n\
4101Entering \"end\" on a line by itself is the normal way to terminate\n\
4102such a list.\n\n\
1bedd215 4103Note: the \"end\" command cannot be used at the gdb prompt."));
c906108c 4104
1bedd215
AC
4105 add_com ("while-stepping", class_trace, while_stepping_pseudocommand, _("\
4106Specify single-stepping behavior at a tracepoint.\n\
c906108c
SS
4107Argument is number of instructions to trace in single-step mode\n\
4108following the tracepoint. This command is normally followed by\n\
4109one or more \"collect\" commands, to specify what to collect\n\
4110while single-stepping.\n\n\
1bedd215 4111Note: this command can only be used in a tracepoint \"actions\" list."));
c906108c 4112
c5aa993b
JM
4113 add_com_alias ("ws", "while-stepping", class_alias, 0);
4114 add_com_alias ("stepping", "while-stepping", class_alias, 0);
c906108c 4115
1bedd215
AC
4116 add_com ("collect", class_trace, collect_pseudocommand, _("\
4117Specify one or more data items to be collected at a tracepoint.\n\
c906108c
SS
4118Accepts a comma-separated list of (one or more) expressions. GDB will\n\
4119collect all data (variables, registers) referenced by that expression.\n\
4120Also accepts the following special arguments:\n\
4121 $regs -- all registers.\n\
4122 $args -- all function arguments.\n\
4123 $locals -- all variables local to the block/function scope.\n\
0fb4aa4b 4124 $_sdata -- static tracepoint data (ignored for non-static tracepoints).\n\
1bedd215 4125Note: this command can only be used in a tracepoint \"actions\" list."));
c906108c 4126
6da95a67
SS
4127 add_com ("teval", class_trace, teval_pseudocommand, _("\
4128Specify one or more expressions to be evaluated at a tracepoint.\n\
4129Accepts a comma-separated list of (one or more) expressions.\n\
4130The result of each evaluation will be discarded.\n\
4131Note: this command can only be used in a tracepoint \"actions\" list."));
4132
e5a873b7 4133 add_com ("actions", class_trace, actions_command, _("\
1bedd215 4134Specify the actions to be taken at a tracepoint.\n\
cce7e648
PA
4135Tracepoint actions may include collecting of specified data,\n\
4136single-stepping, or enabling/disabling other tracepoints,\n\
1bedd215 4137depending on target's capabilities."));
c906108c 4138
236f1d4d
SS
4139 default_collect = xstrdup ("");
4140 add_setshow_string_cmd ("default-collect", class_trace,
4141 &default_collect, _("\
4142Set the list of expressions to collect by default"), _("\
4143Show the list of expressions to collect by default"), NULL,
4144 NULL, NULL,
4145 &setlist, &showlist);
4146
d5551862
SS
4147 add_setshow_boolean_cmd ("disconnected-tracing", no_class,
4148 &disconnected_tracing, _("\
4149Set whether tracing continues after GDB disconnects."), _("\
4150Show whether tracing continues after GDB disconnects."), _("\
4151Use this to continue a tracing run even if GDB disconnects\n\
4152or detaches from the target. You can reconnect later and look at\n\
4153trace data collected in the meantime."),
4154 set_disconnected_tracing,
4155 NULL,
4156 &setlist,
4157 &showlist);
00bf0b85 4158
4daf5ac0
SS
4159 add_setshow_boolean_cmd ("circular-trace-buffer", no_class,
4160 &circular_trace_buffer, _("\
4161Set target's use of circular trace buffer."), _("\
4162Show target's use of circular trace buffer."), _("\
4163Use this to make the trace buffer into a circular buffer,\n\
4164which will discard traceframes (oldest first) instead of filling\n\
4165up and stopping the trace run."),
4166 set_circular_trace_buffer,
4167 NULL,
4168 &setlist,
4169 &showlist);
4170
f6f899bf 4171 add_setshow_zuinteger_unlimited_cmd ("trace-buffer-size", no_class,
9b67fcec 4172 &trace_buffer_size, _("\
f6f899bf
HAQ
4173Set requested size of trace buffer."), _("\
4174Show requested size of trace buffer."), _("\
4175Use this to choose a size for the trace buffer. Some targets\n\
f81d1120
PA
4176may have fixed or limited buffer sizes. Specifying \"unlimited\" or -1\n\
4177disables any attempt to set the buffer size and lets the target choose."),
9b67fcec
YQ
4178 set_trace_buffer_size, NULL,
4179 &setlist, &showlist);
f6f899bf 4180
f196051f
SS
4181 add_setshow_string_cmd ("trace-user", class_trace,
4182 &trace_user, _("\
4183Set the user name to use for current and future trace runs"), _("\
4184Show the user name to use for current and future trace runs"), NULL,
4185 set_trace_user, NULL,
4186 &setlist, &showlist);
4187
4188 add_setshow_string_cmd ("trace-notes", class_trace,
4189 &trace_notes, _("\
4190Set notes string to use for current and future trace runs"), _("\
4191Show the notes string to use for current and future trace runs"), NULL,
4192 set_trace_notes, NULL,
4193 &setlist, &showlist);
4194
4195 add_setshow_string_cmd ("trace-stop-notes", class_trace,
4196 &trace_stop_notes, _("\
4197Set notes string to use for future tstop commands"), _("\
4198Show the notes string to use for future tstop commands"), NULL,
4199 set_trace_stop_notes, NULL,
4200 &setlist, &showlist);
c906108c 4201}
This page took 2.356435 seconds and 4 git commands to generate.