Skip to content

Commit 9ebae9e

Browse files
committed
[lldb][SymbolFileDWARFDebugMap] Introduce enum to indicate whether to continue iteration of object files
This patch introduces a new `IterationMarker` enum (happy to take alternative name suggestions), which callbacks, like the one in `SymbolFileDWARFDebugMap::ForEachSymbolFile` can return in order to indicate whether the caller should continue iterating or bail. For now this patch just changes the `ForEachSymbolFile` callback to use this new enum. In the future we could change the various `DWARFIndex::GetXXX` callbacks to do the same. This makes the callbacks easier to read and hopefully reduces the chance of bugs like llvm#87177.
1 parent 63d22f7 commit 9ebae9e

File tree

3 files changed

+49
-37
lines changed

3 files changed

+49
-37
lines changed

lldb/include/lldb/lldb-enumerations.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,13 @@ enum AddressMaskRange {
13391339
eAddressMaskRangeAll = eAddressMaskRangeAny,
13401340
};
13411341

1342+
/// Useful for callbacks whose return type indicates
1343+
/// whether to continue iteration or short-circuit.
1344+
enum class IterationMarker {
1345+
eContinue = 0,
1346+
eStop,
1347+
};
1348+
13421349
} // namespace lldb
13431350

13441351
#endif // LLDB_LLDB_ENUMERATIONS_H

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

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include "LogChannelDWARF.h"
3939
#include "SymbolFileDWARF.h"
40+
#include "lldb/lldb-enumerations.h"
4041

4142
#include <memory>
4243
#include <optional>
@@ -803,13 +804,13 @@ SymbolFileDWARFDebugMap::GetDynamicArrayInfoForUID(
803804
bool SymbolFileDWARFDebugMap::CompleteType(CompilerType &compiler_type) {
804805
bool success = false;
805806
if (compiler_type) {
806-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
807+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
807808
if (oso_dwarf->HasForwardDeclForCompilerType(compiler_type)) {
808809
oso_dwarf->CompleteType(compiler_type);
809810
success = true;
810-
return true;
811+
return IterationMarker::eStop;
811812
}
812-
return false;
813+
return IterationMarker::eContinue;
813814
});
814815
}
815816
return success;
@@ -915,7 +916,7 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
915916
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
916917
uint32_t total_matches = 0;
917918

918-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
919+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
919920
const uint32_t old_size = variables.GetSize();
920921
oso_dwarf->FindGlobalVariables(name, parent_decl_ctx, max_matches,
921922
variables);
@@ -925,18 +926,18 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
925926

926927
// Are we getting all matches?
927928
if (max_matches == UINT32_MAX)
928-
return false; // Yep, continue getting everything
929+
return IterationMarker::eContinue; // Yep, continue getting everything
929930

930931
// If we have found enough matches, lets get out
931932
if (max_matches >= total_matches)
932-
return true;
933+
return IterationMarker::eStop;
933934

934935
// Update the max matches for any subsequent calls to find globals in any
935936
// other object files with DWARF
936937
max_matches -= oso_matches;
937938
}
938939

939-
return false;
940+
return IterationMarker::eContinue;
940941
});
941942
}
942943

@@ -945,7 +946,7 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
945946
VariableList &variables) {
946947
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
947948
uint32_t total_matches = 0;
948-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
949+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
949950
const uint32_t old_size = variables.GetSize();
950951
oso_dwarf->FindGlobalVariables(regex, max_matches, variables);
951952

@@ -955,18 +956,18 @@ void SymbolFileDWARFDebugMap::FindGlobalVariables(
955956

956957
// Are we getting all matches?
957958
if (max_matches == UINT32_MAX)
958-
return false; // Yep, continue getting everything
959+
return IterationMarker::eContinue; // Yep, continue getting everything
959960

960961
// If we have found enough matches, lets get out
961962
if (max_matches >= total_matches)
962-
return true;
963+
return IterationMarker::eStop;
963964

964965
// Update the max matches for any subsequent calls to find globals in any
965966
// other object files with DWARF
966967
max_matches -= oso_matches;
967968
}
968969

969-
return false;
970+
return IterationMarker::eContinue;
970971
});
971972
}
972973

