Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the .debugger classes #3

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .nuget/packages.config

This file was deleted.

118 changes: 118 additions & 0 deletions Tests/Yodii.Script.Debugger.Tests/BasicDebuggerSupport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Yodii.Script.Debugger.Tests
{
[TestFixture]
class BasicDebuggerSupport
{
[TestCase("let a;", 0)]
[TestCase( "let a=0;",1 )]
[TestCase( "let a,b;a=5; b=2; ", 2 )]
[TestCase( "let a,b,c;a=5; b=2;c= a+b ", 4 )]
public void check_if_breakpoints_count_matches(string script, int count)
{
ScriptEngine engine = new ScriptEngine();

Expr exp = ExprAnalyser.AnalyseString( script );

BreakableVisitor bkv = new BreakableVisitor();
bkv.VisitExpr( exp );
Assert.That( bkv.BreakableExprs.Count, Is.EqualTo(count) );
}

[Test]
public void add_breakpoint_inside_parsed_script()
{
ScriptEngine engine = new ScriptEngine();
string script = @"let a,b,c;
a=5;
b=2;
c= a+b ";

Expr exp = ExprAnalyser.AnalyseString( script );

BreakableVisitor bkv = new BreakableVisitor();
bkv.VisitExpr( exp );
Assert.That( bkv.BreakableExprs.Count, Is.EqualTo(4) );
engine.Breakpoints.AddBreakpoint( bkv.BreakableExprs[3] );

using( var r2 = engine.Execute( exp ) )
{
int nbStep = 0;
while( r2.Status == ScriptEngineStatus.Breakpoint )
{
Assert.That( (r2.Status & ScriptEngineStatus.IsPending), Is.EqualTo( ScriptEngineStatus.IsPending ) );
nbStep++;
r2.Continue();
}

Assert.That( r2.Status, Is.EqualTo( ScriptEngineStatus.IsFinished ) );
Assert.That( nbStep, Is.EqualTo( 1 ) );
}
}
[Test]
public void check_the_debuggers_components()
{
ScriptEngineDebugger engine = new ScriptEngineDebugger(new GlobalContext());
string script = @"let a,b,c;
a=5;
b=2;
c= a+b ";

Expr exp = ExprAnalyser.AnalyseString( script );

BreakableVisitor bkv = new BreakableVisitor();
bkv.VisitExpr( exp );
Assert.That( bkv.BreakableExprs.Count, Is.EqualTo( 4 ) );
engine.Breakpoints.AddBreakpoint( bkv.BreakableExprs[3] );

using( var r2 = engine.Execute( exp ) )
{
Assert.That( engine.ScopeManager.Vars.Count, Is.EqualTo( 3 ) );

r2.Continue();
}
}
[Test]
public void show_vars_from_closure()
{
ScriptEngineDebugger engine = new ScriptEngineDebugger(new GlobalContext());
string script = @"let a = 0;
let b = 1;
function testfunc(){
let b = 2;
a = 'test';
a = 5;
}
testfunc();
let c = 0;
";

Expr exp = ExprAnalyser.AnalyseString( script );

BreakableVisitor bkv = new BreakableVisitor();
bkv.VisitExpr( exp );
engine.Breakpoints.AddBreakpoint( bkv.BreakableExprs[5] );

using( var r2 = engine.Execute( exp ) )
{
Assert.That( engine.ScopeManager.FindByName( "a" ).Object.ToString(), Is.EqualTo( "test" ) );
Assert.That( engine.ScopeManager.FindByName( "b" ).Object.ToDouble(), Is.EqualTo( 2.0 ) );
r2.Continue();
}
engine.Breakpoints.RemoveBreakpoint( bkv.BreakableExprs[5] );
engine.Breakpoints.AddBreakpoint( bkv.BreakableExprs[7] );
using( var r2 = engine.Execute( exp ) )
{
Assert.That( engine.ScopeManager.FindByName( "a" ).Object.ToDouble(), Is.EqualTo( 5.0 ) );
Assert.That( engine.ScopeManager.FindByName( "b" ).Object.ToDouble(), Is.EqualTo( 1.0 ) );
r2.Continue();
}
}
}
}
47 changes: 47 additions & 0 deletions Tests/Yodii.Script.Debugger.Tests/DynamicalVariableEdition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;

