]>
git.saurik.com Git - apple/security.git/blob - libsecurity_utilities/lib/debugging.h
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // debugging - non-trivial debug support
33 // Include DTrace static probe definitions
35 typedef const void *DTException
;
37 #include <security_utilities/utilities_dtrace.h>
42 #include <security_utilities/utilities.h>
52 // Debug-dumping functions always exist. They may be stubs depending on build options.
54 bool dumping(const char *scope
);
55 void dump(const char *format
, ...) __attribute((format(printf
,1,2)));
56 void dumpData(const void *data
, size_t length
);
57 void dumpData(const char *title
, const void *data
, size_t length
);
58 template <class Data
> inline void dumpData(const Data
&obj
)
59 { dumpData(obj
.data(), obj
.length()); }
60 template <class Data
> inline void dumpData(const char *title
, const Data
&obj
)
61 { dumpData(title
, obj
.data(), obj
.length()); }
65 // The following functions perform runtime recovery of type names.
66 // This is meant for debugging ONLY. Don't even THINK of depending
67 // on this for program correctness. For all you know, we may replace
68 // all those names with "XXX" tomorrow.
70 string
makeTypeName(const type_info
&info
);
72 template <class Object
>
73 string
typeName(const Object
&obj
)
75 return makeTypeName(typeid(obj
));
78 template <class Object
>
81 return makeTypeName(typeid(Object
));
86 // We are still conditionally emitting debug-dumping code
96 #if defined(DEBUGDUMP)
97 # define IFDUMP(code) code
98 # define IFDUMPING(scope,code) if (Debug::dumping(scope)) code; else /* no */
100 # define IFDUMP(code) /* no-op */
101 # define IFDUMPING(scope,code) /* no-op */
106 // We have some very, very old customers who call old debug facilities.
107 // Dummy them out for now.
109 inline bool debugging(const char *scope
) DEPRECATED_ATTRIBUTE
;
110 inline void debug(const char *scope
, const char *format
, ...) DEPRECATED_ATTRIBUTE
;
111 inline void vdebug(const char *scope
, const char *format
, va_list args
) DEPRECATED_ATTRIBUTE
;
113 inline bool debugging(const char *scope
) { return false; }
114 inline void debug(const char *scope
, const char *format
, ...) { }
115 inline void vdebug(const char *scope
, const char *format
, va_list args
) { }
121 } // end namespace Debug
122 } // end namespace Security
124 // leak debug() into the global namespace because URLAccess et al rely on that
125 using Security::Debug::debug
;
136 // The debug-log macro is now unconditionally emitted as a DTrace static probe point.
138 #define secdebug(scope, format...) \
139 if (__builtin_expect(SECURITY_DEBUG_LOG_ENABLED(), 0)) { \
140 char __msg[500]; snprintf(__msg, sizeof(__msg), ## format); \
141 volatile char c __attribute__((unused)) = scope[0]; \
142 SECURITY_DEBUG_LOG((char *)(scope), (__msg)); \
144 #define secdebugf(scope, __msg) SECURITY_DEBUG_LOG((char *)(scope), (__msg))
148 // The old secdelay() macro is also emitted as a DTrace probe (use destructive actions to handle this).
149 // Secdelay() should be considered a legacy feature; just put a secdebug at the intended delay point.
151 #define secdelay(file) SECURITY_DEBUG_DELAY((char *)(file))
154 #endif //_H_DEBUGGING