Skip to content

Commit 3cea00c

Browse files
authored
Merge pull request #6369 from Michael137/bugfix/lldb-member-func-ptr-format-to-20221013
[cherry-pick][stable/20221013] [lldb] Format member pointers as regular pointers
2 parents 993d39c + 3f445fc commit 3cea00c

File tree

10 files changed

+82
-54
lines changed

10 files changed

+82
-54
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: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,28 +3018,11 @@ bool TypeSystemClang::IsCStringType(lldb::opaque_compiler_type_t type,
30183018
}
30193019

30203020
bool TypeSystemClang::IsFunctionType(lldb::opaque_compiler_type_t type) {
3021-
if (type) {
3022-
clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3023-
3024-
if (qual_type->isFunctionType()) {
3025-
return true;
3026-
}
3021+
auto isFunctionType = [&](clang::QualType qual_type) {
3022+
return qual_type->isFunctionType();
3023+
};
30273024

3028-
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3029-
switch (type_class) {
3030-
default:
3031-
break;
3032-
case clang::Type::LValueReference:
3033-
case clang::Type::RValueReference: {
3034-
const clang::ReferenceType *reference_type =
3035-
llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3036-
if (reference_type)
3037-
return IsFunctionType(
3038-
reference_type->getPointeeType().getAsOpaquePtr());
3039-
} break;
3040-
}
3041-
}
3042-
return false;
3025+
return IsTypeImpl(type, isFunctionType);
30433026
}
30443027

30453028
// Used to detect "Homogeneous Floating-point Aggregates"
@@ -3153,11 +3136,13 @@ TypeSystemClang::GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
31533136
return CompilerType();
31543137
}
31553138

