Skip to content

Commit 38b963b

Browse files
committed
[lldb][lldb-dap] Add review changes.
1 parent ba68d13 commit 38b963b

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ def test_return_variables(self):
721721
self.verify_variables(verify_locals, local_variables, varref_dict)
722722
break
723723

724+
self.assertFalse(
725+
self.dap_server.request_setVariable(1, "(Return Value)", 20)["success"]
726+
)
727+
724728
@skipIfWindows
725729
def test_indexedVariables(self):
726730
self.do_test_indexedVariables(enableSyntheticChildDebugging=False)

lldb/tools/lldb-dap/Handler/SetVariableRequestHandler.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "JSONUtils.h"
1212
#include "RequestHandler.h"
1313

14+
using namespace lldb_dap::protocol;
15+
1416
namespace lldb_dap {
1517

1618
/// Set the variable with the given name in the variable container to a new
@@ -20,11 +22,17 @@ namespace lldb_dap {
2022
/// If a debug adapter implements both `setVariable` and `setExpression`,
2123
/// a client will only use `setExpression` if the variable has an evaluateName
2224
/// property.
23-
llvm::Expected<protocol::SetVariableResponseBody>
24-
SetVariableRequestHandler::Run(
25-
const protocol::SetVariableArguments &args) const {
25+
llvm::Expected<SetVariableResponseBody>
26+
SetVariableRequestHandler::Run(const SetVariableArguments &args) const {
2627
const auto args_name = llvm::StringRef(args.name);
2728

29+
if (args.variablesReference == UINT64_MAX) {
30+
return llvm::make_error<DAPError>(
31+
llvm::formatv("invalid reference {}", args.variablesReference).str(),
32+
llvm::inconvertibleErrorCode(),
33+
/*show_user=*/false);
34+
}
35+
2836
constexpr llvm::StringRef return_value_name = "(Return Value)";
2937
if (args_name == return_value_name)
3038
return llvm::make_error<DAPError>(
@@ -44,7 +52,7 @@ SetVariableRequestHandler::Run(
4452
VariableDescription desc(variable,
4553
dap.configuration.enableAutoVariableSummaries);
4654

47-
auto body = protocol::SetVariableResponseBody{};
55+
SetVariableResponseBody body;
4856
body.value = desc.display_value;
4957
body.type = desc.display_type_name;
5058

@@ -65,7 +73,7 @@ SetVariableRequestHandler::Run(
6573
body.variablesReference = 0;
6674
}
6775

68-
if (lldb::addr_t addr = variable.GetLoadAddress();
76+
if (const lldb::addr_t addr = variable.GetLoadAddress();
6977
addr != LLDB_INVALID_ADDRESS)
7078
body.memoryReference = EncodeMemoryReference(addr);
7179

lldb/tools/lldb-dap/Protocol/ProtocolRequests.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ struct SetVariableArguments {
299299
/// The reference of the variable container. The `variablesReference` must
300300
/// have been obtained in the current suspended state. See 'Lifetime of Object
301301
/// References' in the Overview section for details.
302-
uint64_t variablesReference;
302+
uint64_t variablesReference = UINT64_MAX;
303303

304304
/// The name of the variable in the container.
305305
std::string name;
@@ -337,13 +337,13 @@ struct SetVariableResponseBody {
337337
/// The client can use this information to present the variables in a paged
338338
/// UI and fetch them in chunks.
339339
/// The value should be less than or equal to 2147483647 (2^31-1).
340-
std::optional<uint64_t> namedVariables;
340+
std::optional<uint32_t> namedVariables;
341341

342342
/// The number of indexed child variables.
343343
/// The client can use this information to present the variables in a paged
344344
/// UI and fetch them in chunks.
345345
/// The value should be less than or equal to 2147483647 (2^31-1).
346-
std::optional<uint64_t> indexedVariables;
346+
std::optional<uint32_t> indexedVariables;
347347

348348
/// A memory reference to a location appropriate for this result.
349349
/// For pointer type eval results, this is generally a reference to the

0 commit comments

Comments
 (0)