Bug 10311 – gdb prints wrong value for variable updated from closure

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2013-06-08T16:39:00Z
Last change time
2015-02-18T03:39:21Z
Keywords
bounty, pull, symdeb
Assigned to
nobody
Creator
mk

Comments

Comment #0 by mk — 2013-06-08T16:39:51Z
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 by code — 2013-11-17T10:48:23Z
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 by mk — 2014-10-12T19:25:48Z
Comment #3 by github-bugzilla — 2014-11-08T22:08:14Z
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 by github-bugzilla — 2015-02-18T03:39:21Z