bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, jingham, mib, aprantl.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: lldb-commits, jplehr, sstefan1.
Herald added a project: LLDB.
There are many situations where we'll iterate over a SymbolContextList
with the pattern:
SymbolContextList sc_list;
// Fill in sc_list here
for (auto i = 0; i < sc_list.GetSize(); i++) {
SymbolContext sc;
sc_list.GetSymbolAtContext(i, sc);
// Do work with sc
}
Adding an iterator to iterate over the instances directly means we don't
have to do bounds checking or create a copy of every element of the
SymbolContextList.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149900
Files:
lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
lldb/include/lldb/Symbol/SymbolContext.h
lldb/include/lldb/Symbol/UnwindTable.h
lldb/source/API/SBThread.cpp
lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
lldb/source/Breakpoint/BreakpointResolverName.cpp
lldb/source/Commands/CommandCompletions.cpp
lldb/source/Commands/CommandObjectSource.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Core/AddressResolverFileLine.cpp
lldb/source/Core/SourceManager.cpp
lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Symbol/Symbol.cpp
lldb/source/Symbol/SymbolContext.cpp
lldb/source/Symbol/UnwindTable.cpp
Index: lldb/source/Symbol/UnwindTable.cpp
===================================================================
--- lldb/source/Symbol/UnwindTable.cpp
+++ lldb/source/Symbol/UnwindTable.cpp
@@ -86,8 +86,8 @@
UnwindTable::~UnwindTable() = default;
-std::optional<AddressRange> UnwindTable::GetAddressRange(const Address &addr,
- SymbolContext &sc) {
+std::optional<AddressRange>
+UnwindTable::GetAddressRange(const Address &addr, const SymbolContext &sc) {
AddressRange range;
// First check the unwind info from the object file plugin
@@ -150,9 +150,8 @@
// don't add it to the UnwindTable. This is intended for use by target modules
// show-unwind where we want to create new UnwindPlans, not re-use existing
// ones.
-FuncUnwindersSP
-UnwindTable::GetUncachedFuncUnwindersContainingAddress(const Address &addr,
- SymbolContext &sc) {
+FuncUnwindersSP UnwindTable::GetUncachedFuncUnwindersContainingAddress(
+ const Address &addr, const SymbolContext &sc) {
Initialize();
auto range_or = GetAddressRange(addr, sc);
Index: lldb/source/Symbol/SymbolContext.cpp
===================================================================
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -771,14 +771,11 @@
Module *module = module_sp.get();
auto ProcessMatches = [this, &name, &target,
- module](SymbolContextList &sc_list,
+ module](const SymbolContextList &sc_list,
Status &error) -> const Symbol * {
llvm::SmallVector<const Symbol *, 1> external_symbols;
llvm::SmallVector<const Symbol *, 1> internal_symbols;
- const uint32_t matches = sc_list.GetSize();
- for (uint32_t i = 0; i < matches; ++i) {
- SymbolContext sym_ctx;
- sc_list.GetContextAtIndex(i, sym_ctx);
+ for (const auto &sym_ctx : sc_list) {
if (sym_ctx.symbol) {
const Symbol *symbol = sym_ctx.symbol;
const Address sym_address = symbol->GetAddress();
Index: lldb/source/Symbol/Symbol.cpp
===================================================================
--- lldb/source/Symbol/Symbol.cpp
+++ lldb/source/Symbol/Symbol.cpp
@@ -488,15 +488,9 @@
lldb_private::SymbolContextList sc_list;
module_sp->FindSymbolsWithNameAndType(reexport_name, eSymbolTypeAny,
sc_list);
- const size_t num_scs = sc_list.GetSize();
- if (num_scs > 0) {
- for (size_t i = 0; i < num_scs; ++i) {
- lldb_private::SymbolContext sc;
- if (sc_list.GetContextAtIndex(i, sc)) {
- if (sc.symbol->IsExternal())
- return sc.symbol;
- }
- }
+ for (const auto &sc : sc_list) {
+ if (sc.symbol->IsExternal())
+ return sc.symbol;
}
// If we didn't find the symbol in this module, it may be because this
// module re-exports some whole other library. We have to search those as
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4028,52 +4028,45 @@
lldb_private::SymbolContextList sc_list;
process->GetTarget().GetImages().FindSymbolsWithNameAndType(
ConstString(symbol_name), eSymbolTypeAny, sc_list);
- if (!sc_list.IsEmpty()) {
- const size_t num_scs = sc_list.GetSize();
- for (size_t sc_idx = 0;
- sc_idx < num_scs &&
- symbol_load_addr == LLDB_INVALID_ADDRESS;
- ++sc_idx) {
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(sc_idx, sc)) {
- if (sc.symbol) {
- switch (sc.symbol->GetType()) {
- case eSymbolTypeInvalid:
- case eSymbolTypeAbsolute:
- case eSymbolTypeUndefined:
- case eSymbolTypeSourceFile:
- case eSymbolTypeHeaderFile:
- case eSymbolTypeObjectFile:
- case eSymbolTypeCommonBlock:
- case eSymbolTypeBlock:
- case eSymbolTypeLocal:
- case eSymbolTypeParam:
- case eSymbolTypeVariable:
- case eSymbolTypeVariableType:
- case eSymbolTypeLineEntry:
- case eSymbolTypeLineHeader:
- case eSymbolTypeScopeBegin:
- case eSymbolTypeScopeEnd:
- case eSymbolTypeAdditional:
- case eSymbolTypeCompiler:
- case eSymbolTypeInstrumentation:
- case eSymbolTypeTrampoline:
- break;
-
- case eSymbolTypeCode:
- case eSymbolTypeResolver:
- case eSymbolTypeData:
- case eSymbolTypeRuntime:
- case eSymbolTypeException:
- case eSymbolTypeObjCClass:
- case eSymbolTypeObjCMetaClass:
- case eSymbolTypeObjCIVar:
- case eSymbolTypeReExported:
- symbol_load_addr =
- sc.symbol->GetLoadAddress(&process->GetTarget());
- break;
- }
- }
+ for (const auto &sc : sc_list) {
+ if (symbol_load_addr != LLDB_INVALID_ADDRESS)
+ break;
+ if (sc.symbol) {
+ switch (sc.symbol->GetType()) {
+ case eSymbolTypeInvalid:
+ case eSymbolTypeAbsolute:
+ case eSymbolTypeUndefined:
+ case eSymbolTypeSourceFile:
+ case eSymbolTypeHeaderFile:
+ case eSymbolTypeObjectFile:
+ case eSymbolTypeCommonBlock:
+ case eSymbolTypeBlock:
+ case eSymbolTypeLocal:
+ case eSymbolTypeParam:
+ case eSymbolTypeVariable:
+ case eSymbolTypeVariableType:
+ case eSymbolTypeLineEntry:
+ case eSymbolTypeLineHeader:
+ case eSymbolTypeScopeBegin:
+ case eSymbolTypeScopeEnd:
+ case eSymbolTypeAdditional:
+ case eSymbolTypeCompiler:
+ case eSymbolTypeInstrumentation:
+ case eSymbolTypeTrampoline:
+ break;
+
+ case eSymbolTypeCode:
+ case eSymbolTypeResolver:
+ case eSymbolTypeData:
+ case eSymbolTypeRuntime:
+ case eSymbolTypeException:
+ case eSymbolTypeObjCClass:
+ case eSymbolTypeObjCMetaClass:
+ case eSymbolTypeObjCIVar:
+ case eSymbolTypeReExported:
+ symbol_load_addr =
+ sc.symbol->GetLoadAddress(&process->GetTarget());
+ break;
}
}
}
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -531,15 +531,11 @@
else
target.GetImages().FindSymbolsWithNameAndType(name, symbol_type, sc_list);
- const uint32_t num_matches = sc_list.GetSize();
addr_t symbol_load_addr = LLDB_INVALID_ADDRESS;
- for (uint32_t i = 0;
- i < num_matches &&
- (symbol_load_addr == 0 || symbol_load_addr == LLDB_INVALID_ADDRESS);
- i++) {
- SymbolContext sym_ctx;
- sc_list.GetContextAtIndex(i, sym_ctx);
+ for (const auto &sym_ctx : sc_list) {
+ if (symbol_load_addr != 0 || symbol_load_addr != LLDB_INVALID_ADDRESS)
+ break;
const Address sym_address = sym_ctx.symbol->GetAddress();
@@ -1147,19 +1143,16 @@
// remove unwanted functions and separate out the functions we want to
// compare and prune into a separate list. Cache the info needed about
// the function declarations in a vector for efficiency.
- uint32_t num_indices = sc_list.GetSize();
SymbolContextList sc_sym_list;
std::vector<FuncDeclInfo> decl_infos;
- decl_infos.reserve(num_indices);
+ decl_infos.reserve(sc_list.GetSize());
clang::DeclContext *frame_decl_ctx =
(clang::DeclContext *)frame_decl_context.GetOpaqueDeclContext();
TypeSystemClang *ast = llvm::dyn_cast_or_null<TypeSystemClang>(
frame_decl_context.GetTypeSystem());
- for (uint32_t index = 0; index < num_indices; ++index) {
+ for (const auto &sym_ctx : sc_list) {
FuncDeclInfo fdi;
- SymbolContext sym_ctx;
- sc_list.GetContextAtIndex(index, sym_ctx);
// We don't know enough about symbols to compare them, but we should
// keep them in the list.
@@ -1294,11 +1287,7 @@
Symbol *extern_symbol = nullptr;
Symbol *non_extern_symbol = nullptr;
- for (uint32_t index = 0, num_indices = sc_list.GetSize();
- index < num_indices; ++index) {
- SymbolContext sym_ctx;
- sc_list.GetContextAtIndex(index, sym_ctx);
-
+ for (const auto &sym_ctx : sc_list) {
if (sym_ctx.function) {
CompilerDeclContext decl_ctx = sym_ctx.function->GetDeclContext();
@@ -1313,16 +1302,17 @@
context.m_found_function_with_type_info = true;
context.m_found_function = true;
} else if (sym_ctx.symbol) {
- if (sym_ctx.symbol->GetType() == eSymbolTypeReExported && target) {
- sym_ctx.symbol = sym_ctx.symbol->ResolveReExportedSymbol(*target);
- if (sym_ctx.symbol == nullptr)
+ Symbol *symbol = sym_ctx.symbol;
+ if (target && symbol->GetType() == eSymbolTypeReExported) {
+ symbol = symbol->ResolveReExportedSymbol(*target);
+ if (symbol == nullptr)
continue;
}
- if (sym_ctx.symbol->IsExternal())
- extern_symbol = sym_ctx.symbol;
+ if (symbol->IsExternal())
+ extern_symbol = symbol;
else
- non_extern_symbol = sym_ctx.symbol;
+ non_extern_symbol = symbol;
}
}
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1036,12 +1036,7 @@
lldb::eFunctionNameTypeSelector,
function_options, candidate_sc_list);
- for (uint32_t ci = 0, ce = candidate_sc_list.GetSize(); ci != ce; ++ci) {
- SymbolContext candidate_sc;
-
- if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc))
- continue;
-
+ for (const auto &candidate_sc : candidate_sc_list) {
if (!candidate_sc.function)
continue;
@@ -1074,12 +1069,7 @@
if (sc_list.GetSize()) {
// We found a good function symbol. Use that.
- for (uint32_t i = 0, e = sc_list.GetSize(); i != e; ++i) {
- SymbolContext sc;
-
- if (!sc_list.GetContextAtIndex(i, sc))
- continue;
-
+ for (const auto &sc : sc_list) {
if (!sc.function)
continue;
Index: lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
===================================================================
--- lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -511,21 +511,17 @@
const ModuleList &images = target.GetImages();
images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
- size_t num_targets = target_symbols.GetSize();
- if (!num_targets)
+ if (target_symbols.GetSize())
return thread_plan_sp;
typedef std::vector<lldb::addr_t> AddressVector;
AddressVector addrs;
- for (size_t i = 0; i < num_targets; ++i) {
- SymbolContext context;
+ for (const auto &context : target_symbols) {
AddressRange range;
- if (target_symbols.GetContextAtIndex(i, context)) {
- context.GetAddressRange(eSymbolContextEverything, 0, false, range);
- lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
- if (addr != LLDB_INVALID_ADDRESS)
- addrs.push_back(addr);
- }
+ context.GetAddressRange(eSymbolContextEverything, 0, false, range);
+ lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
+ if (addr != LLDB_INVALID_ADDRESS)
+ addrs.push_back(addr);
}
if (addrs.size() > 0) {
Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
===================================================================
--- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -888,53 +888,37 @@
SymbolContextList code_symbols;
images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode,
code_symbols);
- size_t num_code_symbols = code_symbols.GetSize();
-
- if (num_code_symbols > 0) {
- for (uint32_t i = 0; i < num_code_symbols; i++) {
- SymbolContext context;
- AddressRange addr_range;
- if (code_symbols.GetContextAtIndex(i, context)) {
- context.GetAddressRange(eSymbolContextEverything, 0, false,
- addr_range);
- addresses.push_back(addr_range.GetBaseAddress());
- if (log) {
- addr_t load_addr =
- addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
-
- LLDB_LOGF(log,
- "Found a trampoline target symbol at 0x%" PRIx64 ".",
- load_addr);
- }
- }
+ for (const auto &context : code_symbols) {
+ AddressRange addr_range;
+ context.GetAddressRange(eSymbolContextEverything, 0, false,
+ addr_range);
+ addresses.push_back(addr_range.GetBaseAddress());
+ if (log) {
+ addr_t load_addr =
+ addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
+
+ LLDB_LOGF(log, "Found a trampoline target symbol at 0x%" PRIx64 ".",
+ load_addr);
}
}
SymbolContextList reexported_symbols;
images.FindSymbolsWithNameAndType(
trampoline_name, eSymbolTypeReExported, reexported_symbols);
- size_t num_reexported_symbols = reexported_symbols.GetSize();
- if (num_reexported_symbols > 0) {
- for (uint32_t i = 0; i < num_reexported_symbols; i++) {
- SymbolContext context;
- if (reexported_symbols.GetContextAtIndex(i, context)) {
- if (context.symbol) {
- Symbol *actual_symbol =
- context.symbol->ResolveReExportedSymbol(*target_sp.get());
- if (actual_symbol) {
- const Address actual_symbol_addr =
- actual_symbol->GetAddress();
- if (actual_symbol_addr.IsValid()) {
- addresses.push_back(actual_symbol_addr);
- if (log) {
- lldb::addr_t load_addr =
- actual_symbol_addr.GetLoadAddress(target_sp.get());
- LLDB_LOGF(
- log,
- "Found a re-exported symbol: %s at 0x%" PRIx64 ".",
- actual_symbol->GetName().GetCString(), load_addr);
- }
- }
+ for (const auto &context : reexported_symbols) {
+ if (context.symbol) {
+ Symbol *actual_symbol =
+ context.symbol->ResolveReExportedSymbol(*target_sp.get());
+ if (actual_symbol) {
+ const Address actual_symbol_addr = actual_symbol->GetAddress();
+ if (actual_symbol_addr.IsValid()) {
+ addresses.push_back(actual_symbol_addr);
+ if (log) {
+ lldb::addr_t load_addr =
+ actual_symbol_addr.GetLoadAddress(target_sp.get());
+ LLDB_LOGF(log,
+ "Found a re-exported symbol: %s at 0x%" PRIx64 ".",
+ actual_symbol->GetName().GetCString(), load_addr);
}
}
}
@@ -944,24 +928,18 @@
SymbolContextList indirect_symbols;
images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver,
indirect_symbols);
- size_t num_indirect_symbols = indirect_symbols.GetSize();
- if (num_indirect_symbols > 0) {
- for (uint32_t i = 0; i < num_indirect_symbols; i++) {
- SymbolContext context;
- AddressRange addr_range;
- if (indirect_symbols.GetContextAtIndex(i, context)) {
- context.GetAddressRange(eSymbolContextEverything, 0, false,
- addr_range);
- addresses.push_back(addr_range.GetBaseAddress());
- if (log) {
- addr_t load_addr =
- addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
-
- LLDB_LOGF(log,
- "Found an indirect target symbol at 0x%" PRIx64 ".",
- load_addr);
- }
- }
+
+ for (const auto &context : indirect_symbols) {
+ AddressRange addr_range;
+ context.GetAddressRange(eSymbolContextEverything, 0, false,
+ addr_range);
+ addresses.push_back(addr_range.GetBaseAddress());
+ if (log) {
+ addr_t load_addr =
+ addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
+
+ LLDB_LOGF(log, "Found an indirect target symbol at 0x%" PRIx64 ".",
+ load_addr);
}
}
}
Index: lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
===================================================================
--- lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
@@ -420,21 +420,17 @@
const ModuleList &images = target.GetImages();
images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
- size_t num_targets = target_symbols.GetSize();
- if (!num_targets)
+ if (target_symbols.GetSize() == 0)
return thread_plan_sp;
typedef std::vector<lldb::addr_t> AddressVector;
AddressVector addrs;
- for (size_t i = 0; i < num_targets; ++i) {
- SymbolContext context;
+ for (const auto &context : target_symbols) {
AddressRange range;
- if (target_symbols.GetContextAtIndex(i, context)) {
- context.GetAddressRange(eSymbolContextEverything, 0, false, range);
- lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
- if (addr != LLDB_INVALID_ADDRESS)
- addrs.push_back(addr);
- }
+ context.GetAddressRange(eSymbolContextEverything, 0, false, range);
+ lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
+ if (addr != LLDB_INVALID_ADDRESS)
+ addrs.push_back(addr);
}
if (addrs.size() > 0) {
Index: lldb/source/Core/SourceManager.cpp
===================================================================
--- lldb/source/Core/SourceManager.cpp
+++ lldb/source/Core/SourceManager.cpp
@@ -359,10 +359,7 @@
executable_ptr->FindFunctions(main_name, CompilerDeclContext(),
lldb::eFunctionNameTypeBase,
function_options, sc_list);
- size_t num_matches = sc_list.GetSize();
- for (size_t idx = 0; idx < num_matches; idx++) {
- SymbolContext sc;
- sc_list.GetContextAtIndex(idx, sc);
+ for (const auto &sc : sc_list) {
if (sc.function) {
lldb_private::LineEntry line_entry;
if (sc.function->GetAddressRange()
@@ -430,11 +427,8 @@
bool got_multiple = false;
if (num_matches != 0) {
if (num_matches > 1) {
- SymbolContext sc;
CompileUnit *test_cu = nullptr;
-
- for (unsigned i = 0; i < num_matches; i++) {
- sc_list.GetContextAtIndex(i, sc);
+ for (const auto &sc : sc_list) {
if (sc.comp_unit) {
if (test_cu) {
if (test_cu != sc.comp_unit)
Index: lldb/source/Core/AddressResolverFileLine.cpp
===================================================================
--- lldb/source/Core/AddressResolverFileLine.cpp
+++ lldb/source/Core/AddressResolverFileLine.cpp
@@ -45,24 +45,20 @@
// TODO: Handle SourceLocationSpec column information
cu->ResolveSymbolContext(m_src_location_spec, eSymbolContextEverything,
sc_list);
- uint32_t sc_list_size = sc_list.GetSize();
- for (uint32_t i = 0; i < sc_list_size; i++) {
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(i, sc)) {
- Address line_start = sc.line_entry.range.GetBaseAddress();
- addr_t byte_size = sc.line_entry.range.GetByteSize();
- if (line_start.IsValid()) {
- AddressRange new_range(line_start, byte_size);
- m_address_ranges.push_back(new_range);
- } else {
- LLDB_LOGF(log,
- "error: Unable to resolve address at file address 0x%" PRIx64
- " for %s:%d\n",
- line_start.GetFileAddress(),
- m_src_location_spec.GetFileSpec().GetFilename().AsCString(
- "<Unknown>"),
- m_src_location_spec.GetLine().value_or(0));
- }
+ for (const auto &sc : sc_list) {
+ Address line_start = sc.line_entry.range.GetBaseAddress();
+ addr_t byte_size = sc.line_entry.range.GetByteSize();
+ if (line_start.IsValid()) {
+ AddressRange new_range(line_start, byte_size);
+ m_address_ranges.push_back(new_range);
+ } else {
+ LLDB_LOGF(log,
+ "error: Unable to resolve address at file address 0x%" PRIx64
+ " for %s:%d\n",
+ line_start.GetFileAddress(),
+ m_src_location_spec.GetFileSpec().GetFilename().AsCString(
+ "<Unknown>"),
+ m_src_location_spec.GetLine().value_or(0));
}
}
return Searcher::eCallbackReturnContinue;
Index: lldb/source/Commands/CommandObjectTarget.cpp
===================================================================
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -957,29 +957,21 @@
compile_units.GetFileSpecAtIndex(cu_idx), sc_list);
}
- const uint32_t num_scs = sc_list.GetSize();
- if (num_scs > 0) {
- SymbolContext sc;
- for (uint32_t sc_idx = 0; sc_idx < num_scs; ++sc_idx) {
- if (sc_list.GetContextAtIndex(sc_idx, sc)) {
- if (sc.comp_unit) {
- const bool can_create = true;
- VariableListSP comp_unit_varlist_sp(
- sc.comp_unit->GetVariableList(can_create));
- if (comp_unit_varlist_sp)
- DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp,
- s);
- } else if (sc.module_sp) {
- // Get all global variables for this module
- lldb_private::RegularExpression all_globals_regex(
- llvm::StringRef(
- ".")); // Any global with at least one character
- VariableList variable_list;
- sc.module_sp->FindGlobalVariables(all_globals_regex, UINT32_MAX,
- variable_list);
- DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s);
- }
- }
+ for (const auto &sc : sc_list) {
+ if (sc.comp_unit) {
+ const bool can_create = true;
+ VariableListSP comp_unit_varlist_sp(
+ sc.comp_unit->GetVariableList(can_create));
+ if (comp_unit_varlist_sp)
+ DumpGlobalVariableList(m_exe_ctx, sc, *comp_unit_varlist_sp, s);
+ } else if (sc.module_sp) {
+ // Get all global variables for this module
+ lldb_private::RegularExpression all_globals_regex(
+ llvm::StringRef(".")); // Any global with at least one character
+ VariableList variable_list;
+ sc.module_sp->FindGlobalVariables(all_globals_regex, UINT32_MAX,
+ variable_list);
+ DumpGlobalVariableList(m_exe_ctx, sc, variable_list, s);
}
}
}
@@ -1306,22 +1298,22 @@
num_matches = module->ResolveSymbolContextsForFileSpec(
file_spec, 0, false, eSymbolContextCompUnit, sc_list);
- for (uint32_t i = 0; i < num_matches; ++i) {
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(i, sc)) {
- if (i > 0)
- strm << "\n\n";
-
- strm << "Line table for " << sc.comp_unit->GetPrimaryFile() << " in `"
- << module->GetFileSpec().GetFilename() << "\n";
- LineTable *line_table = sc.comp_unit->GetLineTable();
- if (line_table)
- line_table->GetDescription(
- &strm, interpreter.GetExecutionContext().GetTargetPtr(),
- desc_level);
- else
- strm << "No line table";
- }
+ bool first_module = true;
+ for (const auto &sc : sc_list) {
+ if (!first_module)
+ strm << "\n\n";
+
+ strm << "Line table for " << sc.comp_unit->GetPrimaryFile() << " in `"
+ << module->GetFileSpec().GetFilename() << "\n";
+ LineTable *line_table = sc.comp_unit->GetLineTable();
+ if (line_table)
+ line_table->GetDescription(
+ &strm, interpreter.GetExecutionContext().GetTargetPtr(),
+ desc_level);
+ else
+ strm << "No line table";
+
+ first_module = false;
}
}
return num_matches;
@@ -1568,23 +1560,21 @@
}
static void DumpSymbolContextList(ExecutionContextScope *exe_scope,
- Stream &strm, SymbolContextList &sc_list,
+ Stream &strm,
+ const SymbolContextList &sc_list,
bool verbose, bool all_ranges) {
strm.IndentMore();
+ bool first_module = true;
+ for (const auto &sc : sc_list) {
+ if (!first_module)
+ strm.EOL();
- const uint32_t num_matches = sc_list.GetSize();
-
- for (uint32_t i = 0; i < num_matches; ++i) {
- SymbolContext sc;
- if (sc_list.GetContextAtIndex(i, sc)) {
- AddressRange range;
+ AddressRange range;
- sc.GetAddressRange(eSymbolContextEverything, 0, true, range);
+ sc.GetAddressRange(eSymbolContextEverything, 0, true, range);
- DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm);
- if (i != (num_matches - 1))
- strm.EOL();
- }
+ DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm);
+ first_module = false;
}
strm.IndentLess();
}
@@ -3368,16 +3358,13 @@
return false;
}
- size_t num_matches = sc_list.GetSize();
- if (num_matches == 0) {
+ if (sc_list.GetSize() == 0) {
result.AppendErrorWithFormat("no unwind data found that matches '%s'.",
m_options.m_str.c_str());
return false;
}
- for (uint32_t idx = 0; idx < num_matches; idx++) {
- SymbolContext sc;
- sc_list.GetContextAtIndex(idx, sc);
+ for (const auto &sc : sc_list) {
if (sc.symbol == nullptr && sc.function == nullptr)
continue;
if (!sc.module_sp || sc.module_sp->GetObjectFile() == nullptr)
Index: lldb/source/Commands/CommandObjectSource.cpp
===================================================================
--- lldb/source/Commands/CommandObjectSource.cpp
+++ lldb/source/Commands/CommandObjectSource.cpp
@@ -146,10 +146,7 @@
uint32_t num_matches = 0;
// Dump all the line entries for the file in the list.
ConstString last_module_file_name;
- uint32_t num_scs = sc_list.GetSize();
- for (uint32_t i = 0; i < num_scs; ++i) {
- SymbolContext sc;
- sc_list.GetContextAtIndex(i, sc);
+ for (const auto &sc : sc_list) {
if (sc.comp_unit) {
Module *module = sc.module_sp.get();
CompileUnit *cu = sc.comp_unit;
@@ -393,10 +390,7 @@
SymbolContextList sc_list_symbols;
module_list.FindFunctionSymbols(name, eFunctionNameTypeAuto,
sc_list_symbols);
- size_t num_symbol_matches = sc_list_symbols.GetSize();
- for (size_t i = 0; i < num_symbol_matches; i++) {
- SymbolContext sc;
- sc_list_symbols.GetContextAtIndex(i, sc);
+ for (const auto &sc : sc_list_symbols) {
if (sc.symbol && sc.symbol->ValueIsAddress()) {
const Address &base_address = sc.symbol->GetAddressRef();
Function *function = base_address.CalculateSymbolContextFunction();
@@ -412,9 +406,7 @@
m_options.symbol_name.c_str());
return false;
}
- for (size_t i = 0; i < num_matches; i++) {
- SymbolContext sc;
- sc_list_funcs.GetContextAtIndex(i, sc);
+ for (const auto &sc : sc_list_funcs) {
bool context_found_for_symbol = false;
// Loop through all the ranges in the function.
AddressRange range;
@@ -926,69 +918,45 @@
// Displaying the source for a symbol. Search for function named name.
FindMatchingFunctions(target, name, sc_list);
- size_t num_matches = sc_list.GetSize();
- if (!num_matches) {
+ if (sc_list.GetSize() == 0) {
// If we didn't find any functions with that name, try searching for
// symbols that line up exactly with function addresses.
SymbolContextList sc_list_symbols;
FindMatchingFunctionSymbols(target, name, sc_list_symbols);
- size_t num_symbol_matches = sc_list_symbols.GetSize();
-
- for (size_t i = 0; i < num_symbol_matches; i++) {
- SymbolContext sc;
- sc_list_symbols.GetContextAtIndex(i, sc);
+ for (const auto &sc : sc_list_symbols) {
if (sc.symbol && sc.symbol->ValueIsAddress()) {
const Address &base_address = sc.symbol->GetAddressRef();
Function *function = base_address.CalculateSymbolContextFunction();
if (function) {
sc_list.Append(SymbolContext(function));
- num_matches++;
break;
}
}
}
}
- if (num_matches == 0) {
+ if (sc_list.GetSize() == 0) {
result.AppendErrorWithFormat("Could not find function named: \"%s\".\n",
m_options.symbol_name.c_str());
return false;
}
- if (num_matches > 1) {
- std::set<SourceInfo> source_match_set;
-
- bool displayed_something = false;
- for (size_t i = 0; i < num_matches; i++) {
- SymbolContext sc;
- sc_list.GetContextAtIndex(i, sc);
- SourceInfo source_info(sc.GetFunctionName(),
- sc.GetFunctionStartLineEntry());
-
- if (source_info.IsValid()) {
- if (source_match_set.find(source_info) == source_match_set.end()) {
- source_match_set.insert(source_info);
- if (DisplayFunctionSource(sc, source_info, result))
- displayed_something = true;
- }
- }
- }
-
- if (displayed_something)
- result.SetStatus(eReturnStatusSuccessFinishResult);
- else
- result.SetStatus(eReturnStatusFailed);
- } else {
- SymbolContext sc;
- sc_list.GetContextAtIndex(0, sc);
- SourceInfo source_info;
-
- if (DisplayFunctionSource(sc, source_info, result)) {
- result.SetStatus(eReturnStatusSuccessFinishResult);
- } else {
- result.SetStatus(eReturnStatusFailed);
+ std::set<SourceInfo> source_match_set;
+ bool displayed_something = false;
+ for (const auto &sc : sc_list) {
+ SourceInfo source_info(sc.GetFunctionName(),
+ sc.GetFunctionStartLineEntry());
+ if (source_info.IsValid() &&
+ source_match_set.find(source_info) == source_match_set.end()) {
+ source_match_set.insert(source_info);
+ if (DisplayFunctionSource(sc, source_info, result))
+ displayed_something = true;
}
}
+ if (displayed_something)
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ else
+ result.SetStatus(eReturnStatusFailed);
return result.Succeeded();
} else if (m_options.address != LLDB_INVALID_ADDRESS) {
Address so_addr;
@@ -1052,10 +1020,7 @@
return false;
}
}
- uint32_t num_matches = sc_list.GetSize();
- for (uint32_t i = 0; i < num_matches; ++i) {
- SymbolContext sc;
- sc_list.GetContextAtIndex(i, sc);
+ for (const auto &sc : sc_list) {
if (sc.comp_unit) {
if (m_options.show_bp_locs) {
m_breakpoint_locations.Clear();
@@ -1175,9 +1140,7 @@
bool got_multiple = false;
CompileUnit *test_cu = nullptr;
- for (unsigned i = 0; i < num_matches; i++) {
- SymbolContext sc;
- sc_list.GetContextAtIndex(i, sc);
+ for (const auto &sc : sc_list) {
if (sc.comp_unit) {
if (test_cu) {
if (test_cu != sc.comp_unit)
Index: lldb/source/Commands/CommandCompletions.cpp
===================================================================
--- lldb/source/Commands/CommandCompletions.cpp
+++ lldb/source/Commands/CommandCompletions.cpp
@@ -220,18 +220,15 @@
function_options.include_inlines = true;
context.module_sp->FindFunctions(m_regex, function_options, sc_list);
- SymbolContext sc;
// Now add the functions & symbols to the list - only add if unique:
- for (uint32_t i = 0; i < sc_list.GetSize(); i++) {
- if (sc_list.GetContextAtIndex(i, sc)) {
- ConstString func_name = sc.GetFunctionName(Mangled::ePreferDemangled);
- // Ensure that the function name matches the regex. This is more than
- // a sanity check. It is possible that the demangled function name
- // does not start with the prefix, for example when it's in an
- // anonymous namespace.
- if (!func_name.IsEmpty() && m_regex.Execute(func_name.GetStringRef()))
- m_match_set.insert(func_name);
- }
+ for (const auto &sc : sc_list) {
+ ConstString func_name = sc.GetFunctionName(Mangled::ePreferDemangled);
+ // Ensure that the function name matches the regex. This is more than
+ // a sanity check. It is possible that the demangled function name
+ // does not start with the prefix, for example when it's in an
+ // anonymous namespace.
+ if (!func_name.IsEmpty() && m_regex.Execute(func_name.GetStringRef()))
+ m_match_set.insert(func_name);
}
}
return Searcher::eCallbackReturnContinue;
Index: lldb/source/Breakpoint/BreakpointResolverName.cpp
===================================================================
--- lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -331,14 +331,7 @@
Address break_addr;
// Remove any duplicates between the function list and the symbol list
- SymbolContext sc;
- if (!func_list.GetSize())
- return Searcher::eCallbackReturnContinue;
-
- for (uint32_t i = 0; i < func_list.GetSize(); i++) {
- if (!func_list.GetContextAtIndex(i, sc))
- continue;
-
+ for (const auto &sc : func_list) {
bool is_reexported = false;
if (sc.block && sc.block->GetInlinedFunctionInfo()) {
Index: lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
===================================================================
--- lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
+++ lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
@@ -192,7 +192,7 @@
}
void BreakpointResolverFileLine::DeduceSourceMapping(
- SymbolContextList &sc_list) {
+ const SymbolContextList &sc_list) {
Target &target = GetBreakpoint()->GetTarget();
if (!target.GetAutoSourceMapRelative())
return;
@@ -223,13 +223,10 @@
return;
const bool case_sensitive = request_file.IsCaseSensitive();
- for (uint32_t i = 0; i < sc_list.GetSize(); ++i) {
- SymbolContext sc;
- sc_list.GetContextAtIndex(i, sc);
-
+ for (const auto &sc : sc_list) {
FileSpec sc_file = sc.line_entry.file;
- if (FileSpec::Equal(sc_file, request_file, /*full*/true))
+ if (FileSpec::Equal(sc_file, request_file, /*full*/ true))
continue;
llvm::StringRef sc_file_dir = sc_file.GetDirectory().GetStringRef();
Index: lldb/source/API/SBThread.cpp
===================================================================
--- lldb/source/API/SBThread.cpp
+++ lldb/source/API/SBThread.cpp
@@ -847,20 +847,14 @@
SymbolContextList sc_list;
frame_sc.comp_unit->ResolveSymbolContext(location_spec,
eSymbolContextLineEntry, sc_list);
- const uint32_t num_matches = sc_list.GetSize();
- if (num_matches > 0) {
- SymbolContext sc;
- for (uint32_t i = 0; i < num_matches; ++i) {
- if (sc_list.GetContextAtIndex(i, sc)) {
- addr_t step_addr =
- sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
- if (step_addr != LLDB_INVALID_ADDRESS) {
- if (fun_range.ContainsLoadAddress(step_addr, target))
- step_over_until_addrs.push_back(step_addr);
- else
- all_in_function = false;
- }
- }
+ for (const auto &sc : sc_list) {
+ addr_t step_addr =
+ sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
+ if (step_addr != LLDB_INVALID_ADDRESS) {
+ if (fun_range.ContainsLoadAddress(step_addr, target))
+ step_over_until_addrs.push_back(step_addr);
+ else
+ all_in_function = false;
}
}
Index: lldb/include/lldb/Symbol/UnwindTable.h
===================================================================
--- lldb/include/lldb/Symbol/UnwindTable.h
+++ lldb/include/lldb/Symbol/UnwindTable.h
@@ -53,7 +53,7 @@
// problem.
lldb::FuncUnwindersSP
GetUncachedFuncUnwindersContainingAddress(const Address &addr,
- SymbolContext &sc);
+ const SymbolContext &sc);
ArchSpec GetArchitecture();
@@ -62,7 +62,7 @@
void Initialize();
std::optional<AddressRange> GetAddressRange(const Address &addr,
- SymbolContext &sc);
+ const SymbolContext &sc);
typedef std::map<lldb::addr_t, lldb::FuncUnwindersSP> collection;
typedef collection::iterator iterator;
Index: lldb/include/lldb/Symbol/SymbolContext.h
===================================================================
--- lldb/include/lldb/Symbol/SymbolContext.h
+++ lldb/include/lldb/Symbol/SymbolContext.h
@@ -451,11 +451,15 @@
protected:
typedef std::vector<SymbolContext>
collection; ///< The collection type for the list.
+ typedef collection::const_iterator const_iterator;
// Member variables.
collection m_symbol_contexts; ///< The list of symbol contexts.
public:
+ const_iterator begin() const { return m_symbol_contexts.begin(); }
+ const_iterator end() const { return m_symbol_contexts.end(); }
+
typedef AdaptedIterable<collection, SymbolContext, vector_adapter>
SymbolContextIterable;
SymbolContextIterable SymbolContexts() {
Index: lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
===================================================================
--- lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
+++ lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
@@ -59,7 +59,7 @@
protected:
void FilterContexts(SymbolContextList &sc_list);
- void DeduceSourceMapping(SymbolContextList &sc_list);
+ void DeduceSourceMapping(const SymbolContextList &sc_list);
friend class Breakpoint;
SourceLocationSpec m_location_spec;
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits