PaxScripter demo application written in C# which illustrates debug capabilities.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using PaxScript.Net;
namespace DebugApp
{
public class WinForm : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.RichTextBox rtbScript;
private System.Windows.Forms.Button btnReset;
private System.Windows.Forms.Button btnRun;
private System.Windows.Forms.Button btnTraceInto;
private System.Windows.Forms.Button btnStepOver;
private System.Windows.Forms.Button btnAddBreakpoint;
private System.Windows.Forms.Button btnRemoveBreakpoint;
private PaxScript.Net.PaxScripter paxScripter1;
private System.Windows.Forms.RichTextBox rtbState;
public WinForm()
{
InitializeComponent();
ShowInfo(paxScripter1, paxScripter1.State);
}
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.rtbScript = new System.Windows.Forms.RichTextBox();
this.btnReset = new System.Windows.Forms.Button();
this.btnRun = new System.Windows.Forms.Button();
this.btnTraceInto = new System.Windows.Forms.Button();
this.btnStepOver = new System.Windows.Forms.Button();
this.btnAddBreakpoint = new System.Windows.Forms.Button();
this.btnRemoveBreakpoint = new System.Windows.Forms.Button();
this.paxScripter1 = new PaxScript.Net.PaxScripter(this.components);
this.rtbState = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// rtbScript
//
this.rtbScript.Location = new System.Drawing.Point(160, 8);
this.rtbScript.Name = "rtbScript";
this.rtbScript.Size = new System.Drawing.Size(280, 200);
this.rtbScript.TabIndex = 0;
this.rtbScript.Text = @"using System;class TestFactorial{ public static long Factorial (long number) { if (number == 0) return 1; else return (number * Factorial (number - 1)); } public static void Main() { Console.WriteLine(""3 factorial is {0}"", Factorial(3)); }}";
//
// btnReset
//
this.btnReset.Location = new System.Drawing.Point(24, 24);
this.btnReset.Name = "btnReset";
this.btnReset.Size = new System.Drawing.Size(112, 23);
this.btnReset.TabIndex = 1;
this.btnReset.Text = "Reset";
this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
//
// btnRun
//
this.btnRun.Location = new System.Drawing.Point(24, 56);
this.btnRun.Name = "btnRun";
this.btnRun.Size = new System.Drawing.Size(112, 23);
this.btnRun.TabIndex = 2;
this.btnRun.Text = "Run";
this.btnRun.Click += new System.EventHandler(this.btnRun_Click);
//
// btnTraceInto
//
this.btnTraceInto.Location = new System.Drawing.Point(24, 88);
this.btnTraceInto.Name = "btnTraceInto";
this.btnTraceInto.Size = new System.Drawing.Size(112, 23);
this.btnTraceInto.TabIndex = 3;
this.btnTraceInto.Text = "Trace Into";
this.btnTraceInto.Click += new System.EventHandler(this.btnTraceInto_Click);
//
// btnStepOver
//
this.btnStepOver.Location = new System.Drawing.Point(24, 120);
this.btnStepOver.Name = "btnStepOver";
this.btnStepOver.Size = new System.Drawing.Size(112, 23);
this.btnStepOver.TabIndex = 4;
this.btnStepOver.Text = "Step Over";
this.btnStepOver.Click += new System.EventHandler(this.btnStepOver_Click);
//
// btnAddBreakpoint
//
this.btnAddBreakpoint.Location = new System.Drawing.Point(24, 152);
this.btnAddBreakpoint.Name = "btnAddBreakpoint";
this.btnAddBreakpoint.Size = new System.Drawing.Size(112, 23);
this.btnAddBreakpoint.TabIndex = 5;
this.btnAddBreakpoint.Text = "Add Breakpoint";
this.btnAddBreakpoint.Click += new System.EventHandler(this.btnAddBreakpoint_Click);
//
// btnRemoveBreakpoint
//
this.btnRemoveBreakpoint.Location = new System.Drawing.Point(24, 184);
this.btnRemoveBreakpoint.Name = "btnRemoveBreakpoint";
this.btnRemoveBreakpoint.Size = new System.Drawing.Size(112, 23);
this.btnRemoveBreakpoint.TabIndex = 6;
this.btnRemoveBreakpoint.Text = "Remove Breakpoint";
this.btnRemoveBreakpoint.Click += new System.EventHandler(this.btnRemoveBreakpoint_Click);
//
// paxScripter1
//
this.paxScripter1.OnChangeState += new PaxScript.Net.ChangeStateHandler(this.paxScripter1_OnChangeState);
//
// rtbState
//
this.rtbState.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.rtbState.Location = new System.Drawing.Point(8, 216);
this.rtbState.Name = "rtbState";
this.rtbState.Size = new System.Drawing.Size(432, 96);
this.rtbState.TabIndex = 9;
this.rtbState.Text = "";
//
// WinForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(448, 326);
this.Controls.Add(this.rtbState);
this.Controls.Add(this.btnRemoveBreakpoint);
this.Controls.Add(this.btnAddBreakpoint);
this.Controls.Add(this.btnStepOver);
this.Controls.Add(this.btnTraceInto);
this.Controls.Add(this.btnRun);
this.Controls.Add(this.btnReset);
this.Controls.Add(this.rtbScript);
this.Name = "WinForm";
this.Text = "WinForm";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new WinForm());
}
private void btnReset_Click(object sender, System.EventArgs e)
{
paxScripter1.Reset();
}
private void btnRun_Click(object sender, System.EventArgs e)
{
paxScripter1.Run(RunMode.Run);
}
private void btnTraceInto_Click(object sender, System.EventArgs e)
{
paxScripter1.Run(RunMode.TraceInto);
}
private void btnStepOver_Click(object sender, System.EventArgs e)
{
paxScripter1.Run(RunMode.StepOver);
}
private void btnAddBreakpoint_Click(object sender, System.EventArgs e)
{
paxScripter1.AddBreakpoint("1", 5);
ShowInfo(paxScripter1, paxScripter1.State);
}
private void btnRemoveBreakpoint_Click(object sender, System.EventArgs e)
{
paxScripter1.RemoveAllBreakpoints();
ShowInfo(paxScripter1, paxScripter1.State);
}
private void ShowInfo(PaxScript.Net.PaxScripter sender, ScripterState new_state)
{
rtbState.Text = "State: " + new_state.ToString();
rtbState.Text += "\nModule: " + sender.CurrentModule;
rtbState.Text += "\nLine " + sender.CurrentLineNumber.ToString() +
" : " + sender.CurrentLine;
object v = null;
if (new_state == ScripterState.Paused)
{
v = sender.Eval("number");
sender.DiscardError();
}
if (v == null)
rtbState.Text += "\nnumber = null";
else
rtbState.Text += "\nnumber = " + v.ToString();
rtbState.Text += "\nCall stack:";
foreach (CallStackRec csr in sender.Call_Stack)
{
rtbState.Text += "\n" + csr.CallView + " at line " + csr.LineNumber;
}
rtbState.Text += "\nBreakpoints:";
foreach (Breakpoint bp in sender.Breakpoint_List)
{
rtbState.Text += "\nBreakpoint at line " + bp.LineNumber +
", Activated = " + bp.Activated;
}
}
private void paxScripter1_OnChangeState(PaxScript.Net.PaxScripter sender, PaxScript.Net.ChangeStateEventArgs e)
{
if (!sender.HasErrors)
ShowInfo(sender, e.NewState);
if (e.NewState == ScripterState.Error)
{
MessageBox.Show("Error: " + sender.Error_List[0].Message);
}
else if (e.OldState == ScripterState.Init)
{
sender.AddModule("1");
sender.AddCode("1", rtbScript.Text);
}
}
}
}
Copyright © 1999-2013
VIRT Laboratory. All rights reserved.