Skip to content

Commit 2e38b48

Browse files
chelcassanovaadrian-prantl
authored andcommitted
[lldb][progress] Correctly check total for deterministic progress (llvm#79912)
The `total` parameter for the constructor for Progress was changed to a std::optional in llvm#77547. It was originally set to 1 to indicate non-determinisitic progress, but this commit changes this. First, `UINT64_MAX` will again be used for non-deterministic progress, and `Progress` now has a static variable set to this value so that we can use this instead of a magic number. The member variable `m_total` could be changed to a std::optional as well, but this means that the `ProgressEventData::GetTotal()` (which is used for the public API) would either need to return a std::optional value or it would return some specific integer to represent non-deterministic progress if `m_total` is std::nullopt. (cherry picked from commit 733b86d)
1 parent dce951c commit 2e38b48

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

lldb/include/lldb/Core/DebuggerEvents.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Core/ModuleSpec.h"
10+
#include "lldb/Core/Progress.h"
1011
#include "lldb/Utility/Event.h"
1112
#include "lldb/Utility/StructuredData.h"
1213

@@ -39,7 +40,7 @@ class ProgressEventData : public EventData {
3940
GetAsStructuredData(const Event *event_ptr);
4041

4142
uint64_t GetID() const { return m_id; }
42-
bool IsFinite() const { return m_total != UINT64_MAX; }
43+
bool IsFinite() const { return m_total != Progress::kNonDeterministicTotal; }
4344
uint64_t GetCompleted() const { return m_completed; }
4445
uint64_t GetTotal() const { return m_total; }
4546
std::string GetMessage() const {

lldb/include/lldb/Core/Progress.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class Progress {
9393
void Increment(uint64_t amount = 1,
9494
std::optional<std::string> updated_detail = {});
9595

96+
/// Used to indicate a non-deterministic progress report
97+
static constexpr uint64_t kNonDeterministicTotal = UINT64_MAX;
98+
9699
private:
97100
void ReportProgress();
98101
static std::atomic<uint64_t> g_id;

lldb/source/Core/DebuggerEvents.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lldb/Core/DebuggerEvents.h"
1010
#include "lldb/Core/Debugger.h"
1111
#include "lldb/Core/Module.h"
12+
#include "lldb/Core/Progress.h"
1213
#include "llvm/Support/WithColor.h"
1314

1415
using namespace lldb_private;
@@ -41,7 +42,7 @@ void ProgressEventData::Dump(Stream *s) const {
4142
s->PutCString(", type = update");
4243
// If m_total is UINT64_MAX, there is no progress to report, just "start"
4344
// and "end". If it isn't we will show the completed and total amounts.
44-
if (m_total != UINT64_MAX)
45+
if (m_total != Progress::kNonDeterministicTotal)
4546
s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
4647
}
4748

lldb/source/Core/Progress.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ Progress::Progress(std::string title, std::string details,
2222
std::optional<uint64_t> total,
2323
lldb_private::Debugger *debugger)
2424
: m_title(title), m_details(details), m_id(++g_id), m_completed(0),
25-
m_total(1) {
26-
assert(total == std::nullopt || total > 0);
25+
m_total(Progress::kNonDeterministicTotal) {
2726
if (total)
2827
m_total = *total;
2928

0 commit comments

Comments
 (0)