zbackup/debug.hh

45 lines
1.0 KiB
C++
Raw Normal View History

2014-12-11 10:50:15 +03:00
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
2013-07-18 21:33:25 +04:00
#ifndef DEBUG_HH_INCLUDED
#define DEBUG_HH_INCLUDED
2013-07-18 21:33:25 +04:00
#include <stdio.h>
2015-01-20 15:46:08 +03:00
#include <typeinfo>
2013-07-18 21:33:25 +04:00
// Macros we use to output debugging information
2015-01-20 15:46:08 +03:00
#define __CLASS typeid( *this ).name()
2013-07-18 21:33:25 +04:00
#ifndef NDEBUG
#define __FILE_BASE (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define dPrintf( ... ) ({ fprintf( stderr, "[DEBUG] at %s( %s:%d ): ", __func__,\
__FILE_BASE, __LINE__ );\
fprintf( stderr, __VA_ARGS__ ); })
2013-07-18 21:33:25 +04:00
#ifdef HAVE_LIBUNWIND
#define UNW_LOCAL_ONLY
#include <libunwind.h>
2015-01-20 15:46:08 +03:00
// TODO: pretty backtraces
#define dPrintBacktrace( ... ) ()
#else
#define dPrintBacktrace( ... ) ()
#endif
2013-07-18 21:33:25 +04:00
#else
#define dPrintf( ... )
#define dPrintBacktrace( ... ) ()
2013-07-18 21:33:25 +04:00
#endif
extern bool verboseMode;
#define verbosePrintf( ... ) ({ if ( verboseMode ) \
fprintf( stderr, __VA_ARGS__ ); })
#endif