Skip to content

Commit 5dc6392

Browse files
committed
[lldb] Emit progress events in SymbolFileDWARFDebugMap
Emit progress events from SymbolFileDWARFDebugMap. Because we know the number of OSOs, we can show determinate progress. This is based on a patch from Adrian, and what prompted me to look into improving how LLDB shows progress events. Before the statusline, all these progress events would get shadowed.
1 parent cc30fba commit 5dc6392

File tree

2 files changed

+99
-76
lines changed

2 files changed

+99
-76
lines changed

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

Lines changed: 97 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "lldb/Core/Module.h"
1515
#include "lldb/Core/ModuleList.h"
1616
#include "lldb/Core/PluginManager.h"
17+
#include "lldb/Core/Progress.h"
1718
#include "lldb/Core/Section.h"
1819
#include "lldb/Host/FileSystem.h"
1920
#include "lldb/Utility/RangeMap.h"
@@ -31,6 +32,7 @@
3132
#include "lldb/Symbol/TypeMap.h"
3233
#include "lldb/Symbol/VariableList.h"
3334
#include "llvm/ADT/STLExtras.h"
35+
#include "llvm/ADT/StringRef.h"
3436
#include "llvm/Support/ScopedPrinter.h"
3537

3638
#include "lldb/Target/StackFrame.h"
@@ -716,6 +718,27 @@ bool SymbolFileDWARFDebugMap::ParseDebugMacros(CompileUnit &comp_unit) {
716718
return false;
717719
}
718720

