[Lldb-commits] [lldb] 733b86d - [lldb][progress] Correctly check total for deterministic progress (#79912)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jan 30 12:00:43 PST 2024
Author: Chelsea Cassanova
Date: 2024-01-30T12:00:38-08:00
New Revision: 733b86d3ff8087f1e267c23eb315bb16e3c6c953
URL: https://github.com/llvm/llvm-project/commit/733b86d3ff8087f1e267c23eb315bb16e3c6c953
DIFF: https://github.com/llvm/llvm-project/commit/733b86d3ff8087f1e267c23eb315bb16e3c6c953.diff
LOG: [lldb][progress] Correctly check total for deterministic progress (#79912)
The `total` parameter for the constructor for Progress was changed to a
std::optional in https://github.com/llvm/llvm-project/pull/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.
Added:
Modified:
lldb/include/lldb/Core/DebuggerEvents.h
lldb/include/lldb/Core/Progress.h
lldb/source/Core/DebuggerEvents.cpp
lldb/source/Core/Progress.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/DebuggerEvents.h b/lldb/include/lldb/Core/DebuggerEvents.h
index 4a27766e94e3a..74bb05e6e6bf8 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Core/Progress.h"
#include "lldb/Utility/Event.h"
#include "lldb/Utility/StructuredData.h"
@@ -39,7 +40,7 @@ class ProgressEventData : public EventData {
GetAsStructuredData(const Event *event_ptr);
uint64_t GetID() const { return m_id; }
- bool IsFinite() const { return m_total != UINT64_MAX; }
+ bool IsFinite() const { return m_total != Progress::kNonDeterministicTotal; }
uint64_t GetCompleted() const { return m_completed; }
uint64_t GetTotal() const { return m_total; }
std::string GetMessage() const {
diff --git a/lldb/include/lldb/Core/Progress.h b/lldb/include/lldb/Core/Progress.h
index 65d30ea25cd29..5d88291024605 100644
--- a/lldb/include/lldb/Core/Progress.h
+++ b/lldb/include/lldb/Core/Progress.h
@@ -93,6 +93,9 @@ class Progress {
void Increment(uint64_t amount = 1,
std::optional<std::string> updated_detail = {});
+ /// Used to indicate a non-deterministic progress report
+ static constexpr uint64_t kNonDeterministicTotal = UINT64_MAX;
+
private:
void ReportProgress();
static std::atomic<uint64_t> g_id;
diff --git a/lldb/source/Core/DebuggerEvents.cpp b/lldb/source/Core/DebuggerEvents.cpp
index dd77fff349a64..65aed0eba9c41 100644
--- a/lldb/source/Core/DebuggerEvents.cpp
+++ b/lldb/source/Core/DebuggerEvents.cpp
@@ -9,6 +9,7 @@
#include "lldb/Core/DebuggerEvents.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
+#include "lldb/Core/Progress.h"
#include "llvm/Support/WithColor.h"
using namespace lldb_private;
@@ -41,7 +42,7 @@ void ProgressEventData::Dump(Stream *s) const {
s->PutCString(", type = update");
// If m_total is UINT64_MAX, there is no progress to report, just "start"
// and "end". If it isn't we will show the completed and total amounts.
- if (m_total != UINT64_MAX)
+ if (m_total != Progress::kNonDeterministicTotal)
s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
}
diff --git a/lldb/source/Core/Progress.cpp b/lldb/source/Core/Progress.cpp
index 355d6952e53ca..732efbc342b45 100644
--- a/lldb/source/Core/Progress.cpp
+++ b/lldb/source/Core/Progress.cpp
@@ -22,8 +22,7 @@ Progress::Progress(std::string title, std::string details,
std::optional<uint64_t> total,
lldb_private::Debugger *debugger)
: m_title(title), m_details(details), m_id(++g_id), m_completed(0),
- m_total(1) {
- assert(total == std::nullopt || total > 0);
+ m_total(Progress::kNonDeterministicTotal) {
if (total)
m_total = *total;
More information about the lldb-commits
mailing list