From 0886e5657b696b7955111359664834b65fd28b6d Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Thu, 22 Sep 2011 00:41:11 +0000 Subject: [PATCH] Fixed a problem with the IR interpreter that caused it to generate result variables that were not bound to their underlying data. This allowed the SBValue class to use the interpreter (if possible). Also made sure that any result variables that point to stack allocations in the stack frame of the interpreted expressions do not get live data. llvm-svn: 140285 --- .../lldb/Expression/ClangExpressionDeclMap.h | 7 +++++- lldb/source/API/SBValue.cpp | 2 +- .../Expression/ClangExpressionDeclMap.cpp | 25 +++++++++++++------ lldb/source/Expression/IRInterpreter.cpp | 7 +++++- .../formatters/TestFormatters.py | 4 --- .../TestDataFormatterObjC.py | 2 -- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lldb/include/lldb/Expression/ClangExpressionDeclMap.h b/lldb/include/lldb/Expression/ClangExpressionDeclMap.h index 3b74db988823..dcea151eba8d 100644 --- a/lldb/include/lldb/Expression/ClangExpressionDeclMap.h +++ b/lldb/include/lldb/Expression/ClangExpressionDeclMap.h @@ -463,6 +463,10 @@ public: /// @param[in] type /// The type of the data. /// + /// @param[in] transient + /// True if the data should be treated as disappearing after the + /// expression completes. In that case, it gets no live data. + /// /// @return /// True on success; false otherwise. //------------------------------------------------------------------ @@ -470,7 +474,8 @@ public: CompleteResultVariable (lldb::ClangExpressionVariableSP &valobj, lldb_private::Value &value, const ConstString &name, - lldb_private::TypeFromParser type); + lldb_private::TypeFromParser type, + bool transient); //------------------------------------------------------------------ /// [Used by CommandObjectExpression] Materialize the entire struct diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index f1905856e2af..37a524495e70 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -379,7 +379,7 @@ SBValue::CreateValueFromExpression (const char *name, const char* expression) ValueObjectSP result_valobj_sp; m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression, m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame(), - eExecutionPolicyAlways, + eExecutionPolicyOnlyWhenNeeded, true, // unwind on error true, // keep in memory eNoDynamicValues, diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp index 1af41b536a4c..763546b589fe 100644 --- a/lldb/source/Expression/ClangExpressionDeclMap.cpp +++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp @@ -320,7 +320,8 @@ bool ClangExpressionDeclMap::CompleteResultVariable (lldb::ClangExpressionVariableSP &valobj, lldb_private::Value &value, const ConstString &name, - lldb_private::TypeFromParser type) + lldb_private::TypeFromParser type, + bool transient) { assert (m_parser_vars.get()); @@ -330,7 +331,8 @@ ClangExpressionDeclMap::CompleteResultVariable (lldb::ClangExpressionVariableSP return false; if (pvar_sp->m_flags & ClangExpressionVariable::EVIsProgramReference && - !pvar_sp->m_live_sp) + !pvar_sp->m_live_sp && + !transient) { // The reference comes from the program. We need to set up a live SP for it. @@ -927,11 +929,20 @@ ClangExpressionDeclMap::LookupDecl (clang::NamedDecl *decl) } else if (persistent_var_sp) { - lldb_private::Value ret; - ret.SetValueType(Value::eValueTypeHostAddress); - ret.SetContext(Value::eContextTypeInvalid, NULL); - ret.GetScalar() = (lldb::addr_t)persistent_var_sp->GetValueBytes(); - return ret; + if ((persistent_var_sp->m_flags & ClangExpressionVariable::EVIsProgramReference || + persistent_var_sp->m_flags & ClangExpressionVariable::EVIsLLDBAllocated) && + persistent_var_sp->m_live_sp) + { + return persistent_var_sp->m_live_sp->GetValue(); + } + else + { + lldb_private::Value ret; + ret.SetValueType(Value::eValueTypeHostAddress); + ret.SetContext(Value::eContextTypeInvalid, NULL); + ret.GetScalar() = (lldb::addr_t)persistent_var_sp->GetValueBytes(); + return ret; + } } else { diff --git a/lldb/source/Expression/IRInterpreter.cpp b/lldb/source/Expression/IRInterpreter.cpp index 02462457ca18..6ae1841c0878 100644 --- a/lldb/source/Expression/IRInterpreter.cpp +++ b/lldb/source/Expression/IRInterpreter.cpp @@ -717,6 +717,8 @@ public: lldb_private::Value base; + bool transient = false; + if (m_decl_map.ResultIsReference(result_name)) { PointerType *R_ptr_ty = dyn_cast(R_ty); @@ -737,6 +739,9 @@ public: if (!R_final.m_allocation) return false; + if (R_final.m_allocation->m_data) + transient = true; // this is a stack allocation + base = R_final.m_allocation->m_origin; base.GetScalar() += (R_final.m_base - R_final.m_allocation->m_virtual_address); } @@ -747,7 +752,7 @@ public: base.GetScalar() = (unsigned long long)R.m_allocation->m_data->GetBytes() + (R.m_base - R.m_allocation->m_virtual_address); } - return m_decl_map.CompleteResultVariable (result, base, result_name, result_type); + return m_decl_map.CompleteResultVariable (result, base, result_name, result_type, transient); } }; diff --git a/lldb/test/expression_command/formatters/TestFormatters.py b/lldb/test/expression_command/formatters/TestFormatters.py index 0a6ab7b058c1..027191b681ef 100644 --- a/lldb/test/expression_command/formatters/TestFormatters.py +++ b/lldb/test/expression_command/formatters/TestFormatters.py @@ -18,16 +18,12 @@ class ExprFormattersTestCase(TestBase): self.line = line_number('main.cpp', '// Stop here') - # rdar://problem/10153585 lldb ToT regression of test suite with r139772 check-in - @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") def test_with_dsym(self): """Test expr + formatters for good interoperability.""" self.buildDsym() self.do_my_test() - # rdar://problem/10153585 lldb ToT regression of test suite with r139772 check-in - @unittest2.expectedFailure def test_with_dwarf_(self): """Test expr + formatters for good interoperability.""" self.buildDsym() diff --git a/lldb/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py b/lldb/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py index 7100b8677d6d..b34c83c33ffa 100644 --- a/lldb/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py +++ b/lldb/test/functionalities/data-formatter/data-formatter-objc/TestDataFormatterObjC.py @@ -12,7 +12,6 @@ class ObjCDataFormatterTestCase(TestBase): mydir = os.path.join("functionalities", "data-formatter", "data-formatter-objc") # rdar://problem/10153585 lldb ToT regression of test suite with r139772 check-in - @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") def test_with_dsym_and_run_command(self): """Test data formatter commands.""" @@ -20,7 +19,6 @@ class ObjCDataFormatterTestCase(TestBase): self.data_formatter_commands() # rdar://problem/10153585 lldb ToT regression of test suite with r139772 check-in - @unittest2.expectedFailure def test_with_dwarf_and_run_command(self): """Test data formatter commands.""" self.buildDwarf()