]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/debugging.h
Security-57337.40.85.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / debugging.h
1 /*
2 * Copyright (c) 2000-2004,2011-2012,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 //
26 // debugging - non-trivial debug support
27 //
28 #ifndef _H_DEBUGGING
29 #define _H_DEBUGGING
30
31
32 #include <security_utilities/debugging_internal.h>
33
34 #ifdef __cplusplus
35
36 #include <security_utilities/utilities.h>
37 #include <cstdarg>
38 #include <typeinfo>
39
40 namespace Security {
41 namespace Debug {
42
43
44 //
45 // Debug-dumping functions always exist. They may be stubs depending on build options.
46 //
47 bool dumping(const char *scope);
48 void dump(const char *format, ...) __attribute((format(printf,1,2)));
49 void dumpData(const void *data, size_t length);
50 void dumpData(const char *title, const void *data, size_t length);
51 template <class Data> inline void dumpData(const Data &obj)
52 { dumpData(obj.data(), obj.length()); }
53 template <class Data> inline void dumpData(const char *title, const Data &obj)
54 { dumpData(title, obj.data(), obj.length()); }
55
56
57 //
58 // The following functions perform runtime recovery of type names.
59 // This is meant for debugging ONLY. Don't even THINK of depending
60 // on this for program correctness. For all you know, we may replace
61 // all those names with "XXX" tomorrow.
62 //
63 string makeTypeName(const type_info &info);
64
65 template <class Object>
66 string typeName(const Object &obj)
67 {
68 return makeTypeName(typeid(obj));
69 }
70
71 template <class Object>
72 string typeName()
73 {
74 return makeTypeName(typeid(Object));
75 }
76
77
78 //
79 // We are still conditionally emitting debug-dumping code
80 //
81 #undef DEBUGGING
82 #if !defined(NDEBUG)
83 # define DEBUGGING 1
84 # define DEBUGDUMP 1
85 #else //NDEBUG
86 # define DEBUGGING 0
87 #endif //NDEBUG
88
89 #if defined(DEBUGDUMP)
90 # define IFDUMP(code) code
91 # define IFDUMPING(scope,code) if (Debug::dumping(scope)) code; else /* no */
92 #else
93 # define IFDUMP(code) /* no-op */
94 # define IFDUMPING(scope,code) /* no-op */
95 #endif
96
97
98 //
99 // We have some very, very old customers who call old debug facilities.
100 // Dummy them out for now.
101 //
102 inline bool debugging(const char *scope) DEPRECATED_ATTRIBUTE;
103 inline void debug(const char *scope, const char *format, ...) DEPRECATED_ATTRIBUTE;
104 inline void vdebug(const char *scope, const char *format, va_list args) DEPRECATED_ATTRIBUTE;
105
106 inline bool debugging(const char *scope) { return false; }
107 inline void debug(const char *scope, const char *format, ...) { }
108 inline void vdebug(const char *scope, const char *format, va_list args) { }
109
110
111
112
113
114 } // end namespace Debug
115 } // end namespace Security
116
117 // leak debug() into the global namespace because URLAccess et al rely on that
118 using Security::Debug::debug;
119
120 #else //__cplusplus
121
122 #include <stdio.h>
123
124 #endif //__cplusplus
125
126 #include <CoreFoundation/CFString.h>
127
128
129 #endif //_H_DEBUGGING