L4Re - L4 Runtime Environment
debug
1 // vi:set ft=cpp: -*- Mode: C++ -*-
2 /**
3  * \internal
4  * \file
5  * \brief Debug interface
6  */
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 
29 namespace L4Re { namespace Util {
30 class Err
31 {
32 public:
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  Err(Level l, char const *component) : _l(l), _component(component)
51  {}
52 
53 private:
54  Level _l;
55  char const *_component;
56 };
57 
58 
59 class Dbg
60 {
61 private:
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 public:
71  static unsigned long level;
72 
73  static void set_level(unsigned long l) { level = l; }
74 
75  bool is_active() const { return _m & level; }
76 
77  int printf(char const *fmt, ...) const
78  __attribute__((format(printf, 2, 3)));
79 
80  int cprintf(char const *fmt, ...) const
81  __attribute__((format(printf, 2, 3)));
82 
83  explicit
84  Dbg() : _m(1), _component(0), _subsys(0) { };
85 
86  explicit
87  Dbg(unsigned long mask, char const *comp, char const *subs)
88  : _m(mask), _component(comp), _subsys(subs)
89  {}
90 
91 #else
92 
93 public:
94  static void set_level(unsigned long) {}
95  bool is_active() const { return false; }
96 
97  int printf(char const * /*fmt*/, ...) const
98  __attribute__((format(printf, 2, 3)))
99  { return 0; }
100 
101  int cprintf(char const * /*fmt*/, ...) const
102  __attribute__((format(printf, 2, 3)))
103  { return 0; }
104 
105  explicit
106  Dbg() {}
107 
108  explicit
109  Dbg(unsigned long, char const *, char const *) {}
110 
111 #endif
112 
113 };
114 
115 }}
116