Re-land "[lldb] Expose a const iterator for SymbolContextList"

Re-lands 04aa943be8 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.
This commit is contained in:
Alex Langford
2023-05-04 18:19:15 -07:00
parent 9c377c53da
commit e9eaf7b430
20 changed files with 216 additions and 358 deletions

View File

@@ -59,7 +59,7 @@ public:
protected:
void FilterContexts(SymbolContextList &sc_list);
void DeduceSourceMapping(SymbolContextList &sc_list);
void DeduceSourceMapping(const SymbolContextList &sc_list);
friend class Breakpoint;
SourceLocationSpec m_location_spec;

View File

@@ -451,11 +451,15 @@ public:
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() {

View File

@@ -53,7 +53,7 @@ public:
// problem.
lldb::FuncUnwindersSP
GetUncachedFuncUnwindersContainingAddress(const Address &addr,
SymbolContext &sc);
const SymbolContext &sc);
ArchSpec GetArchitecture();
@@ -62,7 +62,7 @@ private:
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;

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -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()) {

View File

@@ -220,18 +220,15 @@ public:
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;

View File

@@ -146,10 +146,7 @@ protected:
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 @@ protected:
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 @@ protected:
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 @@ protected:
// 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 @@ protected:
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 @@ protected:
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)

View File

@@ -957,29 +957,21 @@ protected:
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";
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";
}
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();
AddressRange 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);
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 @@ protected:
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)

View File

@@ -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;

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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();
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());
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);
}
}
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);
}
}
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;
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;
}
}
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;
}
}
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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);