Debugger problem

Jun 24, 2010 at 11:49 AM


As part of implementing a DLR language, I'm trying to compile the script in debug mode (so it can be debugged in VS like IronPython scripts)

I have my Debuginfo objects in the expression tree.

As suggested in an earlier post, I am compiling the lambda expression using CompileToMethod rather than lambda.compile.

but it fails with an exception when it returns from the Run method in the language specific ScriptScope .

Here is the Run method.

My ultimate aim is to write an IDE / debugger for the language so does anyone know of any examples / walkthroughs of implementing DebugContexts, TracePipelines etc ?  

Thanks in advance.

<font size="2">


</font>public override object Run(Scope scope)


DebugInfoGenerator dg = DebugInfoGenerator.CreatePdbGenerator();


if (_compiledLambda == null)


<font size="2">


_compiledLambda = Microsoft.Scripting.Generation.CompilerHelpers.CompileToMethod(_lambda, dg, true);

return _compiledLambda(_sdl, scope);





Jun 24, 2010 at 3:19 PM
How exectly does it fail? Can you include the exception message and trace and the tree you're compiling (the value of _lambda)?
Jun 25, 2010 at 8:48 AM

The exception is a System.MethodAccessException

The stack trace is

"lambda_method$1$1.lambda_method$1(DLR.SDL.SDL, System.Dynamic.IDynamicMetaObjectProvider)"

"   at lambda_method$1$1.lambda_method$1(SDL SDLRuntime, IDynamicMetaObjectProvider fileModule)\r\n  
at DLR.SDL.SDLScriptCode.Run(Scope scope) in C:\\Workspace\\DLR.SDL\\DLR.SDL\\SDLScriptCode.cs:line 61\r\n 
at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)\r\n   at Microsoft.Scripting.SourceUnit.Execute(Scope scope)\r\n
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)\r\n  
at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path, ScriptScope scope)\r\n  
at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path)\r\n  
at TestApp.Form1.runToolStripMenuItem_Click(Object sender, EventArgs e) in C:\\Workspace\\DLR.SDL\\TestApp\\Form1.cs:line 83"

The dump of the lambda \ expression tree is

".Lambda #Lambda1<Microsoft.Scripting.Utils.Func`3[DLR.SDL.SDL,System.Dynamic.IDynamicMetaObjectProvider,System.Object]>(\r\n
    DLR.SDL.SDL $SDLRuntime,\r\n
    System.Dynamic.IDynamicMetaObjectProvider $fileModule) {\r\n  .Block(System.Double $I) {\r\n
        $I = 0D;\r\n
        .DebugInfo(C:\\WORKSPACE\\DLR.SDL\\TESTAPP\\BIN\\DEBUG\\DEBUG.SDL: 2, 5 - 3, 8);\r\n
        .Block() {\r\n          $I = 1D;\r\n            .Loop  {\r\n                .Block() {\r\n
                    .If ($I > 5D) {\r\n                        .Goto #Label1 { }\r\n                    }
 .Else {\r\n                        .Default(System.Void)\r\n                    };
\r\n                    .DebugInfo(C:\\WORKSPACE\\DLR.SDL\\TESTAPP\\BIN\\DEBUG\\DEBUG.SDL: 16707566, 0 - 16707566, 0);\r\n
                    .Call System.Console.WriteLine((System.Object)$I);\r\n
                   $I += 1D\r\n                }\r\n            };\r\n            .Label\r\n
           .LabelTarget #Label1:\r\n        };\r\n        null\r\n    }\r\n}"

The same error occurs even if there are no DebugInfos in the expression tree.

Jun 25, 2010 at 4:35 PM

Are all members and types you access from the lambda public? (e.g. DLR.SDL.SDL class)

Jun 28, 2010 at 9:52 AM

Thanks Thomas

The SDL class declaration wasn't public ie

class SDL

When I made this public 

public class SDL

it worked. 

Jul 15, 2010 at 11:51 AM

What is the correct way of putting DebugInfos into loops ?.

I have a FOR loop and I want the debugger to stop when the loop is entered and each time it evaluates the loop condition

Expression.Assign(variable, <start value>)

The Loop body consists of

Expression.IfThen(Expression.GreatarThan(variable, <end value>), Expression.Goto(exitlabel))

..loop body..

Expression.AddAssign(variable, <step value>)

I have found the putting a DebugInfo - CloseDebugInfo arrount the Assign, Loop and exit label block gives me the behaviour I want.

However, when I coded a DO .. WHILE loop where the condition is evaluated at the end of the loop body, the debugger did not stop on the loop condition.

Isn't the correct way to put the debug block around the IfThen in the loop body ?

Also is it ok to have a CloseDebugInfo immediately after a DebugInfo ?  Again this seems to work but need to check.