[Lldb-commits] [lldb] b642fd5 - [lldb][TypeSystemClang] Format pointers to member functions as eFormatHex

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 3 09:44:58 PST 2023


Author: Michael Buch
Date: 2023-03-03T17:44:36Z
New Revision: b642fd5ee250247ccefb38099169b4ee8ac4112b

URL: https://github.com/llvm/llvm-project/commit/b642fd5ee250247ccefb38099169b4ee8ac4112b
DIFF: https://github.com/llvm/llvm-project/commit/b642fd5ee250247ccefb38099169b4ee8ac4112b.diff

LOG: [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

Added: 
    

Modified: 
    lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
    lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
    lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 388c3675dacc5..e08e7bcd96e38 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5277,7 +5277,7 @@ lldb::Format TypeSystemClang::GetFormat(lldb::opaque_compiler_type_t type) {
   case clang::Type::RValueReference:
     return lldb::eFormatHex;
   case clang::Type::MemberPointer:
-    break;
+    return lldb::eFormatHex;
   case clang::Type::Complex: {
     if (qual_type->isComplexType())
       return lldb::eFormatComplex;

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py b/lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
index fa9a3f5093d05..fb79d1463e5e1 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
@@ -285,3 +285,14 @@ def cleanup():
             matching=False,
             substrs=['(int) iAmInt = 0x00000001'])
         self.expect("frame variable iAmInt", substrs=['(int) iAmInt = 1'])
+
+        # Check that pointer to members are correctly formatted
+        self.expect(
+            "frame variable member_ptr",
+            substrs=['member_ptr = 0x'])
+        self.expect(
+            "frame variable member_func_ptr",
+            substrs=['member_func_ptr = 0x'])
+        self.expect(
+            "frame variable ref_to_member_func_ptr",
+            substrs=['ref_to_member_func_ptr = 0x'])

diff  --git a/lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp b/lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp
index c81a68fd2094a..f1cf507e47f87 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp
@@ -57,6 +57,8 @@ struct IUseCharStar
 {
 	const char* pointer;
 	IUseCharStar() : pointer("Hello world") {}
+
+        char const *member_func(int) { return ""; }
 };
 
 int main (int argc, const char * argv[])
@@ -106,7 +108,12 @@ int main (int argc, const char * argv[])
     char* strptr     = "Hello world!";
     
     i_am_cooler the_coolest_guy(1,2,3.14,6.28,'E','G');
-        
+
+    const char *IUseCharStar::*member_ptr = &IUseCharStar::pointer;
+    const char *(IUseCharStar::*member_func_ptr)(int) =
+        &IUseCharStar::member_func;
+    auto &ref_to_member_func_ptr = member_func_ptr;
+
     return 0; // Set break point at this line.
 }
 


        


More information about the lldb-commits mailing list