Christmas request! VD closure debugging

Rainer Schuetze r.sagitario at gmx.de
Mon Dec 17 07:41:02 UTC 2018



On 16/12/2018 05:13, Michelle Long wrote:
> And, of course, it is not working in my production code when a simple
> example works:
> 
> auto foo()
> {
>     int x = 0;
>     auto bar()
>     {
>         int y = 0;
>         x++;
> 
>         y++;
>     }
> 
>     bar();
> }
> 
> 
> int main()
> {
> 
> foo();
> 
> 
>     return 0;
> }
> 
> 
> My code is more like
> 
> class X
> {
>     auto foo()
>     {
>         int x = 0;
>         auto bar()
>         {
>             int y = 0;
>             x++;
> 
>             y++;
>         }
> 
>         bar();
>     }
> }
> 
> int main()
> {
> 
>     X x = new X();
>     x.foo();
> 
> 
>     return 0;
> }
> 
> 
> which when done gives a crap value for x in the auto's and watch. 

Should be fixed by https://github.com/dlang/dmd/pull/9092

> (in my
> production code the variables are not found)

The debug info for captured variables is not generated for OMF object
files as it crashes optlink. You have to use COFF output.

> 
> 
> Note that making foo static (and changing to X.foo()) works...
> 
> My my production code isn't showing any of the variables is beyond me
> since it is pretty much the above case almost exactly, in fact, here is
> the code structure:
> 
> class A { }
> 
> class X
> {
>     A[] a;
> 
>     static auto foo(string s, bool b = false)
>     {
> 
>         int x = 0;
> 
>         struct v;
> 
>         auto r(T, bool s = true)(int l = 1)
>         {
>             static if (s)
>             {
>                 ulong q = 0;
>                 x += T.sizeof*l;
>             }
> 
>             return x;
>         }
> 
>         r!(char, true)();
> 
>     }
> }
> 
> int main()
> {
> 
>     X x = new X();
>     X.foo("asdf");
> 
> 
>     return 0;
> }
> 
> which does show X just fine(I simplified the code above removing all
> "unnecessary" things but seems it isn't so unnecessary.

This seems to work with the patch above, too.

Sometimes I don't see all captured variables listed as locals, will have
to investigate it.

> 
> Building under x64 does work although the auto's are not shown... I can
> still watch the (global)variables and they give the correct values.
> 
> So, this offers a solution until the issue can be sorted. As long as I
> can get at the globals then I can properly debug.  Why my code is having
> issues with the x86 build, but when reduced works fine, but also works
> partially with the x64 build is beyond me...
> 
> Thanks...
> 
> 
> 


More information about the Digitalmars-d-ide mailing list