forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracepoint.c
4555 lines (3834 loc) · 125 KB
/
tracepoint.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Tracing functionality for remote targets in custom GDB protocol
Copyright (C) 1997-2015 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "arch-utils.h"
#include "symtab.h"
#include "frame.h"
#include "gdbtypes.h"
#include "expression.h"
#include "gdbcmd.h"
#include "value.h"
#include "target.h"
#include "target-dcache.h"
#include "language.h"
#include "inferior.h"
#include "breakpoint.h"
#include "tracepoint.h"
#include "linespec.h"
#include "regcache.h"
#include "completer.h"
#include "block.h"
#include "dictionary.h"
#include "observer.h"
#include "user-regs.h"
#include "valprint.h"
#include "gdbcore.h"
#include "objfiles.h"
#include "filenames.h"
#include "gdbthread.h"
#include "stack.h"
#include "remote.h"
#include "source.h"
#include "ax.h"
#include "ax-gdb.h"
#include "memrange.h"
#include "cli/cli-utils.h"
#include "probe.h"
#include "ctf.h"
#include "filestuff.h"
#include "rsp-low.h"
#include "tracefile.h"
#include "location.h"
/* readline include files */
#include "readline/readline.h"
#include "readline/history.h"
/* readline defines this. */
#undef savestring
#include <unistd.h>
/* Maximum length of an agent aexpression.
This accounts for the fact that packets are limited to 400 bytes
(which includes everything -- including the checksum), and assumes
the worst case of maximum length for each of the pieces of a
continuation packet.
NOTE: expressions get mem2hex'ed otherwise this would be twice as
large. (400 - 31)/2 == 184 */
#define MAX_AGENT_EXPR_LEN 184
/* A hook used to notify the UI of tracepoint operations. */
void (*deprecated_trace_find_hook) (char *arg, int from_tty);
void (*deprecated_trace_start_stop_hook) (int start, int from_tty);
/*
Tracepoint.c:
This module defines the following debugger commands:
trace : set a tracepoint on a function, line, or address.
info trace : list all debugger-defined tracepoints.
delete trace : delete one or more tracepoints.
enable trace : enable one or more tracepoints.
disable trace : disable one or more tracepoints.
actions : specify actions to be taken at a tracepoint.
passcount : specify a pass count for a tracepoint.
tstart : start a trace experiment.
tstop : stop a trace experiment.
tstatus : query the status of a trace experiment.
tfind : find a trace frame in the trace buffer.
tdump : print everything collected at the current tracepoint.
save-tracepoints : write tracepoint setup into a file.
This module defines the following user-visible debugger variables:
$trace_frame : sequence number of trace frame currently being debugged.
$trace_line : source line of trace frame currently being debugged.
$trace_file : source file of trace frame currently being debugged.
$tracepoint : tracepoint number of trace frame currently being debugged.
*/
/* ======= Important global variables: ======= */
/* The list of all trace state variables. We don't retain pointers to
any of these for any reason - API is by name or number only - so it
works to have a vector of objects. */
typedef struct trace_state_variable tsv_s;
DEF_VEC_O(tsv_s);
static VEC(tsv_s) *tvariables;
/* The next integer to assign to a variable. */
static int next_tsv_number = 1;
/* Number of last traceframe collected. */
static int traceframe_number;
/* Tracepoint for last traceframe collected. */
static int tracepoint_number;
/* The traceframe info of the current traceframe. NULL if we haven't
yet attempted to fetch it, or if the target does not support
fetching this object, or if we're not inspecting a traceframe
presently. */
static struct traceframe_info *traceframe_info;
/* Tracing command lists. */
static struct cmd_list_element *tfindlist;
/* List of expressions to collect by default at each tracepoint hit. */
char *default_collect = "";
static int disconnected_tracing;
/* This variable controls whether we ask the target for a linear or
circular trace buffer. */
static int circular_trace_buffer;
/* This variable is the requested trace buffer size, or -1 to indicate
that we don't care and leave it up to the target to set a size. */
static int trace_buffer_size = -1;
/* Textual notes applying to the current and/or future trace runs. */
char *trace_user = NULL;
/* Textual notes applying to the current and/or future trace runs. */
char *trace_notes = NULL;
/* Textual notes applying to the stopping of a trace. */
char *trace_stop_notes = NULL;
/* ======= Important command functions: ======= */
static void trace_actions_command (char *, int);
static void trace_start_command (char *, int);
static void trace_stop_command (char *, int);
static void trace_status_command (char *, int);
static void trace_find_command (char *, int);
static void trace_find_pc_command (char *, int);
static void trace_find_tracepoint_command (char *, int);
static void trace_find_line_command (char *, int);
static void trace_find_range_command (char *, int);
static void trace_find_outside_command (char *, int);
static void trace_dump_command (char *, int);
/* support routines */
struct collection_list;
static void add_aexpr (struct collection_list *, struct agent_expr *);
static char *mem2hex (gdb_byte *, char *, int);
static void add_register (struct collection_list *collection,
unsigned int regno);
static struct command_line *
all_tracepoint_actions_and_cleanup (struct breakpoint *t);
extern void _initialize_tracepoint (void);
static struct trace_status trace_status;
const char *stop_reason_names[] = {
"tunknown",
"tnotrun",
"tstop",
"tfull",
"tdisconnected",
"tpasscount",
"terror"
};
struct trace_status *
current_trace_status (void)
{
return &trace_status;
}
/* Destroy INFO. */
static void
free_traceframe_info (struct traceframe_info *info)
{
if (info != NULL)
{
VEC_free (mem_range_s, info->memory);
VEC_free (int, info->tvars);
xfree (info);
}
}
/* Free and clear the traceframe info cache of the current
traceframe. */
static void
clear_traceframe_info (void)
{
free_traceframe_info (traceframe_info);
traceframe_info = NULL;
}
/* Set traceframe number to NUM. */
static void
set_traceframe_num (int num)
{
traceframe_number = num;
set_internalvar_integer (lookup_internalvar ("trace_frame"), num);
}
/* Set tracepoint number to NUM. */
static void
set_tracepoint_num (int num)
{
tracepoint_number = num;
set_internalvar_integer (lookup_internalvar ("tracepoint"), num);
}
/* Set externally visible debug variables for querying/printing
the traceframe context (line, function, file). */
static void
set_traceframe_context (struct frame_info *trace_frame)
{
CORE_ADDR trace_pc;
struct symbol *traceframe_fun;
struct symtab_and_line traceframe_sal;
/* Save as globals for internal use. */
if (trace_frame != NULL
&& get_frame_pc_if_available (trace_frame, &trace_pc))
{
traceframe_sal = find_pc_line (trace_pc, 0);
traceframe_fun = find_pc_function (trace_pc);
/* Save linenumber as "$trace_line", a debugger variable visible to
users. */
set_internalvar_integer (lookup_internalvar ("trace_line"),
traceframe_sal.line);
}
else
{
init_sal (&traceframe_sal);
traceframe_fun = NULL;
set_internalvar_integer (lookup_internalvar ("trace_line"), -1);
}
/* Save func name as "$trace_func", a debugger variable visible to
users. */
if (traceframe_fun == NULL
|| SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
clear_internalvar (lookup_internalvar ("trace_func"));
else
set_internalvar_string (lookup_internalvar ("trace_func"),
SYMBOL_LINKAGE_NAME (traceframe_fun));
/* Save file name as "$trace_file", a debugger variable visible to
users. */
if (traceframe_sal.symtab == NULL)
clear_internalvar (lookup_internalvar ("trace_file"));
else
set_internalvar_string (lookup_internalvar ("trace_file"),
symtab_to_filename_for_display (traceframe_sal.symtab));
}
/* Create a new trace state variable with the given name. */
struct trace_state_variable *
create_trace_state_variable (const char *name)
{
struct trace_state_variable tsv;
memset (&tsv, 0, sizeof (tsv));
tsv.name = xstrdup (name);
tsv.number = next_tsv_number++;
return VEC_safe_push (tsv_s, tvariables, &tsv);
}
/* Look for a trace state variable of the given name. */
struct trace_state_variable *
find_trace_state_variable (const char *name)
{
struct trace_state_variable *tsv;
int ix;
for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
if (strcmp (name, tsv->name) == 0)
return tsv;
return NULL;
}
/* Look for a trace state variable of the given number. Return NULL if
not found. */
struct trace_state_variable *
find_trace_state_variable_by_number (int number)
{
struct trace_state_variable *tsv;
int ix;
for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
if (tsv->number == number)
return tsv;
return NULL;
}
static void
delete_trace_state_variable (const char *name)
{
struct trace_state_variable *tsv;
int ix;
for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
if (strcmp (name, tsv->name) == 0)
{
observer_notify_tsv_deleted (tsv);
xfree ((void *)tsv->name);
VEC_unordered_remove (tsv_s, tvariables, ix);
return;
}
warning (_("No trace variable named \"$%s\", not deleting"), name);
}
/* Throws an error if NAME is not valid syntax for a trace state
variable's name. */
void
validate_trace_state_variable_name (const char *name)
{
const char *p;
if (*name == '\0')
error (_("Must supply a non-empty variable name"));
/* All digits in the name is reserved for value history
references. */
for (p = name; isdigit (*p); p++)
;
if (*p == '\0')
error (_("$%s is not a valid trace state variable name"), name);
for (p = name; isalnum (*p) || *p == '_'; p++)
;
if (*p != '\0')
error (_("$%s is not a valid trace state variable name"), name);
}
/* The 'tvariable' command collects a name and optional expression to
evaluate into an initial value. */
static void
trace_variable_command (char *args, int from_tty)
{
struct cleanup *old_chain;
LONGEST initval = 0;
struct trace_state_variable *tsv;
char *name, *p;
if (!args || !*args)
error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
/* Only allow two syntaxes; "$name" and "$name=value". */
p = skip_spaces (args);
if (*p++ != '$')
error (_("Name of trace variable should start with '$'"));
name = p;
while (isalnum (*p) || *p == '_')
p++;
name = savestring (name, p - name);
old_chain = make_cleanup (xfree, name);
p = skip_spaces (p);
if (*p != '=' && *p != '\0')
error (_("Syntax must be $NAME [ = EXPR ]"));
validate_trace_state_variable_name (name);
if (*p == '=')
initval = value_as_long (parse_and_eval (++p));
/* If the variable already exists, just change its initial value. */
tsv = find_trace_state_variable (name);
if (tsv)
{
if (tsv->initial_value != initval)
{
tsv->initial_value = initval;
observer_notify_tsv_modified (tsv);
}
printf_filtered (_("Trace state variable $%s "
"now has initial value %s.\n"),
tsv->name, plongest (tsv->initial_value));
do_cleanups (old_chain);
return;
}
/* Create a new variable. */
tsv = create_trace_state_variable (name);
tsv->initial_value = initval;
observer_notify_tsv_created (tsv);
printf_filtered (_("Trace state variable $%s "
"created, with initial value %s.\n"),
tsv->name, plongest (tsv->initial_value));
do_cleanups (old_chain);
}
static void
delete_trace_variable_command (char *args, int from_tty)
{
int ix;
char **argv;
struct cleanup *back_to;
if (args == NULL)
{
if (query (_("Delete all trace state variables? ")))
VEC_free (tsv_s, tvariables);
dont_repeat ();
observer_notify_tsv_deleted (NULL);
return;
}
argv = gdb_buildargv (args);
back_to = make_cleanup_freeargv (argv);
for (ix = 0; argv[ix] != NULL; ix++)
{
if (*argv[ix] == '$')
delete_trace_state_variable (argv[ix] + 1);
else
warning (_("Name \"%s\" not prefixed with '$', ignoring"), argv[ix]);
}
do_cleanups (back_to);
dont_repeat ();
}
void
tvariables_info_1 (void)
{
struct trace_state_variable *tsv;
int ix;
int count = 0;
struct cleanup *back_to;
struct ui_out *uiout = current_uiout;
if (VEC_length (tsv_s, tvariables) == 0 && !ui_out_is_mi_like_p (uiout))
{
printf_filtered (_("No trace state variables.\n"));
return;
}
/* Try to acquire values from the target. */
for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix, ++count)
tsv->value_known = target_get_trace_state_variable_value (tsv->number,
&(tsv->value));
back_to = make_cleanup_ui_out_table_begin_end (uiout, 3,
count, "trace-variables");
ui_out_table_header (uiout, 15, ui_left, "name", "Name");
ui_out_table_header (uiout, 11, ui_left, "initial", "Initial");
ui_out_table_header (uiout, 11, ui_left, "current", "Current");
ui_out_table_body (uiout);
for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
{
struct cleanup *back_to2;
char *c;
char *name;
back_to2 = make_cleanup_ui_out_tuple_begin_end (uiout, "variable");
name = concat ("$", tsv->name, (char *) NULL);
make_cleanup (xfree, name);
ui_out_field_string (uiout, "name", name);
ui_out_field_string (uiout, "initial", plongest (tsv->initial_value));
if (tsv->value_known)
c = plongest (tsv->value);
else if (ui_out_is_mi_like_p (uiout))
/* For MI, we prefer not to use magic string constants, but rather
omit the field completely. The difference between unknown and
undefined does not seem important enough to represent. */
c = NULL;
else if (current_trace_status ()->running || traceframe_number >= 0)
/* The value is/was defined, but we don't have it. */
c = "<unknown>";
else
/* It is not meaningful to ask about the value. */
c = "<undefined>";
if (c)
ui_out_field_string (uiout, "current", c);
ui_out_text (uiout, "\n");
do_cleanups (back_to2);
}
do_cleanups (back_to);
}
/* List all the trace state variables. */
static void
tvariables_info (char *args, int from_tty)
{
tvariables_info_1 ();
}
/* Stash definitions of tsvs into the given file. */
void
save_trace_state_variables (struct ui_file *fp)
{
struct trace_state_variable *tsv;
int ix;
for (ix = 0; VEC_iterate (tsv_s, tvariables, ix, tsv); ++ix)
{
fprintf_unfiltered (fp, "tvariable $%s", tsv->name);
if (tsv->initial_value)
fprintf_unfiltered (fp, " = %s", plongest (tsv->initial_value));
fprintf_unfiltered (fp, "\n");
}
}
/* ACTIONS functions: */
/* The three functions:
collect_pseudocommand,
while_stepping_pseudocommand, and
end_actions_pseudocommand
are placeholders for "commands" that are actually ONLY to be used
within a tracepoint action list. If the actual function is ever called,
it means that somebody issued the "command" at the top level,
which is always an error. */
static void
end_actions_pseudocommand (char *args, int from_tty)
{
error (_("This command cannot be used at the top level."));
}
static void
while_stepping_pseudocommand (char *args, int from_tty)
{
error (_("This command can only be used in a tracepoint actions list."));
}
static void
collect_pseudocommand (char *args, int from_tty)
{
error (_("This command can only be used in a tracepoint actions list."));
}
static void
teval_pseudocommand (char *args, int from_tty)
{
error (_("This command can only be used in a tracepoint actions list."));
}
/* Parse any collection options, such as /s for strings. */
const char *
decode_agent_options (const char *exp, int *trace_string)
{
struct value_print_options opts;
*trace_string = 0;
if (*exp != '/')
return exp;
/* Call this to borrow the print elements default for collection
size. */
get_user_print_options (&opts);
exp++;
if (*exp == 's')
{
if (target_supports_string_tracing ())
{
/* Allow an optional decimal number giving an explicit maximum
string length, defaulting it to the "print elements" value;
so "collect/s80 mystr" gets at most 80 bytes of string. */
*trace_string = opts.print_max;
exp++;
if (*exp >= '0' && *exp <= '9')
*trace_string = atoi (exp);
while (*exp >= '0' && *exp <= '9')
exp++;
}
else
error (_("Target does not support \"/s\" option for string tracing."));
}
else
error (_("Undefined collection format \"%c\"."), *exp);
exp = skip_spaces_const (exp);
return exp;
}
/* Enter a list of actions for a tracepoint. */
static void
trace_actions_command (char *args, int from_tty)
{
struct tracepoint *t;
struct command_line *l;
t = get_tracepoint_by_number (&args, NULL);
if (t)
{
char *tmpbuf =
xstrprintf ("Enter actions for tracepoint %d, one per line.",
t->base.number);
struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
l = read_command_lines (tmpbuf, from_tty, 1,
check_tracepoint_command, t);
do_cleanups (cleanups);
breakpoint_set_commands (&t->base, l);
}
/* else just return */
}
/* Report the results of checking the agent expression, as errors or
internal errors. */
static void
report_agent_reqs_errors (struct agent_expr *aexpr)
{
/* All of the "flaws" are serious bytecode generation issues that
should never occur. */
if (aexpr->flaw != agent_flaw_none)
internal_error (__FILE__, __LINE__, _("expression is malformed"));
/* If analysis shows a stack underflow, GDB must have done something
badly wrong in its bytecode generation. */
if (aexpr->min_height < 0)
internal_error (__FILE__, __LINE__,
_("expression has min height < 0"));
/* Issue this error if the stack is predicted to get too deep. The
limit is rather arbitrary; a better scheme might be for the
target to report how much stack it will have available. The
depth roughly corresponds to parenthesization, so a limit of 20
amounts to 20 levels of expression nesting, which is actually
a pretty big hairy expression. */
if (aexpr->max_height > 20)
error (_("Expression is too complicated."));
}
/* worker function */
void
validate_actionline (const char *line, struct breakpoint *b)
{
struct cmd_list_element *c;
struct expression *exp = NULL;
struct cleanup *old_chain = NULL;
const char *tmp_p;
const char *p;
struct bp_location *loc;
struct agent_expr *aexpr;
struct tracepoint *t = (struct tracepoint *) b;
/* If EOF is typed, *line is NULL. */
if (line == NULL)
return;
p = skip_spaces_const (line);
/* Symbol lookup etc. */
if (*p == '\0') /* empty line: just prompt for another line. */
return;
if (*p == '#') /* comment line */
return;
c = lookup_cmd (&p, cmdlist, "", -1, 1);
if (c == 0)
error (_("`%s' is not a tracepoint action, or is ambiguous."), p);
if (cmd_cfunc_eq (c, collect_pseudocommand))
{
int trace_string = 0;
if (*p == '/')
p = decode_agent_options (p, &trace_string);
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
p = skip_spaces_const (p);
if (*p == '$') /* Look for special pseudo-symbols. */
{
if (0 == strncasecmp ("reg", p + 1, 3)
|| 0 == strncasecmp ("arg", p + 1, 3)
|| 0 == strncasecmp ("loc", p + 1, 3)
|| 0 == strncasecmp ("_ret", p + 1, 4)
|| 0 == strncasecmp ("_sdata", p + 1, 6))
{
p = strchr (p, ',');
continue;
}
/* else fall thru, treat p as an expression and parse it! */
}
tmp_p = p;
for (loc = t->base.loc; loc; loc = loc->next)
{
p = tmp_p;
exp = parse_exp_1 (&p, loc->address,
block_for_pc (loc->address), 1);
old_chain = make_cleanup (free_current_contents, &exp);
if (exp->elts[0].opcode == OP_VAR_VALUE)
{
if (SYMBOL_CLASS (exp->elts[2].symbol) == LOC_CONST)
{
error (_("constant `%s' (value %s) "
"will not be collected."),
SYMBOL_PRINT_NAME (exp->elts[2].symbol),
plongest (SYMBOL_VALUE (exp->elts[2].symbol)));
}
else if (SYMBOL_CLASS (exp->elts[2].symbol)
== LOC_OPTIMIZED_OUT)
{
error (_("`%s' is optimized away "
"and cannot be collected."),
SYMBOL_PRINT_NAME (exp->elts[2].symbol));
}
}
/* We have something to collect, make sure that the expr to
bytecode translator can handle it and that it's not too
long. */
aexpr = gen_trace_for_expr (loc->address, exp, trace_string);
make_cleanup_free_agent_expr (aexpr);
if (aexpr->len > MAX_AGENT_EXPR_LEN)
error (_("Expression is too complicated."));
ax_reqs (aexpr);
report_agent_reqs_errors (aexpr);
do_cleanups (old_chain);
}
}
while (p && *p++ == ',');
}
else if (cmd_cfunc_eq (c, teval_pseudocommand))
{
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
p = skip_spaces_const (p);
tmp_p = p;
for (loc = t->base.loc; loc; loc = loc->next)
{
p = tmp_p;
/* Only expressions are allowed for this action. */
exp = parse_exp_1 (&p, loc->address,
block_for_pc (loc->address), 1);
old_chain = make_cleanup (free_current_contents, &exp);
/* We have something to evaluate, make sure that the expr to
bytecode translator can handle it and that it's not too
long. */
aexpr = gen_eval_for_expr (loc->address, exp);
make_cleanup_free_agent_expr (aexpr);
if (aexpr->len > MAX_AGENT_EXPR_LEN)
error (_("Expression is too complicated."));
ax_reqs (aexpr);
report_agent_reqs_errors (aexpr);
do_cleanups (old_chain);
}
}
while (p && *p++ == ',');
}
else if (cmd_cfunc_eq (c, while_stepping_pseudocommand))
{
char *endp;
p = skip_spaces_const (p);
t->step_count = strtol (p, &endp, 0);
if (endp == p || t->step_count == 0)
error (_("while-stepping step count `%s' is malformed."), line);
p = endp;
}
else if (cmd_cfunc_eq (c, end_actions_pseudocommand))
;
else
error (_("`%s' is not a supported tracepoint action."), line);
}
enum {
memrange_absolute = -1
};
/* MEMRANGE functions: */
static int memrange_cmp (const void *, const void *);
/* Compare memranges for qsort. */
static int
memrange_cmp (const void *va, const void *vb)
{
const struct memrange *a = va, *b = vb;
if (a->type < b->type)
return -1;
if (a->type > b->type)
return 1;
if (a->type == memrange_absolute)
{
if ((bfd_vma) a->start < (bfd_vma) b->start)
return -1;
if ((bfd_vma) a->start > (bfd_vma) b->start)
return 1;
}
else
{
if (a->start < b->start)
return -1;
if (a->start > b->start)
return 1;
}
return 0;
}
/* Sort the memrange list using qsort, and merge adjacent memranges. */
static void
memrange_sortmerge (struct collection_list *memranges)
{
int a, b;
qsort (memranges->list, memranges->next_memrange,
sizeof (struct memrange), memrange_cmp);
if (memranges->next_memrange > 0)
{
for (a = 0, b = 1; b < memranges->next_memrange; b++)
{
/* If memrange b overlaps or is adjacent to memrange a,
merge them. */
if (memranges->list[a].type == memranges->list[b].type
&& memranges->list[b].start <= memranges->list[a].end)
{
if (memranges->list[b].end > memranges->list[a].end)
memranges->list[a].end = memranges->list[b].end;
continue; /* next b, same a */
}
a++; /* next a */
if (a != b)
memcpy (&memranges->list[a], &memranges->list[b],
sizeof (struct memrange));
}
memranges->next_memrange = a + 1;
}
}
/* Add a register to a collection list. */
static void
add_register (struct collection_list *collection, unsigned int regno)
{
if (info_verbose)
printf_filtered ("collect register %d\n", regno);
if (regno >= (8 * sizeof (collection->regs_mask)))
error (_("Internal: register number %d too large for tracepoint"),
regno);
collection->regs_mask[regno / 8] |= 1 << (regno % 8);
}
/* Add a memrange to a collection list. */
static void
add_memrange (struct collection_list *memranges,
int type, bfd_signed_vma base,
unsigned long len)
{
if (info_verbose)
{
printf_filtered ("(%d,", type);
printf_vma (base);
printf_filtered (",%ld)\n", len);
}
/* type: memrange_absolute == memory, other n == basereg */
memranges->list[memranges->next_memrange].type = type;
/* base: addr if memory, offset if reg relative. */
memranges->list[memranges->next_memrange].start = base;
/* len: we actually save end (base + len) for convenience */
memranges->list[memranges->next_memrange].end = base + len;
memranges->next_memrange++;
if (memranges->next_memrange >= memranges->listsize)
{
memranges->listsize *= 2;
memranges->list = xrealloc (memranges->list,
memranges->listsize);
}
if (type != memrange_absolute) /* Better collect the base register! */
add_register (memranges, type);
}
/* Add a symbol to a collection list. */
static void
collect_symbol (struct collection_list *collect,
struct symbol *sym,
struct gdbarch *gdbarch,
long frame_regno, long frame_offset,
CORE_ADDR scope,
int trace_string)
{
unsigned long len;
unsigned int reg;
bfd_signed_vma offset;
int treat_as_expr = 0;
len = TYPE_LENGTH (check_typedef (SYMBOL_TYPE (sym)));
switch (SYMBOL_CLASS (sym))
{
default:
printf_filtered ("%s: don't know symbol class %d\n",
SYMBOL_PRINT_NAME (sym),
SYMBOL_CLASS (sym));
break;
case LOC_CONST:
printf_filtered ("constant %s (value %s) will not be collected.\n",
SYMBOL_PRINT_NAME (sym), plongest (SYMBOL_VALUE (sym)));
break;
case LOC_STATIC:
offset = SYMBOL_VALUE_ADDRESS (sym);
if (info_verbose)
{
char tmp[40];
sprintf_vma (tmp, offset);
printf_filtered ("LOC_STATIC %s: collect %ld bytes at %s.\n",
SYMBOL_PRINT_NAME (sym), len,
tmp /* address */);
}
/* A struct may be a C++ class with static fields, go to general
expression handling. */
if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
treat_as_expr = 1;
else