Index: lldb/include/lldb/Symbol/VariableList.h =================================================================== --- lldb/include/lldb/Symbol/VariableList.h +++ lldb/include/lldb/Symbol/VariableList.h @@ -16,6 +16,8 @@ namespace lldb_private { class VariableList { + typedef std::vector collection; + public: // Constructors and Destructors // VariableList(const SymbolContext &symbol_context); @@ -65,11 +67,15 @@ size_t GetSize() const; bool Empty() const { return m_variables.empty(); } -protected: - typedef std::vector collection; typedef collection::iterator iterator; typedef collection::const_iterator const_iterator; + iterator begin() { return m_variables.begin(); } + iterator end() { return m_variables.end(); } + const_iterator begin() const { return m_variables.begin(); } + const_iterator end() const { return m_variables.end(); } + +protected: collection m_variables; private: Index: lldb/source/API/SBFrame.cpp =================================================================== --- lldb/source/API/SBFrame.cpp +++ lldb/source/API/SBFrame.cpp @@ -831,14 +831,12 @@ if (stop_locker.TryLock(&process->GetRunLock())) { frame = exe_ctx.GetFramePtr(); if (frame) { - size_t i; VariableList *variable_list = nullptr; variable_list = frame->GetVariableList(true); if (variable_list) { const size_t num_variables = variable_list->GetSize(); if (num_variables) { - for (i = 0; i < num_variables; ++i) { - VariableSP variable_sp(variable_list->GetVariableAtIndex(i)); + for (VariableSP variable_sp : *variable_list) { if (variable_sp) { bool add_variable = false; switch (variable_sp->GetScope()) { Index: lldb/source/API/SBModule.cpp =================================================================== --- lldb/source/API/SBModule.cpp +++ lldb/source/API/SBModule.cpp @@ -419,16 +419,12 @@ VariableList variable_list; module_sp->FindGlobalVariables(ConstString(name), nullptr, max_matches, variable_list); - const uint32_t match_count = variable_list.GetSize(); - if (match_count > 0) { - for (uint32_t i = 0; i < match_count; ++i) { - lldb::ValueObjectSP valobj_sp; - TargetSP target_sp(target.GetSP()); - valobj_sp = ValueObjectVariable::Create( - target_sp.get(), variable_list.GetVariableAtIndex(i)); - if (valobj_sp) - sb_value_list.Append(SBValue(valobj_sp)); - } + for (VariableSP var : variable_list) { + lldb::ValueObjectSP valobj_sp; + TargetSP target_sp(target.GetSP()); + valobj_sp = ValueObjectVariable::Create(target_sp.get(), var); + if (valobj_sp) + sb_value_list.Append(SBValue(valobj_sp)); } } Index: lldb/source/API/SBTarget.cpp =================================================================== --- lldb/source/API/SBTarget.cpp +++ lldb/source/API/SBTarget.cpp @@ -1929,14 +1929,13 @@ VariableList variable_list; target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches, variable_list); - const uint32_t match_count = variable_list.GetSize(); - if (match_count > 0) { + if (!variable_list.Empty()) { ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); if (exe_scope == nullptr) exe_scope = target_sp.get(); - for (uint32_t i = 0; i < match_count; ++i) { - lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create( - exe_scope, variable_list.GetVariableAtIndex(i))); + for (VariableSP var : variable_list) { + lldb::ValueObjectSP valobj_sp( + ValueObjectVariable::Create(exe_scope, var)); if (valobj_sp) sb_value_list.Append(SBValue(valobj_sp)); } @@ -1961,7 +1960,6 @@ VariableList variable_list; std::string regexstr; - uint32_t match_count; switch (matchtype) { case eMatchTypeNormal: target_sp->GetImages().FindGlobalVariables(ConstString(name), max_matches, @@ -1977,14 +1975,13 @@ max_matches, variable_list); break; } - match_count = variable_list.GetSize(); - if (match_count > 0) { + if (!variable_list.Empty()) { ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); if (exe_scope == nullptr) exe_scope = target_sp.get(); - for (uint32_t i = 0; i < match_count; ++i) { - lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create( - exe_scope, variable_list.GetVariableAtIndex(i))); + for (VariableSP var : variable_list) { + lldb::ValueObjectSP valobj_sp( + ValueObjectVariable::Create(exe_scope, var)); if (valobj_sp) sb_value_list.Append(SBValue(valobj_sp)); } Index: lldb/source/Commands/CommandObjectTarget.cpp =================================================================== --- lldb/source/Commands/CommandObjectTarget.cpp +++ lldb/source/Commands/CommandObjectTarget.cpp @@ -812,32 +812,29 @@ void DumpGlobalVariableList(const ExecutionContext &exe_ctx, const SymbolContext &sc, const VariableList &variable_list, Stream &s) { - size_t count = variable_list.GetSize(); - if (count > 0) { - if (sc.module_sp) { - if (sc.comp_unit) { - s.Printf("Global variables for %s in %s:\n", - sc.comp_unit->GetPath().c_str(), - sc.module_sp->GetFileSpec().GetPath().c_str()); - } else { - s.Printf("Global variables for %s\n", - sc.module_sp->GetFileSpec().GetPath().c_str()); - } - } else if (sc.comp_unit) { - s.Printf("Global variables for %s\n", sc.comp_unit->GetPath().c_str()); + if (variable_list.Empty()) + return; + if (sc.module_sp) { + if (sc.comp_unit) { + s.Printf("Global variables for %s in %s:\n", + sc.comp_unit->GetPath().c_str(), + sc.module_sp->GetFileSpec().GetPath().c_str()); + } else { + s.Printf("Global variables for %s\n", + sc.module_sp->GetFileSpec().GetPath().c_str()); } + } else if (sc.comp_unit) { + s.Printf("Global variables for %s\n", sc.comp_unit->GetPath().c_str()); + } - for (uint32_t i = 0; i < count; ++i) { - VariableSP var_sp(variable_list.GetVariableAtIndex(i)); - if (var_sp) { - ValueObjectSP valobj_sp(ValueObjectVariable::Create( - exe_ctx.GetBestExecutionContextScope(), var_sp)); + for (VariableSP var_sp : variable_list) { + if (!var_sp) + continue; + ValueObjectSP valobj_sp(ValueObjectVariable::Create( + exe_ctx.GetBestExecutionContextScope(), var_sp)); - if (valobj_sp) - DumpValueObject(s, var_sp, valobj_sp, - var_sp->GetName().GetCString()); - } - } + if (valobj_sp) + DumpValueObject(s, var_sp, valobj_sp, var_sp->GetName().GetCString()); } } Index: lldb/source/Core/Address.cpp =================================================================== --- lldb/source/Core/Address.cpp +++ lldb/source/Core/Address.cpp @@ -712,9 +712,7 @@ [](Variable *) { return true; }, &variable_list); - const size_t num_variables = variable_list.GetSize(); - for (size_t var_idx = 0; var_idx < num_variables; ++var_idx) { - Variable *var = variable_list.GetVariableAtIndex(var_idx).get(); + for (VariableSP var : variable_list) { if (var && var->LocationIsValidForAddress(*this)) { s->Indent(); s->Printf(" Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\"", Index: lldb/source/Core/IOHandler.cpp =================================================================== --- lldb/source/Core/IOHandler.cpp +++ lldb/source/Core/IOHandler.cpp @@ -3002,10 +3002,9 @@ VariableList *locals = frame->GetVariableList(true); if (locals) { const DynamicValueType use_dynamic = eDynamicDontRunTarget; - const size_t num_locals = locals->GetSize(); - for (size_t i = 0; i < num_locals; ++i) { - ValueObjectSP value_sp = frame->GetValueObjectForFrameVariable( - locals->GetVariableAtIndex(i), use_dynamic); + for (VariableSP local : *locals) { + ValueObjectSP value_sp = + frame->GetValueObjectForFrameVariable(local, use_dynamic); if (value_sp) { ValueObjectSP synthetic_value_sp = value_sp->GetSyntheticValue(); if (synthetic_value_sp) Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp =================================================================== --- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -648,9 +648,7 @@ if (vars.GetSize()) { if (type) { - for (size_t i = 0; i < vars.GetSize(); ++i) { - VariableSP var_sp = vars.GetVariableAtIndex(i); - + for (VariableSP var_sp : vars) { if (ClangASTContext::AreTypesSame( *type, var_sp->GetType()->GetFullCompilerType())) return var_sp; Index: lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp =================================================================== --- lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp @@ -2240,8 +2240,7 @@ // Iterate over all the global variables looking for one with a matching type // to the Element. We make the assumption a match exists since there needs to // be a global variable to reflect the struct type back into java host code. - for (uint32_t i = 0; i < var_list.GetSize(); ++i) { - const VariableSP var_sp(var_list.GetVariableAtIndex(i)); + for (const VariableSP var_sp : var_list) { if (!var_sp) continue; Index: lldb/source/Symbol/Block.cpp =================================================================== --- lldb/source/Symbol/Block.cpp +++ lldb/source/Symbol/Block.cpp @@ -406,8 +406,7 @@ uint32_t num_variables_added = 0; VariableList *block_var_list = GetBlockVariableList(can_create).get(); if (block_var_list) { - for (size_t i = 0; i < block_var_list->GetSize(); ++i) { - VariableSP variable = block_var_list->GetVariableAtIndex(i); + for (VariableSP variable : *block_var_list) { if (filter(variable.get())) { num_variables_added++; variable_list->AddVariable(variable); Index: lldb/source/Symbol/Variable.cpp =================================================================== --- lldb/source/Symbol/Variable.cpp +++ lldb/source/Symbol/Variable.cpp @@ -609,11 +609,8 @@ VariableList *variable_list = frame->GetVariableList(get_file_globals); if (variable_list) { - const size_t num_variables = variable_list->GetSize(); - for (size_t i = 0; i < num_variables; ++i) { - Variable *variable = variable_list->GetVariableAtIndex(i).get(); + for (VariableSP variable : *variable_list) request.AddCompletion(variable->GetName().AsCString()); - } } } } @@ -710,9 +707,7 @@ if (!variable_list) break; - const size_t num_variables = variable_list->GetSize(); - for (size_t i = 0; i < num_variables; ++i) { - Variable *variable = variable_list->GetVariableAtIndex(i).get(); + for (VariableSP variable : *variable_list) { if (!variable) continue; Index: lldb/source/Target/StackFrame.cpp =================================================================== --- lldb/source/Target/StackFrame.cpp +++ lldb/source/Target/StackFrame.cpp @@ -573,8 +573,7 @@ if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) { // Check if any anonymous unions are there which contain a variable with // the name we need - for (size_t i = 0; i < variable_list->GetSize(); i++) { - VariableSP variable_sp = variable_list->GetVariableAtIndex(i); + for (VariableSP variable_sp : *variable_list) { if (!variable_sp) continue; if (!variable_sp->GetName().IsEmpty()) @@ -1529,11 +1528,9 @@ : Instruction::Operand::BuildDereference( Instruction::Operand::BuildRegister(reg)); - for (size_t vi = 0, ve = variables.GetSize(); vi != ve; ++vi) { - VariableSP var_sp = variables.GetVariableAtIndex(vi); - if (var_sp->LocationExpression().MatchesOperand(frame, op)) { + for (VariableSP var_sp : variables) { + if (var_sp->LocationExpression().MatchesOperand(frame, op)) return frame.GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); - } } const uint32_t current_inst =