@@ -83,9 +83,8 @@ DAP::DAP(llvm::StringRef path, std::ofstream *log,
8383 configuration_done_sent(false ), waiting_for_run_in_terminal(false ),
8484 progress_event_reporter(
8585 [&](const ProgressEvent &event) { SendJSON (event.ToJSON ()); }),
86- reverse_request_seq (0 ), repl_mode(default_repl_mode),
87- onExited(ExitedEventHandler(*this )),
88- onProcess(ProcessEventHandler(*this )) {}
86+ reverse_request_seq (0 ), repl_mode(default_repl_mode), SendExited(*this ),
87+ SendProcess(*this ), SendOutput(*this ) {}
8988
9089DAP::~DAP () = default ;
9190
@@ -205,12 +204,12 @@ llvm::Error DAP::ConfigureIO(std::FILE *overrideOut, std::FILE *overrideErr) {
205204 in = lldb::SBFile (std::fopen (DEV_NULL, " r" ), /* transfer_ownership=*/ true );
206205
207206 if (auto Error = out.RedirectTo (overrideOut, [this ](llvm::StringRef output) {
208- SendOutput (OutputType ::Stdout, output );
207+ SendOutput (output, OutputCategory ::Stdout);
209208 }))
210209 return Error;
211210
212211 if (auto Error = err.RedirectTo (overrideErr, [this ](llvm::StringRef output) {
213- SendOutput (OutputType ::Stderr, output );
212+ SendOutput (output, OutputCategory ::Stderr);
214213 }))
215214 return Error;
216215
@@ -249,103 +248,6 @@ void DAP::Send(const protocol::Message &message) {
249248 transport.GetClientName ());
250249}
251250
252- // "OutputEvent": {
253- // "allOf": [ { "$ref": "#/definitions/Event" }, {
254- // "type": "object",
255- // "description": "Event message for 'output' event type. The event
256- // indicates that the target has produced some output.",
257- // "properties": {
258- // "event": {
259- // "type": "string",
260- // "enum": [ "output" ]
261- // },
262- // "body": {
263- // "type": "object",
264- // "properties": {
265- // "category": {
266- // "type": "string",
267- // "description": "The output category. If not specified,
268- // 'console' is assumed.",
269- // "_enum": [ "console", "stdout", "stderr", "telemetry" ]
270- // },
271- // "output": {
272- // "type": "string",
273- // "description": "The output to report."
274- // },
275- // "variablesReference": {
276- // "type": "number",
277- // "description": "If an attribute 'variablesReference' exists
278- // and its value is > 0, the output contains
279- // objects which can be retrieved by passing
280- // variablesReference to the VariablesRequest."
281- // },
282- // "source": {
283- // "$ref": "#/definitions/Source",
284- // "description": "An optional source location where the output
285- // was produced."
286- // },
287- // "line": {
288- // "type": "integer",
289- // "description": "An optional source location line where the
290- // output was produced."
291- // },
292- // "column": {
293- // "type": "integer",
294- // "description": "An optional source location column where the
295- // output was produced."
296- // },
297- // "data": {
298- // "type":["array","boolean","integer","null","number","object",
299- // "string"],
300- // "description": "Optional data to report. For the 'telemetry'
301- // category the data will be sent to telemetry, for
302- // the other categories the data is shown in JSON
303- // format."
304- // }
305- // },
306- // "required": ["output"]
307- // }
308- // },
309- // "required": [ "event", "body" ]
310- // }]
311- // }
312- void DAP::SendOutput (OutputType o, const llvm::StringRef output) {
313- if (output.empty ())
314- return ;
315-
316- const char *category = nullptr ;
317- switch (o) {
318- case OutputType::Console:
319- category = " console" ;
320- break ;
321- case OutputType::Stdout:
322- category = " stdout" ;
323- break ;
324- case OutputType::Stderr:
325- category = " stderr" ;
326- break ;
327- case OutputType::Telemetry:
328- category = " telemetry" ;
329- break ;
330- }
331-
332- // Send each line of output as an individual event, including the newline if
333- // present.
334- ::size_t idx = 0 ;
335- do {
336- ::size_t end = output.find (' \n ' , idx);
337- if (end == llvm::StringRef::npos)
338- end = output.size () - 1 ;
339- llvm::json::Object event (CreateEventObject (" output" ));
340- llvm::json::Object body;
341- body.try_emplace (" category" , category);
342- EmplaceSafeString (body, " output" , output.slice (idx, end + 1 ).str ());
343- event.try_emplace (" body" , std::move (body));
344- SendJSON (llvm::json::Value (std::move (event)));
345- idx = end + 1 ;
346- } while (idx < output.size ());
347- }
348-
349251// interface ProgressStartEvent extends Event {
350252// event: 'progressStart';
351253//
@@ -444,16 +346,17 @@ void DAP::SendProgressEvent(uint64_t progress_id, const char *message,
444346 progress_event_reporter.Push (progress_id, message, completed, total);
445347}
446348
447- void __attribute__ ((format(printf, 3 , 4 )))
448- DAP::SendFormattedOutput(OutputType o, const char *format, ...) {
449- char buffer[1024 ];
450- va_list args;
451- va_start (args, format);
452- int actual_length = vsnprintf (buffer, sizeof (buffer), format, args);
453- va_end (args);
454- SendOutput (
455- o, llvm::StringRef (buffer, std::min<int >(actual_length, sizeof (buffer))));
456- }
349+ // void __attribute__((format(printf, 3, 4)))
350+ // DAP::SendFormattedOutput(OutputType o, const char *format, ...) {
351+ // char buffer[1024];
352+ // va_list args;
353+ // va_start(args, format);
354+ // int actual_length = vsnprintf(buffer, sizeof(buffer), format, args);
355+ // va_end(args);
356+ // SendOutput(
357+ // o, llvm::StringRef(buffer, std::min<int>(actual_length,
358+ // sizeof(buffer))));
359+ // }
457360
458361ExceptionBreakpoint *DAP::GetExceptionBPFromStopReason (lldb::SBThread &thread) {
459362 const auto num = thread.GetStopReasonDataCount ();
@@ -567,7 +470,7 @@ bool DAP::RunLLDBCommands(llvm::StringRef prefix,
567470 bool required_command_failed = false ;
568471 std::string output =
569472 ::RunLLDBCommands (debugger, prefix, commands, required_command_failed);
570- SendOutput (OutputType::Console, output);
473+ SendOutput (output);
571474 return !required_command_failed;
572475}
573476
@@ -1044,8 +947,7 @@ void DAP::SetFrameFormat(llvm::StringRef format) {
1044947 lldb::SBError error;
1045948 frame_format = lldb::SBFormat (format.str ().c_str (), error);
1046949 if (error.Fail ()) {
1047- SendOutput (OutputType::Console,
1048- llvm::formatv (
950+ SendOutput (llvm::formatv (
1049951 " The provided frame format '{0}' couldn't be parsed: {1}\n " ,
1050952 format, error.GetCString ())
1051953 .str ());
@@ -1058,8 +960,7 @@ void DAP::SetThreadFormat(llvm::StringRef format) {
1058960 lldb::SBError error;
1059961 thread_format = lldb::SBFormat (format.str ().c_str (), error);
1060962 if (error.Fail ()) {
1061- SendOutput (OutputType::Console,
1062- llvm::formatv (
963+ SendOutput (llvm::formatv (
1063964 " The provided thread format '{0}' couldn't be parsed: {1}\n " ,
1064965 format, error.GetCString ())
1065966 .str ());
0 commit comments