blob: 32c3cc605d5722fbe1ba842b66d51915ed805af3 [file] [log] [blame]
xj123f7cc2022-06-06 11:35:21 +08001/*
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 0
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
70/* you must define TRACE_TAG before using this macro */
71#if ADB_HOST
72# define D(...) \
73 do { \
74 if (ADB_TRACING) { \
75 int save_errno = errno; \
76 adb_mutex_lock(&D_lock); \
77 fprintf(stderr, "%s::%s():", \
78 __FILE__, __FUNCTION__); \
79 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 { \
100 int save_errno = errno; \
101 adb_mutex_lock(&D_lock); \
102 fprintf(stderr, "%s::%s():", \
103 __FILE__, __FUNCTION__); \
104 errno = save_errno; \
105 fprintf(stderr, __VA_ARGS__ ); \
106 fflush(stderr); \
107 adb_mutex_unlock(&D_lock); \
108 errno = save_errno; \
109 } while (0)
110#else
111# define D(...) \
112 do { \
113 if (ADB_TRACING) { \
114 __android_log_print( \
115 ANDROID_LOG_INFO, \
116 __FUNCTION__, \
117 __VA_ARGS__ ); \
118 } \
119 } while (0)
120# define DR(...) \
121 do { \
122 if (ADB_TRACING) { \
123 __android_log_print( \
124 ANDROID_LOG_INFO, \
125 __FUNCTION__, \
126 __VA_ARGS__ ); \
127 } \
128 } while (0)
129# define DD(...) \
130 do { \
131 __android_log_print( \
132 ANDROID_LOG_INFO, \
133 __FUNCTION__, \
134 __VA_ARGS__ ); \
135 } while (0)
136#endif /* ADB_HOST */
137#else
138# define D(...) ((void)0)
139# define DR(...) ((void)0)
140# define DD(...) ((void)0)
141# define ADB_TRACING 0
142#endif /* ADB_TRACE */
143
144#endif /* __ADB_TRACE_H */