Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd4b1fa4 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

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
parent e73a8a23
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -88,7 +88,6 @@ LOCAL_SRC_FILES := \
    adb_auth_client.cpp \
    fdevent.cpp \
    jdwp_service.cpp \
    qemu_tracing.cpp \
    usb_linux_client.cpp \

LOCAL_SANITIZE := $(adb_target_sanitize)
+34 −57
Original line number Diff line number Diff line
@@ -42,21 +42,6 @@ enum AdbTrace {
    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;
void adb_trace_init(char**);
@@ -65,50 +50,42 @@ void adb_trace_init(char**);

/* you must define TRACE_TAG before using this macro */
#if ADB_HOST
#  define  D(...)                                      \
#  define D(fmt, ...) \
        do { \
            if (ADB_TRACING) { \
                int save_errno = errno;                \
                int saved_errno = errno; \
                adb_mutex_lock(&D_lock); \
                fprintf(stderr, "%16s: %5d:%5lu | ",   \
                        __FUNCTION__,                  \
                        getpid(), adb_thread_id());    \
                errno = save_errno;                    \
                fprintf(stderr, __VA_ARGS__ );         \
                errno = saved_errno; \
                fprintf(stderr, "%5d:%5lu %s | " fmt, \
                        getpid(), adb_thread_id(), __FUNCTION__, ## __VA_ARGS__); \
                fflush(stderr); \
                adb_mutex_unlock(&D_lock); \
                errno = save_errno;                    \
                errno = saved_errno; \
           } \
        } while (0)
#  define DR(...) \
        do { \
            if (ADB_TRACING) { \
                int save_errno = errno;                \
                int saved_errno = errno; \
                adb_mutex_lock(&D_lock); \
                errno = save_errno;                    \
                errno = saved_errno; \
                fprintf(stderr, __VA_ARGS__); \
                fflush(stderr); \
                adb_mutex_unlock(&D_lock); \
                errno = save_errno;                    \
                errno = saved_errno; \
           } \
        } while (0)
#else
#  define D(...) \
        do { \
            if (ADB_TRACING) { \
                __android_log_print(                   \
                    ANDROID_LOG_INFO,                  \
                    __FUNCTION__,                      \
                    __VA_ARGS__ );                     \
                __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__ );                     \
                __android_log_print(ANDROID_LOG_INFO, __FUNCTION__, __VA_ARGS__); \
            } \
        } while (0)
#endif /* ADB_HOST */
+0 −5
Original line number Diff line number Diff line
@@ -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 @@ int main(int argc, char** argv) {

    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);
}

adb/qemu_tracing.cpp

deleted100644 → 0
+0 −69
Original line number Diff line number Diff line
/*
 * 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));
    }
}

adb/qemu_tracing.h

deleted100644 → 0
+0 −28
Original line number Diff line number Diff line
/*
 * 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 */