blob: 2039dbe3feab807b244e9234df9addce357efde0 [file] [log] [blame]
rjw2e8229f2022-02-15 21:08:12 +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 */
qjb0300fcc2023-08-17 03:54:44 -070025#define ADB_TRACE 1
rjw2e8229f2022-02-15 21:08:12 +080026
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,
qjb0300fcc2023-08-17 03:54:44 -070044 TRACE_LAST, /* 0x1000 */
rjw2e8229f2022-02-15 21:08:12 +080045} AdbTrace;
46
47#if ADB_TRACE
48
49#if !ADB_HOST
50/*
51 * When running inside the emulator, guest's adbd can connect to 'adb-debug'
52 * qemud service that can display adb trace messages (on condition that emulator
53 * has been started with '-debug adb' option).
54 */
55
56/* Delivers a trace message to the emulator via QEMU pipe. */
57void adb_qemu_trace(const char* fmt, ...);
58/* Macro to use to send ADB trace messages to the emulator. */
59#define DQ(...) adb_qemu_trace(__VA_ARGS__)
60#else
61#define DQ(...) ((void)0)
62#endif /* !ADB_HOST */
63
64extern int adb_trace_mask;
65extern unsigned char adb_trace_output_count;
66void adb_trace_init(void);
67
68# define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0)
69
70
71/* you must define TRACE_TAG before using this macro */
72#if ADB_HOST
73# define D(...) \
74 do { \
75 if (ADB_TRACING) { \
76 int save_errno = errno; \
77 adb_mutex_lock(&D_lock); \
78 fprintf(stderr, "%s::%s():", \
79 __FILE__, __FUNCTION__); \
80 errno = save_errno; \
81 fprintf(stderr, __VA_ARGS__ ); \
82 fflush(stderr); \
83 adb_mutex_unlock(&D_lock); \
84 errno = save_errno; \
85 } \
86 } while (0)
87# define DR(...) \
88 do { \
89 if (ADB_TRACING) { \
90 int save_errno = errno; \
91 adb_mutex_lock(&D_lock); \
92 errno = save_errno; \
93 fprintf(stderr, __VA_ARGS__ ); \
94 fflush(stderr); \
95 adb_mutex_unlock(&D_lock); \
96 errno = save_errno; \
97 } \
98 } while (0)
99# define DD(...) \
100 do { \
101 int save_errno = errno; \
102 adb_mutex_lock(&D_lock); \
103 fprintf(stderr, "%s::%s():", \
104 __FILE__, __FUNCTION__); \
105 errno = save_errno; \
106 fprintf(stderr, __VA_ARGS__ ); \
107 fflush(stderr); \
108 adb_mutex_unlock(&D_lock); \
109 errno = save_errno; \
110 } 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 */