[Lldb-commits] [lldb] r115589 - in /lldb/trunk: include/lldb/Core/ValueObject.h include/lldb/Core/ValueObjectConstResult.h include/lldb/Expression/ClangUserExpression.h include/lldb/lldb-forward.h source/API/SBFrame.cpp source/Commands/CommandObjectExpression.cpp source/Core/ValueObject.cpp source/Core/ValueObjectConstResult.cpp source/Expression/ClangUserExpression.cpp

Greg Clayton gclayton at apple.com
Mon Oct 4 20:13:51 PDT 2010


Author: gclayton
Date: Mon Oct  4 22:13:51 2010
New Revision: 115589

URL: http://llvm.org/viewvc/llvm-project?rev=115589&view=rev
Log:
Added the notion that a value object can be constant by adding:
    bool ValueObject::GetIsConstant() const;
    void ValueObject::SetIsConstant();

This will stop anything from being re-evaluated within the value object so
that constant result value objects can maintain their frozen values without
anything being updated or changed within the value object.

Made it so the ValueObjectConstResult can be constructed with an 
lldb_private::Error object to allow for expression results to have errors.

Since ValueObject objects contain error objects, I changed the expression
evaluation in ClangUserExpression from 

    static Error
    ClangUserExpression::Evaluate (ExecutionContext &exe_ctx, 
                                  const char *expr_cstr, 
                                  lldb::ValueObjectSP &result_valobj_sp);

to:

    static lldb::ValueObjectSP
    Evaluate (ExecutionContext &exe_ctx, const char *expr_cstr);
    
Even though expression parsing is borked right now (pending fixes coming from
Sean Callanan), I filled in the implementation for:
    
    SBValue SBFrame::EvaluateExpression (const char *expr);
    
Modified all expression code to deal with the above changes.



Modified:
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Core/ValueObjectConstResult.h
    lldb/trunk/include/lldb/Expression/ClangUserExpression.h
    lldb/trunk/include/lldb/lldb-forward.h
    lldb/trunk/source/API/SBFrame.cpp
    lldb/trunk/source/Commands/CommandObjectExpression.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Core/ValueObjectConstResult.cpp
    lldb/trunk/source/Expression/ClangUserExpression.cpp

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Mon Oct  4 22:13:51 2010
@@ -201,6 +201,18 @@
                      bool use_objc,
                      bool scope_already_checked);
 
+    bool
+    GetIsConstant () const
+    {
+        return m_update_id == LLDB_INVALID_UID;
+    }
+    
+    void
+    SetIsConstant ()
+    {
+        m_update_id = LLDB_INVALID_UID;
+    }
+
 protected:
     //------------------------------------------------------------------
     // Classes that inherit from ValueObject can see and modify these

Modified: lldb/trunk/include/lldb/Core/ValueObjectConstResult.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectConstResult.h?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectConstResult.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectConstResult.h Mon Oct  4 22:13:51 2010
@@ -32,6 +32,9 @@
                             uint8_t addr_size);
 
 
+    // When an expression fails to evaluate, we return an error
+    ValueObjectConstResult (const Error& error);
+
     virtual ~ValueObjectConstResult();
 
     virtual size_t

Modified: lldb/trunk/include/lldb/Expression/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUserExpression.h?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangUserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangUserExpression.h Mon Oct  4 22:13:51 2010
@@ -172,10 +172,8 @@
     }
 
 
-    static Error
-    Evaluate (ExecutionContext &exe_ctx, 
-              const char *expr_cstr, 
-              lldb::ValueObjectSP &result_valobj_sp);
+    static lldb::ValueObjectSP
+    Evaluate (ExecutionContext &exe_ctx, const char *expr_cstr);
 
 private:
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Mon Oct  4 22:13:51 2010
@@ -43,6 +43,7 @@
 class   ClangASTContext;
 class   ClangExpression;
 class   ClangExpressionDeclMap;
+class   ClangExpressionVariable;
 class   ClangExpressionVariableList;
 class   ClangExpressionVariableStore;
 class   CommandInterpreter;

Modified: lldb/trunk/source/API/SBFrame.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/source/API/SBFrame.cpp (original)
+++ lldb/trunk/source/API/SBFrame.cpp Mon Oct  4 22:13:51 2010
@@ -20,6 +20,7 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/ValueObjectRegister.h"
 #include "lldb/Core/ValueObjectVariable.h"
