5555#include < thread>
5656#include < vector>
5757
58+ #include < iostream>
5859#if defined(_WIN32)
5960// We need to #define NOMINMAX in order to skip `min()` and `max()` macro
6061// definitions that conflict with other system headers.
@@ -412,6 +413,30 @@ void SendStdOutStdErr(DAP &dap, lldb::SBProcess &process) {
412413 dap.SendOutput (OutputType::Stderr, llvm::StringRef (buffer, count));
413414}
414415
416+ static std::string GetStringFromStructuredData (lldb::SBStructuredData &data,
417+ const char *key) {
418+ lldb::SBStructuredData keyValue = data.GetValueForKey (key);
419+ if (!keyValue)
420+ return std::string ();
421+
422+ size_t size = keyValue.GetStringValue (nullptr , 0 );
423+ std::cout << " Size for " << key << " " << size << std::endl;
424+ std::string stringValue;
425+ stringValue.resize (size);
426+ keyValue.GetStringValue (&stringValue[0 ], size + 1 );
427+ std::cout << " String value after: " << stringValue << std::endl;
428+ return stringValue;
429+ }
430+
431+ static uint64_t GetUintFromStructuredData (lldb::SBStructuredData &data,
432+ const char *key) {
433+ lldb::SBStructuredData keyValue = data.GetValueForKey (key);
434+
435+ if (!keyValue.IsValid ())
436+ return -1 ;
437+ return keyValue.GetUnsignedIntegerValue ();
438+ }
439+
415440void ProgressEventThreadFunction (DAP &dap) {
416441 lldb::SBListener listener (" lldb-dap.progress.listener" );
417442 dap.debugger .GetBroadcaster ().AddListener (
@@ -428,14 +453,27 @@ void ProgressEventThreadFunction(DAP &dap) {
428453 done = true ;
429454 }
430455 } else {
431- uint64_t progress_id = 0 ;
432- uint64_t completed = 0 ;
433- uint64_t total = 0 ;
434- bool is_debugger_specific = false ;
435- const char *message = lldb::SBDebugger::GetProgressFromEvent (
436- event, progress_id, completed, total, is_debugger_specific);
437- if (message)
438- dap.SendProgressEvent (progress_id, message, completed, total);
456+ lldb::SBStructuredData data =
457+ lldb::SBDebugger::GetProgressDataFromEvent (event);
458+
459+ uint64_t progress_id = GetUintFromStructuredData (data, " progress_id" );
460+ uint64_t completed = GetUintFromStructuredData (data, " completed" );
461+ uint64_t total = GetUintFromStructuredData (data, " total" );
462+ std::string message;
463+ // Include the title on the first event.
464+ if (completed == 0 ) {
465+ std::string title = GetStringFromStructuredData (data, " title" );
466+ message += title;
467+ message += " : " ;
468+ }
469+
470+ std::string details = GetStringFromStructuredData (data, " details" );
471+ message += details;
472+ // Verbose check, but we get -1 for the uint64 on failure to read
473+ // so we check everything before broadcasting an event.
474+ if (message.length () > 0 && progress_id > 0 && total >= 0 &&
475+ completed >= 0 )
476+ dap.SendProgressEvent (progress_id, message.c_str (), completed, total);
439477 }
440478 }
441479 }
0 commit comments