blob: b8a2f4c38587a01fa14b2696f0079d2b62e2a771 [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); \
leozwangcbf02672014-08-15 09:51:27 -070076 fprintf(stderr, "%16s: %5d:%5lu | ", \
77 __FUNCTION__, \
78 getpid(), adb_thread_id()); \
leozwangd3fc15f2014-07-29 12:50:02 -070079 errno = save_errno; \
80 fprintf(stderr, __VA_ARGS__ ); \
81 fflush(stderr); \
82 adb_mutex_unlock(&D_lock); \
83 errno = save_errno; \
84 } \
85 } while (0)
86# define DR(...) \
87 do { \
88 if (ADB_TRACING) { \
89 int save_errno = errno; \
90 adb_mutex_lock(&D_lock); \
91 errno = save_errno; \
92 fprintf(stderr, __VA_ARGS__ ); \
93 fflush(stderr); \
94 adb_mutex_unlock(&D_lock); \
95 errno = save_errno; \
96 } \
97 } while (0)
98# define DD(...) \
99 do { \
leozwangcbf02672014-08-15 09:51:27 -0700100 int save_errno = errno; \
101 adb_mutex_lock(&D_lock); \
102 fprintf(stderr, "%16s: %5d:%5lu | ", \
103 __FUNCTION__, \
104 getpid(), adb_thread_id()); \
105 errno = save_errno; \
106 fprintf(stderr, __VA_ARGS__ ); \
107 fflush(stderr); \
108 adb_mutex_unlock(&D_lock); \
109 errno = save_errno; \
leozwangd3fc15f2014-07-29 12:50:02 -0700110 } while (0)
111#else
112# define D(...) \
113 do { \
114 if (ADB_TRACING) { \
115 __android_log_print( \
116 ANDROID_LOG_INFO, \
117 __FUNCTION__, \
118 __VA_ARGS__ ); \
119 } \
120 } while (0)
121# define DR(...) \
122 do { \
123 if (ADB_TRACING) { \
124 __android_log_print( \
125 ANDROID_LOG_INFO, \
126 __FUNCTION__, \
127 __VA_ARGS__ ); \
128 } \
129 } while (0)
130# define DD(...) \
131 do { \
132 __android_log_print( \
133 ANDROID_LOG_INFO, \
134 __FUNCTION__, \
135 __VA_ARGS__ ); \
136 } while (0)
137#endif /* ADB_HOST */
138#else
139# define D(...) ((void)0)
140# define DR(...) ((void)0)
141# define DD(...) ((void)0)
142# define ADB_TRACING 0
143#endif /* ADB_TRACE */
144
145#endif /* __ADB_TRACE_H */