Skip to content

Commit feae281

Browse files
committed
Adopt InitializeRequestHandler
1 parent a8d212d commit feae281

File tree

6 files changed

+470
-433
lines changed

6 files changed

+470
-433
lines changed

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ add_lldb_tool(lldb-dap
4343
Handler/ConfigurationDoneRequestHandler.cpp
4444
Handler/ContinueRequestHandler.cpp
4545
Handler/DisconnectRequestHandler.cpp
46+
Handler/InitializeRequestHandler.cpp
4647
Handler/EvaluateRequestHandler.cpp
4748
Handler/ExceptionInfoRequestHandler.cpp
4849
Handler/RequestHandler.cpp

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,45 @@ void SendTerminatedEvent(DAP &dap) {
194194
});
195195
}
196196

197+
// Grab any STDOUT and STDERR from the process and send it up to VS Code
198+
// via an "output" event to the "stdout" and "stderr" categories.
199+
void SendStdOutStdErr(DAP &dap, lldb::SBProcess &process) {
200+
char buffer[OutputBufferSize];
201+
size_t count;
202+
while ((count = process.GetSTDOUT(buffer, sizeof(buffer))) > 0)
203+
dap.SendOutput(OutputType::Stdout, llvm::StringRef(buffer, count));
204+
while ((count = process.GetSTDERR(buffer, sizeof(buffer))) > 0)
205+
dap.SendOutput(OutputType::Stderr, llvm::StringRef(buffer, count));
206+
}
207+
208+
// Send a "continued" event to indicate the process is in the running state.
209+
void SendContinuedEvent(DAP &dap) {
210+
lldb::SBProcess process = dap.target.GetProcess();
211+
if (!process.IsValid()) {
212+
return;
213+
}
214+
215+
// If the focus thread is not set then we haven't reported any thread status
216+
// to the client, so nothing to report.
217+
if (!dap.configuration_done_sent || dap.focus_tid == LLDB_INVALID_THREAD_ID) {
218+
return;
219+
}
220+
221+
llvm::json::Object event(CreateEventObject("continued"));
222+
llvm::json::Object body;
223+
body.try_emplace("threadId", (int64_t)dap.focus_tid);
224+
body.try_emplace("allThreadsContinued", true);
225+
event.try_emplace("body", std::move(body));
226+
dap.SendJSON(llvm::json::Value(std::move(event)));
227+
}
228+
229+
// Send a "exited" event to indicate the process has exited.
230+
void SendProcessExitedEvent(DAP &dap, lldb::SBProcess &process) {
231+
llvm::json::Object event(CreateEventObject("exited"));
232+
llvm::json::Object body;
233+
body.try_emplace("exitCode", (int64_t)process.GetExitStatus());
234+
event.try_emplace("body", std::move(body));
235+
dap.SendJSON(llvm::json::Value(std::move(event)));
236+
}
237+
197238
} // namespace lldb_dap

lldb/tools/lldb-dap/EventHelper.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef LLDB_TOOLS_LLDB_DAP_EVENTHELPER_H
1010
#define LLDB_TOOLS_LLDB_DAP_EVENTHELPER_H
1111

12+
#include "DAPForward.h"
13+
1214
namespace lldb_dap {
1315
struct DAP;
1416

@@ -20,6 +22,12 @@ void SendThreadStoppedEvent(DAP &dap);
2022

2123
void SendTerminatedEvent(DAP &dap);
2224

25+
void SendStdOutStdErr(DAP &dap, lldb::SBProcess &process);
26+
27+
void SendContinuedEvent(DAP &dap);
28+
29+
void SendProcessExitedEvent(DAP &dap, lldb::SBProcess &process);
30+
2331
} // namespace lldb_dap
2432

2533
#endif

0 commit comments

Comments
 (0)