Merge "Improve adb tracing."

This commit is contained in:
Elliott Hughes 2015-08-28 21:56:46 +00:00 committed by Gerrit Code Review
commit f6224587e5
5 changed files with 34 additions and 160 deletions

View file

@ -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)

View file

@ -40,22 +40,7 @@ enum AdbTrace {
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 @@ void adb_trace_init(char**);
/* 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 */

View file

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

View file

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

View file

@ -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 */