adb: clean up debug tracing a little.

Always use LOG() for debug tracing.
Remove useless D_lock. I believe it is useless to lock just before and after fprintf.

I verified the log output both on host and on device. The output looks fine to me.

Change-Id: I96ccfe408ff56864361551afe9ad464d197ae104
diff --git a/sysdeps_win32.cpp b/sysdeps_win32.cpp
index 015f89e..b53cd77 100644
--- a/sysdeps_win32.cpp
+++ b/sysdeps_win32.cpp
@@ -122,7 +122,7 @@
     // only need to check for INVALID_HANDLE_VALUE.
     if (h != INVALID_HANDLE_VALUE) {
         if (!CloseHandle(h)) {
-            D("CloseHandle(%p) failed: %s\n", h,
+            D("CloseHandle(%p) failed: %s", h,
               SystemErrorCodeToString(GetLastError()).c_str());
         }
     }
@@ -159,7 +159,7 @@
     if (file_size > 0) {
         data = (char*) malloc( file_size + 1 );
         if (data == NULL) {
-            D("load_file: could not allocate %ld bytes\n", file_size );
+            D("load_file: could not allocate %ld bytes", file_size );
             file_size = 0;
         } else {
             DWORD  out_bytes;
@@ -167,7 +167,7 @@
             if ( !ReadFile( file, data, file_size, &out_bytes, NULL ) ||
                  out_bytes != file_size )
             {
-                D("load_file: could not read %ld bytes from '%s'\n", file_size, fn);
+                D("load_file: could not read %ld bytes from '%s'", file_size, fn);
                 free(data);
                 data      = NULL;
                 file_size = 0;
@@ -229,7 +229,7 @@
     fd -= WIN32_FH_BASE;
 
     if (fd < 0 || fd >= WIN32_MAX_FHS) {
-        D( "_fh_from_int: invalid fd %d passed to %s\n", fd + WIN32_FH_BASE,
+        D( "_fh_from_int: invalid fd %d passed to %s", fd + WIN32_FH_BASE,
            func );
         errno = EBADF;
         return NULL;
@@ -238,7 +238,7 @@
     f = &_win32_fhs[fd];
 
     if (f->used == 0) {
-        D( "_fh_from_int: invalid fd %d passed to %s\n", fd + WIN32_FH_BASE,
+        D( "_fh_from_int: invalid fd %d passed to %s", fd + WIN32_FH_BASE,
            func );
         errno = EBADF;
         return NULL;
@@ -278,7 +278,7 @@
             goto Exit;
         }
     }
-    D( "_fh_alloc: no more free file descriptors\n" );
+    D( "_fh_alloc: no more free file descriptors" );
     errno = EMFILE;   // Too many open files
 Exit:
     if (f) {
@@ -349,7 +349,7 @@
     DWORD  read_bytes;
 
     if ( !ReadFile( f->fh_handle, buf, (DWORD)len, &read_bytes, NULL ) ) {
-        D( "adb_read: could not read %d bytes from %s\n", len, f->name );
+        D( "adb_read: could not read %d bytes from %s", len, f->name );
         errno = EIO;
         return -1;
     } else if (read_bytes < (DWORD)len) {
@@ -362,7 +362,7 @@
     DWORD  wrote_bytes;
 
     if ( !WriteFile( f->fh_handle, buf, (DWORD)len, &wrote_bytes, NULL ) ) {
-        D( "adb_file_write: could not write %d bytes from %s\n", len, f->name );
+        D( "adb_file_write: could not write %d bytes from %s", len, f->name );
         errno = EIO;
         return -1;
     } else if (wrote_bytes < (DWORD)len) {
@@ -422,7 +422,7 @@
             desiredAccess = GENERIC_READ | GENERIC_WRITE;
             break;
         default:
-            D("adb_open: invalid options (0x%0x)\n", options);
+            D("adb_open: invalid options (0x%0x)", options);
             errno = EINVAL;
             return -1;
     }
@@ -441,17 +441,17 @@
         D( "adb_open: could not open '%s': ", path );
         switch (err) {
             case ERROR_FILE_NOT_FOUND:
-                D( "file not found\n" );
+                D( "file not found" );
                 errno = ENOENT;
                 return -1;
 
             case ERROR_PATH_NOT_FOUND:
-                D( "path not found\n" );
+                D( "path not found" );
                 errno = ENOTDIR;
                 return -1;
 
             default:
-                D( "unknown error: %s\n",
+                D( "unknown error: %s",
                    SystemErrorCodeToString( err ).c_str() );
                 errno = ENOENT;
                 return -1;
@@ -459,7 +459,7 @@
     }
 
     snprintf( f->name, sizeof(f->name), "%d(%s)", _fh_to_int(f), path );
-    D( "adb_open: '%s' => fd %d\n", path, _fh_to_int(f) );
+    D( "adb_open: '%s' => fd %d", path, _fh_to_int(f) );
     return _fh_to_int(f);
 }
 
@@ -484,24 +484,24 @@
         D( "adb_creat: could not open '%s': ", path );
         switch (err) {
             case ERROR_FILE_NOT_FOUND:
-                D( "file not found\n" );
+                D( "file not found" );
                 errno = ENOENT;
                 return -1;
 
             case ERROR_PATH_NOT_FOUND:
-                D( "path not found\n" );
+                D( "path not found" );
                 errno = ENOTDIR;
                 return -1;
 
             default:
-                D( "unknown error: %s\n",
+                D( "unknown error: %s",
                    SystemErrorCodeToString( err ).c_str() );
                 errno = ENOENT;
                 return -1;
         }
     }
     snprintf( f->name, sizeof(f->name), "%d(%s)", _fh_to_int(f), path );
-    D( "adb_creat: '%s' => fd %d\n", path, _fh_to_int(f) );
+    D( "adb_creat: '%s' => fd %d", path, _fh_to_int(f) );
     return _fh_to_int(f);
 }
 
@@ -550,7 +550,7 @@
         return -1;
     }
 
-    D( "adb_close: %s\n", f->name);
+    D( "adb_close: %s", f->name);
     _fh_close(f);
     return 0;
 }
@@ -580,7 +580,7 @@
     case WSAEMFILE:      errno = EMFILE; break;
     default:
         errno = EINVAL;
-        D( "_socket_set_errno: mapping Windows error code %lu to errno %d\n",
+        D( "_socket_set_errno: mapping Windows error code %lu to errno %d",
            err, errno );
     }
 }
@@ -589,7 +589,7 @@
     f->fh_socket = INVALID_SOCKET;
     f->event     = WSACreateEvent();
     if (f->event == WSA_INVALID_EVENT) {
-        D("WSACreateEvent failed: %s\n",
+        D("WSACreateEvent failed: %s",
           SystemErrorCodeToString(WSAGetLastError()).c_str());
 
         // _event_socket_start assumes that this field is INVALID_HANDLE_VALUE
@@ -608,19 +608,19 @@
             // If the socket is not connected, this returns an error. We want to
             // minimize logging spam, so don't log these errors for now.
 #if 0
-            D("socket shutdown failed: %s\n",
+            D("socket shutdown failed: %s",
               SystemErrorCodeToString(WSAGetLastError()).c_str());
 #endif
         }
         if (closesocket(f->fh_socket) == SOCKET_ERROR) {
-            D("closesocket failed: %s\n",
+            D("closesocket failed: %s",
               SystemErrorCodeToString(WSAGetLastError()).c_str());
         }
         f->fh_socket = INVALID_SOCKET;
     }
     if (f->event != NULL) {
         if (!CloseHandle(f->event)) {
-            D("CloseHandle failed: %s\n",
+            D("CloseHandle failed: %s",
               SystemErrorCodeToString(GetLastError()).c_str());
         }
         f->event = NULL;
@@ -641,7 +641,7 @@
         // WSAEWOULDBLOCK is normal with a non-blocking socket, so don't trace
         // that to reduce spam and confusion.
         if (err != WSAEWOULDBLOCK) {
-            D("recv fd %d failed: %s\n", _fh_to_int(f),
+            D("recv fd %d failed: %s", _fh_to_int(f),
               SystemErrorCodeToString(err).c_str());
         }
         _socket_set_errno(err);
@@ -654,7 +654,7 @@
     int  result = send(f->fh_socket, reinterpret_cast<const char*>(buf), len, 0);
     if (result == SOCKET_ERROR) {
         const DWORD err = WSAGetLastError();
-        D("send fd %d failed: %s\n", _fh_to_int(f),
+        D("send fd %d failed: %s", _fh_to_int(f),
           SystemErrorCodeToString(err).c_str());
         _socket_set_errno(err);
         result = -1;
@@ -726,7 +726,7 @@
     if(s == INVALID_SOCKET) {
         *error = android::base::StringPrintf("cannot create socket: %s",
                 SystemErrorCodeToString(WSAGetLastError()).c_str());
-        D("%s\n", error->c_str());
+        D("%s", error->c_str());
         return -1;
     }
     f->fh_socket = s;
@@ -737,7 +737,7 @@
         *error = android::base::StringPrintf("cannot connect to %s:%u: %s",
                 inet_ntoa(addr.sin_addr), ntohs(addr.sin_port),
                 SystemErrorCodeToString(err).c_str());
-        D("could not connect to %s:%d: %s\n",
+        D("could not connect to %s:%d: %s",
           type != SOCK_STREAM ? "udp" : "tcp", port, error->c_str());
         return -1;
     }
@@ -745,7 +745,7 @@
     const int fd = _fh_to_int(f.get());
     snprintf( f->name, sizeof(f->name), "%d(lo-client:%s%d)", fd,
               type != SOCK_STREAM ? "udp:" : "", port );
-    D( "port %d type %s => fd %d\n", port, type != SOCK_STREAM ? "udp" : "tcp",
+    D( "port %d type %s => fd %d", port, type != SOCK_STREAM ? "udp" : "tcp",
        fd );
     f.release();
     return fd;
@@ -780,7 +780,7 @@
     if (s == INVALID_SOCKET) {
         *error = android::base::StringPrintf("cannot create socket: %s",
                 SystemErrorCodeToString(WSAGetLastError()).c_str());
-        D("%s\n", error->c_str());
+        D("%s", error->c_str());
         return -1;
     }
 
@@ -794,7 +794,7 @@
         *error = android::base::StringPrintf(
                 "cannot set socket option SO_EXCLUSIVEADDRUSE: %s",
                 SystemErrorCodeToString(WSAGetLastError()).c_str());
-        D("%s\n", error->c_str());
+        D("%s", error->c_str());
         return -1;
     }
 
@@ -804,7 +804,7 @@
         *error = android::base::StringPrintf("cannot bind to %s:%u: %s",
                 inet_ntoa(addr.sin_addr), ntohs(addr.sin_port),
                 SystemErrorCodeToString(err).c_str());
-        D("could not bind to %s:%d: %s\n",
+        D("could not bind to %s:%d: %s",
           type != SOCK_STREAM ? "udp" : "tcp", port, error->c_str());
         return -1;
     }
@@ -812,7 +812,7 @@
         if (listen(s, LISTEN_BACKLOG) == SOCKET_ERROR) {
             *error = android::base::StringPrintf("cannot listen on socket: %s",
                     SystemErrorCodeToString(WSAGetLastError()).c_str());
-            D("could not listen on %s:%d: %s\n",
+            D("could not listen on %s:%d: %s",
               type != SOCK_STREAM ? "udp" : "tcp", port, error->c_str());
             return -1;
         }
@@ -821,7 +821,7 @@
     snprintf( f->name, sizeof(f->name), "%d(%s-server:%s%d)", fd,
               interface_address == INADDR_LOOPBACK ? "lo" : "any",
               type != SOCK_STREAM ? "udp:" : "", port );
-    D( "port %d type %s => fd %d\n", port, type != SOCK_STREAM ? "udp" : "tcp",
+    D( "port %d type %s => fd %d", port, type != SOCK_STREAM ? "udp" : "tcp",
        fd );
     f.release();
     return fd;
@@ -865,7 +865,7 @@
         *error = android::base::StringPrintf(
                 "cannot resolve host '%s' and port %s: %s", host.c_str(),
                 port_str, SystemErrorCodeToString(WSAGetLastError()).c_str());
-        D("%s\n", error->c_str());
+        D("%s", error->c_str());
         return -1;
     }
     std::unique_ptr<struct addrinfo, decltype(freeaddrinfo)*>
@@ -880,7 +880,7 @@
     if(s == INVALID_SOCKET) {
         *error = android::base::StringPrintf("cannot create socket: %s",
                 SystemErrorCodeToString(WSAGetLastError()).c_str());
-        D("%s\n", error->c_str());
+        D("%s", error->c_str());
         return -1;
     }
     f->fh_socket = s;
@@ -892,7 +892,7 @@
         *error = android::base::StringPrintf("cannot connect to %s:%s: %s",
                 host.c_str(), port_str,
                 SystemErrorCodeToString(WSAGetLastError()).c_str());
-        D("could not connect to %s:%s:%s: %s\n",
+        D("could not connect to %s:%s:%s: %s",
           type != SOCK_STREAM ? "udp" : "tcp", host.c_str(), port_str,
           error->c_str());
         return -1;
@@ -901,7 +901,7 @@
     const int fd = _fh_to_int(f.get());
     snprintf( f->name, sizeof(f->name), "%d(net-client:%s%d)", fd,
               type != SOCK_STREAM ? "udp:" : "", port );
-    D( "host '%s' port %d type %s => fd %d\n", host.c_str(), port,
+    D( "host '%s' port %d type %s => fd %d", host.c_str(), port,
        type != SOCK_STREAM ? "udp" : "tcp", fd );
     f.release();
     return fd;
@@ -913,7 +913,7 @@
     FH   serverfh = _fh_from_int(serverfd, __func__);
 
     if ( !serverfh || serverfh->clazz != &_fh_socket_class ) {
-        D("adb_socket_accept: invalid fd %d\n", serverfd);
+        D("adb_socket_accept: invalid fd %d", serverfd);
         errno = EBADF;
         return -1;
     }
@@ -936,7 +936,7 @@
 
     const int fd = _fh_to_int(fh.get());
     snprintf( fh->name, sizeof(fh->name), "%d(accept:%s)", fd, serverfh->name );
-    D( "adb_socket_accept on fd %d returns fd %d\n", serverfd, fd );
+    D( "adb_socket_accept on fd %d returns fd %d", serverfd, fd );
     fh.release();
     return  fd;
 }
@@ -947,7 +947,7 @@
     FH   fh = _fh_from_int(fd, __func__);
 
     if ( !fh || fh->clazz != &_fh_socket_class ) {
-        D("adb_setsockopt: invalid fd %d\n", fd);
+        D("adb_setsockopt: invalid fd %d", fd);
         errno = EBADF;
         return -1;
     }
@@ -970,15 +970,15 @@
     FH   f = _fh_from_int(fd, __func__);
 
     if (!f || f->clazz != &_fh_socket_class) {
-        D("adb_shutdown: invalid fd %d\n", fd);
+        D("adb_shutdown: invalid fd %d", fd);
         errno = EBADF;
         return -1;
     }
 
-    D( "adb_shutdown: %s\n", f->name);
+    D( "adb_shutdown: %s", f->name);
     if (shutdown(f->fh_socket, SD_BOTH) == SOCKET_ERROR) {
         const DWORD err = WSAGetLastError();
-        D("socket shutdown fd %d failed: %s\n", fd,
+        D("socket shutdown fd %d failed: %s", fd,
           SystemErrorCodeToString(err).c_str());
         _socket_set_errno(err);
         return -1;
@@ -1073,7 +1073,7 @@
 static void
 bip_buffer_init( BipBuffer  buffer )
 {
-    D( "bit_buffer_init %p\n", buffer );
+    D( "bit_buffer_init %p", buffer );
     buffer->a_start   = 0;
     buffer->a_end     = 0;
     buffer->b_end     = 0;
@@ -1103,7 +1103,7 @@
 static void
 bip_buffer_done( BipBuffer  bip )
 {
-    BIPD(( "bip_buffer_done: %d->%d\n", bip->fdin, bip->fdout ));
+    BIPD(( "bip_buffer_done: %d->%d", bip->fdin, bip->fdout ));
     CloseHandle( bip->evt_read );
     CloseHandle( bip->evt_write );
     DeleteCriticalSection( &bip->lock );
@@ -1117,7 +1117,7 @@
     if (len <= 0)
         return 0;
 
-    BIPD(( "bip_buffer_write: enter %d->%d len %d\n", bip->fdin, bip->fdout, len ));
+    BIPD(( "bip_buffer_write: enter %d->%d len %d", bip->fdin, bip->fdout, len ));
     BIPDUMP( src, len );
 
     EnterCriticalSection( &bip->lock );
@@ -1133,7 +1133,7 @@
         /* spinlocking here is probably unfair, but let's live with it */
         ret = WaitForSingleObject( bip->evt_write, INFINITE );
         if (ret != WAIT_OBJECT_0) {  /* buffer probably closed */
-            D( "bip_buffer_write: error %d->%d WaitForSingleObject returned %d, error %ld\n", bip->fdin, bip->fdout, ret, GetLastError() );
+            D( "bip_buffer_write: error %d->%d WaitForSingleObject returned %d, error %ld", bip->fdin, bip->fdout, ret, GetLastError() );
             return 0;
         }
         if (bip->closed) {
@@ -1143,7 +1143,7 @@
         EnterCriticalSection( &bip->lock );
     }
 
-    BIPD(( "bip_buffer_write: exec %d->%d len %d\n", bip->fdin, bip->fdout, len ));
+    BIPD(( "bip_buffer_write: exec %d->%d len %d", bip->fdin, bip->fdout, len ));
 
     avail = BIP_BUFFER_SIZE - bip->a_end;
     if (avail > 0)
@@ -1191,7 +1191,7 @@
         SetEvent( bip->evt_read );
     }
 
-    BIPD(( "bip_buffer_write: exit %d->%d count %d (as=%d ae=%d be=%d cw=%d cr=%d\n",
+    BIPD(( "bip_buffer_write: exit %d->%d count %d (as=%d ae=%d be=%d cw=%d cr=%d",
             bip->fdin, bip->fdout, count, bip->a_start, bip->a_end, bip->b_end, bip->can_write, bip->can_read ));
     LeaveCriticalSection( &bip->lock );
 
@@ -1206,7 +1206,7 @@
     if (len <= 0)
         return 0;
 
-    BIPD(( "bip_buffer_read: enter %d->%d len %d\n", bip->fdin, bip->fdout, len ));
+    BIPD(( "bip_buffer_read: enter %d->%d len %d", bip->fdin, bip->fdout, len ));
 
     EnterCriticalSection( &bip->lock );
     while ( !bip->can_read )
@@ -1226,7 +1226,7 @@
 
         ret = WaitForSingleObject( bip->evt_read, INFINITE );
         if (ret != WAIT_OBJECT_0) { /* probably closed buffer */
-            D( "bip_buffer_read: error %d->%d WaitForSingleObject returned %d, error %ld\n", bip->fdin, bip->fdout, ret, GetLastError());
+            D( "bip_buffer_read: error %d->%d WaitForSingleObject returned %d, error %ld", bip->fdin, bip->fdout, ret, GetLastError());
             return 0;
         }
         if (bip->closed) {
@@ -1237,7 +1237,7 @@
 #endif
     }
 
-    BIPD(( "bip_buffer_read: exec %d->%d len %d\n", bip->fdin, bip->fdout, len ));
+    BIPD(( "bip_buffer_read: exec %d->%d len %d", bip->fdin, bip->fdout, len ));
 
     avail = bip->a_end - bip->a_start;
     assert( avail > 0 );  /* since can_read is TRUE */
@@ -1284,7 +1284,7 @@
     }
 
     BIPDUMP( (const unsigned char*)dst - count, count );
-    BIPD(( "bip_buffer_read: exit %d->%d count %d (as=%d ae=%d be=%d cw=%d cr=%d\n",
+    BIPD(( "bip_buffer_read: exit %d->%d count %d (as=%d ae=%d be=%d cw=%d cr=%d",
             bip->fdin, bip->fdout, count, bip->a_start, bip->a_end, bip->b_end, bip->can_write, bip->can_read ));
     LeaveCriticalSection( &bip->lock );
 
@@ -1397,7 +1397,7 @@
 
     pair = reinterpret_cast<SocketPair>(malloc(sizeof(*pair)));
     if (pair == NULL) {
-        D("adb_socketpair: not enough memory to allocate pipes\n" );
+        D("adb_socketpair: not enough memory to allocate pipes" );
         return -1;
     }
 
@@ -1419,7 +1419,7 @@
 
     snprintf( fa->name, sizeof(fa->name), "%d(pair:%d)", sv[0], sv[1] );
     snprintf( fb->name, sizeof(fb->name), "%d(pair:%d)", sv[1], sv[0] );
-    D( "adb_socketpair: returns (%d, %d)\n", sv[0], sv[1] );
+    D( "adb_socketpair: returns (%d, %d)", sv[0], sv[1] );
     fa.release();
     fb.release();
     return 0;
@@ -1575,7 +1575,7 @@
     EventHook   node;
 
     if (f == NULL)  /* invalid arg */ {
-        D("event_looper_hook: invalid fd=%d\n", fd);
+        D("event_looper_hook: invalid fd=%d", fd);
         return;
     }
 
@@ -1589,12 +1589,12 @@
 
     if ( (node->wanted & events) != events ) {
         /* this should update start/stop/check/peek */
-        D("event_looper_hook: call hook for %d (new=%x, old=%x)\n",
+        D("event_looper_hook: call hook for %d (new=%x, old=%x)",
            fd, node->wanted, events);
         f->clazz->_fh_hook( f, events & ~node->wanted, node );
         node->wanted |= events;
     } else {
-        D("event_looper_hook: ignoring events %x for %d wanted=%x)\n",
+        D("event_looper_hook: ignoring events %x for %d wanted=%x)",
            events, fd, node->wanted);
     }
 }
@@ -1609,7 +1609,7 @@
     if (node != NULL) {
         int  events2 = events & node->wanted;
         if ( events2 == 0 ) {
-            D( "event_looper_unhook: events %x not registered for fd %d\n", events, fd );
+            D( "event_looper_unhook: events %x not registered for fd %d", events, fd );
             return;
         }
         node->wanted &= ~events2;
@@ -1728,7 +1728,7 @@
     threads = (WaitForAllParam*)malloc((chunks + (remains ? 1 : 0)) *
                                         sizeof(WaitForAllParam));
     if (threads == NULL) {
-        D("Unable to allocate thread array for %d handles.\n", handles_count);
+        D("Unable to allocate thread array for %d handles.", handles_count);
         return (int)WAIT_FAILED;
     }
 
@@ -1736,7 +1736,7 @@
      * reset" event that will remain set once it was set. */
     main_event = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (main_event == NULL) {
-        D("Unable to create main event. Error: %ld\n", GetLastError());
+        D("Unable to create main event. Error: %ld", GetLastError());
         free(threads);
         return (int)WAIT_FAILED;
     }
@@ -1769,7 +1769,7 @@
                                                        &threads[chunk], 0, NULL);
         if (threads[chunk].thread == NULL) {
             /* Unable to create a waiter thread. Collapse. */
-            D("Unable to create a waiting thread %d of %d. errno=%d\n",
+            D("Unable to create a waiting thread %d of %d. errno=%d",
               chunk, chunks, errno);
             chunks = chunk;
             SetEvent(main_event);
@@ -1829,11 +1829,11 @@
         int  removes = events0 & ~events;
         int  adds    = events  & ~events0;
         if (removes) {
-            D("fdevent_update: remove %x from %d\n", removes, fde->fd);
+            D("fdevent_update: remove %x from %d", removes, fde->fd);
             event_looper_unhook( looper, fde->fd, removes );
         }
         if (adds) {
-            D("fdevent_update: add %x to %d\n", adds, fde->fd);
+            D("fdevent_update: add %x to %d", adds, fde->fd);
             event_looper_hook  ( looper, fde->fd, adds );
         }
     }
@@ -1865,7 +1865,7 @@
         for (hook = looper->hooks; hook; hook = hook->next)
         {
             if (hook->start && !hook->start(hook)) {
-                D( "fdevent_process: error when starting a hook\n" );
+                D( "fdevent_process: error when starting a hook" );
                 return;
             }
             if (hook->h != INVALID_HANDLE_VALUE) {
@@ -1883,7 +1883,7 @@
         }
 
         if (looper->htab_count == 0) {
-            D( "fdevent_process: nothing to wait for !!\n" );
+            D( "fdevent_process: nothing to wait for !!" );
             return;
         }
 
@@ -1891,17 +1891,17 @@
         {
             int   wait_ret;
 
-            D( "adb_win32: waiting for %d events\n", looper->htab_count );
+            D( "adb_win32: waiting for %d events", looper->htab_count );
             if (looper->htab_count > MAXIMUM_WAIT_OBJECTS) {
-                D("handle count %d exceeds MAXIMUM_WAIT_OBJECTS.\n", looper->htab_count);
+                D("handle count %d exceeds MAXIMUM_WAIT_OBJECTS.", looper->htab_count);
                 wait_ret = _wait_for_all(looper->htab, looper->htab_count);
             } else {
                 wait_ret = WaitForMultipleObjects( looper->htab_count, looper->htab, FALSE, INFINITE );
             }
             if (wait_ret == (int)WAIT_FAILED) {
-                D( "adb_win32: wait failed, error %ld\n", GetLastError() );
+                D( "adb_win32: wait failed, error %ld", GetLastError() );
             } else {
-                D( "adb_win32: got one (index %d)\n", wait_ret );
+                D( "adb_win32: got one (index %d)", wait_ret );
 
                 /* according to Cygwin, some objects like consoles wake up on "inappropriate" events
                  * like mouse movements. we need to filter these with the "check" function
@@ -1913,7 +1913,7 @@
                         if ( looper->htab[wait_ret] == hook->h       &&
                          (!hook->check || hook->check(hook)) )
                         {
-                            D( "adb_win32: signaling %s for %x\n", hook->fh->name, hook->ready );
+                            D( "adb_win32: signaling %s for %x", hook->fh->name, hook->ready );
                             event_hook_signal( hook );
                             gotone = 1;
                             break;
@@ -2205,14 +2205,14 @@
 
     hook->h = fh->event;
     if (hook->h == INVALID_HANDLE_VALUE) {
-        D( "_event_socket_start: no event for %s\n", fh->name );
+        D( "_event_socket_start: no event for %s", fh->name );
         return 0;
     }
 
     if ( flags != fh->mask ) {
-        D( "_event_socket_start: hooking %s for %x (flags %ld)\n", hook->fh->name, hook->wanted, flags );
+        D( "_event_socket_start: hooking %s for %x (flags %ld)", hook->fh->name, hook->wanted, flags );
         if ( WSAEventSelect( fh->fh_socket, hook->h, flags ) ) {
-            D( "_event_socket_start: WSAEventSelect() for %s failed, error %d\n", hook->fh->name, WSAGetLastError() );
+            D( "_event_socket_start: WSAEventSelect() for %s failed, error %d", hook->fh->name, WSAGetLastError() );
             CloseHandle( hook->h );
             hook->h = INVALID_HANDLE_VALUE;
             exit(1);
@@ -2241,7 +2241,7 @@
             ResetEvent( hook->h );
         }
     }
-    D( "_event_socket_check %s returns %d\n", fh->name, result );
+    D( "_event_socket_check %s returns %d", fh->name, result );
     return  result;
 }
 
@@ -2305,10 +2305,10 @@
         hook->h = wbip->evt_write;
 
     else {
-        D("_event_socketpair_start: can't handle FDE_READ+FDE_WRITE\n" );
+        D("_event_socketpair_start: can't handle FDE_READ+FDE_WRITE" );
         return 0;
     }
-    D( "_event_socketpair_start: hook %s for %x wanted=%x\n",
+    D( "_event_socketpair_start: hook %s for %x wanted=%x",
        hook->fh->name, _fh_to_int(fh), hook->wanted);
     return 1;
 }
@@ -3118,7 +3118,7 @@
             //
             // Consume the input and 'continue' to cause us to get a new key
             // event.
-            D("_console_read: unknown virtual key code: %d, enhanced: %s\n",
+            D("_console_read: unknown virtual key code: %d, enhanced: %s",
                 vk, _is_enhanced_key(control_key_state) ? "true" : "false");
             key_event->wRepeatCount = 0;
             continue;
@@ -3192,7 +3192,7 @@
         if (!SetConsoleMode(in, _old_console_mode & ~(ENABLE_PROCESSED_INPUT |
             ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT))) {
             // This really should not fail.
-            D("stdin_raw_init: SetConsoleMode() failed: %s\n",
+            D("stdin_raw_init: SetConsoleMode() failed: %s",
               SystemErrorCodeToString(GetLastError()).c_str());
         }
 
@@ -3214,7 +3214,7 @@
 
             if (!SetConsoleMode(in, _old_console_mode)) {
                 // This really should not fail.
-                D("stdin_raw_restore: SetConsoleMode() failed: %s\n",
+                D("stdin_raw_restore: SetConsoleMode() failed: %s",
                   SystemErrorCodeToString(GetLastError()).c_str());
             }
         }