Skip to content

Commit e150907

Browse files
committed
Migrate to structured data
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D68927453
1 parent 82ed76a commit e150907

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

lldb/include/lldb/Core/DebuggerEvents.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,12 @@ class ProgressEventData : public EventData {
4444
uint64_t GetCompleted() const { return m_completed; }
4545
uint64_t GetTotal() const { return m_total; }
4646
std::string GetMessage() const {
47-
// Only put the title in the message of the progress create event.
48-
if (m_completed == 0) {
49-
std::string message = m_title;
50-
if (!m_details.empty()) {
51-
message.append(": ");
52-
message.append(m_details);
53-
}
54-
return message;
55-
} else
56-
return !m_details.empty() ? m_details : std::string();
47+
std::string message = m_title;
48+
if (!m_details.empty()) {
49+
message.append(": ");
50+
message.append(m_details);
51+
}
52+
return message;
5753
}
5854
const std::string &GetTitle() const { return m_title; }
5955
const std::string &GetDetails() const { return m_details; }

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

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
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+
415440
void 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

Comments
 (0)