Kernel - Debugging
authorJohn Hodge <[email protected]>
Thu, 3 Nov 2011 14:13:11 +0000 (22:13 +0800)
committerJohn Hodge <[email protected]>
Thu, 3 Nov 2011 14:13:11 +0000 (22:13 +0800)
Kernel/binary.c
Kernel/messages.c
Kernel/threads.c

index 9534aaa..8c28d72 100644 (file)
@@ -91,7 +91,6 @@ int Proc_Spawn(const char *Path)
 }
 
 /**
- * \fn int Proc_Execve(char *File, char **ArgV, char **EnvP)
  * \brief Replace the current user image with another
  * \param File File to load as the next image
  * \param ArgV Arguments to pass to user
@@ -118,6 +117,7 @@ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP)
                argenvBytes += strlen(ArgV[argc])+1;
        for( envc = 0; EnvP && EnvP[envc]; envc++ )
                argenvBytes += strlen(EnvP[envc])+1;
+       LOG("argc = %i, envc = %i", envc);
        argenvBytes = (argenvBytes + sizeof(void*)-1) & ~(sizeof(void*)-1);
        argenvBytes += (argc+1)*sizeof(void*) + (envc+1)*sizeof(void*);
        
@@ -136,6 +136,7 @@ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP)
        {
                argvSaved[i] = strBuf;
                strcpy(argvSaved[i], ArgV[i]);
+               LOG("argv[%i] = '%s'", i, strBuf);
                strBuf += strlen(ArgV[i])+1;
        }
        argvSaved[i] = NULL;
@@ -143,6 +144,7 @@ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP)
        for( i = 0; i < envc; i++ )
        {
                envpSaved[i] = strBuf;
+               LOG("envp[%i] = '%s'", i, strBuf);
                strcpy(envpSaved[i], EnvP[i]);
                strBuf += strlen(EnvP[i])+1;
        }
index ce23d6b..b70e078 100644 (file)
@@ -66,6 +66,7 @@ int Proc_SendMessage(Uint *Err, Uint Dest, int Length, void *Data)
        SHORTREL(&thread->IsLocked);
        
        SHORTLOCK(&glThreadListLock);
+       LOG("Waking %p (%i %s)", thread, thread->TID, thread->ThreadName);
        Threads_Wake( thread );
        SHORTREL(&glThreadListLock);
        
index 1393f54..2f8d933 100644 (file)
@@ -14,7 +14,7 @@
 // Configuration
 #define DEBUG_TRACE_TICKETS    0       // Trace ticket counts
 #define DEBUG_TRACE_STATE      0       // Trace state changes (sleep/wake)
-#define SEMAPHORE_DEBUG        0
+#define SEMAPHORE_DEBUG        0       // Debug semaphores
 
 // --- Schedulers ---
 #define SCHED_UNDEF    0
@@ -618,7 +618,7 @@ void Threads_Kill(tThread *Thread, int Status)
                }
                break;
        
-       // Brains!... You cannot kill
+       // Brains!... You cannot kill something that is already dead
        case THREAD_STAT_ZOMBIE:
                Log_Warning("Threads", "Threads_Kill - Thread %p(%i,%s) is undead, you cannot kill it",
                        Thread, Thread->TID, Thread->ThreadName);
@@ -635,6 +635,8 @@ void Threads_Kill(tThread *Thread, int Status)
        // Save exit status
        Thread->RetStatus = Status;
 
+       SHORTREL( &Thread->IsLocked );
+
        // Don't Zombie if we are being killed because our parent is
        if(Status == -1)
        {
@@ -650,9 +652,6 @@ void Threads_Kill(tThread *Thread, int Status)
        
        Log("Thread %i went *hurk* (%i)", Thread->TID, Status);
        
-       // Release spinlocks
-       SHORTREL( &Thread->IsLocked );  // TODO: We may not actually be released...
-       
        // And, reschedule
        if(isCurThread)
        {
@@ -713,7 +712,6 @@ void Threads_Sleep(void)
 
 
 /**
- * \fn int Threads_Wake( tThread *Thread )
  * \brief Wakes a sleeping/waiting thread up
  * \param Thread       Thread to wake
  * \return Boolean Failure (Returns ERRNO)
@@ -783,6 +781,7 @@ int Threads_Wake(tThread *Thread)
                                sem->LastSignaling = prev;
                }
                
+               Thread->RetStatus = 0;  // It didn't get anything
                Threads_AddActive( Thread );
                
                #if DEBUG_TRACE_STATE
@@ -1509,8 +1508,17 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake)
                #endif
                
                SHORTREL( &Sem->Protector );    // Release first to make sure it is released
-               SHORTREL( &glThreadListLock );  
-               while(us->Status == THREAD_STAT_SEMAPHORESLEEP) Threads_Yield();
+               SHORTREL( &glThreadListLock );
+               while( us->Status == THREAD_STAT_SEMAPHORESLEEP )
+               {
+                       Threads_Yield();
+                       if(us->Status == THREAD_STAT_SEMAPHORESLEEP)
+                               Log_Warning("Threads", "Semaphore %p %s:%s re-schedulued while asleep",
+                                       Sem, Sem->ModName, Sem->Name);
+               }
+               #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG
+               Log("Semaphore %p %s:%s woken", Sem, Sem->ModName, Sem->Name);
+               #endif
                // We're only woken when there's something avaliable (or a signal arrives)
                us->WaitPointer = NULL;
                
@@ -1557,6 +1565,11 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake)
        }
        SHORTREL( &Sem->Protector );
        
+       #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG
+       Log("Semaphore %p %s:%s took %i by wait",
+               Sem, Sem->ModName, Sem->Name, taken);
+       #endif
+
        return taken;
 }
 

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