Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:59

0001 //===-- ValueObjectVTable.h -------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_VALUEOBJECT_VALUEOBJECTVTABLE_H
0010 #define LLDB_VALUEOBJECT_VALUEOBJECTVTABLE_H
0011 
0012 #include "lldb/ValueObject/ValueObject.h"
0013 
0014 namespace lldb_private {
0015 
0016 /// A class that represents a virtual function table for a C++ class.
0017 ///
0018 /// ValueObject::GetError() will be in the success state if this value
0019 /// represents a C++ class with a vtable, or an appropriate error describing
0020 /// that the object isn't a C++ class with a vtable or not a C++ class.
0021 ///
0022 /// ValueObject::GetName() will be the demangled symbol name for the virtual
0023 /// function table like "vtable for <classname>".
0024 ///
0025 /// ValueObject::GetValueAsCString() will be the address of the first vtable
0026 /// entry if the current ValueObject is a class with a vtable, or nothing the
0027 /// current ValueObject is not a C++ class or not a C++ class that has a
0028 /// vtable.
0029 ///
0030 /// ValueObject::GetValueAtUnsigned(...) will return the address of the first
0031 /// vtable entry.
0032 ///
0033 /// ValueObject::GetAddressOf() will return the address of the vtable pointer
0034 /// found in the parent ValueObject.
0035 ///
0036 /// ValueObject::GetNumChildren() will return the number of virtual function
0037 /// pointers in the vtable, or zero on error.
0038 ///
0039 /// ValueObject::GetChildAtIndex(...) will return each virtual function pointer
0040 /// as a ValueObject object.
0041 ///
0042 /// The child ValueObjects will have the following values:
0043 ///
0044 /// ValueObject::GetError() will indicate success if the vtable entry was
0045 /// successfully read from memory, or an error if not.
0046 ///
0047 /// ValueObject::GetName() will be the vtable function index in the form "[%u]"
0048 /// where %u is the index.
0049 ///
0050 /// ValueObject::GetValueAsCString() will be the virtual function pointer value
0051 ///
0052 /// ValueObject::GetValueAtUnsigned(...) will return the virtual function
0053 /// pointer value.
0054 ///
0055 /// ValueObject::GetAddressOf() will return the address of the virtual function
0056 /// pointer.
0057 ///
0058 /// ValueObject::GetNumChildren() returns 0
0059 class ValueObjectVTable : public ValueObject {
0060 public:
0061   ~ValueObjectVTable() override;
0062 
0063   static lldb::ValueObjectSP Create(ValueObject &parent);
0064 
0065   std::optional<uint64_t> GetByteSize() override;
0066 
0067   llvm::Expected<uint32_t> CalculateNumChildren(uint32_t max) override;
0068 
0069   lldb::ValueType GetValueType() const override;
0070 
0071   ConstString GetTypeName() override;
0072 
0073   ConstString GetQualifiedTypeName() override;
0074 
0075   ConstString GetDisplayTypeName() override;
0076 
0077   bool IsInScope() override;
0078 
0079 protected:
0080   bool UpdateValue() override;
0081 
0082   CompilerType GetCompilerTypeImpl() override;
0083 
0084   /// The symbol for the C++ virtual function table.
0085   const Symbol *m_vtable_symbol = nullptr;
0086   /// Cache the number of vtable children when we update the value.
0087   uint32_t m_num_vtable_entries = 0;
0088   /// Cache the address size in bytes to avoid checking with the process to
0089   /// many times.
0090   uint32_t m_addr_size = 0;
0091 
0092 private:
0093   ValueObjectVTable(ValueObject &parent);
0094 
0095   ValueObject *CreateChildAtIndex(size_t idx) override;
0096   ValueObject *CreateSyntheticArrayMember(size_t idx) override {
0097     return nullptr;
0098   }
0099 
0100   // For ValueObject only
0101   ValueObjectVTable(const ValueObjectVTable &) = delete;
0102   const ValueObjectVTable &operator=(const ValueObjectVTable &) = delete;
0103 };
0104 
0105 } // namespace lldb_private
0106 
0107 #endif // LLDB_VALUEOBJECT_VALUEOBJECTVTABLE_H