[all-commits] [llvm/llvm-project] 7fbd42: Add the ability to get a C++ vtable ValueObject fr...

Greg Clayton via All-commits all-commits at lists.llvm.org
Mon Oct 30 17:46:32 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7fbd427f5ebea4a4ebf25747758851875bb7e173
      https://github.com/llvm/llvm-project/commit/7fbd427f5ebea4a4ebf25747758851875bb7e173
  Author: Greg Clayton <gclayton at fb.com>
  Date:   2023-10-30 (Mon, 30 Oct 2023)

  Changed paths:
    M lldb/bindings/interface/SBTypeDocstrings.i
    M lldb/include/lldb/API/SBValue.h
    M lldb/include/lldb/Core/ValueObject.h
    M lldb/include/lldb/Core/ValueObjectChild.h
    A lldb/include/lldb/Core/ValueObjectVTable.h
    M lldb/include/lldb/Symbol/Type.h
    M lldb/include/lldb/Symbol/TypeSystem.h
    M lldb/include/lldb/Target/LanguageRuntime.h
    M lldb/include/lldb/lldb-enumerations.h
    M lldb/source/API/SBValue.cpp
    M lldb/source/Commands/CommandObjectFrame.cpp
    M lldb/source/Core/CMakeLists.txt
    M lldb/source/Core/ValueObject.cpp
    A lldb/source/Core/ValueObjectVTable.cpp
    M lldb/source/DataFormatters/CXXFunctionPointer.cpp
    M lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
    M lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
    M lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h
    M lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    M lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
    M lldb/source/Symbol/Type.cpp
    A lldb/test/API/functionalities/vtable/Makefile
    A lldb/test/API/functionalities/vtable/TestVTableValue.py
    A lldb/test/API/functionalities/vtable/main.cpp

  Log Message:
  -----------
  Add the ability to get a C++ vtable ValueObject from another ValueObj… (#67599)

Add the ability to get a C++ vtable ValueObject from another
ValueObject.

This patch adds the ability to ask a ValueObject for a ValueObject that
represents the virtual function table for a C++ class. If the
ValueObject is not a C++ class with a vtable, a valid ValueObject value
will be returned that contains an appropriate error. If it is successful
a valid ValueObject that represents vtable will be returned. The
ValueObject that is returned will have a name that matches the demangled
value for a C++ vtable mangled name like "vtable for <class-name>". It
will have N children, one for each virtual function pointer. Each
child's value is the function pointer itself, the summary is the
symbolication of this function pointer, and the type will be a valid
function pointer from the debug info if there is debug information
corresponding to the virtual function pointer.

The vtable SBValue will have the following:
- SBValue::GetName() returns "vtable for <class>"
- SBValue::GetValue() returns a string representation of the vtable
address
- SBValue::GetSummary() returns NULL
- SBValue::GetType() returns a type appropriate for a uintptr_t type for
the current process
- SBValue::GetLoadAddress() returns the address of the vtable adderess
- SBValue::GetValueAsUnsigned(...) returns the vtable address
- SBValue::GetNumChildren() returns the number of virtual function
pointers in the vtable
- SBValue::GetChildAtIndex(...) returns a SBValue that represents a
virtual function pointer

The child SBValue objects that represent a virtual function pointer has
the following values:
- SBValue::GetName() returns "[%u]" where %u is the vtable function
pointer index
- SBValue::GetValue() returns a string representation of the virtual
function pointer
- SBValue::GetSummary() returns a symbolicated respresentation of the
virtual function pointer
- SBValue::GetType() returns the function prototype type if there is
debug info, or a generic funtion prototype if there is no debug info
- SBValue::GetLoadAddress() returns the address of the virtual function
pointer
- SBValue::GetValueAsUnsigned(...) returns the virtual function pointer
- SBValue::GetNumChildren() returns 0
- SBValue::GetChildAtIndex(...) returns invalid SBValue for any index

Examples of using this API via python:

```
(lldb) script vtable = lldb.frame.FindVariable("shape_ptr").GetVTable()
(lldb) script vtable
vtable for Shape = 0x0000000100004088 {
  [0] = 0x0000000100003d20 a.out`Shape::~Shape() at main.cpp:3
  [1] = 0x0000000100003e4c a.out`Shape::~Shape() at main.cpp:3
  [2] = 0x0000000100003e7c a.out`Shape::area() at main.cpp:4
  [3] = 0x0000000100003e3c a.out`Shape::optional() at main.cpp:7
}
(lldb) script c = vtable.GetChildAtIndex(0)
(lldb) script c
(void ()) [0] = 0x0000000100003d20 a.out`Shape::~Shape() at main.cpp:3
```




More information about the All-commits mailing list