]> git.saurik.com Git - apple/security.git/blame - cdsa/cdsa_utilities/debugging.h
Security-30.1.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / debugging.h
CommitLineData
bac41a7b
A
1/*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19//
20// debugging - non-trivial debug support
21//
22#ifndef _H_DEBUGGING
23#define _H_DEBUGGING
24
25#include <Security/utilities.h>
26#include <cstdarg>
27
28#ifdef _CPP_DEBUGGING
29#pragma export on
30#endif
31
32namespace Security {
33namespace Debug {
34
35
36#if !defined(NDEBUG)
37
38
39// Debug to standard target
40void debug(const char *scope, const char *format, ...) __attribute__((format(printf,2,3)));
41void vdebug(const char *scope, const char *format, va_list args);
42bool debugging(const char *scope);
43
44// Stream dumping to standard target
45bool dumping(const char *scope);
46void dump(const char *format, ...) __attribute((format(printf,1,2)));
47void dumpData(const void *data, size_t length);
48void dumpData(const char *title, const void *data, size_t length);
49template <class Data> inline void dumpData(const Data &obj)
50{ dumpData(obj.data(), obj.length()); }
51template <class Data> inline void dumpData(const char *title, const Data &obj)
52{ dumpData(title, obj.data(), obj.length()); }
53
54#if defined(DEBUGDUMP)
55# define IFDUMP(code) code
56# define IFDUMPING(scope,code) if (Debug::dumping(scope)) code; else /* no */
57#else
58# define IFDUMP(code) /* no-op */
59# define IFDUMPING(scope,code) /* no-op */
60#endif
61
62
63//
64// A (prepared) debug scope object.
65//
66class Scope {
67public:
68 Scope(const char *string) { mScope = string; }
69
70 void operator () (const char *format, ...);
71
72private:
73 const char *mScope;
74};
75
76
77#else // NDEBUG
78
79
80//
81// If NDEBUG is defined, we try to make all debugging functions weightless
82//
83inline void debug(const char *, const char *, ...) { }
84inline void vdebug(const char *, const char *, va_list) { }
85inline bool debugging(const char *) { return false; }
86
87class Scope {
88public:
89 Scope(const char *) { }
90 void operator () (const char *, ...) { }
91};
92
93inline bool dumping(const char *) { return false; }
94inline void dump(const char *, ...) { }
95inline void dumpData(const void *, size_t) { }
96void dumpData(const char *, const void *, size_t);
97template <class Data> inline void dumpData(const Data &) { }
98template <class Data> inline void dumpData(const char *, const Data &) { }
99
100// debugdumping is forced off
101#if defined(DEBUGDUMP)
102# undef DEBUGDUMP
103#endif
104# define IFDUMP(code) /* no-op */
105# define IFDUMPING(scope,code) /* no-op */
106
107#endif // NDEBUG
108
109
110} // end namespace Debug
111
112} // end namespace Security
113
114// We intentionally leak a few functions into the global namespace
115using Security::Debug::debug;
116
117
118#ifdef _CPP_DEBUGGING
119#pragma export off
120#endif
121
122#endif //_H_DEBUGGING