CS-Script 3.20.0


Debugging

Debugging

If you need to debug your script firstly make sure you have a CLR compatible debugger installed. Almost any CLR IDE can be used as such a debugger. 

You can start debugging by using one of the these possible approaches: 

Using system CLR debugger

This is the simplest way of debugging scripts. The switch //x, if present as the last parameter in the command line, will always launch the "Select Just-In-Time Debugger" dialog to allow attaching to the script engine process. After appropriate debugger selected you can start debugging.  Press F10 ('Step over' command on most for the MS debuggers) and debugger will stop at the first line of the script.

Note: The Visual Studio debugging option "Enable Just My Code (Managed only)" must be turned on in order for the F10 key to step you to the first line of your script. If this option is turned off, you will need to manually load your script and set a breakpoint on the first line, then hit F5.

Alternatively right-click the script file in explorer and select "Debug Script". It will append //x to your script command automatically. The corresponding shell extension can be enabled/disabled from the configuration console.

Note: if you are debugging under .NET 1.1, you will need to open the source file (script) in the debugger manually, before pressing F10. The problem was addressed by MS in .NET2.0.

Changing default script debugger

If you want to change the debugger associated with the right-click context-menu you can do it from the configuration console. It will allow you to enable particular debugger a list of supported/available debuggers (see  CS-Script settings).




Tracing

Sometimes it is very useful to know runtime settings during the script execution. You can use /verbose command-line switch to to print this information into console output:
C:\cs-script\Samples>cscs.exe /verbose hello.cs arg1 arg2 arg3
C# Script execution engine. Version 2.3.0.0
Copyright (C) 2004-2008 Oleg Shilo.

> ----------------
  CurrentDirectory: C:\cs-script\Samples
  Executing: C:\cs-script\Samples\hello.cs
  Arguments:
    0 - arg1
    1 - arg2
    2 - arg3
  SearchDirectories:
    0 - C:\cs-script\Samples
    1 - C:\cs-script\Lib
    2 - C:\cs-script\Dev
    3 - C:\Documents and Settings\<user>\Local Settings\Temp\CSSCRIPT\Cache\-1582419629
> ----------------

Hello World!

Also it can be very useful to use Trace statements in your code in order to output some run-time information (/dbg switch must be used to enable tracing). Such technique is especially suitable for situations where you do not want to use a debugger. Just run your "trace listener" and it will catch all trace outputs from you script. You can download CLR "trace listener" applications from the Internet. In the example below TraceMonitor (http://www.szurgot.net/projects) was used as a "trace listener". Alternatively you can use DebugView from Sysinternals.

Example:

  1. Put a trace statement in the script code (e.g. System.Diagnostics.Trace.WriteLine("Hello World!"); in Hello.cs
  2. Run the "trace listener" (e.g. TraceMonitor.exe
  3. Run the script (e.g. Hello.cs)  
    cscs /dbg hello
     

This is the trace output caught by TraceMonitor.

 

See Also

Command-line interface | Script Library