[Lldb-commits] [lldb] r236824 - Print process's output line by line (MI)

Ilia K ki.stfu at gmail.com
Fri May 8 03:52:51 PDT 2015


Author: ki.stfu
Date: Fri May  8 05:52:50 2015
New Revision: 236824

URL: http://llvm.org/viewvc/llvm-project?rev=236824&view=rev
Log:
Print process's output line by line (MI)

For example:
was:
```
@"'\r\n` - it's \\ni=1\r\nj=2\r\nx=3\r\ny=4\r\nargc: /Users/IliaK/p/hello\r\nargc: (null)\r\n"
```

now:
```
@"'\r\n"
@"` - it's \\ni=1\r\n"
@"j=2\r\n"
@"x=3\r\n"
@"y=4\r\n"
@"argc: /Users/IliaK/p/hello\r\n"
@"argc: (null)\r\n"
```


Modified:
    lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py
    lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp

Modified: lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py?rev=236824&r1=236823&r2=236824&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py (original)
+++ lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py Fri May  8 05:52:50 2015
@@ -75,7 +75,8 @@ class MiSyntaxTestCase(lldbmi_testcase.M
         self.expect("\^running")
 
         # Test that a process output is wrapped correctly
-        self.expect("\@\"'\\\\r\\\\n` - it's \\\\\\\\n\\\\x12\\\\\"\\\\\\\\\\\\\"")
+        self.expect("\@\"'\\\\r\\\\n\"")
+        self.expect("\@\"` - it's \\\\\\\\n\\\\x12\\\\\"\\\\\\\\\\\\\"")
 
 if __name__ == '__main__':
     unittest2.main()

Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp?rev=236824&r1=236823&r2=236824&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp Fri May  8 05:52:50 2015
@@ -1526,19 +1526,38 @@ CMICmnLLDBDebuggerHandleEvents::GetProce
     while (1)
     {
         const size_t nBytes = process.GetSTDOUT(apStdoutBuffer.get(), 1024);
+        text.append(apStdoutBuffer.get(), nBytes);
+
+        while (1)
+        {
+            const size_t nNewLine = text.find('\n');
+            if (nNewLine == std::string::npos)
+                break;
+
+            const CMIUtilString line(text.substr(0, nNewLine + 1).c_str());
+            text.erase(0, nNewLine + 1);
+            const bool bEscapeQuotes(true);
+            CMICmnMIValueConst miValueConst(line.Escape(bEscapeQuotes));
+            CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
+            const bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
+            if (!bOk)
+                return MIstatus::failure;
+        }
+
         if (nBytes == 0)
+        {
+            if (!text.empty())
+            {
+                const bool bEscapeQuotes(true);
+                CMICmnMIValueConst miValueConst(text.Escape(bEscapeQuotes));
+                CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
+                return MiOutOfBandRecordToStdout(miOutOfBandRecord);
+            }
             break;
-
-        text.append(apStdoutBuffer.get(), nBytes);
+        }
     }
 
-    if (text.empty())
-        return MIstatus::success;
-
-    const bool bEscapeQuotes(true);
-    CMICmnMIValueConst miValueConst(text.Escape(bEscapeQuotes));
-    CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
-    return MiOutOfBandRecordToStdout(miOutOfBandRecord);
+    return MIstatus::success;
 }
 
 //++ ------------------------------------------------------------------------------------
@@ -1560,19 +1579,37 @@ CMICmnLLDBDebuggerHandleEvents::GetProce
     while (1)
     {
         const size_t nBytes = process.GetSTDERR(apStderrBuffer.get(), 1024);
+        text.append(apStderrBuffer.get(), nBytes);
+
+        while (1)
+        {
+            const size_t nNewLine = text.find('\n');
+            if (nNewLine == std::string::npos)
+                break;
+
+            const CMIUtilString line(text.substr(0, nNewLine + 1).c_str());
+            const bool bEscapeQuotes(true);
+            CMICmnMIValueConst miValueConst(line.Escape(bEscapeQuotes));
+            CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
+            const bool bOk = MiOutOfBandRecordToStdout(miOutOfBandRecord);
+            if (!bOk)
+                return MIstatus::failure;
+        }
+
         if (nBytes == 0)
+        {
+            if (!text.empty())
+            {
+                const bool bEscapeQuotes(true);
+                CMICmnMIValueConst miValueConst(text.Escape(bEscapeQuotes));
+                CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
+                return MiOutOfBandRecordToStdout(miOutOfBandRecord);
+            }
             break;
-
-        text.append(apStderrBuffer.get(), nBytes);
+        }
     }
 
-    if (text.empty())
-        return MIstatus::success;
-
-    const bool bEscapeQuotes(true);
-    CMICmnMIValueConst miValueConst(text.Escape(bEscapeQuotes));
-    CMICmnMIOutOfBandRecord miOutOfBandRecord(CMICmnMIOutOfBandRecord::eOutOfBand_TargetStreamOutput, miValueConst);
-    return MiOutOfBandRecordToStdout(miOutOfBandRecord);
+    return MIstatus::success;
 }
 
 //++ ------------------------------------------------------------------------------------





More information about the lldb-commits mailing list