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