• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 #include "lldb/Symbol/CompilerType.h"
13 #include "lldb/Utility/DataBufferHeap.h"
14 #include "lldb/Utility/Scalar.h"
15 #include "lldb/Utility/Status.h"
16 #include "lldb/lldb-enumerations.h"
17 #include "lldb/lldb-private-enumerations.h"
18 #include "lldb/lldb-private-types.h"
19 
20 #include "llvm/ADT/APInt.h"
21 
22 #include <vector>
23 
24 #include <stdint.h>
25 #include <string.h>
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   // Values Less than zero are an error, greater than or equal to zero returns
41   // what the Scalar result is.
42   enum ValueType {
43     // m_value contains...
44     // ============================
45     eValueTypeScalar,      // raw scalar value
46     eValueTypeFileAddress, // file address value
47     eValueTypeLoadAddress, // load address value
48     eValueTypeHostAddress  // host address value (for memory in the process that
49                            // is using liblldb)
50   };
51 
52   enum ContextType // Type that describes Value::m_context
53   {
54     // m_context contains...
55     // ====================
56     eContextTypeInvalid,      // undefined
57     eContextTypeRegisterInfo, // RegisterInfo * (can be a scalar or a vector
58                               // register)
59     eContextTypeLLDBType,     // lldb_private::Type *
60     eContextTypeVariable      // lldb_private::Variable *
61   };
62 
63   Value();
64   Value(const Scalar &scalar);
65   Value(const void *bytes, int len);
66   Value(const Value &rhs);
67 
68   void SetBytes(const void *bytes, int len);
69 
70   void AppendBytes(const void *bytes, int len);
71 
72   Value &operator=(const Value &rhs);
73 
74   const CompilerType &GetCompilerType();
75 
76   void SetCompilerType(const CompilerType &compiler_type);
77 
78   ValueType GetValueType() const;
79 
80   AddressType GetValueAddressType() const;
81 
GetContextType()82   ContextType GetContextType() const { return m_context_type; }
83 
SetValueType(ValueType value_type)84   void SetValueType(ValueType value_type) { m_value_type = value_type; }
85 
ClearContext()86   void ClearContext() {
87     m_context = nullptr;
88     m_context_type = eContextTypeInvalid;
89   }
90 
SetContext(ContextType context_type,void * p)91   void SetContext(ContextType context_type, void *p) {
92     m_context_type = context_type;
93     m_context = p;
94     if (m_context_type == eContextTypeRegisterInfo) {
95       RegisterInfo *reg_info = GetRegisterInfo();
96       if (reg_info->encoding == lldb::eEncodingVector)
97         SetValueType(eValueTypeScalar);
98     }
99   }
100 
101   RegisterInfo *GetRegisterInfo() const;
102 
103   Type *GetType();
104 
105   Scalar &ResolveValue(ExecutionContext *exe_ctx);
106 
GetScalar()107   const Scalar &GetScalar() const { return m_value; }
108 
GetScalar()109   Scalar &GetScalar() { return m_value; }
110 
111   size_t ResizeData(size_t len);
112 
113   size_t AppendDataToHostBuffer(const Value &rhs);
114 
GetBuffer()115   DataBufferHeap &GetBuffer() { return m_data_buffer; }
116 
GetBuffer()117   const DataBufferHeap &GetBuffer() const { return m_data_buffer; }
118 
119   bool ValueOf(ExecutionContext *exe_ctx);
120 
121   Variable *GetVariable();
122 
123   void Dump(Stream *strm);
124 
125   lldb::Format GetValueDefaultFormat();
126 
127   uint64_t GetValueByteSize(Status *error_ptr, ExecutionContext *exe_ctx);
128 
129   Status GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data,
130                         Module *module); // Can be nullptr
131 
132   static const char *GetValueTypeAsCString(ValueType context_type);
133 
134   static const char *GetContextTypeAsCString(ContextType context_type);
135 
136   /// Convert this value's file address to a load address, if possible.
137   void ConvertToLoadAddress(Module *module, Target *target);
138 
139   bool GetData(DataExtractor &data);
140 
141   void Clear();
142 
143 protected:
144   Scalar m_value;
145   CompilerType m_compiler_type;
146   void *m_context;
147   ValueType m_value_type;
148   ContextType m_context_type;
149   DataBufferHeap m_data_buffer;
150 };
151 
152 class ValueList {
153 public:
ValueList()154   ValueList() : m_values() {}
155 
156   ValueList(const ValueList &rhs);
157 
158   ~ValueList() = default;
159 
160   const ValueList &operator=(const ValueList &rhs);
161 
162   // void InsertValue (Value *value, size_t idx);
163   void PushValue(const Value &value);
164 
165   size_t GetSize();
166   Value *GetValueAtIndex(size_t idx);
167   void Clear();
168 
169 private:
170   typedef std::vector<Value> collection;
171 
172   collection m_values;
173 };
174 
175 } // namespace lldb_private
176 
177 #endif // LLDB_CORE_VALUE_H
178