@@ -1071,15 +1072,15 @@ void SymbolFileDWARFDebugMap::FindFunctions(
10711072
LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (name = %s)",
10721073
lookup_info.GetLookupName().GetCString());
10731074

1074-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1075+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
10751076
uint32_t sc_idx = sc_list.GetSize();
10761077
oso_dwarf->FindFunctions(lookup_info, parent_decl_ctx, include_inlines,
10771078
sc_list);
10781079
if (!sc_list.IsEmpty()) {
10791080
RemoveFunctionsWithModuleNotEqualTo(m_objfile_sp->GetModule(), sc_list,
10801081
sc_idx);
10811082
}
1082-
return false;
1083+
return IterationMarker::eContinue;
10831084
});
10841085
}
10851086

@@ -1090,15 +1091,15 @@ void SymbolFileDWARFDebugMap::FindFunctions(const RegularExpression &regex,
10901091
LLDB_SCOPED_TIMERF("SymbolFileDWARFDebugMap::FindFunctions (regex = '%s')",
10911092
regex.GetText().str().c_str());
10921093

1093-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1094+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
10941095
uint32_t sc_idx = sc_list.GetSize();
10951096

10961097
oso_dwarf->FindFunctions(regex, include_inlines, sc_list);
10971098
if (!sc_list.IsEmpty()) {
10981099
RemoveFunctionsWithModuleNotEqualTo(m_objfile_sp->GetModule(), sc_list,
10991100
sc_idx);
11001101
}
1101-
return false;
1102+
return IterationMarker::eContinue;
11021103
});
11031104
}
11041105

@@ -1121,9 +1122,9 @@ void SymbolFileDWARFDebugMap::GetTypes(SymbolContextScope *sc_scope,
11211122
oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
11221123
}
11231124
} else {
1124-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1125+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
11251126
oso_dwarf->GetTypes(sc_scope, type_mask, type_list);
1126-
return false;
1127+
return IterationMarker::eContinue;
11271128
});
11281129
}
11291130
}
@@ -1141,9 +1142,9 @@ SymbolFileDWARFDebugMap::ParseCallEdgesInFunction(
11411142
TypeSP SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext(
11421143
const DWARFDIE &die) {
11431144
TypeSP type_sp;
1144-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1145+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
11451146
type_sp = oso_dwarf->FindDefinitionTypeForDWARFDeclContext(die);
1146-
return ((bool)type_sp);
1147+
return type_sp ? IterationMarker::eStop : IterationMarker::eContinue;
11471148
});
11481149
return type_sp;
11491150
}
@@ -1152,13 +1153,13 @@ bool SymbolFileDWARFDebugMap::Supports_DW_AT_APPLE_objc_complete_type(
11521153
SymbolFileDWARF *skip_dwarf_oso) {
11531154
if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) {
11541155
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
1155-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1156+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
11561157
if (skip_dwarf_oso != oso_dwarf &&
11571158
oso_dwarf->Supports_DW_AT_APPLE_objc_complete_type(nullptr)) {
11581159
m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
1159-
return true;
1160+
return IterationMarker::eStop;
11601161
}
1161-
return false;
1162+
return IterationMarker::eContinue;
11621163
});
11631164
}
11641165
return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
@@ -1217,10 +1218,10 @@ TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
12171218
if (!must_be_implementation) {
12181219
TypeSP type_sp;
12191220

1220-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1221+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
12211222
type_sp = oso_dwarf->FindCompleteObjCDefinitionTypeForDIE(
12221223
die, type_name, must_be_implementation);
1223-
return (bool)type_sp;
1224+
return type_sp ? IterationMarker::eStop : IterationMarker::eContinue;
12241225
});
12251226

