digitalmars.D.debugger - D globals in gdb
- Martin Krejcirik (4/4) Mar 31 2012 Hi all,
- Mihail Zenkov (5/8) Apr 02 2012 Try in gdb:
- Martin Krejcirik (6/8) Apr 02 2012 argh, the single quotes. Thanks, now it works if the global is
- simendsjo (4/13) Apr 02 2012 Unless it's shared or __gshared, every thread gets it's own copy. D
- Martin Krejcirik (16/18) Apr 02 2012 I know but the problem is, that gdb doesn't show the changed value of
- Mihail Zenkov (3/23) Apr 02 2012 Can't reproduce. With gdc and dmd-2.058 I have correct result.
- simendsjo (3/28) Apr 03 2012 I cannot reproduce this on dmd-2.059 trunk either.
- Martin Krejcirik (6/8) Apr 03 2012 Interesting. I'm using dmd 2.058 binary (.zip) on debian squeeze 32bit,
- Mihail Zenkov (10/19) Apr 04 2012 I also use dmd-2.058/linux/bin32/dmd.
- Martin Krejcirik (53/55) Apr 04 2012 I'm not sure what that should accomplish, as I wouldn't get the
- Mihail Zenkov (6/10) Apr 04 2012 DMD without any flags produce enough debug info to see global
- Martin Krejcirik (1/5) Apr 04 2012 Thanks, -gc works indeed.
Hi all, is there any way how to print a content of a D global variable in GDB ? -- mk
Mar 31 2012
On Saturday, 31 March 2012 at 14:58:48 UTC, Martin Krejcirik wrote:Hi all, is there any way how to print a content of a D global variable in GDB ?Try in gdb: p 'module_name.glob_var' P.S. You can also use autocomplete: p 'module_name.<TAB><TAB>
Apr 02 2012
Try in gdb: p 'module_name.glob_var'argh, the single quotes. Thanks, now it works if the global is declared shared. But if it isn't, print shows just the init value, no changed data. Any idea ? -- mk
Apr 02 2012
On Mon, 02 Apr 2012 19:36:27 +0200, Martin Krejcirik <mk-junk i-line.cz> wrote:Unless it's shared or __gshared, every thread gets it's own copy. D defaults to thread local storage (TLS).Try in gdb: p 'module_name.glob_var'argh, the single quotes. Thanks, now it works if the global is declared shared. But if it isn't, print shows just the init value, no changed data. Any idea ? -- mk
Apr 02 2012
On 2.4.2012 19:56, simendsjo wrote:Unless it's shared or __gshared, every thread gets it's own copy. D defaults to thread local storage (TLS).I know but the problem is, that gdb doesn't show the changed value of TLS variable. Example: import std.stdio; shared int shrgl = 1; int tlsgl = 10; void main() { writefln("%s %s", shrgl, tlsgl); // prints 1,10 shrgl++; tlsgl++; writefln("%s %s", shrgl, tlsgl); // prints 2,11 ==> gdb p 'tls.shrgl' ==> 2 ==> gdb p 'tls.tlslg' ==> 10 } -- mk
Apr 02 2012
On Monday, 2 April 2012 at 22:24:36 UTC, Martin Krejcirik wrote:On 2.4.2012 19:56, simendsjo wrote:Can't reproduce. With gdc and dmd-2.058 I have correct result. GDB-7.3Unless it's shared or __gshared, every thread gets it's own copy. D defaults to thread local storage (TLS).I know but the problem is, that gdb doesn't show the changed value of TLS variable. Example: import std.stdio; shared int shrgl = 1; int tlsgl = 10; void main() { writefln("%s %s", shrgl, tlsgl); // prints 1,10 shrgl++; tlsgl++; writefln("%s %s", shrgl, tlsgl); // prints 2,11 ==> gdb p 'tls.shrgl' ==> 2 ==> gdb p 'tls.tlslg' ==> 10 } -- mk
Apr 02 2012
On Tue, 03 Apr 2012 07:47:40 +0200, Mihail Zenkov <mihail.zenkov gmail.com> wrote:On Monday, 2 April 2012 at 22:24:36 UTC, Martin Krejcirik wrote:I cannot reproduce this on dmd-2.059 trunk either.On 2.4.2012 19:56, simendsjo wrote:Can't reproduce. With gdc and dmd-2.058 I have correct result. GDB-7.3Unless it's shared or __gshared, every thread gets it's own copy. D defaults to thread local storage (TLS).I know but the problem is, that gdb doesn't show the changed value of TLS variable. Example: import std.stdio; shared int shrgl = 1; int tlsgl = 10; void main() { writefln("%s %s", shrgl, tlsgl); // prints 1,10 shrgl++; tlsgl++; writefln("%s %s", shrgl, tlsgl); // prints 2,11 ==> gdb p 'tls.shrgl' ==> 2 ==> gdb p 'tls.tlslg' ==> 10 } -- mk
Apr 03 2012
On 3.4.2012 9:40, simendsjo wrote:Interesting. I'm using dmd 2.058 binary (.zip) on debian squeeze 32bit, gdb-minimal 7.3-1~bpo60+1 from backports. Even tried to compile gdb 7.4, but still the same behavior. -- mkCan't reproduce. With gdc and dmd-2.058 I have correct result. GDB-7.3I cannot reproduce this on dmd-2.059 trunk either.
Apr 03 2012
On Wednesday, 4 April 2012 at 01:23:34 UTC, Martin Krejcirik wrote:On 3.4.2012 9:40, simendsjo wrote:I also use dmd-2.058/linux/bin32/dmd. 1. Try compile without options, just 'dmd tls.d' 2. How you set break point in the end of program? Try add this hack: int *p = null; *p = 5; It segfault you program and you can check backtrace and variable state.Interesting. I'm using dmd 2.058 binary (.zip) on debian squeeze 32bit, gdb-minimal 7.3-1~bpo60+1 from backports. Even tried to compile gdb 7.4, but still the same behavior.Can't reproduce. With gdc and dmd-2.058 I have correct result. GDB-7.3I cannot reproduce this on dmd-2.059 trunk either.
Apr 04 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 thisbreakpoints 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.
Apr 04 2012
On Wednesday, 4 April 2012 at 10:45:00 UTC, Martin Krejcirik wrote:On Wednesday, 4 April 2012 at 07:01:39 UTC, Mihail Zenkov wrote:DMD without any flags produce enough debug info to see global variable. I reproduce this problem: only dmd with flag -g have it. Without this flag or with -gc gdb show correct value.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.
Apr 04 2012
DMD without any flags produce enough debug info to see global variable. I reproduce this problem: only dmd with flag -g have it. Without this flag or with -gc gdb show correct value.Thanks, -gc works indeed.
Apr 04 2012