]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/debugging_internal.h
Security-59306.11.20.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / debugging_internal.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_internal - non-trivial debug support
27 //
28 // everything in this file is deprecated. Try not to use it.
29 //
30 #ifndef _H_DEBUGGING
31 #define _H_DEBUGGING
32
33 #ifdef __cplusplus
34
35 #include <security_utilities/utilities.h>
36 #include <cstdarg>
37 #include <typeinfo>
38
39 namespace Security {
40 namespace Debug {
41
42
43 //
44 // Debug-dumping functions always exist. They may be stubs depending on build options.
45 //
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()); }
54
55
56 //
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.
61 //
62 string makeTypeName(const type_info &info);
63
64 template <class Object>
65 string typeName(const Object &obj)
66 {
67 return makeTypeName(typeid(obj));
68 }
69
70 template <class Object>
71 string typeName()
72 {
73 return makeTypeName(typeid(Object));
74 }
75
76
77 //
78 // We are still conditionally emitting debug-dumping code
79 //
80 #undef DEBUGGING
81 #if !defined(NDEBUG)
82 # define DEBUGGING 1
83 // No more debugdump, it emits thread-unsafe buggy code which hampers actual debugging, ironically enough
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 __BEGIN_DECLS
121
122 //
123 // Include DTrace static probe definitions
124 //
125 typedef const void *DTException;
126 #include <security_utilities/utilities_dtrace.h>
127
128 // The following are deprecated functions. Don't use them (but they need to be here for symbol reasons).
129 __attribute__((visibility("default"))) void secdebug_internal(const char* scope, const char* format, ...);
130 __attribute__((visibility("default"))) void secdebugfunc_internal(const char* scope, const char* functionname, const char* format, ...);
131
132 __END_DECLS
133
134 #else //__cplusplus
135
136 #include <stdio.h>
137
138 #endif //__cplusplus
139
140 #include <CoreFoundation/CFString.h>
141
142
143 #endif //_H_DEBUGGING