Hi, I'm having trouble getting gdb backtraces from a multithreaded (nptl) C program in which some threads are blocked in pthread_mutex_lock.
Consider the following program that does a simple deadlock: #include <pthread.h> #include <stdio.h> #include <unistd.h> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_t thread1, thread2; void* thread_function(void* arg) { pthread_mutex_lock(&mutex); pause(); return NULL; } int main() { pthread_create(&thread1, NULL, thread_function, NULL); pthread_create(&thread2, NULL, thread_function, NULL); pause(); return 0; } If I run this on an Etch amd64 machine (libc 2.3.6.ds1-13etch7), and attach with gdb to get a backtrace, for the locked thread I get: Thread 3 (Thread 1090525536 (LWP 14962)): #0 0x00002afcad512eeb in __lll_mutex_lock_wait () from /lib/libpthread.so.0 #1 0x0000000000000002 in ?? () #2 0x00000000410019f0 in ?? () #3 0x00002afcad50fd9f in pthread_mutex_lock () from /lib/libpthread.so.0 #4 0x0000000000000000 in ?? () which is not very useful. I have tried using libc6-dbg, but the output is similar: # LD_LIBRARY_PATH=/usr/lib/debug/ gdb ./a.out I Thread 3 (Thread 1090525536 (LWP 14979)): #0 __lll_mutex_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:59 #1 0x0000000000000002 in ?? () #2 0x00000000410019f0 in ?? () #3 0x00002b8db4265d9f in pthread_mutex_lock () from /usr/lib/debug/libpthread.so.0 #4 0x0000000000000000 in ?? () Current language: auto; currently asm However, on a Lenny machine (libc 2.7-15), the output is as expected: Thread 3 (Thread 0xb763fb90 (LWP 5268)): #0 0xb7fd6424 in __kernel_vsyscall () #1 0xb7fa9c99 in __lll_lock_wait () from /lib/i686/cmov/libpthread.so.0 #2 0xb7fa50c4 in _L_lock_89 () from /lib/i686/cmov/libpthread.so.0 #3 0xb7fa49f2 in pthread_mutex_lock () from /lib/i686/cmov/libpthread.so.0 #4 0x080484a6 in thread_function (arg=0x0) at test.c:11 #5 0xb7fa34c0 in start_thread () from /lib/i686/cmov/libpthread.so.0 #6 0xb7f2261e in clone () from /lib/i686/cmov/libc.so.6 Also, I should mention that if I use a spin lock instead of the mutex, I get a backtrace also in etch. First, I would like to understand why this could happen. I have the libc6-dev package installed and generally I can see the symbols just fine, so this doesn't look like a 'missing symbols' problem. Could it be that the assembler code from the pthread_mutex_lock implementation is not correctly understood by gdb? Is there anything to do in this case? Any suggestions welcome, including redirecting me to the correct list to ask this stuff :-) Also, I would appreciate if you could run the above program on your Etch system and let me know if you can get a meaningful bt. TIA, Tudor -- Tudor Golubenco http://golubenco.org Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]