Skip to content

Commit 342d11d

Browse files
[lldb][Progress] Separate title and details (llvm#77547) (#7978)
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. Some changes were made to Swift progress reports to match the upstream changes to `Progress`. (cherry picked from commit f1ef910)
1 parent 1b1a7d8 commit 342d11d

File tree

11 files changed

+51
-42
lines changed

11 files changed

+51
-42
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
@@ -2888,9 +2888,8 @@ void ObjectFileELF::ParseSymtab(Symtab &lldb_symtab) {
28882888
if (!module_sp)
28892889
return;
28902890

2891-
Progress progress(
2892-
llvm::formatv("Parsing symbol table for {0}",
2893-
m_file.GetFilename().AsCString("<Unknown>")));
2891+
Progress progress("Parsing symbol table",
2892+
m_file.GetFilename().AsCString("<Unknown>"));
28942893
ElapsedTime elapsed(module_sp->GetSymtabParseTime());
28952894

28962895
// 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
@@ -2238,7 +2238,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
22382238
const char *file_name = file.GetFilename().AsCString("<Unknown>");
22392239
LLDB_SCOPED_TIMERF("ObjectFileMachO::ParseSymtab () module = %s", file_name);
22402240
LLDB_LOG(log, "Parsing symbol table for {0}", file_name);
2241-
Progress progress(llvm::formatv("Parsing symbol table for {0}", file_name));
2241+
Progress progress("Parsing symbol table", file_name);
22422242

22432243
llvm::MachO::symtab_command symtab_load_command = {0, 0, 0, 0, 0, 0};
22442244
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
@@ -509,8 +509,6 @@ void SymbolFileDWARF::InitializeObject() {
509509

510510
if (apple_names.GetByteSize() > 0 || apple_namespaces.GetByteSize() > 0 ||
511511
apple_types.GetByteSize() > 0 || apple_objc.GetByteSize() > 0) {
512-
Progress progress(llvm::formatv("Loading Apple DWARF index for {0}",
513-
module_desc.GetData()));
514512
m_index = AppleDWARFIndex::Create(
515513
*GetObjectFile()->GetModule(), apple_names, apple_namespaces,
516514
apple_types, apple_objc, m_context.getOrLoadStrData());
@@ -522,8 +520,7 @@ void SymbolFileDWARF::InitializeObject() {
522520
DWARFDataExtractor debug_names;
523521
LoadSectionData(eSectionTypeDWARFDebugNames, debug_names);
524522
if (debug_names.GetByteSize() > 0) {
525-
Progress progress(
526-
llvm::formatv("Loading DWARF5 index for {0}", module_desc.GetData()));
523+
Progress progress("Loading DWARF5 index", module_desc.GetData());
527524
llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>> index_or =
528525
DebugNamesDWARFIndex::Create(*GetObjectFile()->GetModule(),
529526
debug_names,

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,10 +4208,9 @@ void SwiftASTContext::ValidateSectionModules(
42084208

42094209
Status error;
42104210

4211-
Progress progress(
4212-
llvm::formatv("Loading Swift module '{0}' dependencies",
4213-
module.GetFileSpec().GetFilename().AsCString()),
4214-
module_names.size());
4211+
Progress progress("Loading Swift module '{0}' dependencies",
4212+
module.GetFileSpec().GetFilename().AsCString(),
4213+
module_names.size());
42154214
size_t completion = 0;
42164215

42174216
for (const std::string &module_name : module_names) {
@@ -8788,10 +8787,9 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
87888787
if (cu_imports.size() == 0)
87898788
return true;
87908789

8791-
Progress progress(
8792-
llvm::formatv("Getting Swift compile unit imports for '{0}'",
8793-
compile_unit->GetPrimaryFile().GetFilename()),
8794-
cu_imports.size());
8790+
Progress progress("Getting Swift compile unit imports",
8791+
compile_unit->GetPrimaryFile().GetFilename().GetCString(),
8792+
cu_imports.size());
87958793
size_t completion = 0;
87968794
for (const SourceModule &module : cu_imports) {
87978795
progress.Increment(++completion, module.path.back().GetStringRef().str());

lldb/source/Symbol/LocateSymbolFile.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,8 @@ Symbols::LocateExecutableSymbolFile(const ModuleSpec &module_spec,
267267
FileSystem::Instance().Exists(symbol_file_spec))
268268
return symbol_file_spec;
269269

270-
Progress progress(llvm::formatv(
271-
"Locating external symbol file for {0}",
272-
module_spec.GetFileSpec().GetFilename().AsCString("<Unknown>")));
270+
Progress progress(
271+
"Locating external symbol file", module_spec.GetFileSpec().GetFilename().AsCString("<Unknown>"));
273272

274273
FileSpecList debug_file_search_paths = default_search_paths;
275274

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)

lldb/test/API/functionalities/progress_reporting/swift_progress_reporting/TestSwiftProgressReporting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_swift_progress_report(self):
3838
"Loading Swift module",
3939
"Importing modules used in expression",
4040
"Setting up Swift reflection",
41-
"Getting Swift compile unit imports for",
41+
"Getting Swift compile unit imports",
4242
"Importing Swift modules",
4343
"Importing Swift standard library",
4444
]

0 commit comments

Comments
 (0)