| 1 | /* |
| 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
| 3 | * |
| 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
| 5 | * |
| 6 | * This file contains Original Code and/or Modifications of Original Code |
| 7 | * as defined in and that are subject to the Apple Public Source License |
| 8 | * Version 2.0 (the 'License'). You may not use this file except in |
| 9 | * compliance with the License. The rights granted to you under the License |
| 10 | * may not be used to create, or enable the creation or redistribution of, |
| 11 | * unlawful or unlicensed copies of an Apple operating system, or to |
| 12 | * circumvent, violate, or enable the circumvention or violation of, any |
| 13 | * terms of an Apple operating system software license agreement. |
| 14 | * |
| 15 | * Please obtain a copy of the License at |
| 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
| 17 | * |
| 18 | * The Original Code and all software distributed under the License are |
| 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
| 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
| 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
| 23 | * Please see the License for the specific language governing rights and |
| 24 | * limitations under the License. |
| 25 | * |
| 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
| 27 | */ |
| 28 | /* |
| 29 | * @OSF_COPYRIGHT@ |
| 30 | */ |
| 31 | /* |
| 32 | * HISTORY |
| 33 | * |
| 34 | * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez |
| 35 | * Import of Mac OS X kernel (~semeria) |
| 36 | * |
| 37 | * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez |
| 38 | * Import of OSF Mach kernel (~mburg) |
| 39 | * |
| 40 | * Revision 1.1.11.1 1997/03/27 18:47:01 barbou |
| 41 | * Merge smp_shared merges into mainline. |
| 42 | * [1996/09/19 13:55:17 addis] |
| 43 | * Make tr_indent NCPU safe. |
| 44 | * [95/10/09 rwd] |
| 45 | * Added TR_INIT() macro. |
| 46 | * Change from NMK16.1 [93/09/22 paire] |
| 47 | * [94/02/04 paire] |
| 48 | * [97/02/25 barbou] |
| 49 | * |
| 50 | * Revision 1.1.6.1 1995/02/23 16:34:23 alanl |
| 51 | * Taken from DIPC2_SHARED. Change to !FREE Copyright. |
| 52 | * [95/01/05 rwd] |
| 53 | * |
| 54 | * Revision 1.1.4.4 1994/08/18 01:07:26 alanl |
| 55 | * + Allow tracing strictly based on MACH_TR; |
| 56 | * don't also require MACH_ASSERT (alanl). |
| 57 | * + ANSI-fication: cast tr arguments (alanl). |
| 58 | * + Added tr_indent and macros to use it (sjs). |
| 59 | * [1994/08/18 01:06:09 alanl] |
| 60 | * |
| 61 | * Revision 1.1.4.3 1994/08/08 17:59:35 rwd |
| 62 | * Include mach_tr.h |
| 63 | * [94/08/08 rwd] |
| 64 | * |
| 65 | * Revision 1.1.4.2 1994/08/05 19:36:08 mmp |
| 66 | * Added prototype for db_show_tr. |
| 67 | * |
| 68 | * Conditionalize on MACH_TR |
| 69 | * [94/07/20 rwd] |
| 70 | * |
| 71 | * Revision 1.1.4.1 1994/08/04 01:43:04 mmp |
| 72 | * DIPC: moved from norma/ to ddb/. Updated includes. |
| 73 | * [1994/08/03 13:37:46 mmp] |
| 74 | * |
| 75 | * Revision 1.1.9.1 1994/03/07 16:55:24 paire |
| 76 | * Added ANSI prototypes. |
| 77 | * [94/02/15 paire] |
| 78 | * |
| 79 | * Added TR_INIT() macro. |
| 80 | * Change from NMK16.1 [93/09/22 paire] |
| 81 | * [94/02/04 paire] |
| 82 | * |
| 83 | * Revision 1.1.2.2 1993/06/02 23:57:10 jeffc |
| 84 | * Added to OSF/1 R1.3 from NMK15.0. |
| 85 | * [1993/06/02 21:22:08 jeffc] |
| 86 | * |
| 87 | * Revision 1.1 1992/09/30 02:34:09 robert |
| 88 | * Initial revision |
| 89 | * |
| 90 | * $EndLog$ |
| 91 | */ |
| 92 | |
| 93 | /* |
| 94 | * File: ddb/tr.h |
| 95 | * Author: Alan Langerman, Jeffrey Heller |
| 96 | * Date: 1992 |
| 97 | * |
| 98 | * Internal trace routines. Like old-style XPRs but |
| 99 | * less formatting. |
| 100 | */ |
| 101 | |
| 102 | #include <mach_assert.h> |
| 103 | #include <mach_tr.h> |
| 104 | |
| 105 | #include <kern/cpu_number.h> |
| 106 | |
| 107 | /* |
| 108 | * Originally, we only wanted tracing when |
| 109 | * MACH_TR and MACH_ASSERT were turned on |
| 110 | * together. Now, there's no reason why |
| 111 | * MACH_TR and MACH_ASSERT can't be completely |
| 112 | * orthogonal. |
| 113 | */ |
| 114 | #define TRACE_BUFFER (MACH_TR) |
| 115 | |
| 116 | /* |
| 117 | * Log events in a circular trace buffer for future debugging. |
| 118 | * Events are unsigned integers. Each event has a descriptive |
| 119 | * message. |
| 120 | * |
| 121 | * TR_DECL must be used at the beginning of a routine using |
| 122 | * one of the tr calls. The macro should be passed the name |
| 123 | * of the function surrounded by quotation marks, e.g., |
| 124 | * TR_DECL("netipc_recv_intr"); |
| 125 | * and should be terminated with a semi-colon. The TR_DECL |
| 126 | * must be the *last* declaration in the variable declaration |
| 127 | * list, or syntax errors will be introduced when TRACE_BUFFER |
| 128 | * is turned off. |
| 129 | */ |
| 130 | #ifndef _DDB_TR_H_ |
| 131 | #define _DDB_TR_H_ |
| 132 | |
| 133 | #if TRACE_BUFFER |
| 134 | |
| 135 | #include <machine/db_machdep.h> |
| 136 | |
| 137 | #define __ui__ (unsigned int) |
| 138 | #define TR_INIT() tr_init() |
| 139 | #define TR_SHOW(a,b,c) show_tr((a),(b),(c)) |
| 140 | #define TR_DECL(funcname) char *__ntr_func_name__ = funcname |
| 141 | #define tr1(msg) \ |
| 142 | tr(__ntr_func_name__, __FILE__, __LINE__, (msg), \ |
| 143 | 0,0,0,0) |
| 144 | #define tr2(msg,tag1) \ |
| 145 | tr(__ntr_func_name__, __FILE__, __LINE__, (msg), \ |
| 146 | __ui__(tag1),0,0,0) |
| 147 | #define tr3(msg,tag1,tag2) \ |
| 148 | tr(__ntr_func_name__, __FILE__, __LINE__, (msg), \ |
| 149 | __ui__(tag1),__ui__(tag2),0,0) |
| 150 | #define tr4(msg,tag1,tag2,tag3) \ |
| 151 | tr(__ntr_func_name__, __FILE__, __LINE__, (msg), \ |
| 152 | __ui__(tag1),__ui__(tag2),__ui__(tag3),0) |
| 153 | #define tr5(msg,tag1,tag2,tag3,tag4) \ |
| 154 | tr(__ntr_func_name__, __FILE__, __LINE__, (msg), \ |
| 155 | __ui__(tag1),__ui__(tag2),__ui__(tag3),__ui__(tag4)) |
| 156 | |
| 157 | /* |
| 158 | * Adjust tr log indentation based on function |
| 159 | * call graph. |
| 160 | */ |
| 161 | #if NCPUS == 1 |
| 162 | extern int tr_indent; |
| 163 | #define tr_start() tr_indent++ |
| 164 | #define tr_stop() tr_indent-- |
| 165 | #else /* NCPUS == 1 */ |
| 166 | extern int tr_indent[NCPUS]; |
| 167 | #define tr_start() tr_indent[cpu_number()]++ |
| 168 | #define tr_stop() (--tr_indent[cpu_number()]<0?tr_indent[cpu_number()]=0:0); |
| 169 | #endif /* NCPUS == 1 */ |
| 170 | |
| 171 | extern void tr_init(void); |
| 172 | extern void tr( |
| 173 | char *funcname, |
| 174 | char *file, |
| 175 | unsigned int lineno, |
| 176 | char *fmt, |
| 177 | unsigned int tag1, |
| 178 | unsigned int tag2, |
| 179 | unsigned int tag3, |
| 180 | unsigned int tag4); |
| 181 | |
| 182 | extern void db_show_tr( |
| 183 | db_expr_t addr, |
| 184 | boolean_t have_addr, |
| 185 | db_expr_t count, |
| 186 | char * modif); |
| 187 | |
| 188 | #else /* TRACE_BUFFER */ |
| 189 | |
| 190 | #define TR_INIT() |
| 191 | #define TR_SHOW(a,b,c) |
| 192 | #define TR_DECL(funcname) |
| 193 | #define tr1(msg) |
| 194 | #define tr2(msg, tag1) |
| 195 | #define tr3(msg, tag1, tag2) |
| 196 | #define tr4(msg, tag1, tag2, tag3) |
| 197 | #define tr5(msg, tag1, tag2, tag3, tag4) |
| 198 | #define tr_start() |
| 199 | #define tr_stop() |
| 200 | |
| 201 | #endif /* TRACE_BUFFER */ |
| 202 | |
| 203 | #endif /* _DDB_TR_H_ */ |