GDB (xrefs)
Loading...
Searching...
No Matches
tracepoint.h
Go to the documentation of this file.
1/* Data structures associated with tracepoints in GDB.
2 Copyright (C) 1997-2023 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#if !defined (TRACEPOINT_H)
20#define TRACEPOINT_H 1
21
22#include "breakpoint.h"
23#include "memrange.h"
24#include "gdbsupport/gdb_vecs.h"
25
26#include <vector>
27#include <string>
28
29/* An object describing the contents of a traceframe. */
30
32{
33 /* Collected memory. */
34 std::vector<mem_range> memory;
35
36 /* Collected trace state variables. */
37 std::vector<int> tvars;
38};
39
40typedef std::unique_ptr<traceframe_info> traceframe_info_up;
41
42/* A trace state variable is a value managed by a target being
43 traced. A trace state variable (or tsv for short) can be accessed
44 and assigned to by tracepoint actions and conditionals, but is not
45 part of the program being traced, and it doesn't have to be
46 collected. Effectively the variables are scratch space for
47 tracepoints. */
48
50{
51 trace_state_variable (std::string &&name_, int number_)
52 : name (name_), number (number_)
53 {}
54
55 /* The variable's name. The user has to prefix with a dollar sign,
56 but we don't store that internally. */
57 std::string name;
58
59 /* An id number assigned by GDB, and transmitted to targets. */
60 int number = 0;
61
62 /* The initial value of a variable is a 64-bit signed integer. */
63 LONGEST initial_value = 0;
64
65 /* 1 if the value is known, else 0. The value is known during a
66 trace run, or in tfind mode if the variable was collected into
67 the current trace frame. */
68 int value_known = 0;
69
70 /* The value of a variable is a 64-bit signed integer. */
71 LONGEST value = 0;
72
73 /* This is true for variables that are predefined and built into
74 the target. */
75 int builtin = 0;
76 };
77
78/* The trace status encompasses various info about the general state
79 of the tracing run. */
80
91
93{
94 /* If the status is coming from a file rather than a live target,
95 this points at the file's filename. Otherwise, this is NULL. */
96 const char *filename;
97
98 /* This is true if the value of the running field is known. */
100
101 /* This is true when the trace experiment is actually running. */
103
105
106 /* If stop_reason is tracepoint_passcount or tracepoint_error, this
107 is the (on-target) number of the tracepoint which caused the
108 stop. */
110
111 /* If stop_reason is tstop_command or tracepoint_error, this is an
112 arbitrary string that may describe the reason for the stop in
113 more detail. */
114
116
117 /* Number of traceframes currently in the buffer. */
118
120
121 /* Number of traceframes created since start of run. */
122
124
125 /* Total size of the target's trace buffer. */
126
128
129 /* Unused bytes left in the target's trace buffer. */
130
132
133 /* 1 if the target will continue tracing after disconnection, else
134 0. If the target does not report a value, assume 0. */
135
137
138 /* 1 if the target is using a circular trace buffer, else 0. If the
139 target does not report a value, assume 0. */
140
142
143 /* The "name" of the person running the trace. This is an
144 arbitrary string. */
145
147
148 /* "Notes" about the trace. This is an arbitrary string not
149 interpreted by GDBserver in any special way. */
150
151 char *notes;
152
153 /* The calendar times at which the trace run started and stopped,
154 both expressed in microseconds of Unix time. */
155
156 LONGEST start_time;
157 LONGEST stop_time;
158};
159
161
162extern std::string default_collect;
163
164extern int trace_regblock_size;
165
166extern const char *stop_reason_names[];
167
168/* Struct to collect random info about tracepoints on the target. */
169
171{
172 int number = 0;
174 ULONGEST addr = 0;
175 int enabled = 0;
176 int step = 0;
177 int pass = 0;
178 int orig_size = 0;
179
180 /* String that is the encoded form of the tracepoint's condition. */
181 gdb::unique_xmalloc_ptr<char[]> cond;
182
183 /* Vectors of strings that are the encoded forms of a tracepoint's
184 actions. */
185 std::vector<gdb::unique_xmalloc_ptr<char[]>> actions;
186 std::vector<gdb::unique_xmalloc_ptr<char[]>> step_actions;
187
188 /* The original string defining the location of the tracepoint. */
189 gdb::unique_xmalloc_ptr<char[]> at_string;
190
191 /* The original string defining the tracepoint's condition. */
192 gdb::unique_xmalloc_ptr<char[]> cond_string;
193
194 /* List of original strings defining the tracepoint's actions. */
195 std::vector<gdb::unique_xmalloc_ptr<char[]>> cmd_strings;
196
197 /* The tracepoint's current hit count. */
198 int hit_count = 0;
199
200 /* The tracepoint's current traceframe usage. */
201 ULONGEST traceframe_usage = 0;
202
203 struct uploaded_tp *next = nullptr;
204};
205
206/* Struct recording info about trace state variables on the target. */
207
209{
210 const char *name;
215};
216
217/* Struct recording info about a target static tracepoint marker. */
218
220{
222
226
227 struct gdbarch *gdbarch = NULL;
228 CORE_ADDR address = 0;
229
230 /* The string ID of the marker. */
231 std::string str_id;
232
233 /* Extra target reported info associated with the marker. */
234 std::string extra;
235};
236
238{
239 memrange (int type_, bfd_signed_vma start_, bfd_signed_vma end_)
240 : type (type_), start (start_), end (end_)
241 {}
242
244 {}
245
246 /* memrange_absolute for absolute memory range, else basereg
247 number. */
248 int type;
249 bfd_signed_vma start;
250 bfd_signed_vma end;
251};
252
254{
255public:
257
258 void add_wholly_collected (const char *print_name);
259
260 void append_exp (std::string &&exp);
261
262 /* Add AEXPR to the list, taking ownership. */
263 void add_aexpr (agent_expr_up aexpr);
264
265 void add_remote_register (unsigned int regno);
266 void add_ax_registers (struct agent_expr *aexpr);
267 void add_local_register (struct gdbarch *gdbarch,
268 unsigned int regno,
269 CORE_ADDR scope);
270 void add_memrange (struct gdbarch *gdbarch,
271 int type, bfd_signed_vma base,
272 unsigned long len, CORE_ADDR scope);
273 void collect_symbol (struct symbol *sym,
274 struct gdbarch *gdbarch,
275 long frame_regno, long frame_offset,
276 CORE_ADDR scope,
277 int trace_string);
278
279 void add_local_symbols (struct gdbarch *gdbarch, CORE_ADDR pc,
280 long frame_regno, long frame_offset, int type,
281 int trace_string);
282 void add_static_trace_data ();
283
284 void finish ();
285
286 std::vector<std::string> stringify ();
287
288 const std::vector<std::string> &wholly_collected ()
289 { return m_wholly_collected; }
290
291 const std::vector<std::string> &computed ()
292 { return m_computed; }
293
294private:
295 /* We need the allocator zero-initialize the mask, so we don't use
296 gdb::byte_vector. */
297 std::vector<unsigned char> m_regs_mask;
298
299 std::vector<memrange> m_memranges;
300
301 std::vector<agent_expr_up> m_aexprs;
302
303 /* True is the user requested a collection of "$_sdata", "static
304 tracepoint data". */
306
307 /* A set of names of wholly collected objects. */
308 std::vector<std::string> m_wholly_collected;
309 /* A set of computed expressions. */
310 std::vector<std::string> m_computed;
311};
312
313extern void
314 parse_static_tracepoint_marker_definition (const char *line, const char **pp,
316
317/* Returns the current traceframe number. */
318extern int get_traceframe_number (void);
319
320/* Returns the tracepoint number for current traceframe. */
321extern int get_tracepoint_number (void);
322
323/* Make the traceframe NUM be the current trace frame, all the way to
324 the target, and flushes all global state (register/frame caches,
325 etc.). */
326extern void set_current_traceframe (int num);
327
344
345extern const char *decode_agent_options (const char *exp, int *trace_string);
346
347extern void encode_actions (struct bp_location *tloc,
348 struct collection_list *tracepoint_list,
349 struct collection_list *stepping_list);
350
351extern void encode_actions_rsp (struct bp_location *tloc,
352 std::vector<std::string> *tdp_actions,
353 std::vector<std::string> *stepping_actions);
354
355extern void validate_actionline (const char *, tracepoint *);
356extern void validate_trace_state_variable_name (const char *name);
357
358extern struct trace_state_variable *find_trace_state_variable (const char *name);
359extern struct trace_state_variable *
361
362extern struct trace_state_variable *create_trace_state_variable (const char *name);
363
364extern int encode_source_string (int num, ULONGEST addr,
365 const char *srctype, const char *src,
366 char *buf, int buf_size);
367
368extern void parse_trace_status (const char *line, struct trace_status *ts);
369
370extern void parse_tracepoint_status (const char *p, tracepoint *tp,
371 struct uploaded_tp *utp);
372
373extern void parse_tracepoint_definition (const char *line,
374 struct uploaded_tp **utpp);
375extern void parse_tsv_definition (const char *line, struct uploaded_tsv **utsvp);
376
377extern struct uploaded_tp *get_uploaded_tp (int num, ULONGEST addr,
378 struct uploaded_tp **utpp);
379extern void free_uploaded_tps (struct uploaded_tp **utpp);
380
381extern struct uploaded_tsv *get_uploaded_tsv (int num,
382 struct uploaded_tsv **utsvp);
383extern void free_uploaded_tsvs (struct uploaded_tsv **utsvp);
384extern struct tracepoint *create_tracepoint_from_upload (struct uploaded_tp *utp);
385extern void merge_uploaded_tracepoints (struct uploaded_tp **utpp);
386extern void merge_uploaded_trace_state_variables (struct uploaded_tsv **utsvp);
387
388extern void query_if_trace_running (int from_tty);
389extern void disconnect_tracing (void);
390extern void trace_reset_local_state (void);
391
392extern void check_trace_running (struct trace_status *);
393
394extern void start_tracing (const char *notes);
395extern void stop_tracing (const char *notes);
396
397extern void trace_status_mi (int on_stop);
398
399extern void tvariables_info_1 (void);
400extern void save_trace_state_variables (struct ui_file *fp);
401
402/* Enumeration of the kinds of traceframe searches that a target may
403 be able to perform. */
404
413
414extern void tfind_1 (enum trace_find_type type, int num,
415 CORE_ADDR addr1, CORE_ADDR addr2,
416 int from_tty);
417
418extern void trace_save_tfile (const char *filename,
419 int target_does_save);
420extern void trace_save_ctf (const char *dirname,
421 int target_does_save);
422
423extern traceframe_info_up parse_traceframe_info (const char *tframe_info);
424
425extern int traceframe_available_memory (std::vector<mem_range> *result,
426 CORE_ADDR memaddr, ULONGEST len);
427
428extern struct traceframe_info *get_traceframe_info (void);
429
430extern struct bp_location *get_traceframe_location (int *stepping_frame_p);
431
432/* Command element for the 'while-stepping' command. */
434
435#endif /* TRACEPOINT_H */
const char *const name
std::unique_ptr< agent_expr > agent_expr_up
Definition ax.h:147
bptype
Definition breakpoint.h:84
@ bp_none
Definition breakpoint.h:85
std::vector< memrange > m_memranges
Definition tracepoint.h:299
const std::vector< std::string > & wholly_collected()
Definition tracepoint.h:288
const std::vector< std::string > & computed()
Definition tracepoint.h:291
std::vector< std::string > stringify()
void collect_symbol(struct symbol *sym, struct gdbarch *gdbarch, long frame_regno, long frame_offset, CORE_ADDR scope, int trace_string)
Definition tracepoint.c:908
void add_wholly_collected(const char *print_name)
std::vector< std::string > m_wholly_collected
Definition tracepoint.h:308
std::vector< unsigned char > m_regs_mask
Definition tracepoint.h:297
void add_remote_register(unsigned int regno)
Definition tracepoint.c:822
void append_exp(std::string &&exp)
void add_local_symbols(struct gdbarch *gdbarch, CORE_ADDR pc, long frame_regno, long frame_offset, int type, int trace_string)
std::vector< std::string > m_computed
Definition tracepoint.h:310
std::vector< agent_expr_up > m_aexprs
Definition tracepoint.h:301
void add_ax_registers(struct agent_expr *aexpr)
Definition tracepoint.c:835
void add_static_trace_data()
void add_local_register(struct gdbarch *gdbarch, unsigned int regno, CORE_ADDR scope)
Definition tracepoint.c:854
void add_aexpr(agent_expr_up aexpr)
void add_memrange(struct gdbarch *gdbarch, int type, bfd_signed_vma base, unsigned long len, CORE_ADDR scope)
Definition tracepoint.c:889
memrange(int type_, bfd_signed_vma start_, bfd_signed_vma end_)
Definition tracepoint.h:239
bfd_signed_vma end
Definition tracepoint.h:250
bfd_signed_vma start
Definition tracepoint.h:249
DISABLE_COPY_AND_ASSIGN(scoped_restore_current_traceframe)
static_tracepoint_marker & operator=(static_tracepoint_marker &&)=default
DISABLE_COPY_AND_ASSIGN(static_tracepoint_marker)
static_tracepoint_marker(static_tracepoint_marker &&)=default
static_tracepoint_marker()=default
trace_state_variable(std::string &&name_, int number_)
Definition tracepoint.h:51
int disconnected_tracing
Definition tracepoint.h:136
int running_known
Definition tracepoint.h:99
char * stop_desc
Definition tracepoint.h:115
int traceframes_created
Definition tracepoint.h:123
LONGEST stop_time
Definition tracepoint.h:157
LONGEST start_time
Definition tracepoint.h:156
int stopping_tracepoint
Definition tracepoint.h:109
int circular_buffer
Definition tracepoint.h:141
char * user_name
Definition tracepoint.h:146
int traceframe_count
Definition tracepoint.h:119
const char * filename
Definition tracepoint.h:96
enum trace_stop_reason stop_reason
Definition tracepoint.h:104
std::vector< mem_range > memory
Definition tracepoint.h:34
std::vector< int > tvars
Definition tracepoint.h:37
std::vector< gdb::unique_xmalloc_ptr< char[]> > cmd_strings
Definition tracepoint.h:195
gdb::unique_xmalloc_ptr< char[]> cond_string
Definition tracepoint.h:192
std::vector< gdb::unique_xmalloc_ptr< char[]> > step_actions
Definition tracepoint.h:186
ULONGEST traceframe_usage
Definition tracepoint.h:201
std::vector< gdb::unique_xmalloc_ptr< char[]> > actions
Definition tracepoint.h:185
ULONGEST addr
Definition tracepoint.h:174
gdb::unique_xmalloc_ptr< char[]> at_string
Definition tracepoint.h:189
gdb::unique_xmalloc_ptr< char[]> cond
Definition tracepoint.h:181
const char * name
Definition tracepoint.h:210
LONGEST initial_value
Definition tracepoint.h:212
struct uploaded_tsv * next
Definition tracepoint.h:214
Definition value.h:130
void validate_actionline(const char *, tracepoint *)
Definition tracepoint.c:629
int get_tracepoint_number(void)
std::unique_ptr< traceframe_info > traceframe_info_up
Definition tracepoint.h:40
struct trace_state_variable * find_trace_state_variable(const char *name)
Definition tracepoint.c:263
struct traceframe_info * get_traceframe_info(void)
void stop_tracing(const char *notes)
struct trace_status * current_trace_status(void)
Definition tracepoint.c:175
const char * stop_reason_names[]
Definition tracepoint.c:164
void parse_trace_status(const char *line, struct trace_status *ts)
void disconnect_tracing(void)
void parse_tracepoint_status(const char *p, tracepoint *tp, struct uploaded_tp *utp)
int get_traceframe_number(void)
void save_trace_state_variables(struct ui_file *fp)
Definition tracepoint.c:476
struct trace_state_variable * find_trace_state_variable_by_number(int number)
Definition tracepoint.c:276
cmd_list_element * while_stepping_cmd_element
void encode_actions_rsp(struct bp_location *tloc, std::vector< std::string > *tdp_actions, std::vector< std::string > *stepping_actions)
struct uploaded_tp * get_uploaded_tp(int num, ULONGEST addr, struct uploaded_tp **utpp)
void check_trace_running(struct trace_status *)
void query_if_trace_running(int from_tty)
void parse_tsv_definition(const char *line, struct uploaded_tsv **utsvp)
void merge_uploaded_trace_state_variables(struct uploaded_tsv **utsvp)
void validate_trace_state_variable_name(const char *name)
Definition tracepoint.c:303
int trace_regblock_size
struct uploaded_tsv * get_uploaded_tsv(int num, struct uploaded_tsv **utsvp)
void start_tracing(const char *notes)
trace_stop_reason
Definition tracepoint.h:82
@ trace_buffer_full
Definition tracepoint.h:86
@ tracepoint_error
Definition tracepoint.h:89
@ trace_stop_command
Definition tracepoint.h:85
@ trace_disconnected
Definition tracepoint.h:87
@ tracepoint_passcount
Definition tracepoint.h:88
@ trace_never_run
Definition tracepoint.h:84
@ trace_stop_reason_unknown
Definition tracepoint.h:83
trace_find_type
Definition tracepoint.h:406
@ tfind_outside
Definition tracepoint.h:411
@ tfind_pc
Definition tracepoint.h:408
@ tfind_number
Definition tracepoint.h:407
@ tfind_range
Definition tracepoint.h:410
@ tfind_tp
Definition tracepoint.h:409
void tfind_1(enum trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int from_tty)
struct trace_state_variable * create_trace_state_variable(const char *name)
Definition tracepoint.c:254
void trace_reset_local_state(void)
void parse_static_tracepoint_marker_definition(const char *line, const char **pp, static_tracepoint_marker *marker)
int traceframe_available_memory(std::vector< mem_range > *result, CORE_ADDR memaddr, ULONGEST len)
struct bp_location * get_traceframe_location(int *stepping_frame_p)
std::string default_collect
Definition tracepoint.c:130
void tvariables_info_1(void)
Definition tracepoint.c:408
struct tracepoint * create_tracepoint_from_upload(struct uploaded_tp *utp)
void trace_save_tfile(const char *filename, int target_does_save)
Definition tracefile.c:361
void trace_status_mi(int on_stop)
traceframe_info_up parse_traceframe_info(const char *tframe_info)
void trace_save_ctf(const char *dirname, int target_does_save)
Definition tracefile.c:370
int encode_source_string(int num, ULONGEST addr, const char *srctype, const char *src, char *buf, int buf_size)
void free_uploaded_tps(struct uploaded_tp **utpp)
const char * decode_agent_options(const char *exp, int *trace_string)
Definition tracepoint.c:525
void merge_uploaded_tracepoints(struct uploaded_tp **utpp)
void set_current_traceframe(int num)
void parse_tracepoint_definition(const char *line, struct uploaded_tp **utpp)
void free_uploaded_tsvs(struct uploaded_tsv **utsvp)
void encode_actions(struct bp_location *tloc, struct collection_list *tracepoint_list, struct collection_list *stepping_list)