From d41f032a450b71c33dce5f37f08ee92e2a1b8e4f Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Tue, 2 Aug 2011 23:35:43 +0000 Subject: [PATCH] Fixed an issue where StackFrame::GetValueForVariableExpressionPath(...) was previously using the entire frame variable list instead of using the in scope variable list. I added a new function to a stack frame: lldb::VariableListSP StackFrame::GetInScopeVariableList (bool get_file_globals); This gets only variables that are in scope and they will be ordered such that the variables from the current scope are first. llvm-svn: 136745 --- lldb/include/lldb/Target/StackFrame.h | 3 +++ lldb/source/Target/StackFrame.cpp | 33 ++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lldb/include/lldb/Target/StackFrame.h b/lldb/include/lldb/Target/StackFrame.h index 4dd04c3d9c9e..d7d13fcfd0a2 100644 --- a/lldb/include/lldb/Target/StackFrame.h +++ b/lldb/include/lldb/Target/StackFrame.h @@ -101,6 +101,9 @@ public: VariableList * GetVariableList (bool get_file_globals); + lldb::VariableListSP + GetInScopeVariableList (bool get_file_globals); + // See ExpressionPathOption enumeration for "options" values lldb::ValueObjectSP GetValueForVariableExpressionPath (const char *var_expr, diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp index 48055d075e72..803e49b6a967 100644 --- a/lldb/source/Target/StackFrame.cpp +++ b/lldb/source/Target/StackFrame.cpp @@ -485,6 +485,34 @@ StackFrame::GetVariableList (bool get_file_globals) return m_variable_list_sp.get(); } +VariableListSP +StackFrame::GetInScopeVariableList (bool get_file_globals) +{ + VariableListSP var_list_sp(new VariableList); + GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock); + + if (m_sc.block) + { + const bool can_create = true; + const bool get_parent_variables = true; + const bool stop_if_block_is_inlined_function = true; + m_sc.block->AppendVariables (can_create, + get_parent_variables, + stop_if_block_is_inlined_function, + var_list_sp.get()); + } + + if (m_sc.comp_unit) + { + VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); + if (global_variable_list_sp) + var_list_sp->AddVariables (global_variable_list_sp.get()); + } + + return var_list_sp; +} + + ValueObjectSP StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, lldb::DynamicValueType use_dynamic, @@ -502,7 +530,10 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, bool address_of = false; ValueObjectSP valobj_sp; const bool get_file_globals = true; - VariableList *variable_list = GetVariableList (get_file_globals); + // When looking up a variable for an expression, we need only consider the + // variables that are in scope. + VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals)); + VariableList *variable_list = var_list_sp.get(); if (variable_list) {