LLDB mainline
Value.h
Go to the documentation of this file.
1//===-- Value.h -------------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_CORE_VALUE_H
10#define LLDB_CORE_VALUE_H
11
15#include "lldb/Utility/Scalar.h"
16#include "lldb/Utility/Status.h"
20
21#include "llvm/ADT/APInt.h"
22
23#include <vector>
24
25#include <cstdint>
26#include <cstring>
27
28namespace lldb_private {
29class DataExtractor;
31class Module;
32class Stream;
33class Type;
34class Variable;
35}
36
37namespace lldb_private {
38
39class Value {
40public:
41 /// Type that describes Value::m_value.
42 enum class ValueType {
43 Invalid = -1,
44 // m_value contains:
45 /// A raw scalar value.
46 Scalar = 0,
47 /// A file address value.
49 /// A load address value.
51 /// A host address value (for memory in the process that < A is
52 /// using liblldb).
54 };
55
56 /// Type that describes Value::m_context.
57 enum class ContextType {
58 // m_context contains:
59 /// Undefined.
60 Invalid = -1,
61 /// RegisterInfo * (can be a scalar or a vector register).
63 /// lldb_private::Type *.
65 /// lldb_private::Variable *.
67 };
68
69 Value();
70 Value(const Scalar &scalar);
71 Value(const void *bytes, int len);
72 Value(const Value &rhs);
73
74 void SetBytes(const void *bytes, int len);
75
76 void AppendBytes(const void *bytes, int len);
77
78 Value &operator=(const Value &rhs);
79
81
82 void SetCompilerType(const CompilerType &compiler_type);
83
84 ValueType GetValueType() const;
85
87
89
90 void SetValueType(ValueType value_type) { m_value_type = value_type; }
91
92 void ClearContext() {
93 m_context = nullptr;
95 }
96
97 void SetContext(ContextType context_type, void *p) {
98 m_context_type = context_type;
99 m_context = p;
101 RegisterInfo *reg_info = GetRegisterInfo();
102 if (reg_info->encoding == lldb::eEncodingVector)
104 }
105 }
106
108
109 Type *GetType();
110
111 Scalar &ResolveValue(ExecutionContext *exe_ctx, Module *module = nullptr);
112
113 /// See comment on m_scalar to understand what GetScalar returns.
114 const Scalar &GetScalar() const { return m_value; }
115
116 /// See comment on m_scalar to understand what GetScalar returns.
117 Scalar &GetScalar() { return m_value; }
118
119 size_t ResizeData(size_t len);
120
121 size_t AppendDataToHostBuffer(const Value &rhs);
122
124
125 const DataBufferHeap &GetBuffer() const { return m_data_buffer; }
126
127 bool ValueOf(ExecutionContext *exe_ctx);
128
130
131 void Dump(Stream *strm);
132
134
135 uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx);
136
138 Module *module); // Can be nullptr
139
140 static const char *GetValueTypeAsCString(ValueType context_type);
141
142 static const char *GetContextTypeAsCString(ContextType context_type);
143
144 /// Convert this value's file address to a load address, if possible.
145 void ConvertToLoadAddress(Module *module, Target *target);
146
147 bool GetData(DataExtractor &data);
148
149 void Clear();
150
151 static ValueType GetValueTypeFromAddressType(AddressType address_type);
152
153protected:
154 /// Represents a value, which can be a scalar, a load address, a file address,
155 /// or a host address.
156 ///
157 /// The interpretation of `m_value` depends on `m_value_type`:
158 /// - Scalar: `m_value` contains the scalar value.
159 /// - Load Address: `m_value` contains the load address.
160 /// - File Address: `m_value` contains the file address.
161 /// - Host Address: `m_value` contains a pointer to the start of the buffer in
162 /// host memory.
163 /// Currently, this can point to either:
164 /// - The `m_data_buffer` of this Value instance (e.g., in DWARF
165 /// computations).
166 /// - The `m_data` of a Value Object containing this Value.
167 // TODO: the GetScalar() API relies on knowledge not codified by the type
168 // system, making it hard to understand and easy to misuse.
169 // - Separate the scalar from the variable that contains the address (be it a
170 // load, file or host address).
171 // - Rename GetScalar() to something more indicative to what the scalar is,
172 // like GetScalarOrAddress() for example.
173 // - Split GetScalar() into two functions, GetScalar() and GetAddress(), which
174 // verify (or assert) what m_value_type is to make sure users of the class are
175 // querying the right thing.
176 // TODO: It's confusing to point to multiple possible buffers when the
177 // ValueType is a host address. Value should probably always own its buffer.
178 // Perhaps as a shared pointer with a copy on write system if the same buffer
179 // can be shared by multiple classes.
182 void *m_context = nullptr;
186};
187
189public:
190 ValueList() = default;
191 ~ValueList() = default;
192
193 ValueList(const ValueList &rhs) = default;
194 ValueList &operator=(const ValueList &rhs) = default;
195
196 // void InsertValue (Value *value, size_t idx);
197 void PushValue(const Value &value);
198
199 size_t GetSize();
200 Value *GetValueAtIndex(size_t idx);
201 void Clear();
202
203private:
204 typedef std::vector<Value> collection;
205
207};
208
209} // namespace lldb_private
210
211#endif // LLDB_CORE_VALUE_H
Generic representation of a type in a programming language.
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
std::vector< Value > collection
Definition Value.h:204
ValueList & operator=(const ValueList &rhs)=default
ValueList(const ValueList &rhs)=default
void PushValue(const Value &value)
Definition Value.cpp:694
collection m_values
Definition Value.h:206
Value * GetValueAtIndex(size_t idx)
Definition Value.cpp:698
const Scalar & GetScalar() const
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:114
void AppendBytes(const void *bytes, int len)
Definition Value.cpp:96
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition Value.cpp:323
RegisterInfo * GetRegisterInfo() const
Definition Value.cpp:142
ValueType
Type that describes Value::m_value.
Definition Value.h:42
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
Definition Value.h:53
@ FileAddress
A file address value.
Definition Value.h:48
@ LoadAddress
A load address value.
Definition Value.h:50
@ Scalar
A raw scalar value.
Definition Value.h:46
void Dump(Stream *strm)
Definition Value.cpp:102
static ValueType GetValueTypeFromAddressType(AddressType address_type)
Definition Value.cpp:128
ContextType m_context_type
Definition Value.h:184
Scalar & GetScalar()
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:117
Value & operator=(const Value &rhs)
Definition Value.cpp:70
void ClearContext()
Definition Value.h:92
size_t AppendDataToHostBuffer(const Value &rhs)
Definition Value.cpp:154
ValueType GetValueType() const
Definition Value.cpp:111
void SetCompilerType(const CompilerType &compiler_type)
Definition Value.cpp:276
DataBufferHeap m_data_buffer
Definition Value.h:185
void SetContext(ContextType context_type, void *p)
Definition Value.h:97
lldb::Format GetValueDefaultFormat()
Definition Value.cpp:280
Scalar & ResolveValue(ExecutionContext *exe_ctx, Module *module=nullptr)
Definition Value.cpp:589
static const char * GetValueTypeAsCString(ValueType context_type)
Definition Value.cpp:645
DataBufferHeap & GetBuffer()
Definition Value.h:123
uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx)
Definition Value.cpp:213
void SetValueType(ValueType value_type)
Definition Value.h:90
CompilerType m_compiler_type
Definition Value.h:181
const DataBufferHeap & GetBuffer() const
Definition Value.h:125
ContextType
Type that describes Value::m_context.
Definition Value.h:57
@ Variable
lldb_private::Variable *.
Definition Value.h:66
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
Definition Value.h:62
@ LLDBType
lldb_private::Type *.
Definition Value.h:64
ContextType GetContextType() const
Definition Value.h:88
ValueType m_value_type
Definition Value.h:183
bool GetData(DataExtractor &data)
Definition Value.cpp:300
AddressType GetValueAddressType() const
Definition Value.cpp:113
const CompilerType & GetCompilerType()
Definition Value.cpp:247
static const char * GetContextTypeAsCString(ContextType context_type)
Definition Value.cpp:661
void ConvertToLoadAddress(Module *module, Target *target)
Convert this value's file address to a load address, if possible.
Definition Value.cpp:675
size_t ResizeData(size_t len)
Definition Value.cpp:192
void SetBytes(const void *bytes, int len)
Definition Value.cpp:90
bool ValueOf(ExecutionContext *exe_ctx)
Definition Value.cpp:199
Scalar m_value
Represents a value, which can be a scalar, a load address, a file address, or a host address.
Definition Value.h:180
Variable * GetVariable()
Definition Value.cpp:630
A class that represents a running process on the host machine.
Format
Display format definitions.
@ eEncodingVector
vector registers
Every register is described in detail including its name, alternate name (optional),...
lldb::Encoding encoding
Encoding of the register bits.