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;
29class ExecutionContext;
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).
61 RegisterInfo = 0,
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 const Scalar &GetScalar() const { return m_value; }
113
114 Scalar &GetScalar() { return m_value; }
115
116 size_t ResizeData(size_t len);
117
118 size_t AppendDataToHostBuffer(const Value &rhs);
119
121
122 const DataBufferHeap &GetBuffer() const { return m_data_buffer; }
123
124 bool ValueOf(ExecutionContext *exe_ctx);
125
127
128 void Dump(Stream *strm);
129
131
132 uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx);
133
135 Module *module); // Can be nullptr
136
137 static const char *GetValueTypeAsCString(ValueType context_type);
138
139 static const char *GetContextTypeAsCString(ContextType context_type);
140
141 /// Convert this value's file address to a load address, if possible.
142 void ConvertToLoadAddress(Module *module, Target *target);
143
144 bool GetData(DataExtractor &data);
145
146 void Clear();
147
149
150protected:
153 void *m_context = nullptr;
157};
158
160public:
161 ValueList() = default;
162 ~ValueList() = default;
163
164 ValueList(const ValueList &rhs) = default;
165 ValueList &operator=(const ValueList &rhs) = default;
166
167 // void InsertValue (Value *value, size_t idx);
168 void PushValue(const Value &value);
169
170 size_t GetSize();
171 Value *GetValueAtIndex(size_t idx);
172 void Clear();
173
174private:
175 typedef std::vector<Value> collection;
176
178};
179
180} // namespace lldb_private
181
182#endif // LLDB_CORE_VALUE_H
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
Definition: DataExtractor.h:48
"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:88
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
std::vector< Value > collection
Definition: Value.h:175
ValueList & operator=(const ValueList &rhs)=default
ValueList(const ValueList &rhs)=default
void PushValue(const Value &value)
Definition: Value.cpp:682
collection m_values
Definition: Value.h:177
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:686
const Scalar & GetScalar() const
Definition: Value.h:112
Type * GetType()
Definition: Value.cpp:146
void AppendBytes(const void *bytes, int len)
Definition: Value.cpp:94
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:315
RegisterInfo * GetRegisterInfo() const
Definition: Value.cpp:140
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).
@ FileAddress
A file address value.
@ LoadAddress
A load address value.
@ Scalar
A raw scalar value.
void * m_context
Definition: Value.h:153
void Dump(Stream *strm)
Definition: Value.cpp:100
static ValueType GetValueTypeFromAddressType(AddressType address_type)
Definition: Value.cpp:126
ContextType m_context_type
Definition: Value.h:155
Scalar & GetScalar()
Definition: Value.h:114
Value & operator=(const Value &rhs)
Definition: Value.cpp:68
void ClearContext()
Definition: Value.h:91
size_t AppendDataToHostBuffer(const Value &rhs)
Definition: Value.cpp:152
ValueType GetValueType() const
Definition: Value.cpp:109
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:268
DataBufferHeap m_data_buffer
Definition: Value.h:156
void SetContext(ContextType context_type, void *p)
Definition: Value.h:96
lldb::Format GetValueDefaultFormat()
Definition: Value.cpp:272
Scalar & ResolveValue(ExecutionContext *exe_ctx, Module *module=nullptr)
Definition: Value.cpp:577
static const char * GetValueTypeAsCString(ValueType context_type)
Definition: Value.cpp:633
DataBufferHeap & GetBuffer()
Definition: Value.h:120
uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx)
Definition: Value.cpp:211
void SetValueType(ValueType value_type)
Definition: Value.h:89
CompilerType m_compiler_type
Definition: Value.h:152
const DataBufferHeap & GetBuffer() const
Definition: Value.h:122
ContextType
Type that describes Value::m_context.
Definition: Value.h:56
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
@ LLDBType
lldb_private::Type *.
ContextType GetContextType() const
Definition: Value.h:87
ValueType m_value_type
Definition: Value.h:154
bool GetData(DataExtractor &data)
Definition: Value.cpp:292
AddressType GetValueAddressType() const
Definition: Value.cpp:111
const CompilerType & GetCompilerType()
Definition: Value.cpp:239
static const char * GetContextTypeAsCString(ContextType context_type)
Definition: Value.cpp:649
void ConvertToLoadAddress(Module *module, Target *target)
Convert this value's file address to a load address, if possible.
Definition: Value.cpp:663
size_t ResizeData(size_t len)
Definition: Value.cpp:190
void SetBytes(const void *bytes, int len)
Definition: Value.cpp:88
bool ValueOf(ExecutionContext *exe_ctx)
Definition: Value.cpp:197
Scalar m_value
Definition: Value.h:151
Variable * GetVariable()
Definition: Value.cpp:618
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.