<rdar://problem/12446320> Fixing an issue with our Driver where setting an immediate...
authorEnrico Granata <egranata@apple.com>
Tue, 16 Oct 2012 20:57:12 +0000 (20:57 +0000)
committerEnrico Granata <egranata@apple.com>
Tue, 16 Oct 2012 20:57:12 +0000 (20:57 +0000)
llvm-svn: 166058

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

index 1dc632c..5de54f7 100644 (file)
@@ -92,6 +92,18 @@ public:
     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;
index 82c07ee..81e85ca 100644 (file)
@@ -36,14 +36,26 @@ public:
     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);
 
index 4632009..e923bba 100644 (file)
@@ -268,7 +268,7 @@ SBCommandReturnObject::SetImmediateOutputFile (FILE *fh)
     if (m_opaque_ap.get())
         m_opaque_ap->SetImmediateOutputFile (fh);
 }
-    
+
 void
 SBCommandReturnObject::SetImmediateErrorFile (FILE *fh)
 {
@@ -285,6 +285,46 @@ SBCommandReturnObject::PutCString(const char* string, int len)
     }
 }
 
+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, ...)
 {
index 29bbbc4..da65e6d 100644 (file)
@@ -18,10 +18,11 @@ def target_name_impl(debugger, args, result, dict):
         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
index 048faff..11db9b2 100644 (file)
@@ -1020,11 +1020,17 @@ Driver::HandleIOEvent (const SBEvent &event)
         // 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.
index b6d4224..ade07b0 100644 (file)
@@ -528,7 +528,7 @@ IOChannel::RefreshPrompt ()
 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 @@ IOChannel::OutWrite (const char *buffer, size_t len, bool asynchronous)
 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.