1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of Apple Inc. ("Apple") nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * Portions of this software have been released under the following terms: 31 * 32 * (c) Copyright 1989-1993 OPEN SOFTWARE FOUNDATION, INC. 33 * (c) Copyright 1989-1993 HEWLETT-PACKARD COMPANY 34 * (c) Copyright 1989-1993 DIGITAL EQUIPMENT CORPORATION 35 * 36 * To anyone who acknowledges that this file is provided "AS IS" 37 * without any express or implied warranty: 38 * permission to use, copy, modify, and distribute this file for any 39 * purpose is hereby granted without fee, provided that the above 40 * copyright notices and this notice appears in all source code copies, 41 * and that none of the names of Open Software Foundation, Inc., Hewlett- 42 * Packard Company or Digital Equipment Corporation be used 43 * in advertising or publicity pertaining to distribution of the software 44 * without specific, written prior permission. Neither Open Software 45 * Foundation, Inc., Hewlett-Packard Company nor Digital 46 * Equipment Corporation makes any representations about the suitability 47 * of this software for any purpose. 48 * 49 * Copyright (c) 2007, Novell, Inc. All rights reserved. 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in the 58 * documentation and/or other materials provided with the distribution. 59 * 3. Neither the name of Novell Inc. nor the names of its contributors 60 * may be used to endorse or promote products derived from this 61 * this software without specific prior written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 64 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 65 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 66 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY 67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 68 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 69 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 70 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 71 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 72 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73 * 74 * @APPLE_LICENSE_HEADER_END@ 75 */ 76 77/* 78** 79** NAME: 80** 81** rpcdbg.h 82** 83** FACILITY: 84** 85** Remote Procedure Call (RPC) 86** 87** ABSTRACT: 88** 89** Various macros and data to assist with debugging related code. 90** 91** 92*/ 93 94#ifndef _RPCDBG_H 95#define _RPCDBG_H 1 96 97/* 98 * Debug has been separated into messaging 99 * code and "other" ... messaging now largely 100 * implemented by rpcsvc.{c,h} 101 */ 102# include <rpcsvc.h> 103 104/* 105 * A few macros for dealing with debugging code / printfs. 106 * 107 * The model here is that there are a number of debug "switches", each one 108 * of which can be set to some debug "level". The switches are represented 109 * as an enumeration. 110 */ 111 112/* 113 * The debug switches. 114 */ 115 116typedef enum { 117 rpc_es_dgb_none = 0, 118 rpc_es_dbg_general, /* 1 */ 119 rpc_es_dbg_mutex, /* 2 */ 120 rpc_es_dbg_xmit, /* 3 */ 121 rpc_es_dbg_recv, /* 4 */ 122 rpc_es_dbg_dg_lossy, /* 5 */ 123 rpc_es_dbg_dg_state, /* 6 */ 124 rpc_es_dbg_ip_max_pth_unfrag_tpdu, /* 7 */ 125 rpc_es_dbg_ip_max_loc_unfrag_tpdu, /* 8 */ 126 rpc_es_dbg_dds_max_pth_unfrag_tpdu, /* 9 */ 127 rpc_es_dbg_dds_max_loc_unfrag_tpdu, /* 10 */ 128 rpc_es_dbg_dg_rq_qsize, /* 11 */ 129 rpc_es_dbg_cancel, /* 12 */ 130 rpc_es_dbg_orphan, /* 13 */ 131 rpc_es_dbg_cn_state, /* 14 */ 132 rpc_es_dbg_cn_pkt, /* 15 */ 133 rpc_es_dbg_pkt_quotas, /* 16 */ 134 rpc_es_dbg_auth, /* 17 */ 135 rpc_es_dbg_source, /* 18 */ 136 rpc_es_dbg_pkt_quota_size, /* 19 */ 137 rpc_es_dbg_stats, /* 20 */ 138 rpc_es_dbg_mem, /* 21 */ 139 rpc_es_dbg_mem_type, /* 22 */ 140 rpc_es_dbg_dg_pktlog, /* 23 */ 141 rpc_es_dbg_thread_id, /* 24 */ 142 rpc_es_dbg_timestamp, /* 25 */ 143 rpc_es_dbg_cn_errors, /* 25 */ 144 rpc_es_dbg_conv_thread, /* 27 */ 145 rpc_es_dbg_pid, /* 28 */ 146 rpc_es_dbg_atfork, /* 29 */ 147 rpc_es_dbg_cma_thread, /* 30 */ 148 rpc_es_dbg_inherit, /* 31 */ 149 rpc_es_dbg_dg_sockets, /* 32 */ 150 rpc_es_dbg_ip_max_tsdu, /* 33 */ 151 rpc_es_dbg_dg_max_psock, /* 34 */ 152 rpc_es_dbg_dg_max_window_size, /* 35 */ 153 rpc_es_dbg_threads, /* 36 */ 154 rpc_es_dbg_uxd_max_pth_unfrag_tpdu, /* 37 */ 155 rpc_es_dbg_uxd_max_loc_unfrag_tpdu, /* 38 */ 156 rpc_es_dbg_uxd_max_tsdu, /* 39 */ 157 rpc_es_dbg_np_max_pth_unfrag_tpdu, /* 40 */ 158 rpc_es_dbg_np_max_loc_unfrag_tpdu, /* 41 */ 159 rpc_es_dbg_np_max_tsdu, /* 42 */ 160 rpc_es_dbg_server_call, /* 43 */ 161 rpc_es_dbg_libidl, /* 44 */ 162 rpc_es_dbg_dg_pkt, /* 45 */ 163 164 /* 165 * Add new switches above this comment and adjust the 166 * "last_switch" value if necessary. We keep a few 167 * empty slots to allow for easy temporary additions. 168 */ 169 rpc_es_dbg_last_switch = 45 /* 45 */ 170} rpc_dbg_switch_t; 171 172#define RPC_DBG_N_SWITCHES (((int) rpc_es_dbg_last_switch) + 1) 173 174/* 175 * Debug table 176 * 177 * A vector of "debug levels", one level per "debug switch". 178 */ 179EXTERNAL unsigned8 rpc_g_dbg_switches[]; 180 181/* 182 * R P C _ D B G 183 * 184 * Tests whether a particular debug switch is set at a particular level (or 185 * higher). 186 */ 187#define RPC_DBG(switch, level) (rpc_g_dbg_switches[(int) (switch)] >= (level)) 188 189/* 190 * R P C _ D B G _ E X A C T 191 * 192 * Tests whether a particular debug switch is set at exactly a particular level 193 */ 194#define RPC_DBG_EXACT(switch, level) (rpc_g_dbg_switches[(int) (switch)] == (level)) 195 196/* 197 * a macro to set *status rpc_s_coding_error 198 */ 199#define CODING_ERROR(status) *(status) = rpc_s_coding_error 200 201#ifndef DCE_RPC_SVC 202/* 203 * R P C _ D B G _ P R I N T F 204 * 205 * A macro that prints debug info based on a debug switch's level. Note 206 * that this macro is intended to be used as follows: 207 * 208 * RPC_DBG_PRINTF(rpc_es_dbg_xmit, 3, ("Sent pkt %d", pkt_count)); 209 * 210 * I.e. the third parameter is the argument list to "printf" and must be 211 * enclosed in parens. 212 * 213 */ 214#define RPC_DBG_ADD_PRINTF(switch, level, pargs) \ 215do { \ 216 if (RPC_DBG((switch), (level))) {\ 217 rpc__printf pargs; \ 218} } while(0) 219 220#define RPC_DBG_PRINTF(switch, level, pargs) \ 221do { \ 222 if (RPC_DBG((switch), (level))) { \ 223 rpc__printf pargs ; \ 224 rpc__print_source(__FILE__, __LINE__); \ 225} } while(0) 226 227#define RPC_DBG_GPRINTF(pargs) \ 228 RPC_DBG_PRINTF(rpc_es_dbg_general, 1, pargs) 229 230#else /* !DCE_RPC_SVC */ 231 232/* 233 * R P C _ D B G _ G P R I N T F 234 * 235 * A macro on top of RPC_DBG_PRINTF that's used for printing random general 236 * debug info. Sample usage: 237 * 238 * RPC_DBG_GPRINTF(("Sent pkt %d", pkt_count)); 239 * 240 */ 241 242#define RPC_DBG_GPRINTF(pargs) \ 243 RPC_DBG_PRINTF(rpc_es_dbg_general, 1, pargs) 244 245#endif /* !DCE_RPC_SVC */ 246 247/* 248 * R P C _ _ D B G _ S E T _ S W I T C H E S 249 */ 250 251PUBLIC void rpc__dbg_set_switches ( 252 const char * /*s*/, 253 unsigned32 * /*st*/ 254 ); 255 256#ifndef DCE_RPC_SVC 257/* 258 * R P C _ _ P R I N T F 259 * 260 * Note: This function uses a variable-length argument list. The "right" 261 * way to handle this is using the ANSI C notation (listed below under 262 * #ifdef STDARG_PRINTF). However, not all of the compilers support this, 263 * so it's here just for future reference purposes. 264 * 265 * An alternative is to use the "varargs" convention (listed below under 266 * #ifndef NO_VARARGS_PRINTF). Most compilers support this convention, 267 * however you can't use prototypes with this. 268 * 269 * The next to last choice is to use the "old" notation. In this case 270 * also you can't use prototypes. 271 * 272 * The last choice is to abandon this all together, define NO_RPC_PRINTF 273 * and just use "printf" (from commonp.h). 274 */ 275 276#ifndef NO_RPC_PRINTF 277 278#include <stdarg.h> 279 280PRIVATE ssize_t rpc__printf ( const char * /*format*/, ...) 281#if __GNUC__ 282__attribute__((__format__ (__printf__, 1, 2))) 283#endif 284; 285 286#endif /* NO_RPC_PRINTF */ 287 288#endif /* !DCE_RPC_SVC */ 289 290/* 291 * R P C _ _ D I E 292 */ 293 294PRIVATE void rpc__die ( 295 char * /*text*/, 296 char * /*file*/, 297 int /*line*/ 298 ); 299 300/* 301 * R P C _ _ U U I D _ S T R I N G 302 */ 303 304PRIVATE char *rpc__uuid_string ( idl_uuid_t */*uuid*/); 305 306/* 307 * R P C _ _ P R I N T _ S O U R C E 308 */ 309 310PRIVATE void rpc__print_source ( 311 const char * /*file*/, 312 int /*line*/ 313 ); 314 315#endif /* _RPCDBG_H */ 316