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