[Lldb-commits] [lldb] e9eaf7b - Re-land "[lldb] Expose a const iterator for SymbolContextList"
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Fri May 5 11:27:44 PDT 2023
Author: Alex Langford
Date: 2023-05-05T11:19:21-07:00
New Revision: e9eaf7b430ee69e8ef145884cbc8fa3ef8bd3237
URL: https://github.com/llvm/llvm-project/commit/e9eaf7b430ee69e8ef145884cbc8fa3ef8bd3237
DIFF: https://github.com/llvm/llvm-project/commit/e9eaf7b430ee69e8ef145884cbc8fa3ef8bd3237.diff
LOG: Re-land "[lldb] Expose a const iterator for SymbolContextList"
Re-lands 04aa943be8ed5c03092e2a90112ac638360ec253 with modifications
to fix tests.
I originally reverted this because it caused a test to fail on Linux.
The problem was that I inverted a condition on accident.
Added:
Modified:
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
Removed:
################################################################################
diff --git a/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h b/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
index 5864a284d6f1e..3747e6d2d9a22 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointResolverFileLine.h
@@ -59,7 +59,7 @@ class BreakpointResolverFileLine : public BreakpointResolver {
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
index 73fa25514aff3..68bef70f3bcfe 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -451,11 +451,15 @@ class SymbolContextList {
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() {
diff --git a/lldb/include/lldb/Symbol/UnwindTable.h b/lldb/include/lldb/Symbol/UnwindTable.h
index a3026504dbdfe..f0ce7047de2d1 100644
--- a/lldb/include/lldb/Symbol/UnwindTable.h
+++ b/lldb/include/lldb/Symbol/UnwindTable.h
@@ -53,7 +53,7 @@ class UnwindTable {
// problem.
lldb::FuncUnwindersSP
GetUncachedFuncUnwindersContainingAddress(const Address &addr,
- SymbolContext &sc);
+ const SymbolContext &sc);
ArchSpec GetArchitecture();
@@ -62,7 +62,7 @@ class UnwindTable {
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;
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index ef8a0ab8f9d46..35cc45d79c57a 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -847,20 +847,14 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame,
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
index 890b38af5c88d..04374decd3635 100644
--- a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
@@ -192,7 +192,7 @@ void BreakpointResolverFileLine::FilterContexts(SymbolContextList &sc_list) {
}
void BreakpointResolverFileLine::DeduceSourceMapping(
- SymbolContextList &sc_list) {
+ const SymbolContextList &sc_list) {
Target &target = GetBreakpoint()->GetTarget();
if (!target.GetAutoSourceMapRelative())
return;
@@ -223,13 +223,10 @@ void BreakpointResolverFileLine::DeduceSourceMapping(
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
index dbaeec9c9afb9..d7cff7f17a808 100644
--- a/lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -331,14 +331,7 @@ BreakpointResolverName::SearchCallback(SearchFilter &filter,
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
index 53a3f966a6c79..a3c9cf78dfe1a 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -220,18 +220,15 @@ class SymbolCompleter : public Completer {
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
index 44561cfd736e7..bbc3142c51be6 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -146,10 +146,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
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 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
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 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
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 @@ class CommandObjectSourceList : public CommandObjectParsed {
// 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<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 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 @@ class CommandObjectSourceList : public CommandObjectParsed {
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 @@ class CommandObjectSourceList : public CommandObjectParsed {
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
index 0a1cacfaf7509..e3bb7fc06ed1a 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -957,29 +957,21 @@ class CommandObjectTargetVariable : public CommandObjectParsed {
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 @@ static uint32_t DumpCompileUnitLineTable(CommandInterpreter &interpreter,
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 uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
}
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 @@ class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
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
index 8152a57644fa4..6ab3b8fcee154 100644
--- a/lldb/source/Core/AddressResolverFileLine.cpp
+++ b/lldb/source/Core/AddressResolverFileLine.cpp
@@ -45,24 +45,20 @@ AddressResolverFileLine::SearchCallback(SearchFilter &filter,
// 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 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(
+ "<Unknown>"),
+ 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
index e0eb327223b57..b8460383f0f3c 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/source/Core/SourceManager.cpp
@@ -359,10 +359,7 @@ bool SourceManager::GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line) {
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 @@ void SourceManager::File::CommonInitializer(const FileSpec &file_spec,
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
index 1834402bb2b1f..96c94535c623c 100644
--- a/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
@@ -420,21 +420,17 @@ DynamicLoaderHexagonDYLD::GetStepThroughTrampolinePlan(Thread &thread,
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 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
index a72d888c51e71..6506d000668e9 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -888,53 +888,37 @@ DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread,
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 @@ DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread,
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
index 13a6ffa78a6e1..b4b38a88e1b9c 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -511,21 +511,17 @@ DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread,
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 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
index 76cbfc4c05f82..5d7e1252038da 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1036,12 +1036,7 @@ void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) {
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 @@ void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) {
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
index d478b0838f068..daab7be4b58b9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -531,15 +531,11 @@ addr_t ClangExpressionDeclMap::GetSymbolAddress(Target &target,
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 @@ SymbolContextList ClangExpressionDeclMap::SearchFunctionsInSymbolContexts(
// 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 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 @@ void ClangExpressionDeclMap::LookupFunction(
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 @@ void ClangExpressionDeclMap::LookupFunction(
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
index 0501c5bd0ce04..d43401c46a7a9 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4028,52 +4028,45 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups(
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
index ee42df9e4d469..26b4c4d62ad9c 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -488,15 +488,9 @@ Symbol *Symbol::ResolveReExportedSymbolInModuleSpec(
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
index 0a00802f064b9..f2d88b6dc46be 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -771,14 +771,11 @@ const Symbol *SymbolContext::FindBestGlobalDataSymbol(ConstString name,
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 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
index 268f95f71eb47..3c1a5187b1105 100644
--- a/lldb/source/Symbol/UnwindTable.cpp
+++ b/lldb/source/Symbol/UnwindTable.cpp
@@ -86,8 +86,8 @@ void UnwindTable::Initialize() {
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 @@ UnwindTable::GetFuncUnwindersContainingAddress(const Address &addr,
// 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);
More information about the lldb-commits
mailing list