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

via lldb-commits lldb-commits at lists.llvm.org
Mon May 20 15:39:50 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r 7ecdf620330d8e044a48b6f59f8eddd2f88f01d4...25a51ed4e87042411b03ba4e57cb4a595679c37b lldb/test/API/python_api/debugger/TestDebuggerAPI.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- TestDebuggerAPI.py	2024-05-17 00:49:05.000000 +0000
+++ TestDebuggerAPI.py	2024-05-20 22:39:20.840610 +0000
@@ -167,69 +167,72 @@
         called = []
 
         def foo(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal called
-            called += [('foo', dbg_id)]
+            called += [("foo", dbg_id)]
 
         def bar(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal called
-            called += [('bar', dbg_id)]
+            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()`.
-        self.assertEqual(called, [
-            ('foo', original_dbg_id),
-            ('bar', original_dbg_id),
-        ])
+        self.assertEqual(
+            called,
+            [
+                ("foo", original_dbg_id),
+                ("bar", original_dbg_id),
+            ],
+        )
 
     def test_RemoveDestroyCallback(self):
         original_dbg_id = self.dbg.GetID()
         called = []
 
         def foo(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal called
-            called += [('foo', dbg_id)]
+            called += [("foo", dbg_id)]
 
         def bar(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal called
-            called += [('bar', dbg_id)]
+            called += [("bar", dbg_id)]
 
         token_foo = self.dbg.AddDestroyCallback(foo)
         token_bar = self.dbg.AddDestroyCallback(bar)
         ret = self.dbg.RemoveDestroyCallback(token_foo)
         self.dbg.Destroy(self.dbg)
 
         # `Remove` should be successful
         self.assertTrue(ret)
         # Should only call `bar()`
-        self.assertEqual(called, [('bar', original_dbg_id)])
+        self.assertEqual(called, [("bar", original_dbg_id)])
 
     def test_RemoveDestroyCallback_invalid_token(self):
         original_dbg_id = self.dbg.GetID()
         magic_token_that_should_not_exist = 32413
         called = []
 
         def foo(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal called
-            called += [('foo', dbg_id)]
+            called += [("foo", dbg_id)]
 
         token_foo = self.dbg.AddDestroyCallback(foo)
         ret = self.dbg.RemoveDestroyCallback(magic_token_that_should_not_exist)
         self.dbg.Destroy(self.dbg)
 
         # `Remove` should be unsuccessful
         self.assertFalse(ret)
         # Should call `foo()`
-        self.assertEqual(called, [('foo', original_dbg_id)])
+        self.assertEqual(called, [("foo", original_dbg_id)])
 
     def test_HandleDestroyCallback(self):
         """
         Validates:
         1. AddDestroyCallback and RemoveDestroyCallback work during debugger destroy.
@@ -240,45 +243,51 @@
         bar_token = None
 
         def foo(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal events
-            events.append(('foo called', dbg_id))
+            events.append(("foo called", dbg_id))
 
         def bar(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal events
-            events.append(('bar called', dbg_id))
+            events.append(("bar called", dbg_id))
 
         def add_foo(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal events
-            events.append(('add_foo called', dbg_id))
-            events.append(('foo token', self.dbg.AddDestroyCallback(foo)))
+            events.append(("add_foo called", dbg_id))
+            events.append(("foo token", self.dbg.AddDestroyCallback(foo)))
 
         def remove_bar(dbg_id):
             # Need nonlocal to modify closure variable.
             nonlocal events
-            events.append(('remove_bar called', dbg_id))
-            events.append(('remove bar ret', self.dbg.RemoveDestroyCallback(bar_token)))
+            events.append(("remove_bar called", dbg_id))
+            events.append(("remove bar ret", self.dbg.RemoveDestroyCallback(bar_token)))
 
         # Setup
-        events.append(('add_foo token', self.dbg.AddDestroyCallback(add_foo)))
+        events.append(("add_foo token", self.dbg.AddDestroyCallback(add_foo)))
         bar_token = self.dbg.AddDestroyCallback(bar)
-        events.append(('bar token', bar_token))
-        events.append(('remove_bar token', self.dbg.AddDestroyCallback(remove_bar)))
+        events.append(("bar token", bar_token))
+        events.append(("remove_bar token", self.dbg.AddDestroyCallback(remove_bar)))
         # Destroy
         self.dbg.Destroy(self.dbg)
 
-        self.assertEqual(events, [
-            # Setup
-            ('add_foo token', 0), # add_foo should be added
-            ('bar token', 1), # bar should be added
-            ('remove_bar token', 2), # remove_bar should be added
-            # Destroy
-            ('add_foo called', original_dbg_id), # add_foo should be called
-            ('foo token', 3), # foo should be added
-            ('bar called', original_dbg_id), # bar should be called
-            ('remove_bar called', original_dbg_id), # remove_bar should be called
-            ('remove bar ret', False), # remove_bar should fail, because it's already invoked and removed
-            ('foo called', original_dbg_id), # foo should be called
-        ])
+        self.assertEqual(
+            events,
+            [
+                # Setup
+                ("add_foo token", 0),  # add_foo should be added
+                ("bar token", 1),  # bar should be added
+                ("remove_bar token", 2),  # remove_bar should be added
+                # Destroy
+                ("add_foo called", original_dbg_id),  # add_foo should be called
+                ("foo token", 3),  # foo should be added
+                ("bar called", original_dbg_id),  # bar should be called
+                ("remove_bar called", original_dbg_id),  # remove_bar should be called
+                (
+                    "remove bar ret",
+                    False,
+                ),  # remove_bar should fail, because it's already invoked and removed
+                ("foo called", original_dbg_id),  # foo should be called
+            ],
+        )

``````````

</details>


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


More information about the lldb-commits mailing list