[lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider for member-function...
authorMichael Buch <michaelbuch12@gmail.com>
Fri, 3 Mar 2023 14:18:21 +0000 (14:18 +0000)
committerMichael Buch <michaelbuch12@gmail.com>
Fri, 3 Mar 2023 17:44:36 +0000 (17:44 +0000)
With this patch member-function pointers are formatted using
`CXXFunctionPointerSummaryProvider`.

This turns,
```
(lldb) v pointer_to_member_func
(void (Foo::*)()) ::pointer_to_member_func = 0x00000000000000000000000100003f94
```
into
```
(lldb) v pointer_to_member_func
(void (Foo::*)()) ::pointer_to_member_func = 0x00000000000000000000000100003f94 (a.out`Foo::member_func() at main.cpp:3)
```

Differential Revision: https://reviews.llvm.org/D145242

lldb/include/lldb/Symbol/CompilerType.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/source/Symbol/CompilerType.cpp
lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py

index c96fc5a..50587f4 100644 (file)
@@ -164,6 +164,8 @@ public:
 
   bool IsFunctionPointerType() const;
 
+  bool IsMemberFunctionPointerType() const;
+
   bool
   IsBlockPointerType(CompilerType *function_pointer_type_ptr = nullptr) const;
 
index a358d6f..9c27fd9 100644 (file)
@@ -169,6 +169,9 @@ public:
 
   virtual bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) = 0;
 
+  virtual bool
+  IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) = 0;
+
   virtual bool IsBlockPointerType(lldb::opaque_compiler_type_t type,
                                   CompilerType *function_pointer_type_ptr) = 0;
 
index 1b152c1..0dfaa92 100644 (file)
@@ -1390,7 +1390,8 @@ CPlusPlusLanguage::GetHardcodedSummaries() {
                   TypeSummaryImpl::Flags(),
                   lldb_private::formatters::CXXFunctionPointerSummaryProvider,
                   "Function pointer summary provider"));
-          if (valobj.GetCompilerType().IsFunctionPointerType()) {
+          if (CompilerType CT = valobj.GetCompilerType();
+              CT.IsFunctionPointerType() || CT.IsMemberFunctionPointerType()) {
             return formatter_sp;
           }
           return nullptr;
index e08e7bc..aefc67b 100644 (file)
@@ -3194,6 +3194,15 @@ bool TypeSystemClang::IsTypeImpl(
   return false;
 }
 
+bool TypeSystemClang::IsMemberFunctionPointerType(
+    lldb::opaque_compiler_type_t type) {
+  auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
+    return qual_type->isMemberFunctionPointerType();
+  };
+
+  return IsTypeImpl(type, isMemberFunctionPointerType);
+}
+
 bool TypeSystemClang::IsFunctionPointerType(lldb::opaque_compiler_type_t type) {
   auto isFunctionPointerType = [](clang::QualType qual_type) {
     return qual_type->isFunctionPointerType();
index 9751c0d..d6c09cf 100644 (file)
@@ -658,6 +658,8 @@ public:
 
   bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override;
 
+  bool IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) override;
+
   bool IsBlockPointerType(lldb::opaque_compiler_type_t type,
                           CompilerType *function_pointer_type_ptr) override;
 
index 11a7d09..d6dc43c 100644 (file)
@@ -154,6 +154,13 @@ bool CompilerType::IsFunctionPointerType() const {
   return false;
 }
 
+bool CompilerType::IsMemberFunctionPointerType() const {
+  if (IsValid())
+    if (auto type_system_sp = GetTypeSystem())
+      return type_system_sp->IsMemberFunctionPointerType(m_type);
+  return false;
+}
+
 bool CompilerType::IsBlockPointerType(
     CompilerType *function_pointer_type_ptr) const {
   if (IsValid())
index fb79d14..2085025 100644 (file)
@@ -292,7 +292,9 @@ class CppDataFormatterTestCase(TestBase):
             substrs=['member_ptr = 0x'])
         self.expect(
             "frame variable member_func_ptr",
-            substrs=['member_func_ptr = 0x'])
+            substrs=['member_func_ptr = 0x',
+                     '(a.out`IUseCharStar::member_func(int) at main.cpp:61)'])
         self.expect(
             "frame variable ref_to_member_func_ptr",
-            substrs=['ref_to_member_func_ptr = 0x'])
+            substrs=['ref_to_member_func_ptr = 0x',
+                     '(a.out`IUseCharStar::member_func(int) at main.cpp:61)'])