Hello
I'm trying to use gdb to look at the callstacks in a multi-threaded application. I started with a very simple application where main simply spawns two threads and waits to join them.
When I do a "thread apply all where", the main threads stack looks valid, but the stacks for the child threads don't show the functions at the top of their stack.
(gdb) thread apply all where
Thread 3 (Thread 24709):
#0 0x400d60d4 in nanosleep ()
from /data/rernst/VIPE_platforms/Bullet/bld/target-root/lib/libc.so.6
#1 0x40112ab4 in ?? ()
from /data/rernst/VIPE_platforms/Bullet/bld/target-root/lib/libc.so.6
Thread 2 (Thread 24708):
#0 0x400d60d4 in nanosleep ()
from /data/rernst/VIPE_platforms/Bullet/bld/target-root/lib/libc.so.6
#1 0x40112ab4 in ?? ()
from /data/rernst/VIPE_platforms/Bullet/bld/target-root/lib/libc.so.6
Thread 1 (Thread 24679):
#0 0x4002c870 in pthread_join ()
from /data/rernst/VIPE_platforms/Bullet/bld/target-root/lib/libpthread.so.0
#1 0x000086dc in main () at thread-ex.c:46
The debugger lists the symbol names for the main() thread (thread 1).
Threads 2 & 3 should show one more lever of stack, the entry point for the child threads, the function named print_message_function.
main() and print_message_function() are in the same file, so the symbol data is available.
The stacks for threads 2&3 should be 3 levels deep:
#0-nonsleep()
#1-sleep()
#2-print_message_function()
All of my code is in the same file:
int main()
{
pthread_t thread1, thread2; /* thread variables */
thdata data1, data2; /* structs to be passed to threads */
int PID=getpid();
printf("\nPID:%d\n", PID);
/* initialize data to pass to thread 1 */
data1.thread_no = 1;
strcpy(data1.message, "Hello!");
/* initialize data to pass to thread 2 */
data2.thread_no = 2;
strcpy(data2.message, "Hi!");
/* create threads 1 and 2 */
pthread_create (&thread1, NULL, (void *) &print_message_function, (void *) &data1);
pthread_create (&thread2, NULL, (void *) &print_message_function, (void *) &data2);
/* Main block now waits for both threads to terminate, before it exits
If main block exits, both threads exit, even if the threads have not
finished their work */
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
/* exit */
exit(0);
} /* main() */
/**
* print_message_function is used as the start routine for the threads used
* it accepts a void pointer
**/
void print_message_function ( void *ptr )
{
thdata *data;
data = (thdata *) ptr; /* type cast to a pointer to thdata */
unsigned int systid = (unsigned int) syscall(SYS_gettid);
prctl(PR_SET_NAME, data->message ,0,0,0);
/* do the work */
printf("Thread:%d PID:%u says:%s \n", data->thread_no, systid, data->message);
sleep(100);
pthread_exit(0); /* exit */
} /* print_message_function ( void *ptr ) */
Why doesn't gdb show the top level function?