Browse Source

Fixed debugger test

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@848 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 20 years ago
parent
commit
3f22a40553
  1. 19
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs
  2. 13
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs
  3. 17
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs
  4. 7
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs
  5. 3
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs
  6. 3
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj
  7. 10
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs

19
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/MTA2STA.cs

@ -19,6 +19,7 @@ namespace Debugger @@ -19,6 +19,7 @@ namespace Debugger
{
Form hiddenForm;
IntPtr hiddenFormHandle;
AutoResetEvent staPump = new AutoResetEvent(false);
public MTA2STA()
{
@ -32,6 +33,22 @@ namespace Debugger @@ -32,6 +33,22 @@ namespace Debugger
//System.Console.WriteLine("MTA2STA: " + msg);
}
/// <summary>
/// SoftWait waits for the given WaitHandle and allows processing of CallInSTA during the wait
/// </summary>
public void SoftWait(WaitHandle waitFor)
{
if (System.Threading.Thread.CurrentThread.GetApartmentState() == System.Threading.ApartmentState.STA) {
staPump.Set();
// Wait until the waitFor handle is set
while(WaitHandle.WaitAny(new WaitHandle[] {staPump, waitFor}) != 1) {
Application.DoEvents();
}
} else {
waitFor.WaitOne();
}
}
// Try to avoid this since it will catch exceptions and it is slow
public object CallInSTA(object targetObject, string functionName, object[] functionParameters)
{
@ -55,6 +72,8 @@ namespace Debugger @@ -55,6 +72,8 @@ namespace Debugger
if (hiddenForm.InvokeRequired == true) {
// Warrning: BeginInvoke will not pass exceptions if you do not use MethodInvoker delegate!
IAsyncResult async = hiddenForm.BeginInvoke(callDelegate);
// Pump a locked STA thread
staPump.Set();
// Give it 1 second to run
if (!async.AsyncWaitHandle.WaitOne(1000, true)) {
// Abandon the call if possible

13
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallbackProxy.cs

@ -27,7 +27,6 @@ namespace Debugger @@ -27,7 +27,6 @@ namespace Debugger
{
NDebugger debugger;
ManagedCallback realCallback;
MTA2STA mta2sta;
public NDebugger Debugger {
get {
@ -39,22 +38,16 @@ namespace Debugger @@ -39,22 +38,16 @@ namespace Debugger
{
this.debugger = realCallback.Debugger;
this.realCallback = realCallback;
mta2sta = new MTA2STA();
}
private void CallbackReceived (string function, object[] parameters)
void Call(MethodInvoker callback)
{
if (debugger.RequiredApartmentState == ApartmentState.STA) {
mta2sta.CallInSTA(realCallback, function, parameters);
debugger.MTA2STA.CallInSTA(callback);
} else {
MTA2STA.InvokeMethod(realCallback, function, parameters);
callback();
}
}
void Call(MethodInvoker d)
{
mta2sta.CallInSTA(d);
}
public void StepComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pStepper, Debugger.Interop.CorDebug.CorDebugStepReason reason)
{

17
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs

@ -225,6 +225,23 @@ namespace Debugger @@ -225,6 +225,23 @@ namespace Debugger
}
}
/// <summary>
/// Waits until all debugged precesses exit. Returns imideately if there are no running processes.
/// </summary>
public void WaitForPrecessExit()
{
// The process is removed first and then the even is called
AutoResetEvent exitedEvent = new AutoResetEvent(false);
this.ProcessExited += delegate {
exitedEvent.Set();
};
// If it has not been removed yet, we will get an event later
while (Processes.Count > 0) {
this.MTA2STA.SoftWait(exitedEvent);
}
}
/// <summary>
/// Wait handle, which will be set as long as the debugger is paused
/// </summary>

7
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs

@ -24,6 +24,7 @@ namespace Debugger @@ -24,6 +24,7 @@ namespace Debugger
ManagedCallbackProxy managedCallbackProxy;
ApartmentState requiredApartmentState;
MTA2STA mta2sta = new MTA2STA();
VariableCollection localVariables;
@ -34,6 +35,12 @@ namespace Debugger @@ -34,6 +35,12 @@ namespace Debugger
return requiredApartmentState;
}
}
internal MTA2STA MTA2STA {
get {
return mta2sta;
}
}
internal ICorDebug CorDebug {
get {

3
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs

@ -80,8 +80,7 @@ namespace Debugger @@ -80,8 +80,7 @@ namespace Debugger
{
Process createdProcess = null;
if (debugger.RequiredApartmentState == ApartmentState.STA) {
MTA2STA m2s = new MTA2STA();
createdProcess = (Process)m2s.CallInSTA(typeof(Process), "StartInternal", new Object[] {debugger, filename, workingDirectory, arguments});
createdProcess = (Process)debugger.MTA2STA.CallInSTA(typeof(Process), "StartInternal", new Object[] {debugger, filename, workingDirectory, arguments});
} else {
createdProcess = StartInternal(debugger, filename, workingDirectory, arguments);
}

3
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj

@ -25,6 +25,9 @@ @@ -25,6 +25,9 @@
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<Reference Include="MbUnit.Framework" />
<Reference Include="MbUnit.Framework" />
<Reference Include="MbUnit.Framework" />
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\AssemblyInfo.cs" />

10
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs

@ -90,17 +90,11 @@ namespace DebuggerLibrary.Tests @@ -90,17 +90,11 @@ namespace DebuggerLibrary.Tests
}
[Test, Ignore("Disabled because of deadlock problem")]
[Test]
public void RunSimpleProgram()
{
ManualResetEvent exitedEvent = new ManualResetEvent(false);
debugger.ProcessExited += delegate {
exitedEvent.Set();
};
debugger.Start((string)programs["SimpleProgram"], tempPath, "");
if (!exitedEvent.WaitOne(1000, false)) {
throw new System.Exception("Time out");
}
debugger.WaitForPrecessExit();
}
}
}

Loading…
Cancel
Save