| 1 | //===-- Request.h ---------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLDB_TOOLS_LLDB_DAP_HANDLER_HANDLER_H |
| 10 | #define LLDB_TOOLS_LLDB_DAP_HANDLER_HANDLER_H |
| 11 | |
| 12 | #include "DAP.h" |
| 13 | #include "DAPError.h" |
| 14 | #include "DAPLog.h" |
| 15 | #include "Protocol/ProtocolBase.h" |
| 16 | #include "Protocol/ProtocolRequests.h" |
| 17 | #include "Protocol/ProtocolTypes.h" |
| 18 | #include "llvm/ADT/DenseSet.h" |
| 19 | #include "llvm/ADT/StringRef.h" |
| 20 | #include "llvm/Support/Error.h" |
| 21 | #include "llvm/Support/JSON.h" |
| 22 | #include <optional> |
| 23 | #include <type_traits> |
| 24 | #include <variant> |
| 25 | #include <vector> |
| 26 | |
| 27 | template <typename T> struct is_optional : std::false_type {}; |
| 28 | |
| 29 | template <typename T> struct is_optional<std::optional<T>> : std::true_type {}; |
| 30 | |
| 31 | template <typename T> |
| 32 | inline constexpr bool is_optional_v = is_optional<T>::value; |
| 33 | |
| 34 | namespace lldb_dap { |
| 35 | struct DAP; |
| 36 | |
| 37 | /// Base class for request handlers. Do not extend this directly: Extend |
| 38 | /// the RequestHandler template subclass instead. |
| 39 | class BaseRequestHandler { |
| 40 | public: |
| 41 | BaseRequestHandler(DAP &dap) : dap(dap) {} |
| 42 | |
| 43 | /// BaseRequestHandler are not copyable. |
| 44 | /// @{ |
| 45 | BaseRequestHandler(const BaseRequestHandler &) = delete; |
| 46 | BaseRequestHandler &operator=(const BaseRequestHandler &) = delete; |
| 47 | /// @} |
| 48 | |
| 49 | virtual ~BaseRequestHandler() = default; |
| 50 | |
| 51 | void Run(const protocol::Request &); |
| 52 | |
| 53 | virtual void operator()(const protocol::Request &request) const = 0; |
| 54 | |
| 55 | using FeatureSet = llvm::SmallDenseSet<AdapterFeature, 1>; |
| 56 | virtual FeatureSet GetSupportedFeatures() const { return {}; } |
| 57 | |
| 58 | protected: |
| 59 | /// Helpers used by multiple request handlers. |
| 60 | /// FIXME: Move these into the DAP class? |
| 61 | /// @{ |
| 62 | |
| 63 | /// Prints a welcome message on the editor if the preprocessor variable |
| 64 | /// LLDB_DAP_WELCOME_MESSAGE is defined. |
| 65 | void PrintWelcomeMessage() const; |
| 66 | |
| 67 | // Takes a LaunchRequest object and launches the process, also handling |
| 68 | // runInTerminal if applicable. It doesn't do any of the additional |
| 69 | // initialization and bookkeeping stuff that is needed for `request_launch`. |
| 70 | // This way we can reuse the process launching logic for RestartRequest too. |
| 71 | llvm::Error |
| 72 | LaunchProcess(const protocol::LaunchRequestArguments &request) const; |
| 73 | |
| 74 | // Check if the step-granularity is `instruction`. |
| 75 | bool HasInstructionGranularity(const llvm::json::Object &request) const; |
| 76 | |
| 77 | /// @} |
| 78 | |
| 79 | DAP &dap; |
| 80 | }; |
| 81 | |
| 82 | /// FIXME: Migrate callers to typed RequestHandler for improved type handling. |
| 83 | class LegacyRequestHandler : public BaseRequestHandler { |
| 84 | using BaseRequestHandler::BaseRequestHandler; |
| 85 | virtual void operator()(const llvm::json::Object &request) const = 0; |
| 86 | void operator()(const protocol::Request &request) const override { |
| 87 | auto req = toJSON(request); |
| 88 | (*this)(*req.getAsObject()); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | template <typename Args> |
| 93 | llvm::Expected<Args> parseArgs(const protocol::Request &request) { |
| 94 | if (!is_optional_v<Args> && !request.arguments) |
| 95 | return llvm::make_error<DAPError>( |
| 96 | Args: llvm::formatv(Fmt: "arguments required for command '{0}' " |
| 97 | "but none received" , |
| 98 | Vals: request.command) |
| 99 | .str()); |
| 100 | |
| 101 | Args arguments; |
| 102 | llvm::json::Path::Root root("arguments" ); |
| 103 | if (request.arguments && !fromJSON(*request.arguments, arguments, root)) { |
| 104 | std::string parse_failure; |
| 105 | llvm::raw_string_ostream OS(parse_failure); |
| 106 | OS << "invalid arguments for request '" << request.command |
| 107 | << "': " << llvm::toString(E: root.getError()) << "\n" ; |
| 108 | root.printErrorContext(*request.arguments, OS); |
| 109 | return llvm::make_error<DAPError>(Args&: parse_failure); |
| 110 | } |
| 111 | |
| 112 | return arguments; |
| 113 | } |
| 114 | template <> |
| 115 | inline llvm::Expected<protocol::EmptyArguments> |
| 116 | parseArgs(const protocol::Request &request) { |
| 117 | return std::nullopt; |
| 118 | } |
| 119 | |
| 120 | /// Base class for handling DAP requests. Handlers should declare their |
| 121 | /// arguments and response body types like: |
| 122 | /// |
| 123 | /// class MyRequestHandler : public RequestHandler<Arguments, Response> { |
| 124 | /// .... |
| 125 | /// }; |
| 126 | template <typename Args, typename Resp> |
| 127 | class RequestHandler : public BaseRequestHandler { |
| 128 | using BaseRequestHandler::BaseRequestHandler; |
| 129 | |
| 130 | void operator()(const protocol::Request &request) const override { |
| 131 | protocol::Response response; |
| 132 | response.request_seq = request.seq; |
| 133 | response.command = request.command; |
| 134 | |
| 135 | llvm::Expected<Args> arguments = parseArgs<Args>(request); |
| 136 | if (llvm::Error err = arguments.takeError()) { |
| 137 | HandleErrorResponse(err: std::move(err), response); |
| 138 | dap.Send(message: response); |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | if constexpr (std::is_same_v<Resp, llvm::Error>) { |
| 143 | if (llvm::Error err = Run(*arguments)) { |
| 144 | HandleErrorResponse(err: std::move(err), response); |
| 145 | } else { |
| 146 | response.success = true; |
| 147 | } |
| 148 | } else { |
| 149 | Resp body = Run(*arguments); |
| 150 | if (llvm::Error err = body.takeError()) { |
| 151 | HandleErrorResponse(err: std::move(err), response); |
| 152 | } else { |
| 153 | response.success = true; |
| 154 | response.body = std::move(*body); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // Mark the request as 'cancelled' if the debugger was interrupted while |
| 159 | // evaluating this handler. |
| 160 | if (dap.debugger.InterruptRequested()) { |
| 161 | dap.debugger.CancelInterruptRequest(); |
| 162 | response.success = false; |
| 163 | response.message = protocol::eResponseMessageCancelled; |
| 164 | response.body = std::nullopt; |
| 165 | } |
| 166 | |
| 167 | dap.Send(message: response); |
| 168 | |
| 169 | PostRun(); |
| 170 | }; |
| 171 | |
| 172 | virtual Resp Run(const Args &) const = 0; |
| 173 | |
| 174 | /// A hook for a request handler to run additional operations after the |
| 175 | /// request response is sent but before the next request handler. |
| 176 | /// |
| 177 | /// *NOTE*: PostRun will be invoked even if the `Run` operation returned an |
| 178 | /// error. |
| 179 | virtual void PostRun() const {}; |
| 180 | |
| 181 | void HandleErrorResponse(llvm::Error err, |
| 182 | protocol::Response &response) const { |
| 183 | response.success = false; |
| 184 | llvm::handleAllErrors( |
| 185 | std::move(err), |
| 186 | [&](const NotStoppedError &err) { |
| 187 | response.message = lldb_dap::protocol::eResponseMessageNotStopped; |
| 188 | }, |
| 189 | [&](const DAPError &err) { |
| 190 | protocol::ErrorMessage error_message; |
| 191 | error_message.sendTelemetry = false; |
| 192 | error_message.format = err.getMessage(); |
| 193 | error_message.showUser = err.getShowUser(); |
| 194 | error_message.id = err.convertToErrorCode().value(); |
| 195 | error_message.url = err.getURL(); |
| 196 | error_message.urlLabel = err.getURLLabel(); |
| 197 | protocol::ErrorResponseBody body; |
| 198 | body.error = error_message; |
| 199 | response.body = body; |
| 200 | }, |
| 201 | [&](const llvm::ErrorInfoBase &err) { |
| 202 | protocol::ErrorMessage error_message; |
| 203 | error_message.showUser = true; |
| 204 | error_message.sendTelemetry = false; |
| 205 | error_message.format = err.message(); |
| 206 | error_message.id = err.convertToErrorCode().value(); |
| 207 | protocol::ErrorResponseBody body; |
| 208 | body.error = error_message; |
| 209 | response.body = body; |
| 210 | }); |
| 211 | } |
| 212 | }; |
| 213 | |
| 214 | class AttachRequestHandler |
| 215 | : public RequestHandler<protocol::AttachRequestArguments, |
| 216 | protocol::AttachResponse> { |
| 217 | public: |
| 218 | using RequestHandler::RequestHandler; |
| 219 | static llvm::StringLiteral GetCommand() { return "attach" ; } |
| 220 | llvm::Error Run(const protocol::AttachRequestArguments &args) const override; |
| 221 | void PostRun() const override; |
| 222 | }; |
| 223 | |
| 224 | class BreakpointLocationsRequestHandler |
| 225 | : public RequestHandler< |
| 226 | protocol::BreakpointLocationsArguments, |
| 227 | llvm::Expected<protocol::BreakpointLocationsResponseBody>> { |
| 228 | public: |
| 229 | using RequestHandler::RequestHandler; |
| 230 | static llvm::StringLiteral GetCommand() { return "breakpointLocations" ; } |
| 231 | FeatureSet GetSupportedFeatures() const override { |
| 232 | return {protocol::eAdapterFeatureBreakpointLocationsRequest}; |
| 233 | } |
| 234 | llvm::Expected<protocol::BreakpointLocationsResponseBody> |
| 235 | Run(const protocol::BreakpointLocationsArguments &args) const override; |
| 236 | |
| 237 | std::vector<std::pair<uint32_t, uint32_t>> |
| 238 | GetSourceBreakpointLocations(std::string path, uint32_t start_line, |
| 239 | uint32_t start_column, uint32_t end_line, |
| 240 | uint32_t end_column) const; |
| 241 | std::vector<std::pair<uint32_t, uint32_t>> |
| 242 | GetAssemblyBreakpointLocations(int64_t source_reference, uint32_t start_line, |
| 243 | uint32_t end_line) const; |
| 244 | }; |
| 245 | |
| 246 | class CompletionsRequestHandler : public LegacyRequestHandler { |
| 247 | public: |
| 248 | using LegacyRequestHandler::LegacyRequestHandler; |
| 249 | static llvm::StringLiteral GetCommand() { return "completions" ; } |
| 250 | FeatureSet GetSupportedFeatures() const override { |
| 251 | return {protocol::eAdapterFeatureCompletionsRequest}; |
| 252 | } |
| 253 | void operator()(const llvm::json::Object &request) const override; |
| 254 | }; |
| 255 | |
| 256 | class ContinueRequestHandler |
| 257 | : public RequestHandler<protocol::ContinueArguments, |
| 258 | llvm::Expected<protocol::ContinueResponseBody>> { |
| 259 | public: |
| 260 | using RequestHandler::RequestHandler; |
| 261 | static llvm::StringLiteral GetCommand() { return "continue" ; } |
| 262 | llvm::Expected<protocol::ContinueResponseBody> |
| 263 | Run(const protocol::ContinueArguments &args) const override; |
| 264 | }; |
| 265 | |
| 266 | class ConfigurationDoneRequestHandler |
| 267 | : public RequestHandler<protocol::ConfigurationDoneArguments, |
| 268 | protocol::ConfigurationDoneResponse> { |
| 269 | public: |
| 270 | using RequestHandler::RequestHandler; |
| 271 | static llvm::StringLiteral GetCommand() { return "configurationDone" ; } |
| 272 | FeatureSet GetSupportedFeatures() const override { |
| 273 | return {protocol::eAdapterFeatureConfigurationDoneRequest}; |
| 274 | } |
| 275 | protocol::ConfigurationDoneResponse |
| 276 | Run(const protocol::ConfigurationDoneArguments &) const override; |
| 277 | }; |
| 278 | |
| 279 | class DisconnectRequestHandler |
| 280 | : public RequestHandler<std::optional<protocol::DisconnectArguments>, |
| 281 | protocol::DisconnectResponse> { |
| 282 | public: |
| 283 | using RequestHandler::RequestHandler; |
| 284 | static llvm::StringLiteral GetCommand() { return "disconnect" ; } |
| 285 | FeatureSet GetSupportedFeatures() const override { |
| 286 | return {protocol::eAdapterFeatureTerminateDebuggee}; |
| 287 | } |
| 288 | llvm::Error |
| 289 | Run(const std::optional<protocol::DisconnectArguments> &args) const override; |
| 290 | }; |
| 291 | |
| 292 | class EvaluateRequestHandler : public LegacyRequestHandler { |
| 293 | public: |
| 294 | using LegacyRequestHandler::LegacyRequestHandler; |
| 295 | static llvm::StringLiteral GetCommand() { return "evaluate" ; } |
| 296 | void operator()(const llvm::json::Object &request) const override; |
| 297 | FeatureSet GetSupportedFeatures() const override { |
| 298 | return {protocol::eAdapterFeatureEvaluateForHovers}; |
| 299 | } |
| 300 | }; |
| 301 | |
| 302 | class ExceptionInfoRequestHandler : public LegacyRequestHandler { |
| 303 | public: |
| 304 | using LegacyRequestHandler::LegacyRequestHandler; |
| 305 | static llvm::StringLiteral GetCommand() { return "exceptionInfo" ; } |
| 306 | FeatureSet GetSupportedFeatures() const override { |
| 307 | return {protocol::eAdapterFeatureExceptionInfoRequest}; |
| 308 | } |
| 309 | void operator()(const llvm::json::Object &request) const override; |
| 310 | }; |
| 311 | |
| 312 | class InitializeRequestHandler |
| 313 | : public RequestHandler<protocol::InitializeRequestArguments, |
| 314 | llvm::Expected<protocol::InitializeResponse>> { |
| 315 | public: |
| 316 | using RequestHandler::RequestHandler; |
| 317 | static llvm::StringLiteral GetCommand() { return "initialize" ; } |
| 318 | llvm::Expected<protocol::InitializeResponse> |
| 319 | Run(const protocol::InitializeRequestArguments &args) const override; |
| 320 | }; |
| 321 | |
| 322 | class LaunchRequestHandler |
| 323 | : public RequestHandler<protocol::LaunchRequestArguments, |
| 324 | protocol::LaunchResponse> { |
| 325 | public: |
| 326 | using RequestHandler::RequestHandler; |
| 327 | static llvm::StringLiteral GetCommand() { return "launch" ; } |
| 328 | llvm::Error |
| 329 | Run(const protocol::LaunchRequestArguments &arguments) const override; |
| 330 | void PostRun() const override; |
| 331 | }; |
| 332 | |
| 333 | class RestartRequestHandler : public LegacyRequestHandler { |
| 334 | public: |
| 335 | using LegacyRequestHandler::LegacyRequestHandler; |
| 336 | static llvm::StringLiteral GetCommand() { return "restart" ; } |
| 337 | void operator()(const llvm::json::Object &request) const override; |
| 338 | }; |
| 339 | |
| 340 | class NextRequestHandler |
| 341 | : public RequestHandler<protocol::NextArguments, protocol::NextResponse> { |
| 342 | public: |
| 343 | using RequestHandler::RequestHandler; |
| 344 | static llvm::StringLiteral GetCommand() { return "next" ; } |
| 345 | llvm::Error Run(const protocol::NextArguments &args) const override; |
| 346 | }; |
| 347 | |
| 348 | class StepInRequestHandler : public RequestHandler<protocol::StepInArguments, |
| 349 | protocol::StepInResponse> { |
| 350 | public: |
| 351 | using RequestHandler::RequestHandler; |
| 352 | static llvm::StringLiteral GetCommand() { return "stepIn" ; } |
| 353 | llvm::Error Run(const protocol::StepInArguments &args) const override; |
| 354 | }; |
| 355 | |
| 356 | class StepInTargetsRequestHandler : public LegacyRequestHandler { |
| 357 | public: |
| 358 | using LegacyRequestHandler::LegacyRequestHandler; |
| 359 | static llvm::StringLiteral GetCommand() { return "stepInTargets" ; } |
| 360 | FeatureSet GetSupportedFeatures() const override { |
| 361 | return {protocol::eAdapterFeatureStepInTargetsRequest}; |
| 362 | } |
| 363 | void operator()(const llvm::json::Object &request) const override; |
| 364 | }; |
| 365 | |
| 366 | class StepOutRequestHandler : public RequestHandler<protocol::StepOutArguments, |
| 367 | protocol::StepOutResponse> { |
| 368 | public: |
| 369 | using RequestHandler::RequestHandler; |
| 370 | static llvm::StringLiteral GetCommand() { return "stepOut" ; } |
| 371 | llvm::Error Run(const protocol::StepOutArguments &args) const override; |
| 372 | }; |
| 373 | |
| 374 | class SetBreakpointsRequestHandler |
| 375 | : public RequestHandler< |
| 376 | protocol::SetBreakpointsArguments, |
| 377 | llvm::Expected<protocol::SetBreakpointsResponseBody>> { |
| 378 | public: |
| 379 | using RequestHandler::RequestHandler; |
| 380 | static llvm::StringLiteral GetCommand() { return "setBreakpoints" ; } |
| 381 | FeatureSet GetSupportedFeatures() const override { |
| 382 | return {protocol::eAdapterFeatureConditionalBreakpoints, |
| 383 | protocol::eAdapterFeatureHitConditionalBreakpoints}; |
| 384 | } |
| 385 | llvm::Expected<protocol::SetBreakpointsResponseBody> |
| 386 | Run(const protocol::SetBreakpointsArguments &args) const override; |
| 387 | }; |
| 388 | |
| 389 | class SetExceptionBreakpointsRequestHandler : public LegacyRequestHandler { |
| 390 | public: |
| 391 | using LegacyRequestHandler::LegacyRequestHandler; |
| 392 | static llvm::StringLiteral GetCommand() { return "setExceptionBreakpoints" ; } |
| 393 | FeatureSet GetSupportedFeatures() const override { |
| 394 | return {protocol::eAdapterFeatureExceptionOptions}; |
| 395 | } |
| 396 | void operator()(const llvm::json::Object &request) const override; |
| 397 | }; |
| 398 | |
| 399 | class SetFunctionBreakpointsRequestHandler |
| 400 | : public RequestHandler< |
| 401 | protocol::SetFunctionBreakpointsArguments, |
| 402 | llvm::Expected<protocol::SetFunctionBreakpointsResponseBody>> { |
| 403 | public: |
| 404 | using RequestHandler::RequestHandler; |
| 405 | static llvm::StringLiteral GetCommand() { return "setFunctionBreakpoints" ; } |
| 406 | FeatureSet GetSupportedFeatures() const override { |
| 407 | return {protocol::eAdapterFeatureFunctionBreakpoints}; |
| 408 | } |
| 409 | llvm::Expected<protocol::SetFunctionBreakpointsResponseBody> |
| 410 | Run(const protocol::SetFunctionBreakpointsArguments &args) const override; |
| 411 | }; |
| 412 | |
| 413 | class DataBreakpointInfoRequestHandler |
| 414 | : public RequestHandler< |
| 415 | protocol::DataBreakpointInfoArguments, |
| 416 | llvm::Expected<protocol::DataBreakpointInfoResponseBody>> { |
| 417 | public: |
| 418 | using RequestHandler::RequestHandler; |
| 419 | static llvm::StringLiteral GetCommand() { return "dataBreakpointInfo" ; } |
| 420 | llvm::Expected<protocol::DataBreakpointInfoResponseBody> |
| 421 | Run(const protocol::DataBreakpointInfoArguments &args) const override; |
| 422 | }; |
| 423 | |
| 424 | class SetDataBreakpointsRequestHandler |
| 425 | : public RequestHandler< |
| 426 | protocol::SetDataBreakpointsArguments, |
| 427 | llvm::Expected<protocol::SetDataBreakpointsResponseBody>> { |
| 428 | public: |
| 429 | using RequestHandler::RequestHandler; |
| 430 | static llvm::StringLiteral GetCommand() { return "setDataBreakpoints" ; } |
| 431 | FeatureSet GetSupportedFeatures() const override { |
| 432 | return {protocol::eAdapterFeatureDataBreakpoints}; |
| 433 | } |
| 434 | llvm::Expected<protocol::SetDataBreakpointsResponseBody> |
| 435 | Run(const protocol::SetDataBreakpointsArguments &args) const override; |
| 436 | }; |
| 437 | |
| 438 | class SetInstructionBreakpointsRequestHandler |
| 439 | : public RequestHandler< |
| 440 | protocol::SetInstructionBreakpointsArguments, |
| 441 | llvm::Expected<protocol::SetInstructionBreakpointsResponseBody>> { |
| 442 | public: |
| 443 | using RequestHandler::RequestHandler; |
| 444 | static llvm::StringLiteral GetCommand() { |
| 445 | return "setInstructionBreakpoints" ; |
| 446 | } |
| 447 | FeatureSet GetSupportedFeatures() const override { |
| 448 | return {protocol::eAdapterFeatureInstructionBreakpoints}; |
| 449 | } |
| 450 | llvm::Expected<protocol::SetInstructionBreakpointsResponseBody> |
| 451 | Run(const protocol::SetInstructionBreakpointsArguments &args) const override; |
| 452 | }; |
| 453 | |
| 454 | class CompileUnitsRequestHandler : public LegacyRequestHandler { |
| 455 | public: |
| 456 | using LegacyRequestHandler::LegacyRequestHandler; |
| 457 | static llvm::StringLiteral GetCommand() { return "compileUnits" ; } |
| 458 | void operator()(const llvm::json::Object &request) const override; |
| 459 | }; |
| 460 | |
| 461 | class ModulesRequestHandler : public LegacyRequestHandler { |
| 462 | public: |
| 463 | using LegacyRequestHandler::LegacyRequestHandler; |
| 464 | static llvm::StringLiteral GetCommand() { return "modules" ; } |
| 465 | FeatureSet GetSupportedFeatures() const override { |
| 466 | return {protocol::eAdapterFeatureModulesRequest}; |
| 467 | } |
| 468 | void operator()(const llvm::json::Object &request) const override; |
| 469 | }; |
| 470 | |
| 471 | class PauseRequestHandler : public LegacyRequestHandler { |
| 472 | public: |
| 473 | using LegacyRequestHandler::LegacyRequestHandler; |
| 474 | static llvm::StringLiteral GetCommand() { return "pause" ; } |
| 475 | void operator()(const llvm::json::Object &request) const override; |
| 476 | }; |
| 477 | |
| 478 | class ScopesRequestHandler final |
| 479 | : public RequestHandler<protocol::ScopesArguments, |
| 480 | llvm::Expected<protocol::ScopesResponseBody>> { |
| 481 | public: |
| 482 | using RequestHandler::RequestHandler; |
| 483 | static llvm::StringLiteral GetCommand() { return "scopes" ; } |
| 484 | |
| 485 | llvm::Expected<protocol::ScopesResponseBody> |
| 486 | Run(const protocol::ScopesArguments &args) const override; |
| 487 | }; |
| 488 | |
| 489 | class SetVariableRequestHandler final |
| 490 | : public RequestHandler<protocol::SetVariableArguments, |
| 491 | llvm::Expected<protocol::SetVariableResponseBody>> { |
| 492 | public: |
| 493 | using RequestHandler::RequestHandler; |
| 494 | static llvm::StringLiteral GetCommand() { return "setVariable" ; } |
| 495 | FeatureSet GetSupportedFeatures() const override { |
| 496 | return {protocol::eAdapterFeatureSetVariable}; |
| 497 | } |
| 498 | llvm::Expected<protocol::SetVariableResponseBody> |
| 499 | Run(const protocol::SetVariableArguments &args) const override; |
| 500 | }; |
| 501 | |
| 502 | class SourceRequestHandler final |
| 503 | : public RequestHandler<protocol::SourceArguments, |
| 504 | llvm::Expected<protocol::SourceResponseBody>> { |
| 505 | public: |
| 506 | using RequestHandler::RequestHandler; |
| 507 | static llvm::StringLiteral GetCommand() { return "source" ; } |
| 508 | llvm::Expected<protocol::SourceResponseBody> |
| 509 | Run(const protocol::SourceArguments &args) const override; |
| 510 | }; |
| 511 | |
| 512 | class StackTraceRequestHandler : public LegacyRequestHandler { |
| 513 | public: |
| 514 | using LegacyRequestHandler::LegacyRequestHandler; |
| 515 | static llvm::StringLiteral GetCommand() { return "stackTrace" ; } |
| 516 | void operator()(const llvm::json::Object &request) const override; |
| 517 | FeatureSet GetSupportedFeatures() const override { |
| 518 | return {protocol::eAdapterFeatureDelayedStackTraceLoading}; |
| 519 | } |
| 520 | }; |
| 521 | |
| 522 | class ThreadsRequestHandler |
| 523 | : public RequestHandler<protocol::ThreadsArguments, |
| 524 | llvm::Expected<protocol::ThreadsResponseBody>> { |
| 525 | public: |
| 526 | using RequestHandler::RequestHandler; |
| 527 | static llvm::StringLiteral GetCommand() { return "threads" ; } |
| 528 | llvm::Expected<protocol::ThreadsResponseBody> |
| 529 | Run(const protocol::ThreadsArguments &) const override; |
| 530 | }; |
| 531 | |
| 532 | class VariablesRequestHandler : public LegacyRequestHandler { |
| 533 | public: |
| 534 | using LegacyRequestHandler::LegacyRequestHandler; |
| 535 | static llvm::StringLiteral GetCommand() { return "variables" ; } |
| 536 | void operator()(const llvm::json::Object &request) const override; |
| 537 | }; |
| 538 | |
| 539 | class LocationsRequestHandler : public LegacyRequestHandler { |
| 540 | public: |
| 541 | using LegacyRequestHandler::LegacyRequestHandler; |
| 542 | static llvm::StringLiteral GetCommand() { return "locations" ; } |
| 543 | void operator()(const llvm::json::Object &request) const override; |
| 544 | }; |
| 545 | |
| 546 | class DisassembleRequestHandler final |
| 547 | : public RequestHandler<protocol::DisassembleArguments, |
| 548 | llvm::Expected<protocol::DisassembleResponseBody>> { |
| 549 | public: |
| 550 | using RequestHandler::RequestHandler; |
| 551 | static llvm::StringLiteral GetCommand() { return "disassemble" ; } |
| 552 | FeatureSet GetSupportedFeatures() const override { |
| 553 | return {protocol::eAdapterFeatureDisassembleRequest}; |
| 554 | } |
| 555 | llvm::Expected<protocol::DisassembleResponseBody> |
| 556 | Run(const protocol::DisassembleArguments &args) const override; |
| 557 | }; |
| 558 | |
| 559 | class ReadMemoryRequestHandler : public LegacyRequestHandler { |
| 560 | public: |
| 561 | using LegacyRequestHandler::LegacyRequestHandler; |
| 562 | static llvm::StringLiteral GetCommand() { return "readMemory" ; } |
| 563 | FeatureSet GetSupportedFeatures() const override { |
| 564 | return {protocol::eAdapterFeatureReadMemoryRequest}; |
| 565 | } |
| 566 | void operator()(const llvm::json::Object &request) const override; |
| 567 | }; |
| 568 | |
| 569 | class CancelRequestHandler : public RequestHandler<protocol::CancelArguments, |
| 570 | protocol::CancelResponse> { |
| 571 | public: |
| 572 | using RequestHandler::RequestHandler; |
| 573 | static llvm::StringLiteral GetCommand() { return "cancel" ; } |
| 574 | FeatureSet GetSupportedFeatures() const override { |
| 575 | return {protocol::eAdapterFeatureCancelRequest}; |
| 576 | } |
| 577 | llvm::Error Run(const protocol::CancelArguments &args) const override; |
| 578 | }; |
| 579 | |
| 580 | /// A request used in testing to get the details on all breakpoints that are |
| 581 | /// currently set in the target. This helps us to test "setBreakpoints" and |
| 582 | /// "setFunctionBreakpoints" requests to verify we have the correct set of |
| 583 | /// breakpoints currently set in LLDB. |
| 584 | class TestGetTargetBreakpointsRequestHandler : public LegacyRequestHandler { |
| 585 | public: |
| 586 | using LegacyRequestHandler::LegacyRequestHandler; |
| 587 | static llvm::StringLiteral GetCommand() { |
| 588 | return "_testGetTargetBreakpoints" ; |
| 589 | } |
| 590 | void operator()(const llvm::json::Object &request) const override; |
| 591 | }; |
| 592 | |
| 593 | } // namespace lldb_dap |
| 594 | |
| 595 | #endif |
| 596 | |