Re: Printing thread_local a.k.a. __thread variables

Yao Qi <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <CAH=s-PP8rg3YxP1uO-PiXa1WJhM4+ks8Z3=TwKJuCmqUBdxULg@mail.gmail.com>
On Mon, Feb 12, 2018 at 1:29 PM, Dmitry Antipov <[email protected]> wrote:
> I just tried the recent git snapshot (on x86 GNU/Linux) and always seeing
> 100 for 'tlocal' variable. Compiled wit GCC 7.3, -O0 -g3, regardless of
> -gdwarf-4 default or -gdwarf-5. Am I doing wrong something?
>

Because you are in thread 1, main thread, in which tlocal is not changed.
If you switch to other threads, you'll see the right value of tlocal.

Thread 1 "2.exe" received signal SIGINT, Interrupt.
0x00007ffff7bc565b in pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) p tlocal
$1 = 100
(gdb) thread 2
[Switching to thread 2 (Thread 0x7ffff6fc6700 (LWP 29726))]
#0  0x00007ffff7bcbb9d in nanosleep () from
/lib/x86_64-linux-gnu/libpthread.so.0
(gdb) p tlocal
$2 = 104
(gdb) thread 4
[Switching to thread 4 (Thread 0x7ffff5fc4700 (LWP 29728))]
#0  0x00007ffff7bcbb9d in nanosleep () from
/lib/x86_64-linux-gnu/libpthread.so.0
(gdb) p tlocal
$4 = 112
(gdb) thread apply all print tlocal

Thread 9 (Thread 0x7ffff37bf700 (LWP 29733)):
$5 = 148

Thread 8 (Thread 0x7ffff3fc0700 (LWP 29732)):
$6 = 121

Thread 7 (Thread 0x7ffff47c1700 (LWP 29731)):
$7 = 124

Thread 6 (Thread 0x7ffff4fc2700 (LWP 29730)):
$8 = 110

Thread 5 (Thread 0x7ffff57c3700 (LWP 29729)):
$9 = 112

Thread 4 (Thread 0x7ffff5fc4700 (LWP 29728)):
$10 = 112

Thread 3 (Thread 0x7ffff67c5700 (LWP 29727)):
$11 = 108

Thread 2 (Thread 0x7ffff6fc6700 (LWP 29726)):
$12 = 104

Thread 1 (Thread 0x7ffff7fca780 (LWP 29722)):
$13 = 100

-- 
Yao (齐尧)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.