namespace Yodii.Script.Debugger.Tests
{
[TestFixture]
class DynamicalVariableEdition
{
[Test]
public void Check_if_variables_can_be_edited_on_breakpoint()
{
ScriptEngineDebugger engine = new ScriptEngineDebugger(new GlobalContext());

string script = @"let a,b,c;
a=5;
b=2;
c= a+b;
let d=0;";

Expr exp = ExprAnalyser.AnalyseString( script );

BreakableVisitor bkv = new BreakableVisitor();
bkv.VisitExpr( exp );
engine.Breakpoints.AddBreakpoint( bkv.BreakableExprs[3] );
engine.Breakpoints.AddBreakpoint( bkv.BreakableExprs[4] );

using( var r2 = engine.Execute( exp ) )
{

RefRuntimeObj O = engine.ScopeManager.FindByName( "b" ).Object;
O.Value = new JSEvalNumber( 5.0 );
Assert.That( engine.ScopeManager.FindByName( "b" ).Object.Value.ToDouble(), Is.EqualTo( 5.0 ) );

r2.Continue();

Assert.That( engine.ScopeManager.FindByName( "c" ).Object.Value.ToDouble(), Is.EqualTo( 10.0 ) );

r2.Continue();

}
}
}
}
36 changes: 36 additions & 0 deletions Tests/Yodii.Script.Debugger.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Yodii.Script.Debugger.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Yodii.Script.Debugger.Tests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("18c42bd6-56a2-4d19-8569-5093795b492b")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{04FE4BA4-34A8-4987-A3B5-E14B963F6BE7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Yodii.Script.Debugger.Tests</RootNamespace>
<AssemblyName>Yodii.Script.Debugger.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BasicDebuggerSupport.cs" />
<Compile Include="DynamicalVariableEdition.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Yodii.Script.Debugger\Yodii.Script.Debugger.csproj">
<Project>{576274a5-5fbf-4803-91db-96effcf4159a}</Project>
<Name>Yodii.Script.Debugger</Name>
</ProjectReference>
<ProjectReference Include="..\..\Yodii.Script\Yodii.Script.csproj">
<Project>{388870e4-cf4e-45b5-bbec-ec6fad2e7490}</Project>
<Name>Yodii.Script</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
4 changes: 4 additions & 0 deletions Tests/Yodii.Script.Debugger.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.4" targetFramework="net451" />
</packages>
1 change: 0 additions & 1 deletion Tests/Yodii.Script.Tests/Yodii.Script.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<StartAction>Program</StartAction>
Expand Down
16 changes: 16 additions & 0 deletions Yodii-Script.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4BFD09D0-AAD1-4343-B7E2-89A891379139}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yodii.Script.Debugger", "Yodii.Script.Debugger\Yodii.Script.Debugger.csproj", "{576274A5-5FBF-4803-91DB-96EFFCF4159A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yodii.Script.Debugger.Tests", "Tests\Yodii.Script.Debugger.Tests\Yodii.Script.Debugger.Tests.csproj", "{04FE4BA4-34A8-4987-A3B5-E14B963F6BE7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,11 +41,20 @@ Global
{270354A6-A0EE-4C0F-BF23-D5CAC4121DEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{270354A6-A0EE-4C0F-BF23-D5CAC4121DEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{270354A6-A0EE-4C0F-BF23-D5CAC4121DEC}.Release|Any CPU.Build.0 = Release|Any CPU
{576274A5-5FBF-4803-91DB-96EFFCF4159A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{576274A5-5FBF-4803-91DB-96EFFCF4159A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{576274A5-5FBF-4803-91DB-96EFFCF4159A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{576274A5-5FBF-4803-91DB-96EFFCF4159A}.Release|Any CPU.Build.0 = Release|Any CPU
{04FE4BA4-34A8-4987-A3B5-E14B963F6BE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04FE4BA4-34A8-4987-A3B5-E14B963F6BE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04FE4BA4-34A8-4987-A3B5-E14B963F6BE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04FE4BA4-34A8-4987-A3B5-E14B963F6BE7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{270354A6-A0EE-4C0F-BF23-D5CAC4121DEC} = {0453B444-D4D8-402E-A2CB-B5E0821B071C}
{04FE4BA4-34A8-4987-A3B5-E14B963F6BE7} = {0453B444-D4D8-402E-A2CB-B5E0821B071C}
EndGlobalSection
EndGlobal
31 changes: 31 additions & 0 deletions Yodii.Script.Debugger/BreakableVisitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yodii.Script.Debugger
{
/// <summary>
/// Basic class parsing an <see cref="Expr"/> into a list of atomic breakable <see cref="Expr"/>
/// </summary>
public class BreakableVisitor : ExprVisitor
{
readonly List<Expr> _breakableExprs = new List<Expr>();
/// <summary>
/// Reads the full AST, to find all breakable atomic <see cref="Expr"/>
/// </summary>
/// <param name="e">An Expr to parse as Breakables Exprs</param>
/// <returns></returns>
public override Expr VisitExpr( Expr e )
{
Console.WriteLine( e.ToString() );
if( e.IsBreakable ) _breakableExprs.Add( e );
return base.VisitExpr( e );
}
public IReadOnlyList<Expr> BreakableExprs
{
get { return _breakableExprs; }
}
}
}
12 changes: 12 additions & 0 deletions Yodii.Script.Debugger/BreakpointManagerDebugger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yodii.Script.Debugger
{
class BreakPointManagerDebugger : BreakpointManager
{
}
}
Loading