[Lldb-commits] [lldb] r346174 - Set stdout/stdin to binary mode on Windows

Nathan Lanza via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 5 14:25:00 PST 2018


Author: lanza
Date: Mon Nov  5 14:25:00 2018
New Revision: 346174

URL: http://llvm.org/viewvc/llvm-project?rev=346174&view=rev
Log:
Set stdout/stdin to binary mode on Windows

Summary:
A file opened in text mode on Windows will have `\n` automatically changed to `13,10` while Darwin and Linux leave it as `10`.

Set the file to binary mode to avoid this automatic conversion so that Darwin, Linux and Windows have equivalent treatment of `\r`.

Reviewers: clayborg, xiaobai

Reviewed By: clayborg

Subscribers: emaste, ki.stfu, mgorny, eraman, JDevlieghere, mgrang

Differential Revision: https://reviews.llvm.org/D52672

Modified:
    lldb/trunk/tools/lldb-vscode/VSCode.cpp

Modified: lldb/trunk/tools/lldb-vscode/VSCode.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-vscode/VSCode.cpp?rev=346174&r1=346173&r2=346174&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-vscode/VSCode.cpp (original)
+++ lldb/trunk/tools/lldb-vscode/VSCode.cpp Mon Nov  5 14:25:00 2018
@@ -14,6 +14,11 @@
 #include "VSCode.h"
 #include "LLDBUtils.h"
 
+#if defined(_WIN32)
+#include <io.h>
+#include <fcntl.h>
+#endif
+
 using namespace lldb_vscode;
 
 namespace {
@@ -39,6 +44,13 @@ VSCode::VSCode()
       focus_tid(LLDB_INVALID_THREAD_ID), sent_terminated_event(false),
       stop_at_entry(false) {
   const char *log_file_path = getenv("LLDBVSCODE_LOG");
+#if defined(_WIN32)
+// Windows opens stdout and stdin in text mode which converts \n to 13,10
+// while the value is just 10 on Darwin/Linux. Setting the file mode to binary
+// fixes this.
+  assert(_setmode(fileno(stdout), _O_BINARY));
+  assert(_setmode(fileno(stdin), _O_BINARY));
+#endif
   if (log_file_path)
     log.reset(new std::ofstream(log_file_path));
 }




More information about the lldb-commits mailing list