vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / dwarf / AttributeValue.h
blob3bc4c50d11df5f35d9f7774610da4b10da258c6e
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef ATTRIBUTE_VALUE_H
6 #define ATTRIBUTE_VALUE_H
8 #include "AttributeClasses.h"
9 #include "Types.h"
12 class DebugInfoEntry;
15 struct AttributeValue {
16 union {
17 target_addr_t address;
18 struct {
19 const void* data;
20 off_t length;
21 } block;
22 uint64 constant;
23 bool flag;
24 off_t pointer;
25 DebugInfoEntry* reference;
26 const char* string;
29 uint16 attributeForm;
30 uint8 attributeClass;
31 bool isSigned;
33 AttributeValue()
35 attributeClass(ATTRIBUTE_CLASS_UNKNOWN)
39 ~AttributeValue()
41 Unset();
44 void SetToAddress(target_addr_t address)
46 Unset();
47 attributeClass = ATTRIBUTE_CLASS_ADDRESS;
48 this->address = address;
51 void SetToBlock(const void* data, off_t length)
53 Unset();
54 attributeClass = ATTRIBUTE_CLASS_BLOCK;
55 block.data = data;
56 block.length = length;
59 void SetToConstant(uint64 value, bool isSigned)
61 Unset();
62 attributeClass = ATTRIBUTE_CLASS_CONSTANT;
63 this->constant = value;
64 this->isSigned = isSigned;
67 void SetToFlag(bool value)
69 Unset();
70 attributeClass = ATTRIBUTE_CLASS_FLAG;
71 this->flag = value;
74 void SetToLinePointer(off_t value)
76 Unset();
77 attributeClass = ATTRIBUTE_CLASS_LINEPTR;
78 this->pointer = value;
81 void SetToLocationListPointer(off_t value)
83 Unset();
84 attributeClass = ATTRIBUTE_CLASS_LOCLISTPTR;
85 this->pointer = value;
88 void SetToMacroPointer(off_t value)
90 Unset();
91 attributeClass = ATTRIBUTE_CLASS_MACPTR;
92 this->pointer = value;
95 void SetToRangeListPointer(off_t value)
97 Unset();
98 attributeClass = ATTRIBUTE_CLASS_RANGELISTPTR;
99 this->pointer = value;
102 void SetToReference(DebugInfoEntry* entry)
104 Unset();
105 attributeClass = ATTRIBUTE_CLASS_REFERENCE;
106 this->reference = entry;
109 void SetToString(const char* string)
111 Unset();
112 attributeClass = ATTRIBUTE_CLASS_STRING;
113 this->string = string;
116 void Unset()
118 attributeClass = ATTRIBUTE_CLASS_UNKNOWN;
121 const char* ToString(char* buffer, size_t size);
125 struct DynamicAttributeValue {
126 union {
127 uint64 constant;
128 DebugInfoEntry* reference;
129 struct {
130 const void* data;
131 off_t length;
132 } block;
134 uint8 attributeClass;
136 DynamicAttributeValue()
138 attributeClass(ATTRIBUTE_CLASS_UNKNOWN)
140 this->constant = 0;
143 bool IsValid() const
145 return attributeClass != ATTRIBUTE_CLASS_UNKNOWN;
148 void SetTo(uint64 constant)
150 this->constant = constant;
151 attributeClass = ATTRIBUTE_CLASS_CONSTANT;
154 void SetTo(DebugInfoEntry* reference)
156 this->reference = reference;
157 attributeClass = ATTRIBUTE_CLASS_REFERENCE;
160 void SetTo(const void* data, off_t length)
162 block.data = data;
163 block.length = length;
164 attributeClass = ATTRIBUTE_CLASS_BLOCK;
169 struct ConstantAttributeValue {
170 union {
171 uint64 constant;
172 const char* string;
173 struct {
174 const void* data;
175 off_t length;
176 } block;
178 uint8 attributeClass;
180 ConstantAttributeValue()
182 attributeClass(ATTRIBUTE_CLASS_UNKNOWN)
186 bool IsValid() const
188 return attributeClass != ATTRIBUTE_CLASS_UNKNOWN;
191 void SetTo(uint64 constant)
193 this->constant = constant;
194 attributeClass = ATTRIBUTE_CLASS_CONSTANT;
197 void SetTo(const char* string)
199 this->string = string;
200 attributeClass = ATTRIBUTE_CLASS_STRING;
203 void SetTo(const void* data, off_t length)
205 block.data = data;
206 block.length = length;
207 attributeClass = ATTRIBUTE_CLASS_BLOCK;
212 struct MemberLocation {
213 union {
214 uint64 constant;
215 off_t listOffset;
216 struct {
217 const void* data;
218 off_t length;
219 } expression;
221 uint8 attributeClass;
223 MemberLocation()
225 attributeClass(ATTRIBUTE_CLASS_UNKNOWN)
229 bool IsValid() const
231 return attributeClass != ATTRIBUTE_CLASS_UNKNOWN;
234 bool IsConstant() const
236 return attributeClass == ATTRIBUTE_CLASS_CONSTANT;
239 bool IsExpression() const
241 return attributeClass == ATTRIBUTE_CLASS_BLOCK
242 && expression.data != NULL;
245 bool IsLocationList() const
247 return attributeClass == ATTRIBUTE_CLASS_LOCLISTPTR;
250 void SetToConstant(uint64 constant)
252 this->constant = constant;
253 attributeClass = ATTRIBUTE_CLASS_CONSTANT;
256 void SetToExpression(const void* data, off_t length)
258 expression.data = data;
259 expression.length = length;
260 attributeClass = ATTRIBUTE_CLASS_BLOCK;
263 void SetToLocationList(off_t listOffset)
265 this->listOffset = listOffset;
266 attributeClass = ATTRIBUTE_CLASS_LOCLISTPTR;
271 struct LocationDescription {
272 union {
273 off_t listOffset; // location list
274 struct {
275 const void* data;
276 off_t length;
277 } expression; // location expression
279 uint8 attributeClass;
281 LocationDescription()
283 attributeClass(ATTRIBUTE_CLASS_BLOCK)
285 expression.data = NULL;
286 expression.length = 0;
289 bool IsExpression() const
291 return attributeClass == ATTRIBUTE_CLASS_BLOCK
292 && expression.data != NULL;
295 bool IsLocationList() const
297 return attributeClass == ATTRIBUTE_CLASS_LOCLISTPTR;
300 bool IsValid() const
302 return IsExpression() || IsLocationList();
305 void SetToLocationList(off_t offset)
307 listOffset = offset;
308 attributeClass = ATTRIBUTE_CLASS_LOCLISTPTR;
311 void SetToExpression(const void* data, off_t length)
313 expression.data = data;
314 expression.length = length;
315 attributeClass = ATTRIBUTE_CLASS_BLOCK;
320 struct DeclarationLocation {
321 uint32 file;
322 uint32 line;
323 uint32 column;
325 DeclarationLocation()
327 file(0xffffffff),
328 line(0xffffffff),
329 column(0xffffffff)
333 void SetFile(uint32 file)
335 this->file = file;
338 void SetLine(uint32 line)
340 this->line = line;
343 void SetColumn(uint32 column)
345 this->column = column;
348 bool IsFileSet() const
350 return file != 0xffffffff;
353 bool IsLineSet() const
355 return line != 0xffffffff;
358 bool IsColumnSet() const
360 return column != 0xffffffff;
364 #endif // ATTRIBUTE_VALUE_H