]>
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
27 #include <Security/utilities.h>
36 // Debug logging functions always exist.
37 // They may be stubs depending on build options.
39 bool debugging(const char *scope
);
40 void debug(const char *scope
, const char *format
, ...) __attribute__((format(printf
,2,3)));
41 void vdebug(const char *scope
, const char *format
, va_list args
);
44 // Ditto with debug dumping functions.
46 bool dumping(const char *scope
);
47 void dump(const char *format
, ...) __attribute((format(printf
,1,2)));
48 void dumpData(const void *data
, size_t length
);
49 void dumpData(const char *title
, const void *data
, size_t length
);
50 template <class Data
> inline void dumpData(const Data
&obj
)
51 { dumpData(obj
.data(), obj
.length()); }
52 template <class Data
> inline void dumpData(const char *title
, const Data
&obj
)
53 { dumpData(title
, obj
.data(), obj
.length()); }
57 // The following functions perform runtime recovery of type names.
58 // This is meant for debugging ONLY. Don't even THINK of depending
59 // on this for program correctness. For all you know, we may replace
60 // all those names with "XXX" tomorrow.
62 string
makeTypeName(const type_info
&info
);
64 template <class Object
>
65 string
typeName(const Object
&obj
)
67 return makeTypeName(typeid(obj
));
70 template <class Object
>
73 return makeTypeName(typeid(Object
));
78 // Now for the conditional inline code
81 # define secdebug(scope, format...) Security::Debug::debug(scope, ## format)
83 # define secdebug(scope, format...) /* nothing */
88 // Conditional dump code
90 #if defined(DEBUGDUMP)
91 # define IFDUMP(code) code
92 # define IFDUMPING(scope,code) if (Debug::dumping(scope)) code; else /* no */
94 # define IFDUMP(code) /* no-op */
95 # define IFDUMPING(scope,code) /* no-op */
100 // Kernel trace support
102 inline void trace(int code
, int arg1
= 0, int arg2
= 0, int arg3
= 0, int arg4
= 0)
104 #if defined(ENABLE_SECTRACE)
105 syscall(180, code
, arg1
, arg2
, arg3
, arg4
);
110 } // end namespace Debug
111 } // end namespace Security
113 // We intentionally leak a few functions into the global namespace
114 // @@@ (not much longer: after the switch to secdebug(), this will go)
115 using Security::Debug::debug
;
118 #else //!__cplusplus, C code
121 extern void __security_debug(const char *scope
, const char *format
, ...);
122 extern int __security_debugging(const char *scope
);
125 # define secdebug(scope, format...) __security_debug(scope, ## format)
127 # define secdebug(scope, format...) /* nothing */
131 // ktrace support (C style)
132 extern void security_ktrace(int code
);
136 #endif //_H_DEBUGGING