721+
void SymbolFileDWARFDebugMap::ForEachSymbolFile(
722+
std::string description,
723+
std::function<IterationAction(SymbolFileDWARF *)> closure) {
724+
const size_t num_oso_idxs = m_compile_unit_infos.size();
725+
const size_t update_rate = std::max<size_t>(1, num_oso_idxs / 100);
726+
Progress progress(std::move(description), "", num_oso_idxs);
727+
for (uint32_t oso_idx = 0; oso_idx < num_oso_idxs; ++oso_idx) {
728+
if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
729+
if (oso_idx % update_rate == 0)
730+
progress.Increment(oso_idx, oso_dwarf->GetObjectFile()
731+
? oso_dwarf->GetObjectFile()
732+
->GetFileSpec()
733+
.GetFilename()
734+
.GetString()
735+
: std::string());
736+
if (closure(oso_dwarf) == IterationAction::Stop)
737+
return;
738+
}
739+
}
740+
}
741+
719742
bool SymbolFileDWARFDebugMap::ForEachExternalModule(
720743
CompileUnit &comp_unit,
721744
llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
@@ -804,7 +827,7 @@ SymbolFileDWARFDebugMap::GetDynamicArrayInfoForUID(
804827
bool SymbolFileDWARFDebugMap::CompleteType(CompilerType &compiler_type) {
805828
bool success = false;
806829
if (compiler_type) {
807-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
830+
ForEachSymbolFile("Completing type", [&](SymbolFileDWARF *oso_dwarf) {
808831
if (oso_dwarf->HasForwardDeclForCompilerType(compiler_type)) {
809832
oso_dwarf->CompleteType(compiler_type);
810833
success = true;
@@ -924,59 +947,63 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
924947
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
925948
uint32_t total_matches = 0;
926949

927-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
928-
const uint32_t old_size = variables.GetSize();
929-
oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
930-
variables);
931-
const uint32_t oso_matches = variables.GetSize() - old_size;
932-
if (oso_matches > 0) {
933-
total_matches += oso_matches;
934-
935-
// Are we getting all matches?
936-
if (max_matches == UINT32_MAX)
937-
return IterationAction::Continue; // Yep, continue getting everything
938-
939-
// If we have found enough matches, lets get out
940-
if (max_matches >= total_matches)
941-
return IterationAction::Stop;
942-
943-
// Update the max matches for any subsequent calls to find globals in any
944-
// other object files with DWARF
945-
max_matches -= oso_matches;
946-
}
950+
ForEachSymbolFile(
951+
"Looking up global variables", [&](SymbolFileDWARF *oso_dwarf) {
952+
const uint32_t old_size = variables.GetSize();
953+
oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
954+
variables);
955+
const uint32_t oso_matches = variables.GetSize() - old_size;
956+
if (oso_matches > 0) {
957+
total_matches += oso_matches;
958+
959+
// Are we getting all matches?
960+
if (max_matches == UINT32_MAX)
961+
return IterationAction::Continue; // Yep, continue getting
962+
// everything
963+
964+
// If we have found enough matches, lets get out
965+
if (max_matches >= total_matches)
966+
return IterationAction::Stop;
967+
968+
// Update the max matches for any subsequent calls to find globals in
969+
// any other object files with DWARF
970+
max_matches -= oso_matches;
971+
}
947972

948-
return IterationAction::Continue;
949-
});
973+
return IterationAction::Continue;
974+
});
950975
}
951976

952977
void SymbolFileDWARFDebugMap::FindGlobalVariables(
953978
const RegularExpression &regex, uint32_t max_matches,
954979
VariableList &variables) {
955980
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
956981
uint32_t total_matches = 0;
957-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
958-
const uint32_t old_size = variables.GetSize();
959-
oso_dwarf->FindGlobalVariables(regex, max_matches, variables);
960-
961-
const uint32_t oso_matches = variables.GetSize() - old_size;
962-
if (oso_matches > 0) {
963-
total_matches += oso_matches;
964-
965-
// Are we getting all matches?
966-
if (max_matches == UINT32_MAX)
967-
return IterationAction::Continue; // Yep, continue getting everything
968-
969-
// If we have found enough matches, lets get out
970-
if (max_matches >= total_matches)
971-
return IterationAction::Stop;
972-
973-
// Update the max matches for any subsequent calls to find globals in any
974-
// other object files with DWARF
975-
max_matches -= oso_matches;
976-
}
982+
ForEachSymbolFile(
983+
"Looking up global variables", [&](SymbolFileDWARF *oso_dwarf) {
984+
const uint32_t old_size = variables.GetSize();
985+
oso_dwarf->FindGlobalVariables(regex, max_matches, variables);
986+
987+
const uint32_t oso_matches = variables.GetSize() - old_size;
988+
if (oso_matches > 0) {
989+
total_matches += oso_matches;
990+
991+
// Are we getting all matches?
992+
if (max_matches == UINT32_MAX)
993+
return IterationAction::Continue; // Yep, continue getting
994+
// everything
995+
996+
// If we have found enough matches, lets get out
997+
if (max_matches >= total_matches)
998+
return IterationAction::Stop;
999+
1000+
// Update the max matches for any subsequent calls to find globals in
1001+
// any other object files with DWARF
1002+
max_matches -= oso_matches;
1003+
}
9771004

978-
return IterationAction::Continue;
979-
});
1005+
return IterationAction::Continue;
1006+
});
9801007
}
9811008

