aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Commands')
-rw-r--r--lldb/source/Commands/CommandCompletions.cpp19
-rw-r--r--lldb/source/Commands/CommandObjectSource.cpp81
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp99
3 files changed, 73 insertions, 126 deletions
diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp
index ae1ee1f..f7d8e68 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -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;
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)
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 0a1cacf..e3bb7fc 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -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";
-
- 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 @@ 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)