libclues
Linux C++ Tracing Library
Loading...
Searching...
No Matches
items.hxx
1#pragma once
2
3// C++
4#include <vector>
5
6// clues
7#include <clues/SystemCallItem.hxx>
8
9/*
10 * Various specializations of SystemCallItem are found in this header
11 */
12
13namespace clues::item {
14
16class ReturnValue :
17 public SystemCallItem {
18public:
19 explicit ReturnValue(const std::string_view short_name, const std::string_view long_name = {}) :
20 SystemCallItem{ItemType::RETVAL, short_name, long_name}
21 {}
22};
23
25
33class ValueParameter :
34 public SystemCallItem {
35public: // functions
36
37 explicit ValueParameter(
38 const ItemType type,
39 const std::string_view short_name,
40 const std::string_view long_name = {}) :
41 SystemCallItem{type, short_name, long_name} {
42 }
43};
44
46class ValueInParameter :
47 public ValueParameter {
48public: // functions
49
50 explicit ValueInParameter(
51 const std::string_view short_name,
52 const std::string_view long_name = {}) :
53 ValueParameter{ItemType::PARAM_IN, short_name, long_name} {
54 }
55};
56
58class ValueOutParameter :
59 public ValueParameter {
60public: // functions
61
62 explicit ValueOutParameter(
63 const std::string_view short_name,
64 const std::string_view long_name) :
65 ValueParameter{ItemType::PARAM_OUT, short_name, long_name} {
66 }
67};
68
70
76class PointerValue :
77 public SystemCallItem {
78public: // functions
79
80 explicit PointerValue(
81 const ItemType type,
82 const std::string_view short_name,
83 const std::string_view long_name) :
84 SystemCallItem{type, short_name, long_name} {
85 }
86};
87
89
94class PointerOutValue :
95 public PointerValue {
96public: // functions
97
98 explicit PointerOutValue(
99 const std::string_view short_name,
100 const std::string_view long_name = {},
101 const ItemType type = ItemType::PARAM_OUT) :
102 PointerValue{type, short_name, long_name} {
103 }
104};
105
107
112class PointerInValue :
113 public PointerValue {
114public: // functions
115
116 explicit PointerInValue(
117 const std::string_view short_name,
118 const std::string_view long_name = {}) :
119 PointerValue{ItemType::PARAM_IN, short_name, long_name} {
120 }
121};
122
123class CLUES_API GenericPointerValue :
124 public PointerValue {
125public: // functions
126
127 explicit GenericPointerValue(
128 const std::string_view short_name,
129 const std::string_view long_name = {},
130 const ItemType type = ItemType::PARAM_IN) :
131 PointerValue{type, short_name, long_name} {
132 }
133
134 std::string str() const override;
135
136 ForeignPtr ptr() const {
138 }
139
140protected: // functions
141
142 void processValue(const Tracee &) override {}
143 void updateData(const Tracee &) override {}
144};
145
147
152class CLUES_API BufferPointer :
153 public PointerValue {
154public: // functions
155
156 explicit BufferPointer(
157 const SystemCallItem &size_par,
158 const ItemType type,
159 const std::string_view short_name,
160 const std::string_view long_name = {}) :
161 PointerValue{type, short_name, long_name},
162 m_size_par{size_par} {
163 if (type == ItemType::PARAM_IN) {
164 /*
165 * currently needed for write(), but other system
166 * calls might be affected, too.
167 */
169 }
170 }
171
172 const auto& data() const {
173 return m_data;
174 }
175
177
185 size_t availableBytes() const;
186
187 std::string str() const override;
188
189protected: // functions
190
191 void processValue(const Tracee &) override;
192 void updateData(const Tracee &) override;
193
194 void fillBuffer(const Tracee &);
195
196protected: // data
197
198 const SystemCallItem &m_size_par;
199 std::vector<uint8_t> m_data;
200};
201
203
207template <typename INT>
208class CLUES_API PointerToScalar :
209 public PointerValue {
210public: // functions
211
212 explicit PointerToScalar(
213 const std::string_view short_name,
214 const std::string_view long_name = {},
215 const ItemType type = ItemType::PARAM_OUT) :
216 PointerValue{type, short_name, long_name} {
217 }
218
219 ForeignPtr pointer() const {
220 return m_ptr;
221 }
222
223 std::optional<INT> value() const {
224 return m_val;
225 }
226
227 std::string str() const override;
228
229 void setBase(const Base base) {
230 m_base = base;
231 }
232
233protected: // functions
234
235 void processValue(const Tracee &tracee) override {
236 m_ptr = valueAs<ForeignPtr>();
237
238 if (isIn() || isInOut()) {
239 fetchValue(tracee);
240 } else {
241 m_val.reset();
242 }
243 }
244
245 void updateData(const Tracee &tracee) override {
246 if (needsUpdate()) {
247 fetchValue(tracee);
248 }
249 }
250
251 void fetchValue(const Tracee &tracee);
252
253 virtual std::string scalarToString() const;
254
255protected: // data
256
257 ForeignPtr m_ptr = ForeignPtr{};
258 std::optional<INT> m_val;
259 Base m_base = Base::DEC;
260};
261
263template <typename INT>
264class CLUES_API IntValueT :
265 public ValueParameter {
266public: // functions
267
268 explicit IntValueT(
269 const std::string_view short_name,
270 const std::string_view long_name = {},
271 const ItemType type = ItemType::PARAM_IN) :
272 ValueParameter{type, short_name, long_name} {
273 }
274
275 INT value() const {
276 return m_value;
277 }
278
279 std::string str() const override;
280
281 void setBase(const Base base) {
282 m_base = base;
283 }
284
285protected: // functions
286
287 void processValue(const Tracee &) override {
288 m_value = valueAs<INT>();
289 }
290
291protected: // data
292
293 INT m_value = 0;
294 Base m_base = Base::DEC;
295};
296
297using IntValue = IntValueT<int>;
298using UintValue = IntValueT<unsigned int>;
299using Uint32Value = IntValueT<uint32_t>;
300using ULongValue = IntValueT<unsigned long>;
301using SizeValue = IntValueT<size_t>;
302using OffsetValue = IntValueT<off_t>;
303
305
311CLUES_API extern SystemCallItem unused;
312
313inline bool is_unused_par(const SystemCallItem &item) {
314 return &item == &unused;
315}
316
318struct UnknownItem :
319 public ValueInParameter {
320
321 UnknownItem() :
322 ValueInParameter{"unknown"} {
323 }
324
325 std::string str() const override {
326 return "<yet unsupported system call>";
327 }
328};
329
330} // end ns
Base class for any kind of system call parameter or return value.
bool needsUpdate() const
Returns whether the item needs to be updated after the system call is finished.
Flags m_flags
Flags influencing the processing of the item.
OTHER valueAs() const
Helper to cast the strongly typed Word m_val to other strong enum types.
SystemCallItem(const ItemType type, const std::string_view short_name={}, const std::string_view long_name={})
Constructs a new SystemCallItem.
@ DEFER_FILL
Only fill in this item after all other items have been filled.
Base class for traced processes.
Definition Tracee.hxx:39
std::string str() const override
Returns a human readable string representation of the item.
Definition items.cxx:126
size_t availableBytes() const
Returns the actual number of input bytes available in the Tracee.
Definition items.cxx:122
void updateData(const Tracee &) override
Called upon exit of the system call to update possible out parameters.
Definition items.cxx:101
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition items.cxx:91
void updateData(const Tracee &) override
Called upon exit of the system call to update possible out parameters.
Definition items.hxx:143
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition items.hxx:142
std::string str() const override
Returns a human readable string representation of the item.
Definition items.cxx:34
std::string str() const override
Returns a human readable string representation of the item.
Definition items.cxx:45
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
Definition items.hxx:287
void updateData(const Tracee &tracee) override
Called upon exit of the system call to update possible out parameters.
Definition items.hxx:245
std::string str() const override
Returns a human readable string representation of the item.
Definition items.cxx:68
void processValue(const Tracee &tracee) override
Processes the value stored in m_val acc. to the actual item type.
Definition items.hxx:235
ItemType
Basic type of a SystemCallItem.
@ PARAM_OUT
An output parameter filled by in by the system call.
@ PARAM_IN
An input parameter to the system call.
@ RETVAL
A system call return value.
Base
Integer number display base for formatting purposes.
Definition types.hxx:129
ForeignPtr
Strongly typed opaque pointer to tracee memory.
Definition types.hxx:140
std::string str() const override
Returns a human readable string representation of the item.
Definition items.hxx:325