Kernel/debug - make Panic() emit red text
[tpg/acess2.git] / KernelLand / Kernel / debug.c
index 70f503a..b32036e 100644 (file)
@@ -4,17 +4,17 @@
  */
 #include <acess.h>
 #include <stdarg.h>
+#include <debug_hooks.h>
 
 #define        DEBUG_MAX_LINE_LEN      256
 #define        LOCK_DEBUG_OUTPUT       1       // Avoid interleaving of output lines?
-#define TRACE_TO_KTERM         1       // Send ENTER/DEBUG/LEAVE to debug?
+#define TRACE_TO_KTERM         0       // Send ENTER/DEBUG/LEAVE to debug?
 
 // === IMPORTS ===
-extern void    Threads_Dump(void);
-extern void    Heap_Dump(void);
 extern void    KernelPanic_SetMode(void);
 extern void    KernelPanic_PutChar(char Ch);
 extern void    IPStack_SendDebugText(const char *Text);
+extern void    VT_SetTerminal(int TerminalID);
 
 // === PROTOTYPES ===
 static void    Debug_Putchar(char ch);
@@ -114,17 +114,17 @@ void Debug_FmtS(int bUseKTerm, const char *format, ...)
 
 void Debug_KernelPanic(void)
 {
-       if( !gbDebug_IsKPanic )
+       // 5 nested panics? Fuck it
+       if( gbDebug_IsKPanic > 5 )
+               HALT_CPU();
+       gbDebug_IsKPanic ++;
+       if( gbDebug_IsKPanic == 1 )
        {
                #if LOCK_DEBUG_OUTPUT
                SHORTREL(&glDebug_Lock);
                #endif
                VT_SetTerminal(7);
        }
-       // 5 nested panics? Fuck it
-       if( gbDebug_IsKPanic > 5 )
-               HALT_CPU();
-       gbDebug_IsKPanic ++;
        KernelPanic_SetMode();
 }
 
@@ -137,6 +137,7 @@ void LogF(const char *Fmt, ...)
        va_list args;
 
        #if LOCK_DEBUG_OUTPUT
+       if(CPU_HAS_LOCK(&glDebug_Lock)) return ;
        SHORTLOCK(&glDebug_Lock);
        #endif
        
@@ -159,7 +160,8 @@ void Debug(const char *Fmt, ...)
        va_list args;
        
        #if LOCK_DEBUG_OUTPUT
-       if(!CPU_HAS_LOCK(&glDebug_Lock)) SHORTLOCK(&glDebug_Lock);
+       if(CPU_HAS_LOCK(&glDebug_Lock)) return ;
+       SHORTLOCK(&glDebug_Lock);
        #endif
 
        Debug_Puts(0, "Debug: ");
@@ -177,6 +179,7 @@ void Debug(const char *Fmt, ...)
 void LogFV(const char *Fmt, va_list args)
 {
        #if LOCK_DEBUG_OUTPUT
+       if(CPU_HAS_LOCK(&glDebug_Lock)) return ;
        SHORTLOCK(&glDebug_Lock);
        #endif
 
@@ -190,6 +193,7 @@ void LogFV(const char *Fmt, va_list args)
 void LogV(const char *Fmt, va_list args)
 {
        #if LOCK_DEBUG_OUTPUT
+       if(CPU_HAS_LOCK(&glDebug_Lock)) return ;
        SHORTLOCK(&glDebug_Lock);
        #endif
 
@@ -218,6 +222,7 @@ void Warning(const char *Fmt, ...)
        va_list args;
        
        #if LOCK_DEBUG_OUTPUT
+       if(CPU_HAS_LOCK(&glDebug_Lock)) return ;
        SHORTLOCK(&glDebug_Lock);
        #endif
        
@@ -244,13 +249,14 @@ void Panic(const char *Fmt, ...)
        
        Debug_KernelPanic();
        
+       Debug_Puts(1, "\x1b[31m");
        Debug_Puts(1, "Panic: ");
        va_start(args, Fmt);
        Debug_Fmt(1, Fmt, args);
        va_end(args);
-       Debug_Putchar('\r');
-       Debug_Putchar('\n');
+       Debug_Puts(1, "\x1b[0m\r\n");
 
+       Proc_PrintBacktrace();
        //Threads_Dump();
        //Heap_Dump();
 
@@ -279,6 +285,7 @@ void Debug_Enter(const char *FuncName, const char *ArgTypes, ...)
        tTID    tid = Threads_GetTID();
         
        #if LOCK_DEBUG_OUTPUT
+       if(CPU_HAS_LOCK(&glDebug_Lock)) return ;
        SHORTLOCK(&glDebug_Lock);
        #endif
 
@@ -339,6 +346,7 @@ void Debug_Log(const char *FuncName, const char *Fmt, ...)
        tTID    tid = Threads_GetTID();
 
        #if LOCK_DEBUG_OUTPUT
+       if(CPU_HAS_LOCK(&glDebug_Lock)) return ;
        SHORTLOCK(&glDebug_Lock);
        #endif
 
@@ -367,6 +375,7 @@ void Debug_Leave(const char *FuncName, char RetType, ...)
        tTID    tid = Threads_GetTID();
 
        #if LOCK_DEBUG_OUTPUT
+       if(CPU_HAS_LOCK(&glDebug_Lock)) return ;
        SHORTLOCK(&glDebug_Lock);
        #endif
        

UCC git Repository :: git.ucc.asn.au