1/*
2 * Copyright (c) 2000, 2005 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/*	hfs_dbg.h
29 *
30 *	(c) 1997 Apple Computer, Inc.  All Rights Reserved
31 *
32 *	hfs_dbg.h -- debugging macros for HFS file system.
33 *
34 *	HISTORY
35 *	10-Nov-1998 Pat Dirks		Cleaned up definition of DBG_ASSERT to handle embedded '%' correctly.
36 *	28-Apr-1998	Scott Roberts	Reorganized and added HFS_DEBUG_STAGE
37 *	17-Nov-1997	Pat Dirks		Pat Dirks at Apple Computer
38 *								Derived from old hfs version.
39 */
40
41struct componentname;
42extern void Debugger(const char *message);
43
44/* Define the debugging stage...
45		4 -> Do all, aggresive, call_kdp
46		3 -> debug asserts and debug err, panic instead of call_kdp
47		2 -> debug error, no kdb
48		1 -> very little, panic only
49*/
50#ifndef HFS_DIAGNOSTIC
51	#define HFS_DIAGNOSTIC 0
52#endif /* HFS_DIAGNOSTIC */
53
54#ifndef HFS_DEBUG_STAGE
55#if HFS_DIAGNOSTIC
56	#define HFS_DEBUG_STAGE 4
57#else
58	#define HFS_DEBUG_STAGE 1
59#endif /* KERNEL */
60#endif	/* HFS_DEBUG_STAGE */
61
62#ifdef KERNEL
63  #define PRINTIT kprintf
64#else /* KERNEL */
65  #define PRINTIT printf
66#endif /* KERNEL */
67
68#if (HFS_DEBUG_STAGE > 3)
69#define DEBUG_BREAK Debugger("");
70#else
71#define DEBUG_BREAK
72#endif
73
74#if (HFS_DEBUG_STAGE == 4)
75    #define DEBUG_BREAK_MSG(PRINTF_ARGS) { PRINTIT PRINTF_ARGS; DEBUG_BREAK };
76#elif (HFS_DEBUG_STAGE == 3)
77    #define DEBUG_BREAK_MSG(PRINTF_ARGS) { panic PRINTF_ARGS;};
78#else
79    #define DEBUG_BREAK_MSG(PRINTF_ARGS) { PRINTIT PRINTF_ARGS; };
80#endif
81
82
83#define PRINT_DELAY
84
85/*
86 * Debugging macros.
87 */
88#if	HFS_DIAGNOSTIC
89extern int hfs_dbg_all;
90extern int hfs_dbg_err;
91
92#ifdef KERNEL
93    #if (HFS_DEBUG_STAGE == 4)
94		char		gDebugAssertStr[255];
95		#define DBG_ASSERT(a) { if (!(a)) { \
96				snprintf(gDebugAssertStr, sizeof (gDebugAssertStr), "Oops - File "__FILE__", line %d: assertion '%s' failed.\n", __LINE__, #a); \
97                Debugger(gDebugAssertStr); } }
98	#else
99#define DBG_ASSERT(a) { if (!(a)) { panic("File "__FILE__", line %d: assertion '%s' failed.\n", __LINE__, #a); } }
100    #endif /* HFS_DEBUG_STAGE */
101#else
102    #define DBG_ASSERT(a) assert(a)
103#endif /* KERNEL */
104
105#define DBG_ERR(x)	{		\
106	if(hfs_dbg_all || hfs_dbg_err) {	\
107        PRINTIT("%X: ", proc_selfpid()); \
108	    PRINTIT("HFS ERROR: "); \
109	    PRINTIT x;			\
110	    PRINT_DELAY;  \
111	};			\
112}
113
114#else	/* HFS_DIAGNOSTIC */
115
116#define DBG_ASSERT(a)
117#define DBG_ERR(x)
118
119#endif	/* HFS_DIAGNOSTIC */
120
121