9821009
int SymbolFileDWARFDebugMap::SymbolContainsSymbolWithIndex(
@@ -1079,7 +1106,7 @@ void SymbolFileDWARFDebugMap::FindFunctions(
10791106
LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
10801107
lookup_info.GetLookupName().GetCString());
10811108

1082-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1109+
ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF *oso_dwarf) {
10831110
uint32_t sc_idx = sc_list.GetSize();
10841111
oso_dwarf->FindFunctions(lookup_info, parent_decl_ctx, include_inlines,
10851112
sc_list);
@@ -1098,7 +1125,7 @@ void SymbolFileDWARFDebugMap::FindFunctions(const RegularExpression &regex,
10981125
LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
10991126
regex.GetText().str().c_str());
11001127

1101-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1128+
ForEachSymbolFile("Looking up functions", [&](SymbolFileDWARF *oso_dwarf) {
11021129
uint32_t sc_idx = sc_list.GetSize();
11031130

11041131
oso_dwarf->FindFunctions(regex, include_inlines, sc_list);
@@ -1129,7 +1156,7 @@ void SymbolFileDWARFDebugMap::GetTypes(SymbolContextScope *sc_scope,
11291156
oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
11301157
}
11311158
} else {
1132-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1159+
ForEachSymbolFile("Looking up types", [&](SymbolFileDWARF *oso_dwarf) {
11331160
oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
11341161
return IterationAction::Continue;
11351162
});
@@ -1148,16 +1175,16 @@ SymbolFileDWARFDebugMap::ParseCallEdgesInFunction(
11481175

11491176
DWARFDIE SymbolFileDWARFDebugMap::FindDefinitionDIE(const DWARFDIE &die) {
11501177
DWARFDIE result;
1151-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1152-
result = oso_dwarf->FindDefinitionDIE(die);
1153-
return result ? IterationAction::Stop : IterationAction::Continue;
1154-
});
1178+
ForEachSymbolFile(
1179+
"Looking up type definition", [&](SymbolFileDWARF *oso_dwarf) {
1180+
result = oso_dwarf->FindDefinitionDIE(die);
1181+
return result ? IterationAction::Stop : IterationAction::Continue;
1182+
});
11551183
return result;
11561184
}
11571185

11581186
TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
1159-
const DWARFDIE &die, ConstString type_name,
1160-
bool must_be_implementation) {
1187+
const DWARFDIE &die, ConstString type_name, bool must_be_implementation) {
11611188
// If we have a debug map, we will have an Objective-C symbol whose name is
11621189
// the type name and whose type is eSymbolTypeObjCClass. If we can find that
11631190
// symbol and find its containing parent, we can locate the .o file that will
@@ -1208,11 +1235,12 @@ TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
12081235
if (!must_be_implementation) {
12091236
TypeSP type_sp;
12101237

1211-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1212-
type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE(
1213-
die, type_name, must_be_implementation);
1214-
return type_sp ? IterationAction::Stop : IterationAction::Continue;
1215-
});
1238+
ForEachSymbolFile(
1239+
"Looking up Objective-C definition", [&](SymbolFileDWARF *oso_dwarf) {
1240+
type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE(
1241+
die, type_name, must_be_implementation);
1242+
return type_sp ? IterationAction::Stop : IterationAction::Continue;
1243+
});
12161244

12171245
return type_sp;
12181246
}
@@ -1222,7 +1250,7 @@ TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
12221250
void SymbolFileDWARFDebugMap::FindTypes(const TypeQuery &query,
12231251
TypeResults &results) {
12241252
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1225-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1253+
ForEachSymbolFile("Looking up type", [&](SymbolFileDWARF *oso_dwarf) {
12261254
oso_dwarf->FindTypes(query, results);
12271255
return results.Done(query) ? IterationAction::Stop
12281256
: IterationAction::Continue;
@@ -1235,7 +1263,7 @@ CompilerDeclContext SymbolFileDWARFDebugMap::FindNamespace(
12351263
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
12361264
CompilerDeclContext matching_namespace;
12371265

1238-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1266+
ForEachSymbolFile("Looking up namespace", [&](SymbolFileDWARF *oso_dwarf) {
12391267
matching_namespace =
12401268
oso_dwarf->FindNamespace(name, parent_decl_ctx, only_root_namespaces);
12411269

@@ -1247,7 +1275,7 @@ CompilerDeclContext SymbolFileDWARFDebugMap::FindNamespace(
12471275
}
12481276

12491277
void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s) {
1250-
ForEachSymbolFile([&s](SymbolFileDWARF *oso_dwarf) {
1278+
ForEachSymbolFile("Dumping clang AST", [&s](SymbolFileDWARF *oso_dwarf) {
12511279
oso_dwarf->DumpClangAST(s);
12521280
// The underlying assumption is that DumpClangAST(...) will obtain the
12531281
// AST from the underlying TypeSystem and therefore we only need to do
@@ -1294,7 +1322,8 @@ bool SymbolFileDWARFDebugMap::GetSeparateDebugInfo(
12941322
}
12951323

12961324
lldb::CompUnitSP
1297-
SymbolFileDWARFDebugMap::GetCompileUnit(SymbolFileDWARF *oso_dwarf, DWARFCompileUnit &dwarf_cu) {
1325+
SymbolFileDWARFDebugMap::GetCompileUnit(SymbolFileDWARF *oso_dwarf,
1326+
DWARFCompileUnit &dwarf_cu) {
12981327
if (oso_dwarf) {
12991328
const uint32_t cu_count = GetNumCompileUnits();
13001329
for (uint32_t cu_idx = 0; cu_idx < cu_count; ++cu_idx) {
@@ -1344,7 +1373,8 @@ void SymbolFileDWARFDebugMap::SetCompileUnit(SymbolFileDWARF *oso_dwarf,
13441373
} else {
13451374
assert(cu_sp->GetID() == 0 &&
13461375
"Setting first compile unit but with id different than 0!");
1347-
auto &compile_units_sps = m_compile_unit_infos[cu_idx].compile_units_sps;
1376+
auto &compile_units_sps =
1377+
m_compile_unit_infos[cu_idx].compile_units_sps;
13481378
compile_units_sps.push_back(cu_sp);
13491379
m_compile_unit_infos[cu_idx].id_to_index_map.insert(
13501380
{cu_sp->GetID(), compile_units_sps.size() - 1});
@@ -1382,7 +1412,7 @@ SymbolFileDWARFDebugMap::GetCompilerContextForUID(lldb::user_id_t type_uid) {
13821412

13831413
void SymbolFileDWARFDebugMap::ParseDeclsForContext(
13841414
lldb_private::CompilerDeclContext decl_ctx) {
1385-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1415+
ForEachSymbolFile("Parsing declarations", [&](SymbolFileDWARF *oso_dwarf) {
13861416
oso_dwarf->ParseDeclsForContext(decl_ctx);
13871417
return IterationAction::Continue;
13881418
});
@@ -1512,7 +1542,7 @@ SymbolFileDWARFDebugMap::AddOSOARanges(SymbolFileDWARF *dwarf2Data,
15121542

15131543
ModuleList SymbolFileDWARFDebugMap::GetDebugInfoModules() {
15141544
ModuleList oso_modules;
1515-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1545+
ForEachSymbolFile("Parsing modules", [&](SymbolFileDWARF *oso_dwarf) {
15161546
ObjectFile *oso_objfile = oso_dwarf->GetObjectFile();
15171547
if (oso_objfile) {
15181548
ModuleSP module_sp = oso_objfile->GetModule();
@@ -1573,7 +1603,7 @@ Status SymbolFileDWARFDebugMap::CalculateFrameVariableError(StackFrame &frame) {
15731603
void SymbolFileDWARFDebugMap::GetCompileOptions(
15741604
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
15751605

1576-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
1606+
ForEachSymbolFile("Parsing compile options", [&](SymbolFileDWARF *oso_dwarf) {
15771607
oso_dwarf->GetCompileOptions(args);
15781608
return IterationAction::Continue;
15791609
});

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,8 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
237237
/// If closure returns \ref IterationAction::Continue, iteration
238238
/// continues. Otherwise, iteration terminates.
239239
void
240-
ForEachSymbolFile(std::function<IterationAction(SymbolFileDWARF *)> closure) {
241-
for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
242-
oso_idx < num_oso_idxs; ++oso_idx) {
243-
if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
244-
if (closure(oso_dwarf) == IterationAction::Stop)
245-
return;
246-
}
247-
}
248-
}
240+
ForEachSymbolFile(std::string description,
241+
std::function<IterationAction(SymbolFileDWARF *)> closure);
249242

250243
CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
251244
uint32_t *oso_idx_ptr);

0 commit comments

Comments
 (0)