blob: dbc7ec83ee6d306ed90a4cfc8f9ad1a93d0c2d50 [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>
Dan Albertcc731cc2015-02-24 21:26:58 -080022#else
23#include <stdio.h>
leozwangd3fc15f2014-07-29 12:50:02 -070024#endif
25
leozwangd3fc15f2014-07-29 12:50:02 -070026/* IMPORTANT: if you change the following list, don't
27 * forget to update the corresponding 'tags' table in
28 * the adb_trace_init() function implemented in adb.c
29 */
Elliott Hughes2d4121c2015-04-17 09:47:42 -070030enum AdbTrace {
leozwangd3fc15f2014-07-29 12:50:02 -070031 TRACE_ADB = 0, /* 0x001 */
32 TRACE_SOCKETS,
33 TRACE_PACKETS,
34 TRACE_TRANSPORT,
35 TRACE_RWX, /* 0x010 */
36 TRACE_USB,
37 TRACE_SYNC,
38 TRACE_SYSDEPS,
39 TRACE_JDWP, /* 0x100 */
40 TRACE_SERVICES,
41 TRACE_AUTH,
42 TRACE_FDEVENT,
Elliott Hughes2d4121c2015-04-17 09:47:42 -070043} ;
leozwangd3fc15f2014-07-29 12:50:02 -070044
leozwangd3fc15f2014-07-29 12:50:02 -070045#if !ADB_HOST
46/*
47 * When running inside the emulator, guest's adbd can connect to 'adb-debug'
48 * qemud service that can display adb trace messages (on condition that emulator
49 * has been started with '-debug adb' option).
50 */
51
52/* Delivers a trace message to the emulator via QEMU pipe. */
53void adb_qemu_trace(const char* fmt, ...);
54/* Macro to use to send ADB trace messages to the emulator. */
55#define DQ(...) adb_qemu_trace(__VA_ARGS__)
56#else
57#define DQ(...) ((void)0)
58#endif /* !ADB_HOST */
59
Dan Albert9313c0d2015-05-21 13:58:50 -070060extern int adb_trace_mask;
61extern unsigned char adb_trace_output_count;
62void adb_trace_init(char**);
leozwangd3fc15f2014-07-29 12:50:02 -070063
64# define ADB_TRACING ((adb_trace_mask & (1 << TRACE_TAG)) != 0)
65
66/* you must define TRACE_TAG before using this macro */
67#if ADB_HOST
68# define D(...) \
69 do { \
70 if (ADB_TRACING) { \
71 int save_errno = errno; \
72 adb_mutex_lock(&D_lock); \
leozwangcbf02672014-08-15 09:51:27 -070073 fprintf(stderr, "%16s: %5d:%5lu | ", \
74 __FUNCTION__, \
75 getpid(), adb_thread_id()); \
leozwangd3fc15f2014-07-29 12:50:02 -070076 errno = save_errno; \
77 fprintf(stderr, __VA_ARGS__ ); \
78 fflush(stderr); \
79 adb_mutex_unlock(&D_lock); \
80 errno = save_errno; \
81 } \
82 } while (0)
83# define DR(...) \
84 do { \
85 if (ADB_TRACING) { \
86 int save_errno = errno; \
87 adb_mutex_lock(&D_lock); \
88 errno = save_errno; \
89 fprintf(stderr, __VA_ARGS__ ); \
90 fflush(stderr); \
91 adb_mutex_unlock(&D_lock); \
92 errno = save_errno; \
93 } \
94 } while (0)
leozwangd3fc15f2014-07-29 12:50:02 -070095#else
96# define D(...) \
97 do { \
98 if (ADB_TRACING) { \
99 __android_log_print( \
100 ANDROID_LOG_INFO, \
101 __FUNCTION__, \
102 __VA_ARGS__ ); \
103 } \
104 } while (0)
105# define DR(...) \
106 do { \
107 if (ADB_TRACING) { \
108 __android_log_print( \
109 ANDROID_LOG_INFO, \
110 __FUNCTION__, \
111 __VA_ARGS__ ); \
112 } \
113 } while (0)
leozwangd3fc15f2014-07-29 12:50:02 -0700114#endif /* ADB_HOST */
leozwangd3fc15f2014-07-29 12:50:02 -0700115
leozwangd3fc15f2014-07-29 12:50:02 -0700116#endif /* __ADB_TRACE_H */