+#include "lldb/Expression/ClangUserExpression.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Symbol/SymbolContext.h"
 #include "lldb/Symbol/VariableList.h"
@@ -416,6 +417,9 @@
     lldb::SBValue expr_result_value;
     if (m_opaque_sp)
     {
+        ExecutionContext exe_ctx;
+        m_opaque_sp->CalculateExecutionContext (exe_ctx);
+        *expr_result_value = ClangUserExpression::Evaluate (exe_ctx, expr);
     }
     return expr_result_value;
 }

Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Mon Oct  4 22:13:51 2010
@@ -233,13 +233,10 @@
         m_exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
     }
     
-    lldb::ValueObjectSP result_valobj_sp;
-    
-    Error expr_error (ClangUserExpression::Evaluate (m_exe_ctx, expr, result_valobj_sp));
-    
-    if (expr_error.Success())
+    lldb::ValueObjectSP result_valobj_sp (ClangUserExpression::Evaluate (m_exe_ctx, expr));
+    assert (result_valobj_sp.get());
+    if (result_valobj_sp->GetError().Success())
     {
-        assert (result_valobj_sp.get() != NULL);
         ValueObject::DumpValueObject (output_stream,
                                       m_exe_ctx.GetBestExecutionContextScope(),
                                       result_valobj_sp.get(),   // Variable object to dump
@@ -257,9 +254,9 @@
     }
     else
     {
-        error_stream.PutCString(expr_error.AsCString());
+        error_stream.PutCString(result_valobj_sp->GetError().AsCString());
         if (result)
-            result->SetStatus (eReturnStatusSuccessFinishNoResult);
+            result->SetStatus (eReturnStatusFailed);
     }
         
     return true;

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Mon Oct  4 22:13:51 2010
@@ -79,6 +79,11 @@
 bool
 ValueObject::UpdateValueIfNeeded (ExecutionContextScope *exe_scope)
 {
+    // If this is a constant value, then our success is predicated on whether
+    // we have an error or not
+    if (GetIsConstant())
+        return m_error.Success();
+
     if (exe_scope)
     {
         Process *process = exe_scope->CalculateProcess();

Modified: lldb/trunk/source/Core/ValueObjectConstResult.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectConstResult.cpp?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectConstResult.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectConstResult.cpp Mon Oct  4 22:13:51 2010
@@ -46,6 +46,16 @@
     m_value.SetValueType(Value::eValueTypeHostAddress);
     m_value.SetContext(Value::eContextTypeOpaqueClangQualType, clang_type);
     m_name = name;
+    SetIsConstant ();
+}
+
+ValueObjectConstResult::ValueObjectConstResult (const Error& error) :
+    ValueObject (),
+    m_clang_ast (NULL),
+    m_type_name ()
+{
+    m_error = error;
+    SetIsConstant ();
 }
 
 ValueObjectConstResult::~ValueObjectConstResult()

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=115589&r1=115588&r2=115589&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Oct  4 22:13:51 2010
@@ -21,6 +21,7 @@
 #include "lldb/Core/ConstString.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Core/StreamString.h"
+#include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/Expression/ClangExpressionDeclMap.h"
 #include "lldb/Expression/ClangExpressionParser.h"
 #include "lldb/Expression/ClangFunction.h"
@@ -338,12 +339,11 @@
 }
 
 
-Error
-ClangUserExpression::Evaluate (ExecutionContext &exe_ctx, const char *expr_cstr, lldb::ValueObjectSP &result_valobj_sp)
+lldb::ValueObjectSP
+ClangUserExpression::Evaluate (ExecutionContext &exe_ctx, const char *expr_cstr)
 {
     Error error;
-    result_valobj_sp.reset();
-
+    lldb::ValueObjectSP result_valobj_sp;
     ClangUserExpression user_expression (expr_cstr);
     
     StreamString error_stream;
@@ -385,6 +385,9 @@
             }
         }
     }
-    return error;
+    if (result_valobj_sp.get() == NULL)
+        result_valobj_sp.reset (new ValueObjectConstResult (error));
+
+    return result_valobj_sp;
 
 }
\ No newline at end of file





More information about the lldb-commits mailing list