File indexing completed on 2026-05-10 08:42:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_CORE_VALUE_H
0010 #define LLDB_CORE_VALUE_H
0011
0012 #include "lldb/Symbol/CompilerType.h"
0013 #include "lldb/Utility/DataBufferHeap.h"
0014 #include "lldb/Utility/Scalar.h"
0015 #include "lldb/Utility/Status.h"
0016 #include "lldb/lldb-enumerations.h"
0017 #include "lldb/lldb-private-enumerations.h"
0018 #include "lldb/lldb-private-types.h"
0019
0020 #include "llvm/ADT/APInt.h"
0021
0022 #include <vector>
0023
0024 #include <cstdint>
0025 #include <cstring>
0026
0027 namespace lldb_private {
0028 class DataExtractor;
0029 class ExecutionContext;
0030 class Module;
0031 class Stream;
0032 class Type;
0033 class Variable;
0034 }
0035
0036 namespace lldb_private {
0037
0038 class Value {
0039 public:
0040
0041 enum class ValueType {
0042 Invalid = -1,
0043
0044
0045 Scalar = 0,
0046
0047 FileAddress,
0048
0049 LoadAddress,
0050
0051
0052 HostAddress
0053 };
0054
0055
0056 enum class ContextType {
0057
0058
0059 Invalid = -1,
0060
0061 RegisterInfo = 0,
0062
0063 LLDBType,
0064
0065 Variable
0066 };
0067
0068 Value();
0069 Value(const Scalar &scalar);
0070 Value(const void *bytes, int len);
0071 Value(const Value &rhs);
0072
0073 void SetBytes(const void *bytes, int len);
0074
0075 void AppendBytes(const void *bytes, int len);
0076
0077 Value &operator=(const Value &rhs);
0078
0079 const CompilerType &GetCompilerType();
0080
0081 void SetCompilerType(const CompilerType &compiler_type);
0082
0083 ValueType GetValueType() const;
0084
0085 AddressType GetValueAddressType() const;
0086
0087 ContextType GetContextType() const { return m_context_type; }
0088
0089 void SetValueType(ValueType value_type) { m_value_type = value_type; }
0090
0091 void ClearContext() {
0092 m_context = nullptr;
0093 m_context_type = ContextType::Invalid;
0094 }
0095
0096 void SetContext(ContextType context_type, void *p) {
0097 m_context_type = context_type;
0098 m_context = p;
0099 if (m_context_type == ContextType::RegisterInfo) {
0100 RegisterInfo *reg_info = GetRegisterInfo();
0101 if (reg_info->encoding == lldb::eEncodingVector)
0102 SetValueType(ValueType::Scalar);
0103 }
0104 }
0105
0106 RegisterInfo *GetRegisterInfo() const;
0107
0108 Type *GetType();
0109
0110 Scalar &ResolveValue(ExecutionContext *exe_ctx, Module *module = nullptr);
0111
0112 const Scalar &GetScalar() const { return m_value; }
0113
0114 Scalar &GetScalar() { return m_value; }
0115
0116 size_t ResizeData(size_t len);
0117
0118 size_t AppendDataToHostBuffer(const Value &rhs);
0119
0120 DataBufferHeap &GetBuffer() { return m_data_buffer; }
0121
0122 const DataBufferHeap &GetBuffer() const { return m_data_buffer; }
0123
0124 bool ValueOf(ExecutionContext *exe_ctx);
0125
0126 Variable *GetVariable();
0127
0128 void Dump(Stream *strm);
0129
0130 lldb::Format GetValueDefaultFormat();
0131
0132 uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx);
0133
0134 Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data,
0135 Module *module);
0136
0137 static const char *GetValueTypeAsCString(ValueType context_type);
0138
0139 static const char *GetContextTypeAsCString(ContextType context_type);
0140
0141
0142 void ConvertToLoadAddress(Module *module, Target *target);
0143
0144 bool GetData(DataExtractor &data);
0145
0146 void Clear();
0147
0148 static ValueType GetValueTypeFromAddressType(AddressType address_type);
0149
0150 protected:
0151 Scalar m_value;
0152 CompilerType m_compiler_type;
0153 void *m_context = nullptr;
0154 ValueType m_value_type = ValueType::Scalar;
0155 ContextType m_context_type = ContextType::Invalid;
0156 DataBufferHeap m_data_buffer;
0157 };
0158
0159 class ValueList {
0160 public:
0161 ValueList() = default;
0162 ~ValueList() = default;
0163
0164 ValueList(const ValueList &rhs) = default;
0165 ValueList &operator=(const ValueList &rhs) = default;
0166
0167
0168 void PushValue(const Value &value);
0169
0170 size_t GetSize();
0171 Value *GetValueAtIndex(size_t idx);
0172 void Clear();
0173
0174 private:
0175 typedef std::vector<Value> collection;
0176
0177 collection m_values;
0178 };
0179
0180 }
0181
0182 #endif