D globals in gdb
Martin Krejcirik
mk-junk at i-line.cz
Wed Apr 4 03:44:59 PDT 2012
On Wednesday, 4 April 2012 at 07:01:39 UTC, Mihail Zenkov wrote:
> 1. Try compile without options, just 'dmd tls.d'
I'm not sure what that should accomplish, as I wouldn't get the
debug info.
> 2. How you set break point in the end of program? Try add this
breakpoints are ok. In fact everything is ok, except it looks
like that gdb is accessing (in print, set var) a "shadow" non-tls
copy of my tls variable.
Consider this example:
import std.stdio;
__gshared int shrvar = 1;
int tlsvar = 5;
void main()
{
writefln("%d %d | %#x %#x", shrvar, tlsvar, &shrvar, &tlsvar);
// 1, 5
shrvar++; tlsvar++;
writefln("%d %d | %#x %#x", shrvar, tlsvar, &shrvar, &tlsvar);
// gdb p 'tls.tlsvar' = 5
}
Now running GDB:
(gdb) b 10
Breakpoint 1 at 0x806b7ba: file tls.d, line 10.
(gdb) r
Starting program: /home/mk/dmd/tls
[Thread debugging using libthread_db enabled]
Using host libthread_db library
"/lib/i686/cmov/libthread_db.so.1".
1 5 | 0x808f308 0xf7e466c8
Breakpoint 1, D main () at tls.d:10
10 writefln("%d %d | %#x %#x", shrvar, tlsvar, &shrvar,
&tlsvar); // gdb p 'tls.tlslg' = 5
(gdb) n
2 6 | 0x808f308 0xf7e466c8
11 }
(gdb) info address tls.shrvar
Symbol "tls.shrvar()" is static storage at address 0x808f308.
(gdb) info address tls.tlsvar
Symbol "tls.tlsvar()" is static storage at address 0x808f004.
(gdb) x 0xf7e466c8
0xf7e466c8: 0x00000006
(gdb) x 0x808f004
0x808f004: 0x00000005
As you can see, the address of tlsvar in gdb is different then
the one from writeln.
Trying similar C program in gdb, it correctly recognize the TLS
variable:
(gdb) info address shrvar
Symbol "shrvar" is static storage at address 0x8049658.
(gdb) info address tlsvar
Symbol "tlsvar" is a thread-local variable at offset 0x0 in the
thread-local storage for `/home/mk/dmd/glob'.
I read somwhere that it is necessary to link libpthread, not sure
if that applies to DMD too, but it doesn't seem to have any
effect anyway.
More information about the Digitalmars-d-debugger
mailing list