[Lldb-commits] [lldb] [lldb-dap] Improving lldbdap_testcase.py error diagnosability and adding exception handling for dap server disconnect and terminations (PR #155335)
Piyush Jaiswal via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 25 21:10:19 PDT 2025
https://github.com/piyushjaiswal98 updated https://github.com/llvm/llvm-project/pull/155335
>From 443c2b4c983399fce0ac6805abfa7ca2fffd1322 Mon Sep 17 00:00:00 2001
From: Piyush Jaiswal <piyushjais at meta.com>
Date: Mon, 25 Aug 2025 17:31:45 -0700
Subject: [PATCH 1/2] Improving lldbdap server error diagnosability and adding
exception handling
---
.../test/tools/lldb-dap/lldbdap_testcase.py | 28 +++++++++++++++----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index c23b2e73fb45e..8691a87b6fa87 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -466,8 +466,15 @@ def attach(
# if we throw an exception during the test case.
def cleanup():
if disconnectAutomatically:
- self.dap_server.request_disconnect(terminateDebuggee=True)
- self.dap_server.terminate()
+ try:
+ self.dap_server.request_disconnect(terminateDebuggee=True)
+ except (ValueError, TimeoutError, BrokenPipeError, ConnectionError, Exception) as e:
+ # DAP server might not be responsive, skip disconnect and terminate directly
+ print(f"Warning: disconnect failed ({e}), skipping and terminating directly")
+ try:
+ self.dap_server.terminate()
+ except Exception as e:
+ print(f"Warning: terminate failed ({e}), DAP server may have already died")
# Execute the cleanup function during test case tear down.
self.addTearDownHook(cleanup)
@@ -477,9 +484,20 @@ def cleanup():
if expectFailure:
return response
if not (response and response["success"]):
- self.assertTrue(
- response["success"], "attach failed (%s)" % (response["message"])
- )
+ error_msg = "attach failed"
+ if response:
+ if "message" in response:
+ error_msg += " (%s)" % response["message"]
+ elif "body" in response and "error" in response["body"]:
+ if "format" in response["body"]["error"]:
+ error_msg += " (%s)" % response["body"]["error"]["format"]
+ else:
+ error_msg += " (error in body)"
+ else:
+ error_msg += " (no error details available)"
+ else:
+ error_msg += " (no response)"
+ self.assertTrue(response and response["success"], error_msg)
def launch(
self,
>From 1c68d3f63f020eaea8aceefc015641fa1fa8e801 Mon Sep 17 00:00:00 2001
From: Piyush Jaiswal <piyushjais at meta.com>
Date: Mon, 25 Aug 2025 21:09:59 -0700
Subject: [PATCH 2/2] spliting into 2 PRs and consolidating exeptions
---
.../test/tools/lldb-dap/lldbdap_testcase.py | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
index 8691a87b6fa87..04de3cc6cec0d 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py
@@ -468,7 +468,7 @@ def cleanup():
if disconnectAutomatically:
try:
self.dap_server.request_disconnect(terminateDebuggee=True)
- except (ValueError, TimeoutError, BrokenPipeError, ConnectionError, Exception) as e:
+ except Exception as e:
# DAP server might not be responsive, skip disconnect and terminate directly
print(f"Warning: disconnect failed ({e}), skipping and terminating directly")
try:
@@ -484,20 +484,9 @@ def cleanup():
if expectFailure:
return response
if not (response and response["success"]):
- error_msg = "attach failed"
- if response:
- if "message" in response:
- error_msg += " (%s)" % response["message"]
- elif "body" in response and "error" in response["body"]:
- if "format" in response["body"]["error"]:
- error_msg += " (%s)" % response["body"]["error"]["format"]
- else:
- error_msg += " (error in body)"
- else:
- error_msg += " (no error details available)"
- else:
- error_msg += " (no response)"
- self.assertTrue(response and response["success"], error_msg)
+ self.assertTrue(
+ response["success"], "attach failed (%s)" % (response["message"])
+ )
def launch(
self,
More information about the lldb-commits
mailing list