blob: 8a5d9f8e140dfb723e7a911343f6021830d0453f [file] [log] [blame]
leozwangd3fc15f2014-07-29 12:50:02 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __ADB_TRACE_H
18#define __ADB_TRACE_H
19
20#if !ADB_HOST
21#include <android/log.h>
22#endif
23
24/* define ADB_TRACE to 1 to enable tracing support, or 0 to disable it */
25#define ADB_TRACE 1
26
27/* IMPORTANT: if you change the following list, don't
28 * forget to update the corresponding 'tags' table in
29 * the adb_trace_init() function implemented in adb.c
30 */
31typedef enum {
32 TRACE_ADB = 0, /* 0x001 */
33 TRACE_SOCKETS,
34 TRACE_PACKETS,
35 TRACE_TRANSPORT,
36 TRACE_RWX, /* 0x010 */
37 TRACE_USB,
38 TRACE_SYNC,
39 TRACE_SYSDEPS,
40 TRACE_JDWP, /* 0x100 */
41 TRACE_SERVICES,
42 TRACE_AUTH,
43 TRACE_FDEVENT,
44} AdbTrace;
45
46#if ADB_TRACE
47
48#if !ADB_HOST
49/*
50 * When running inside the emulator, guest's adbd can connect to 'adb-debug'
51 * qemud service that can display adb trace messages (on condition that emulator
52 * has been started with '-debug adb' option).
53 */
54
55/* Delivers a trace message to the emulator via QEMU pipe. */
56void adb_qemu_trace(const char* fmt, ...);
57/* Macro to use to send ADB trace messages to the emulator. */
58#define DQ(...) adb_qemu_trace(__VA_ARGS__)
59#else
60#define DQ(...) ((void)0)
61#endif /* !ADB_HOST */
62
63extern int adb_trace_mask;
64extern unsigned char adb_trace_output_count;
65void adb_trace_init(void);
66
67# define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0)
68
69/* you must define TRACE_TAG before using this macro */
70#if ADB_HOST
71# define D(...) \
72 do { \
73 if (ADB_TRACING) { \
74 int save_errno = errno; \
75 adb_mutex_lock(&D_lock); \
76 fprintf(stderr, "%s::%s():", \
77 __FILE__, __FUNCTION__); \
78 errno = save_errno; \
79 fprintf(stderr, __VA_ARGS__ ); \
80 fflush(stderr); \
81 adb_mutex_unlock(&D_lock); \
82 errno = save_errno; \
83 } \
84 } while (0)
85# define DR(...) \
86 do { \
87 if (ADB_TRACING) { \
88 int save_errno = errno; \
89 adb_mutex_lock(&D_lock); \
90 errno = save_errno; \
91 fprintf(stderr, __VA_ARGS__ ); \
92 fflush(stderr); \
93 adb_mutex_unlock(&D_lock); \
94 errno = save_errno; \
95 } \
96 } while (0)
97# define DD(...) \
98 do { \
99 int save_errno = errno; \
100 adb_mutex_lock(&D_lock); \
101 fprintf(stderr, "%s::%s():", \
102 __FILE__, __FUNCTION__); \
103 errno = save_errno; \
104 fprintf(stderr, __VA_ARGS__ ); \
105 fflush(stderr); \
106 adb_mutex_unlock(&D_lock); \
107 errno = save_errno; \
108 } while (0)
109#else
110# define D(...) \
111 do { \
112 if (ADB_TRACING) { \
113 __android_log_print( \
114 ANDROID_LOG_INFO, \
115 __FUNCTION__, \
116 __VA_ARGS__ ); \
117 } \
118 } while (0)
119# define DR(...) \
120 do { \
121 if (ADB_TRACING) { \
122 __android_log_print( \
123 ANDROID_LOG_INFO, \
124 __FUNCTION__, \
125 __VA_ARGS__ ); \
126 } \
127 } while (0)
128# define DD(...) \
129 do { \
130 __android_log_print( \
131 ANDROID_LOG_INFO, \
132 __FUNCTION__, \
133 __VA_ARGS__ ); \
134 } while (0)
135#endif /* ADB_HOST */
136#else
137# define D(...) ((void)0)
138# define DR(...) ((void)0)
139# define DD(...) ((void)0)
140# define ADB_TRACING 0
141#endif /* ADB_TRACE */
142
143#endif /* __ADB_TRACE_H */