[omniORB] linux/gdb and multithreading

Sai-Lai Lo S.Lo@orl.co.uk
24 Nov 1998 14:46:37 +0000


> I'm having problem debugging my multithreaded orb using RedHat-5.1 (and
> RedHat 5.2).  My debugger supports multi-threading (gdb-4.17.0.4 from
> RedHat).
> 
> Here is whats happening:
> 
> In the file src/lib/omnithread/posix.cc, in the function timedwait I get
> a EINTR from pthread_cond_timedwait(), and this leads to omniorb throwing
> an exception.
> 
> The question is: why do I get an EINTR? And why does this only happen from
> within the debugger? My programs runs fine without the debugger. 

The following is a patch to work around the bug in glibc-2.0.x that causes
the thread to return EINTR instead of blocking again till the timeout has
expired.

I've used gdb that comes with Redhat-5.2 successfully after the patch is
applied. Its a pity that egcs runtime still cannot give me a stack trace of
the exact location of where an uncaught exception is thrown. But at least
now we can put a multithreaded process under a debugger!

Regards,

Sai-Lai



*** src/lib/omnithread/posix.cc        Sat Aug 22 14:05:34 1998
--- newsrc/lib/omnithread/posix.cc        Tue Nov 24 14:30:51 1998
***************
*** 152,157 ****
--- 152,158 ----
  {
      timespec rqts = { secs, nanosecs };
  
+  again:
      int rc = ERRNO(pthread_cond_timedwait(&posix_cond,
                                          &mutex->posix_mutex, &rqts));
      if (rc == 0)
***************
*** 160,165 ****
--- 161,174 ----
  #if (PthreadDraftVersion <= 6)
      if (rc == EAGAIN)
        return 0;
+ #endif
+ 
+ #if defined(__GLIBC__)
+     // Some versions of the glibc 2.0.x produces this errno when the 
+     // program is debugged under gdb. Straightly speaking this is non-posix
+     // compliant. We catch this here to make debugging possible.
+     if (rc == EINTR)
+       goto again;
  #endif
  
      if (rc == ETIMEDOUT)

-- 
Dr. Sai-Lai Lo                          |       Research Scientist
                                        |
E-mail:         S.Lo@orl.co.uk          |       Olivetti & Oracle Research Lab
                                        |       24a Trumpington Street
Tel:            +44 223 343000          |       Cambridge CB2 1QA
Fax:            +44 223 313542          |       ENGLAND