https://github.com/Teemperor created 
https://github.com/llvm/llvm-project/pull/207181

ProcessAttach calls Destroy() on the test SBProcess when tearing down the test. 
However, Destroy() only detaches us from the process but keeps it running. The 
correct way would be to call Kill() which does the same as Destroy but also 
kills an process we attached to.

To avoid this issue in future tests, I moved this tear down logic to the common 
test tear-down logic used for all tests. I don't see any reason for why we 
should not try to kill an alive test inferior at the end of a test.

>From 14c6fb0581402e60e1488108b4d1245ccded0162 Mon Sep 17 00:00:00 2001
From: Raphael Isemann <[email protected]>
Date: Thu, 2 Jul 2026 11:17:02 +0100
Subject: [PATCH] [lldb][test] Always kill test processes

ProcessAttach calls Destroy() on the test SBProcess when tearing down
the test. However, Destroy() only detaches us from the process but
keeps it running. The correct way would be to call Kill() which does
the same as Destroy but also kills an process we attached to.

To avoid this issue in future tests, I moved this tear down logic
to the common test tear-down logic used for all tests. I don't see any
reason for why we should not try to kill an alive test inferior at the
end of a test.
---
 lldb/packages/Python/lldbsuite/test/lldbtest.py      | 12 ++++++++++++
 .../API/commands/process/attach/TestProcessAttach.py |  7 -------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 416b357754015..7adec7d677b3f 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1203,6 +1203,18 @@ def tearDown(self):
                 for dict in reversed(self.dicts):
                     self.cleanup(dictionary=dict)
 
+        # Kill any process a target is still holding on to.
+        for i in range(self.dbg.GetNumTargets()):
+            process = self.dbg.GetTargetAtIndex(i).GetProcess()
+            # Only kill processes that are still alive.
+            if process.IsValid() and process.is_alive:
+                process.Kill()
+                self.assertEqual(
+                    process.GetState(),
+                    lldb.eStateExited,
+                    "Failed to kill process during teardown",
+                )
+
         # Remove subprocesses created by the test.
         self.cleanupSubprocesses()
 
diff --git a/lldb/test/API/commands/process/attach/TestProcessAttach.py 
b/lldb/test/API/commands/process/attach/TestProcessAttach.py
index 5abcf69d0acba..f0fa9af4e4d0d 100644
--- a/lldb/test/API/commands/process/attach/TestProcessAttach.py
+++ b/lldb/test/API/commands/process/attach/TestProcessAttach.py
@@ -142,10 +142,3 @@ def 
test_attach_to_process_by_id_correct_executable_offset(self):
         )
         self.runCmd("process continue")
         self.expect("v g_val", substrs=["12345"])
-
-    def tearDown(self):
-        # Destroy process before TestBase.tearDown()
-        self.dbg.GetSelectedTarget().GetProcess().Destroy()
-
-        # Call super's tearDown().
-        TestBase.tearDown(self)

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

Reply via email to