[Lldb-commits] [lldb] [lldb-dap] Add clipboard context support (PR #170644)
Sergei Druzhkov via lldb-commits
lldb-commits at lists.llvm.org
Thu Dec 4 03:49:13 PST 2025
https://github.com/DrSergei created https://github.com/llvm/llvm-project/pull/170644
This patch introduces support for `clipboard` context from [DAP](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Capabilities). This feature is very useful when you want to copy all nested values from a structure or a container instead of a summary (e.g. `size = 3` for vector). I added new short mode for description generation to reduce output verbosity, which is particularly useful for primitive types.
>From 1c7e5cfcb144bd9ebcfc2ddaa2defe27305a6188 Mon Sep 17 00:00:00 2001
From: Druzhkov Sergei <serzhdruzhok at gmail.com>
Date: Thu, 4 Dec 2025 14:31:36 +0300
Subject: [PATCH] [lldb-dap] Add clipboard context support
---
lldb/include/lldb/API/SBValue.h | 2 +-
lldb/source/API/SBValue.cpp | 7 +++-
.../lldb-dap/evaluate/TestDAP_evaluate.py | 36 +++++++++++++++++++
lldb/tools/lldb-dap/Handler/RequestHandler.h | 3 +-
lldb/tools/lldb-dap/JSONUtils.cpp | 9 ++---
5 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index 0f788ff602b70..91fa78b206cf2 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -318,7 +318,7 @@ class LLDB_API SBValue {
lldb::SBValue Persist();
- bool GetDescription(lldb::SBStream &description);
+ bool GetDescription(lldb::SBStream &description, bool short_mode = false);
bool GetExpressionPath(lldb::SBStream &description);
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index e300ecee3f8ac..5ff6f4dc301ea 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1259,7 +1259,7 @@ lldb::SBValue SBValue::EvaluateExpression(const char *expr,
return result;
}
-bool SBValue::GetDescription(SBStream &description) {
+bool SBValue::GetDescription(SBStream &description, bool short_mode) {
LLDB_INSTRUMENT_VA(this, description);
Stream &strm = description.ref();
@@ -1270,6 +1270,11 @@ bool SBValue::GetDescription(SBStream &description) {
DumpValueObjectOptions options;
options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
+ if (short_mode) {
+ options.SetAllowOnelinerMode(true);
+ options.SetHideRootName(true);
+ options.SetHideRootType(true);
+ }
if (llvm::Error error = value_sp->Dump(strm, options)) {
strm << "error: " << toString(std::move(error));
return false;
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 95573780e94bd..8e1ed858b1006 100644
--- a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
+++ b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
@@ -81,6 +81,9 @@ def assertEvaluateFailure(self, expression):
def isResultExpandedDescription(self):
return self.context == "repl"
+ def isResultShortDescription(self):
+ return self.context == "clipboard"
+
def isExpressionParsedExpected(self):
return self.context != "hover"
@@ -165,6 +168,25 @@ def run_test_evaluate_expressions(
want_type="my_struct *",
want_varref=True,
)
+ elif self.isResultShortDescription():
+ self.assertEvaluate(
+ "struct1",
+ "(foo = 15)",
+ want_type="my_struct",
+ want_varref=True,
+ )
+ self.assertEvaluate(
+ "struct2",
+ r"0x.*",
+ want_type="my_struct *",
+ want_varref=True,
+ )
+ self.assertEvaluate(
+ "struct3",
+ "nullptr",
+ want_type="my_struct *",
+ want_varref=True,
+ )
else:
self.assertEvaluate(
"struct1",
@@ -240,6 +262,13 @@ def run_test_evaluate_expressions(
want_type="my_struct",
want_varref=True,
)
+ elif self.isResultShortDescription():
+ self.assertEvaluate(
+ "struct1",
+ "(foo = 15)",
+ want_type="my_struct",
+ want_varref=True,
+ )
else:
self.assertEvaluate(
"struct1",
@@ -363,3 +392,10 @@ def test_variable_evaluate_expressions(self):
self.run_test_evaluate_expressions(
"variables", enableAutoVariableSummaries=True
)
+
+ @skipIfWindows
+ def test_variable_evaluate_expressions(self):
+ # Tests expression evaluations that are triggered when value copied in editor
+ self.run_test_evaluate_expressions(
+ "clipboard", enableAutoVariableSummaries=False
+ )
diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.h b/lldb/tools/lldb-dap/Handler/RequestHandler.h
index 5d235352b7738..a0da0c1c35014 100644
--- a/lldb/tools/lldb-dap/Handler/RequestHandler.h
+++ b/lldb/tools/lldb-dap/Handler/RequestHandler.h
@@ -301,7 +301,8 @@ class EvaluateRequestHandler
llvm::Expected<protocol::EvaluateResponseBody>
Run(const protocol::EvaluateArguments &) const override;
FeatureSet GetSupportedFeatures() const override {
- return {protocol::eAdapterFeatureEvaluateForHovers};
+ return {protocol::eAdapterFeatureEvaluateForHovers,
+ protocol::eAdapterFeatureClipboardContext};
}
};
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 40b4f5b9f7f90..ea00eec8efdfc 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -825,9 +825,10 @@ VariableDescription::VariableDescription(lldb::SBValue v,
}
std::string VariableDescription::GetResult(protocol::EvaluateContext context) {
- // In repl context, the results can be displayed as multiple lines so more
- // detailed descriptions can be returned.
- if (context != protocol::eEvaluateContextRepl)
+ // In repl and clipboard contexts, the results can be displayed as multiple
+ // lines so more detailed descriptions can be returned.
+ if (context != protocol::eEvaluateContextRepl &&
+ context != protocol::eEvaluateContextClipboard)
return display_value;
if (!v.IsValid())
@@ -836,7 +837,7 @@ std::string VariableDescription::GetResult(protocol::EvaluateContext context) {
// Try the SBValue::GetDescription(), which may call into language runtime
// specific formatters (see ValueObjectPrinter).
lldb::SBStream stream;
- v.GetDescription(stream);
+ v.GetDescription(stream, context == protocol::eEvaluateContextClipboard);
llvm::StringRef description = stream.GetData();
return description.trim().str();
}
More information about the lldb-commits
mailing list