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