Skip to content

Commit 96f0ebb

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

File tree

2 files changed

+73
-20
lines changed

2 files changed

+73
-20
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/Handler/InitializeRequestHandler.cpp

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,32 @@ using namespace lldb;
1818

1919
namespace lldb_dap {
2020

21-
static void ProgressEventThreadFunction(DAP &dap) {
22-
llvm::set_thread_name(dap.name + ".progress_handler");
21+
static std::string GetStringFromStructuredData(lldb::SBStructuredData &data,
22+
const char *key) {
23+
lldb::SBStructuredData keyValue = data.GetValueForKey(key);
24+
if (!keyValue)
25+
return std::string();
26+
27+
const size_t length = keyValue.GetStringValue(nullptr, 0);
28+
29+
if (length == 0)
30+
return std::string();
31+
32+
std::string str(length + 1, 0);
33+
keyValue.GetStringValue(&str[0], length + 1);
34+
return str;
35+
}
36+
37+
static uint64_t GetUintFromStructuredData(lldb::SBStructuredData &data,
38+
const char *key) {
39+
lldb::SBStructuredData keyValue = data.GetValueForKey(key);
40+
41+
if (!keyValue.IsValid())
42+
return 0;
43+
return keyValue.GetUnsignedIntegerValue();
44+
}
45+
46+
void ProgressEventThreadFunction(DAP &dap) {
2347
lldb::SBListener listener("lldb-dap.progress.listener");
2448
dap.debugger.GetBroadcaster().AddListener(
2549
listener, lldb::SBDebugger::eBroadcastBitProgress |
@@ -35,14 +59,47 @@ static void ProgressEventThreadFunction(DAP &dap) {
3559
done = true;
3660
}
3761
} else {
38-
uint64_t progress_id = 0;
39-
uint64_t completed = 0;
40-
uint64_t total = 0;
41-
bool is_debugger_specific = false;
42-
const char *message = lldb::SBDebugger::GetProgressFromEvent(
43-
event, progress_id, completed, total, is_debugger_specific);
44-
if (message)
45-
dap.SendProgressEvent(progress_id, message, completed, total);
62+
lldb::SBStructuredData data =
63+
lldb::SBDebugger::GetProgressDataFromEvent(event);
64+
65+
const uint64_t progress_id =
66+
GetUintFromStructuredData(data, "progress_id");
67+
const uint64_t completed = GetUintFromStructuredData(data, "completed");
68+
const uint64_t total = GetUintFromStructuredData(data, "total");
69+
const std::string details =
70+
GetStringFromStructuredData(data, "details");
71+
72+
if (completed == 0) {
73+
if (total == 1) {
74+
// This progress is non deterministic and won't get updated until it
75+
// is completed. Send the "message" which will be the combined title
76+
// and detail. The only other progress event for thus
77+
// non-deterministic progress will be the completed event So there
78+
// will be no need to update the detail.
79+
const std::string message =
80+
GetStringFromStructuredData(data, "message");
81+
dap.SendProgressEvent(progress_id, message.c_str(), completed,
82+
total);
83+
} else {
84+
// This progress is deterministic and will receive updates,
85+
// on the progress creation event VSCode will save the message in
86+
// the create packet and use that as the title, so we send just the
87+
// title in the progressCreate packet followed immediately by a
88+
// detail packet, if there is any detail.
89+
const std::string title =
90+
GetStringFromStructuredData(data, "title");
91+
dap.SendProgressEvent(progress_id, title.c_str(), completed, total);
92+
if (!details.empty())
93+
dap.SendProgressEvent(progress_id, details.c_str(), completed,
94+
total);
95+
}
96+
} else {
97+
// This progress event is either the end of the progress dialog, or an
98+
// update with possible detail. The "detail" string we send to VS Code
99+
// will be appended to the progress dialog's initial text from when it
100+
// was created.
101+
dap.SendProgressEvent(progress_id, details.c_str(), completed, total);
102+
}
46103
}
47104
}
48105
}

0 commit comments

Comments
 (0)