mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
<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
llvm-svn: 166058
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -35,15 +35,27 @@ public:
|
||||
const char *
|
||||
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);
|
||||
|
||||
|
||||
@@ -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, ...)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user