Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr. r=Yoric
authorsourav3 <sourav.mukherjee619@gmail.com>
Thu, 21 Sep 2017 17:06:51 +0800
changeset 435469 83afa692da84387ded48b42f36f05911a4cbadb0
parent 435468 2b87ee06ac0478e58c7a20be52b413f73ee630dc
child 435470 ae7f9f3bbec21bcecdf98fcae2312a34f9008eb2
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1399777
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1399777 Fprinter directing output to Windows debug console when it outputs to stderr. r=Yoric MozReview-Commit-ID: 81ubXofHIlG *** Using PodCopy instead of std::copy and fixing spaces
js/src/vm/Printer.cpp
--- a/js/src/vm/Printer.cpp
+++ b/js/src/vm/Printer.cpp
@@ -13,16 +13,20 @@
 #include <stdarg.h>
 #include <stdio.h>
 
 #include "jscntxt.h"
 #include "jsutil.h"
 
 #include "ds/LifoAlloc.h"
 
+#ifdef XP_WIN32
+#include "jswin.h"
+#endif
+
 using mozilla::PodCopy;
 
 namespace
 {
 
 class GenericPrinterPrintfTarget : public mozilla::PrintfTarget
 {
 public:
@@ -445,16 +449,28 @@ bool
 Fprinter::put(const char* s, size_t len)
 {
     MOZ_ASSERT(file_);
     int i = fwrite(s, /*size=*/ 1, /*nitems=*/ len, file_);
     if (size_t(i) != len) {
         reportOutOfMemory();
         return false;
     }
+#ifdef XP_WIN32
+    if ((file_ == stderr) && (IsDebuggerPresent())) {
+        UniqueChars buf(static_cast<char*>(js_malloc(len + 1)));
+        if (!buf) {
+            reportOutOfMemory();
+            return false;
+        }
+        PodCopy(buf.get(), s, len);
+        buf[len] = '\0';
+        OutputDebugStringA(buf.get());
+    }
+#endif
     return true;
 }
 
 LSprinter::LSprinter(LifoAlloc* lifoAlloc)
   : alloc_(lifoAlloc),
     head_(nullptr),
     tail_(nullptr),
     unused_(0)