shafik created this revision. shafik added a reviewer: jingham. SBFrame should be a thin wrapper around the core functionality in StackFrame. Currently FindVariable() core functionality is implemented in SBFrame and this will move that into StackFrame.
This is step two in enabling stepping into std::function. https://reviews.llvm.org/D52247 Files: include/lldb/Target/StackFrame.h source/API/SBFrame.cpp source/Target/StackFrame.cpp Index: source/Target/StackFrame.cpp =================================================================== --- source/Target/StackFrame.cpp +++ source/Target/StackFrame.cpp @@ -1709,6 +1709,41 @@ GetFrameCodeAddress()); } +lldb::ValueObjectSP StackFrame::FindVariable(const char *name) { + ValueObjectSP value_sp; + + if (name == nullptr || name[0] == '\0') + 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(ConstString(name)); + } + + if (var_sp) + value_sp = GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); + } + + return value_sp; +} + TargetSP StackFrame::CalculateTarget() { TargetSP target_sp; ThreadSP thread_sp(GetThread()); Index: source/API/SBFrame.cpp =================================================================== --- source/API/SBFrame.cpp +++ source/API/SBFrame.cpp @@ -666,28 +666,10 @@ if (stop_locker.TryLock(&process->GetRunLock())) { frame = exe_ctx.GetFramePtr(); if (frame) { - VariableList variable_list; - SymbolContext sc(frame->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; + value_sp = frame->FindVariable(name); - 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 " Index: include/lldb/Target/StackFrame.h =================================================================== --- include/lldb/Target/StackFrame.h +++ include/lldb/Target/StackFrame.h @@ -503,6 +503,8 @@ lldb::ValueObjectSP GuessValueForRegisterAndOffset(ConstString reg, int64_t offset); + lldb::ValueObjectSP FindVariable(const char *name); + //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------
Index: source/Target/StackFrame.cpp =================================================================== --- source/Target/StackFrame.cpp +++ source/Target/StackFrame.cpp @@ -1709,6 +1709,41 @@ GetFrameCodeAddress()); } +lldb::ValueObjectSP StackFrame::FindVariable(const char *name) { + ValueObjectSP value_sp; + + if (name == nullptr || name[0] == '\0') + 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(ConstString(name)); + } + + if (var_sp) + value_sp = GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); + } + + return value_sp; +} + TargetSP StackFrame::CalculateTarget() { TargetSP target_sp; ThreadSP thread_sp(GetThread()); Index: source/API/SBFrame.cpp =================================================================== --- source/API/SBFrame.cpp +++ source/API/SBFrame.cpp @@ -666,28 +666,10 @@ if (stop_locker.TryLock(&process->GetRunLock())) { frame = exe_ctx.GetFramePtr(); if (frame) { - VariableList variable_list; - SymbolContext sc(frame->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; + value_sp = frame->FindVariable(name); - 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 " Index: include/lldb/Target/StackFrame.h =================================================================== --- include/lldb/Target/StackFrame.h +++ include/lldb/Target/StackFrame.h @@ -503,6 +503,8 @@ lldb::ValueObjectSP GuessValueForRegisterAndOffset(ConstString reg, int64_t offset); + lldb::ValueObjectSP FindVariable(const char *name); + //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits