Author: shafik Date: Thu Sep 20 10:06:34 2018 New Revision: 342663 URL: http://llvm.org/viewvc/llvm-project?rev=342663&view=rev Log: Refactor FindVariable() core functionality into StackFrame out of SBFrame
rdar://problem/14365983 Patch by Shafik Yaghmour Differential Revision: https://reviews.llvm.org/D52247 Modified: lldb/trunk/include/lldb/Target/StackFrame.h lldb/trunk/source/API/SBFrame.cpp lldb/trunk/source/Target/StackFrame.cpp Modified: lldb/trunk/include/lldb/Target/StackFrame.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StackFrame.h?rev=342663&r1=342662&r2=342663&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/StackFrame.h (original) +++ lldb/trunk/include/lldb/Target/StackFrame.h Thu Sep 20 10:06:34 2018 @@ -504,6 +504,21 @@ public: int64_t offset); //------------------------------------------------------------------ + /// Attempt to reconstruct the ValueObject for a variable with a given \a name + /// from within the current StackFrame, within the current block. The search + /// for the variable starts in the deepest block corresponding to the current + /// PC in the stack frame and traverse through all parent blocks stopping at + /// inlined function boundaries. + /// + /// @params [in] name + /// The name of the variable. + /// + /// @return + /// The ValueObject if found. + //------------------------------------------------------------------ + lldb::ValueObjectSP FindVariable(ConstString name); + + //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ lldb::TargetSP CalculateTarget() override; Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=342663&r1=342662&r2=342663&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Thu Sep 20 10:06:34 2018 @@ -666,28 +666,10 @@ SBValue SBFrame::FindVariable(const char if (stop_locker.TryLock(&process->GetRunLock())) { frame = exe_ctx.GetFramePtr(); if (frame) { - VariableList variable_list; - SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock)); + value_sp = frame->FindVariable(ConstString(name)); - if (sc.block) { - const bool can_create = true; - const bool get_parent_variables = true; - const bool stop_if_block_is_inlined_function = true; - - if (sc.block->AppendVariables( - can_create, get_parent_variables, - stop_if_block_is_inlined_function, - [frame](Variable *v) { return v->IsInScope(frame); }, - &variable_list)) { - var_sp = variable_list.FindVariable(ConstString(name)); - } - } - - if (var_sp) { - value_sp = - frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); + if (value_sp) sb_value.SetSP(value_sp, use_dynamic); - } } else { if (log) log->Printf("SBFrame::FindVariable () => error: could not " Modified: lldb/trunk/source/Target/StackFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=342663&r1=342662&r2=342663&view=diff ============================================================================== --- lldb/trunk/source/Target/StackFrame.cpp (original) +++ lldb/trunk/source/Target/StackFrame.cpp Thu Sep 20 10:06:34 2018 @@ -1709,6 +1709,41 @@ lldb::ValueObjectSP StackFrame::GuessVal GetFrameCodeAddress()); } +lldb::ValueObjectSP StackFrame::FindVariable(ConstString name) { + ValueObjectSP value_sp; + + if (!name) + return value_sp; + + TargetSP target_sp = CalculateTarget(); + ProcessSP process_sp = CalculateProcess(); + + if (!target_sp && !process_sp) + return value_sp; + + VariableList variable_list; + VariableSP var_sp; + SymbolContext sc(GetSymbolContext(eSymbolContextBlock)); + + if (sc.block) { + const bool can_create = true; + const bool get_parent_variables = true; + const bool stop_if_block_is_inlined_function = true; + + if (sc.block->AppendVariables( + can_create, get_parent_variables, stop_if_block_is_inlined_function, + [this](Variable *v) { return v->IsInScope(this); }, + &variable_list)) { + var_sp = variable_list.FindVariable(name); + } + + if (var_sp) + value_sp = GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); + } + + return value_sp; +} + TargetSP StackFrame::CalculateTarget() { TargetSP target_sp; ThreadSP thread_sp(GetThread()); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits