Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Commit

Permalink
2007-07-02 Atsushi Enomoto <atsushi@ximian.com>
Browse files Browse the repository at this point in the history
	* XsltDebugger.cs XsltDebuggerSession.cs :
	  some renaming. Added thread manager and got break commands working.

	* xslt-debugger.cs : added couple of commands.


svn path=/trunk/olive/; revision=81155
  • Loading branch information
atsushieno committed Jul 2, 2007
1 parent 947a6ae commit ac86bb7
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 22 deletions.
5 changes: 5 additions & 0 deletions class/Mono.XsltDebugger/Mono.XsltDebugger/ChangeLog
@@ -1,3 +1,8 @@
2007-07-02 Atsushi Enomoto <atsushi@ximian.com>

* XsltDebugger.cs XsltDebuggerSession.cs :
some renaming. Added thread manager and got break commands working.

2007-06-29 Atsushi Enomoto <atsushi@ximian.com> 2007-06-29 Atsushi Enomoto <atsushi@ximian.com>


* XsltExecuteEventArgs.cs XsltExecuteEventHandler.cs * XsltExecuteEventArgs.cs XsltExecuteEventHandler.cs
Expand Down
115 changes: 109 additions & 6 deletions class/Mono.XsltDebugger/Mono.XsltDebugger/XsltDebugger.cs
Expand Up @@ -2,13 +2,14 @@
using System.Collections; using System.Collections;
using System.IO; using System.IO;
using System.Security.Policy; using System.Security.Policy;
using System.Threading;
using System.Xml; using System.Xml;
using System.Xml.XPath; using System.Xml.XPath;
using System.Xml.Xsl; using System.Xml.Xsl;


namespace Mono.XsltDebugger namespace Mono.XsltDebugger
{ {
public class XsltDebugger public class XsltDebuggerService
{ {
XPathDocument style; XPathDocument style;
XPathDocument input; XPathDocument input;
Expand All @@ -17,11 +18,16 @@ public class XsltDebugger
ArrayList breakpoints = new ArrayList (); ArrayList breakpoints = new ArrayList ();
XsltDebuggerSession current_run; XsltDebuggerSession current_run;
XmlNamespaceManager nsmgr = new XmlNamespaceManager (new NameTable ()); XmlNamespaceManager nsmgr = new XmlNamespaceManager (new NameTable ());
ThreadManager thread_manager;


public XsltDebugger () public XsltDebuggerService ()
{ {
} }


public event EventHandler BreakpointMatched;

public event EventHandler TransformCompleted;

public XmlNamespaceManager NamespaceManager { public XmlNamespaceManager NamespaceManager {
get { return nsmgr; } get { return nsmgr; }
} }
Expand Down Expand Up @@ -90,21 +96,26 @@ public void Run ()
Abort (); Abort ();
} }
current_run = new XsltDebuggerSession (this); current_run = new XsltDebuggerSession (this);
thread_manager = new ThreadManager (current_run);


// set breakpoints // set breakpoints
current_run.Executed += OnExecute; current_run.Executed += OnExecute;


current_run.Run (); thread_manager.StartTransform ();
} }


public virtual void Interrupt () public virtual void Interrupt ()
{ {
throw new NotImplementedException (); if (thread_manager == null)
throw new XsltDebuggerException ("No active transformation to interrupt");
thread_manager.InterruptTransform ();
} }


public virtual void Resume () public virtual void Resume ()
{ {
throw new NotImplementedException (); if (thread_manager == null)
throw new XsltDebuggerException ("No active transformation to interrupt");
thread_manager.ResumeTransform ();
} }


public virtual void Abort () public virtual void Abort ()
Expand Down Expand Up @@ -140,13 +151,30 @@ protected internal virtual void Transform (XslTransform transform, XmlWriter wri
if (input == null) if (input == null)
throw new XsltDebuggerException ("Input document is not specified"); throw new XsltDebuggerException ("Input document is not specified");
transform.Transform (input, null, writer, xml_resolver); transform.Transform (input, null, writer, xml_resolver);

OnTransformCompleted ();
} }


