Author: martin
Date: 2007-11-19 17:31:14 -0500 (Mon, 19 Nov 2007)
New Revision: 89945
Modified:
trunk/debugger/ChangeLog
trunk/debugger/frontend/Interpreter.cs
trunk/debugger/frontend/Main.cs
trunk/debugger/test/testsuite/NUnit.cs
Log:
2007-11-19 Martin Baulig <[EMAIL PROTECTED]>
* frontend/Main.cs
(Main.RunInferiorMainLoop): New public method. This can be used
to run a main loop inside the nunit test suite.
* test/testsuite/NUnit.cs
(TestSuite.MainLoop): New public method; run an inferior main loop
from within the testsuite.
Modified: trunk/debugger/ChangeLog
===================================================================
--- trunk/debugger/ChangeLog 2007-11-19 22:03:56 UTC (rev 89944)
+++ trunk/debugger/ChangeLog 2007-11-19 22:31:14 UTC (rev 89945)
@@ -1,3 +1,13 @@
+2007-11-19 Martin Baulig <[EMAIL PROTECTED]>
+
+ * frontend/Main.cs
+ (Main.RunInferiorMainLoop): New public method. This can be used
+ to run a main loop inside the nunit test suite.
+
+ * test/testsuite/NUnit.cs
+ (TestSuite.MainLoop): New public method; run an inferior main loop
+ from within the testsuite.
+
2007-11-06 Martin Baulig <[EMAIL PROTECTED]>
* backend/arch/Architecture_I386.cs
Modified: trunk/debugger/frontend/Interpreter.cs
===================================================================
--- trunk/debugger/frontend/Interpreter.cs 2007-11-19 22:03:56 UTC (rev
89944)
+++ trunk/debugger/frontend/Interpreter.cs 2007-11-19 22:31:14 UTC (rev
89945)
@@ -33,6 +33,7 @@
StyleBase current_style;
bool is_interactive;
+ bool is_script;
int exit_code = 0;
int interrupt_level;
@@ -53,6 +54,7 @@
{
this.config = config;
this.is_interactive = is_interactive;
+ this.is_script = options.IsScript;
this.parser = new ExpressionParser (this);
this.session = new DebuggerSession (config, options,
"main", parser);
this.engine = new DebuggerEngine (this);
@@ -149,10 +151,12 @@
public bool IsInteractive {
get { return is_interactive; }
+ set { is_interactive = value; }
}
public bool IsScript {
- get { return Options.IsScript; }
+ get { return is_script; }
+ set { is_script = value; }
}
public DebuggerOptions Options {
Modified: trunk/debugger/frontend/Main.cs
===================================================================
--- trunk/debugger/frontend/Main.cs 2007-11-19 22:03:56 UTC (rev 89944)
+++ trunk/debugger/frontend/Main.cs 2007-11-19 22:31:14 UTC (rev 89945)
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.Configuration;
using ST = System.Threading;
using System.Runtime.InteropServices;
@@ -16,6 +17,7 @@
const string prompt = "(mdb) ";
int line = 0;
+ bool is_inferior_main;
ST.Thread command_thread;
ST.Thread main_thread;
@@ -49,6 +51,19 @@
command_thread.IsBackground = true;
}
+ public CommandLineInterpreter (Interpreter interpreter)
+ {
+ this.interpreter = interpreter;
+ this.engine = interpreter.DebuggerEngine;
+ parser = new LineParser (engine);
+
+ main_thread = new ST.Thread (new ST.ThreadStart
(main_thread_main));
+ main_thread.IsBackground = true;
+
+ command_thread = new ST.Thread (new ST.ThreadStart
(command_thread_main));
+ command_thread.IsBackground = true;
+ }
+
public void MainLoop ()
{
string s;
@@ -73,14 +88,18 @@
try {
interpreter.ClearInterrupt ();
MainLoop ();
+ if (is_inferior_main)
+ break;
} catch (ST.ThreadAbortException) {
ST.Thread.ResetAbort ();
}
}
}
- public void RunMainLoop ()
+ internal void RunMainLoop ()
{
+ is_inferior_main = false;
+
command_thread.Start ();
try {
@@ -100,13 +119,65 @@
}
}
+ public void RunInferiorMainLoop ()
+ {
+ is_inferior_main = true;
+
+ command_thread.Start ();
+
+ TextReader old_stdin = Console.In;
+ TextWriter old_stdout = Console.Out;
+ TextWriter old_stderr = Console.Error;
+
+ StreamReader stdin_reader = new StreamReader
(Console.OpenStandardInput ());
+
+ StreamWriter stdout_writer = new StreamWriter
(Console.OpenStandardOutput ());
+ stdout_writer.AutoFlush = true;
+
+ StreamWriter stderr_writer = new StreamWriter
(Console.OpenStandardError ());
+ stderr_writer.AutoFlush = true;
+
+ Console.SetIn (stdin_reader);
+ Console.SetOut (stdout_writer);
+ Console.SetError (stderr_writer);
+
+ bool old_is_script = interpreter.IsScript;
+ bool old_is_interactive = interpreter.IsInteractive;
+
+ interpreter.IsScript = false;
+ interpreter.IsInteractive = true;
+
+ Console.WriteLine ();
+
+ try {
+ main_thread.Start ();
+ main_thread.Join ();
+ } catch (ScriptingException ex) {
+ interpreter.Error (ex);
+ } catch (TargetException ex) {
+ interpreter.Error (ex);
+ } catch (Exception ex) {
+ interpreter.Error ("ERROR: {0}", ex);
+ } finally {
+ Console.WriteLine ();
+
+ Console.SetIn (old_stdin);
+ Console.SetOut (old_stdout);
+ Console.SetError (old_stderr);
+ interpreter.IsScript = old_is_script;
+ interpreter.IsInteractive = old_is_interactive;
+ }
+
+ command_thread.Abort ();
+ }
+
public string ReadInput (bool is_complete)
{
++line;
again:
string result;
string the_prompt = is_complete ? prompt : "... ";
- if (interpreter.Options.IsScript) {
+ if (interpreter.IsScript) {
Console.Write (the_prompt);
result = Console.ReadLine ();
if (result == null)
Modified: trunk/debugger/test/testsuite/NUnit.cs
===================================================================
--- trunk/debugger/test/testsuite/NUnit.cs 2007-11-19 22:03:56 UTC (rev
89944)
+++ trunk/debugger/test/testsuite/NUnit.cs 2007-11-19 22:31:14 UTC (rev
89945)
@@ -177,6 +177,8 @@
public override void Print (string message)
{
+ if (!IsScript)
+ base.Print (message);
}
}
@@ -775,6 +777,12 @@
AssertNoTargetOutput ();
}
+
+ public void MainLoop ()
+ {
+ CommandLineInterpreter cmdline = new
CommandLineInterpreter (interpreter);
+ cmdline.RunInferiorMainLoop ();
+ }
}
internal class LineReader
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches