Skip to content

Commit 4b47511

Browse files
committed
[lldb][TypeSystemClang] Format pointers to member functions as eFormatHex
Before this patch, LLDB used to format pointers to members, such as, ``` void (Foo::*pointer_to_member_func)() = &Foo::member_func; ``` as `eFormatBytes`. E.g., ``` (lldb) v pointer_to_member_func (void (Foo::*)()) $1 = 94 3f 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ``` This patch makes sure we format pointers to member functions the same way we do regular function pointers. After this patch we format member pointers as: ``` (lldb) v pointer_to_member_func (void (Foo::*)()) ::pointer_to_member_func = 0x00000000000000000000000100003f94 ``` Differential Revision: https://reviews.llvm.org/D145241 (cherry picked from commit b642fd5)
1 parent a2f57b8 commit 4b47511

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5249,7 +5249,7 @@ lldb::Format TypeSystemClang::GetFormat(lldb::opaque_compiler_type_t type) {
52495249
case clang::Type::RValueReference:
52505250
return lldb::eFormatHex;
52515251
case clang::Type::MemberPointer:
5252-
break;
5252+
return lldb::eFormatHex;
52535253
case clang::Type::Complex: {
52545254
if (qual_type->isComplexType())
52555255
return lldb::eFormatComplex;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,14 @@ 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+
self.expect(
297+
"frame variable ref_to_member_func_ptr",
298+
substrs=['ref_to_member_func_ptr = 0x'])

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

0 commit comments

Comments
 (0)