#ifndef _H_DEBUGGING
#define _H_DEBUGGING
#ifdef __cplusplus
#include <Security/utilities.h>
#include <cstdarg>
#include <typeinfo>
namespace Security {
namespace Debug {
bool debugging(const char *scope);
void debug(const char *scope, const char *format, ...) __attribute__((format(printf,2,3)));
void vdebug(const char *scope, const char *format, va_list args);
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()); }
string makeTypeName(const type_info &info);
template <class Object>
string typeName(const Object &obj)
{
return makeTypeName(typeid(obj));
}
template <class Object>
string typeName()
{
return makeTypeName(typeid(Object));
}
#if !defined(NDEBUG)
# define secdebug(scope, format...) Security::Debug::debug(scope, ## format)
#else //NDEBUG
# define secdebug(scope, format...)
#endif //NDEBUG
#if defined(DEBUGDUMP)
# define IFDUMP(code) code
# define IFDUMPING(scope,code) if (Debug::dumping(scope)) code; else
#else
# define IFDUMP(code)
# define IFDUMPING(scope,code)
#endif
inline void trace(int code, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0)
{
#if defined(ENABLE_SECTRACE)
syscall(180, code, arg1, arg2, arg3, arg4);
#endif
}
} }
using Security::Debug::debug;
#else //!__cplusplus, C code
extern void __security_debug(const char *scope, const char *format, ...);
extern int __security_debugging(const char *scope);
#if !defined(NDEBUG)
# define secdebug(scope, format...) __security_debug(scope, ## format)
#else
# define secdebug(scope, format...)
#endif
extern void security_ktrace(int code);
#endif //__cplusplus
#endif //_H_DEBUGGING