[Lldb-commits] [lldb] r150217 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h include/lldb/Expression/ClangUserExpression.h source/Expression/ClangExpressionDeclMap.cpp source/Expression/ClangUserExpression.cpp

Sean Callanan scallanan at apple.com
Thu Feb 9 17:22:05 PST 2012


Author: spyffe
Date: Thu Feb  9 19:22:05 2012
New Revision: 150217

URL: http://llvm.org/viewvc/llvm-project?rev=150217&view=rev
Log:
Fixed a bunch of ownership problems with the expression
parser.  Specifically:

- ClangUserExpression now keeps weak pointers to the
  structures it needs and then locks them when needed.
  This ensures that they continue to be valid without
  leaking memory if the ClangUserExpression is long
  lived.

- ClangExpressionDeclMap, instead of keeping a pointer
  to an ExecutionContext, now contains an
  ExecutionContext.  This prevents bugs if the pointer
  or its contents somehow become stale.  It also no
  longer requires that ExecutionContexts be passed
  into any function except its initialization function,
  since it can count on the ExecutionContext still
  being around.

There's a lot of room for improvement (specifically,
ClangExpressionDeclMap should also use weak pointers
insetad of shared pointers) but this is an important
first step that codifies assumptions that already
existed in the code.

Modified:
    lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
    lldb/trunk/include/lldb/Expression/ClangUserExpression.h
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Expression/ClangUserExpression.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=150217&r1=150216&r2=150217&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Thu Feb  9 19:22:05 2012
@@ -512,9 +512,6 @@
     /// at a given address, which should be aligned as specified by 
     /// GetStructInfo().
     ///
-    /// @param[in] exe_ctx
-    ///     The execution context at which to dump the struct.
-    ///
     /// @param[in] struct_address
     ///     The address at which the struct should be written.
     ///
@@ -526,8 +523,7 @@
     ///     True on success; false otherwise.
     //------------------------------------------------------------------
     bool 
