none
Debugging Dynamic Code RRS feed

  • Question

  • I am writing a program that I wan't to be able to add script to.  To do this, I'm dynamically compiling the script and running it.  Is there any way to step through the code of the dynamic assembly?  There is an option to include debug information, but I don't know how to execute one line of code at a time.  Any help would be greatly appreciated!

    Thanks!
    -Nathan A

    Friday, April 24, 2009 10:30 PM

Answers

  • If you don't want to handle the parsing & compilation yourself there are a few other things you can do:

    - Mono has a project called CSharpRepl that allows you to use C# in an interactive shell
    - you can host IronPython or PowerShell

    HTH
    • Marked as answer by Zhi-Xin Ye Thursday, April 30, 2009 10:01 AM
    Tuesday, April 28, 2009 5:08 PM

All replies

  • I don't think debugging the script inside your program fits the job.Just extract it and test /debug it in a unit test.
    Saturday, April 25, 2009 2:17 AM
  • If you generate code in memory using Reflection.Emit it's also possible to emit debug symbols so that you're actually able to step through that code. (Read about debugging IL here )

    With expression trees it works as well - you just step into and analyze the expression.
    Saturday, April 25, 2009 7:08 AM
  • I know that using MarkSequencePoint, you can set debugging information that Visual Studio can use.  However, my end-users will not have visual studio, nor have access to the application source code.  I want to be able to debug the scripts they write from within the application, not from Visual Studio.  How do I step through IL code, once script line at a time?  And How do I obtain the points set by MarkSequencePoint?
    Monday, April 27, 2009 3:17 PM
  • mdbg sample (http://www.microsoft.com/downloads/details.aspx?FamilyID=38449a42-6b7a-4e28-80ce-c55645ab1310&displaylang=en) comes with source code. What kind of scripts do you want to support ?
    Monday, April 27, 2009 3:25 PM
  • Thanks, p.b.a.  I think that might be what I'm looking for.  I'll have to take a look.

    My goal is to provide a scripting environment to my users, using the C# language, but limited to a subset of commands.  I figured I'd write a class that provides the functions I want to support, and then attach the script as a DynamicMethod (or a dynamically compiled assembly) to that class.  However, I also want them to be able to step through the scripts that I write, one line at a time.  Pretty much a simplified version of a debugger.
    Monday, April 27, 2009 3:38 PM
  • If you don't want to handle the parsing & compilation yourself there are a few other things you can do:

    - Mono has a project called CSharpRepl that allows you to use C# in an interactive shell
    - you can host IronPython or PowerShell

    HTH
    • Marked as answer by Zhi-Xin Ye Thursday, April 30, 2009 10:01 AM
    Tuesday, April 28, 2009 5:08 PM