aBothe / Mono-D

D Add-In for MonoDevelop
http://wiki.dlang.org/Mono-D
Other
113 stars 26 forks source link

Debugger: variables in nested functions won't display values #329

Open AthanasiusOfAlex opened 11 years ago

AthanasiusOfAlex commented 11 years ago

Here is an interesting one for the debugger:

In a nested function, some variables won't display any values. Try the following simple code, and put the break point inside the nested function:

module main;

import std.stdio;

void main(string[] args)
{
    // Here is the nested function I am testing:
    long nestedfunc(long one, ulong two,
                    string someString, string[] listOfStrings){
        long unum = one;
        ulong duo = two;
        ulong undeviginti = 19;
        float quattuorVirgulaVigintiTria = 4.23;

        string textusReceptus = someString;

        return (unum + duo + textusReceptus.length -
                undeviginti + listOfStrings.length)
                * 10000 +
                cast(uint)(quattuorVirgulaVigintiTria * 100);
    }

    long returnValue = nestedfunc(4, 5,
                        "something to pass to the function",
                        ["a", "few", "choice", "words"]);

    writeln(returnValue);
}

I tried various types and tried assigning variables within the nested function. It seems that strings and arrays do OK, but more primitive variables do not. Where the value should appear (in the Locals or Watch windows), instead there is a message in red: "Can't read primitive 'name-of-variable'."

Thanks for the help!

aBothe commented 11 years ago

Yeah, it's probably because of the nesting and mis-scoping -- it tries to scope the outer function, and simply doesn't know that there's such a separated inner block.

aBothe commented 11 years ago

Okay, apparently, it's not my direct fault: The debugger just spits out gdb exception - couldn't read '(void[])nestedParam': Internal error:this' is not an aggregate`` - whereas the latter part comes from gdb directly. Nice. Edit: This is a 10 years old bug. I just started gdb manually, breakpointed at some nested method and tried to resolve some locals without any (void[]) in front of the parameter name..only then it worked, at no time else.