]> git.saurik.com Git - apple/security.git/blame - OSX/libsecurity_utilities/lib/debugging_internal.h
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / debugging_internal.h
CommitLineData
427c49bc 1/*
fa7225c8
A
2 * Copyright (c) 2000-2004,2011-2012,2014 Apple Inc. All Rights Reserved.
3 *
427c49bc
A
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
fa7225c8
A
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
427c49bc 32
d8f41ccd 33#ifdef __cplusplus
fa7225c8
A
34
35#include <security_utilities/utilities.h>
36#include <cstdarg>
37#include <typeinfo>
38
39namespace Security {
40namespace Debug {
41
42
43//
44// Debug-dumping functions always exist. They may be stubs depending on build options.
45//
46bool dumping(const char *scope);
47void dump(const char *format, ...) __attribute((format(printf,1,2)));
48void dumpData(const void *data, size_t length);
49void dumpData(const char *title, const void *data, size_t length);
50template <class Data> inline void dumpData(const Data &obj)
51{ dumpData(obj.data(), obj.length()); }
52template <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//
62string makeTypeName(const type_info &info);
63
64template <class Object>
65string typeName(const Object &obj)
427c49bc 66{
fa7225c8
A
67 return makeTypeName(typeid(obj));
68}
69
70template <class Object>
71string typeName()
72{
73 return makeTypeName(typeid(Object));
74}
75
d8f41ccd
A
76
77//
fa7225c8 78// We are still conditionally emitting debug-dumping code
d8f41ccd 79//
fa7225c8
A
80#undef DEBUGGING
81#if !defined(NDEBUG)
82# define DEBUGGING 1
79b9da22
A
83// No more debugdump, it emits thread-unsafe buggy code which hampers actual debugging, ironically enough
84// # define DEBUGDUMP 1
fa7225c8
A
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
d8f41ccd 96
d8f41ccd
A
97
98//
fa7225c8
A
99// We have some very, very old customers who call old debug facilities.
100// Dummy them out for now.
d8f41ccd 101//
fa7225c8
A
102inline bool debugging(const char *scope) DEPRECATED_ATTRIBUTE;
103inline void debug(const char *scope, const char *format, ...) DEPRECATED_ATTRIBUTE;
104inline void vdebug(const char *scope, const char *format, va_list args) DEPRECATED_ATTRIBUTE;
105
106inline bool debugging(const char *scope) { return false; }
107inline void debug(const char *scope, const char *format, ...) { }
108inline void vdebug(const char *scope, const char *format, va_list args) { }
109
d8f41ccd 110
d8f41ccd 111
fa7225c8
A
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
118using Security::Debug::debug;
119
120__BEGIN_DECLS
d8f41ccd
A
121
122//
fa7225c8 123// Include DTrace static probe definitions
d8f41ccd 124//
fa7225c8
A
125typedef const void *DTException;
126#include <security_utilities/utilities_dtrace.h>
d8f41ccd 127
fa7225c8 128// The following are deprecated functions. Don't use them (but they need to be here for symbol reasons).
79b9da22
A
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, ...);
d8f41ccd 131
fa7225c8 132__END_DECLS
d8f41ccd 133
fa7225c8
A
134#else //__cplusplus
135
136#include <stdio.h>
137
138#endif //__cplusplus
139
140#include <CoreFoundation/CFString.h>
141
142
143#endif //_H_DEBUGGING