Skip to content

Commit 4088557

Browse files
authored
[lldb-dap] Move request capabilities into request handlers (NFC) (#131943)
This distributes the registration of request related capabilities to the corresponding request handler. Global and unsupported capabilities are registered at the DAP level.
1 parent 04e39ce commit 4088557

File tree

4 files changed

+79
-75
lines changed

4 files changed

+79
-75
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,4 +1145,33 @@ lldb::SBValue Variables::FindVariable(uint64_t variablesReference,
11451145
return variable;
11461146
}
11471147

1148+
llvm::StringMap<bool> DAP::GetCapabilities() {
1149+
llvm::StringMap<bool> capabilities;
1150+
1151+
// Supported capabilities.
1152+
capabilities["supportTerminateDebuggee"] = true;
1153+
capabilities["supportsDataBreakpoints"] = true;
1154+
capabilities["supportsDelayedStackTraceLoading"] = true;
1155+
capabilities["supportsEvaluateForHovers"] = true;
1156+
capabilities["supportsExceptionOptions"] = true;
1157+
capabilities["supportsLogPoints"] = true;
1158+
capabilities["supportsProgressReporting"] = true;
1159+
capabilities["supportsSteppingGranularity"] = true;
1160+
capabilities["supportsValueFormattingOptions"] = true;
1161+
1162+
// Unsupported capabilities.
1163+
capabilities["supportsGotoTargetsRequest"] = false;
1164+
capabilities["supportsLoadedSourcesRequest"] = false;
1165+
capabilities["supportsRestartFrame"] = false;
1166+
capabilities["supportsStepBack"] = false;
1167+
1168+
// Capabilities associated with specific requests.
1169+
for (auto &kv : request_handlers) {
1170+
for (auto &request_kv : kv.second->GetCapabilities())
1171+
capabilities[request_kv.getKey()] = request_kv.getValue();
1172+
}
1173+
1174+
return capabilities;
1175+
}
1176+
11481177
} // namespace lldb_dap

lldb/tools/lldb-dap/DAP.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ struct DAP {
364364
request_handlers[Handler::getCommand()] = std::make_unique<Handler>(*this);
365365
}
366366

367+
/// Return a key-value list of capabilities.
368+
llvm::StringMap<bool> GetCapabilities();
369+
367370
/// Debuggee will continue from stopped state.
368371
void WillContinue() { variables.Clear(); }
369372

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

