[Lldb-commits] [PATCH] D107778: [lldb] Add a test for user-defined objc_copyRealizedClassList_nolock

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 10 05:55:06 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57bf5c86591a: [lldb] Add a test for user-defined objc_copyRealizedClassList_nolock (authored by teemperor).
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107778/new/

https://reviews.llvm.org/D107778

Files:
  lldb/test/API/lang/objc/conflicting-class-list-function-from-user/Makefile
  lldb/test/API/lang/objc/conflicting-class-list-function-from-user/TestObjCClassListFunctionFromUser.py
  lldb/test/API/lang/objc/conflicting-class-list-function-from-user/main.m


Index: lldb/test/API/lang/objc/conflicting-class-list-function-from-user/main.m
===================================================================
--- /dev/null
+++ lldb/test/API/lang/objc/conflicting-class-list-function-from-user/main.m
@@ -0,0 +1,27 @@
+#import <Foundation/Foundation.h>
+#include <stdlib.h>
+
+// A function with this signature will be called by LLDB to retrieve the
+// Objective-C class list. We shouldn't call this function that is defined
+// by the user if possible.
+Class *objc_copyRealizedClassList_nolock(unsigned int *outCount) {
+  // Don't try to implement this properly but just abort.
+  abort();
+}
+
+// Define some custom class that makes LLDB read the Objective-C class list.
+ at interface CustomClass : NSObject {
+};
+ at end
+ at implementation CustomClass
+ at end
+
+int main(int argc, char **argv) {
+  id custom_class = [[CustomClass alloc] init];
+  // Make sure our trap function is emitted but never called (the test doesn't
+  // launch the executable with any args).
+  if (argc == 123) {
+    objc_copyRealizedClassList_nolock(0);
+  }
+  return 0; // break here
+}
Index: lldb/test/API/lang/objc/conflicting-class-list-function-from-user/TestObjCClassListFunctionFromUser.py
===================================================================
--- /dev/null
+++ lldb/test/API/lang/objc/conflicting-class-list-function-from-user/TestObjCClassListFunctionFromUser.py
@@ -0,0 +1,30 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @skipUnlessDarwin
+    # LLDB ends up calling the user-defined function (but at least doesn't
+    # crash).
+    @expectedFailureDarwin
+    def test(self):
+        """
+        Tests LLDB's behaviour if the user defines their own conflicting
+        objc_copyRealizedClassList_nolock function.
+        """
+
+        self.build()
+        lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.m"))
+
+        # Get the (dynamic) type of our 'id' variable so that our Objective-C
+        # runtime information is updated.
+        str_val = self.expect_expr("custom_class")
+        dyn_val = str_val.GetDynamicValue(lldb.eDynamicCanRunTarget)
+
+        # We should have retrieved the proper class list even in presence of
+        # the user-defined function.
+        self.assertEqual(dyn_val.GetTypeName(), "CustomClass *")
Index: lldb/test/API/lang/objc/conflicting-class-list-function-from-user/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/lang/objc/conflicting-class-list-function-from-user/Makefile
@@ -0,0 +1,4 @@
+OBJC_SOURCES := main.m
+LD_EXTRAS := -lobjc -framework Foundation
+
+include Makefile.rules


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107778.365452.patch
Type: text/x-patch
Size: 2847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210810/eeef2a48/attachment-0001.bin>


More information about the lldb-commits mailing list