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/DataBufferHeap.h"
21 #include "lldb/Core/Error.h"
22 #include "lldb/Core/Scalar.h"
23 #include "lldb/Symbol/CompilerType.h"
25 namespace lldb_private {
30 // Values Less than zero are an error, greater than or equal to zero
31 // returns what the Scalar result is.
34 // m_value contains...
35 // ============================
36 eValueTypeScalar, // raw scalar value
37 eValueTypeVector, // byte array of m_vector.length with endianness of m_vector.byte_order
38 eValueTypeFileAddress, // file address value
39 eValueTypeLoadAddress, // load address value
40 eValueTypeHostAddress // host address value (for memory in the process that is using liblldb)
43 enum ContextType // Type that describes Value::m_context
45 // m_context contains...
46 // ====================
47 eContextTypeInvalid, // undefined
48 eContextTypeRegisterInfo, // RegisterInfo * (can be a scalar or a vector register)
49 eContextTypeLLDBType, // lldb_private::Type *
50 eContextTypeVariable // lldb_private::Variable *
53 const static size_t kMaxByteSize = 32u;
57 // The byte array must be big enough to hold vector registers for any supported target.
58 uint8_t bytes[kMaxByteSize];
60 lldb::ByteOrder byte_order;
64 byte_order(lldb::eByteOrderInvalid)
68 Vector(const Vector& vector)
72 operator=(const Vector& vector)
74 SetBytes(vector.bytes, vector.length, vector.byte_order);
85 SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
87 this->length = length;
88 this->byte_order = byte_order;
90 ::memcpy(this->bytes, bytes, length < kMaxByteSize ? length : kMaxByteSize);
97 return (length > 0 && length < kMaxByteSize && byte_order != lldb::eByteOrderInvalid);
99 // Casts a vector, if valid, to an unsigned int of matching or largest supported size.
100 // Truncates to the beginning of the vector if required.
101 // Returns a default constructed Scalar if the Vector data is internally inconsistent.
102 llvm::APInt rhs = llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)bytes)->x);
109 if (length == 1) scalar = *(const uint8_t *)bytes;
110 else if (length == 2) scalar = *(const uint16_t *)bytes;
111 else if (length == 4) scalar = *(const uint32_t *)bytes;
112 else if (length == 8) scalar = *(const uint64_t *)bytes;
113 else if (length >= 16) scalar = rhs;
120 Value(const Scalar& scalar);
121 Value(const Vector& vector);
122 Value(const void *bytes, int len);
123 Value(const Value &rhs);
126 SetBytes (const void *bytes, int len);
129 AppendBytes (const void *bytes, int len);
132 operator=(const Value &rhs);
138 SetCompilerType (const CompilerType &compiler_type);
141 GetValueType() const;
144 GetValueAddressType () const;
147 GetContextType() const
149 return m_context_type;
153 SetValueType (ValueType value_type)
155 m_value_type = value_type;
162 m_context_type = eContextTypeInvalid;
166 SetContext (ContextType context_type, void *p)
168 m_context_type = context_type;
170 if (m_context_type == eContextTypeRegisterInfo) {
171 RegisterInfo *reg_info = GetRegisterInfo();
172 if (reg_info->encoding == lldb::eEncodingVector)
173 SetValueType(eValueTypeVector);
175 SetValueType(eValueTypeScalar);
180 GetRegisterInfo() const;
186 ResolveValue (ExecutionContext *exe_ctx);
213 SetVectorBytes(const Vector& vector)
216 return m_vector.IsValid();
220 SetVectorBytes(uint8_t *bytes, size_t length, lldb::ByteOrder byte_order)
222 return m_vector.SetBytes(bytes, length, byte_order);
226 SetScalarFromVector()
228 if (m_vector.IsValid())
230 m_value = m_vector.GetAsScalar();
237 ResizeData(size_t len);
240 AppendDataToHostBuffer (const Value &rhs);
245 return m_data_buffer;
248 const DataBufferHeap &
251 return m_data_buffer;
255 ValueOf(ExecutionContext *exe_ctx);
264 GetValueDefaultFormat ();
267 GetValueByteSize (Error *error_ptr, ExecutionContext *exe_ctx);
270 GetValueAsData(ExecutionContext *exe_ctx,
272 uint32_t data_offset,
273 Module *module); // Can be nullptr
276 GetValueTypeAsCString (ValueType context_type);
279 GetContextTypeAsCString (ContextType context_type);
282 GetData (DataExtractor &data);
290 CompilerType m_compiler_type;
292 ValueType m_value_type;
293 ContextType m_context_type;
294 DataBufferHeap m_data_buffer;
305 ValueList (const ValueList &rhs);
307 ~ValueList() = default;
309 const ValueList & operator= (const ValueList &rhs);
311 // void InsertValue (Value *value, size_t idx);
312 void PushValue (const Value &value);
315 Value *GetValueAtIndex(size_t idx);
319 typedef std::vector<Value> collection;
324 } // namespace lldb_private
326 #endif // liblldb_Value_h_