[Lldb-commits] [lldb] 3d6073a - Revert "[lldb] Expose a const iterator for SymbolContextList"
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Thu May 4 16:50:05 PDT 2023
Author: Alex Langford
Date: 2023-05-04T16:49:30-07:00
New Revision: 3d6073a9c33005abf8c6fc074e434c90b36dccb9
URL: https://github.com/llvm/llvm-project/commit/3d6073a9c33005abf8c6fc074e434c90b36dccb9
DIFF: https://github.com/llvm/llvm-project/commit/3d6073a9c33005abf8c6fc074e434c90b36dccb9.diff
LOG: Revert "[lldb] Expose a const iterator for SymbolContextList"
This reverts commit 04aa943be8ed5c03092e2a90112ac638360ec253.
This broke the debian buildbot and I'm not sure why. Reverting so I can
investigate.
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 3747e6d2d9a22..5864a284d6f1e 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(const SymbolContextList &sc_list);
+ void DeduceSourceMapping(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 68bef70f3bcfe..73fa25514aff3 100644
--- a/lldb/include/lldb/Symbol/SymbolContext.h
+++ b/lldb/include/lldb/Symbol/SymbolContext.h
@@ -451,15 +451,11 @@ 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 f0ce7047de2d1..a3026504dbdfe 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,
- const SymbolContext &sc);
+ SymbolContext &sc);
ArchSpec GetArchitecture();
@@ -62,7 +62,7 @@ class UnwindTable {
void Initialize();
std::optional<AddressRange> GetAddressRange(const Address &addr,
- const SymbolContext &sc);
+ 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 35cc45d79c57a..ef8a0ab8f9d46 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -847,14 +847,20 @@ SBError SBThread::StepOverUntil(lldb::SBFrame &sb_frame,
SymbolContextList sc_list;
frame_sc.comp_unit->ResolveSymbolContext(location_spec,
eSymbolContextLineEntry, sc_list);
- 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;
+ 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;
+ }
+ }
}
}
diff --git a/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp b/lldb/source/Breakpoint/BreakpointResolverFileLine.cpp
index 04374decd3635..890b38af5c88d 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(
- const SymbolContextList &sc_list) {
+ SymbolContextList &sc_list) {
Target &target = GetBreakpoint()->GetTarget();
if (!target.GetAutoSourceMapRelative())
return;
@@ -223,10 +223,13 @@ void BreakpointResolverFileLine::DeduceSourceMapping(
return;
const bool case_sensitive = request_file.IsCaseSensitive();
- for (const SymbolContext &sc : sc_list) {
+ for (uint32_t i = 0; i < sc_list.GetSize(); ++i) {
+ SymbolContext sc;
+ sc_list.GetContextAtIndex(i, sc);
+
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 d7cff7f17a808..dbaeec9c9afb9 100644
--- a/lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -331,7 +331,14 @@ BreakpointResolverName::SearchCallback(SearchFilter &filter,
Address break_addr;
// Remove any duplicates between the function list and the symbol list
- for (const SymbolContext &sc : func_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;
+
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 f7d8e68c1fabc..ae1ee1fdd30b8 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -220,15 +220,18 @@ 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 (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);
+ 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);
+ }
}
}
return Searcher::eCallbackReturnContinue;
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp
index bbc3142c51be6..44561cfd736e7 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -146,7 +146,10 @@ 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;
- for (const SymbolContext &sc : sc_list) {
+ uint32_t num_scs = sc_list.GetSize();
+ for (uint32_t i = 0; i < num_scs; ++i) {
+ SymbolContext sc;
+ sc_list.GetContextAtIndex(i, sc);
if (sc.comp_unit) {
Module *module = sc.module_sp.get();
CompileUnit *cu = sc.comp_unit;
@@ -390,7 +393,10 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
SymbolContextList sc_list_symbols;
module_list.FindFunctionSymbols(name, eFunctionNameTypeAuto,
sc_list_symbols);
- for (const SymbolContext &sc : 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);
if (sc.symbol && sc.symbol->ValueIsAddress()) {
const Address &base_address = sc.symbol->GetAddressRef();
Function *function = base_address.CalculateSymbolContextFunction();
@@ -406,7 +412,9 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
m_options.symbol_name.c_str());
return false;
}
- for (const SymbolContext &sc : sc_list_funcs) {
+ for (size_t i = 0; i < num_matches; i++) {
+ SymbolContext sc;
+ sc_list_funcs.GetContextAtIndex(i, sc);
bool context_found_for_symbol = false;
// Loop through all the ranges in the function.
AddressRange range;
@@ -918,45 +926,69 @@ class CommandObjectSourceList : public CommandObjectParsed {
// Displaying the source for a symbol. Search for function named name.
FindMatchingFunctions(target, name, sc_list);
- if (sc_list.GetSize() == 0) {
+ size_t num_matches = sc_list.GetSize();
+ if (!num_matches) {
// 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);
- for (const SymbolContext &sc : 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);
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 (sc_list.GetSize() == 0) {
+ if (num_matches == 0) {
result.AppendErrorWithFormat("Could not find function named: \"%s\".\n",
m_options.symbol_name.c_str());
return false;
}
- 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 (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);
}
}
- if (displayed_something)
- result.SetStatus(eReturnStatusSuccessFinishResult);
- else
- result.SetStatus(eReturnStatusFailed);
return result.Succeeded();
} else if (m_options.address != LLDB_INVALID_ADDRESS) {
Address so_addr;
@@ -1020,7 +1052,10 @@ class CommandObjectSourceList : public CommandObjectParsed {
return false;
}
}
- for (const SymbolContext &sc : sc_list) {
+ uint32_t num_matches = sc_list.GetSize();
+ for (uint32_t i = 0; i < num_matches; ++i) {
+ SymbolContext sc;
+ sc_list.GetContextAtIndex(i, sc);
if (sc.comp_unit) {
if (m_options.show_bp_locs) {
m_breakpoint_locations.Clear();
@@ -1140,7 +1175,9 @@ class CommandObjectSourceList : public CommandObjectParsed {
bool got_multiple = false;
CompileUnit *test_cu = nullptr;
- for (const SymbolContext &sc : sc_list) {
+ for (unsigned i = 0; i < num_matches; i++) {
+ SymbolContext sc;
+ sc_list.GetContextAtIndex(i, sc);
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 e3bb7fc06ed1a..0a1cacfaf7509 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -957,21 +957,29 @@ class CommandObjectTargetVariable : public CommandObjectParsed {
compile_units.GetFileSpecAtIndex(cu_idx), sc_list);
}
- 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);
+ 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);
+ }
+ }
}
}
}
@@ -1298,22 +1306,22 @@ static uint32_t DumpCompileUnitLineTable(CommandInterpreter &interpreter,
num_matches = module->ResolveSymbolContextsForFileSpec(
file_spec, 0, false, eSymbolContextCompUnit, sc_list);
- 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;
+ 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";
+ }
}
}
return num_matches;
@@ -1560,21 +1568,23 @@ static uint32_t LookupSymbolInModule(CommandInterpreter &interpreter,
}
static void DumpSymbolContextList(ExecutionContextScope *exe_scope,
- Stream &strm,
- const SymbolContextList &sc_list,
+ Stream &strm, 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();
- AddressRange range;
+ const uint32_t num_matches = sc_list.GetSize();
- sc.GetAddressRange(eSymbolContextEverything, 0, true, range);
+ for (uint32_t i = 0; i < num_matches; ++i) {
+ SymbolContext sc;
+ if (sc_list.GetContextAtIndex(i, sc)) {
+ AddressRange range;
+
+ sc.GetAddressRange(eSymbolContextEverything, 0, true, range);
- DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm);
- first_module = false;
+ DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm);
+ if (i != (num_matches - 1))
+ strm.EOL();
+ }
}
strm.IndentLess();
}
@@ -3358,13 +3368,16 @@ class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
return false;
}
- if (sc_list.GetSize() == 0) {
+ size_t num_matches = sc_list.GetSize();
+ if (num_matches == 0) {
result.AppendErrorWithFormat("no unwind data found that matches '%s'.",
m_options.m_str.c_str());
return false;
}
- for (const SymbolContext &sc : sc_list) {
+ for (uint32_t idx = 0; idx < num_matches; idx++) {
+ SymbolContext sc;
+ sc_list.GetContextAtIndex(idx, sc);
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 6ab3b8fcee154..8152a57644fa4 100644
--- a/lldb/source/Core/AddressResolverFileLine.cpp
+++ b/lldb/source/Core/AddressResolverFileLine.cpp
@@ -45,20 +45,24 @@ AddressResolverFileLine::SearchCallback(SearchFilter &filter,
// TODO: Handle SourceLocationSpec column information
cu->ResolveSymbolContext(m_src_location_spec, eSymbolContextEverything,
sc_list);
- 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));
+ 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));
+ }
}
}
return Searcher::eCallbackReturnContinue;
diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp
index b8460383f0f3c..e0eb327223b57 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/source/Core/SourceManager.cpp
@@ -359,7 +359,10 @@ bool SourceManager::GetDefaultFileAndLine(FileSpec &file_spec, uint32_t &line) {
executable_ptr->FindFunctions(main_name, CompilerDeclContext(),
lldb::eFunctionNameTypeBase,
function_options, sc_list);
- for (const SymbolContext &sc : 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);
if (sc.function) {
lldb_private::LineEntry line_entry;
if (sc.function->GetAddressRange()
@@ -427,8 +430,11 @@ 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 (const SymbolContext &sc : sc_list) {
+
+ for (unsigned i = 0; i < num_matches; i++) {
+ sc_list.GetContextAtIndex(i, sc);
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 96c94535c623c..1834402bb2b1f 100644
--- a/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/DynamicLoaderHexagonDYLD.cpp
@@ -420,17 +420,21 @@ DynamicLoaderHexagonDYLD::GetStepThroughTrampolinePlan(Thread &thread,
const ModuleList &images = target.GetImages();
images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
- if (target_symbols.GetSize() == 0)
+ size_t num_targets = target_symbols.GetSize();
+ if (!num_targets)
return thread_plan_sp;
typedef std::vector<lldb::addr_t> AddressVector;
AddressVector addrs;
- for (const SymbolContext &context : target_symbols) {
+ for (size_t i = 0; i < num_targets; ++i) {
+ SymbolContext context;
AddressRange range;
- context.GetAddressRange(eSymbolContextEverything, 0, false, range);
- lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
- if (addr != LLDB_INVALID_ADDRESS)
- addrs.push_back(addr);
+ 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);
+ }
}
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 6506d000668e9..a72d888c51e71 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -888,37 +888,53 @@ DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread,
SymbolContextList code_symbols;
images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode,
code_symbols);
- 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);
+ 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);
+ }
+ }
}
}
SymbolContextList reexported_symbols;
images.FindSymbolsWithNameAndType(
trampoline_name, eSymbolTypeReExported, reexported_symbols);
- 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);
+ 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);
+ }
+ }
}
}
}
@@ -928,18 +944,24 @@ DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread,
SymbolContextList indirect_symbols;
images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeResolver,
indirect_symbols);
-
- 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);
+ 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);
+ }
+ }
}
}
}
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 3b6ca1ecd6a1b..13a6ffa78a6e1 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -511,17 +511,21 @@ DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread,
const ModuleList &images = target.GetImages();
images.FindSymbolsWithNameAndType(sym_name, eSymbolTypeCode, target_symbols);
- if (target_symbols.GetSize())
+ size_t num_targets = target_symbols.GetSize();
+ if (!num_targets)
return thread_plan_sp;
typedef std::vector<lldb::addr_t> AddressVector;
AddressVector addrs;
- for (const SymbolContext &context : target_symbols) {
+ for (size_t i = 0; i < num_targets; ++i) {
+ SymbolContext context;
AddressRange range;
- context.GetAddressRange(eSymbolContextEverything, 0, false, range);
- lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
- if (addr != LLDB_INVALID_ADDRESS)
- addrs.push_back(addr);
+ 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);
+ }
}
if (addrs.size() > 0) {
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 5d7e1252038da..76cbfc4c05f82 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -1036,7 +1036,12 @@ void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) {
lldb::eFunctionNameTypeSelector,
function_options, candidate_sc_list);
- for (const SymbolContext &candidate_sc : 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;
+
if (!candidate_sc.function)
continue;
@@ -1069,7 +1074,12 @@ void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) {
if (sc_list.GetSize()) {
// We found a good function symbol. Use that.
- for (const SymbolContext &sc : sc_list) {
+ for (uint32_t i = 0, e = sc_list.GetSize(); i != e; ++i) {
+ SymbolContext sc;
+
+ if (!sc_list.GetContextAtIndex(i, sc))
+ continue;
+
if (!sc.function)
continue;
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index daab7be4b58b9..d478b0838f068 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -531,11 +531,15 @@ 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 (const SymbolContext &sym_ctx : sc_list) {
- if (symbol_load_addr != 0 || symbol_load_addr != LLDB_INVALID_ADDRESS)
- break;
+ 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);
const Address sym_address = sym_ctx.symbol->GetAddress();
@@ -1143,16 +1147,19 @@ 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(sc_list.GetSize());
+ decl_infos.reserve(num_indices);
clang::DeclContext *frame_decl_ctx =
(clang::DeclContext *)frame_decl_context.GetOpaqueDeclContext();
TypeSystemClang *ast = llvm::dyn_cast_or_null<TypeSystemClang>(
frame_decl_context.GetTypeSystem());
- for (const SymbolContext &sym_ctx : sc_list) {
+ for (uint32_t index = 0; index < num_indices; ++index) {
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.
@@ -1287,7 +1294,11 @@ void ClangExpressionDeclMap::LookupFunction(
Symbol *extern_symbol = nullptr;
Symbol *non_extern_symbol = nullptr;
- for (const SymbolContext &sym_ctx : sc_list) {
+ for (uint32_t index = 0, num_indices = sc_list.GetSize();
+ index < num_indices; ++index) {
+ SymbolContext sym_ctx;
+ sc_list.GetContextAtIndex(index, sym_ctx);
+
if (sym_ctx.function) {
CompilerDeclContext decl_ctx = sym_ctx.function->GetDeclContext();
@@ -1302,17 +1313,16 @@ void ClangExpressionDeclMap::LookupFunction(
context.m_found_function_with_type_info = true;
context.m_found_function = true;
} else if (sym_ctx.symbol) {
- Symbol *symbol = sym_ctx.symbol;
- if (target && symbol->GetType() == eSymbolTypeReExported) {
- symbol = symbol->ResolveReExportedSymbol(*target);
- if (symbol == nullptr)
+ if (sym_ctx.symbol->GetType() == eSymbolTypeReExported && target) {
+ sym_ctx.symbol = sym_ctx.symbol->ResolveReExportedSymbol(*target);
+ if (sym_ctx.symbol == nullptr)
continue;
}
- if (symbol->IsExternal())
- extern_symbol = symbol;
+ if (sym_ctx.symbol->IsExternal())
+ extern_symbol = sym_ctx.symbol;
else
- non_extern_symbol = symbol;
+ non_extern_symbol = sym_ctx.symbol;
}
}
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index d43401c46a7a9..0501c5bd0ce04 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4028,45 +4028,52 @@ void GDBRemoteCommunicationClient::ServeSymbolLookups(
lldb_private::SymbolContextList sc_list;
process->GetTarget().GetImages().FindSymbolsWithNameAndType(
ConstString(symbol_name), eSymbolTypeAny, sc_list);
- 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;
+ 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;
+ }
+ }
}
}
}
diff --git a/lldb/source/Symbol/Symbol.cpp b/lldb/source/Symbol/Symbol.cpp
index 26b4c4d62ad9c..ee42df9e4d469 100644
--- a/lldb/source/Symbol/Symbol.cpp
+++ b/lldb/source/Symbol/Symbol.cpp
@@ -488,9 +488,15 @@ Symbol *Symbol::ResolveReExportedSymbolInModuleSpec(
lldb_private::SymbolContextList sc_list;
module_sp->FindSymbolsWithNameAndType(reexport_name, eSymbolTypeAny,
sc_list);
- for (const SymbolContext &sc : sc_list) {
- if (sc.symbol->IsExternal())
- return sc.symbol;
+ 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;
+ }
+ }
}
// 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 f2d88b6dc46be..0a00802f064b9 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -771,11 +771,14 @@ const Symbol *SymbolContext::FindBestGlobalDataSymbol(ConstString name,
Module *module = module_sp.get();
auto ProcessMatches = [this, &name, &target,
- module](const SymbolContextList &sc_list,
+ module](SymbolContextList &sc_list,
Status &error) -> const Symbol * {
llvm::SmallVector<const Symbol *, 1> external_symbols;
llvm::SmallVector<const Symbol *, 1> internal_symbols;
- for (const SymbolContext &sym_ctx : sc_list) {
+ const uint32_t matches = sc_list.GetSize();
+ for (uint32_t i = 0; i < matches; ++i) {
+ SymbolContext sym_ctx;
+ sc_list.GetContextAtIndex(i, sym_ctx);
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 3c1a5187b1105..268f95f71eb47 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, const SymbolContext &sc) {
+std::optional<AddressRange> UnwindTable::GetAddressRange(const Address &addr,
+ SymbolContext &sc) {
AddressRange range;
// First check the unwind info from the object file plugin
@@ -150,8 +150,9 @@ 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, const SymbolContext &sc) {
+FuncUnwindersSP
+UnwindTable::GetUncachedFuncUnwindersContainingAddress(const Address &addr,
+ SymbolContext &sc) {
Initialize();
auto range_or = GetAddressRange(addr, sc);
More information about the lldb-commits
mailing list