mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 19:08:21 +08:00
Add a method to StreamFile to line buffer the file. Use that in "log enable -f file" to line buffer the log output.
llvm-svn: 124107
This commit is contained in:
@@ -61,6 +61,9 @@ public:
|
||||
|
||||
const char *
|
||||
GetFilePathname ();
|
||||
|
||||
void
|
||||
SetLineBuffered();
|
||||
|
||||
protected:
|
||||
//------------------------------------------------------------------
|
||||
|
||||
@@ -113,23 +113,30 @@ public:
|
||||
std::string channel(args.GetArgumentAtIndex(0));
|
||||
args.Shift (); // Shift off the channel
|
||||
StreamSP log_stream_sp;
|
||||
|
||||
StreamFile *log_file_ptr = NULL; // This will get put in the log_stream_sp, no need to free it.
|
||||
if (m_options.log_file.empty())
|
||||
{
|
||||
log_stream_sp.reset(new StreamFile(m_interpreter.GetDebugger().GetOutputFileHandle()));
|
||||
log_file_ptr = new StreamFile(m_interpreter.GetDebugger().GetOutputFileHandle());
|
||||
log_stream_sp.reset(log_file_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogStreamMap::iterator pos = m_log_streams.find(m_options.log_file);
|
||||
if (pos == m_log_streams.end())
|
||||
{
|
||||
log_stream_sp.reset (new StreamFile (m_options.log_file.c_str(), "w"));
|
||||
log_file_ptr = new StreamFile (m_options.log_file.c_str(), "w");
|
||||
log_stream_sp.reset (log_file_ptr);
|
||||
m_log_streams[m_options.log_file] = log_stream_sp;
|
||||
}
|
||||
else
|
||||
log_stream_sp = pos->second;
|
||||
}
|
||||
assert (log_stream_sp.get());
|
||||
|
||||
// If we ended up making a StreamFile for log output, line buffer it.
|
||||
if (log_file_ptr != NULL)
|
||||
log_file_ptr->SetLineBuffered();
|
||||
|
||||
uint32_t log_options = m_options.log_options;
|
||||
if (log_options == 0)
|
||||
log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE;
|
||||
|
||||
@@ -94,6 +94,13 @@ StreamFile::Open (const char *path, const char *permissions)
|
||||
return m_file != NULL;
|
||||
}
|
||||
|
||||
void
|
||||
StreamFile::SetLineBuffered ()
|
||||
{
|
||||
if (m_file != NULL)
|
||||
setlinebuf (m_file);
|
||||
}
|
||||
|
||||
void
|
||||
StreamFile::Flush ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user