LLDB mainline
SBTraceCursor.h
Go to the documentation of this file.
1//===-- SBTraceCursor.h -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_API_SBTRACECURSOR_H
10#define LLDB_API_SBTRACECURSOR_H
11
12#include "lldb/API/SBDefines.h"
13#include "lldb/API/SBError.h"
15
16namespace lldb {
17
19public:
20 /// Default constructor for an invalid \a SBTraceCursor object.
22
24
26
27#ifndef SWIG
29
31#endif
32
34
35 /// Set the direction to use in the \a SBTraceCursor::Next() method.
36 ///
37 /// \param[in] forwards
38 /// If \b true, then the traversal will be forwards, otherwise backwards.
39 void SetForwards(bool forwards);
40
41 /// Check if the direction to use in the \a SBTraceCursor::Next() method is
42 /// forwards.
43 ///
44 /// \return
45 /// \b true if the current direction is forwards, \b false if backwards.
46 bool IsForwards() const;
47
48 /// Move the cursor to the next item (instruction or error).
49 ///
50 /// Direction:
51 /// The traversal is done following the current direction of the trace. If
52 /// it is forwards, the instructions are visited forwards
53 /// chronologically. Otherwise, the traversal is done in
54 /// the opposite direction. By default, a cursor moves backwards unless
55 /// changed with \a SBTraceCursor::SetForwards().
56 void Next();
57
58 /// \return
59 /// \b true if the cursor is pointing to a valid item. \b false if the
60 /// cursor has reached the end of the trace.
61 bool HasValue() const;
62
63 /// Instruction identifiers:
64 ///
65 /// When building complex higher level tools, fast random accesses in the
66 /// trace might be needed, for which each instruction requires a unique
67 /// identifier within its thread trace. For example, a tool might want to
68 /// repeatedly inspect random consecutive portions of a trace. This means that
69 /// it will need to first move quickly to the beginning of each section and
70 /// then start its iteration. Given that the number of instructions can be in
71 /// the order of hundreds of millions, fast random access is necessary.
72 ///
73 /// An example of such a tool could be an inspector of the call graph of a
74 /// trace, where each call is represented with its start and end instructions.
75 /// Inspecting all the instructions of a call requires moving to its first
76 /// instruction and then iterating until the last instruction, which following
77 /// the pattern explained above.
78 ///
79 /// Instead of using 0-based indices as identifiers, each Trace plug-in can
80 /// decide the nature of these identifiers and thus no assumptions can be made
81 /// regarding their ordering and sequentiality. The reason is that an
82 /// instruction might be encoded by the plug-in in a way that hides its actual
83 /// 0-based index in the trace, but it's still possible to efficiently find
84 /// it.
85 ///
86 /// Requirements:
87 /// - For a given thread, no two instructions have the same id.
88 /// - In terms of efficiency, moving the cursor to a given id should be as
89 /// fast as possible, but not necessarily O(1). That's why the recommended
90 /// way to traverse sequential instructions is to use the \a
91 /// SBTraceCursor::Next() method and only use \a SBTraceCursor::GoToId(id)
92 /// sparingly.
93
94 /// Make the cursor point to the item whose identifier is \p id.
95 ///
96 /// \return
97 /// \b true if the given identifier exists and the cursor effectively
98 /// moved to it. Otherwise, \b false is returned and the cursor now points
99 /// to an invalid item, i.e. calling \a HasValue() will return \b false.
100 bool GoToId(lldb::user_id_t id);
101
102 /// \return
103 /// \b true if and only if there's an instruction item with the given \p
104 /// id.
105 bool HasId(lldb::user_id_t id) const;
106
107 /// \return
108 /// A unique identifier for the instruction or error this cursor is
109 /// pointing to.
110 lldb::user_id_t GetId() const;
111 /// \}
112
113 /// Make the cursor point to an item in the trace based on an origin point and
114 /// an offset.
115 ///
116 /// The resulting position of the trace is
117 /// origin + offset
118 ///
119 /// If this resulting position would be out of bounds, the trace then points
120 /// to an invalid item, i.e. calling \a HasValue() returns \b false.
121 ///
122 /// \param[in] offset
123 /// How many items to move forwards (if positive) or backwards (if
124 /// negative) from the given origin point. For example, if origin is \b
125 /// End, then a negative offset would move backward in the trace, but a
126 /// positive offset would move past the trace to an invalid item.
127 ///
128 /// \param[in] origin
129 /// The reference point to use when moving the cursor.
130 ///
131 /// \return
132 /// \b true if and only if the cursor ends up pointing to a valid item.
133 bool Seek(int64_t offset, lldb::TraceCursorSeekType origin);
134
135 /// Trace item information (instructions, errors and events)
136 /// \{
137
138 /// \return
139 /// The kind of item the cursor is pointing at.
141
142 /// \return
143 /// Whether the cursor points to an error or not.
144 bool IsError() const;
145
146 /// \return
147 /// The error message the cursor is pointing at.
148 const char *GetError() const;
149
150 /// \return
151 /// Whether the cursor points to an event or not.
152 bool IsEvent() const;
153
154 /// \return
155 /// The specific kind of event the cursor is pointing at.
157
158 /// \return
159 /// A human-readable description of the event this cursor is pointing at.
160 const char *GetEventTypeAsString() const;
161
162 /// \return
163 /// Whether the cursor points to an instruction.
164 bool IsInstruction() const;
165
166 /// \return
167 /// The load address of the instruction the cursor is pointing at.
169
170 /// \return
171 /// The requested CPU id, or LLDB_INVALID_CPU_ID if this information is
172 /// not available for the current item.
173 lldb::cpu_id_t GetCPU() const;
174
175 bool IsValid() const;
176
177 explicit operator bool() const;
178
179protected:
180 friend class SBTrace;
181
182 /// Create a cursor that initially points to the end of the trace, i.e. the
183 /// most recent item.
184 SBTraceCursor(lldb::TraceCursorSP trace_cursor_sp);
185
187};
188} // namespace lldb
189
190#endif // LLDB_API_SBTRACECURSOR_H
#define LLDB_API
Definition SBDefines.h:28
lldb::user_id_t GetId() const
lldb::addr_t GetLoadAddress() const
lldb::TraceCursorSP m_opaque_sp
bool IsForwards() const
Check if the direction to use in the SBTraceCursor::Next() method is forwards.
const char * GetEventTypeAsString() const
bool GoToId(lldb::user_id_t id)
Instruction identifiers:
bool IsInstruction() const
void Next()
Move the cursor to the next item (instruction or error).
const char * GetError() const
SBTraceCursor()
Default constructor for an invalid SBTraceCursor object.
lldb::TraceEvent GetEventType() const
lldb::TraceItemKind GetItemKind() const
Trace item information (instructions, errors and events)
lldb::SBTraceCursor & operator=(const lldb::SBTraceCursor &rhs)
void SetForwards(bool forwards)
Set the direction to use in the SBTraceCursor::Next() method.
lldb::cpu_id_t GetCPU() const
bool Seek(int64_t offset, lldb::TraceCursorSeekType origin)
Make the cursor point to an item in the trace based on an origin point and an offset.
bool HasId(lldb::user_id_t id) const
TraceEvent
Events that might happen during a trace session.
uint32_t cpu_id_t
Definition lldb-types.h:93
TraceCursorSeekType
Enum to indicate the reference point when invoking TraceCursor::Seek().
std::shared_ptr< lldb_private::TraceCursor > TraceCursorSP
uint64_t user_id_t
Definition lldb-types.h:83
uint64_t addr_t
Definition lldb-types.h:80