leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 1 | /* |
| 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 Albert | cc731cc | 2015-02-24 21:26:58 -0800 | [diff] [blame] | 22 | #else |
| 23 | #include <stdio.h> |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 24 | #endif |
| 25 | |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 26 | /* 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 Hughes | 2d4121c | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 30 | enum AdbTrace { |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 31 | 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 Hughes | 2d4121c | 2015-04-17 09:47:42 -0700 | [diff] [blame] | 43 | } ; |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 44 | |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 45 | #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. */ |
| 53 | void 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 Albert | 9313c0d | 2015-05-21 13:58:50 -0700 | [diff] [blame^] | 60 | extern int adb_trace_mask; |
| 61 | extern unsigned char adb_trace_output_count; |
| 62 | void adb_trace_init(char**); |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 63 | |
| 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); \ |
leozwang | cbf0267 | 2014-08-15 09:51:27 -0700 | [diff] [blame] | 73 | fprintf(stderr, "%16s: %5d:%5lu | ", \ |
| 74 | __FUNCTION__, \ |
| 75 | getpid(), adb_thread_id()); \ |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 76 | 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) |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 95 | #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) |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 114 | #endif /* ADB_HOST */ |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 115 | |
leozwang | d3fc15f | 2014-07-29 12:50:02 -0700 | [diff] [blame] | 116 | #endif /* __ADB_TRACE_H */ |