summaryrefslogtreecommitdiff
path: root/server/src/debug.h
blob: 838d83f3fe55713d577709788771bfc53e981e62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set et sw=2 ts=2: */
/***************************************************************************
 *            debug.h
 *
 *  Wed Feb 11 11:22:12 CET 2009
 *  Copyright 2009 Bent Bisballe Nyeng
 *  deva@aasimon.org
 ****************************************************************************/

/*
 *  This file is part of Pracro.
 *
 *  Pracro is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Pentominos is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Pentominos; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
#ifndef __PENTOMINOS_DEBUG_H__
#define __PENTOMINOS_DEBUG_H__

#include <stdarg.h>
#include <stdio.h>

#ifdef HAVE_CONFIG_H
// For USE_EFENCE
#include <config.h>
#ifdef USE_EFENCE
#include <new>
#include <stdlib.h>
#include <efencepp.h>
#include <efence.h>

// Lazy static alocations makes efence freak out.
// Use this to use hardcoded values instead.
// Currently it disables:
// - gethostbyname
// - getsockname
// - getpeername
// - iconv
//#define BYPASS_STATICALLOCATIONS

#endif/*USE_EFENCE*/
#endif/*HAVE_CONFIG*/

void debug_init(FILE *fp);
void debug_reinit(const char *file);
void debug_parse(const char *fmt);

enum __debug_class
{
	__class_fixme = 0,
	__class_err = 1,
	__class_warn = 2,
	__class_info = 3,
	__class_debug = 4
};

#ifdef WITH_DEBUG
int __debug(const char *func, const int line, enum __debug_class cl,
            const char *ch, const char *fmt, ...)
  __attribute__((format (printf,5,6)));

int __debug_va(const char *func, const int line, enum __debug_class cl,
               const char *ch, const char *fmt, va_list va);

#define __DEBUG_PRINT(cl, ch, fmt...)	\
	do { __debug(__func__, __LINE__, cl, ch, fmt); } while(0)
#define __DEBUG_PRINT_VA(cl, ch, fmt, a)	\
	do { __debug_va(__func__, __LINE__, cl, ch, fmt, a); } while(0)
#define __DEBUG(cl, ch, fmt...) \
	__DEBUG_PRINT(__class##cl, #ch, fmt)
#define __DEBUG_VA(cl, ch, fmt, a) \
  __DEBUG_PRINT_VA(__class##cl, #ch, fmt, a)

#define FIXME(ch, fmt...) __DEBUG(_fixme, ch, fmt)
#define ERR(ch, fmt...) __DEBUG(_err, ch, fmt)
#define WARN(ch, fmt...) __DEBUG(_warn, ch, fmt)
#define INFO(ch, fmt...) __DEBUG(_info, ch, fmt)
#define DEBUG(ch, fmt...) __DEBUG(_debug, ch, fmt)

#define FIXME_VA(ch, fmt, a) __DEBUG_VA(_fixme, ch, fmt, a)
#define ERR_VA(ch, fmt, a) __DEBUG_VA(_err, ch, fmt, a)
#define WARN_VA(ch, fmt, a) __DEBUG_VA(_warn, ch, fmt, a)
#define INFO_VA(ch, fmt, a) __DEBUG_VA(_info, ch, fmt, a)
#define DEBUG_VA(ch, fmt, a) __DEBUG_VA(_debug, ch, fmt, a)

#else

// If we compile without debug support, we want them all to go away
#define FIXME(ch, fmt...)
#define INFO(ch, fmt...)
#define WARN(ch, fmt...)
#define ERR(ch, fmt...)
#define DEBUG(ch, fmt...)
#define FIXME_VA(ch, fmt...)
#define INFO_VA(ch, fmt...)
#define WARN_VA(ch, fmt...)
#define ERR_VA(ch, fmt...)
#define DEBUG_VA(ch, fmt...)

#endif/*WITH_DEBUG*/

int __log(const char *func, const int line,
          enum __debug_class cl, const char *ch, const char *fmt, ...)
  __attribute__((format (printf,5,6)));

int __log_va(const char *func, const int line, enum __debug_class cl,
             const char *ch, const char *fmt, va_list va);

#define __LOG_PRINT(cl, ch, fmt...) \
  do { __log(__func__, __LINE__, cl, ch, fmt); } while(0)
#define __LOG_PRINT_VA(cl, ch, fmt, a) \
  do { __log_va(__func__, __LINE__, cl, ch, fmt, a); } while(0)
#define __LOG(cl, ch, fmt...) __LOG_PRINT(__class##cl, #ch, fmt)
#define __LOG_VA(cl, ch, fmt, a) __LOG_PRINT_VA(__class##cl, #ch, fmt, a)

#define INFO_LOG(ch, fmt...) __LOG(_info, ch, fmt)
#define WARN_LOG(ch, fmt...) __LOG(_warn, ch, fmt)
#define ERR_LOG(ch, fmt...) __LOG(_err, ch, fmt)
#define INFO_LOG_VA(ch, fmt, a) __LOG_VA(_info, ch, fmt, a)
#define WARN_LOG_VA(ch, fmt, a) __LOG_VA(_warn, ch, fmt, a)
#define ERR_LOG_VA(ch, fmt, a) __LOG_VA(_err, ch, fmt, a)

#endif/*__PENTOMINOS_DEBUG_H__*/