[Lldb-commits] [lldb] r140202 - in /lldb/trunk: include/lldb/Target/Process.h source/Expression/ClangExpressionParser.cpp source/Expression/ClangUserExpression.cpp source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp source/Target/Process.cpp

Sean Callanan scallanan at apple.com
Tue Sep 20 16:01:52 PDT 2011


Author: spyffe
Date: Tue Sep 20 18:01:51 2011
New Revision: 140202

URL: http://llvm.org/viewvc/llvm-project?rev=140202&view=rev
Log:
Fixed a problem where expressions would attempt to
allocate memory in a process that did not support
expression execution.  Also improved detection of
whether or not a process can execute expressions.

Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Expression/ClangExpressionParser.cpp
    lldb/trunk/source/Expression/ClangUserExpression.cpp
    lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=140202&r1=140201&r2=140202&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Tue Sep 20 18:01:51 2011
@@ -2301,6 +2301,24 @@
     AllocateMemory (size_t size, uint32_t permissions, Error &error);
 
     //------------------------------------------------------------------
+    /// Determines whether executing JIT-compiled code in this process 
+    /// is possible.
+    ///
+    /// @return
+    ///     True if execution of JIT code is possible; false otherwise.
+    //------------------------------------------------------------------    
+    bool CanJIT ();
+    
+    //------------------------------------------------------------------
+    /// Sets whether executing JIT-compiled code in this process 
+    /// is possible.
+    ///
+    /// @param[in] can_jit
+    ///     True if execution of JIT code is possible; false otherwise.
+    //------------------------------------------------------------------
+    void SetCanJIT (bool can_jit);
+    
+    //------------------------------------------------------------------
     /// Actually deallocate memory in the process.
     ///
     /// This function will deallocate memory in the process's address
@@ -2771,6 +2789,12 @@
     LanguageRuntimeCollection m_language_runtimes;
     std::auto_ptr<NextEventAction> m_next_event_action_ap;
 
+    enum {
+        eCanJITDontKnow= 0,
+        eCanJITYes,
+        eCanJITNo
+    } m_can_jit;
+
     size_t
     RemoveBreakpointOpcodesFromBuffer (lldb::addr_t addr, size_t size, uint8_t *buf) const;
 

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=140202&r1=140201&r2=140202&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Tue Sep 20 18:01:51 2011
@@ -496,8 +496,32 @@
             return err;
         }
         
-        if (m_expr.NeedsValidation() && exe_ctx.process && exe_ctx.process->GetDynamicCheckers())
+        if (execution_policy != eExecutionPolicyNever &&
+            m_expr.NeedsValidation() && 
+            exe_ctx.process)
         {
+            if (!exe_ctx.process->GetDynamicCheckers())
+            {                
+                DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions();
+                
+                StreamString install_errors;
+                
+                if (!dynamic_checkers->Install(install_errors, exe_ctx))
+                {
+                    if (install_errors.GetString().empty())
+                        err.SetErrorString ("couldn't install checkers, unknown error");
+                    else
+                        err.SetErrorString (install_errors.GetString().c_str());
+                    
+                    return err;
+                }
+                
+                exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
+                
+                if (log)
+                    log->Printf("== [ClangUserExpression::Evaluate] Finished installing dynamic checkers ==");
+            }
+            
             IRDynamicChecks ir_dynamic_checks(*exe_ctx.process->GetDynamicCheckers(), function_name.c_str());
         
             if (!ir_dynamic_checks.runOnModule(*module))

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=140202&r1=140201&r2=140202&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Tue Sep 20 18:01:51 2011
@@ -615,34 +615,8 @@
         }
     }
     
-    if (exe_ctx.process == NULL)
+    if (exe_ctx.process == NULL || !exe_ctx.process->CanJIT())
         execution_policy = eExecutionPolicyNever;
-        
-    if (execution_policy != eExecutionPolicyNever && !exe_ctx.process->GetDynamicCheckers())
-    {
-        if (log)
-            log->Printf("== [ClangUserExpression::Evaluate] Installing dynamic checkers ==");
-        
-        DynamicCheckerFunctions *dynamic_checkers = new DynamicCheckerFunctions();
-        
-        StreamString install_errors;
-        
-        if (!dynamic_checkers->Install(install_errors, exe_ctx))
-        {
-            if (install_errors.GetString().empty())
-                error.SetErrorString ("couldn't install checkers, unknown error");
-            else
-                error.SetErrorString (install_errors.GetString().c_str());
-            
-            result_valobj_sp = ValueObjectConstResult::Create (NULL, error);
-            return eExecutionSetupError;
-        }
-            
-        exe_ctx.process->SetDynamicCheckers(dynamic_checkers);
-        
-        if (log)
-            log->Printf("== [ClangUserExpression::Evaluate] Finished installing dynamic checkers ==");
-    }
     
     ClangUserExpressionSP user_expression_sp (new ClangUserExpression (expr_cstr, expr_prefix));
 

Modified: lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp?rev=140202&r1=140201&r2=140202&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp Tue Sep 20 18:01:51 2011
@@ -78,7 +78,10 @@
     }
     
     if (create)
+    {
+        process->SetCanJIT(false);
         return new DynamicLoaderDarwinKernel (process);
+    }
     return NULL;
 }
 

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=140202&r1=140201&r2=140202&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Tue Sep 20 18:01:51 2011
@@ -601,7 +601,8 @@
     m_memory_cache (*this),
     m_allocated_memory_cache (*this),
     m_attached_to_process (false),
-    m_next_event_action_ap()
+    m_next_event_action_ap(),
+    m_can_jit(eCanJITYes)
 {
     UpdateInstanceName();
 
@@ -1956,6 +1957,18 @@
 #endif
 }
 
+bool
+Process::CanJIT ()
+{
+    return m_can_jit == eCanJITYes;
+}
+
+void
+Process::SetCanJIT (bool can_jit)
+{
+    m_can_jit = (can_jit ? eCanJITYes : eCanJITNo);
+}
+
 Error
 Process::DeallocateMemory (addr_t ptr)
 {





More information about the lldb-commits mailing list