[Lldb-commits] [lldb] [lldb-dap] Don't duplicate script output in the evaluate response (PR #232583)
Nathan Fusselman via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 15 20:55:57 PDT 2026
https://github.com/nathanfusselman created https://github.com/llvm/llvm-project/pull/232583
`script print(...)` run through an evaluate request writes to the debugger's immediate output stream, which lldb-dap already forwards as an `output` event, and the same text was also returned in the response body, so the debug console showed it twice. Honor the immediate stream the way the lldb driver does, by dropping the buffered copy when one was set.
rdar://188121059
>From c9f325f4ae6560b329c169fc6c7430393caebc72 Mon Sep 17 00:00:00 2001
From: Nathan Fusselman <nfusselman at apple.com>
Date: Thu, 15 Oct 2026 16:01:10 -0700
Subject: [PATCH] [lldb-dap] Don't duplicate script output in the evaluate
response
`script print(...)` run through an evaluate request writes to the
debugger's immediate output stream, which lldb-dap already forwards as an
`output` event, and the same text was also returned in the response body,
so the debug console showed it twice. Honor the immediate stream the way
the lldb driver does, by dropping the buffered copy when one was set.
rdar://188121059
---
.../API/tools/lldb-dap/evaluate/TestDAP_evaluate.py | 10 ++++++++++
.../variables/children/TestDAP_variables_children.py | 8 ++++----
lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp | 7 +++++--
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
index 49d8967340e403..6c17a9ff336d2a 100644
--- a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
+++ b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
@@ -248,6 +248,16 @@ def assert_eval_fails_frameless(expression: str):
after=event_before_help_eval,
)
+ # `script print(...)` output goes to the console only, not the
+ # evaluate response.
+ marker = "lldb_dap_test_script_print_marker"
+ event_before_script_eval = session.last_event()
+ eval_body = session.evaluate(
+ f"script print('{marker}')", context=context
+ )
+ session.verify_evaluate(eval_body, result="")
+ session.collect_console(until=marker, after=event_before_script_eval)
+
# A valid frame should add local lookup without preventing the same
# global from taking precedence over the LLDB command.
eval_body = a_frame.evaluate("help", context=context)
diff --git a/lldb/test/API/tools/lldb-dap/variables/children/TestDAP_variables_children.py b/lldb/test/API/tools/lldb-dap/variables/children/TestDAP_variables_children.py
index fae2de35f013d6..3e1a203ddf4e42 100644
--- a/lldb/test/API/tools/lldb-dap/variables/children/TestDAP_variables_children.py
+++ b/lldb/test/API/tools/lldb-dap/variables/children/TestDAP_variables_children.py
@@ -34,10 +34,10 @@ def test_get_num_children(self):
self.assertEqual(indexed_var.indexedVariables, 1)
self.assertIsNone(not_indexed_var.indexedVariables)
- resp_body = session.evaluate(
- "`script formatter.num_children_calls", context="repl"
- )
- self.assertIn("['Indexed']", resp_body.result)
+ # `script` output goes to the console only, not the evaluate response.
+ event_before = session.last_event()
+ session.evaluate("`script formatter.num_children_calls", context="repl")
+ session.collect_console(until="['Indexed']", after=event_before)
@expectedFailureAll(archs=["arm$", "arm64", "aarch64"])
@skipIfWasm # there is no ABI plugin for Wasm to find a return value with
diff --git a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
index ac0d1ed9fb1d92..8408ae1b69d2bc 100644
--- a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp
@@ -118,13 +118,16 @@ EvaluateRequestHandler::Run(const EvaluateArguments &arguments) const {
/*add_to_history=*/true);
if (!result.Succeeded()) {
+ const char *error = result.GetError(/*only_if_no_immediate=*/true);
return llvm::make_error<DAPError>(
- std::string(result.GetError(), result.GetErrorSize()),
+ error ? std::string(error, result.GetErrorSize()) : std::string(),
/**error_code=*/llvm::inconvertibleErrorCode(),
/**show_user= */ false);
}
- body.result = std::string(result.GetOutput(), result.GetOutputSize());
+ const char *output = result.GetOutput(/*only_if_no_immediate=*/true);
+ body.result =
+ output ? std::string(output, result.GetOutputSize()) : std::string();
return body;
}
More information about the lldb-commits
mailing list