D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10311 - gdb prints wrong value for variable updated from closure
Summary: gdb prints wrong value for variable updated from closure
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: bounty, DebugInfo, pull
Depends on:
Blocks:
 
Reported: 2013-06-08 16:39 UTC by Martin Krejcirik
Modified: 2015-02-18 03:39 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Krejcirik 2013-06-08 16:39:51 UTC
import std.stdio;

void receive(void delegate(int n) dg)
{
    static int cnt;
    dg(++cnt);
}

void main()
{
    int loc1=10;
    int loc2=100;
    loc1++;
    receive(
        (int n) { loc2++; writeln("received ", n); }
    );
    writefln("loc: %d %d", loc1, loc2); /* prints 11 101 */
    /* run gdb, breakpoint at line 17
    (gdb) p loc1
    $1 = 11
    (gdb) p loc2
    $1 = 0
    */
}

dmd 2.063+, x86, linux, gdb 7.3, compiled dmd -gc

As you can see, variable loc2, which is incremented inside the function literal, shows wrong value by gdb print.

Quite annoying, I use code like this with std.concurrency and it's impossible to debug (without writef's);
Comment 1 Martin Nowak 2013-11-17 10:48:23 UTC
This is a little harder to solve. DMD has to put out the debug information which closure variables are captured by the delegate and how to access them. I'll look what DWARF has to offer.
Comment 2 Martin Krejcirik 2014-10-12 19:25:48 UTC
https://github.com/D-Programming-Language/dmd/pull/4063
Comment 3 github-bugzilla 2014-11-08 22:08:14 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7298c30d6fe45ec1f88c76d991af0c090b5d1a12
Fix Issue 10311 - GDB prints wrong value for variable updated from closure

https://github.com/D-Programming-Language/dmd/commit/dfb31be7edcec3a4210e06733f5f3843210514df
Merge pull request #4074 from tramker/bug10311

Fix Issue 10311 - GDB prints wrong value for variable updated from closure
Comment 4 github-bugzilla 2015-02-18 03:39:21 UTC
Commits pushed to 2.067 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7298c30d6fe45ec1f88c76d991af0c090b5d1a12
Fix Issue 10311 - GDB prints wrong value for variable updated from closure

https://github.com/D-Programming-Language/dmd/commit/dfb31be7edcec3a4210e06733f5f3843210514df
Merge pull request #4074 from tramker/bug10311