1 //===-- ValueObjectDynamicValue.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_VALUEOBJECTDYNAMICVALUE_H
10 #define LLDB_CORE_VALUEOBJECTDYNAMICVALUE_H
11 
12 #include "lldb/Core/Address.h"
13 #include "lldb/Core/ValueObject.h"
14 #include "lldb/Symbol/CompilerType.h"
15 #include "lldb/Symbol/Type.h"
16 #include "lldb/Utility/ConstString.h"
17 #include "lldb/lldb-defines.h"
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-forward.h"
20 #include "lldb/lldb-private-enumerations.h"
21 
22 #include <cassert>
23 #include <cstddef>
24 #include <cstdint>
25 
26 namespace lldb_private {
27 class DataExtractor;
28 class Declaration;
29 class Status;
30 
31 /// A ValueObject that represents memory at a given address, viewed as some
32 /// set lldb type.
33 class ValueObjectDynamicValue : public ValueObject {
34 public:
35   ~ValueObjectDynamicValue() = default;
36 
37   llvm::Optional<uint64_t> GetByteSize() override;
38 
39   ConstString GetTypeName() override;
40 
41   ConstString GetQualifiedTypeName() override;
42 
43   ConstString GetDisplayTypeName() override;
44 
45   size_t CalculateNumChildren(uint32_t max) override;
46 
47   lldb::ValueType GetValueType() const override;
48 
49   bool IsInScope() override;
50 
51   bool IsDynamic() override { return true; }
52 
53   bool IsBaseClass() override {
54     if (m_parent)
55       return m_parent->IsBaseClass();
56     return false;
57   }
58 
59   bool GetIsConstant() const override { return false; }
60 
61   ValueObject *GetParent() override {
62     return ((m_parent != nullptr) ? m_parent->GetParent() : nullptr);
63   }
64 
65   const ValueObject *GetParent() const override {
66     return ((m_parent != nullptr) ? m_parent->GetParent() : nullptr);
67   }
68 
69   lldb::ValueObjectSP GetStaticValue() override { return m_parent->GetSP(); }
70 
71   bool SetValueFromCString(const char *value_str, Status &error) override;
72 
73   bool SetData(DataExtractor &data, Status &error) override;
74 
75   TypeImpl GetTypeImpl() override;
76 
77   lldb::VariableSP GetVariable() override {
78     return m_parent ? m_parent->GetVariable() : nullptr;
79   }
80 
81   lldb::LanguageType GetPreferredDisplayLanguage() override;
82 
83   void SetPreferredDisplayLanguage(lldb::LanguageType);
84 
85   bool IsSyntheticChildrenGenerated() override;
86 
87   void SetSyntheticChildrenGenerated(bool b) override;
88 
89   bool GetDeclaration(Declaration &decl) override;
90 
91   uint64_t GetLanguageFlags() override;
92 
93   void SetLanguageFlags(uint64_t flags) override;
94 
95 protected:
96   bool UpdateValue() override;
97 
98   LazyBool CanUpdateWithInvalidExecutionContext() override {
99     return eLazyBoolYes;
100   }
101 
102   lldb::DynamicValueType GetDynamicValueTypeImpl() override {
103     return m_use_dynamic;
104   }
105 
106   bool HasDynamicValueTypeInfo() override { return true; }
107 
108   CompilerType GetCompilerTypeImpl() override;
109 
110   Address m_address; ///< The variable that this value object is based upon
111   TypeAndOrName m_dynamic_type_info; // We can have a type_sp or just a name
112   lldb::DynamicValueType m_use_dynamic;
113   TypeImpl m_type_impl;
114 
115 private:
116   friend class ValueObject;
117   friend class ValueObjectConstResult;
118   ValueObjectDynamicValue(ValueObject &parent,
119                           lldb::DynamicValueType use_dynamic);
120 
121   ValueObjectDynamicValue(const ValueObjectDynamicValue &) = delete;
122   const ValueObjectDynamicValue &
123   operator=(const ValueObjectDynamicValue &) = delete;
124 };
125 
126 } // namespace lldb_private
127 
128 #endif // LLDB_CORE_VALUEOBJECTDYNAMICVALUE_H
129