1 //===-- Value.h -------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Value_h_
11 #define liblldb_Value_h_
17 // Other libraries and framework includes
19 #include "lldb/lldb-private.h"
20 #include "lldb/Core/ClangForward.h"
21 #include "lldb/Core/DataBufferHeap.h"
22 #include "lldb/Core/Error.h"
23 #include "lldb/Core/Scalar.h"
24 #include "lldb/Symbol/ClangASTType.h"
26 namespace lldb_private {
32 // Values Less than zero are an error, greater than or equal to zero
33 // returns what the Scalar result is.
36 // m_value contains...
37 // ============================
38 eValueTypeScalar, // raw scalar value
39 eValueTypeVector, // byte array of m_vector.length with endianness of m_vector.byte_order
40 eValueTypeFileAddress, // file address value
41 eValueTypeLoadAddress, // load address value
42 eValueTypeHostAddress // host address value (for memory in the process that is using liblldb)
45 enum ContextType // Type that describes Value::m_context
47 // m_context contains...
48 // ====================
49 eContextTypeInvalid, // undefined
50 eContextTypeRegisterInfo, // RegisterInfo * (can be a scalar or a vector register)
51 eContextTypeLLDBType, // lldb_private::Type *
52 eContextTypeVariable // lldb_private::Variable *
55 const static size_t kMaxByteSize = 32u;
59 // The byte array must be big enough to hold vector registers for any supported target.
60 uint8_t bytes[kMaxByteSize];
62 lldb::ByteOrder byte_order;
66 byte_order(lldb::eByteOrderInvalid)
70 Vector(const Vector& vector)
74 operator=(const Vector& vector)
76 SetBytes(vector.bytes, vector.length, vector.byte_order);
87 SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
89 this->length = length;
90 this->byte_order = byte_order;
92 ::memcpy(this->bytes, bytes, length < kMaxByteSize ? length : kMaxByteSize);
99 return (length > 0 && length < kMaxByteSize && byte_order != lldb::eByteOrderInvalid);
101 // Casts a vector, if valid, to an unsigned int of matching or largest supported size.
102 // Truncates to the beginning of the vector if required.
103 // Returns a default constructed Scalar if the Vector data is internally inconsistent.
110 if (length == 1) scalar = *(const uint8_t *)bytes;
111 else if (length == 2) scalar = *(const uint16_t *)bytes;
112 else if (length == 4) scalar = *(const uint32_t *)bytes;
113 else if (length == 8) scalar = *(const uint64_t *)bytes;
114 #if defined (ENABLE_128_BIT_SUPPORT)
115 else if (length >= 16) scalar = *(const __uint128_t *)bytes;
117 else if (length >= 16) scalar = *(const __uint64_t *)bytes;
125 Value(const Scalar& scalar);
126 Value(const Vector& vector);
127 Value(const uint8_t *bytes, int len);
128 Value(const Value &rhs);
131 operator=(const Value &rhs);
137 SetClangType (const ClangASTType &clang_type);
140 GetValueType() const;
143 GetValueAddressType () const;
146 GetContextType() const
148 return m_context_type;
152 SetValueType (ValueType value_type)
154 m_value_type = value_type;
161 m_context_type = eContextTypeInvalid;
165 SetContext (ContextType context_type, void *p)
167 m_context_type = context_type;
169 if (m_context_type == eContextTypeRegisterInfo) {
170 RegisterInfo *reg_info = GetRegisterInfo();
171 if (reg_info->encoding == lldb::eEncodingVector)
172 SetValueType(eValueTypeVector);
174 SetValueType(eValueTypeScalar);
179 GetRegisterInfo() const;
185 ResolveValue (ExecutionContext *exe_ctx);
212 SetVectorBytes(const Vector& vector)
215 return m_vector.IsValid();
219 SetVectorBytes(uint8_t *bytes, size_t length, lldb::ByteOrder byte_order)
221 return m_vector.SetBytes(bytes, length, byte_order);
225 SetScalarFromVector()
227 if (m_vector.IsValid())
229 m_value = m_vector.GetAsScalar();
236 ResizeData(size_t len);
239 ValueOf(ExecutionContext *exe_ctx);
248 GetValueDefaultFormat ();
251 GetValueByteSize (Error *error_ptr);
254 GetValueAsData (ExecutionContext *exe_ctx,
256 uint32_t data_offset,
257 Module *module); // Can be NULL
260 GetValueTypeAsCString (ValueType context_type);
263 GetContextTypeAsCString (ContextType context_type);
266 GetData (DataExtractor &data);
274 ClangASTType m_clang_type;
276 ValueType m_value_type;
277 ContextType m_context_type;
278 DataBufferHeap m_data_buffer;
289 ValueList (const ValueList &rhs);
295 const ValueList & operator= (const ValueList &rhs);
297 // void InsertValue (Value *value, size_t idx);
298 void PushValue (const Value &value);
301 Value *GetValueAtIndex(size_t idx);
307 typedef std::vector<Value> collection;
312 } // namespace lldb_private
314 #endif // liblldb_Value_h_