-    Materialize (ExecutionContext &exe_ctx,
-                 lldb::addr_t &struct_address,
+    Materialize (lldb::addr_t &struct_address,
                  Error &error);
     
     //------------------------------------------------------------------
@@ -541,9 +537,6 @@
     ///     The name of the object pointer -- "this," "self," or similar
     ///     depending on language
     ///
-    /// @param[in] exe_ctx
-    ///     The execution context at which to dump the struct.
-    ///
     /// @param[in] error
     ///     An Error to populate with any messages related to
     ///     finding the "this" pointer.
@@ -557,7 +550,6 @@
     bool
     GetObjectPointer (lldb::addr_t &object_ptr,
                       ConstString &object_name,
-                      ExecutionContext &exe_ctx,
                       Error &error,
                       bool suppress_type_check = false);
     
@@ -580,8 +572,7 @@
     ///     True on success; false otherwise.
     //------------------------------------------------------------------
     bool 
-    DumpMaterializedStruct (ExecutionContext &exe_ctx,
-                            Stream &s,
+    DumpMaterializedStruct (Stream &s,
                             Error &error);
     
     //------------------------------------------------------------------
@@ -608,8 +599,7 @@
     ///     True on success; false otherwise.
     //------------------------------------------------------------------
     bool 
-    Dematerialize (ExecutionContext &exe_ctx,
-                   lldb::ClangExpressionVariableSP &result_sp,
+    Dematerialize (lldb::ClangExpressionVariableSP &result_sp,
                    lldb::addr_t stack_frame_top,
                    lldb::addr_t stack_frame_bottom,
                    Error &error);
@@ -670,7 +660,7 @@
     {
     public:
         ParserVars(ClangExpressionDeclMap &decl_map) :
-            m_exe_ctx(NULL),
+            m_exe_ctx(),
             m_sym_ctx(),
             m_persistent_vars(NULL),
             m_enable_lookups(false),
@@ -681,14 +671,14 @@
         Target *
         GetTarget()
         {
-            if (m_exe_ctx && m_exe_ctx->GetTargetPtr())
-                return m_exe_ctx->GetTargetPtr();
+            if (m_exe_ctx.GetTargetPtr())
+                return m_exe_ctx.GetTargetPtr();
             else if (m_sym_ctx.target_sp)
                 m_sym_ctx.target_sp.get();
             return NULL;
         }
         
-        ExecutionContext           *m_exe_ctx;          ///< The execution context to use when parsing.
+        ExecutionContext            m_exe_ctx;          ///< The execution context to use when parsing.
         SymbolContext               m_sym_ctx;          ///< The symbol context to use in finding variables and types.
         ClangPersistentVariables   *m_persistent_vars;  ///< The persistent variables for the process.
         bool                        m_enable_lookups;   ///< Set to true during parsing if we have found the first "$__lldb" name.
@@ -874,9 +864,6 @@
     /// Get the value of a variable in a given execution context and return
     /// the associated Types if needed.
     ///
-    /// @param[in] exe_ctx
-    ///     The execution context to look for the variable in.
-    ///
     /// @param[in] var
     ///     The variable to evaluate.
     ///
@@ -900,8 +887,7 @@
     ///     The LLDB Value for the variable.
     //------------------------------------------------------------------
     Value *
-    GetVariableValue (ExecutionContext &exe_ctx,
-                      lldb::VariableSP &var,
+    GetVariableValue (lldb::VariableSP &var,
                       clang::ASTContext *parser_ast_context,
                       TypeFromUser *found_type = NULL,
                       TypeFromParser *parser_type = NULL);
@@ -1026,9 +1012,6 @@
     ///     True if the struct is to be dematerialized; false if it is to
     ///     be materialized.
     ///
-    /// @param[in] exe_ctx
-    ///     The execution context to use.
-    ///
     /// @param[in] stack_frame_top, stack_frame_bottom
     ///     If not LLDB_INVALID_ADDRESS, the bounds for the stack frame
     ///     in which the expression ran.  A result whose address falls
@@ -1049,7 +1032,6 @@
     //------------------------------------------------------------------
     bool 
     DoMaterialize (bool dematerialize,
-                   ExecutionContext &exe_ctx,
                    lldb::addr_t stack_frame_top,
                    lldb::addr_t stack_frame_bottom,
                    lldb::ClangExpressionVariableSP *result_sp_ptr,
@@ -1069,9 +1051,6 @@
     ///     True if the variable is to be dematerialized; false if it is to
     ///     be materialized.
     ///
-    /// @param[in] exe_ctx
-    ///     The execution context to use.
-    ///
     /// @param[in] var_sp
     ///     The persistent variable to materialize
     ///
@@ -1093,7 +1072,6 @@
     //------------------------------------------------------------------
     bool 
     DoMaterializeOnePersistentVariable (bool dematerialize,
-                                        ExecutionContext &exe_ctx,
                                         lldb::ClangExpressionVariableSP &var_sp,
                                         lldb::addr_t addr,
                                         lldb::addr_t stack_frame_top,
@@ -1108,9 +1086,6 @@
     ///     True if the variable is to be dematerialized; false if it is to
     ///     be materialized.
     ///
-    /// @param[in] exe_ctx
-    ///     The execution context to use.
-    ///
     /// @param[in] sym_ctx
     ///     The symbol context to use (for looking the variable up).
     ///
@@ -1132,7 +1107,6 @@
     //------------------------------------------------------------------
     bool 
     DoMaterializeOneVariable (bool dematerialize,
-                              ExecutionContext &exe_ctx,
                               const SymbolContext &sym_ctx,
                               lldb::ClangExpressionVariableSP &expr_var,
                               lldb::addr_t addr, 
@@ -1146,9 +1120,6 @@
     ///     True if the variable is to be dematerialized; false if it is to
     ///     be materialized.
     ///
-    /// @param[in] exe_ctx
-    ///     The execution context to use.
-    ///
     /// @param[in] reg_ctx
     ///     The register context to use.
     ///
@@ -1167,7 +1138,6 @@
     //------------------------------------------------------------------
     bool 
     DoMaterializeOneRegister (bool dematerialize,
-                              ExecutionContext &exe_ctx,
                               RegisterContext &reg_ctx,
                               const RegisterInfo &reg_info,
                               lldb::addr_t addr, 

Modified: lldb/trunk/include/lldb/Expression/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUserExpression.h?rev=150217&r1=150216&r2=150217&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangUserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangUserExpression.h Thu Feb  9 19:22:05 2012
@@ -28,7 +28,7 @@
 #include "lldb/Expression/IRForTarget.h"
 #include "lldb/Expression/ProcessDataAllocator.h"
 #include "lldb/Symbol/TaggedASTType.h"
-#include "lldb/Target/Process.h"
+#include "lldb/Target/ExecutionContext.h"
 
 #include "llvm/ExecutionEngine/JITMemoryManager.h"
 
@@ -356,6 +356,36 @@
         return m_evaluated_statically;
     }
     
+    void
+    InstallContext (ExecutionContext &exe_ctx)
+    {
+        m_process_wp = exe_ctx.GetProcessSP();
+        m_target_wp = exe_ctx.GetTargetSP();
+        m_frame_wp = exe_ctx.GetFrameSP();
+    }
+    
+    bool
+    LockAndCheckContext (ExecutionContext &exe_ctx,
+                         lldb::TargetSP &target_sp,
+                         lldb::ProcessSP &process_sp,
+                         lldb::StackFrameSP &frame_sp)
+    {
+        target_sp = m_target_wp.lock();
+        process_sp = m_process_wp.lock();
+        frame_sp = m_frame_wp.lock();
+        
+        if ((target_sp && target_sp.get() != exe_ctx.GetTargetPtr()) || 
+            (process_sp && process_sp.get() != exe_ctx.GetProcessPtr()) ||
+            (frame_sp && frame_sp.get() != exe_ctx.GetFramePtr()))
+            return false;
+        
+        return true;
+    }
+    
+    lldb::TargetWP                              m_target_wp;            ///< The target used as the context for the expression.
+    lldb::ProcessWP                             m_process_wp;           ///< The process used as the context for the expression.
+    lldb::StackFrameWP                          m_frame_wp;             ///< The stack frame used as context for the expression.
+    
     std::string                                 m_expr_text;            ///< The text of the expression, as typed by the user
     std::string                                 m_expr_prefix;          ///< The text of the translation-level definitions, as provided by the user
     lldb::LanguageType                          m_language;             ///< The language to use when parsing (eLanguageTypeUnknown means use defaults)

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=150217&r1=150216&r2=150217&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Thu Feb  9 19:22:05 2012
@@ -75,7 +75,7 @@
 ClangExpressionDeclMap::WillParse(ExecutionContext &exe_ctx)
 {    
     EnableParserVars();
-    m_parser_vars->m_exe_ctx = &exe_ctx;
+    m_parser_vars->m_exe_ctx = exe_ctx;
     
     Target *target = exe_ctx.GetTargetPtr();
     if (exe_ctx.GetFramePtr())
@@ -146,26 +146,24 @@
     
     TargetInfo ret;
     
-    ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    if (exe_ctx)
+    ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
+
+    Process *process = exe_ctx.GetProcessPtr();
+    if (process)
     {
-        Process *process = exe_ctx->GetProcessPtr();
-        if (process)
-        {
-            ret.byte_order = process->GetByteOrder();
-            ret.address_byte_size = process->GetAddressByteSize();
-        }
-        else 
+        ret.byte_order = process->GetByteOrder();
+        ret.address_byte_size = process->GetAddressByteSize();
+    }
+    else 
+    {
+        Target *target = exe_ctx.GetTargetPtr();
+        if (target)
         {
-            Target *target = exe_ctx->GetTargetPtr();
-            if (target)
-            {
-                ret.byte_order = target->GetArchitecture().GetByteOrder();
-                ret.address_byte_size = target->GetArchitecture().GetAddressByteSize();
-            }
+            ret.byte_order = target->GetArchitecture().GetByteOrder();
+            ret.address_byte_size = target->GetArchitecture().GetAddressByteSize();
         }
     }
-    
+
     return ret;
 }
 
@@ -190,10 +188,12 @@
 {
     assert (m_parser_vars.get());
     
-    ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    if (exe_ctx == NULL)
-        return lldb::ClangExpressionVariableSP();
-    Target *target = exe_ctx->GetTargetPtr();
+    ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
+    
+    Target *target = exe_ctx.GetTargetPtr();
+    
+    if (!target)
+        return ClangExpressionVariableSP();
 
     ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
     
@@ -212,7 +212,7 @@
         return lldb::ClangExpressionVariableSP();
     }
     
-    if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx->GetBestExecutionContextScope (),
+    if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx.GetBestExecutionContextScope (),
                                                                      name, 
                                                                      user_type, 
                                                                      m_parser_vars->m_target_info.byte_order,
@@ -279,10 +279,8 @@
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
-    ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    if (exe_ctx == NULL)
-        return lldb::ClangExpressionVariableSP();
-    Target *target = exe_ctx->GetTargetPtr();
+    ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
+    Target *target = exe_ctx.GetTargetPtr();
     if (target == NULL)
         return lldb::ClangExpressionVariableSP();
 
@@ -313,7 +311,7 @@
     
     TypeFromUser var_type = var_sp->GetTypeFromUser();
     
-    StackFrame *frame = exe_ctx->GetFramePtr();
+    StackFrame *frame = exe_ctx.GetFramePtr();
     if (frame == NULL)
         return lldb::ClangExpressionVariableSP();
     
@@ -384,8 +382,7 @@
         
     if (maybe_make_load && 
         value.GetValueType() == Value::eValueTypeFileAddress &&
-        m_parser_vars->m_exe_ctx && 
-        m_parser_vars->m_exe_ctx->GetProcessPtr())
+        m_parser_vars->m_exe_ctx.GetProcessPtr())
     {
         value.SetValueType(Value::eValueTypeLoadAddress);
     }
@@ -399,7 +396,7 @@
         unsigned long long address = value.GetScalar().ULongLong();
         AddressType address_type = value.GetValueAddressType();
         
-        pvar_sp->m_live_sp = ValueObjectConstResult::Create(m_parser_vars->m_exe_ctx->GetBestExecutionContextScope(),
+        pvar_sp->m_live_sp = ValueObjectConstResult::Create(m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
                                                             pvar_sp->GetTypeFromUser().GetASTContext(),
                                                             pvar_sp->GetTypeFromUser().GetOpaqueQualType(),
                                                             pvar_sp->GetName(),
@@ -449,10 +446,8 @@
     assert (m_parser_vars.get());
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    if (exe_ctx == NULL)
-        return false;
-    Target *target = exe_ctx->GetTargetPtr();
+    ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
+    Target *target = exe_ctx.GetTargetPtr();
     if (target == NULL)
         return false;
 
@@ -473,7 +468,7 @@
     if (!m_parser_vars->m_target_info.IsValid())
         return false;
     
-    if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx->GetBestExecutionContextScope (),
+    if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx.GetBestExecutionContextScope (),
                                                                      name, 
                                                                      user_type, 
                                                                      m_parser_vars->m_target_info.byte_order,
@@ -695,10 +690,8 @@
     assert (m_parser_vars.get());
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
-    if (exe_ctx == NULL)
-        return false;
-    Target *target = exe_ctx->GetTargetPtr();
+    ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
+    Target *target = exe_ctx.GetTargetPtr();
     // Back out in all cases where we're not fully initialized
     if (target == NULL)
         return false;
@@ -819,11 +812,10 @@
 {
     assert (m_parser_vars.get());
     
-    if (!m_parser_vars->m_exe_ctx ||
-        !m_parser_vars->m_exe_ctx->GetTargetPtr())
+    if (!m_parser_vars->m_exe_ctx.GetTargetPtr())
         return false;
     
-    return GetSymbolAddress(m_parser_vars->m_exe_ctx->GetTargetRef(), name, symbol_type);
+    return GetSymbolAddress(m_parser_vars->m_exe_ctx.GetTargetRef(), name, symbol_type);
 }
 
 // Interface for IRInterpreter
@@ -835,7 +827,7 @@
 
     ret.SetContext(Value::eContextTypeInvalid, NULL);
 
-    if (m_parser_vars->m_exe_ctx && m_parser_vars->m_exe_ctx->GetProcessPtr())
+    if (m_parser_vars->m_exe_ctx.GetProcessPtr())
         ret.SetValueType(Value::eValueTypeLoadAddress);
     else
         ret.SetValueType(Value::eValueTypeFileAddress);
@@ -852,15 +844,15 @@
 {
     assert (m_parser_vars.get());
     
-    ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
+    ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
     
-    Process *process = exe_ctx->GetProcessPtr();
+    Process *process = exe_ctx.GetProcessPtr();
     if (value.GetContextType() == Value::eContextTypeRegisterInfo)
     {
         if (!process)
             return false;
         
-        RegisterContext *reg_ctx = exe_ctx->GetRegisterContext();
+        RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
         RegisterInfo *reg_info = value.GetRegisterInfo();
         
         if (!reg_ctx)
@@ -885,7 +877,7 @@
                 if (!process)
                     return false;
                 
-                Target *target = exe_ctx->GetTargetPtr();
+                Target *target = exe_ctx.GetTargetPtr();
                 Address file_addr;
                 
                 if (!target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr))
@@ -928,16 +920,16 @@
 {
     assert (m_parser_vars.get());
     
-    ExecutionContext *exe_ctx = m_parser_vars->m_exe_ctx;
+    ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
 
-    Process *process = exe_ctx->GetProcessPtr();
+    Process *process = exe_ctx.GetProcessPtr();
 
     if (value.GetContextType() == Value::eContextTypeRegisterInfo)
     {
         if (!process)
             return false;
         
-        RegisterContext *reg_ctx = exe_ctx->GetRegisterContext();
+        RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
         RegisterInfo *reg_info = value.GetRegisterInfo();
         
         if (!reg_ctx)
@@ -959,7 +951,7 @@
                 return false;
             case Value::eValueTypeFileAddress:
             {
-                Target *target = exe_ctx->GetTargetPtr();
+                Target *target = exe_ctx.GetTargetPtr();
                 if (target == NULL)
                     return false;
                 
@@ -1003,9 +995,7 @@
 ClangExpressionDeclMap::LookupDecl (clang::NamedDecl *decl)
 {
     assert (m_parser_vars.get());
-    
-    ExecutionContext exe_ctx = *m_parser_vars->m_exe_ctx;
-        
+            
     ClangExpressionVariableSP expr_var_sp (m_found_entities.GetVariable(decl));
     ClangExpressionVariableSP persistent_var_sp (m_parser_vars->m_persistent_vars->GetVariable(decl));
     
@@ -1018,11 +1008,11 @@
 
         if (expr_var_sp->m_parser_vars->m_lldb_var)
         {
-            std::auto_ptr<Value> value(GetVariableValue(exe_ctx, expr_var_sp->m_parser_vars->m_lldb_var, NULL));
+            std::auto_ptr<Value> value(GetVariableValue(expr_var_sp->m_parser_vars->m_lldb_var, NULL));
             
             if (is_reference && value.get() && value->GetValueType() == Value::eValueTypeLoadAddress)
             {
-                Process *process = m_parser_vars->m_exe_ctx->GetProcessPtr();
+                Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
                 
                 if (!process)
                     return Value();
@@ -1069,8 +1059,8 @@
              persistent_var_sp->m_flags & ClangExpressionVariable::EVIsLLDBAllocated) &&
             persistent_var_sp->m_live_sp &&
             ((persistent_var_sp->m_live_sp->GetValue().GetValueType() == Value::eValueTypeLoadAddress &&
-              m_parser_vars->m_exe_ctx->GetProcessSP() &&
-              m_parser_vars->m_exe_ctx->GetProcessSP()->IsAlive()) ||
+              m_parser_vars->m_exe_ctx.GetProcessSP() &&
+              m_parser_vars->m_exe_ctx.GetProcessSP()->IsAlive()) ||
              (persistent_var_sp->m_live_sp->GetValue().GetValueType() == Value::eValueTypeFileAddress)))
         {
             return persistent_var_sp->m_live_sp->GetValue();
@@ -1095,10 +1085,7 @@
 {
     assert(m_parser_vars.get());
     
-    if (!m_parser_vars->m_exe_ctx)
-        return Value();
-
-    StackFrame *frame = m_parser_vars->m_exe_ctx->GetFramePtr();
+    StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
     
     if (!frame)
         return Value();
@@ -1115,11 +1102,11 @@
         !var->LocationIsValidForFrame (frame))
         return Value();
     
-    std::auto_ptr<Value> value(GetVariableValue(*m_parser_vars->m_exe_ctx, var, NULL));
+    std::auto_ptr<Value> value(GetVariableValue(var, NULL));
     
     if (value.get() && value->GetValueType() == Value::eValueTypeLoadAddress)
     {
-        Process *process = m_parser_vars->m_exe_ctx->GetProcessPtr();
+        Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
         
         if (!process)
             return Value();
@@ -1145,17 +1132,18 @@
 bool 
 ClangExpressionDeclMap::Materialize 
 (
-    ExecutionContext &exe_ctx, 
     lldb::addr_t &struct_address,
     Error &err
 )
 {
+    if (!m_parser_vars.get())
+        return false;
+    
     EnableMaterialVars();
     
-    m_material_vars->m_process = exe_ctx.GetProcessPtr();
+    m_material_vars->m_process = m_parser_vars->m_exe_ctx.GetProcessPtr();
     
     bool result = DoMaterialize(false /* dematerialize */, 
-                                exe_ctx, 
                                 LLDB_INVALID_ADDRESS /* top of stack frame */, 
                                 LLDB_INVALID_ADDRESS /* bottom of stack frame */, 
                                 NULL, /* result SP */
@@ -1172,16 +1160,15 @@
 (
     lldb::addr_t &object_ptr,
     ConstString &object_name,
-    ExecutionContext &exe_ctx,
     Error &err,
     bool suppress_type_check
 )
 {
     assert (m_struct_vars.get());
     
-    Target *target = exe_ctx.GetTargetPtr();
-    Process *process = exe_ctx.GetProcessPtr();
-    StackFrame *frame = exe_ctx.GetFramePtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+    Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
+    StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
 
     if (frame == NULL || process == NULL || target == NULL)
     {
@@ -1205,8 +1192,7 @@
         return false;
     }
     
-    std::auto_ptr<lldb_private::Value> location_value(GetVariableValue(exe_ctx,
-                                                                       object_ptr_var,
+    std::auto_ptr<lldb_private::Value> location_value(GetVariableValue(object_ptr_var,
                                                                        NULL));
     
     if (!location_value.get())
@@ -1260,7 +1246,7 @@
                 return false;
             }
             
-            RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
+            RegisterContext *reg_ctx = m_parser_vars->m_exe_ctx.GetRegisterContext();
             
             if (!reg_ctx)
             {
@@ -1280,14 +1266,13 @@
 bool 
 ClangExpressionDeclMap::Dematerialize 
 (
-    ExecutionContext &exe_ctx,
     ClangExpressionVariableSP &result_sp,
     lldb::addr_t stack_frame_top,
     lldb::addr_t stack_frame_bottom,
     Error &err
 )
 {
-    return DoMaterialize(true, exe_ctx, stack_frame_top, stack_frame_bottom, &result_sp, err);
+    return DoMaterialize(true, stack_frame_top, stack_frame_bottom, &result_sp, err);
     
     DidDematerialize();
 }
@@ -1314,7 +1299,6 @@
 bool
 ClangExpressionDeclMap::DumpMaterializedStruct
 (
-    ExecutionContext &exe_ctx, 
     Stream &s,
     Error &err
 )
@@ -1327,7 +1311,7 @@
         err.SetErrorString("Structure hasn't been laid out yet");
         return false;
     }
-    Process *process = exe_ctx.GetProcessPtr();
+    Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
 
     if (!process)
     {
@@ -1335,7 +1319,7 @@
         return false;
     }
     
-    Target *target = exe_ctx.GetTargetPtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
     if (!target)
     {
         err.SetErrorString("Couldn't find the target");
@@ -1395,7 +1379,6 @@
 ClangExpressionDeclMap::DoMaterialize 
 (
     bool dematerialize,
-    ExecutionContext &exe_ctx,
     lldb::addr_t stack_frame_top,
     lldb::addr_t stack_frame_bottom,
     lldb::ClangExpressionVariableSP *result_sp_ptr,
@@ -1415,13 +1398,13 @@
         return false;
     }
     
-    StackFrame *frame = exe_ctx.GetFramePtr();
+    StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
     if (!frame)
     {
         err.SetErrorString("Received null execution frame");
         return false;
     }
-    Target *target = exe_ctx.GetTargetPtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
     
     ClangPersistentVariables &persistent_vars = target->GetPersistentVariables();
         
@@ -1439,7 +1422,7 @@
     
     if (!dematerialize)
     {
-        Process *process = exe_ctx.GetProcessPtr();
+        Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
         if (m_material_vars->m_materialized_location)
         {
             process->DeallocateMemory(m_material_vars->m_materialized_location);
@@ -1481,7 +1464,7 @@
             {
                 // This is a register variable
                 
-                RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
+                RegisterContext *reg_ctx = m_parser_vars->m_exe_ctx.GetRegisterContext();
                 
                 if (!reg_ctx)
                 {
@@ -1490,7 +1473,6 @@
                 }
                     
                 if (!DoMaterializeOneRegister (dematerialize, 
-                                               exe_ctx, 
                                                *reg_ctx, 
                                                *reg_info, 
                                                m_material_vars->m_materialized_location + member_sp->m_jit_vars->m_offset, 
@@ -1506,7 +1488,6 @@
                 }
                 
                 if (!DoMaterializeOneVariable (dematerialize, 
-                                               exe_ctx, 
                                                sym_ctx,
                                                member_sp,
                                                m_material_vars->m_materialized_location + member_sp->m_jit_vars->m_offset, 
@@ -1532,7 +1513,6 @@
                 }
 
                 if (!DoMaterializeOnePersistentVariable (dematerialize, 
-                                                         exe_ctx,
                                                          member_sp, 
                                                          m_material_vars->m_materialized_location + member_sp->m_jit_vars->m_offset,
                                                          stack_frame_top,
@@ -1555,7 +1535,6 @@
 ClangExpressionDeclMap::DoMaterializeOnePersistentVariable
 (
     bool dematerialize,
-    ExecutionContext &exe_ctx,
     ClangExpressionVariableSP &var_sp,
     lldb::addr_t addr,
     lldb::addr_t stack_frame_top,
@@ -1581,7 +1560,7 @@
     }
     
     Error error;
-    Process *process = exe_ctx.GetProcessPtr();
+    Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
 
     lldb::addr_t mem; // The address of a spare memory area used to hold the persistent variable.
     
@@ -1610,7 +1589,7 @@
                 // If the reference comes from the program, then the ClangExpressionVariable's
                 // live variable data hasn't been set up yet.  Do this now.
                 
-                var_sp->m_live_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope (),
+                var_sp->m_live_sp = ValueObjectConstResult::Create (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope (),
                                                                     var_sp->GetTypeFromUser().GetASTContext(),
                                                                     var_sp->GetTypeFromUser().GetOpaqueQualType(),
                                                                     var_sp->GetName(),
@@ -1716,7 +1695,7 @@
             
             // Put the location of the spare memory into the live data of the ValueObject.
             
-            var_sp->m_live_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
+            var_sp->m_live_sp = ValueObjectConstResult::Create (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
                                                                 var_sp->GetTypeFromUser().GetASTContext(),
                                                                 var_sp->GetTypeFromUser().GetOpaqueQualType(),
                                                                 var_sp->GetName(),
@@ -1769,7 +1748,6 @@
 ClangExpressionDeclMap::DoMaterializeOneVariable
 (
     bool dematerialize,
-    ExecutionContext &exe_ctx,
     const SymbolContext &sym_ctx,
     ClangExpressionVariableSP &expr_var,
     lldb::addr_t addr, 
@@ -1777,9 +1755,9 @@
 )
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    Target *target = exe_ctx.GetTargetPtr();
-    Process *process = exe_ctx.GetProcessPtr();
-    StackFrame *frame = exe_ctx.GetFramePtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+    Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
+    StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
 
     if (!frame || !process || !target || !m_parser_vars.get() || !expr_var->m_parser_vars.get())
     {
@@ -1801,8 +1779,7 @@
 
     if (var)
     {
-        location_value.reset(GetVariableValue(exe_ctx,
-                                              var,
+        location_value.reset(GetVariableValue(var,
                                               NULL));
     }
     else if (sym)
@@ -1939,7 +1916,7 @@
             
             RegisterValue reg_value;
 
-            RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
+            RegisterContext *reg_ctx = m_parser_vars->m_exe_ctx.GetRegisterContext();
             
             if (!reg_ctx)
             {
@@ -2053,7 +2030,7 @@
                 
                 // Put the location of the spare memory into the live data of the ValueObject.
                 
-                expr_var->m_live_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
+                expr_var->m_live_sp = ValueObjectConstResult::Create (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
                                                                       type.GetASTContext(),
                                                                       type.GetOpaqueQualType(),
                                                                       name,
@@ -2107,7 +2084,6 @@
 ClangExpressionDeclMap::DoMaterializeOneRegister
 (
     bool dematerialize,
-    ExecutionContext &exe_ctx,
     RegisterContext &reg_ctx,
     const RegisterInfo &reg_info,
     lldb::addr_t addr, 
@@ -2364,8 +2340,8 @@
     
     // Only look for functions by name out in our symbols if the function 
     // doesn't start with our phony prefix of '$'
-    Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
-    StackFrame *frame = m_parser_vars->m_exe_ctx->GetFramePtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
+    StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
     if (name_unique_cstr[0] == '$' && !namespace_decl)
     {
         static ConstString g_lldb_class_name ("$__lldb_class");
@@ -2554,9 +2530,9 @@
         
         const char *reg_name(&name.GetCString()[1]);
         
-        if (m_parser_vars->m_exe_ctx->GetRegisterContext())
+        if (m_parser_vars->m_exe_ctx.GetRegisterContext())
         {
-            const RegisterInfo *reg_info(m_parser_vars->m_exe_ctx->GetRegisterContext()->GetRegisterInfoByName(reg_name));
+            const RegisterInfo *reg_info(m_parser_vars->m_exe_ctx.GetRegisterContext()->GetRegisterInfoByName(reg_name));
             
             if (reg_info)
             {
@@ -2695,7 +2671,6 @@
 Value *
 ClangExpressionDeclMap::GetVariableValue
 (
-    ExecutionContext &exe_ctx,
     VariableSP &var,
     ASTContext *parser_ast_context,
     TypeFromUser *user_type,
@@ -2737,7 +2712,7 @@
     
     lldb::addr_t loclist_base_load_addr = LLDB_INVALID_ADDRESS;
     
-    Target *target = exe_ctx.GetTargetPtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
 
     if (var_location_expr.IsLocationList())
     {
@@ -2747,7 +2722,7 @@
     }
     Error err;
     
-    if (!var_location_expr.Evaluate(&exe_ctx, ast, NULL, NULL, NULL, loclist_base_load_addr, NULL, *var_location.get(), &err))
+    if (!var_location_expr.Evaluate(&m_parser_vars->m_exe_ctx, ast, NULL, NULL, NULL, loclist_base_load_addr, NULL, *var_location.get(), &err))
     {
         if (log)
             log->Printf("Error evaluating location: %s", err.AsCString());
@@ -2817,8 +2792,7 @@
     TypeFromUser ut;
     TypeFromParser pt;
     
-    Value *var_location = GetVariableValue (*m_parser_vars->m_exe_ctx, 
-                                            var, 
+    Value *var_location = GetVariableValue (var, 
                                             m_ast_context,
                                             &ut,
                                             &pt);
@@ -2903,7 +2877,7 @@
     
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
-    Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
 
     if (target == NULL)
         return;
@@ -2920,7 +2894,7 @@
     
     std::string decl_name(context.m_decl_name.getAsString());
     ConstString entity_name(decl_name.c_str());
-    ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx->GetBestExecutionContextScope (),
+    ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope (),
                                                                       entity_name, 
                                                                       user_type,
                                                                       m_parser_vars->m_target_info.byte_order,
@@ -2956,7 +2930,7 @@
 ClangExpressionDeclMap::ResolveUnknownTypes()
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-    Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
 
     ASTContext *scratch_ast_context = target->GetScratchClangASTContext()->getASTContext();
 
@@ -3035,7 +3009,7 @@
     
     NamedDecl *var_decl = context.AddVarDecl(parser_type.GetOpaqueQualType());
     
-    ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx->GetBestExecutionContextScope(),
+    ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
                                                                       m_parser_vars->m_target_info.byte_order,
                                                                       m_parser_vars->m_target_info.address_byte_size));
     assert (entity.get());
@@ -3127,13 +3101,13 @@
         return;
     }
     
-    Target *target = m_parser_vars->m_exe_ctx->GetTargetPtr();
+    Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
 
     lldb::addr_t load_addr = fun_address->GetCallableLoadAddress(target);
     fun_location->SetValueType(Value::eValueTypeLoadAddress);
     fun_location->GetScalar() = load_addr;
     
-    ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx->GetBestExecutionContextScope (),
+    ClangExpressionVariableSP entity(m_found_entities.CreateVariable (m_parser_vars->m_exe_ctx.GetBestExecutionContextScope (),
                                                                       m_parser_vars->m_target_info.byte_order,
                                                                       m_parser_vars->m_target_info.address_byte_size));
     assert (entity.get());

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=150217&r1=150216&r2=150217&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Thu Feb  9 19:22:05 2012
@@ -255,6 +255,8 @@
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
     Error err;
+ 
+    InstallContext(exe_ctx);
     
     ScanContext(exe_ctx, err);
     
@@ -385,6 +387,19 @@
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
 
+    lldb::TargetSP target;
+    lldb::ProcessSP process;
+    lldb::StackFrameSP frame;
+    
+    if (!LockAndCheckContext(exe_ctx,
+                             target,
+                             process, 
+                             frame))
+    {
+        error_stream.Printf("The context has changed before we could JIT the expression!");
+        return false;
+    }
+    
     if (m_jit_start_addr != LLDB_INVALID_ADDRESS)
     {
         Error materialize_error;
@@ -407,7 +422,7 @@
                 return false;
             }
             
-            if (!(m_expr_decl_map->GetObjectPointer(object_ptr, object_name, exe_ctx, materialize_error)))
+            if (!(m_expr_decl_map->GetObjectPointer(object_ptr, object_name, materialize_error)))
             {
                 error_stream.Printf("warning: couldn't get required object pointer (substituting NULL): %s\n", materialize_error.AsCString());
                 object_ptr = 0;
@@ -417,7 +432,7 @@
             {
                 ConstString cmd_name("_cmd");
                 
-                if (!(m_expr_decl_map->GetObjectPointer(cmd_ptr, cmd_name, exe_ctx, materialize_error, true)))
+                if (!(m_expr_decl_map->GetObjectPointer(cmd_ptr, cmd_name, materialize_error, true)))
                 {
                     error_stream.Printf("warning: couldn't get object pointer (substituting NULL): %s\n", materialize_error.AsCString());
                     cmd_ptr = 0;
@@ -425,7 +440,7 @@
             }
         }
                 
-        if (!m_expr_decl_map->Materialize(exe_ctx, struct_address, materialize_error))
+        if (!m_expr_decl_map->Materialize(struct_address, materialize_error))
         {
             error_stream.Printf("Couldn't materialize struct: %s\n", materialize_error.AsCString());
             return false;
@@ -454,7 +469,7 @@
             
             if (struct_address)
             {
-                if (!m_expr_decl_map->DumpMaterializedStruct(exe_ctx, args, dump_error))
+                if (!m_expr_decl_map->DumpMaterializedStruct(args, dump_error))
                 {
                     log->Printf("  Couldn't extract variable values : %s", dump_error.AsCString("unknown error"));
                 }
@@ -511,7 +526,7 @@
         
         Error dump_error;
         
-        if (!m_expr_decl_map->DumpMaterializedStruct(exe_ctx, args, dump_error))
+        if (!m_expr_decl_map->DumpMaterializedStruct(args, dump_error))
         {
             log->Printf("  Couldn't extract variable values : %s", dump_error.AsCString("unknown error"));
         }
@@ -524,7 +539,7 @@
     lldb::addr_t function_stack_bottom = function_stack_pointer - Host::GetPageSize();
     
         
-    if (!m_expr_decl_map->Dematerialize(exe_ctx, result, function_stack_pointer, function_stack_bottom, expr_error))
+    if (!m_expr_decl_map->Dematerialize(result, function_stack_pointer, function_stack_bottom, expr_error))
     {
         error_stream.Printf ("Couldn't dematerialize struct : %s\n", expr_error.AsCString("unknown error"));
         return false;





More information about the lldb-commits mailing list