L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
debug
1// vi:set ft=cpp: -*- Mode: C++ -*-
7/*
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
11 *
12 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU General Public License 2.
14 * Please see the COPYING-GPL-2 file for details.
15 *
16 * As a special exception, you may use this file as part of a free software
17 * library without restriction. Specifically, if other files instantiate
18 * templates or use macros or inline functions from this file, or you compile
19 * this file and link it with other files to produce an executable, this
20 * file does not by itself cause the resulting executable to be covered by
21 * the GNU General Public License. This exception does not however
22 * invalidate any other reasons why the executable file might be covered by
23 * the GNU General Public License.
24 */
25#pragma once
26
27#include <l4/sys/types.h>
28
29namespace L4Re { namespace Util {
30class Err
31{
32public:
33 enum Level
34 {
35 Normal = 0,
36 Fatal,
37 };
38
39 static char const *const levels[];
40
41 void tag() const
42 { cprintf("%s: %s", _component, levels[_l]); }
43
44 int printf(char const *fmt, ...) const
45 __attribute__((format(printf,2,3)));
46
47 int cprintf(char const *fmt, ...) const
48 __attribute__((format(printf,2,3)));
49
50 constexpr Err(Level l, char const *component) : _l(l), _component(component)
51 {}
52
53private:
54 Level _l;
55 char const *_component;
56};
57
58
59class Dbg
60{
61private:
62 void tag() const;
63
64#ifndef NDEBUG
65
66 unsigned long _m;
67 char const *const _component;
68 char const *const _subsys;
69
70# ifndef __clang__
71
72 int printf_impl(char const *fmt, ...) const
73 __attribute__((format(printf, 2, 3)));
74
75 int cprintf_impl(char const *fmt, ...) const
76 __attribute__((format(printf, 2, 3)));
77
78# endif
79
80public:
81 static unsigned long level;
82
83 static void set_level(unsigned long l) { level = l; }
84
85 bool is_active() const { return _m & level; }
86
87# ifdef __clang__
88
89 int printf(char const *fmt, ...) const
90 __attribute__((format(printf, 2, 3)));
91
92 int cprintf(char const *fmt, ...) const
93 __attribute__((format(printf, 2, 3)));
94
95# else
96
97 int __attribute__((always_inline, format(printf, 2, 3)))
98 printf(char const *fmt, ...) const
99 {
100 if (!(level & _m))
101 return 0;
102
103 return printf_impl(fmt, __builtin_va_arg_pack());
104 }
105
106 int __attribute__((always_inline, format(printf, 2, 3)))
107 cprintf(char const *fmt, ...) const
108 {
109 if (!(level & _m))
110 return 0;
111
112 return cprintf_impl(fmt, __builtin_va_arg_pack());
113 }
114
115# endif
116
117 explicit constexpr
118 Dbg() : _m(1), _component(0), _subsys(0) { };
119
120 explicit constexpr
121 Dbg(unsigned long mask, char const *comp, char const *subs)
122 : _m(mask), _component(comp), _subsys(subs)
123 {}
124
125#else
126
127public:
128 static void set_level(unsigned long) {}
129 bool is_active() const { return false; }
130
131 int printf(char const * /*fmt*/, ...) const
132 __attribute__((format(printf, 2, 3)))
133 { return 0; }
134
135 int cprintf(char const * /*fmt*/, ...) const
136 __attribute__((format(printf, 2, 3)))
137 { return 0; }
138
139 explicit constexpr
140 Dbg() {}
141
142 explicit constexpr
143 Dbg(unsigned long, char const *, char const *) {}
144
145#endif
146
147};
148
149}}
150
Common L4 ABI Data Types.
L4Re C++ Interfaces.
Definition l4re.dox:17