Index: /trunk/source/lisp-kernel/lisp-debug.c
===================================================================
--- /trunk/source/lisp-kernel/lisp-debug.c	(revision 12712)
+++ /trunk/source/lisp-kernel/lisp-debug.c	(revision 12713)
@@ -28,5 +28,7 @@
 #include <stdio.h>
 
-#ifndef WINDOWS
+#ifdef WINDOWS
+#include <fcntl.h>
+#else
 #include <sys/socket.h>
 #include <dlfcn.h>
@@ -100,6 +102,16 @@
           (fd0stat.st_dev == devnullstat.st_dev));
 }
-
-#endif
+#endif
+
+#ifdef WINDOWS
+Boolean
+stdin_is_dev_null()
+{
+  HANDLE stdIn;
+  stdIn = GetStdHandle(STD_INPUT_HANDLE);
+  return (stdIn == NULL);
+}
+#endif
+
 
 char *
@@ -145,4 +157,6 @@
     switch(c) {
     case '\n':
+      continue;
+    case '\r':
       continue;
     case EOF:
@@ -1108,4 +1122,8 @@
 #endif
 
+#ifdef WINDOWS
+Boolean first_debugger_call = TRUE;
+#endif
+
 
 OSStatus
@@ -1120,15 +1138,47 @@
   debug_command_return state = debug_continue;
 
+#ifdef WINDOWS
+  HANDLE h;
+  int fd;
+  FILE *f;
+
+  if (first_debugger_call) {
+    first_debugger_call = FALSE;
+    if (stdin_is_dev_null())
+      AllocConsole();
+    // Reassociate C's stdin with Windows' stdin
+    h = GetStdHandle(STD_INPUT_HANDLE);
+    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
+    if (fd >= 0) {
+      f = _fdopen(fd, "r");
+      *stdin = *f;
+    }
+    // Reassociate C's stdout with Windows' stdout
+    h = GetStdHandle(STD_OUTPUT_HANDLE);
+    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
+    if (fd >= 0) {
+      f = _fdopen(fd, "w");
+      *stdout = *f;
+    }
+    // Reassociate C's stderr with Windows' stderr
+    h = GetStdHandle(STD_ERROR_HANDLE);
+    fd = _open_osfhandle((intptr_t)h, _O_TEXT);
+    if (fd >= 0) {
+      f = _fdopen(fd, "w");
+      *stderr = *f;
+    }
+    dbgout = stderr;
+  }
+#endif
+
+  if (stdin_is_dev_null()) {
+    return -1;
+  }
+
   va_start(args,message);
   vfprintf(dbgout, message, args);
   fprintf(dbgout, "\n");
   va_end(args);
-  
-
-#ifndef WINDOWS
-  if (stdin_is_dev_null()) {
-    return -1;
-  }
-#endif
+
   if (threads_initialized) {
     suspend_other_threads(false);
