]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/debugging.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // debugging - non-trivial debug support
25 #include <Security/utilities.h>
36 // Debug to standard target
37 void debug(const char *scope
, const char *format
, ...) __attribute__((format(printf
,2,3)));
38 void vdebug(const char *scope
, const char *format
, va_list args
);
39 bool debugging(const char *scope
);
41 // Stream dumping to standard target
42 bool dumping(const char *scope
);
43 void dump(const char *format
, ...) __attribute((format(printf
,1,2)));
44 void dumpData(const void *data
, size_t length
);
45 void dumpData(const char *title
, const void *data
, size_t length
);
46 template <class Data
> inline void dumpData(const Data
&obj
)
47 { dumpData(obj
.data(), obj
.length()); }
48 template <class Data
> inline void dumpData(const char *title
, const Data
&obj
)
49 { dumpData(title
, obj
.data(), obj
.length()); }
51 #if defined(DEBUGDUMP)
52 # define IFDUMP(code) code
53 # define IFDUMPING(scope,code) if (Debug::dumping(scope)) code; else /* no */
55 # define IFDUMP(code) /* no-op */
56 # define IFDUMPING(scope,code) /* no-op */
61 // A (prepared) debug scope object.
65 Scope(const char *string
) { mScope
= string
; }
67 void operator () (const char *format
, ...);
75 // Given an object of any type, produce the proper name of its type.
77 string
makeTypeName(const type_info
&info
);
79 template <class Object
>
80 string
typeName(const Object
&obj
)
82 return makeTypeName(typeid(obj
));
90 // If NDEBUG is defined, we try to make all debugging functions weightless
94 inline void debug(const char *, const char *, ...) { }
96 // @@@ Hack to work around the fact that gcc2 can't inline empty varargs functions.
97 extern "C" inline void debug() { }
100 inline void vdebug(const char *, const char *, va_list) { }
101 inline bool debugging(const char *) { return false; }
105 Scope(const char *) { }
107 // @@@ Hack to work around the fact that gcc can't inline empty varargs functions.
108 //void operator () (const char *, ...) { }
109 void operator () (const char *, ...);
112 inline bool dumping(const char *) { return false; }
114 // @@@ Hack to work around the fact that gcc can't inline empty varargs functions.
115 //inline void dump(const char *, ...) { }
116 extern "C" inline void dump() { }
118 inline void dumpData(const void *, size_t) { }
119 void dumpData(const char *, const void *, size_t);
120 template <class Data
> inline void dumpData(const Data
&) { }
121 template <class Data
> inline void dumpData(const char *, const Data
&) { }
123 // debugdumping is forced off
124 #if defined(DEBUGDUMP)
127 # define IFDUMP(code) /* no-op */
128 # define IFDUMPING(scope,code) /* no-op */
130 // no debug typeName; don't call this if NDEBUG
135 } // end namespace Debug
136 } // end namespace Security
138 // We intentionally leak a few functions into the global namespace
139 using Security::Debug::debug
;
142 #endif //_H_DEBUGGING