-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Closed
Labels
Description
I have a small C
program that uses pthread
and thread local storage
.
static __thread long z = 0xdeadbeef;
static __thread long x = 0xdeadbeef;
// create the function to be executed as a thread
void *thread(void *ptr)
{
…
}
int main(int argc, char **argv)
{
…
pthread_create(&thread1, NULL, *thread, (void *) thr);
pthread_create(&thread2, NULL, *thread, (void *) thr2);
…
}
- I compile with the following options
-g -O0 -pthread
- when I try to debug it with
lldb
and print the variables I get the following error:
[amin@lzvmr5 c_example]$ lldb main
(lldb) target create "main"
Current executable set to '/home/amin/bugs/.../c_example/main' (x86_64).
(lldb) b thread
Breakpoint 1: where = main`thread + 12 at main.c:11:22, address = 0x000000000040074c
(lldb) run
Process 3366142 launched: '/home/amin/bugs/.../c_example/main' (x86_64)
Process 3366142 stopped
* thread #2, name = 'main', stop reason = breakpoint 1.1
frame #0: 0x000000000040074c main`thread(ptr=0x0000000000000001) at main.c:11:22
8 // create the function to be executed as a thread
9 void *thread(void *ptr)
10 {
-> 11 int type = (int) ptr;
12 printf("%p\n", &z);
13 printf("%p\n", &x);
14 fprintf(stderr,"Thread - %d\n",type);
(lldb) p z
error: Couldn't materialize: couldn't get the value of variable z: No TLS data currently exists for this thread.
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
(lldb) p x
error: Couldn't materialize: couldn't get the value of variable x: No TLS data currently exists for this thread.
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
I can print the variables if I use gdb
.
- I use the following versions of
clang
andlldb
:
$ clang -v
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
...
$ lldb -v
lldb version 10.0.0
Attached you can find the complete reproducer.
embg and xingyu0618