================
@@ -1,58 +1,52 @@
-import dap_server
+"""
+Test 'module' events for dynamically loaded libraries.
+"""
+
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
 import lldbdap_testcase
-import re
 
 
 class TestDAP_module_event(lldbdap_testcase.DAPTestCaseBase):
     @skipIfWindows
     def test_module_event(self):
         program = self.getBuildArtifact("a.out")
         self.build_and_launch(program)
+        self.continue_to_exit()
 
-        source = "main.cpp"
-        breakpoint1_line = line_number(source, "// breakpoint 1")
-        breakpoint2_line = line_number(source, "// breakpoint 2")
-        breakpoint3_line = line_number(source, "// breakpoint 3")
-
-        breakpoint_ids = self.set_source_breakpoints(
-            source, [breakpoint1_line, breakpoint2_line, breakpoint3_line]
+        # Module 'remove' events will only contain the 'id' not the 'name',
+        # first lookup the module id to find all the events.
+        a_out_id = next(
+            e
+            for e in self.dap_server.module_events
+            if e["body"]["module"]["name"] == "a.out"
+        )["body"]["module"]["id"]
+        a_out_events = [
+            e
+            for e in self.dap_server.module_events
+            if e["body"]["module"]["id"] == a_out_id
+        ]
+
+        self.assertIn(
+            "new",
+            [e["body"]["reason"] for e in a_out_events],
+            "Expected a.out to load during the debug session.",
         )
-        self.continue_to_breakpoints(breakpoint_ids)
-
-        # We're now stopped at breakpoint 1 before the dlopen. Flush all the 
module events.
-        event = self.dap_server.wait_for_event(["module"])
-        while event is not None:
-            event = self.dap_server.wait_for_event(["module"])
-
-        # Continue to the second breakpoint, before the dlclose.
-        self.continue_to_breakpoints(breakpoint_ids)
-
-        # Make sure we got a module event for libother.
-        event = self.dap_server.wait_for_event(["module"])
-        self.assertIsNotNone(event, "didn't get a module event")
-        module_name = event["body"]["module"]["name"]
-        module_id = event["body"]["module"]["id"]
-        self.assertEqual(event["body"]["reason"], "new")
-        self.assertIn("libother", module_name)
 
-        # Continue to the third breakpoint, after the dlclose.
-        self.continue_to_breakpoints(breakpoint_ids)
-
-        # Make sure we got a module event for libother.
-        event = self.dap_server.wait_for_event(["module"])
-        self.assertIsNotNone(event, "didn't get a module event")
-        reason = event["body"]["reason"]
-        self.assertEqual(reason, "removed")
-        self.assertEqual(event["body"]["module"]["id"], module_id)
-
-        # The removed module event should omit everything but the module id 
and name
-        # as they are required fields.
-        module_data = event["body"]["module"]
-        required_keys = ["id", "name"]
-        self.assertListEqual(list(module_data.keys()), required_keys)
-        self.assertEqual(module_data["name"], "", "expects empty name.")
-
-        self.continue_to_exit()
+        libother_id = next(
+            e
+            for e in self.dap_server.module_events
+            if e["body"]["module"]["name"].startswith("libother.")
+        )["body"]["module"]["id"]
+        libother_events = [
+            e
+            for e in self.dap_server.module_events
+            if e["body"]["module"]["id"] == libother_id
+        ]
+
+        self.assertTrue(libother_events, "Expected libother to produce module 
events.")
+        self.assertEqual(
+            [e["body"]["reason"] for e in libother_events],
+            ["new", "removed"],
----------------
da-viper wrote:

could we also check the new comes before the removed event. and there are only 
two of them because we had cases previously of removed event being added later. 

https://github.com/llvm/llvm-project/pull/165496
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to