3156-
bool TypeSystemClang::IsFunctionPointerType(lldb::opaque_compiler_type_t type) {
3139+
bool TypeSystemClang::IsTypeImpl(
3140+
lldb::opaque_compiler_type_t type,
3141+
llvm::function_ref<bool(clang::QualType)> predicate) const {
31573142
if (type) {
31583143
clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
31593144

3160-
if (qual_type->isFunctionPointerType())
3145+
if (predicate(qual_type))
31613146
return true;
31623147

31633148
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
@@ -3170,20 +3155,34 @@ bool TypeSystemClang::IsFunctionPointerType(lldb::opaque_compiler_type_t type) {
31703155
const clang::ReferenceType *reference_type =
31713156
llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
31723157
if (reference_type)
3173-
return IsFunctionPointerType(
3174-
reference_type->getPointeeType().getAsOpaquePtr());
3158+
return IsTypeImpl(reference_type->getPointeeType().getAsOpaquePtr(), predicate);
31753159
} break;
31763160
}
31773161
}
31783162
return false;
31793163
}
31803164

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+
3174+
bool TypeSystemClang::IsFunctionPointerType(lldb::opaque_compiler_type_t type) {
3175+
auto isFunctionPointerType = [](clang::QualType qual_type) {
3176+
return qual_type->isFunctionPointerType();
3177+
};
3178+
3179+
return IsTypeImpl(type, isFunctionPointerType);
3180+
}
3181+
31813182
bool TypeSystemClang::IsBlockPointerType(
31823183
lldb::opaque_compiler_type_t type,
31833184
CompilerType *function_pointer_type_ptr) {
3184-
if (type) {
3185-
clang::QualType qual_type = RemoveWrappingTypes(GetCanonicalQualType(type));
3186-
3185+
auto isBlockPointerType = [&](clang::QualType qual_type) {
31873186
if (qual_type->isBlockPointerType()) {
31883187
if (function_pointer_type_ptr) {
31893188
const clang::BlockPointerType *block_pointer_type =
@@ -3196,23 +3195,10 @@ bool TypeSystemClang::IsBlockPointerType(
31963195
return true;
31973196
}
31983197

3199-
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
3200-
switch (type_class) {
3201-
default:
3202-
break;
3198+
return false;
3199+
};
32033200

3204-
case clang::Type::LValueReference:
3205-
case clang::Type::RValueReference: {
3206-
const clang::ReferenceType *reference_type =
3207-
llvm::cast<clang::ReferenceType>(qual_type.getTypePtr());
3208-
if (reference_type)
3209-
return IsBlockPointerType(
3210-
reference_type->getPointeeType().getAsOpaquePtr(),
3211-
function_pointer_type_ptr);
3212-
} break;
3213-
}
3214-
}
3215-
return false;
3201+
return IsTypeImpl(type, isBlockPointerType);
32163202
}
32173203

32183204
bool TypeSystemClang::IsIntegerType(lldb::opaque_compiler_type_t type,
@@ -5272,7 +5258,7 @@ lldb::Format TypeSystemClang::GetFormat(lldb::opaque_compiler_type_t type) {
52725258
case clang::Type::RValueReference:
52735259
return lldb::eFormatHex;
52745260
case clang::Type::MemberPointer:
5275-
break;
5261+
return lldb::eFormatHex;
52765262
case clang::Type::Complex: {
52775263
if (qual_type->isComplexType())
52785264
return lldb::eFormatComplex;

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

Lines changed: 5 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

@@ -1137,6 +1139,9 @@ class TypeSystemClang : public TypeSystem {
11371139
const clang::ClassTemplateSpecializationDecl *
11381140
GetAsTemplateSpecialization(lldb::opaque_compiler_type_t type);
11391141

1142+
bool IsTypeImpl(lldb::opaque_compiler_type_t type,
1143+
llvm::function_ref<bool(clang::QualType)> predicate) const;
1144+
11401145
// Classes that inherit from TypeSystemClang can see and modify these
11411146
std::string m_target_triple;
11421147
std::unique_ptr<clang::ASTContext> m_ast_up;

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ class TypeSystemSwift : public TypeSystem {
240240
CompilerType *function_pointer_type_ptr) override {
241241
return false;
242242
}
243+
bool IsMemberFunctionPointerType(
244+
lldb::opaque_compiler_type_t type) override {
245+
return false;
246+
}
243247
bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override {
244248
return false;
245249
}

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,16 @@ def cleanup():
285285
matching=False,
286286
substrs=['(int) iAmInt = 0x00000001'])
287287
self.expect("frame variable iAmInt", substrs=['(int) iAmInt = 1'])
288+
289+
# Check that pointer to members are correctly formatted
290+
self.expect(
291+
"frame variable member_ptr",
292+
substrs=['member_ptr = 0x'])
293+
self.expect(
294+
"frame variable member_func_ptr",
295+
substrs=['member_func_ptr = 0x',
296+
'(a.out`IUseCharStar::member_func(int) at main.cpp:61)'])
297+
self.expect(
298+
"frame variable ref_to_member_func_ptr",
299+
substrs=['ref_to_member_func_ptr = 0x',
300+
'(a.out`IUseCharStar::member_func(int) at main.cpp:61)'])

lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ struct IUseCharStar
5757
{
5858
const char* pointer;
5959
IUseCharStar() : pointer("Hello world") {}
60+
61+
char const *member_func(int) { return ""; }
6062
};
6163

6264
int main (int argc, const char * argv[])
@@ -106,7 +108,12 @@ int main (int argc, const char * argv[])
106108
char* strptr = "Hello world!";
107109

108110
i_am_cooler the_coolest_guy(1,2,3.14,6.28,'E','G');
109-
111+
112+
const char *IUseCharStar::*member_ptr = &IUseCharStar::pointer;
113+
const char *(IUseCharStar::*member_func_ptr)(int) =
114+
&IUseCharStar::member_func;
115+
auto &ref_to_member_func_ptr = member_func_ptr;
116+
110117
return 0; // Set break point at this line.
111118
}
112119

lldb/test/Shell/SymbolFile/NativePDB/ast-types.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ int SI::*mp9 = nullptr;
131131
// CHECK: (Anonymous<int>) AnonInt = (AnonymousMember = 0)
132132
// CHECK: (Anonymous<A::B::C<void>>) AnonABCVoid = (AnonymousMember = 0)
133133
// CHECK: (Anonymous<A::B::C<void>>::D) AnonABCVoidD = (AnonymousDMember = 0)
134-
// CHECK: (void (SI::*)()) mp1 = 00 00 00 00 00 00 00 00
135-
// CHECK: (void (MI::*)()) mp2 = 00 00 00 00 00 00 00 00
136-
// CHECK: (void (MI2::*)()) mp3 = 00 00 00 00 00 00 00 00
137-
// CHECK: (void (VI::*)()) mp4 = 00 00 00 00 00 00 00 00
138-
// CHECK: (void (VI2::*)()) mp5 = 00 00 00 00 00 00 00 00
139-
// CHECK: (void (UI::*)()) mp6 = 00 00 00 00 00 00 00 00
134+
// CHECK: (void (SI::*)()) mp1 = 0x0000000000000000
135+
// CHECK: (void (MI::*)()) mp2 = 0x0000000000000000
136+
// CHECK: (void (MI2::*)()) mp3 = 0x0000000000000000
137+
// CHECK: (void (VI::*)()) mp4 = 0x0000000000000000
138+
// CHECK: (void (VI2::*)()) mp5 = 0x0000000000000000
139+
// CHECK: (void (UI::*)()) mp6 = 0x0000000000000000
140140
// CHECK: (void (MI::**)()) mp7 = 0x0000000000000000
141141
// CHECK: (void (VI2::**)()) mp8 = 0x0000000000000000
142-
// CHECK: (int SI::*) mp9 = ff ff ff ff
142+
// CHECK: (int SI::*) mp9 = 0xffffffff
143143
// CHECK: Dumping clang ast for 1 modules.
144144
// CHECK: TranslationUnitDecl {{.*}}
145145
// CHECK: |-CXXRecordDecl {{.*}} class TrivialC definition

0 commit comments

Comments
 (0)