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.