1 /* 2 * Copyright 2002-2007, 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 14 #define KDEBUG 1 15 16 #if DEBUG 17 /* 18 * The kernel debug level. 19 * Level 1 is usual asserts, > 1 should be used for very expensive runtime checks 20 */ 21 #define KDEBUG 1 22 #endif 23 24 #define ASSERT_ALWAYS(x) \ 25 do { if (!(x)) { panic("ASSERT FAILED (%s:%d): %s\n", __FILE__, __LINE__, #x); } } while (0) 26 27 #define ASSERT_ALWAYS_PRINT(x, format...) \ 28 do { \ 29 if (!(x)) { \ 30 dprintf_no_syslog(format); \ 31 panic("ASSERT FAILED (%s:%d): %s\n", __FILE__, __LINE__, #x); \ 32 } \ 33 } while (0) 34 35 #if KDEBUG 36 # define ASSERT(x) ASSERT_ALWAYS(x) 37 # define ASSERT_PRINT(x, format...) ASSERT_ALWAYS_PRINT(x, format) 38 #else 39 # define ASSERT(x) do { } while(0) 40 # define ASSERT_PRINT(x, format...) do { } while(0) 41 #endif 42 43 #define B_KDEBUG_DONT_PARSE_ARGUMENTS (0x01) 44 45 extern int dbg_register_file[B_MAX_CPU_COUNT][14]; 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 struct kernel_args; 52 53 extern status_t debug_init(struct kernel_args *args); 54 extern status_t debug_init_post_vm(struct kernel_args *args); 55 extern status_t debug_init_post_modules(struct kernel_args *args); 56 extern void debug_early_boot_message(const char *string); 57 extern void debug_puts(const char *s, int32 length); 58 extern bool debug_debugger_running(void); 59 extern void debug_stop_screen_debug_output(void); 60 61 extern void kputs(const char *string); 62 extern void dprintf_no_syslog(const char *format, ...) 63 __attribute__ ((format (__printf__, 1, 2))); 64 65 extern bool is_debug_variable_defined(const char* variableName); 66 extern bool set_debug_variable(const char* variableName, uint64 value); 67 extern uint64 get_debug_variable(const char* variableName, 68 uint64 defaultValue); 69 extern bool unset_debug_variable(const char* variableName); 70 extern void unset_all_debug_variables(); 71 72 extern bool evaluate_debug_expression(const char* expression, 73 uint64* result, bool silent); 74 extern int evaluate_debug_command(const char* command); 75 76 extern status_t add_debugger_command_etc(const char* name, 77 debugger_command_hook func, const char* description, 78 const char* usage, uint32 flags); 79 extern status_t add_debugger_command_alias(const char* newName, 80 const char* oldName, const char* description); 81 extern bool print_debugger_command_usage(const char* command); 82 83 extern void _user_debug_output(const char *userString); 84 85 #ifdef __cplusplus 86 } 87 #endif 88 89 #endif /* _KERNEL_DEBUG_H */ 90