// invoked inside transformation thread.
void OnExecute (object o, XsltExecuteEventArgs args) void OnExecute (object o, XsltExecuteEventArgs args)
{ {
if (!Break (args.Context)) if (!Break (args.Context))
return; return;
Console.WriteLine ("Match"); thread_manager.DispatchBreakpointMatch (o, args);
}

// invoked from ThreadManager notification thread
void OnBreakpointMatch (object o, XsltExecuteEventArgs args)
{
if (BreakpointMatched != null)
BreakpointMatched (o, args);
}

void OnTransformCompleted ()
{
if (TransformCompleted != null)
TransformCompleted (null, null);
thread_manager.Dispose ();
} }


bool Break (XsltDebuggerContext ctx) bool Break (XsltDebuggerContext ctx)
Expand All @@ -158,5 +186,80 @@ bool Break (XsltDebuggerContext ctx)
return true; return true;
return false; return false;
} }

class ThreadManager : IDisposable
{
XsltDebuggerSession session;
Thread run_thread, notify_thread;
ManualResetEvent notify_handle, trans_handle;

// used between notification thread and transformation thread
object event_sender;
XsltExecuteEventArgs event_args;

public ThreadManager (XsltDebuggerSession session)
{
this.session = session;
}

public void Dispose ()
{
if (notify_thread != null) {
notify_thread.Abort ();
notify_thread = null;
}
if (run_thread != null) {
run_thread.Abort ();
run_thread = null;
}
}

// It kicks the transform thread and returns.
public void StartTransform ()
{
notify_handle = new ManualResetEvent (false);
trans_handle = new ManualResetEvent (false);

run_thread = new Thread (delegate () {
try {
session.Run ();
} catch (ThreadAbortException) {
Thread.ResetAbort ();
}
});
notify_thread = new Thread (delegate () {
try {
while (true) {
notify_handle.Reset ();
notify_handle.WaitOne ();
session.Debugger.OnBreakpointMatch (event_sender, event_args);
}
} catch (ThreadAbortException) {
Thread.ResetAbort ();
}
});

notify_thread.Start ();
run_thread.Start ();
}

public void InterruptTransform ()
{
trans_handle.WaitOne ();
}

public void ResumeTransform ()
{
trans_handle.Set ();
}

public void DispatchBreakpointMatch (object o, XsltExecuteEventArgs args)
{
this.event_sender = o;
this.event_args = args;
notify_handle.Set ();
trans_handle.WaitOne ();
}
}
} }
} }
Expand Up @@ -11,19 +11,19 @@ namespace Mono.XsltDebugger
{ {
public class XsltDebuggerSession : IDisposable public class XsltDebuggerSession : IDisposable
{ {
XsltDebugger debugger; XsltDebuggerService debugger;
XsltInjector injector; XsltInjector injector;
XslTransform transform; XslTransform transform;
XmlNodeWriter output; XmlNodeWriter output;
Hashtable custom_cache; Hashtable custom_cache;


public XsltDebuggerSession (XsltDebugger debugger) public XsltDebuggerSession (XsltDebuggerService debugger)
{ {
this.debugger = debugger; this.debugger = debugger;
Init (); Init ();
} }


public XsltDebugger Debugger { public XsltDebuggerService Debugger {
get { return debugger; } get { return debugger; }
} }


Expand All @@ -46,6 +46,7 @@ public void Dispose ()
output = null; output = null;
} }


// It is indicated by ThreadManager.StartDebug().
internal void Run () internal void Run ()
{ {
custom_cache = new Hashtable (); custom_cache = new Hashtable ();
Expand Down
4 changes: 4 additions & 0 deletions tools/xslt-debugger/ChangeLog
@@ -1,3 +1,7 @@
2007-07-02 Atsushi Enomoto <atsushi@ximian.com>

* xslt-debugger.cs : added couple of commands.

2007-06-29 Atsushi Enomoto <atsushi@ximian.com> 2007-06-29 Atsushi Enomoto <atsushi@ximian.com>


* Makefile * Makefile
Expand Down

0 comments on commit ac86bb7

Please sign in to comment.