This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Debug improvement


While debugging some thread problems recently, I turned on asserts and 
thread stack checking only to find the results less than useful.  Yes, 
the checking code detected the error (most times), but I was unable to 
get useful information from GDB (I set a breakpoint at 
cyg_assert_fail).  This was because the stack had been trashed severely.

What I ended up doing was augmenting the stack check to provide a simple
dump when an error was detected (along with the assert).  By being able 
to see the dump, I was able to get more information and move along.

My question is: what do y'all think of making such a change permanent.  
I know that we've tried to keep most of these interfaces pretty pristine
(no prints, no dumps, etc), but what's there didn't help me and I'm sure
that others in the world (certainly ones with less experience with eCos 
than I) would have been "stuck" with the existing support.

Here's a patch which helped me:

Index: kernel/current/include/thread.inl
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/kernel/current/include/thread.inl,v
retrieving revision 1.14
diff -u -5 -p -r1.14 thread.inl
--- kernel/current/include/thread.inl	23 May 2002 23:06:51 -0000	1.14
+++ kernel/current/include/thread.inl	24 Jan 2003 00:17:07 -0000
@@ -62,10 +62,11 @@
 
 #include <cyg/kernel/thread.hxx>
 #include <cyg/hal/hal_arch.h>
 
 #include <cyg/kernel/clock.inl>
+#include <cyg/infra/diag.h>
 
 #ifndef CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE
 #define CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE (0)
 #endif
 
@@ -108,10 +109,14 @@ inline void Cyg_HardwareThread::check_st
                 "Stack_ptr above top" );
 
     for ( i = 0;
           i < CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE/sizeof(cyg_uint32);
           i++ ) {
+        if ((sig ^ (i * 0x01010101)) != base[i]) {
+            diag_printf("Stack base corrupt - i: %d\n", i);
+            diag_dump_buf(base, CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE);
+        }
         CYG_ASSERT( (sig ^ (i * 0x01010101)) == base[i], "Stack base corrupt" );
         CYG_ASSERT( (sig ^ (i * 0x10101010)) ==  top[i], "Stack top corrupt"  );
     }            
 
 #ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT


-- 
------------------------------------------------------------
Gary Thomas                 |
MLB Associates              |  Consulting for the
+1 (970) 229-1963           |    Embedded world
http://www.mlbassoc.com/    |
email: <gary@mlbassoc.com>  |
gpg: http://www.chez-thomas.org/gary/gpg_key.asc
------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]