xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Core/ValueObjectVTable.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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   lldb::ValueType GetValueType() const override;
70 
71   ConstString GetTypeName() override;
72 
73   ConstString GetQualifiedTypeName() override;
74 
75   ConstString GetDisplayTypeName() override;
76 
77   bool IsInScope() override;
78 
79 protected:
80   bool UpdateValue() override;
81 
82   CompilerType GetCompilerTypeImpl() override;
83 
84   /// The symbol for the C++ virtual function table.
85   const Symbol *m_vtable_symbol = nullptr;
86   /// Cache the number of vtable children when we update the value.
87   uint32_t m_num_vtable_entries = 0;
88   /// Cache the address size in bytes to avoid checking with the process to
89   /// many times.
90   uint32_t m_addr_size = 0;
91 
92 private:
93   ValueObjectVTable(ValueObject &parent);
94 
95   ValueObject *CreateChildAtIndex(size_t idx) override;
CreateSyntheticArrayMember(size_t idx)96   ValueObject *CreateSyntheticArrayMember(size_t idx) override {
97     return nullptr;
98   }
99 
100   // For ValueObject only
101   ValueObjectVTable(const ValueObjectVTable &) = delete;
102   const ValueObjectVTable &operator=(const ValueObjectVTable &) = delete;
103 };
104 
105 } // namespace lldb_private
106 
107 #endif // LLDB_CORE_VALUEOBJECTVTABLE_H
108