diff --git a/lldb/include/lldb/Symbol/VariableList.h b/lldb/include/lldb/Symbol/VariableList.h --- a/lldb/include/lldb/Symbol/VariableList.h +++ b/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: diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp --- a/lldb/source/API/SBFrame.cpp +++ b/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 (const VariableSP &variable_sp : *variable_list) { if (variable_sp) { bool add_variable = false; switch (variable_sp->GetScope()) { diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp --- a/lldb/source/API/SBModule.cpp +++ b/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 (const VariableSP &var_sp : variable_list) { + lldb::ValueObjectSP valobj_sp; + TargetSP target_sp(target.GetSP()); + valobj_sp = ValueObjectVariable::Create(target_sp.get(), var_sp); + if (valobj_sp) + sb_value_list.Append(SBValue(valobj_sp)); } } diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp --- a/lldb/source/API/SBTarget.cpp +++ b/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 (const VariableSP &var_sp : variable_list) { + lldb::ValueObjectSP valobj_sp( + ValueObjectVariable::Create(exe_scope, var_sp)); 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 (const VariableSP &var_sp : variable_list) { + lldb::ValueObjectSP valobj_sp( + ValueObjectVariable::Create(exe_scope, var_sp)); if (valobj_sp) sb_value_list.Append(SBValue(valobj_sp)); } diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/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()); } } diff --git a/lldb/source/Core/Address.cpp b/lldb/source/Core/Address.cpp --- a/lldb/source/Core/Address.cpp +++ b/lldb/source/Core/Address.cpp @@ -712,22 +712,20 @@ [](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(); - if (var && var->LocationIsValidForAddress(*this)) { + for (const VariableSP &var_sp : variable_list) { + if (var_sp && var_sp->LocationIsValidForAddress(*this)) { s->Indent(); s->Printf(" Variable: id = {0x%8.8" PRIx64 "}, name = \"%s\"", - var->GetID(), var->GetName().GetCString()); - Type *type = var->GetType(); + var_sp->GetID(), var_sp->GetName().GetCString()); + Type *type = var_sp->GetType(); if (type) s->Printf(", type = \"%s\"", type->GetName().GetCString()); else s->PutCString(", type = "); s->PutCString(", location = "); - var->DumpLocationForAddress(s, *this); + var_sp->DumpLocationForAddress(s, *this); s->PutCString(", decl = "); - var->GetDeclaration().DumpStopContext(s, false); + var_sp->GetDeclaration().DumpStopContext(s, false); s->EOL(); } } diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp --- a/lldb/source/Core/IOHandler.cpp +++ b/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 (const VariableSP &local_sp : *locals) { + ValueObjectSP value_sp = + frame->GetValueObjectForFrameVariable(local_sp, use_dynamic); if (value_sp) { ValueObjectSP synthetic_value_sp = value_sp->GetSyntheticValue(); if (synthetic_value_sp) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/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; diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp --- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/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; diff --git a/lldb/source/Symbol/Block.cpp b/lldb/source/Symbol/Block.cpp --- a/lldb/source/Symbol/Block.cpp +++ b/lldb/source/Symbol/Block.cpp @@ -406,11 +406,10 @@ 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); - if (filter(variable.get())) { + for (const VariableSP &var_sp : *block_var_list) { + if (filter(var_sp.get())) { num_variables_added++; - variable_list->AddVariable(variable); + variable_list->AddVariable(var_sp); } } } diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp --- a/lldb/source/Symbol/Variable.cpp +++ b/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(); - request.AddCompletion(variable->GetName().AsCString()); - } + for (const VariableSP &var_sp : *variable_list) + request.AddCompletion(var_sp->GetName().AsCString()); } } } @@ -710,17 +707,15 @@ 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 var_sp : *variable_list) { - if (!variable) + if (!var_sp) continue; - const char *variable_name = variable->GetName().AsCString(); + const char *variable_name = var_sp->GetName().AsCString(); if (strstr(variable_name, token.c_str()) == variable_name) { if (strcmp(variable_name, token.c_str()) == 0) { - Type *variable_type = variable->GetType(); + Type *variable_type = var_sp->GetType(); if (variable_type) { CompilerType variable_compiler_type( variable_type->GetForwardCompilerType()); diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp --- a/lldb/source/Target/StackFrame.cpp +++ b/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 (const 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 =