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