xref: /haiku/headers/private/kernel/debug.h (revision cfc3fa87da824bdf593eb8b817a83b6376e77935)
1 /*
2  * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de
3  * Distributed under the terms of the Haiku License.
4  *
5  * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6  * Distributed under the terms of the NewOS License.
7  */
8 #ifndef _KERNEL_DEBUG_H
9 #define _KERNEL_DEBUG_H
10 
11 
12 #include <KernelExport.h>
13 #include <module.h>
14 
15 
16 #define KDEBUG 1
17 
18 #if DEBUG
19 /*
20  * The kernel debug level.
21  * Level 1 is usual asserts, > 1 should be used for very expensive runtime checks
22  */
23 #	define KDEBUG 1
24 #endif
25 
26 #define ASSERT_ALWAYS(x) \
27 	do { if (!(x)) { panic("ASSERT FAILED (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0)
28 
29 #define ASSERT_ALWAYS_PRINT(x, format...) \
30 	do {																	\
31 		if (!(x)) {															\
32 			dprintf_no_syslog(format);										\
33 			panic("ASSERT FAILED (%s:%d): %s\n", __FILE__, __LINE__, #x);	\
34 		}																	\
35 	} while (0)
36 
37 #if KDEBUG
38 #	define ASSERT(x)					ASSERT_ALWAYS(x)
39 #	define ASSERT_PRINT(x, format...)	ASSERT_ALWAYS_PRINT(x, format)
40 #else
41 #	define ASSERT(x)					do { } while(0)
42 #	define ASSERT_PRINT(x, format...)	do { } while(0)
43 #endif
44 
45 #define B_KDEBUG_DONT_PARSE_ARGUMENTS	(0x01)
46 
47 struct debugger_module_info {
48 	module_info info;
49 
50 	void (*enter_debugger)(void);
51 	void (*exit_debugger)(void);
52 
53 	// io hooks
54 	int (*debugger_puts)(const char *str, int32 length);
55 	int (*debugger_getchar)(void);
56 	// TODO: add hooks for tunnelling gdb ?
57 };
58 
59 extern int dbg_register_file[B_MAX_CPU_COUNT][14];
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 struct kernel_args;
66 
67 extern status_t debug_init(struct kernel_args *args);
68 extern status_t	debug_init_post_vm(struct kernel_args *args);
69 extern status_t	debug_init_post_modules(struct kernel_args *args);
70 extern void debug_early_boot_message(const char *string);
71 extern void debug_puts(const char *s, int32 length);
72 extern bool debug_debugger_running(void);
73 extern bool debug_screen_output_enabled(void);
74 extern void debug_stop_screen_debug_output(void);
75 
76 extern void	kputs(const char *string);
77 extern void dprintf_no_syslog(const char *format, ...)
78 				__attribute__ ((format (__printf__, 1, 2)));
79 
80 extern bool		is_debug_variable_defined(const char* variableName);
81 extern bool		set_debug_variable(const char* variableName, uint64 value);
82 extern uint64	get_debug_variable(const char* variableName,
83 					uint64 defaultValue);
84 extern bool		unset_debug_variable(const char* variableName);
85 extern void		unset_all_debug_variables();
86 
87 extern bool		evaluate_debug_expression(const char* expression,
88 					uint64* result, bool silent);
89 extern int		evaluate_debug_command(const char* command);
90 
91 extern status_t	add_debugger_command_etc(const char* name,
92 					debugger_command_hook func, const char* description,
93 					const char* usage, uint32 flags);
94 extern status_t	add_debugger_command_alias(const char* newName,
95 					const char* oldName, const char* description);
96 extern bool		print_debugger_command_usage(const char* command);
97 
98 extern void		_user_debug_output(const char *userString);
99 
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif	/* _KERNEL_DEBUG_H */
105