L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
debug.h
1/*
2 * (c) 2013-2014 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
4 *
5 * License: see LICENSE.spdx (in this directory or the directories above)
6 */
7#pragma once
8
9#include <l4/re/util/debug>
10
11struct Err : L4Re::Util::Err
12{
13 Err(Level l = Fatal) : L4Re::Util::Err(l, "VSwitch") {}
14};
15
16class Dbg : public L4Re::Util::Dbg
17{
19 static constexpr unsigned Verbosity_shift = 4;
20 static constexpr unsigned long Verbosity_mask = (1UL << Verbosity_shift) - 1;
21
22public:
24 enum Verbosity : unsigned long
25 {
26 Quiet = 0,
27 Warn = 1,
28 Info = 2,
29 Debug = 4,
30 Trace = 8,
31 Max_verbosity = 8
32 };
33
37 enum Component
38 {
39 Core = 0,
40 Virtio,
41 Port,
42 Request,
43 Queue,
44 Packet,
45 Max_component
46 };
47
48#ifndef NDEBUG
49
50 static_assert(Max_component * Verbosity_shift <= sizeof(level) * 8,
51 "Too many components for level mask");
52 static_assert((Max_verbosity & Verbosity_mask) == Max_verbosity,
53 "Verbosity_shift to small for verbosity levels");
54
60 static void set_verbosity(unsigned mask)
61 {
62 for (unsigned i = 0; i < Max_component; ++i)
63 set_verbosity(i, mask);
64 }
65
72 static void set_verbosity(unsigned c, unsigned mask)
73 {
74 level &= ~(Verbosity_mask << (Verbosity_shift * c));
75 level |= (mask & Verbosity_mask) << (Verbosity_shift * c);
76 }
77
87 static bool is_active(unsigned c, unsigned mask)
88 { return level & (mask & Verbosity_mask) << (Verbosity_shift * c); }
89
96 using L4Re::Util::Dbg::is_active;
97
98 Dbg(Component c = Core, Verbosity v = Warn, char const *subsys = nullptr)
99 : L4Re::Util::Dbg(v << (Verbosity_shift * c), "SWI", subsys)
100 {}
101
102#else
103
104 static void set_verbosity(unsigned) {}
105 static void set_verbosity(unsigned, unsigned) {}
106
107 static bool is_active(unsigned, unsigned) { return false; }
108 using L4Re::Util::Dbg::is_active;
109
110 Dbg(Component c = Core, Verbosity v = Warn, char const *subsys = nullptr)
111 : L4Re::Util::Dbg(v << (Verbosity_shift * c), "", subsys)
112 {}
113
114#endif
115};