[Lldb-commits] [lldb] r164082 - in /lldb/trunk: include/lldb/Expression/ClangExpression.h source/Expression/ClangFunction.cpp source/Expression/ClangUserExpression.cpp source/Expression/ClangUtilityFunction.cpp

Enrico Granata egranata at apple.com
Mon Sep 17 17:08:47 PDT 2012


Author: enrico
Date: Mon Sep 17 19:08:47 2012
New Revision: 164082

URL: http://llvm.org/viewvc/llvm-project?rev=164082&view=rev
Log:
Making ClangExpression hold on to a WP to the Process instead of a SP. This fix should enable us to have per-process maps of ClangExpressions without fear of keeping the process alive forever

Modified:
    lldb/trunk/include/lldb/Expression/ClangExpression.h
    lldb/trunk/source/Expression/ClangFunction.cpp
    lldb/trunk/source/Expression/ClangUserExpression.cpp
    lldb/trunk/source/Expression/ClangUtilityFunction.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpression.h?rev=164082&r1=164081&r2=164082&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpression.h Mon Sep 17 19:08:47 2012
@@ -47,7 +47,7 @@
     };
     
     ClangExpression () :
-        m_jit_process_sp(),
+        m_jit_process_wp(),
         m_jit_alloc (LLDB_INVALID_ADDRESS),
         m_jit_start_addr (LLDB_INVALID_ADDRESS),
         m_jit_end_addr (LLDB_INVALID_ADDRESS)
@@ -143,13 +143,13 @@
     void
     DeallocateJITFunction ()
     {
-        if (m_jit_process_sp && m_jit_alloc != LLDB_INVALID_ADDRESS)
+        lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
+        if (jit_process_sp && m_jit_alloc != LLDB_INVALID_ADDRESS)
         {
-            m_jit_process_sp->DeallocateMemory (m_jit_alloc);
+            jit_process_sp->DeallocateMemory (m_jit_alloc);
             // If this process is ever used for anything else, we can not clear it 
             // here. For now it is only used in order to deallocate any code if
             // m_jit_alloc is a valid address.
-            m_jit_process_sp.reset(); 
             m_jit_alloc = LLDB_INVALID_ADDRESS;
         }
     }
@@ -166,7 +166,7 @@
 
 protected:
 
-    lldb::ProcessSP m_jit_process_sp;
+    lldb::ProcessWP m_jit_process_wp;
     lldb::addr_t    m_jit_alloc;            ///< The address of the block containing JITted code.  LLDB_INVALID_ADDRESS if invalid.
     lldb::addr_t    m_jit_start_addr;       ///< The address of the JITted function within the JIT allocation.  LLDB_INVALID_ADDRESS if invalid.
     lldb::addr_t    m_jit_end_addr;         ///< The address of the JITted function within the JIT allocation.  LLDB_INVALID_ADDRESS if invalid.

Modified: lldb/trunk/source/Expression/ClangFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=164082&r1=164081&r2=164082&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangFunction.cpp Mon Sep 17 19:08:47 2012
@@ -66,9 +66,9 @@
     m_compiled (false),
     m_JITted (false)
 {
-    m_jit_process_sp = exe_scope.CalculateProcess();
+    m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
     // Can't make a ClangFunction without a process.
-    assert (m_jit_process_sp);
+    assert (m_jit_process_wp.lock());
 }
 
 ClangFunction::ClangFunction
@@ -89,9 +89,9 @@
     m_compiled (false),
     m_JITted (false)
 {
-    m_jit_process_sp = exe_scope.CalculateProcess();
+    m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
     // Can't make a ClangFunction without a process.
-    assert (m_jit_process_sp);
+    assert (m_jit_process_wp.lock());
 
     m_function_addr = m_function_ptr->GetAddressRange().GetBaseAddress();
     m_function_return_qual_type = m_function_ptr->GetReturnClangType();
@@ -219,10 +219,19 @@
         log->Printf ("Expression: \n\n%s\n\n", m_wrapper_function_text.c_str());
         
     // Okay, now compile this expression
-        
-    m_parser.reset(new ClangExpressionParser(m_jit_process_sp.get(), *this));
     
-    num_errors = m_parser->Parse (errors);
+    lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
+    if (jit_process_sp)
+    {
+        m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this));
+        
+        num_errors = m_parser->Parse (errors);
+    }
+    else
+    {
+        errors.Printf("no process - unable to inject function");
+        num_errors = 1;
+    }
     
     m_compiled = (num_errors == 0);
     
@@ -239,8 +248,10 @@
 
     if (!process)
         return false;
-        
-    if (process != m_jit_process_sp.get())
+    
+    lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
+    
+    if (process != jit_process_sp.get())
         return false;
     
     if (!m_compiled)
@@ -265,7 +276,7 @@
     if (!jit_error.Success())
         return false;
     if (process && m_jit_alloc != LLDB_INVALID_ADDRESS)
-        m_jit_process_sp = process->shared_from_this();
+        m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
 
     return true;
 }
@@ -302,7 +313,9 @@
     if (process == NULL)
         return return_value;
 
-    if (process != m_jit_process_sp.get())
+    lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
+    
+    if (process != jit_process_sp.get())
         return false;
                 
     if (args_addr_ref == LLDB_INVALID_ADDRESS)
@@ -426,7 +439,10 @@
     
     if (process == NULL)
         return false;
-    if (process != m_jit_process_sp.get())
+
+    lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
+    
+    if (process != jit_process_sp.get())
         return false;
                 
     Error error;

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=164082&r1=164081&r2=164082&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Sep 17 19:08:47 2012
@@ -351,7 +351,7 @@
     if (jit_error.Success())
     {
         if (process && m_jit_alloc != LLDB_INVALID_ADDRESS)
-            m_jit_process_sp = process->shared_from_this();        
+            m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
         return true;
     }
     else

Modified: lldb/trunk/source/Expression/ClangUtilityFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUtilityFunction.cpp?rev=164082&r1=164081&r2=164082&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUtilityFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangUtilityFunction.cpp Mon Sep 17 19:08:47 2012
@@ -148,7 +148,7 @@
     }
     
     if (m_jit_start_addr != LLDB_INVALID_ADDRESS)
-        m_jit_process_sp = process->shared_from_this();
+        m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
     
 #if 0
 	// jingham: look here





More information about the lldb-commits mailing list