Improve adb tracing.

The existing format was unreadable; putting the pid and tid first helps
somewhat. Also remove the unused qemu tracing which wasn't called anywhere.

Change-Id: I37ef3c556fe17b237ba1d8ca3216e2155ce5d0de
diff --git a/Android.mk b/Android.mk
index df0c7a1..f9d4441 100644
--- a/Android.mk
+++ b/Android.mk
@@ -88,7 +88,6 @@
     adb_auth_client.cpp \
     fdevent.cpp \
     jdwp_service.cpp \
-    qemu_tracing.cpp \
     usb_linux_client.cpp \
 
 LOCAL_SANITIZE := $(adb_target_sanitize)
diff --git a/adb_trace.h b/adb_trace.h
index dbc7ec8..4e03165 100644
--- a/adb_trace.h
+++ b/adb_trace.h
@@ -40,22 +40,7 @@
     TRACE_SERVICES,
     TRACE_AUTH,
     TRACE_FDEVENT,
-} ;
-
-#if !ADB_HOST
-/*
- * When running inside the emulator, guest's adbd can connect to 'adb-debug'
- * qemud service that can display adb trace messages (on condition that emulator
- * has been started with '-debug adb' option).
- */
-
-/* Delivers a trace message to the emulator via QEMU pipe. */
-void adb_qemu_trace(const char* fmt, ...);
-/* Macro to use to send ADB trace messages to the emulator. */
-#define DQ(...)    adb_qemu_trace(__VA_ARGS__)
-#else
-#define DQ(...) ((void)0)
-#endif  /* !ADB_HOST */
+};
 
 extern int adb_trace_mask;
 extern unsigned char adb_trace_output_count;
@@ -65,51 +50,43 @@
 
 /* you must define TRACE_TAG before using this macro */
 #if ADB_HOST
-#  define  D(...)                                      \
-        do {                                           \
-            if (ADB_TRACING) {                         \
-                int save_errno = errno;                \
-                adb_mutex_lock(&D_lock);               \
-                fprintf(stderr, "%16s: %5d:%5lu | ",   \
-                        __FUNCTION__,                  \
-                        getpid(), adb_thread_id());    \
-                errno = save_errno;                    \
-                fprintf(stderr, __VA_ARGS__ );         \
-                fflush(stderr);                        \
-                adb_mutex_unlock(&D_lock);             \
-                errno = save_errno;                    \
-           }                                           \
+#  define D(fmt, ...) \
+        do { \
+            if (ADB_TRACING) { \
+                int saved_errno = errno; \
+                adb_mutex_lock(&D_lock); \
+                errno = saved_errno; \
+                fprintf(stderr, "%5d:%5lu %s | " fmt, \
+                        getpid(), adb_thread_id(), __FUNCTION__, ## __VA_ARGS__); \
+                fflush(stderr); \
+                adb_mutex_unlock(&D_lock); \
+                errno = saved_errno; \
+           } \
         } while (0)
-#  define  DR(...)                                     \
-        do {                                           \
-            if (ADB_TRACING) {                         \
-                int save_errno = errno;                \
-                adb_mutex_lock(&D_lock);               \
-                errno = save_errno;                    \
-                fprintf(stderr, __VA_ARGS__ );         \
-                fflush(stderr);                        \
-                adb_mutex_unlock(&D_lock);             \
-                errno = save_errno;                    \
-           }                                           \
+#  define DR(...) \
+        do { \
+            if (ADB_TRACING) { \
+                int saved_errno = errno; \
+                adb_mutex_lock(&D_lock); \
+                errno = saved_errno; \
+                fprintf(stderr, __VA_ARGS__); \
+                fflush(stderr); \
+                adb_mutex_unlock(&D_lock); \
+                errno = saved_errno; \
+           } \
         } while (0)
 #else
-#  define  D(...)                                      \
-        do {                                           \
-            if (ADB_TRACING) {                         \
-                __android_log_print(                   \
-                    ANDROID_LOG_INFO,                  \
-                    __FUNCTION__,                      \
-                    __VA_ARGS__ );                     \
-            }                                          \
+#  define D(...) \
+        do { \
+            if (ADB_TRACING) { \
+                __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, __VA_ARGS__); \
+            } \
         } while (0)
-#  define  DR(...)                                     \
-        do {                                           \
-            if (ADB_TRACING) {                         \
-                __android_log_print(                   \
-                    ANDROID_LOG_INFO,                  \
-                    __FUNCTION__,                      \
-                    __VA_ARGS__ );                     \
-            }                                          \
+#  define DR(...) \
+        do { \
+            if (ADB_TRACING) { \
+                __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, __VA_ARGS__); \
+            } \
         } while (0)
 #endif /* ADB_HOST */
 
diff --git a/daemon/main.cpp b/daemon/main.cpp
index dc89639..2eba625 100644
--- a/daemon/main.cpp
+++ b/daemon/main.cpp
@@ -35,7 +35,6 @@
 #include "adb_auth.h"
 #include "adb_listeners.h"
 #include "transport.h"
-#include "qemu_tracing.h"
 
 static const char* root_seclabel = nullptr;
 
@@ -262,10 +261,6 @@
 
     adb_trace_init(argv);
 
-    /* If adbd runs inside the emulator this will enable adb tracing via
-     * adb-debug qemud service in the emulator. */
-    adb_qemu_trace_init();
-
     D("Handling main()\n");
     return adbd_main(DEFAULT_ADB_PORT);
 }
diff --git a/qemu_tracing.cpp b/qemu_tracing.cpp
deleted file mode 100644
index f31eae8..0000000
--- a/qemu_tracing.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Implements ADB tracing inside the emulator.
- */
-
-#include <stdarg.h>
-
-#include "sysdeps.h"
-#include "qemu_tracing.h"
-
-/*
- * Redefine open and write for qemu_pipe.h that contains inlined references
- * to those routines. We will redifine them back after qemu_pipe.h inclusion.
- */
-
-#undef open
-#undef write
-#define open    adb_open
-#define write   adb_write
-#include <hardware/qemu_pipe.h>
-#undef open
-#undef write
-#define open    ___xxx_open
-#define write   ___xxx_write
-
-/* A handle to adb-debug qemud service in the emulator. */
-int   adb_debug_qemu = -1;
-
-/* Initializes connection with the adb-debug qemud service in the emulator. */
-int adb_qemu_trace_init(void)
-{
-    char con_name[32];
-
-    if (adb_debug_qemu >= 0) {
-        return 0;
-    }
-
-    /* adb debugging QEMUD service connection request. */
-    snprintf(con_name, sizeof(con_name), "qemud:adb-debug");
-    adb_debug_qemu = qemu_pipe_open(con_name);
-    return (adb_debug_qemu >= 0) ? 0 : -1;
-}
-
-void adb_qemu_trace(const char* fmt, ...)
-{
-    va_list args;
-    va_start(args, fmt);
-    char msg[1024];
-
-    if (adb_debug_qemu >= 0) {
-        vsnprintf(msg, sizeof(msg), fmt, args);
-        adb_write(adb_debug_qemu, msg, strlen(msg));
-    }
-}
diff --git a/qemu_tracing.h b/qemu_tracing.h
deleted file mode 100644
index ff42d4f..0000000
--- a/qemu_tracing.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Implements ADB tracing inside the emulator.
- */
-
-#ifndef __QEMU_TRACING_H
-#define __QEMU_TRACING_H
-
-/* Initializes connection with the adb-debug qemud service in the emulator. */
-int adb_qemu_trace_init(void);
-void adb_qemu_trace(const char* fmt, ...);
-
-#endif /* __QEMU_TRACING_H */