[Lldb-commits] [lldb] r166058 - in /lldb/trunk: include/lldb/API/SBCommandReturnObject.h scripts/Python/interface/SBCommandReturnObject.i source/API/SBCommandReturnObject.cpp test/functionalities/command_script/welcome.py tools/driver/Driver.cpp tools/driver/IOChannel.cpp

Enrico Granata egranata at apple.com
Tue Oct 16 13:57:13 PDT 2012


Author: enrico
Date: Tue Oct 16 15:57:12 2012
New Revision: 166058

URL: http://llvm.org/viewvc/llvm-project?rev=166058&view=rev
Log:
<rdar://problem/12446320> Fixing an issue with our Driver where setting an immediate output would not cause suppression of the final printout. This allows effective output redirection for Python commands

Modified:
    lldb/trunk/include/lldb/API/SBCommandReturnObject.h
    lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i
    lldb/trunk/source/API/SBCommandReturnObject.cpp
    lldb/trunk/test/functionalities/command_script/welcome.py
    lldb/trunk/tools/driver/Driver.cpp
    lldb/trunk/tools/driver/IOChannel.cpp

Modified: lldb/trunk/include/lldb/API/SBCommandReturnObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBCommandReturnObject.h?rev=166058&r1=166057&r2=166058&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBCommandReturnObject.h (original)
+++ lldb/trunk/include/lldb/API/SBCommandReturnObject.h Tue Oct 16 15:57:12 2012
@@ -92,6 +92,18 @@
     size_t
     Printf(const char* format, ...)  __attribute__ ((format (printf, 2, 3)));
     
+    const char *
+    GetOutput (bool only_if_no_immediate);
+    
+    const char *
+    GetError (bool only_if_no_immediate);
+    
+    size_t
+    GetErrorSize (bool only_if_no_immediate);
+    
+    size_t
+    GetOutputSize (bool only_if_no_immediate);
+    
 protected:
     friend class SBCommandInterpreter;
     friend class SBOptions;

Modified: lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i?rev=166058&r1=166057&r2=166058&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i (original)
+++ lldb/trunk/scripts/Python/interface/SBCommandReturnObject.i Tue Oct 16 15:57:12 2012
@@ -36,14 +36,26 @@
     GetError ();
 
     size_t
-    PutOutput (FILE *fh);
-
-    size_t
     GetOutputSize ();
 
     size_t
     GetErrorSize ();
 
+    const char *
+    GetOutput (bool only_if_no_immediate);
+    
+    const char *
+    GetError (bool if_no_immediate);
+    
+    size_t
+    GetErrorSize (bool only_if_no_immediate);
+    
+    size_t
+    GetOutputSize (bool only_if_no_immediate);
+    
+    size_t
+    PutOutput (FILE *fh);
+    
     size_t
     PutError (FILE *fh);
 

Modified: lldb/trunk/source/API/SBCommandReturnObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandReturnObject.cpp?rev=166058&r1=166057&r2=166058&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandReturnObject.cpp (original)
+++ lldb/trunk/source/API/SBCommandReturnObject.cpp Tue Oct 16 15:57:12 2012
@@ -268,7 +268,7 @@
     if (m_opaque_ap.get())
         m_opaque_ap->SetImmediateOutputFile (fh);
 }
-    
+
 void
 SBCommandReturnObject::SetImmediateErrorFile (FILE *fh)
 {
@@ -285,6 +285,46 @@
     }
 }
 
