1 /* 2 * Copyright 2002-2009, Haiku Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Ingo Weinhold, bonefish@cs.tu-berlin.de. 7 * Axel Dörfler, axeld@pinc-software.de. 8 */ 9 10 #include <signal.h> 11 #define _KERNEL_MODE 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 16 #include <KernelExport.h> 17 18 19 bool gDebugOutputEnabled = true; 20 21 22 extern "C" uint64 23 parse_expression(const char* arg) 24 { 25 return strtoull(arg, NULL, 0); 26 } 27 28 29 extern "C" bool 30 set_debug_variable(const char* variableName, uint64 value) 31 { 32 return true; 33 } 34 35 36 extern "C" bool 37 print_debugger_command_usage(const char* command) 38 { 39 return true; 40 } 41 42 43 extern "C" status_t 44 add_debugger_command_etc(const char* name, debugger_command_hook func, 45 const char* description, const char* usage, uint32 flags) 46 { 47 return B_OK; 48 } 49 50 51 extern "C" int 52 add_debugger_command(const char *name, int (*func)(int, char **), 53 const char *desc) 54 { 55 return B_OK; 56 } 57 58 59 extern "C" int 60 remove_debugger_command(const char * name, int (*func)(int, char **)) 61 { 62 return B_OK; 63 } 64 65 66 extern "C" void 67 panic(const char *format, ...) 68 { 69 char buffer[1024]; 70 71 strcpy(buffer, "PANIC: "); 72 int32 prefixLen = strlen(buffer); 73 int bufferSize = sizeof(buffer) - prefixLen; 74 75 va_list args; 76 va_start(args, format); 77 vsnprintf(buffer + prefixLen, bufferSize - 1, format, args); 78 va_end(args); 79 80 buffer[sizeof(buffer) - 1] = '\0'; 81 82 debugger(buffer); 83 } 84 85 86 void 87 kernel_debugger(const char *message) 88 { 89 debugger(message); 90 } 91 92 93 extern "C" void 94 dprintf(const char *format,...) 95 { 96 if (!gDebugOutputEnabled) 97 return; 98 99 va_list args; 100 va_start(args, format); 101 printf("\33[34m"); 102 vprintf(format, args); 103 printf("\33[0m"); 104 fflush(stdout); 105 va_end(args); 106 } 107 108 109 extern "C" void 110 dprintf_no_syslog(const char *format,...) 111 { 112 if (!gDebugOutputEnabled) 113 return; 114 115 va_list args; 116 va_start(args, format); 117 printf("\33[34m"); 118 vprintf(format, args); 119 printf("\33[0m"); 120 fflush(stdout); 121 va_end(args); 122 } 123 124 125 extern "C" void 126 kprintf(const char *format,...) 127 { 128 va_list args; 129 va_start(args, format); 130 printf("\33[35m"); 131 vprintf(format, args); 132 printf("\33[0m"); 133 fflush(stdout); 134 va_end(args); 135 } 136 137 138 extern "C" void 139 dump_block(const char *buffer, int size, const char *prefix) 140 { 141 const int DUMPED_BLOCK_SIZE = 16; 142 int i; 143 144 for (i = 0; i < size;) { 145 int start = i; 146 147 dprintf("%s", prefix); 148 for (; i < start + DUMPED_BLOCK_SIZE; i++) { 149 if (!(i % 4)) 150 dprintf(" "); 151 152 if (i >= size) 153 dprintf(" "); 154 else 155 dprintf("%02x", *(unsigned char *)(buffer + i)); 156 } 157 dprintf(" "); 158 159 for (i = start; i < start + DUMPED_BLOCK_SIZE; i++) { 160 if (i < size) { 161 char c = buffer[i]; 162 163 if (c < 30) 164 dprintf("."); 165 else 166 dprintf("%c", c); 167 } else 168 break; 169 } 170 dprintf("\n"); 171 } 172 } 173