12261227
return type_sp;
@@ -1231,9 +1232,10 @@ TypeSP SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE(
12311232
void SymbolFileDWARFDebugMap::FindTypes(const TypeQuery &query,
12321233
TypeResults &results) {
12331234
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1234-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1235+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
12351236
oso_dwarf->FindTypes(query, results);
1236-
return results.Done(query); // Keep iterating if we aren't done.
1237+
return results.Done(query) ? IterationMarker::eStop
1238+
: IterationMarker::eContinue;
12371239
});
12381240
}
12391241

@@ -1243,23 +1245,24 @@ CompilerDeclContext SymbolFileDWARFDebugMap::FindNamespace(
12431245
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
12441246
CompilerDeclContext matching_namespace;
12451247

1246-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1248+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
12471249
matching_namespace =
12481250
oso_dwarf->FindNamespace(name, parent_decl_ctx, only_root_namespaces);
12491251

1250-
return (bool)matching_namespace;
1252+
return matching_namespace ? IterationMarker::eStop
1253+
: IterationMarker::eContinue;
12511254
});
12521255

12531256
return matching_namespace;
12541257
}
12551258

12561259
void SymbolFileDWARFDebugMap::DumpClangAST(Stream &s) {
1257-
ForEachSymbolFile([&s](SymbolFileDWARF *oso_dwarf) -> bool {
1260+
ForEachSymbolFile([&s](SymbolFileDWARF *oso_dwarf) {
12581261
oso_dwarf->DumpClangAST(s);
12591262
// The underlying assumption is that DumpClangAST(...) will obtain the
12601263
// AST from the underlying TypeSystem and therefore we only need to do
12611264
// this once and can stop after the first iteration hence we return true.
1262-
return true;
1265+
return IterationMarker::eStop;
12631266
});
12641267
}
12651268

@@ -1391,7 +1394,7 @@ void SymbolFileDWARFDebugMap::ParseDeclsForContext(
13911394
lldb_private::CompilerDeclContext decl_ctx) {
13921395
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
13931396
oso_dwarf->ParseDeclsForContext(decl_ctx);
1394-
return false; // Keep iterating
1397+
return IterationMarker::eContinue;
13951398
});
13961399
}
13971400

@@ -1519,14 +1522,14 @@ SymbolFileDWARFDebugMap::AddOSOARanges(SymbolFileDWARF *dwarf2Data,
15191522

15201523
ModuleList SymbolFileDWARFDebugMap::GetDebugInfoModules() {
15211524
ModuleList oso_modules;
1522-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1525+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
15231526
ObjectFile *oso_objfile = oso_dwarf->GetObjectFile();
15241527
if (oso_objfile) {
15251528
ModuleSP module_sp = oso_objfile->GetModule();
15261529
if (module_sp)
15271530
oso_modules.Append(module_sp);
15281531
}
1529-
return false; // Keep iterating
1532+
return IterationMarker::eContinue;
15301533
});
15311534
return oso_modules;
15321535
}
@@ -1579,8 +1582,8 @@ Status SymbolFileDWARFDebugMap::CalculateFrameVariableError(StackFrame &frame) {
15791582
void SymbolFileDWARFDebugMap::GetCompileOptions(
15801583
std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {
15811584

1582-
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1585+
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) {
15831586
oso_dwarf->GetCompileOptions(args);
1584-
return false;
1587+
return IterationMarker::eContinue;
15851588
});
15861589
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "UniqueDWARFASTType.h"
2222
#include "lldb/Utility/StructuredData.h"
23+
#include "lldb/lldb-enumerations.h"
2324

2425
class DWARFASTParserClang;
2526

@@ -235,11 +236,12 @@ class SymbolFileDWARFDebugMap : public SymbolFileCommon {
235236

236237
// If closure returns "false", iteration continues. If it returns
237238
// "true", iteration terminates.
238-
void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
239+
void ForEachSymbolFile(
240+
std::function<lldb::IterationMarker(SymbolFileDWARF *)> closure) {
239241
for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
240242
oso_idx < num_oso_idxs; ++oso_idx) {
241243
if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
242-
if (closure(oso_dwarf))
244+
if (closure(oso_dwarf) == lldb::IterationMarker::eStop)
243245
return;
244246
}
245247
}

0 commit comments

Comments
 (0)