1
/*
2
* \brief Interface of the printf back end
3
* \author Norman Feske
4
* \date 2006-04-08
5
*/
6
7
/*
8
* Copyright (C) 2006-2014 Genode Labs GmbH
9
*
10
* This file is part of the Genode OS framework, which is distributed
11
* under the terms of the GNU General Public License version 2.
12
*/
13
14
#
ifndef _INCLUDE__BASE__PRINTF_H_
15
#
define _INCLUDE__BASE__PRINTF_H_
16
17
#
include <stdarg.h>
18
19
namespace
Genode {
20
21
/**
22
* Output format string to LOG session
23
*/
24
void
printf(
const
char *
format
,
.
.
.
)
__attribute__(
(
format(
printf,
1,
2)
)
)
;
25
26
void
vprintf(
const
char *
format
,
va_list
)
__attribute__(
(
format(
printf,
1,
0)
)
)
;
27
}
28
29
#
define ESC_LOG "\033[33m"
30
#
define ESC_DBG "\033[33m"
31
#
define ESC_INF "\033[32m"
32
#
define ESC_WRN "\033[34m"
33
#
define ESC_ERR "\033[31m"
34
#
define ESC_END "\033[0m"
35
36
/**
37
* Remove colored output from release version
38
*/
39
#
ifdef GENODE_RELEASE
40
#
undef ESC_LOG
41
#
undef ESC_DBG
42
#
undef ESC_INF
43
#
undef ESC_WRN
44
#
undef ESC_ERR
45
#
undef ESC_END
46
#
define ESC_LOG
47
#
define ESC_DBG
48
#
define ESC_INF
49
#
define ESC_WRN
50
#
define ESC_ERR
51
#
define ESC_END
52
#
endif /* GENODE_RELEASE */
53
54
/**
55
* Suppress debug messages in release version
56
*/
57
#
ifdef GENODE_RELEASE
58
#
define DO_PDBG false
59
#
define DO_PWRN false
60
#
else
61
#
define DO_PDBG true
62
#
define DO_PWRN true
63
#
endif /* GENODE_RELEASE */
64
65
/**
66
* Print debug message with function name
67
*
68
* We`re using heavy CPP wizardry here to prevent compiler errors after macro
69
* expansion. Each macro works as follows:
70
*
71
* - Support one format string plus zero or more arguments.
72
* - Put all static strings (including the format string) in the first argument
73
* of the call to printf() and let the compiler merge them.
74
* - Append the function name (magic static string variable) as first argument.
75
* - (Optionally) append the arguments to the macro with ", ##__VA_ARGS__". CPP
76
* only appends the comma and arguments if __VA__ARGS__ is not empty,
77
* otherwise nothing (not even the comma) is appended.
78
*/
79
#
define PDBG(fmt, ...) \
80
do { \
81
if (DO_PDBG) \
82
Genode::printf("%s: "
ESC_DBG fmt ESC_END "\n"
, \
83
__PRETTY_FUNCTION__, #
#
__VA_ARGS__ ); \
84
} while (0)
85
86
/**
87
* Print log message
88
*/
89
#
define PLOG(fmt, ...) \
90
Genode::printf(ESC_LOG fmt ESC_END "\n"
, #
#
__VA_ARGS__ )
91
92
/**
93
* Print status-information message
94
*/
95
#
define PINF(fmt, ...) \
96
Genode::printf(ESC_INF fmt ESC_END "\n"
, #
#
__VA_ARGS__ )
97
98
/**
99
* Print warning message
100
*/
101
#
define PWRN(fmt, ...) \
102
do { \
103
if (DO_PWRN) \
104
Genode::printf(ESC_WRN fmt ESC_END "\n"
, #
#
__VA_ARGS__ ); \
105
} while (0)
106
107
/**
108
* Print error message
109
*/
110
#
define PERR(fmt, ...) \
111
Genode::printf(ESC_ERR fmt ESC_END "\n"
, #
#
__VA_ARGS__ )
112
113
#
endif /* _INCLUDE__BASE__PRINTF_H_ */