Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendebug.c
Go to the documentation of this file.
00001 /* 00002 * FreeLoader 00003 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #include <freeldr.h> 00021 00022 #include <debug.h> 00023 00024 #if DBG && !defined(_M_ARM) 00025 00026 //#define DEBUG_ALL 00027 //#define DEBUG_INIFILE 00028 //#define DEBUG_REACTOS 00029 //#define DEBUG_CUSTOM 00030 #define DEBUG_NONE 00031 00032 #define DBG_DEFAULT_LEVELS (ERR_LEVEL|FIXME_LEVEL) 00033 00034 #define SCREEN 1 00035 #define RS232 2 00036 #define BOCHS 4 00037 00038 #define COM1 1 00039 #define COM2 2 00040 #define COM3 3 00041 #define COM4 4 00042 00043 #define BOCHS_OUTPUT_PORT 0xe9 00044 00045 00046 static UCHAR DbgChannels[DBG_CHANNELS_COUNT]; 00047 00048 ULONG DebugPort = RS232; 00049 //ULONG DebugPort = SCREEN; 00050 //ULONG DebugPort = BOCHS; 00051 //ULONG DebugPort = SCREEN|BOCHS; 00052 ULONG ComPort = COM1; 00053 //ULONG BaudRate = 19200; 00054 ULONG BaudRate = 115200; 00055 00056 BOOLEAN DebugStartOfLine = TRUE; 00057 00058 VOID DebugInit(VOID) 00059 { 00060 #if defined (DEBUG_ALL) 00061 memset(DbgChannels, MAX_LEVEL, DBG_CHANNELS_COUNT); 00062 #else 00063 memset(DbgChannels, 0, DBG_CHANNELS_COUNT); 00064 #endif 00065 00066 #if defined (DEBUG_INIFILE) 00067 DbgChannels[DPRINT_INIFILE] = MAX_LEVEL; 00068 #elif defined (DEBUG_REACTOS) 00069 DbgChannels[DPRINT_REACTOS] = MAX_LEVEL; 00070 DbgChannels[DPRINT_REGISTRY] = MAX_LEVEL; 00071 #elif defined (DEBUG_CUSTOM) 00072 DbgChannels[DPRINT_WARNING] = MAX_LEVEL; 00073 DbgChannels[DPRINT_WINDOWS] = MAX_LEVEL; 00074 #endif 00075 00076 if (DebugPort & RS232) 00077 { 00078 Rs232PortInitialize(ComPort, BaudRate); 00079 } 00080 } 00081 00082 VOID DebugPrintChar(UCHAR Character) 00083 { 00084 if (Character == '\n') 00085 { 00086 DebugStartOfLine = TRUE; 00087 } 00088 00089 if (DebugPort & RS232) 00090 { 00091 if (Character == '\n') 00092 { 00093 Rs232PortPutByte('\r'); 00094 } 00095 Rs232PortPutByte(Character); 00096 } 00097 if (DebugPort & BOCHS) 00098 { 00099 WRITE_PORT_UCHAR((PUCHAR)BOCHS_OUTPUT_PORT, Character); 00100 } 00101 if (DebugPort & SCREEN) 00102 { 00103 MachConsPutChar(Character); 00104 } 00105 } 00106 00107 ULONG 00108 DbgPrint(const char *Format, ...) 00109 { 00110 int i; 00111 int Length; 00112 va_list ap; 00113 CHAR Buffer[512]; 00114 00115 va_start(ap, Format); 00116 Length = _vsnprintf(Buffer, sizeof(Buffer), Format, ap); 00117 va_end(ap); 00118 00119 /* Check if we went past the buffer */ 00120 if (Length == -1) 00121 { 00122 /* Terminate it if we went over-board */ 00123 Buffer[sizeof(Buffer) - 1] = '\n'; 00124 00125 /* Put maximum */ 00126 Length = sizeof(Buffer); 00127 } 00128 00129 for (i = 0; i < Length; i++) 00130 { 00131 DebugPrintChar(Buffer[i]); 00132 } 00133 00134 return 0; 00135 } 00136 00137 VOID 00138 DbgPrint2(ULONG Mask, ULONG Level, const char *File, ULONG Line, char *Format, ...) 00139 { 00140 va_list ap; 00141 char Buffer[2096]; 00142 char *ptr = Buffer; 00143 00144 // Mask out unwanted debug messages 00145 if (!(DbgChannels[Mask] & Level) && !(Level & DBG_DEFAULT_LEVELS )) 00146 { 00147 return; 00148 } 00149 00150 // Print the header if we have started a new line 00151 if (DebugStartOfLine) 00152 { 00153 DbgPrint("(%s:%lu) ", File, Line); 00154 00155 switch (Level) 00156 { 00157 case ERR_LEVEL: 00158 DbgPrint("err: "); 00159 break; 00160 case FIXME_LEVEL: 00161 DbgPrint("fixme: "); 00162 break; 00163 case WARN_LEVEL: 00164 DbgPrint("warn: "); 00165 break; 00166 case TRACE_LEVEL: 00167 DbgPrint("trace: "); 00168 break; 00169 } 00170 00171 DebugStartOfLine = FALSE; 00172 } 00173 00174 va_start(ap, Format); 00175 vsprintf(Buffer, Format, ap); 00176 va_end(ap); 00177 00178 while (*ptr) 00179 { 00180 DebugPrintChar(*ptr++); 00181 } 00182 } 00183 00184 VOID 00185 DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length) 00186 { 00187 PUCHAR BufPtr = (PUCHAR)Buffer; 00188 ULONG Idx; 00189 ULONG Idx2; 00190 00191 // Mask out unwanted debug messages 00192 if (!(DbgChannels[Mask] & TRACE_LEVEL)) 00193 { 00194 return; 00195 } 00196 00197 DebugStartOfLine = FALSE; // We don't want line headers 00198 DbgPrint("Dumping buffer at %p with length of %lu bytes:\n", Buffer, Length); 00199 00200 for (Idx=0; Idx<Length; ) 00201 { 00202 DebugStartOfLine = FALSE; // We don't want line headers 00203 00204 if (Idx < 0x0010) 00205 { 00206 DbgPrint("000%x:\t", Idx); 00207 } 00208 else if (Idx < 0x0100) 00209 { 00210 DbgPrint("00%x:\t", Idx); 00211 } 00212 else if (Idx < 0x1000) 00213 { 00214 DbgPrint("0%x:\t", Idx); 00215 } 00216 else 00217 { 00218 DbgPrint("%x:\t", Idx); 00219 } 00220 00221 for (Idx2=0; Idx2<16; Idx2++,Idx++) 00222 { 00223 if (BufPtr[Idx] < 0x10) 00224 { 00225 DbgPrint("0"); 00226 } 00227 DbgPrint("%x", BufPtr[Idx]); 00228 00229 if (Idx2 == 7) 00230 { 00231 DbgPrint("-"); 00232 } 00233 else 00234 { 00235 DbgPrint(" "); 00236 } 00237 } 00238 00239 Idx -= 16; 00240 DbgPrint(" "); 00241 00242 for (Idx2=0; Idx2<16; Idx2++,Idx++) 00243 { 00244 if ((BufPtr[Idx] > 20) && (BufPtr[Idx] < 0x80)) 00245 { 00246 DbgPrint("%c", BufPtr[Idx]); 00247 } 00248 else 00249 { 00250 DbgPrint("."); 00251 } 00252 } 00253 00254 DbgPrint("\n"); 00255 } 00256 } 00257 00258 static BOOLEAN 00259 DbgAddDebugChannel( CHAR* channel, CHAR* level, CHAR op) 00260 { 00261 int iLevel, iChannel; 00262 00263 if(channel == NULL || *channel == L'\0' ||strlen(channel) == 0 ) 00264 return FALSE; 00265 00266 if(level == NULL || *level == L'\0' ||strlen(level) == 0 ) 00267 iLevel = MAX_LEVEL; 00268 else if(strcmp(level, "err") == 0) 00269 iLevel = ERR_LEVEL; 00270 else if(strcmp(level, "fixme") == 0) 00271 iLevel = FIXME_LEVEL; 00272 else if(strcmp(level, "warn") == 0) 00273 iLevel = WARN_LEVEL; 00274 else if (strcmp(level, "trace") == 0) 00275 iLevel = TRACE_LEVEL; 00276 else 00277 return FALSE; 00278 00279 if(strcmp(channel, "memory") == 0) iChannel = DPRINT_MEMORY; 00280 else if(strcmp(channel, "filesystem") == 0) iChannel = DPRINT_FILESYSTEM; 00281 else if(strcmp(channel, "inifile") == 0) iChannel = DPRINT_INIFILE; 00282 else if(strcmp(channel, "ui") == 0) iChannel = DPRINT_UI; 00283 else if(strcmp(channel, "disk") == 0) iChannel = DPRINT_DISK; 00284 else if(strcmp(channel, "cache") == 0) iChannel = DPRINT_CACHE; 00285 else if(strcmp(channel, "registry") == 0) iChannel = DPRINT_REGISTRY; 00286 else if(strcmp(channel, "linux") == 0) iChannel = DPRINT_LINUX; 00287 else if(strcmp(channel, "hwdetect") == 0) iChannel = DPRINT_HWDETECT; 00288 else if(strcmp(channel, "windows") == 0) iChannel = DPRINT_WINDOWS; 00289 else if(strcmp(channel, "peloader") == 0) iChannel = DPRINT_PELOADER; 00290 else if(strcmp(channel, "scsiport") == 0) iChannel = DPRINT_SCSIPORT; 00291 else if(strcmp(channel, "heap") == 0) iChannel = DPRINT_HEAP; 00292 else if(strcmp(channel, "all") == 0) 00293 { 00294 int i; 00295 00296 for(i= 0 ; i < DBG_CHANNELS_COUNT; i++) 00297 { 00298 if(op==L'+') 00299 DbgChannels[i] |= iLevel; 00300 else 00301 DbgChannels[i] &= ~iLevel; 00302 } 00303 00304 return TRUE; 00305 } 00306 00307 if(op==L'+') 00308 DbgChannels[iChannel] |= iLevel; 00309 else 00310 DbgChannels[iChannel] &= ~iLevel; 00311 00312 return TRUE; 00313 } 00314 00315 VOID 00316 DbgParseDebugChannels(PCHAR Value) 00317 { 00318 CHAR *str, *separator, *c, op; 00319 00320 str = Value; 00321 00322 do 00323 { 00324 separator = strchr(str, L','); 00325 if(separator != NULL) 00326 *separator = L'\0'; 00327 00328 c = strchr(str, L'+'); 00329 if(c == NULL) 00330 c = strchr(str, L'-'); 00331 00332 if(c != NULL) 00333 { 00334 op = *c; 00335 *c = L'\0'; 00336 c++; 00337 00338 DbgAddDebugChannel(c, str, op); 00339 } 00340 00341 str = separator + 1; 00342 } while(separator != NULL); 00343 } 00344 00345 #else 00346 00347 ULONG 00348 DbgPrint(PCCH Format, ...) 00349 { 00350 return 0; 00351 } 00352 00353 #endif // DBG 00354 00355 ULONG 00356 MsgBoxPrint(const char *Format, ...) 00357 { 00358 va_list ap; 00359 CHAR Buffer[512]; 00360 ULONG Length; 00361 00362 va_start(ap, Format); 00363 00364 /* Construct a string */ 00365 Length = _vsnprintf(Buffer, 512, Format, ap); 00366 00367 /* Check if we went past the buffer */ 00368 if (Length == MAXULONG) 00369 { 00370 /* Terminate it if we went over-board */ 00371 Buffer[sizeof(Buffer) - 1] = '\n'; 00372 00373 /* Put maximum */ 00374 Length = sizeof(Buffer); 00375 } 00376 00377 /* Show it as a message box */ 00378 UiMessageBox(Buffer); 00379 00380 /* Cleanup and exit */ 00381 va_end(ap); 00382 return 0; 00383 } 00384 00385 //DECLSPEC_NORETURN 00386 VOID 00387 NTAPI 00388 KeBugCheckEx( 00389 IN ULONG BugCheckCode, 00390 IN ULONG_PTR BugCheckParameter1, 00391 IN ULONG_PTR BugCheckParameter2, 00392 IN ULONG_PTR BugCheckParameter3, 00393 IN ULONG_PTR BugCheckParameter4) 00394 { 00395 char Buffer[70]; 00396 sprintf(Buffer, "*** STOP: 0x%08lX (0x%08lX, 0x%08lX, 0x%08lX, 0x%08lX)", 00397 BugCheckCode, BugCheckParameter1, BugCheckParameter2, 00398 BugCheckParameter3, BugCheckParameter4); 00399 UiMessageBoxCritical(Buffer); 00400 assert(FALSE); 00401 for (;;); 00402 } 00403 00404 VOID 00405 NTAPI 00406 RtlAssert(IN PVOID FailedAssertion, 00407 IN PVOID FileName, 00408 IN ULONG LineNumber, 00409 IN PCHAR Message OPTIONAL) 00410 { 00411 if (Message) 00412 { 00413 DbgPrint("Assertion \'%s\' failed at %s line %d: %s\n", 00414 (PCHAR)FailedAssertion, 00415 (PCHAR)FileName, 00416 LineNumber, 00417 Message); 00418 } 00419 else 00420 { 00421 DbgPrint("Assertion \'%s\' failed at %s line %d\n", 00422 (PCHAR)FailedAssertion, 00423 (PCHAR)FileName, 00424 LineNumber); 00425 } 00426 00427 DbgBreakPoint(); 00428 } Generated on Sun May 27 2012 04:17:45 for ReactOS by
1.7.6.1
|