]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_utilities/lib/debugging_internal.h
Security-58286.20.16.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / debugging_internal.h
index f4e7cb852adab7ccef50134ddaf8b69224af6533..a33ee7c2c70c1fdc15aff933a7c5aea36a615703 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2012,2014 Apple Inc. All Rights Reserved.
- *
+ * Copyright (c) 2000-2004,2011-2012,2014 Apple Inc. All Rights Reserved.
+ * 
  * @APPLE_LICENSE_HEADER_START@
  * 
  * This file contains Original Code and/or Modifications of Original Code
  */
 
 
-#ifndef libsecurity_utilities_debugging_internal_h
-#define libsecurity_utilities_debugging_internal_h
-
+//
+// debugging_internal - non-trivial debug support
+//
+// everything in this file is deprecated. Try not to use it.
+//
+#ifndef _H_DEBUGGING
+#define _H_DEBUGGING
 
 #ifdef __cplusplus
-extern "C"
+
+#include <security_utilities/utilities.h>
+#include <cstdarg>
+#include <typeinfo>
+
+namespace Security {
+namespace Debug {
+
+
+//
+// Debug-dumping functions always exist. They may be stubs depending on build options.
+//
+bool dumping(const char *scope);
+void dump(const char *format, ...) __attribute((format(printf,1,2)));
+void dumpData(const void *data, size_t length);
+void dumpData(const char *title, const void *data, size_t length);
+template <class Data> inline void dumpData(const Data &obj)
+{ dumpData(obj.data(), obj.length()); }
+template <class Data> inline void dumpData(const char *title, const Data &obj) 
+{ dumpData(title, obj.data(), obj.length()); }
+
+
+//
+// The following functions perform runtime recovery of type names.
+// This is meant for debugging ONLY. Don't even THINK of depending
+// on this for program correctness. For all you know, we may replace
+// all those names with "XXX" tomorrow.
+//
+string makeTypeName(const type_info &info);
+
+template <class Object>
+string typeName(const Object &obj)
 {
-#endif // __cplusplus
+       return makeTypeName(typeid(obj));
+}
+
+template <class Object>
+string typeName()
+{
+       return makeTypeName(typeid(Object));
+}
+
 
 //
-// Include DTrace static probe definitions
+// We are still conditionally emitting debug-dumping code
 //
-typedef const void *DTException;
+#undef DEBUGGING
+#if !defined(NDEBUG)
+# define DEBUGGING 1
+# define DEBUGDUMP  1
+#else //NDEBUG
+# define DEBUGGING 0
+#endif //NDEBUG
+
+#if defined(DEBUGDUMP)
+# define IFDUMP(code)                          code
+# define IFDUMPING(scope,code)         if (Debug::dumping(scope)) code; else /* no */
+#else
+# define IFDUMP(code)                          /* no-op */
+# define IFDUMPING(scope,code)         /* no-op */
+#endif
 
-#include <security_utilities/utilities_dtrace.h>
 
 //
-// The debug-log macro is now unconditionally emitted as a DTrace static probe point.
+// We have some very, very old customers who call old debug facilities.
+// Dummy them out for now.
 //
+inline bool debugging(const char *scope) DEPRECATED_ATTRIBUTE;
+inline void debug(const char *scope, const char *format, ...) DEPRECATED_ATTRIBUTE;
+inline void vdebug(const char *scope, const char *format, va_list args) DEPRECATED_ATTRIBUTE;
+
+inline bool debugging(const char *scope) { return false; }
+inline void debug(const char *scope, const char *format, ...) { }
+inline void vdebug(const char *scope, const char *format, va_list args) { }
+
 
-void secdebug_internal(const char* scope, const char* format, ...);
 
-#define secdebug(scope, format...) secdebug_internal(scope, format)
-#define secdebugf(scope, __msg)        SECURITY_DEBUG_LOG((char *)(scope), (__msg))
+
+
+} // end namespace Debug
+} // end namespace Security
+
+// leak debug() into the global namespace because URLAccess et al rely on that
+using Security::Debug::debug;
+
+__BEGIN_DECLS
 
 //
-// The old secdelay() macro is also emitted as a DTrace probe (use destructive actions to handle this).
-// Secdelay() should be considered a legacy feature; just put a secdebug at the intended delay point.
+// Include DTrace static probe definitions
 //
-#define secdelay(file) SECURITY_DEBUG_DELAY((char *)(file))
+typedef const void *DTException;
+#include <security_utilities/utilities_dtrace.h>
 
+// The following are deprecated functions. Don't use them (but they need to be here for symbol reasons).
+void secdebug_internal(const char* scope, const char* format, ...);
+void secdebugfunc_internal(const char* scope, const char* functionname, const char* format, ...);
 
-#ifdef __cplusplus
-};
-#endif // __cplusplus
+__END_DECLS
 
-#endif
+#else  //__cplusplus
+
+#include <stdio.h>
+
+#endif //__cplusplus
+
+#include <CoreFoundation/CFString.h>
+
+
+#endif //_H_DEBUGGING