1 //===-- ValueObjectRegister.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 liblldb_ValueObjectRegister_h_
10 #define liblldb_ValueObjectRegister_h_
11 
12 #include "lldb/Core/ValueObject.h"
13 #include "lldb/Symbol/CompilerType.h"
14 #include "lldb/Utility/ConstString.h"
15 #include "lldb/Utility/RegisterValue.h"
16 #include "lldb/lldb-defines.h"
17 #include "lldb/lldb-enumerations.h"
18 #include "lldb/lldb-forward.h"
19 #include "lldb/lldb-private-types.h"
20 
21 #include <stddef.h>
22 #include <stdint.h>
23 
24 namespace lldb_private {
25 class DataExtractor;
26 class Status;
27 class ExecutionContextScope;
28 class Scalar;
29 class Stream;
30 
31 // A ValueObject that contains a root variable that may or may not
32 // have children.
33 class ValueObjectRegisterContext : public ValueObject {
34 public:
35   ~ValueObjectRegisterContext() override;
36 
37   uint64_t GetByteSize() override;
38 
39   lldb::ValueType GetValueType() const override {
40     return lldb::eValueTypeRegisterSet;
41   }
42 
43   ConstString GetTypeName() override;
44 
45   ConstString GetQualifiedTypeName() override;
46 
47   ConstString GetDisplayTypeName() override;
48 
49   size_t CalculateNumChildren(uint32_t max) override;
50 
51   ValueObject *CreateChildAtIndex(size_t idx, bool synthetic_array_member,
52                                   int32_t synthetic_index) override;
53 
54 protected:
55   bool UpdateValue() override;
56 
57   CompilerType GetCompilerTypeImpl() override;
58 
59   lldb::RegisterContextSP m_reg_ctx_sp;
60 
61 private:
62   ValueObjectRegisterContext(ValueObject &parent,
63                              lldb::RegisterContextSP &reg_ctx_sp);
64   // For ValueObject only
65   DISALLOW_COPY_AND_ASSIGN(ValueObjectRegisterContext);
66 };
67 
68 class ValueObjectRegisterSet : public ValueObject {
69 public:
70   ~ValueObjectRegisterSet() override;
71 
72   static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
73                                     lldb::RegisterContextSP &reg_ctx_sp,
74                                     uint32_t set_idx);
75 
76   uint64_t GetByteSize() override;
77 
78   lldb::ValueType GetValueType() const override {
79     return lldb::eValueTypeRegisterSet;
80   }
81 
82   ConstString GetTypeName() override;
83 
84   ConstString GetQualifiedTypeName() override;
85 
86   size_t CalculateNumChildren(uint32_t max) override;
87 
88   ValueObject *CreateChildAtIndex(size_t idx, bool synthetic_array_member,
89                                   int32_t synthetic_index) override;
90 
91   lldb::ValueObjectSP GetChildMemberWithName(ConstString name,
92                                              bool can_create) override;
93 
94   size_t GetIndexOfChildWithName(ConstString name) override;
95 
96 protected:
97   bool UpdateValue() override;
98 
99   CompilerType GetCompilerTypeImpl() override;
100 
101   lldb::RegisterContextSP m_reg_ctx_sp;
102   const RegisterSet *m_reg_set;
103   uint32_t m_reg_set_idx;
104 
105 private:
106   friend class ValueObjectRegisterContext;
107 
108   ValueObjectRegisterSet(ExecutionContextScope *exe_scope,
109                          lldb::RegisterContextSP &reg_ctx_sp, uint32_t set_idx);
110 
111   // For ValueObject only
112   DISALLOW_COPY_AND_ASSIGN(ValueObjectRegisterSet);
113 };
114 
115 class ValueObjectRegister : public ValueObject {
116 public:
117   ~ValueObjectRegister() override;
118 
119   static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope,
120                                     lldb::RegisterContextSP &reg_ctx_sp,
121                                     uint32_t reg_num);
122 
123   uint64_t GetByteSize() override;
124 
125   lldb::ValueType GetValueType() const override {
126     return lldb::eValueTypeRegister;
127   }
128 
129   ConstString GetTypeName() override;
130 
131   size_t CalculateNumChildren(uint32_t max) override;
132 
133   bool SetValueFromCString(const char *value_str, Status &error) override;
134 
135   bool SetData(DataExtractor &data, Status &error) override;
136 
137   bool ResolveValue(Scalar &scalar) override;
138 
139   void
140   GetExpressionPath(Stream &s, bool qualify_cxx_base_classes,
141                     GetExpressionPathFormat epformat =
142                         eGetExpressionPathFormatDereferencePointers) override;
143 
144 protected:
145   bool UpdateValue() override;
146 
147   CompilerType GetCompilerTypeImpl() override;
148 
149   lldb::RegisterContextSP m_reg_ctx_sp;
150   RegisterInfo m_reg_info;
151   RegisterValue m_reg_value;
152   ConstString m_type_name;
153   CompilerType m_compiler_type;
154 
155 private:
156   void ConstructObject(uint32_t reg_num);
157 
158   friend class ValueObjectRegisterSet;
159 
160   ValueObjectRegister(ValueObject &parent, lldb::RegisterContextSP &reg_ctx_sp,
161                       uint32_t reg_num);
162   ValueObjectRegister(ExecutionContextScope *exe_scope,
163                       lldb::RegisterContextSP &reg_ctx_sp, uint32_t reg_num);
164 
165   // For ValueObject only
166   DISALLOW_COPY_AND_ASSIGN(ValueObjectRegister);
167 };
168 
169 } // namespace lldb_private
170 
171 #endif // liblldb_ValueObjectRegister_h_
172