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
14#include "lldb/Utility/Scalar.h"
15#include "lldb/Utility/Status.h"
19
20#include "llvm/ADT/APInt.h"
21
22#include <vector>
23
24#include <cstdint>
25#include <cstring>
26
27namespace lldb_private {
28class DataExtractor;
30class Module;
31class Stream;
32class Type;
33class Variable;
34}
35
36namespace lldb_private {
37
38class Value {
39public:
40 /// Type that describes Value::m_value.
41 enum class ValueType {
42 Invalid = -1,
43 // m_value contains:
44 /// A raw scalar value.
45 Scalar = 0,
46 /// A file address value.
48 /// A load address value.
50 /// A host address value (for memory in the process that < A is
51 /// using liblldb).
53 };
54
55 /// Type that describes Value::m_context.
56 enum class ContextType {
57 // m_context contains:
58 /// Undefined.
59 Invalid = -1,
60 /// RegisterInfo * (can be a scalar or a vector register).
62 /// lldb_private::Type *.
64 /// lldb_private::Variable *.
66 };
67
68 Value();
69 Value(const Scalar &scalar);
70 Value(const void *bytes, int len);
71 Value(const Value &rhs);
72
73 void SetBytes(const void *bytes, int len);
74
75 void AppendBytes(const void *bytes, int len);
76
77 Value &operator=(const Value &rhs);
78
80
81 void SetCompilerType(const CompilerType &compiler_type);
82
83 ValueType GetValueType() const;
84
86
88
89 void SetValueType(ValueType value_type) { m_value_type = value_type; }
90
91 void ClearContext() {
92 m_context = nullptr;
94 }
95
96 void SetContext(ContextType context_type, void *p) {
97 m_context_type = context_type;
98 m_context = p;
100 RegisterInfo *reg_info = GetRegisterInfo();
101 if (reg_info->encoding == lldb::eEncodingVector)
103 }
104 }
105
107
108 Type *GetType();
109
110 Scalar &ResolveValue(ExecutionContext *exe_ctx, Module *module = nullptr);
111
112 /// See comment on m_scalar to understand what GetScalar returns.
113 const Scalar &GetScalar() const { return m_value; }
114
115 /// See comment on m_scalar to understand what GetScalar returns.
116 Scalar &GetScalar() { return m_value; }
117
118 size_t ResizeData(size_t len);
119
120 size_t AppendDataToHostBuffer(const Value &rhs);
121
123
124 const DataBufferHeap &GetBuffer() const { return m_data_buffer; }
125
126 bool ValueOf(ExecutionContext *exe_ctx);
127
129
130 void Dump(Stream *strm);
131
133
134 uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx);
135
137 Module *module); // Can be nullptr
138
139 static const char *GetValueTypeAsCString(ValueType context_type);
140
141 static const char *GetContextTypeAsCString(ContextType context_type);
142
143 /// Convert this value's file address to a load address, if possible.
144 void ConvertToLoadAddress(Module *module, Target *target);
145
146 bool GetData(DataExtractor &data);
147
148 void Clear();
149
150 static ValueType GetValueTypeFromAddressType(AddressType address_type);
151
152protected:
153 /// Represents a value, which can be a scalar, a load address, a file address,
154 /// or a host address.
155 ///
156 /// The interpretation of `m_value` depends on `m_value_type`:
157 /// - Scalar: `m_value` contains the scalar value.
158 /// - Load Address: `m_value` contains the load address.
159 /// - File Address: `m_value` contains the file address.
160 /// - Host Address: `m_value` contains a pointer to the start of the buffer in
161 /// host memory.
162 /// Currently, this can point to either:
163 /// - The `m_data_buffer` of this Value instance (e.g., in DWARF
164 /// computations).
165 /// - The `m_data` of a Value Object containing this Value.
166 // TODO: the GetScalar() API relies on knowledge not codified by the type
167 // system, making it hard to understand and easy to misuse.
168 // - Separate the scalar from the variable that contains the address (be it a
169 // load, file or host address).
170 // - Rename GetScalar() to something more indicative to what the scalar is,
171 // like GetScalarOrAddress() for example.
172 // - Split GetScalar() into two functions, GetScalar() and GetAddress(), which
173 // verify (or assert) what m_value_type is to make sure users of the class are
174 // querying the right thing.
175 // TODO: It's confusing to point to multiple possible buffers when the
176 // ValueType is a host address. Value should probably always own its buffer.
177 // Perhaps as a shared pointer with a copy on write system if the same buffer
178 // can be shared by multiple classes.
181 void *m_context = nullptr;
185};
186
188public:
189 ValueList() = default;
190 ~ValueList() = default;
191
192 ValueList(const ValueList &rhs) = default;
193 ValueList &operator=(const ValueList &rhs) = default;
194
195 // void InsertValue (Value *value, size_t idx);
196 void PushValue(const Value &value);
197
198 size_t GetSize();
199 Value *GetValueAtIndex(size_t idx);
200 void Clear();
201
202private:
203 typedef std::vector<Value> collection;
204
206};
207
208} // namespace lldb_private
209
210#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:90
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:203
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:205
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:113
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:41
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
Definition Value.h:52
@ FileAddress
A file address value.
Definition Value.h:47
@ LoadAddress
A load address value.
Definition Value.h:49
@ Scalar
A raw scalar value.
Definition Value.h:45
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:183
Scalar & GetScalar()
See comment on m_scalar to understand what GetScalar returns.
Definition Value.h:116
Value & operator=(const Value &rhs)
Definition Value.cpp:70
void ClearContext()
Definition Value.h:91
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:184
void SetContext(ContextType context_type, void *p)
Definition Value.h:96
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:122
uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx)
Definition Value.cpp:213
void SetValueType(ValueType value_type)
Definition Value.h:89
CompilerType m_compiler_type
Definition Value.h:180
const DataBufferHeap & GetBuffer() const
Definition Value.h:124
ContextType
Type that describes Value::m_context.
Definition Value.h:56
@ Variable
lldb_private::Variable *.
Definition Value.h:65
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
Definition Value.h:61
@ LLDBType
lldb_private::Type *.
Definition Value.h:63
ContextType GetContextType() const
Definition Value.h:87
ValueType m_value_type
Definition Value.h:182
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:179
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.