Improve debugging output from threads.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 24 Oct 2009 23:56:11 +0000 (19:56 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 24 Oct 2009 23:56:11 +0000 (19:56 -0400)
Show the "thread id" on each debug message sent from a thread.
Also, cleanup translation dprintf() so it looks nicer withe thread output.

src/block.c
src/config.h
src/output.c
src/util.c
src/util.h

index a62536caa8707b343852ec4e9c4bccbf07780ffb..0a65ae698feac8e49285220786f0a1c942020b3a 100644 (file)
@@ -86,15 +86,15 @@ setup_translation(struct drive_s *drive_g)
     u16 cylinders = GET_GLOBAL(drive_g->pchs.cylinders);
     u16 spt = GET_GLOBAL(drive_g->pchs.spt);
     u64 sectors = GET_GLOBAL(drive_g->sectors);
+    const char *desc;
 
-    dprintf(1, "ata%d-%d: PCHS=%u/%d/%d translation="
-            , channel, slave, cylinders, heads, spt);
     switch (translation) {
+    default:
     case TRANSLATION_NONE:
-        dprintf(1, "none");
+        desc = "none";
         break;
     case TRANSLATION_LBA:
-        dprintf(1, "lba");
+        desc = "lba";
         spt = 63;
         if (sectors > 63*255*1024) {
             heads = 255;
@@ -116,7 +116,7 @@ setup_translation(struct drive_s *drive_g)
         cylinders = sect / heads;
         break;
     case TRANSLATION_RECHS:
-        dprintf(1, "r-echs");
+        desc = "r-echs";
         // Take care not to overflow
         if (heads==16) {
             if (cylinders>61439)
@@ -127,7 +127,7 @@ setup_translation(struct drive_s *drive_g)
         // then go through the large bitshift process
     case TRANSLATION_LARGE:
         if (translation == TRANSLATION_LARGE)
-            dprintf(1, "large");
+            desc = "large";
         while (cylinders > 1024) {
             cylinders >>= 1;
             heads <<= 1;
@@ -141,7 +141,11 @@ setup_translation(struct drive_s *drive_g)
     // clip to 1024 cylinders in lchs
     if (cylinders > 1024)
         cylinders = 1024;
-    dprintf(1, " LCHS=%d/%d/%d\n", cylinders, heads, spt);
+    dprintf(1, "ata%d-%d: PCHS=%u/%d/%d translation=%s LCHS=%d/%d/%d\n"
+            , channel, slave
+            , drive_g->pchs.cylinders, drive_g->pchs.heads, drive_g->pchs.spt
+            , desc
+            , cylinders, heads, spt);
 
     SET_GLOBAL(drive_g->lchs.heads, heads);
     SET_GLOBAL(drive_g->lchs.cylinders, cylinders);
index ab243deb3cb1ac630714845986651f1c74853b1c..3033133f7beacf24b4d5b8ac9c0fa87763b6e704 100644 (file)
 #define DEBUG_ISR_hwpic2 5
 #define DEBUG_HDL_pnp 1
 #define DEBUG_HDL_pmm 1
+#define DEBUG_thread 1
 
 #endif // config.h
index e860b0b2c6247d6b6ecaf54e2ca644931ac53433..7f74a69ec44c2024a8e6dfb59158f2d603c15307 100644 (file)
@@ -115,7 +115,7 @@ static void
 putc_screen(struct putcinfo *action, char c)
 {
     if (CONFIG_SCREEN_AND_DEBUG)
-        putc_debug(action, c);
+        putc_debug(&debuginfo, c);
     if (c == '\n')
         screenc('\r');
     screenc(c);
@@ -325,6 +325,18 @@ panic(const char *fmt, ...)
 void
 __dprintf(const char *fmt, ...)
 {
+    if (!MODE16 && CONFIG_THREADS && CONFIG_DEBUG_LEVEL >= DEBUG_thread
+        && *fmt != '\\' && *fmt != '/') {
+        struct thread_info *cur = getCurThread();
+        if (cur != &MainThread) {
+            // Show "thread id" for this debug message.
+            putc_debug(&debuginfo, '|');
+            puthex(&debuginfo, (u32)cur, 8);
+            putc_debug(&debuginfo, '|');
+            putc_debug(&debuginfo, ' ');
+        }
+    }
+
     va_list args;
     va_start(args, fmt);
     bvprintf(&debuginfo, fmt, args);
index 21c7a62c577f2299c5a9536c7e3df808031a596f..36f32e43208265d89322c21036d788fdd629a951 100644 (file)
@@ -134,9 +134,9 @@ struct thread_info {
     void *stackpos;
 };
 
-static struct thread_info MainThread = {&MainThread, NULL};
+struct thread_info MainThread = {&MainThread, NULL};
 
-static struct thread_info *
+struct thread_info *
 getCurThread()
 {
     u32 esp = getesp();
@@ -187,7 +187,7 @@ __end_thread(struct thread_info *old)
         pos = pos->next;
     pos->next = old->next;
     free(old);
-    dprintf(2, "=========== end thread %p\n", old);
+    dprintf(DEBUG_thread, "\\%08x/ End thread\n", (u32)old);
 }
 
 void
@@ -206,7 +206,7 @@ run_thread(void (*func)(void*), void *data)
     thread->next = cur->next;
     cur->next = thread;
 
-    dprintf(2, "=========== start thread %p\n", thread);
+    dprintf(DEBUG_thread, "/%08x\\ Start thread\n", (u32)thread);
     asm volatile(
         // Start thread
         "  pushl $1f\n"                 // store return pc
index c2214c9f4a659843b2119593c351a265efe59c7d..637fd2bc6efec20259a54a47ed316ba45361535b 100644 (file)
@@ -139,6 +139,8 @@ static inline u8 readb(const void *addr) {
 
 // util.c
 inline u32 stack_hop(u32 eax, u32 edx, u32 ecx, void *func);
+extern struct thread_info MainThread;
+struct thread_info *getCurThread();
 void run_thread(void (*func)(void*), void *data);
 void wait_threads();
 u8 checksum_far(u16 buf_seg, void *buf_far, u32 len);