Skip to content

Commit f1ef910

Browse files
[lldb][Progress] Separate title and details (llvm#77547)
Per this RFC: https://discourse.llvm.org/t/rfc-improve-lldb-progress-reporting/75717 on improving progress reports, this commit separates the title field and details field so that the title specifies the category that the progress report falls under. The details field is added as a part of the constructor for progress reports and by default is an empty string. In addition, changes the total amount of progress completed into a std::optional. Also updates the test to check for details being correctly reported from the event structured data dictionary.
1 parent 77610dd commit f1ef910

File tree

9 files changed

+45
-33
lines changed

9 files changed

+45
-33
lines changed

lldb/include/lldb/Core/DebuggerEvents.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class Stream;
2020

2121
class ProgressEventData : public EventData {
2222
public:
23-
ProgressEventData(uint64_t progress_id, std::string title, std::string update,
24-
uint64_t completed, uint64_t total, bool debugger_specific)
25-
: m_title(std::move(title)), m_details(std::move(update)),
23+
ProgressEventData(uint64_t progress_id, std::string title,
24+
std::string details, uint64_t completed, uint64_t total,
25+
bool debugger_specific)
26+
: m_title(std::move(title)), m_details(std::move(details)),
2627
m_id(progress_id), m_completed(completed), m_total(total),
2728
m_debugger_specific(debugger_specific) {}
2829

lldb/include/lldb/Core/Progress.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ class Progress {
6464
/// @param [in] title The title of this progress activity.
6565
///
6666
/// @param [in] total The total units of work to be done if specified, if
67-
/// set to UINT64_MAX then an indeterminate progress indicator should be
67+
/// set to std::nullopt then an indeterminate progress indicator should be
6868
/// displayed.
6969
///
7070
/// @param [in] debugger An optional debugger pointer to specify that this
7171
/// progress is to be reported only to specific debuggers.
72-
Progress(std::string title, uint64_t total = UINT64_MAX,
72+
Progress(std::string title, std::string details = {},
73+
std::optional<uint64_t> total = std::nullopt,
7374
lldb_private::Debugger *debugger = nullptr);
7475

7576
/// Destroy the progress object.
@@ -89,20 +90,23 @@ class Progress {
8990
/// @param [in] amount The amount to increment m_completed by.
9091
///
9192
/// @param [in] an optional message associated with this update.
92-
void Increment(uint64_t amount = 1, std::string update = {});
93+
void Increment(uint64_t amount = 1,
94+
std::optional<std::string> updated_detail = {});
9395

9496
private:
95-
void ReportProgress(std::string update = {});
97+
void ReportProgress();
9698
static std::atomic<uint64_t> g_id;
9799
/// The title of the progress activity.
98100
std::string m_title;
101+
std::string m_details;
99102
std::mutex m_mutex;
100103
/// A unique integer identifier for progress reporting.
101104
const uint64_t m_id;
102105
/// How much work ([0...m_total]) that has been completed.
103106
uint64_t m_completed;
104-
/// Total amount of work, UINT64_MAX for non deterministic progress.
105-
const uint64_t m_total;
107+
/// Total amount of work, use a std::nullopt in the constructor for non
108+
/// deterministic progress.
109+
uint64_t m_total;
106110
/// The optional debugger ID to report progress to. If this has no value then
107111
/// all debuggers will receive this event.
108112
std::optional<lldb::user_id_t> m_debugger_id;

lldb/source/Core/Progress.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@
1111
#include "lldb/Core/Debugger.h"
1212
#include "lldb/Utility/StreamString.h"
1313

14+
#include <optional>
15+
1416
using namespace lldb;
1517
using namespace lldb_private;
1618

1719
std::atomic<uint64_t> Progress::g_id(0);
1820

19-
Progress::Progress(std::string title, uint64_t total,
21+
Progress::Progress(std::string title, std::string details,
22+
std::optional<uint64_t> total,
2023
lldb_private::Debugger *debugger)
21-
: m_title(title), m_id(++g_id), m_completed(0), m_total(total) {
22-
assert(total > 0);
24+
: m_title(title), m_details(details), m_id(++g_id), m_completed(0),
25+
m_total(1) {
26+
assert(total == std::nullopt || total > 0);
27+
if (total)
28+
m_total = *total;
29+
2330
if (debugger)
2431
m_debugger_id = debugger->GetID();
2532
std::lock_guard<std::mutex> guard(m_mutex);
@@ -35,25 +42,28 @@ Progress::~Progress() {
3542
ReportProgress();
3643
}
3744

38-
void Progress::Increment(uint64_t amount, std::string update) {
45+
void Progress::Increment(uint64_t amount,
46+
std::optional<std::string> updated_detail) {
3947
if (amount > 0) {
4048
std::lock_guard<std::mutex> guard(m_mutex);
49+
if (updated_detail)
50+
m_details = std::move(updated_detail.value());
4151
// Watch out for unsigned overflow and make sure we don't increment too
4252
// much and exceed m_total.
43-
if (amount > (m_total - m_completed))
53+
if (m_total && (amount > (m_total - m_completed)))
4454
m_completed = m_total;
4555
else
4656
m_completed += amount;
47-
ReportProgress(update);
57+
ReportProgress();
4858
}
4959
}
5060

51-
void Progress::ReportProgress(std::string update) {
61+
void Progress::ReportProgress() {
5262
if (!m_complete) {
5363
// Make sure we only send one notification that indicates the progress is
54-
// complete.
64+
// complete
5565
m_complete = m_completed == m_total;
56-
Debugger::ReportProgress(m_id, m_title, std::move(update), m_completed,
57-
m_total, m_debugger_id);
66+
Debugger::ReportProgress(m_id, m_title, m_details, m_completed, m_total,
67+
m_debugger_id);
5868
}
5969
}

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,9 +2897,8 @@ void ObjectFileELF::ParseSymtab(Symtab &lldb_symtab) {
28972897
if (!module_sp)
28982898
return;
28992899

2900-
Progress progress(
2901-
llvm::formatv("Parsing symbol table for {0}",
2902-
m_file.GetFilename().AsCString("<Unknown>")));
2900+
Progress progress("Parsing symbol table",
2901+
m_file.GetFilename().AsCString("<Unknown>"));
29032902
ElapsedTime elapsed(module_sp->GetSymtabParseTime());
29042903

29052904
// We always want to use the main object file so we (hopefully) only have one

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
22252225
const char *file_name = file.GetFilename().AsCString("<Unknown>");
22262226
LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s", file_name);
22272227
LLDB_LOG(log, "Parsing symbol table for {0}", file_name);
2228-
Progress progress(llvm::formatv("Parsing symbol table for {0}", file_name));
2228+
Progress progress("Parsing symbol table", file_name);
22292229

22302230
llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
22312231
llvm::MachO::linkedit_data_command function_starts_load_command = {0, 0, 0, 0};

lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ void ManualDWARFIndex::Index() {
7575
// Include 2 passes per unit to index for extracting DIEs from the unit and
7676
// indexing the unit, and then 8 extra entries for finalizing each index set.
7777
const uint64_t total_progress = units_to_index.size() * 2 + 8;
78-
Progress progress(
79-
llvm::formatv("Manually indexing DWARF for {0}", module_desc.GetData()),
80-
total_progress);
78+
Progress progress("Manually indexing DWARF", module_desc.GetData(),
79+
total_progress);
8180

8281
std::vector<IndexSet> sets(units_to_index.size());
8382

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,6 @@ void SymbolFileDWARF::InitializeObject() {
519519

520520
if (apple_names.GetByteSize() > 0 || apple_namespaces.GetByteSize() > 0 ||
521521
apple_types.GetByteSize() > 0 || apple_objc.GetByteSize() > 0) {
522-
Progress progress(llvm::formatv("Loading Apple DWARF index for {0}",
523-
module_desc.GetData()));
524522
m_index = AppleDWARFIndex::Create(
525523
*GetObjectFile()->GetModule(), apple_names, apple_namespaces,
526524
apple_types, apple_objc, m_context.getOrLoadStrData());
@@ -532,8 +530,7 @@ void SymbolFileDWARF::InitializeObject() {
532530
DWARFDataExtractor debug_names;
533531
LoadSectionData(eSectionTypeDWARFDebugNames, debug_names);
534532
if (debug_names.GetByteSize() > 0) {
535-
Progress progress(
536-
llvm::formatv("Loading DWARF5 index for {0}", module_desc.GetData()));
533+
Progress progress("Loading DWARF5 index", module_desc.GetData());
537534
llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>> index_or =
538535
DebugNamesDWARFIndex::Create(*GetObjectFile()->GetModule(),
539536
debug_names,

lldb/source/Plugins/SymbolLocator/Default/SymbolLocatorDefault.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ std::optional<FileSpec> SymbolLocatorDefault::LocateExecutableSymbolFile(
9898
FileSystem::Instance().Exists(symbol_file_spec))
9999
return symbol_file_spec;
100100

101-
Progress progress(llvm::formatv(
102-
"Locating external symbol file for {0}",
103-
module_spec.GetFileSpec().GetFilename().AsCString("<Unknown>")));
101+
Progress progress(
102+
"Locating external symbol file",
103+
module_spec.GetFileSpec().GetFilename().AsCString("<Unknown>"));
104104

105105
FileSpecList debug_file_search_paths = default_search_paths;
106106

lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ def test_dwarf_symbol_loading_progress_report_structured_data(self):
3939
progress_data = lldb.SBDebugger.GetProgressDataFromEvent(event)
4040
message = progress_data.GetValueForKey("message").GetStringValue(100)
4141
self.assertGreater(len(message), 0)
42+
details = progress_data.GetValueForKey("details").GetStringValue(100)
43+
self.assertGreater(len(details), 0)

0 commit comments

Comments
 (0)