[Lldb-commits] [PATCH] D145241: [lldb][TypeSystemClang] Format pointers to member functions as eFormatHex

Michael Buch via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 3 06:29:08 PST 2023


Michael137 created this revision.
Michael137 added a reviewer: aprantl.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145241

Files:
  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


Index: lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp
+++ lldb/test/API/functionalities/data-formatter/data-formatter-cpp/main.cpp
@@ -57,6 +57,8 @@
 {
 	const char* pointer;
 	IUseCharStar() : pointer("Hello world") {}
+
+        char const *member_func(int) { return ""; }
 };
 
 int main (int argc, const char * argv[])
@@ -106,7 +108,12 @@
     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.
 }
 
Index: lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
@@ -285,3 +285,14 @@
             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'])
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===================================================================
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -5277,7 +5277,7 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145241.502118.patch
Type: text/x-patch
Size: 2372 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230303/741702cf/attachment-0001.bin>


More information about the lldb-commits mailing list