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 void *bytes, int len);
128 Value(const Value &rhs);
131 SetBytes (const void *bytes, int len);
134 AppendBytes (const void *bytes, int len);
137 operator=(const Value &rhs);
143 SetClangType (const ClangASTType &clang_type);
146 GetValueType() const;
149 GetValueAddressType () const;
152 GetContextType() const
154 return m_context_type;
158 SetValueType (ValueType value_type)
160 m_value_type = value_type;
167 m_context_type = eContextTypeInvalid;
171 SetContext (ContextType context_type, void *p)
173 m_context_type = context_type;
175 if (m_context_type == eContextTypeRegisterInfo) {
176 RegisterInfo *reg_info = GetRegisterInfo();
177 if (reg_info->encoding == lldb::eEncodingVector)
178 SetValueType(eValueTypeVector);
180 SetValueType(eValueTypeScalar);
185 GetRegisterInfo() const;
191 ResolveValue (ExecutionContext *exe_ctx);
218 SetVectorBytes(const Vector& vector)
221 return m_vector.IsValid();
225 SetVectorBytes(uint8_t *bytes, size_t length, lldb::ByteOrder byte_order)
227 return m_vector.SetBytes(bytes, length, byte_order);
231 SetScalarFromVector()
233 if (m_vector.IsValid())
235 m_value = m_vector.GetAsScalar();
242 ResizeData(size_t len);
245 AppendDataToHostBuffer (const Value &rhs);
250 return m_data_buffer;
253 const DataBufferHeap &
256 return m_data_buffer;
260 ValueOf(ExecutionContext *exe_ctx);
269 GetValueDefaultFormat ();
272 GetValueByteSize (Error *error_ptr);
275 GetValueAsData (ExecutionContext *exe_ctx,
277 uint32_t data_offset,
278 Module *module); // Can be NULL
281 GetValueTypeAsCString (ValueType context_type);
284 GetContextTypeAsCString (ContextType context_type);
287 GetData (DataExtractor &data);
295 ClangASTType m_clang_type;
297 ValueType m_value_type;
298 ContextType m_context_type;
299 DataBufferHeap m_data_buffer;
310 ValueList (const ValueList &rhs);
316 const ValueList & operator= (const ValueList &rhs);
318 // void InsertValue (Value *value, size_t idx);
319 void PushValue (const Value &value);
322 Value *GetValueAtIndex(size_t idx);
328 typedef std::vector<Value> collection;
333 } // namespace lldb_private
335 #endif // liblldb_Value_h_