[Lldb-commits] [lldb] r124107 - in /lldb/trunk: include/lldb/Core/StreamFile.h source/Commands/CommandObjectLog.cpp source/Core/StreamFile.cpp

Jim Ingham jingham at apple.com
Sun Jan 23 20:09:26 PST 2011


Author: jingham
Date: Sun Jan 23 22:09:25 2011
New Revision: 124107

URL: http://llvm.org/viewvc/llvm-project?rev=124107&view=rev
Log:
Add a method to StreamFile to line buffer the file.  Use  that in "log enable -f file" to line buffer the log output.

Modified:
    lldb/trunk/include/lldb/Core/StreamFile.h
    lldb/trunk/source/Commands/CommandObjectLog.cpp
    lldb/trunk/source/Core/StreamFile.cpp

Modified: lldb/trunk/include/lldb/Core/StreamFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StreamFile.h?rev=124107&r1=124106&r2=124107&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/StreamFile.h (original)
+++ lldb/trunk/include/lldb/Core/StreamFile.h Sun Jan 23 22:09:25 2011
@@ -61,6 +61,9 @@
 
     const char *
     GetFilePathname ();
+    
+    void
+    SetLineBuffered();
 
 protected:
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Commands/CommandObjectLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectLog.cpp?rev=124107&r1=124106&r2=124107&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectLog.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectLog.cpp Sun Jan 23 22:09:25 2011
@@ -113,23 +113,30 @@
             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;

Modified: lldb/trunk/source/Core/StreamFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamFile.cpp?rev=124107&r1=124106&r2=124107&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamFile.cpp (original)
+++ lldb/trunk/source/Core/StreamFile.cpp Sun Jan 23 22:09:25 2011
@@ -95,6 +95,13 @@
 }
 
 void
+StreamFile::SetLineBuffered ()
+{
+    if (m_file != NULL)
+        setlinebuf (m_file);
+}
+
+void
 StreamFile::Flush ()
 {
     if (m_file)





More information about the lldb-commits mailing list