Bug 1582505 - gdb can't display thread-local variables in F28
Summary: gdb can't display thread-local variables in F28
Keywords:
Status: CLOSED WORKSFORME
Alias: None
Product: Fedora
Classification: Fedora
Component: gdb
Version: 28
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Sergio Durigan Junior
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-05-25 12:29 UTC by Robert O'Callahan
Modified: 2019-05-13 13:18 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-06-04 12:08:40 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Robert O'Callahan 2018-05-25 12:29:43 UTC
Description of problem:
gdb isn't able to read the values of C __thread variables.

Version-Release number of selected component (if applicable):
GNU gdb (GDB) Fedora 8.1-15.fc28

How reproducible:
100%

Steps to Reproduce:
1. Copy this program to /tmp/test.c:
#include <stdio.h>
__thread int tlsvar;
int main(void) {
  tlsvar = 1;
  printf("%d\n", tlsvar);
  return 0;
}

2. Do the following commands:
gcc -o /tmp/test -g /tmp/test.c"
gdb /tmp/test
break main
run
print tlsvar

Actual results:
Cannot find thread-local storage for process ..., executable file /tmp/test:
Cannot find thread-local variables on this target

Expected results:
$1 = 1

Comment 1 Phil Muldoon 2018-05-25 14:01:19 UTC
The short interim solution is to compile with -pthread (even though in that example you don't need to). GDB needs symbols in libpthread to access thread local storage (so the inferior program must be linked with libpthread). In this case, this is an unfortunate outcome.

There's a solution being worked on (not by me) out there:

https://sourceware.org/ml/libc-alpha/2017-09/msg00543.html

Comment 2 Robert O'Callahan 2018-05-25 22:19:19 UTC
Thanks! Unfortunately compiling with -pthread does not fix the problem. Amend the first line of step 2 to

gcc -pthread -o ~/tmp/test -g ~/tmp/test.c

My original testcase actually used -pthread and I forgot to add that when I reduced. Also, I just upgraded from F27 and my original testcase worked there. The above testcase works in Ubuntu 16.04 and I'm pretty confident would work in F27, though now I've upgraded, testing F27 again would be a pain.

Comment 3 Pedro Alves 2018-06-04 11:56:12 UTC
Curious.  I'm still on F27, and the testcase works for me with -pthread, and does not work without -pthread, which is what I expected.  Without -pthread, GDB can't  use libthread_db.so to get at the TLS variable's address.  I get the same result (fails with -pthread) with current gdb master on F27.  This seems to suggest that something changed in gcc or glibc.

Comment 4 Pedro Alves 2018-06-04 12:03:46 UTC
Same result (works with -pthread) with "gcc version 8.0.1 20180423 (experimental) (GCC)" built from sources, on F27.

Comment 5 Pedro Alves 2018-06-04 12:05:16 UTC
What does "ldd ~/tmp/test" say on F28 (with -pthread) ?

Comment 6 Robert O'Callahan 2018-06-04 12:08:40 UTC
It's actually working on my system now. The corresponding rr test is also working. Perhaps something got updated in the last couple of weeks.


Note You need to log in before you can comment on or make changes to this bug.