Skip to content

Commit 4b8bda5

Browse files
committed
[lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider for member-function pointers
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 (cherry picked from commit 6bd46e7)
1 parent 4b47511 commit 4b8bda5

File tree

7 files changed

+29
-3
lines changed

7 files changed

+29
-3
lines changed

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class CompilerType {
163163

164164
bool IsFunctionPointerType() const;
165165

166+
bool IsMemberFunctionPointerType() const;
167+
166168
bool
167169
IsBlockPointerType(CompilerType *function_pointer_type_ptr = nullptr) const;
168170

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ class TypeSystem : public PluginInterface,
173173

174174
virtual bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) = 0;
175175

176+
virtual bool
177+
IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) = 0;
178+
176179
virtual bool IsBlockPointerType(lldb::opaque_compiler_type_t type,
177180
CompilerType *function_pointer_type_ptr) = 0;
178181

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,8 @@ CPlusPlusLanguage::GetHardcodedSummaries() {
13431343
TypeSummaryImpl::Flags(),
13441344
lldb_private::formatters::CXXFunctionPointerSummaryProvider,
13451345
"Function pointer summary provider"));
1346-
if (valobj.GetCompilerType().IsFunctionPointerType()) {
1346+
if (CompilerType CT = valobj.GetCompilerType();
1347+
CT.IsFunctionPointerType() || CT.IsMemberFunctionPointerType()) {
13471348
return formatter_sp;
13481349
}
13491350
return nullptr;

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,15 @@ bool TypeSystemClang::IsTypeImpl(
31623162
return false;
31633163
}
31643164

3165+
bool TypeSystemClang::IsMemberFunctionPointerType(
3166+
lldb::opaque_compiler_type_t type) {
3167+
auto isMemberFunctionPointerType = [](clang::QualType qual_type) {
3168+
return qual_type->isMemberFunctionPointerType();
3169+
};
3170+
3171+
return IsTypeImpl(type, isMemberFunctionPointerType);
3172+
}
3173+
31653174
bool TypeSystemClang::IsFunctionPointerType(lldb::opaque_compiler_type_t type) {
31663175
auto isFunctionPointerType = [](clang::QualType qual_type) {
31673176
return qual_type->isFunctionPointerType();

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ class TypeSystemClang : public TypeSystem {
649649

650650
bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override;
651651

652+
bool IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) override;
653+
652654
bool IsBlockPointerType(lldb::opaque_compiler_type_t type,
653655
CompilerType *function_pointer_type_ptr) override;
654656

lldb/source/Symbol/CompilerType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ bool CompilerType::IsFunctionPointerType() const {
146146
return false;
147147
}
148148

149+
bool CompilerType::IsMemberFunctionPointerType() const {
150+
if (IsValid())
151+
if (auto type_system_sp = GetTypeSystem())
152+
return type_system_sp->IsMemberFunctionPointerType(m_type);
153+
return false;
154+
}
155+
149156
bool CompilerType::IsBlockPointerType(
150157
CompilerType *function_pointer_type_ptr) const {
151158
if (IsValid())

lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ def cleanup():
292292
substrs=['member_ptr = 0x'])
293293
self.expect(
294294
"frame variable member_func_ptr",
295-
substrs=['member_func_ptr = 0x'])
295+
substrs=['member_func_ptr = 0x',
296+
'(a.out`IUseCharStar::member_func(int) at main.cpp:61)'])
296297
self.expect(
297298
"frame variable ref_to_member_func_ptr",
298-
substrs=['ref_to_member_func_ptr = 0x'])
299+
substrs=['ref_to_member_func_ptr = 0x',
300+
'(a.out`IUseCharStar::member_func(int) at main.cpp:61)'])

0 commit comments

Comments
 (0)