Debug: add trace to debug out

If enabled, TRACE macros (in Reactor and Vulkan) will use
OutputDebugString on Windows, printf otherwise, to print the trace. On
Windows, this allows us to use DbgView to monitor and filter the trace
easily, especially useful when running with Chrome, for e.g.

Bug: b/146051794
Change-Id: I15a46f5f0e8bc4e9edcacaf63c15dc605323356d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39568
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Reactor/Debug.cpp b/src/Reactor/Debug.cpp
index 65a894f..0e87015 100644
--- a/src/Reactor/Debug.cpp
+++ b/src/Reactor/Debug.cpp
@@ -14,15 +14,34 @@
 
 #include "Debug.hpp"
 
-#include <stdarg.h>
+#include <cstdarg>
+#include <cstdio>
 #include <string>
 
+#if defined(_WIN32)
+#	include <windows.h>
+#endif
+
 namespace rr {
 
 void tracev(const char *format, va_list args)
 {
 #ifndef RR_DISABLE_TRACE
-	if(false)
+	const bool traceToDebugOut = false;
+	const bool traceToFile = false;
+
+	if(traceToDebugOut)
+	{
+		char buffer[2048];
+		vsnprintf(buffer, sizeof(buffer), format, args);
+#	if defined(_WIN32)
+		::OutputDebugString(buffer);
+#	else
+		printf("%s", buffer);
+#	endif
+	}
+
+	if(traceToFile)
 	{
 		FILE *file = fopen(TRACE_OUTPUT_FILE, "a");
 
diff --git a/src/Vulkan/VkDebug.cpp b/src/Vulkan/VkDebug.cpp
index ba4a5f8..d841366 100644
--- a/src/Vulkan/VkDebug.cpp
+++ b/src/Vulkan/VkDebug.cpp
@@ -14,8 +14,9 @@
 
 #include "VkDebug.hpp"
 
-#include <stdarg.h>
 #include <atomic>
+#include <cstdarg>
+#include <cstdio>
 #include <string>
 
 #if defined(__unix__)
@@ -90,7 +91,21 @@
 void tracev(const char *format, va_list args)
 {
 #ifndef SWIFTSHADER_DISABLE_TRACE
-	if(false)
+	const bool traceToDebugOut = false;
+	const bool traceToFile = false;
+
+	if(traceToDebugOut)
+	{
+		char buffer[2048];
+		vsnprintf(buffer, sizeof(buffer), format, args);
+#	if defined(_WIN32)
+		::OutputDebugString(buffer);
+#	else
+		printf("%s", buffer);
+#	endif
+	}
+
+	if(traceToFile)
 	{
 		FILE *file = fopen(TRACE_OUTPUT_FILE, "a");
 
@@ -100,7 +115,7 @@
 			fclose(file);
 		}
 	}
-#endif
+#endif  // SWIFTSHADER_DISABLE_TRACE
 }
 
 void trace(const char *format, ...)