MentOS  0.8.0
The Mentoring Operating System
debug.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "sys/kernel_levels.h"
9 
10 #ifndef __DEBUG_LEVEL__
12 #define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
13 #endif
14 
15 #ifndef __DEBUG_HEADER__
17 #define __DEBUG_HEADER__ 0
18 #endif
19 
21 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
22 
25 void set_log_level(int level);
26 
29 int get_log_level(void);
30 
33 void dbg_putchar(char c);
34 
37 void dbg_puts(const char *s);
38 
47 void dbg_printf(const char *file, const char *fun, int line, char *header, short log_level, const char *format, ...);
48 
52 const char *to_human_size(unsigned long bytes);
53 
58 const char *dec_to_binary(unsigned long value, unsigned length);
59 
61 #define pr_default(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_DEFAULT, __VA_ARGS__)
62 
64 #if __DEBUG_LEVEL__ >= LOGLEVEL_EMERG
65 #define pr_emerg(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_EMERG, __VA_ARGS__)
66 #else
67 #define pr_emerg(...)
68 #endif
69 
71 #if __DEBUG_LEVEL__ >= LOGLEVEL_ALERT
72 #define pr_alert(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_ALERT, __VA_ARGS__)
73 #else
74 #define pr_alert(...)
75 #endif
76 
78 #if __DEBUG_LEVEL__ >= LOGLEVEL_CRIT
79 #define pr_crit(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_CRIT, __VA_ARGS__)
80 #else
81 #define pr_crit(...)
82 #endif
83 
85 #if __DEBUG_LEVEL__ >= LOGLEVEL_ERR
86 #define pr_err(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_ERR, __VA_ARGS__)
87 #else
88 #define pr_err(...)
89 #endif
90 
92 #if __DEBUG_LEVEL__ >= LOGLEVEL_WARNING
93 #define pr_warning(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_WARNING, __VA_ARGS__)
94 #else
95 #define pr_warning(...)
96 #endif
97 
99 #if __DEBUG_LEVEL__ >= LOGLEVEL_NOTICE
100 #define pr_notice(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_NOTICE, __VA_ARGS__)
101 #else
102 #define pr_notice(...)
103 #endif
104 
106 #if __DEBUG_LEVEL__ >= LOGLEVEL_INFO
107 #define pr_info(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_INFO, __VA_ARGS__)
108 #else
109 #define pr_info(...)
110 #endif
111 
113 #if __DEBUG_LEVEL__ >= LOGLEVEL_DEBUG
114 #define pr_debug(...) dbg_printf(__FILENAME__, __func__, __LINE__, __DEBUG_HEADER__, LOGLEVEL_DEBUG, __VA_ARGS__)
115 #else
116 #define pr_debug(...)
117 #endif
118 
119 #ifdef __KERNEL__
120 
121 struct pt_regs;
122 
125 void dbg_print_regs(struct pt_regs *frame);
126 
127 #endif
void dbg_puts(const char *s)
Prints the given string to debug output.
Definition: debug.c:25
void dbg_printf(const char *file, const char *fun, int line, char *header, short log_level, const char *format,...)
Prints the given string to the debug output.
Definition: debug.c:99
const char * dec_to_binary(unsigned long value, unsigned length)
Transforms the given value to a binary string.
Definition: debug.c:155
void dbg_putchar(char c)
Prints the given character to debug output.
Definition: debug.c:20
const char * to_human_size(unsigned long bytes)
Transforms the given amount of bytes to a readable string.
Definition: debug.c:139
void set_log_level(int level)
Sets the loglevel.
Definition: debug.c:87
int get_log_level(void)
Returns the current loglevel.
Definition: debug.c:94
void dbg_print_regs(pt_regs *frame)
Prints the registers.
Definition: debug.c:171
Interrupt stack frame.
Definition: kernel.h:24