[Lldb-commits] [lldb] SBDebugger: Add new APIs `AddDestroyCallback` and `RemoveDestroyCallback` (PR #89868)

via lldb-commits lldb-commits at lists.llvm.org
Mon May 13 10:42:50 PDT 2024


================
@@ -161,3 +161,122 @@ def foo(dbg_id):
         original_dbg_id = self.dbg.GetID()
         self.dbg.Destroy(self.dbg)
         self.assertEqual(destroy_dbg_id, original_dbg_id)
+
+    def test_AddDestroyCallback(self):
+        original_dbg_id = self.dbg.GetID()
+        called = []
+
+        def foo(dbg_id):
+            # Need nonlocal to modify closure variable.
+            nonlocal called
+            called += [('foo', dbg_id)]
+
+        def bar(dbg_id):
+            # Need nonlocal to modify closure variable.
+            nonlocal called
+            called += [('bar', dbg_id)]
+
+        token_foo = self.dbg.AddDestroyCallback(foo)
+        token_bar = self.dbg.AddDestroyCallback(bar)
+        self.dbg.Destroy(self.dbg)
+
+        # Should call both `foo()` and `bar()`. Order is undermined because
+        # of the `unordered_map` in the implementation.
+        self.assertTrue(('foo', original_dbg_id) in called)
+        self.assertTrue(('bar', original_dbg_id) in called)
----------------
jeffreytan81 wrote:

Use `self.assertIn()`

https://github.com/llvm/llvm-project/pull/89868


More information about the lldb-commits mailing list