diff options
author | Alex Langford <alangford@apple.com> | 2023-05-04 18:19:15 -0700 |
---|---|---|
committer | Alex Langford <alangford@apple.com> | 2023-05-05 11:19:21 -0700 |
commit | e9eaf7b430ee69e8ef145884cbc8fa3ef8bd3237 (patch) | |
tree | 54729f00ee50f97d280b5a0e7b8b14b2b6c878d3 /lldb/source/Commands/CommandObjectSource.cpp | |
parent | 9c377c53da4771389fbd65e99e1615d99c257bdf (diff) | |
download | llvm-e9eaf7b430ee69e8ef145884cbc8fa3ef8bd3237.zip llvm-e9eaf7b430ee69e8ef145884cbc8fa3ef8bd3237.tar.gz llvm-e9eaf7b430ee69e8ef145884cbc8fa3ef8bd3237.tar.bz2 |
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.
Diffstat (limited to 'lldb/source/Commands/CommandObjectSource.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectSource.cpp | 81 |
1 files changed, 22 insertions, 59 deletions
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index 44561cf..bbc3142 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -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) |