blob: 69b6c697b0c8444f71d28195ae2a0834357eb526 [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
Dan Albert818fb4b2015-02-18 00:18:25 -080024#ifdef __cplusplus
25extern "C" {
26#endif
27
leozwangd3fc15f2014-07-29 12:50:02 -070028/* define ADB_TRACE to 1 to enable tracing support, or 0 to disable it */
29#define ADB_TRACE 1
30
31/* IMPORTANT: if you change the following list, don't
32 * forget to update the corresponding 'tags' table in
33 * the adb_trace_init() function implemented in adb.c
34 */
35typedef enum {
36 TRACE_ADB = 0, /* 0x001 */
37 TRACE_SOCKETS,
38 TRACE_PACKETS,
39 TRACE_TRANSPORT,
40 TRACE_RWX, /* 0x010 */
41 TRACE_USB,
42 TRACE_SYNC,
43 TRACE_SYSDEPS,
44 TRACE_JDWP, /* 0x100 */
45 TRACE_SERVICES,
46 TRACE_AUTH,
47 TRACE_FDEVENT,
48} AdbTrace;
49
50#if ADB_TRACE
51
52#if !ADB_HOST
53/*
54 * When running inside the emulator, guest's adbd can connect to 'adb-debug'
55 * qemud service that can display adb trace messages (on condition that emulator
56 * has been started with '-debug adb' option).
57 */
58
59/* Delivers a trace message to the emulator via QEMU pipe. */
60void adb_qemu_trace(const char* fmt, ...);
61/* Macro to use to send ADB trace messages to the emulator. */
62#define DQ(...) adb_qemu_trace(__VA_ARGS__)
63#else
64#define DQ(...) ((void)0)
65#endif /* !ADB_HOST */
66
67extern int adb_trace_mask;
68extern unsigned char adb_trace_output_count;
69void adb_trace_init(void);
70
71# define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0)
72
73/* you must define TRACE_TAG before using this macro */
74#if ADB_HOST
75# define D(...) \
76 do { \
77 if (ADB_TRACING) { \
78 int save_errno = errno; \
79 adb_mutex_lock(&D_lock); \
leozwangcbf02672014-08-15 09:51:27 -070080 fprintf(stderr, "%16s: %5d:%5lu | ", \
81 __FUNCTION__, \
82 getpid(), adb_thread_id()); \
leozwangd3fc15f2014-07-29 12:50:02 -070083 errno = save_errno; \
84 fprintf(stderr, __VA_ARGS__ ); \
85 fflush(stderr); \
86 adb_mutex_unlock(&D_lock); \
87 errno = save_errno; \
88 } \
89 } while (0)
90# define DR(...) \
91 do { \
92 if (ADB_TRACING) { \
93 int save_errno = errno; \
94 adb_mutex_lock(&D_lock); \
95 errno = save_errno; \
96 fprintf(stderr, __VA_ARGS__ ); \
97 fflush(stderr); \
98 adb_mutex_unlock(&D_lock); \
99 errno = save_errno; \
100 } \
101 } while (0)
102# define DD(...) \
103 do { \
leozwangcbf02672014-08-15 09:51:27 -0700104 int save_errno = errno; \
105 adb_mutex_lock(&D_lock); \
106 fprintf(stderr, "%16s: %5d:%5lu | ", \
107 __FUNCTION__, \
108 getpid(), adb_thread_id()); \
109 errno = save_errno; \
110 fprintf(stderr, __VA_ARGS__ ); \
111 fflush(stderr); \
112 adb_mutex_unlock(&D_lock); \
113 errno = save_errno; \
leozwangd3fc15f2014-07-29 12:50:02 -0700114 } while (0)
115#else
116# define D(...) \
117 do { \
118 if (ADB_TRACING) { \
119 __android_log_print( \
120 ANDROID_LOG_INFO, \
121 __FUNCTION__, \
122 __VA_ARGS__ ); \
123 } \
124 } while (0)
125# define DR(...) \
126 do { \
127 if (ADB_TRACING) { \
128 __android_log_print( \
129 ANDROID_LOG_INFO, \
130 __FUNCTION__, \
131 __VA_ARGS__ ); \
132 } \
133 } while (0)
134# define DD(...) \
135 do { \
136 __android_log_print( \
137 ANDROID_LOG_INFO, \
138 __FUNCTION__, \
139 __VA_ARGS__ ); \
140 } while (0)
141#endif /* ADB_HOST */
142#else
143# define D(...) ((void)0)
144# define DR(...) ((void)0)
145# define DD(...) ((void)0)
146# define ADB_TRACING 0
147#endif /* ADB_TRACE */
148
Dan Albert818fb4b2015-02-18 00:18:25 -0800149#ifdef __cplusplus
150}
151#endif
152
leozwangd3fc15f2014-07-29 12:50:02 -0700153#endif /* __ADB_TRACE_H */