[Ltrace-devel] ltrace stucks with pthreads

Georg Lohrer georg at tropezien.de
Fri Apr 14 03:45:34 UTC 2006


Hi,

I have just tried to use ltrace with this small application:

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *thread(void *i)
{
    pthread_t t2,t3;
    printf("In thread\n");

    printf("thread PID %d\n", getpid());
    sleep(5);
    pthread_exit(0);
}


int main(int argc, char **argv)
{
    pthread_t t1, t2;

    printf("main PID %d\n", getpid());
    pthread_create(&t1, NULL, thread, NULL);
    pthread_create(&t2, NULL, thread, NULL);
    pthread_join(t1, NULL);
    pthread_join(t2, NULL);
    printf("threads joined\n");

    return 0;
}

compiled with an easy:

  $ gcc -o threadtest threadtest.c

I got a running:

  $ threadtest
  main PID 7739
  In thread
  thread PID 7739
  In thread
  thread PID 7739
  threads joined

seeming quite okay. Both threads will be started and after five seconds they
finish themselves and the whole stuff will be joined.
And now with ltrace-0.40:

  $ ltrace threadtest
  __libc_start_main(0x8048563, 1, 0xbffdc5a4, 0x8048620, 0x8048690 <unfinished
...>
  getpid()                                                  = 7981
  printf("main PID %d\n", 7981main PID 7981)                = 14
  pthread_create(0xbffdc524, 0, 0x8048524, 0, 1)            = 0
  pthread_create(0xbffdc520, 0, 0x8048524, 0, 1In thread
thread PID 7981
  )                                                         = 0
  pthread_join(0xb7e6dbb0, 0, 0x8048524, 0, 1 <unfinished ...>
  +++ killed by SIGTRAP +++

Ah yes, there is this internal pthread-lib communication with signals. So I
use:

  $ ltrace -f threadtest
  __libc_start_main(0x8048563, 1, 0xbf83ccb4, 0x8048620, 0x8048690 <unfinished
...>
  getpid()                                             = 8510
  printf("main PID %d\n", 8510main PID 8510
  )                                                    = 14
  pthread_create(0xbf83cc34, 0, 0x8048524, 0, 1)       = 0
  [pid 8510] pthread_create(0xbf83cc30, 0, 0x8048524, 0, 1)  = 0
  [pid 8510] pthread_join(0xb7dccbb0, 0, 0x8048524, 0, 1

And that's it. The application is in stuck-state. Nothing more happens. If I try
to send a SIGTERM or SIGINT to the app nothing happens beside the application
will be marked as defunct.

  $ ps aux
  georg     8509  0.0  0.0   1752   628 pts/4    S+   05:33   0:00 ltrace -f
threadtest.x86.bin
  georg     8510  0.0  0.0  18036   456 pts/4    Sl+  05:33   0:00
threadtest.x86.bin

  $ kill -SIGINT 8510
  $ ps aux
  georg     8509  0.0  0.0   1752   652 pts/4    S+   05:33   0:00 ltrace -f
threadtest.x86.bin
  georg     8510  0.0  0.0      0     0 pts/4    Zl+  05:33   0:00
[threadtest.x86.] <defunct>

Only a SIGKILL will clean up this situation.

What am I doing wrong? Is there a hidden secret to use ltrace with threads? Any
additional parameter to pass. Or any specific compilation switch to use?

BTW, this test application testthread was only extracted from a much more bigger
application to show the gory details. Usually the ACE-framework is used, that
itself is based on pthreads.

The testing system is an x86-host-system running glibc-2.3.6, libpthread-0.10,
and gcc-4.0.2. But the same happens on x86-host with glibc-2.3.5,
libpthread-0.10 and gcc-3.4.3. Also happens on PowerPC with glibc-2.3.4,
linuxthreads and gcc-3.4.3.

And the same situation happens with the brand-new updated svn-checkout of
ltrace.

Any ideas?

Ciao, Georg


-- 
Georg Lohrer
GnuPGP-Key available on WebSite http://www.tropezien.de



More information about the Ltrace-devel mailing list