Kernel/debug - Clean up Debug() method, bind to #define config
[tpg/acess2.git] / KernelLand / Kernel / debug.c
index 18c7ebb..3db5387 100644 (file)
@@ -7,8 +7,8 @@
 #include <debug_hooks.h>
 
 #define        DEBUG_MAX_LINE_LEN      256
-#define        LOCK_DEBUG_OUTPUT       1       // Avoid interleaving of output lines?
-#define TRACE_TO_KTERM         0       // Send ENTER/DEBUG/LEAVE to debug?
+#define        LOCK_DEBUG_OUTPUT       0       // Avoid interleaving of output lines?
+#define TRACE_TO_KTERM         0       // Send ENTER/DEBUG/LEAVE/Debug to the VTerm
 
 // === IMPORTS ===
 extern void    KernelPanic_SetMode(void);
@@ -19,7 +19,6 @@ extern void   VT_SetTerminal(int TerminalID);
 // === PROTOTYPES ===
 static void    Debug_Putchar(char ch);
 static void    Debug_Puts(int bUseKTerm, const char *Str);
-void   Debug_DbgOnlyFmt(const char *format, va_list args);
 void   Debug_FmtS(int bUseKTerm, const char *format, ...);
 bool   Debug_Fmt(int bUseKTerm, const char *format, va_list args);
 void   Debug_SetKTerminal(const char *File);
@@ -77,20 +76,14 @@ static void Debug_Puts(int UseKTerm, const char *Str)
                IPStack_SendDebugText(Str);
 
        // Output to the kernel terminal
-       if( UseKTerm && gbDebug_IsKPanic < 2 && giDebug_KTerm != -1)
+       if( UseKTerm && gbDebug_IsKPanic < 2 && giDebug_KTerm != -1 && gbInPutChar == 0)
        {
-               if(gbInPutChar) return ;
                gbInPutChar = 1;
                VFS_Write(giDebug_KTerm, len, Str);
                gbInPutChar = 0;
        }
 }
 
-void Debug_DbgOnlyFmt(const char *format, va_list args)
-{
-       Debug_Fmt(0, format, args);
-}
-
 bool Debug_Fmt(int bUseKTerm, const char *format, va_list args)
 {
        char    buf[DEBUG_MAX_LINE_LEN];
@@ -137,7 +130,10 @@ void Debug_KernelPanic(void)
 bool LogF(const char *Fmt, ...)
 {
        #if LOCK_DEBUG_OUTPUT
-       if(CPU_HAS_LOCK(&glDebug_Lock)) return true;
+       if(CPU_HAS_LOCK(&glDebug_Lock)) {
+               Debug_Puts("[#]");
+               return true;
+       }
        SHORTLOCK(&glDebug_Lock);
        #endif
        
@@ -164,12 +160,11 @@ void Debug(const char *Fmt, ...)
        SHORTLOCK(&glDebug_Lock);
        #endif
 
-       Debug_Puts(0, "Debug: ");
+       Debug_Puts(TRACE_TO_KTERM, "Debug: ");
        va_start(args, Fmt);
-       Debug_DbgOnlyFmt(Fmt, args);
+       Debug_Fmt(TRACE_TO_KTERM, Fmt, args);
        va_end(args);
-       Debug_PutCharDebug('\r');
-       Debug_PutCharDebug('\n');
+       Debug_Puts(TRACE_TO_KTERM, "\r\n");
        #if LOCK_DEBUG_OUTPUT
        SHORTREL(&glDebug_Lock);
        #endif
@@ -265,16 +260,13 @@ void Panic(const char *Fmt, ...)
 
 void Debug_SetKTerminal(const char *File)
 {
-        int    tmp;
        if(giDebug_KTerm != -1) {
-               tmp = giDebug_KTerm;
+               // Clear FD to -1 before closing (prevents writes to closed FD)
+               int oldfd = giDebug_KTerm;
                giDebug_KTerm = -1;
-               VFS_Close(tmp);
+               VFS_Close(oldfd);
        }
-       tmp = VFS_Open(File, VFS_OPENFLAG_WRITE);
-//     Log_Log("Debug", "Opened '%s' as 0x%x", File, tmp);
-       giDebug_KTerm = tmp;
-//     Log_Log("Debug", "Returning to %p", __builtin_return_address(0));
+       giDebug_KTerm = VFS_Open(File, VFS_OPENFLAG_WRITE);
 }
 
 void Debug_Enter(const char *FuncName, const char *ArgTypes, ...)

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