Skip to content

Commit 92322ae

Browse files
committed
Address review feedback
1 parent e6cbcc3 commit 92322ae

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ add_lldb_tool(lldb-dap
3636
SourceBreakpoint.cpp
3737
Watchpoint.cpp
3838

39-
Request/Request.cpp
40-
Request/AttachRequest.cpp
39+
Handler/RequestHandler.cpp
40+
Handler/AttachHandler.cpp
4141

4242
LINK_LIBS
4343
liblldb

lldb/tools/lldb-dap/DAP.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#include "DAPForward.h"
1313
#include "ExceptionBreakpoint.h"
1414
#include "FunctionBreakpoint.h"
15+
#include "Handler/RequestHandler.h"
1516
#include "IOStream.h"
1617
#include "InstructionBreakpoint.h"
1718
#include "OutputRedirector.h"
1819
#include "ProgressEvent.h"
19-
#include "Request/Request.h"
2020
#include "SourceBreakpoint.h"
2121
#include "lldb/API/SBBroadcaster.h"
2222
#include "lldb/API/SBCommandInterpreter.h"
@@ -186,7 +186,7 @@ struct DAP {
186186
lldb::pid_t restarting_process_id;
187187
bool configuration_done_sent;
188188
std::map<std::string, RequestCallback, std::less<>> request_handlers;
189-
llvm::StringMap<std::unique_ptr<Request>> new_request_handlers;
189+
llvm::StringMap<std::unique_ptr<RequestHandler>> new_request_handlers;
190190
bool waiting_for_run_in_terminal;
191191
ProgressEventReporter progress_event_reporter;
192192
// Keep track of the last stop thread index IDs as threads won't go away
@@ -334,8 +334,9 @@ struct DAP {
334334
void RegisterRequestCallback(std::string request, RequestCallback callback);
335335

336336
/// Registers a request handler.
337-
template <typename Request> void RegisterRequest() {
338-
new_request_handlers[Request::getName()] = std::make_unique<Request>(*this);
337+
template <typename Handler> void RegisterRequest() {
338+
new_request_handlers[Handler::getCommand()] =
339+
std::make_unique<Handler>(*this);
339340
}
340341

341342
/// Debuggee will continue from stopped state.

lldb/tools/lldb-dap/Request/AttachRequest.cpp renamed to lldb/tools/lldb-dap/Handler/AttachHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- AttachRequest.cpp -------------------------------------------------===//
1+
//===-- AttachHandler.cpp -------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -8,7 +8,7 @@
88

99
#include "DAP.h"
1010
#include "JSONUtils.h"
11-
#include "Request.h"
11+
#include "RequestHandler.h"
1212
#include "lldb/API/SBListener.h"
1313
#include "llvm/Support/FileSystem.h"
1414

@@ -50,7 +50,7 @@ static void PrintWelcomeMessage(DAP &dap) {
5050
// }]
5151
// }
5252

53-
void AttachRequest::operator()(const llvm::json::Object &request) {
53+
void AttachRequestHandler::operator()(const llvm::json::Object &request) {
5454
dap.is_attach = true;
5555
dap.last_launch_or_attach_request = request;
5656
llvm::json::Object response;

lldb/tools/lldb-dap/Request/Request.cpp renamed to lldb/tools/lldb-dap/Handler/RequestHandler.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
//===-- Request.cpp -------------------------------------------------------===//
1+
//===-- Handler.cpp -------------------------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "Request.h"
9+
#include "RequestHandler.h"
1010
#include "DAP.h"
1111
#include "JSONUtils.h"
1212
#include "lldb/API/SBFileSpec.h"
1313

1414
namespace lldb_dap {
1515

16-
void Request::SendProcessEvent(Request::LaunchMethod launch_method) {
16+
void RequestHandler::SendProcessEvent(
17+
RequestHandler::LaunchMethod launch_method) {
1718
lldb::SBFileSpec exe_fspec = dap.target.GetExecutable();
1819
char exe_path[PATH_MAX];
1920
exe_fspec.GetPath(exe_path, sizeof(exe_path));
@@ -42,7 +43,8 @@ void Request::SendProcessEvent(Request::LaunchMethod launch_method) {
4243

4344
// Both attach and launch take a either a sourcePath or sourceMap
4445
// argument (or neither), from which we need to set the target.source-map.
45-
void Request::SetSourceMapFromArguments(const llvm::json::Object &arguments) {
46+
void RequestHandler::SetSourceMapFromArguments(
47+
const llvm::json::Object &arguments) {
4648
const char *sourceMapHelp =
4749
"source must be be an array of two-element arrays, "
4850
"each containing a source and replacement path string.\n";

lldb/tools/lldb-dap/Request/Request.h renamed to lldb/tools/lldb-dap/Handler/RequestHandler.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,38 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
10-
#define LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
9+
#ifndef LLDB_TOOLS_LLDB_DAP_HANDLER_HANDLER_H
10+
#define LLDB_TOOLS_LLDB_DAP_HANDLER_HANDLER_H
1111

1212
#include "llvm/ADT/StringRef.h"
1313
#include "llvm/Support/JSON.h"
1414

1515
namespace lldb_dap {
1616
struct DAP;
1717

18-
class Request {
18+
class RequestHandler {
1919
public:
20-
Request(DAP &dap) : dap(dap) {}
21-
virtual ~Request() = default;
20+
RequestHandler(DAP &dap) : dap(dap) {}
21+
virtual ~RequestHandler() = default;
2222

2323
virtual void operator()(const llvm::json::Object &request) = 0;
2424

25-
static llvm::StringLiteral getName() { return "invalid"; };
26-
25+
/// Helpers used by multiple request handlers.
26+
/// FIXME: Move these into the DAP class.
27+
/// @{
2728
enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };
28-
2929
void SendProcessEvent(LaunchMethod launch_method);
3030
void SetSourceMapFromArguments(const llvm::json::Object &arguments);
31+
/// @}
3132

3233
protected:
3334
DAP &dap;
3435
};
3536

36-
class AttachRequest : public Request {
37+
class AttachRequestHandler : public RequestHandler {
3738
public:
38-
using Request::Request;
39-
static llvm::StringLiteral getName() { return "attach"; }
39+
using RequestHandler::RequestHandler;
40+
static llvm::StringLiteral getCommand() { return "attach"; }
4041
void operator()(const llvm::json::Object &request) override;
4142
};
4243

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#include "DAP.h"
1010
#include "FifoFiles.h"
11+
#include "Handler/RequestHandler.h"
1112
#include "JSONUtils.h"
1213
#include "LLDBUtils.h"
13-
#include "Request/Request.h"
1414
#include "RunInTerminal.h"
1515
#include "Watchpoint.h"
1616
#include "lldb/API/SBDeclaration.h"
@@ -4813,7 +4813,7 @@ void request_setInstructionBreakpoints(DAP &dap,
48134813
}
48144814

48154815
void RegisterRequestCallbacks(DAP &dap) {
4816-
dap.RegisterRequest<AttachRequest>();
4816+
dap.RegisterRequest<AttachRequestHandler>();
48174817

48184818
dap.RegisterRequestCallback("breakpointLocations",
48194819
request_breakpointLocations);

0 commit comments

Comments
 (0)