1 | //===-- ValueObjectVTable.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_VALUEOBJECTVTABLE_H |
10 | #define LLDB_CORE_VALUEOBJECTVTABLE_H |
11 | |
12 | #include "lldb/Core/ValueObject.h" |
13 | |
14 | namespace lldb_private { |
15 | |
16 | /// A class that represents a virtual function table for a C++ class. |
17 | /// |
18 | /// ValueObject::GetError() will be in the success state if this value |
19 | /// represents a C++ class with a vtable, or an appropriate error describing |
20 | /// that the object isn't a C++ class with a vtable or not a C++ class. |
21 | /// |
22 | /// ValueObject::GetName() will be the demangled symbol name for the virtual |
23 | /// function table like "vtable for <classname>". |
24 | /// |
25 | /// ValueObject::GetValueAsCString() will be the address of the first vtable |
26 | /// entry if the current ValueObject is a class with a vtable, or nothing the |
27 | /// current ValueObject is not a C++ class or not a C++ class that has a |
28 | /// vtable. |
29 | /// |
30 | /// ValueObject::GetValueAtUnsigned(...) will return the address of the first |
31 | /// vtable entry. |
32 | /// |
33 | /// ValueObject::GetAddressOf() will return the address of the vtable pointer |
34 | /// found in the parent ValueObject. |
35 | /// |
36 | /// ValueObject::GetNumChildren() will return the number of virtual function |
37 | /// pointers in the vtable, or zero on error. |
38 | /// |
39 | /// ValueObject::GetChildAtIndex(...) will return each virtual function pointer |
40 | /// as a ValueObject object. |
41 | /// |
42 | /// The child ValueObjects will have the following values: |
43 | /// |
44 | /// ValueObject::GetError() will indicate success if the vtable entry was |
45 | /// successfully read from memory, or an error if not. |
46 | /// |
47 | /// ValueObject::GetName() will be the vtable function index in the form "[%u]" |
48 | /// where %u is the index. |
49 | /// |
50 | /// ValueObject::GetValueAsCString() will be the virtual function pointer value |
51 | /// |
52 | /// ValueObject::GetValueAtUnsigned(...) will return the virtual function |
53 | /// pointer value. |
54 | /// |
55 | /// ValueObject::GetAddressOf() will return the address of the virtual function |
56 | /// pointer. |
57 | /// |
58 | /// ValueObject::GetNumChildren() returns 0 |
59 | class ValueObjectVTable : public ValueObject { |
60 | public: |
61 | ~ValueObjectVTable() override; |
62 | |
63 | static lldb::ValueObjectSP Create(ValueObject &parent); |
64 | |
65 | std::optional<uint64_t> GetByteSize() override; |
66 | |
67 | llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override; |
68 | |
69 | ValueObject *CreateChildAtIndex(size_t idx, bool synthetic_array_member, |
70 | int32_t synthetic_index) override; |
71 | |
72 | lldb::ValueType GetValueType() const override; |
73 | |
74 | ConstString GetTypeName() override; |
75 | |
76 | ConstString GetQualifiedTypeName() override; |
77 | |
78 | ConstString GetDisplayTypeName() override; |
79 | |
80 | bool IsInScope() override; |
81 | |
82 | protected: |
83 | bool UpdateValue() override; |
84 | |
85 | CompilerType GetCompilerTypeImpl() override; |
86 | |
87 | /// The symbol for the C++ virtual function table. |
88 | const Symbol *m_vtable_symbol = nullptr; |
89 | /// Cache the number of vtable children when we update the value. |
90 | uint32_t m_num_vtable_entries = 0; |
91 | /// Cache the address size in bytes to avoid checking with the process to |
92 | /// many times. |
93 | uint32_t m_addr_size = 0; |
94 | |
95 | private: |
96 | ValueObjectVTable(ValueObject &parent); |
97 | |
98 | // For ValueObject only |
99 | ValueObjectVTable(const ValueObjectVTable &) = delete; |
100 | const ValueObjectVTable &operator=(const ValueObjectVTable &) = delete; |
101 | }; |
102 | |
103 | } // namespace lldb_private |
104 | |
105 | #endif // LLDB_CORE_VALUEOBJECTVTABLE_H |
106 | |