diff --git a/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h b/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h --- a/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h +++ b/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; diff --git a/lldb/include/lldb/Symbol/SymbolContext.h b/lldb/include/lldb/Symbol/SymbolContext.h --- a/lldb/include/lldb/Symbol/SymbolContext.h +++ b/lldb/include/lldb/Symbol/SymbolContext.h @@ -451,11 +451,15 @@ protected: typedef std::vector 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 SymbolContextIterable; SymbolContextIterable SymbolContexts() { diff --git a/lldb/include/lldb/Symbol/UnwindTable.h b/lldb/include/lldb/Symbol/UnwindTable.h --- a/lldb/include/lldb/Symbol/UnwindTable.h +++ b/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 GetAddressRange(const Address &addr, - SymbolContext &sc); + const SymbolContext &sc); typedef std::map collection; typedef collection::iterator iterator; diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp --- a/lldb/source/API/SBThread.cpp +++ b/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 SymbolContext &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; } } diff --git a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp --- a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp +++ b/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 SymbolContext &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(); diff --git a/lldb/source/Breakpoint/BreakpointResolverName.cpp b/lldb/source/Breakpoint/BreakpointResolverName.cpp --- a/lldb/source/Breakpoint/BreakpointResolverName.cpp +++ b/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 SymbolContext &sc : func_list) { bool is_reexported = false; if (sc.block && sc.block->GetInlinedFunctionInfo()) { diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp --- a/lldb/source/Commands/CommandCompletions.cpp +++ b/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 SymbolContext &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; diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/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 SymbolContext &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 SymbolContext &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 SymbolContext &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 SymbolContext &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 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 source_match_set; + bool displayed_something = false; + for (const SymbolContext &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 SymbolContext &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 SymbolContext &sc : sc_list) { if (sc.comp_unit) { if (test_cu) { if (test_cu != sc.comp_unit) diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/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 SymbolContext &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 SymbolContext &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 SymbolContext &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 SymbolContext &sc : sc_list) { if (sc.symbol == nullptr && sc.function == nullptr) continue; if (!sc.module_sp || sc.module_sp->GetObjectFile() == nullptr) diff --git a/lldb/source/Core/AddressResolverFileLine.cpp b/lldb/source/Core/AddressResolverFileLine.cpp --- a/lldb/source/Core/AddressResolverFileLine.cpp +++ b/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( - ""), - m_src_location_spec.GetLine().value_or(0)); - } + for (const SymbolContext &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( + ""), + m_src_location_spec.GetLine().value_or(0)); } } return Searcher::eCallbackReturnContinue; diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp --- a/lldb/source/Core/SourceManager.cpp +++ b/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 SymbolContext &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 SymbolContext &sc : sc_list) { if (sc.comp_unit) { if (test_cu) { if (test_cu != sc.comp_unit) diff --git a/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp b/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp --- a/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp +++ b/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 AddressVector; AddressVector addrs; - for (size_t i = 0; i < num_targets; ++i) { - SymbolContext context; + for (const SymbolContext &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) { diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/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 SymbolContext &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 SymbolContext &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 SymbolContext &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); } } } diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/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 AddressVector; AddressVector addrs; - for (size_t i = 0; i < num_targets; ++i) { - SymbolContext context; + for (const SymbolContext &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) { diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp +++ b/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 SymbolContext &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 SymbolContext &sc : sc_list) { if (!sc.function) continue; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/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 SymbolContext &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 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( frame_decl_context.GetTypeSystem()); - for (uint32_t index = 0; index < num_indices; ++index) { + for (const SymbolContext &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 SymbolContext &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; } } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/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 SymbolContext &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; } } } diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp --- a/lldb/source/Symbol/Symbol.cpp +++ b/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 SymbolContext &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 diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp --- a/lldb/source/Symbol/SymbolContext.cpp +++ b/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 external_symbols; llvm::SmallVector 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 SymbolContext &sym_ctx : sc_list) { if (sym_ctx.symbol) { const Symbol *symbol = sym_ctx.symbol; const Address sym_address = symbol->GetAddress(); diff --git a/lldb/source/Symbol/UnwindTable.cpp b/lldb/source/Symbol/UnwindTable.cpp --- a/lldb/source/Symbol/UnwindTable.cpp +++ b/lldb/source/Symbol/UnwindTable.cpp @@ -86,8 +86,8 @@ UnwindTable::~UnwindTable() = default; -std::optional UnwindTable::GetAddressRange(const Address &addr, - SymbolContext &sc) { +std::optional +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);