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"
16 #include "lldb/lldb-enumerations.h"
19 
20 #include "llvm/ADT/APInt.h"
21 
22 #include <vector>
23 
24 #include <cstdint>
25 #include <cstring>
26 
27 namespace lldb_private {
28 class DataExtractor;
29 class ExecutionContext;
30 class Module;
31 class Stream;
32 class Type;
33 class Variable;
34 }
35 
36 namespace lldb_private {
37 
38 class Value {
39 public:
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 *.
63  LLDBType,
64  /// lldb_private::Variable *.
65  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 
106  RegisterInfo *GetRegisterInfo() const;
107 
108  Type *GetType();
109 
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 
148 protected:
151  void *m_context = nullptr;
155 };
156 
157 class ValueList {
158 public:
160 
161  ValueList(const ValueList &rhs);
162 
163  ~ValueList() = default;
164 
165  const ValueList &operator=(const ValueList &rhs);
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 
174 private:
175  typedef std::vector<Value> collection;
176 
178 };
179 
180 } // namespace lldb_private
181 
182 #endif // LLDB_CORE_VALUE_H
lldb_private::npdb::PdbSymUidKind::Type
@ Type
lldb_private::Value::GetValueDefaultFormat
lldb::Format GetValueDefaultFormat()
Definition: Value.cpp:258
lldb_private::Value::ValueType::Scalar
@ Scalar
A raw scalar value.
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::Value::GetValueAddressType
AddressType GetValueAddressType() const
Definition: Value.cpp:111
lldb_private::Value::GetBuffer
DataBufferHeap & GetBuffer()
Definition: Value.h:120
lldb-private-types.h
Scalar.h
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::Value::Clear
void Clear()
Definition: Value.cpp:610
lldb_private::Value
Definition: Value.h:38
lldb_private::Value::SetValueType
void SetValueType(ValueType value_type)
Definition: Value.h:89
lldb_private::Value::ContextType::LLDBType
@ LLDBType
lldb_private::Type *.
lldb_private::Value::GetValueAsData
Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data, Module *module)
Definition: Value.cpp:301
lldb_private::Value::ValueType::Invalid
@ Invalid
lldb_private::Value::ValueType::FileAddress
@ FileAddress
A file address value.
lldb_private::Value::GetValueType
ValueType GetValueType() const
Definition: Value.cpp:109
lldb_private::ValueList::GetValueAtIndex
Value * GetValueAtIndex(size_t idx)
Definition: Value.cpp:679
lldb_private::Value::GetScalar
Scalar & GetScalar()
Definition: Value.h:114
lldb_private::AddressType
AddressType
Definition: lldb-private-enumerations.h:30
lldb_private::Value::m_compiler_type
CompilerType m_compiler_type
Definition: Value.h:150
lldb_private::Scalar
Definition: Scalar.h:34
lldb_private::ValueList::~ValueList
~ValueList()=default
lldb_private::Module
Definition: Module.h:85
lldb_private::CompilerContextKind::Module
@ Module
lldb_private::Value::ValueOf
bool ValueOf(ExecutionContext *exe_ctx)
Definition: Value.cpp:183
lldb_private::Value::ValueType::LoadAddress
@ LoadAddress
A load address value.
lldb_private::ValueList
Definition: Value.h:157
lldb_private::Stream
Definition: Stream.h:28
lldb_private::Value::GetValueTypeAsCString
static const char * GetValueTypeAsCString(ValueType context_type)
Definition: Value.cpp:619
lldb-private-enumerations.h
lldb_private::Target
Definition: Target.h:451
lldb_private::ValueList::GetSize
size_t GetSize()
Definition: Value.cpp:677
lldb_private::Value::m_context
void * m_context
Definition: Value.h:151
lldb_private::Value::operator=
Value & operator=(const Value &rhs)
Definition: Value.cpp:70
lldb_private::Value::ContextType::Invalid
@ Invalid
Undefined.
lldb_private::Value::GetRegisterInfo
RegisterInfo * GetRegisterInfo() const
Definition: Value.cpp:126
lldb_private::Value::SetCompilerType
void SetCompilerType(const CompilerType &compiler_type)
Definition: Value.cpp:254
lldb_private::Value::GetScalar
const Scalar & GetScalar() const
Definition: Value.h:112
lldb_private::ValueList::m_values
collection m_values
Definition: Value.h:177
lldb_private::Value::m_value
Scalar m_value
Definition: Value.h:149
lldb_private::ValueList::operator=
const ValueList & operator=(const ValueList &rhs)
Definition: Value.cpp:670
lldb_private::ValueList::PushValue
void PushValue(const Value &value)
Definition: Value.cpp:675
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::Value::ConvertToLoadAddress
void ConvertToLoadAddress(Module *module, Target *target)
Convert this value's file address to a load address, if possible.
Definition: Value.cpp:649
lldb_private::Value::m_value_type
ValueType m_value_type
Definition: Value.h:152
lldb-enumerations.h
lldb_private::Value::AppendBytes
void AppendBytes(const void *bytes, int len)
Definition: Value.cpp:96
lldb_private::Value::ValueType
ValueType
Type that describes Value::m_value.
Definition: Value.h:41
lldb_private::Value::m_data_buffer
DataBufferHeap m_data_buffer
Definition: Value.h:154
lldb_private::Value::GetContextTypeAsCString
static const char * GetContextTypeAsCString(ContextType context_type)
Definition: Value.cpp:635
CompilerType.h
lldb_private::Value::ClearContext
void ClearContext()
Definition: Value.h:91
lldb_private::Value::ResolveValue
Scalar & ResolveValue(ExecutionContext *exe_ctx)
Definition: Value.cpp:563
lldb_private::Value::m_context_type
ContextType m_context_type
Definition: Value.h:153
lldb::eEncodingVector
@ eEncodingVector
vector registers
Definition: lldb-enumerations.h:151
lldb_private::Status
Definition: Status.h:44
lldb_private::Value::ValueType::HostAddress
@ HostAddress
A host address value (for memory in the process that < A is using liblldb).
lldb_private::CompilerContextKind::Variable
@ Variable
lldb_private::Value::GetData
bool GetData(DataExtractor &data)
Definition: Value.cpp:278
lldb_private::Type
Definition: Type.h:66
lldb_private::Value::GetContextType
ContextType GetContextType() const
Definition: Value.h:87
lldb_private::Value::GetType
Type * GetType()
Definition: Value.cpp:132
lldb_private::ValueList::Clear
void Clear()
Definition: Value.cpp:686
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::Value::GetCompilerType
const CompilerType & GetCompilerType()
Definition: Value.cpp:225
lldb_private::Value::ContextType::RegisterInfo
@ RegisterInfo
RegisterInfo * (can be a scalar or a vector register).
Status.h
lldb_private::ValueList::collection
std::vector< Value > collection
Definition: Value.h:175
lldb_private::Value::SetBytes
void SetBytes(const void *bytes, int len)
Definition: Value.cpp:90
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Value::SetContext
void SetContext(ContextType context_type, void *p)
Definition: Value.h:96
lldb_private::Value::ResizeData
size_t ResizeData(size_t len)
Definition: Value.cpp:176
lldb_private::Value::GetVariable
Variable * GetVariable()
Definition: Value.cpp:604
lldb_private::Value::ContextType
ContextType
Type that describes Value::m_context.
Definition: Value.h:56
lldb_private::Value::GetValueByteSize
uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx)
Definition: Value.cpp:197
lldb_private::Variable
Definition: Variable.h:25
lldb_private::Value::Dump
void Dump(Stream *strm)
Definition: Value.cpp:102
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::Value::Value
Value()
Definition: Value.cpp:41
lldb_private::Value::GetBuffer
const DataBufferHeap & GetBuffer() const
Definition: Value.h:122
lldb_private::Value::AppendDataToHostBuffer
size_t AppendDataToHostBuffer(const Value &rhs)
Definition: Value.cpp:138
DataBufferHeap.h
lldb_private::ValueList::ValueList
ValueList()
Definition: Value.h:159