MOS Source Code
Loading...
Searching...
No Matches
debug.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/syslog/debug.h"
4
5#include "mos/misc/setup.h"
6
7#if MOS_CONFIG(MOS_DYNAMIC_DEBUG)
10#include "mos/syslog/printk.h"
11#endif
12
13#include <mos/mos_global.h>
14
15#define _check_debug_macro_defined_(name) MOS_STATIC_ASSERT(MOS_CONCAT(MOS_DEBUG_, name) != 0);
17#undef _check_debug_macro_defined_
18
19#if MOS_CONFIG(MOS_DYNAMIC_DEBUG)
20
21// populate default debug settings
22struct _mos_debug_info mos_debug_info = {
23#define X(_name) ._name = { .id = __COUNTER__ + 1, .name = #_name, .enabled = MOS_DEBUG_FEATURE(_name) },
25#undef X
26};
27
28// expose a sysfs file to enable/disable each debug feature
29
30void debug_print_action(const char *name, bool newstate)
31{
32 pr_info("debug option '%s' has been turned %s", name, newstate ? "on" : "off");
33}
34
35#define debug_show_function(name) \
36 bool debug_show_##name(sysfs_file_t *file) \
37 { \
38 sysfs_printf(file, "%d\n", mos_debug_info.name.enabled); \
39 return true; \
40 }
41
42#define debug_store_function(name) \
43 size_t debug_store_##name(sysfs_file_t *file, const char *buf, size_t count, off_t offset) \
44 { \
45 MOS_UNUSED(file); \
46 MOS_UNUSED(offset); \
47 if (count < 1) \
48 return -EINVAL; \
49 const bool on = buf[0] == '1'; \
50 mos_debug_info.name.enabled = on; \
51 debug_print_action(#name, on); \
52 return count; \
53 }
54
55MOS_ALL_DEBUG_MODULES(debug_show_function)
56MOS_ALL_DEBUG_MODULES(debug_store_function)
57
58static sysfs_item_t sys_debug_items[] = {
59#define X(name) SYSFS_RW_ITEM(#name, debug_show_##name, debug_store_##name),
61#undef X
62};
63
64SYSFS_AUTOREGISTER(debug, sys_debug_items);
65
66#define SETUP_DEBUG_MODULE(name) \
67 static bool setup_debug_##name(const char *value) \
68 { \
69 mos_debug_info.name.enabled = cmdline_string_truthiness(value, true); \
70 return true; \
71 } \
72 MOS_SETUP("debug." #name, setup_debug_##name);
73
74MOS_ALL_DEBUG_MODULES(SETUP_DEBUG_MODULE)
75
76// ! expose debug info id to userspace
77#define debug_show_id_function(name) \
78 bool debug_show_id_##name(sysfs_file_t *file) \
79 { \
80 sysfs_printf(file, "%d\n", mos_debug_info.name.id); \
81 return true; \
82 }
83
84MOS_ALL_DEBUG_MODULES(debug_show_id_function)
85
86static sysfs_item_t sys_debug_id_items[] = {
87#define X(name) SYSFS_RO_ITEM(#name, debug_show_id_##name),
89};
90
91SYSFS_AUTOREGISTER(debug_id, sys_debug_id_items);
92
93#endif
#define _check_debug_macro_defined_(name)
Definition debug.c:15
#define MOS_ALL_DEBUG_MODULES(X)
Definition debug.h:19
#define pr_info(fmt,...)
Definition printk.h:35
const char * name
Definition slab.c:31
#define SYSFS_AUTOREGISTER(sysfs_name, sysfs_items)