Lines changed: 5 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -377,49 +377,15 @@ void InitializeRequestHandler::operator()(
377377
// process and more.
378378
dap.event_thread = std::thread(EventThreadFunction, std::ref(dap));
379379

380-
// The debug adapter supports the configurationDoneRequest.
381-
body.try_emplace("supportsConfigurationDoneRequest", true);
382-
// The debug adapter supports function breakpoints.
383-
body.try_emplace("supportsFunctionBreakpoints", true);
384-
// The debug adapter supports conditional breakpoints.
385-
body.try_emplace("supportsConditionalBreakpoints", true);
386-
// The debug adapter supports breakpoints that break execution after a
387-
// specified number of hits.
388-
body.try_emplace("supportsHitConditionalBreakpoints", true);
389-
// The debug adapter supports a (side effect free) evaluate request for
390-
// data hovers.
391-
body.try_emplace("supportsEvaluateForHovers", true);
380+
llvm::StringMap<bool> capabilities = dap.GetCapabilities();
381+
for (auto &kv : capabilities)
382+
body.try_emplace(kv.getKey(), kv.getValue());
383+
392384
// Available filters or options for the setExceptionBreakpoints request.
393385
llvm::json::Array filters;
394-
for (const auto &exc_bp : *dap.exception_breakpoints) {
386+
for (const auto &exc_bp : *dap.exception_breakpoints)
395387
filters.emplace_back(CreateExceptionBreakpointFilter(exc_bp));
396-
}
397388
body.try_emplace("exceptionBreakpointFilters", std::move(filters));
398-
// The debug adapter supports launching a debugee in intergrated VSCode
399-
// terminal.
400-
body.try_emplace("supportsRunInTerminalRequest", true);
401-
// The debug adapter supports stepping back via the stepBack and
402-
// reverseContinue requests.
403-
body.try_emplace("supportsStepBack", false);
404-
// The debug adapter supports setting a variable to a value.
405-
body.try_emplace("supportsSetVariable", true);
406-
// The debug adapter supports restarting a frame.
407-
body.try_emplace("supportsRestartFrame", false);
408-
// The debug adapter supports the gotoTargetsRequest.
409-
body.try_emplace("supportsGotoTargetsRequest", false);
410-
// The debug adapter supports the stepInTargetsRequest.
411-
body.try_emplace("supportsStepInTargetsRequest", true);
412-
// The debug adapter supports the completions request.
413-
body.try_emplace("supportsCompletionsRequest", true);
414-
// The debug adapter supports the disassembly request.
415-
body.try_emplace("supportsDisassembleRequest", true);
416-
// The debug adapter supports the `breakpointLocations` request.
417-
body.try_emplace("supportsBreakpointLocationsRequest", true);
418-
// The debug adapter supports stepping granularities (argument `granularity`)
419-
// for the stepping requests.
420-
body.try_emplace("supportsSteppingGranularity", true);
421-
// The debug adapter support for instruction breakpoint.
422-
body.try_emplace("supportsInstructionBreakpoints", true);
423389

424390
llvm::json::Array completion_characters;
425391
completion_characters.emplace_back(".");
@@ -428,42 +394,6 @@ void InitializeRequestHandler::operator()(
428394
body.try_emplace("completionTriggerCharacters",
429395
std::move(completion_characters));
430396

431-
// The debug adapter supports the modules request.
432-
body.try_emplace("supportsModulesRequest", true);
433-
// The set of additional module information exposed by the debug adapter.
434-
// body.try_emplace("additionalModuleColumns"] = ColumnDescriptor
435-
// Checksum algorithms supported by the debug adapter.
436-
// body.try_emplace("supportedChecksumAlgorithms"] = ChecksumAlgorithm
437-
// The debug adapter supports the RestartRequest. In this case a client
438-
// should not implement 'restart' by terminating and relaunching the adapter
439-
// but by calling the RestartRequest.
440-
body.try_emplace("supportsRestartRequest", true);
441-
// The debug adapter supports 'exceptionOptions' on the
442-
// setExceptionBreakpoints request.
443-
body.try_emplace("supportsExceptionOptions", true);
444-
// The debug adapter supports a 'format' attribute on the stackTraceRequest,
445-
// variablesRequest, and evaluateRequest.
446-
body.try_emplace("supportsValueFormattingOptions", true);
447-
// The debug adapter supports the exceptionInfo request.
448-
body.try_emplace("supportsExceptionInfoRequest", true);
449-
// The debug adapter supports the 'terminateDebuggee' attribute on the
450-
// 'disconnect' request.
451-
body.try_emplace("supportTerminateDebuggee", true);
452-
// The debug adapter supports the delayed loading of parts of the stack,
453-
// which requires that both the 'startFrame' and 'levels' arguments and the
454-
// 'totalFrames' result of the 'StackTrace' request are supported.
455-
body.try_emplace("supportsDelayedStackTraceLoading", true);
456-
// The debug adapter supports the 'loadedSources' request.
457-
body.try_emplace("supportsLoadedSourcesRequest", false);
458-
// The debug adapter supports sending progress reporting events.
459-
body.try_emplace("supportsProgressReporting", true);
460-
// The debug adapter supports 'logMessage' in breakpoint.
461-
body.try_emplace("supportsLogPoints", true);
462-
// The debug adapter supports data watchpoints.
463-
body.try_emplace("supportsDataBreakpoints", true);
464-
// The debug adapter supports the `readMemory` request.
465-
body.try_emplace("supportsReadMemoryRequest", true);
466-
467397
// Put in non-DAP specification lldb specific information.
468398
llvm::json::Object lldb_json;
469399
lldb_json.try_emplace("version", dap.debugger.GetVersionString());

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class BaseRequestHandler {
4545

4646
virtual void operator()(const protocol::Request &request) const = 0;
4747

48+
virtual llvm::StringMap<bool> GetCapabilities() const { return {}; }
49+
4850
protected:
4951
/// Helpers used by multiple request handlers.
5052
/// FIXME: Move these into the DAP class?
@@ -153,13 +155,19 @@ class BreakpointLocationsRequestHandler : public LegacyRequestHandler {
153155
public:
154156
using LegacyRequestHandler::LegacyRequestHandler;
155157
static llvm::StringLiteral getCommand() { return "breakpointLocations"; }
158+
llvm::StringMap<bool> GetCapabilities() const override {
159+
return {{"supportsBreakpointLocationsRequest", true}};
160+
}
156161
void operator()(const llvm::json::Object &request) const override;
157162
};
158163

159164
class CompletionsRequestHandler : public LegacyRequestHandler {
160165
public:
161166
using LegacyRequestHandler::LegacyRequestHandler;
162167
static llvm::StringLiteral getCommand() { return "completions"; }
168+
llvm::StringMap<bool> GetCapabilities() const override {
169+
return {{"supportsCompletionsRequest", true}};
170+
}
163171
void operator()(const llvm::json::Object &request) const override;
164172
};
165173

@@ -174,6 +182,9 @@ class ConfigurationDoneRequestHandler : public LegacyRequestHandler {
174182
public:
175183
using LegacyRequestHandler::LegacyRequestHandler;
176184
static llvm::StringLiteral getCommand() { return "configurationDone"; }
185+
llvm::StringMap<bool> GetCapabilities() const override {
186+
return {{"supportsConfigurationDoneRequest", true}};
187+
}
177188
void operator()(const llvm::json::Object &request) const override;
178189
};
179190

@@ -198,13 +209,19 @@ class ExceptionInfoRequestHandler : public LegacyRequestHandler {
198209
public:
199210
using LegacyRequestHandler::LegacyRequestHandler;
200211
static llvm::StringLiteral getCommand() { return "exceptionInfo"; }
212+
llvm::StringMap<bool> GetCapabilities() const override {
213+
return {{"supportsExceptionInfoRequest", true}};
214+
}
201215
void operator()(const llvm::json::Object &request) const override;
202216
};
203217

204218
class InitializeRequestHandler : public LegacyRequestHandler {
205219
public:
206220
using LegacyRequestHandler::LegacyRequestHandler;
207221
static llvm::StringLiteral getCommand() { return "initialize"; }
222+
llvm::StringMap<bool> GetCapabilities() const override {
223+
return {{"supportsRunInTerminalRequest", true}};
224+
}
208225
void operator()(const llvm::json::Object &request) const override;
209226
};
210227

@@ -219,6 +236,9 @@ class RestartRequestHandler : public LegacyRequestHandler {
219236
public:
220237
using LegacyRequestHandler::LegacyRequestHandler;
221238
static llvm::StringLiteral getCommand() { return "restart"; }
239+
llvm::StringMap<bool> GetCapabilities() const override {
240+
return {{"supportsRestartRequest", true}};
241+
}
222242
void operator()(const llvm::json::Object &request) const override;
223243
};
224244

@@ -240,6 +260,9 @@ class StepInTargetsRequestHandler : public LegacyRequestHandler {
240260
public:
241261
using LegacyRequestHandler::LegacyRequestHandler;
242262
static llvm::StringLiteral getCommand() { return "stepInTargets"; }
263+
llvm::StringMap<bool> GetCapabilities() const override {
264+
return {{"supportsStepInTargetsRequest", true}};
265+
}
243266
void operator()(const llvm::json::Object &request) const override;
244267
};
245268

@@ -254,6 +277,10 @@ class SetBreakpointsRequestHandler : public LegacyRequestHandler {
254277
public:
255278
using LegacyRequestHandler::LegacyRequestHandler;
256279
static llvm::StringLiteral getCommand() { return "setBreakpoints"; }
280+
llvm::StringMap<bool> GetCapabilities() const override {
281+
return {{"supportsConditionalBreakpoints", true},
282+
{"supportsHitConditionalBreakpoints", true}};
283+
}
257284
void operator()(const llvm::json::Object &request) const override;
258285
};
259286

@@ -268,6 +295,9 @@ class SetFunctionBreakpointsRequestHandler : public LegacyRequestHandler {
268295
public:
269296
using LegacyRequestHandler::LegacyRequestHandler;
270297
static llvm::StringLiteral getCommand() { return "setFunctionBreakpoints"; }
298+
llvm::StringMap<bool> GetCapabilities() const override {
299+
return {{"supportsFunctionBreakpoints", true}};
300+
}
271301
void operator()(const llvm::json::Object &request) const override;
272302
};
273303

@@ -305,6 +335,9 @@ class ModulesRequestHandler : public LegacyRequestHandler {
305335
public:
306336
using LegacyRequestHandler::LegacyRequestHandler;
307337
static llvm::StringLiteral getCommand() { return "modules"; }
338+
llvm::StringMap<bool> GetCapabilities() const override {
339+
return {{"supportsModulesRequest", true}};
340+
}
308341
void operator()(const llvm::json::Object &request) const override;
309342
};
310343

@@ -326,6 +359,9 @@ class SetVariableRequestHandler : public LegacyRequestHandler {
326359
public:
327360
using LegacyRequestHandler::LegacyRequestHandler;
328361
static llvm::StringLiteral getCommand() { return "setVariable"; }
362+
llvm::StringMap<bool> GetCapabilities() const override {
363+
return {{"supportsSetVariable", true}};
364+
}
329365
void operator()(const llvm::json::Object &request) const override;
330366
};
331367

@@ -371,13 +407,19 @@ class DisassembleRequestHandler : public LegacyRequestHandler {
371407
public:
372408
using LegacyRequestHandler::LegacyRequestHandler;
373409
static llvm::StringLiteral getCommand() { return "disassemble"; }
410+
llvm::StringMap<bool> GetCapabilities() const override {
411+
return {{"supportsDisassembleRequest", true}};
412+
}
374413
void operator()(const llvm::json::Object &request) const override;
375414
};
376415

377416
class ReadMemoryRequestHandler : public LegacyRequestHandler {
378417
public:
379418
using LegacyRequestHandler::LegacyRequestHandler;
380419
static llvm::StringLiteral getCommand() { return "readMemory"; }
420+
llvm::StringMap<bool> GetCapabilities() const override {
421+
return {{"supportsReadMemoryRequest", true}};
422+
}
381423
void operator()(const llvm::json::Object &request) const override;
382424
};
383425

0 commit comments

Comments
 (0)