/* * Debugging fonctions * * Copyright 2004-2009 Nicolas Bernard * All rights reserved. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ /* * IMPORTANT WARNING * * Beware of string format vulnerabilities: ensure an attacker cannot control * the format string! */ #ifndef _DEBUG_H_ #define _DEBUG_H_ #include #include #include #include #include #include "confloader/confloader.h" log_t logtype; FILE* logfiledesc; #ifndef WITHOUT_DEBUG_POS #define debug(...) debugf(__FILE__, __LINE__, __func__, __VA_ARGS__) #define panic(...) panicf(__FILE__, __LINE__, __func__, __VA_ARGS__) #define logger(...) loggerf(__FILE__, __LINE__, __func__, __VA_ARGS__) #ifdef _WITH_ERRSTACK_ #define stkdbg(...) stkdebugf(__FILE__, __LINE__, __func__, __VA_ARGS__) #else #define stkdbg(...) debugf(__FILE__, __LINE__, __func__, __VA_ARGS__) #endif #else #define debug(...) debugf(NULL, 0, NULL, __VA_ARGS__) #define panic(...) panicf(NULL, 0, NULL, __VA_ARGS__) #define logger(...) loggerf(NULL, 0, NULL, __VA_ARGS__) #ifdef _WITH_ERRSTACK_ #define stkdbg(...) stkdebugf(NULL, 0, NULL, __VA_ARGS__) #else #define stkdbg(...) debugf(NULL, 0, NULL, __VA_ARGS__) #endif #endif /* ! WITH_DEBUG_POS */ void debugf(const char* file, int line, const char* func, const char* fmt, ...) __attribute__ ((format (printf, 4, 5))); /* Flawfinder: ignore */ void panicf(const char* file, int line, const char* func, const char* fmt, ...) __attribute__ ((format (printf, 4, 5), noreturn)); /* Flawfinder: ignore */ void loggerf(const char* file, int line, const char* func, int priority, const char* fmt, ...) __attribute__ ((format (printf, 5, 6))); /* Flawfinder: ignore */ //#define free(a) debugf(__FILE__, __LINE__, __func__, "free(%p)", (void*) a); free(a); //#define close(a) 0; debugf(__FILE__, __LINE__, __func__, "close(%d)", a); close(a) #define exit(a) {debugf(__FILE__, __LINE__, __func__, "exit(%d)", a); exit(a);}; #include "dsession.h" #define dsessionforceclosed(a) {debugf(__FILE__, __LINE__, __func__, "dsessionforceclosed(%p)", a); dsessionforceclosedf(a);}; #ifdef _WITH_ERRSTACK_ void dumperrstack(log_t where); void dumperrstackstderr(void); /* useful with atexit */ void flusherrstack(void); /* if the error was recovered and doesn't need to be remembered... */ void stkdebugf(const char* file, int line, const char* func, const char* fmt, ...); #endif /* _WITH_ERRSTACK_*/ #endif /* _DEBUG_H_ */