This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: gdb doesnt show nptl threads
Here's the snapshot of the session (I've attached the code for the
appln "thread" I'm running). I'm building it w/ gcc -Wall
-D_REENTRANT -g -o thread main.c -lpthread).
# ls -l /lib64/libpthread
libpthread-2.3.6.so libpthread.so.0
# gdb64 thread
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu"...
Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) break main
Breakpoint 1 at 0x4006e0: file main.c, line 29.
(gdb) r
Starting program: thread
Failed to read a valid object file image from memory.
Breakpoint 1, main () at main.c:29
29 main.c: No such file or directory.
in main.c
(gdb) n
30 in main.c
(gdb) n
29 in main.c
(gdb)
Thread ID1075841376: X is now 1.
Thread ID1075841376: X is now 2.
Thread ID1075841376: X is now 3.
Thread ID1075841376: X is now 4.
Thread ID1075841376: X is now 5.
Thread ID1075841376: X is now 6.
Thread ID1075841376: X is now 7.
Thread ID1075841376: X is now 8.
Thread ID1075841376: X is now 9.
Thread ID1075841376: X is now 10.
30 in main.c
(gdb)
Thread ID1075841376: X is now 11.
Thread ID1075841376: X is now 12.
Thread ID1075841376: X is now 13.
Thread ID1075841376: X is now 14.
Thread ID1075841376: X is now 15.
Thread ID1075841376: X is now 16.
Thread ID1075841376: X is now 17.
Thread ID1075841376: X is now 18.
Thread ID1075841376: X is now 19.
Thread ID1075841376: X is now 20.
Thread ID1075841376: X is now 21.
Thread ID1075841376: X is now 22.
Thread ID1075841376: X is now 23.
Thread ID1075841376: X is now 24.
Thread ID1075841376: X is now 25.
Thread ID1075841376: X is now 26.
Thread ID1075841376: X is now 27.
Thread ID1075841376: X is now 28.
Thread ID1075841376: X is now 29.
Thread ID1075841376: X is now 30.
Thread ID1075841376: X is now 31.
Thread ID1075841376: X is now 32.
Thread ID1075841376: X is now 33.
Thread ID1075841376: X is now 34.
Thread ID1075841376: X is now 35.
Thread ID1075841376: X is now 36.
Thread ID1075841376: X is now 37.
Thread ID1075841376: X is now 38.
Thread ID1075841376: X is now 39.
Thread ID1075841376: X is now 40.
Thread ID1075841376: X is now 41.
Thread ID1075841376: X is now 42.
Thread ID1075841376: X is now 43.
Thread ID1075841376: X is now 44.
Thread ID1075841376: X is now 45.
Thread ID1075841376: X is now 46.
Thread ID1075841376: X is now 47.
Thread ID1075841376: X is now 48.
Thread ID1075841376: X is now 49.
Thread ID1075841376: X is now 50.
Thread ID1075841376: X is now 51.
Thread ID1075841376: X is now 52.
Thread ID1075841376: X is now 53.
Thread ID1075841376: X is now 54.
Thread ID1075841376: X is now 55.
Thread ID1075841376: X is now 56.
Thread ID1075841376: X is now 57.
Thread ID1075841376: X is now 58.
Thread ID1075841376: X is now 59.
Thread ID1075841376: X is now 60.
Thread ID1075841376: X is now 61.
Thread ID1075841376: X is now 62.
Thread ID1075841376: X is now 63.
Thread ID1075841376: X is now 64.
Thread ID1075841376: X is now 65.
Thread ID1075841376: X is now 66.
Thread ID1075841376: X is now 67.
Thread ID1075841376: X is now 68.
Thread ID1075841376: X is now 69.
Thread ID1075841376: X is now 70.
Thread ID1075841376: X is now 71.
Thread ID1075841376: X is now 72.
Thread ID1075841376: X is now 73.
Thread ID1075841376: X is now 74.
Thread ID1075841376: X is now 75.
Thread ID1075841376: X is now 76.
Thread ID1075841376: X is now 77.
Thread ID1075841376: X is now 78.
Thread ID1075841376: X is now 79.
Thread ID1075841376: X is now 80.
Thread ID1075841376: X is now 81.
Thread ID1075841376: X is now 82.
Thread ID1075841376: X is now 83.
Thread ID1075841376: X is now 84.
Thread ID1075841376: X is now 85.
Thread ID1075841376: X is now 86.
Thread ID1075841376: X is now 87.
Thread ID1075841376: X is now 88.
Thread ID1075841376: X is now 89.
Thread ID1075841376: X is now 90.
Thread ID1075841376: X is now 91.
Thread ID1075841376: X is now 92.
Thread ID1075841376: X is now 93.
Thread ID1075841376: X is now 94.
Thread ID1075841376: X is now 95.
Thread ID1075841376: X is now 96.
Thread ID1075841376: X is now 97.
Thread ID1075841376: X is now 98.
Thread ID1075841376: X is now 99.
Thread ID1075841376: X is now 100.
Thread ID1075841376: X is now 101.
Thread ID1075841376: X is now 102.
Thread ID1075841376: X is now 103.
Thread ID1075841376: X is now 104.
Thread ID1075841376: X is now 105.
29 in main.c
(gdb) info threads
(gdb) n
Thread ID1077942624: X is now 106.
Thread ID1077942624: X is now 107.
Thread ID1077942624: X is now 108.
Thread ID1077942624: X is now 109.
Thread ID1077942624: X is now 110.
Thread ID1077942624: X is now 111.
Thread ID1077942624: X is now 112.
Thread ID1077942624: X is now 113.
30 in main.c
(gdb) n
Thread ID1077942624: X is now 114.
Thread ID1077942624: X is now 115.
Thread ID1077942624: X is now 116.
Thread ID1077942624: X is now 117.
Thread ID1077942624: X is now 118.
Thread ID1077942624: X is now 119.
Thread ID1077942624: X is now 120.
Thread ID1077942624: X is now 121.
Thread ID1077942624: X is now 122.
Thread ID1077942624: X is now 123.
Thread ID1077942624: X is now 124.
Thread ID1077942624: X is now 125.
Thread ID1077942624: X is now 126.
Thread ID1077942624: X is now 127.
Thread ID1077942624: X is now 128.
Thread ID1077942624: X is now 129.
Thread ID1077942624: X is now 130.
Thread ID1077942624: X is now 131.
Thread ID1077942624: X is now 132.
Thread ID1077942624: X is now 133.
Thread ID1077942624: X is now 134.
Thread ID1077942624: X is now 135.
Thread ID1077942624: X is now 136.
Thread ID1075841376: X is now 137.
Thread ID1075841376: X is now 138.
Thread ID1075841376: X is now 139.
Thread ID1075841376: X is now 140.
Thread ID1075841376: X is now 141.
Thread ID1075841376: X is now 142.
Thread ID1075841376: X is now 143.
Thread ID1077942624: X is now 144.
29 in main.c
(gdb) n
Thread ID1080043872: X is now 145.
Thread ID1080043872: X is now 146.
Thread ID1080043872: X is now 147.
Thread ID1080043872: X is now 148.
Thread ID1080043872: X is now 149.
Thread ID1080043872: X is now 150.
30 in main.c
(gdb)
Thread ID1080043872: X is now 151.
Thread ID1080043872: X is now 152.
Thread ID1080043872: X is now 153.
Thread ID1077942624: X is now 154.
Thread ID1077942624: X is now 155.
Thread ID1077942624: X is now 156.
Thread ID1077942624: X is now 157.
Thread ID1077942624: X is now 158.
Thread ID1077942624: X is now 159.
Thread ID1077942624: X is now 160.
Thread ID1077942624: X is now 161.
Thread ID1080043872: X is now 162.
Thread ID1080043872: X is now 163.
Thread ID1080043872: X is now 164.
Thread ID1080043872: X is now 165.
Thread ID1080043872: X is now 166.
Thread ID1080043872: X is now 167.
Thread ID1080043872: X is now 168.
Thread ID1080043872: X is now 169.
Thread ID1080043872: X is now 170.
Thread ID1080043872: X is now 171.
Thread ID1080043872: X is now 172.
Thread ID1080043872: X is now 173.
Thread ID1080043872: X is now 174.
Thread ID1080043872: X is now 175.
Thread ID1080043872: X is now 176.
Thread ID1080043872: X is now 177.
Thread ID1080043872: X is now 178.
Thread ID1080043872: X is now 179.
29 in main.c
(gdb) info threads
(gdb) thread 2
Thread ID 2 not known.
(gdb) thread 1
Thread ID 1 not known.
(gdb) thread 1080043872
Thread ID 1080043872 not known.
(gdb) info threads
On Wed, Jun 11, 2008 at 7:58 AM, Doug Evans <dje@google.com> wrote:
> On Wed, Jun 11, 2008 at 12:19 AM, Srinivas Murthy <codevana@gmail.com> wrote:
>> Hi,
>> I have the following setup:
>> gdb6.6 built using a 64b glibc w/ nptl enabled
>> 64b glibc - 2.3.6 (nptl enabled)
>>
>> When I use gdb on a sample multi-threaded (nptl) app, I cant get any
>> thread specific gdb cmds to work.
>>
>> For ex. info threads shows only one thread (the main thread).
>>
>> Any idea what might be going wrong?
>
> Unlikely, but one thing that could explain this is the glibc you're
> using is a hand-made one installed in some place other than /lib64.
> gdb will only look for libthread_db in a few specific places.
>
> A copy of the session log from the start up until the error could help
> diagnosis.
>
/* You can compile this program with:
* gcc -Wall -D_REENTRANT -o thread thread.c<\n>
* -lpthread */
/* We always need to include this header file for<\n>
* the threads */
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
/* This is the prototype for our thread function */
void *mythread(void *data);
/* We must initialize our mutex */
pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
/* This will be a shared variable between all of<\n>
* the threads */
int x = 0;
int main(void) {
/* This will be an array holding the thread ids<\n>
* for each thread */
/* We keep track of all the tids so that we can<\n>
* call pthread_join()later to retrieve
* the return value from the thread */
pthread_t tids[10];
int i;
/* We will now create the 10 threads. Each<\n>
* thread will increment x until x is 4000.
* On our last argument ot pthread_create
* we could have passed an argument to the
* thread function */
for(i=0; i<10; i++) {
pthread_create(&tids[i], NULL, mythread, NULL);
}
/* We will now wait for each thread to<\n>
* terminate */
for(i=0; i<10; i++) {
/* This will block until the specified
* thread finishes execution. Our second
* argument to pthread_join can be a pointer
* that will have the return value of the
* thread stored in it */
pthread_join(tids[i], NULL);
printf("Thread id %ld returned\n", tids[i]);
}
return(1);
}
/* This is our actual thread function */
void *mythread(void *data) {
while(x < 4000) {
/* We will now try to lock the mutex. If
* another thread already has it locked, we
* block until it is available again. After
* you first run this program, you should
* comment out the lock/unlock lines in this
* function so that you can see why you need
* mutexes. */
pthread_mutex_lock(&count_mutex);
x++;
/* We will have it print out the thread ID
* and the value of X */
printf("Thread ID%ld: X is now %d.\n",
pthread_self(), x);
/* We will now release the mutex so that
* another thread gets the chance to run. */
pthread_mutex_unlock(&count_mutex);
}
/* We can return a pointer. Whatever pointer
* we return can later be retrieved using the
* pthread_join function */
pthread_exit(NULL);