+const char *
+SBCommandReturnObject::GetOutput (bool only_if_no_immediate)
+{
+    if (!m_opaque_ap.get())
+        return NULL;
+    if (only_if_no_immediate == false || m_opaque_ap->GetImmediateOutputStream().get() == NULL)
+        return GetOutput();
+    return NULL;
+}
+
+const char *
+SBCommandReturnObject::GetError (bool only_if_no_immediate)
+{
+    if (!m_opaque_ap.get())
+        return NULL;
+    if (only_if_no_immediate == false || m_opaque_ap->GetImmediateErrorStream().get() == NULL)
+        return GetError();
+    return NULL;
+}
+
+size_t
+SBCommandReturnObject::GetErrorSize (bool only_if_no_immediate)
+{
+    if (!m_opaque_ap.get())
+        return NULL;
+    if (only_if_no_immediate == false || m_opaque_ap->GetImmediateErrorStream().get() == NULL)
+        return GetErrorSize();
+    return NULL;
+}
+
+size_t
+SBCommandReturnObject::GetOutputSize (bool only_if_no_immediate)
+{
+    if (!m_opaque_ap.get())
+        return NULL;
+    if (only_if_no_immediate == false || m_opaque_ap->GetImmediateOutputStream().get() == NULL)
+        return GetOutputSize();
+    return NULL;
+}
+
 size_t
 SBCommandReturnObject::Printf(const char* format, ...)
 {

Modified: lldb/trunk/test/functionalities/command_script/welcome.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/command_script/welcome.py?rev=166058&r1=166057&r2=166058&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/command_script/welcome.py (original)
+++ lldb/trunk/test/functionalities/command_script/welcome.py Tue Oct 16 15:57:12 2012
@@ -18,10 +18,11 @@
         return None
 
 def print_wait_impl(debugger, args, result, dict):
-    print 'Trying to do long task..';
+    result.SetImmediateOutputFile(sys.stdout)
+    result.PutCString('Trying to do long task..')
     import time
     time.sleep(1)
-    print 'Still doing long task..';
+    result.PutCString('Still doing long task..')
     time.sleep(1)
     result.PutCString('Done; if you saw the delays I am doing OK')
     return None

Modified: lldb/trunk/tools/driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/Driver.cpp?rev=166058&r1=166057&r2=166058&view=diff
==============================================================================
--- lldb/trunk/tools/driver/Driver.cpp (original)
+++ lldb/trunk/tools/driver/Driver.cpp Tue Oct 16 15:57:12 2012
@@ -1020,11 +1020,17 @@
         // output orderings and problems with the prompt.
         m_debugger.GetCommandInterpreter().HandleCommand (command_string, result, true);
 
-        if (result.GetOutputSize() > 0)
-            m_io_channel_ap->OutWrite (result.GetOutput(), result.GetOutputSize(), NO_ASYNC);
-            
-        if (result.GetErrorSize() > 0)
-            m_io_channel_ap->OutWrite (result.GetError(), result.GetErrorSize(), NO_ASYNC);
+        const bool only_if_no_immediate = true;
+
+        const size_t output_size = result.GetOutputSize(only_if_no_immediate);
+        
+        if (output_size > 0)
+            m_io_channel_ap->OutWrite (result.GetOutput(only_if_no_immediate), output_size, NO_ASYNC);
+
+        const size_t error_size = result.GetErrorSize(only_if_no_immediate);
+
+        if (error_size > 0)
+            m_io_channel_ap->OutWrite (result.GetError(only_if_no_immediate), error_size, NO_ASYNC);
 
         // We are done getting and running our command, we can now clear the
         // m_waiting_for_command so we can get another one.

Modified: lldb/trunk/tools/driver/IOChannel.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/driver/IOChannel.cpp?rev=166058&r1=166057&r2=166058&view=diff
==============================================================================
--- lldb/trunk/tools/driver/IOChannel.cpp (original)
+++ lldb/trunk/tools/driver/IOChannel.cpp Tue Oct 16 15:57:12 2012
@@ -528,7 +528,7 @@
 void
 IOChannel::OutWrite (const char *buffer, size_t len, bool asynchronous)
 {
-    if (len == 0)
+    if (len == 0 || buffer == NULL)
         return;
 
     // We're in the process of exiting -- IOChannel::Run() has already completed
@@ -552,7 +552,7 @@
 void
 IOChannel::ErrWrite (const char *buffer, size_t len, bool asynchronous)
 {
-    if (len == 0)
+    if (len == 0 || buffer == NULL)
         return;
 
     // Use the mutex to make sure OutWrite and ErrWrite do not interfere with each other's output.





More information about the lldb-commits mailing list