Skip to content

Commit 14bd9a7

Browse files
committed
[lldb] [lldb-dap] Return optional values for unsigned json values.
1 parent 5c375c3 commit 14bd9a7

16 files changed

+45
-38
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ lldb::SBThread DAP::GetLLDBThread(const llvm::json::Object &arguments) {
531531
}
532532

533533
lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) {
534-
const uint64_t frame_id = GetUnsigned(arguments, "frameId", UINT64_MAX);
534+
const uint64_t frame_id =
535+
GetUnsigned(arguments, "frameId").value_or(UINT64_MAX);
535536
lldb::SBProcess process = target.GetProcess();
536537
// Upper 32 bits is the thread index ID
537538
lldb::SBThread thread =

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
5454
const int invalid_port = 0;
5555
const auto *arguments = request.getObject("arguments");
5656
const lldb::pid_t pid =
57-
GetUnsigned(arguments, "pid", LLDB_INVALID_PROCESS_ID);
57+
GetUnsigned(arguments, "pid").value_or(LLDB_INVALID_PROCESS_ID);
5858
const auto gdb_remote_port =
59-
GetUnsigned(arguments, "gdb-remote-port", invalid_port);
59+
GetUnsigned(arguments, "gdb-remote-port").value_or(invalid_port);
6060
const auto gdb_remote_hostname =
6161
GetString(arguments, "gdb-remote-hostname", "localhost");
6262
if (pid != LLDB_INVALID_PROCESS_ID)
@@ -70,7 +70,8 @@ void AttachRequestHandler::operator()(const llvm::json::Object &request) const {
7070
dap.terminate_commands = GetStrings(arguments, "terminateCommands");
7171
auto attachCommands = GetStrings(arguments, "attachCommands");
7272
llvm::StringRef core_file = GetString(arguments, "coreFile");
73-
const uint64_t timeout_seconds = GetUnsigned(arguments, "timeout", 30);
73+
const uint64_t timeout_seconds =
74+
GetUnsigned(arguments, "timeout").value_or(30);
7475
dap.stop_at_entry = core_file.empty()
7576
? GetBoolean(arguments, "stopOnEntry").value_or(false)
7677
: true;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ void BreakpointLocationsRequestHandler::operator()(
131131
auto *arguments = request.getObject("arguments");
132132
auto *source = arguments->getObject("source");
133133
std::string path = GetString(source, "path").str();
134-
uint64_t start_line = GetUnsigned(arguments, "line", 0);
135-
uint64_t start_column = GetUnsigned(arguments, "column", 0);
136-
uint64_t end_line = GetUnsigned(arguments, "endLine", start_line);
137-
uint64_t end_column =
138-
GetUnsigned(arguments, "endColumn", std::numeric_limits<uint64_t>::max());
134+
const uint64_t start_line = GetUnsigned(arguments, "line").value_or(0);
135+
const uint64_t start_column = GetUnsigned(arguments, "column").value_or(0);
136+
const uint64_t end_line =
137+
GetUnsigned(arguments, "endLine").value_or(start_line);
138+
const uint64_t end_column =
139+
GetUnsigned(arguments, "endColumn")
140+
.value_or(std::numeric_limits<uint64_t>::max());
139141

140142
lldb::SBFileSpec file_spec(path.c_str(), true);
141143
lldb::SBSymbolContextList compile_units =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void DataBreakpointInfoRequestHandler::operator()(
116116
llvm::json::Array accessTypes{"read", "write", "readWrite"};
117117
const auto *arguments = request.getObject("arguments");
118118
const auto variablesReference =
119-
GetUnsigned(arguments, "variablesReference", 0);
119+
GetUnsigned(arguments, "variablesReference").value_or(0);
120120
llvm::StringRef name = GetString(arguments, "name");
121121
lldb::SBFrame frame = dap.GetLLDBFrame(*arguments);
122122
lldb::SBValue variable = dap.variables.FindVariable(variablesReference, name);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ void DisassembleRequestHandler::operator()(
113113
return;
114114
}
115115

116-
const auto inst_count = GetUnsigned(arguments, "instructionCount", 0);
116+
const auto inst_count =
117+
GetUnsigned(arguments, "instructionCount").value_or(0);
117118
lldb::SBInstructionList insts = dap.target.ReadInstructions(addr, inst_count);
118119

119120
if (!insts.IsValid()) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ void LocationsRequestHandler::operator()(
9797
FillResponse(request, response);
9898
auto *arguments = request.getObject("arguments");
9999

100-
uint64_t location_id = GetUnsigned(arguments, "locationReference", 0);
100+
uint64_t location_id =
101+
GetUnsigned(arguments, "locationReference").value_or(0);
101102
// We use the lowest bit to distinguish between value location and declaration
102103
// location
103104
auto [var_ref, is_value_location] = UnpackLocation(location_id);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void ReadMemoryRequestHandler::operator()(
109109
}
110110
lldb::addr_t addr_int = *addr_opt;
111111
addr_int += GetSigned(arguments, "offset", 0);
112-
const uint64_t count_requested = GetUnsigned(arguments, "count", 0);
112+
const uint64_t count_requested = GetUnsigned(arguments, "count").value_or(0);
113113

114114
// We also need support reading 0 bytes
115115
// VS Code sends those requests to check if a `memoryReference`

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ RequestHandler::LaunchProcess(const llvm::json::Object &request) const {
184184
launch_info.SetDetachOnError(detachOnError);
185185
launch_info.SetLaunchFlags(flags | lldb::eLaunchFlagDebug |
186186
lldb::eLaunchFlagStopAtEntry);
187-
const uint64_t timeout_seconds = GetUnsigned(arguments, "timeout", 30);
187+
const uint64_t timeout_seconds =
188+
GetUnsigned(arguments, "timeout").value_or(30);
188189

189190
if (GetBoolean(arguments, "runInTerminal").value_or(false)) {
190191
if (llvm::Error err = RunInTerminal(dap, request, timeout_seconds))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void SetVariableRequestHandler::operator()(
115115
const auto *arguments = request.getObject("arguments");
116116
// This is a reference to the containing variable/scope
117117
const auto variablesReference =
118-
GetUnsigned(arguments, "variablesReference", 0);
118+
GetUnsigned(arguments, "variablesReference").value_or(0);
119119
llvm::StringRef name = GetString(arguments, "name");
120120

121121
const auto value = GetString(arguments, "value");
@@ -133,7 +133,7 @@ void SetVariableRequestHandler::operator()(
133133
// the name of the variable. We could have two shadowed variables with the
134134
// same name in "Locals" or "Globals". In our case the "id" absolute index
135135
// of the variable within the dap.variables list.
136-
const auto id_value = GetUnsigned(arguments, "id", UINT64_MAX);
136+
const auto id_value = GetUnsigned(arguments, "id").value_or(UINT64_MAX);
137137
if (id_value != UINT64_MAX) {
138138
variable = dap.variables.GetVariable(id_value);
139139
} else {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ void SourceRequestHandler::operator()(const llvm::json::Object &request) const {
8585
const auto *arguments = request.getObject("arguments");
8686
const auto *source = arguments->getObject("source");
8787
llvm::json::Object body;
88-
int64_t source_ref = GetUnsigned(
89-
source, "sourceReference", GetUnsigned(arguments, "sourceReference", 0));
88+
int64_t source_ref =
89+
GetUnsigned(source, "sourceReference")
90+
.value_or(GetUnsigned(arguments, "sourceReference").value_or(0));
9091

9192
if (source_ref) {
9293
lldb::SBProcess process = dap.target.GetProcess();

0 commit comments

Comments
 (0)