1 /* 2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #if !defined(_DEBUG_TRACE_H) 27 #define _DEBUG_TRACE_H 28 29 #if defined(__cplusplus) 30 extern "C" { 31 #endif 32 33 #if defined(DEBUG) 34 35 #include "debug_util.h" 36 37 typedef int dtrace_id; 38 enum { 39 UNDEFINED_TRACE_ID = -1 /* indicates trace point has not been registered yet */ 40 }; 41 42 /* prototype for client provided output callback function */ 43 typedef void (JNICALL *DTRACE_OUTPUT_CALLBACK)(const char * msg); 44 45 /* prototype for client provided print callback function */ 46 typedef void (JNICALL *DTRACE_PRINT_CALLBACK)(const char * file, int line, int argc, const char * fmt, va_list arglist); 47 48 extern void DTrace_EnableAll(dbool_t enabled); 49 extern void DTrace_EnableFile(const char * file, dbool_t enabled); 50 extern void DTrace_EnableLine(const char * file, int linenum, dbool_t enabled); 51 extern void DTrace_SetOutputCallback(DTRACE_OUTPUT_CALLBACK pfn); 52 extern void DTrace_Initialize(); 53 extern void DTrace_Shutdown(); 54 void DTrace_DisableMutex(); 55 extern void DTrace_VPrintImpl(const char * fmt, va_list arglist); 56 extern void DTrace_PrintImpl(const char * fmt, ...); 57 /* JNIEXPORT because these functions are also called from libawt_xawt */ 58 JNIEXPORT void JNICALL DTrace_PrintFunction(DTRACE_PRINT_CALLBACK pfn, dtrace_id * pFileTraceId, dtrace_id * pTraceId, const char * file, int line, int argc, const char * fmt, ...); 59 60 /* these functions are exported only for use in macros-- do not call them directly!!! */ 61 JNIEXPORT void JNICALL DTrace_VPrint(const char * file, int line, int argc, const char * fmt, va_list arglist); 62 JNIEXPORT void JNICALL DTrace_VPrintln(const char * file, int line, int argc, const char * fmt, va_list arglist); 63 64 /* each file includes this flag indicating module trace status */ 65 static dtrace_id _Dt_FileTraceId = UNDEFINED_TRACE_ID; 66 67 /* not meant to be called from client code-- 68 * it's just a template for the other macros 69 */ 70 #define _DTrace_Template(_func, _ac, _f, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8) \ 71 { \ 72 static dtrace_id _dt_lineid_ = UNDEFINED_TRACE_ID; \ 73 DTrace_PrintFunction((_func), &_Dt_FileTraceId, &_dt_lineid_, __FILE__, __LINE__, (_ac), (_f), (_a1), (_a2), (_a3), (_a4), (_a5), (_a6), (_a7), (_a8) ); \ 74 } 75 76 /* printf style trace macros */ 77 #define DTRACE_PRINT(_fmt) \ 78 _DTrace_Template(DTrace_VPrint, 0, (_fmt), 0, 0, 0, 0, 0, 0, 0, 0) 79 #define DTRACE_PRINT1(_fmt, _arg1) \ 80 _DTrace_Template(DTrace_VPrint, 1, (_fmt), (_arg1), 0, 0, 0, 0, 0, 0, 0) 81 #define DTRACE_PRINT2(_fmt, _arg1, _arg2) \ 82 _DTrace_Template(DTrace_VPrint, 2, (_fmt), (_arg1), (_arg2), 0, 0, 0, 0, 0, 0) 83 #define DTRACE_PRINT3(_fmt, _arg1, _arg2, _arg3) \ 84 _DTrace_Template(DTrace_VPrint, 3, (_fmt), (_arg1), (_arg2), (_arg3), 0, 0, 0, 0, 0) 85 #define DTRACE_PRINT4(_fmt, _arg1, _arg2, _arg3, _arg4) \ 86 _DTrace_Template(DTrace_VPrint, 4, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), 0, 0, 0, 0) 87 #define DTRACE_PRINT5(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5) \ 88 _DTrace_Template(DTrace_VPrint, 5, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), (_arg5), 0, 0, 0) 89 #define DTRACE_PRINT6(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6) \ 90 _DTrace_Template(DTrace_VPrint, 6, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), (_arg5), (_arg6), 0, 0) 91 #define DTRACE_PRINT7(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7) \ 92 _DTrace_Template(DTrace_VPrint, 7, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), (_arg5), (_arg6), (_arg7), 0) 93 #define DTRACE_PRINT8(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8) \ 94 _DTrace_Template(DTrace_VPrint, 8, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), (_arg5), (_arg6), (_arg7), (_arg8)) 95 96 /* printf style trace macros that automatically output a newline */ 97 #define DTRACE_PRINTLN(_fmt) \ 98 _DTrace_Template(DTrace_VPrintln, 0, (_fmt), 0, 0, 0, 0, 0, 0, 0, 0) 99 #define DTRACE_PRINTLN1(_fmt, _arg1) \ 100 _DTrace_Template(DTrace_VPrintln, 1, (_fmt), (_arg1), 0, 0, 0, 0, 0, 0, 0) 101 #define DTRACE_PRINTLN2(_fmt, _arg1, _arg2) \ 102 _DTrace_Template(DTrace_VPrintln, 2, (_fmt), (_arg1), (_arg2), 0, 0, 0, 0, 0, 0) 103 #define DTRACE_PRINTLN3(_fmt, _arg1, _arg2, _arg3) \ 104 _DTrace_Template(DTrace_VPrintln, 3, (_fmt), (_arg1), (_arg2), (_arg3), 0, 0, 0, 0, 0) 105 #define DTRACE_PRINTLN4(_fmt, _arg1, _arg2, _arg3, _arg4) \ 106 _DTrace_Template(DTrace_VPrintln, 4, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), 0, 0, 0, 0) 107 #define DTRACE_PRINTLN5(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5) \ 108 _DTrace_Template(DTrace_VPrintln, 5, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), (_arg5), 0, 0, 0) 109 #define DTRACE_PRINTLN6(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6) \ 110 _DTrace_Template(DTrace_VPrintln, 6, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), (_arg5), (_arg6), 0, 0) 111 #define DTRACE_PRINTLN7(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7) \ 112 _DTrace_Template(DTrace_VPrintln, 7, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), (_arg5), (_arg6), (_arg7), 0) 113 #define DTRACE_PRINTLN8(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8) \ 114 _DTrace_Template(DTrace_VPrintln, 8, (_fmt), (_arg1), (_arg2), (_arg3), (_arg4), (_arg5), (_arg6), (_arg7), (_arg8)) 115 116 #else /* else DEBUG not defined */ 117 118 /* printf style trace macros */ 119 #define DTRACE_PRINT(_fmt) 120 #define DTRACE_PRINT1(_fmt, _arg1) 121 #define DTRACE_PRINT2(_fmt, _arg1, _arg2) 122 #define DTRACE_PRINT3(_fmt, _arg1, _arg2, _arg3) 123 #define DTRACE_PRINT4(_fmt, _arg1, _arg2, _arg3, _arg4) 124 #define DTRACE_PRINT5(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5) 125 #define DTRACE_PRINT6(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6) 126 #define DTRACE_PRINT7(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7) 127 #define DTRACE_PRINT8(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8) 128 129 /* printf style trace macros that automatically output a newline */ 130 #define DTRACE_PRINTLN(_fmt) 131 #define DTRACE_PRINTLN1(_fmt, _arg1) 132 #define DTRACE_PRINTLN2(_fmt, _arg1, _arg2) 133 #define DTRACE_PRINTLN3(_fmt, _arg1, _arg2, _arg3) 134 #define DTRACE_PRINTLN4(_fmt, _arg1, _arg2, _arg3, _arg4) 135 #define DTRACE_PRINTLN5(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5) 136 #define DTRACE_PRINTLN6(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6) 137 #define DTRACE_PRINTLN7(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7) 138 #define DTRACE_PRINTLN8(_fmt, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8) 139 140 #endif /* endif DEBUG defined */ 141 142 #if defined(__cplusplus) 143 } /* extern "C" */ 144 #endif 145 146 #endif /* _DEBUG_TRACE_H */ 147