Browse Source

Use other thread for evaluation if the current one is not suitable

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5301 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
David Srbecký 16 years ago
parent
commit
b90c4ffe1b
  1. 41
      src/AddIns/Debugger/Debugger.Core/Eval.cs
  2. 15
      src/AddIns/Debugger/Debugger.Core/Process.cs

41
src/AddIns/Debugger/Debugger.Core/Eval.cs

@ -91,8 +91,8 @@ namespace Debugger
this.process = appDomain.Process; this.process = appDomain.Process;
this.description = description; this.description = description;
this.state = EvalState.Evaluating; this.state = EvalState.Evaluating;
this.thread = GetEvaluationThread(appDomain);
this.corEval = CreateCorEval(appDomain, out this.thread); this.corEval = thread.CorThread.CreateEval();
try { try {
evalStarter(this); evalStarter(this);
@ -133,35 +133,22 @@ namespace Debugger
} }
} }
static ICorDebugEval CreateCorEval(AppDomain appDomain, out Thread thread) static Thread GetEvaluationThread(AppDomain appDomain)
{ {
appDomain.Process.AssertPaused(); appDomain.Process.AssertPaused();
thread = appDomain.Process.SelectedThread; Thread st = appDomain.Process.SelectedThread;
if (st != null && !st.Suspended && !st.IsInNativeCode && st.IsAtSafePoint && st.CorThread.GetAppDomain().GetID() == appDomain.ID) {
if (thread.CorThread.GetAppDomain().GetID() != appDomain.ID) { return st;
foreach(Thread t in appDomain.Process.Threads) {
if (t.CorThread.GetAppDomain().GetID() == appDomain.ID &&
!t.Suspended &&
!t.IsInNativeCode &&
t.IsAtSafePoint)
{
thread = t;
break;
}
}
} }
if (thread == null) foreach(Thread t in appDomain.Process.Threads) {
throw new GetValueException("Can not evaluate because no thread is selected"); if (!t.Suspended && !t.IsInNativeCode && t.IsAtSafePoint && t.CorThread.GetAppDomain().GetID() == appDomain.ID) {
if (thread.IsInNativeCode) return t;
throw new GetValueException("Can not evaluate because native frame is on top of stack"); }
if (!thread.IsAtSafePoint) }
throw new GetValueException("Can not evaluate because thread is not at a safe point");
if (thread.Suspended)
throw new GetValueException("Can not evaluate on suspended thread");
return thread.CorThread.CreateEval(); throw new GetValueException("No suitable thread for evaluation");
} }
internal bool IsCorEval(ICorDebugEval corEval) internal bool IsCorEval(ICorDebugEval corEval)
@ -293,8 +280,8 @@ namespace Debugger
{ {
if (value == null) { if (value == null) {
ICorDebugClass corClass = appDomain.ObjectType.CorType.GetClass(); ICorDebugClass corClass = appDomain.ObjectType.CorType.GetClass();
Thread thread; Thread thread = GetEvaluationThread(appDomain);
ICorDebugEval corEval = CreateCorEval(appDomain, out thread); ICorDebugEval corEval = thread.CorThread.CreateEval();
ICorDebugValue corValue = corEval.CreateValue((uint)CorElementType.CLASS, corClass); ICorDebugValue corValue = corEval.CreateValue((uint)CorElementType.CLASS, corClass);
return new Value(appDomain, corValue); return new Value(appDomain, corValue);
} else if (value is string) { } else if (value is string) {

15
src/AddIns/Debugger/Debugger.Core/Process.cs

@ -416,12 +416,12 @@ namespace Debugger
internal Thread[] UnsuspendedThreads { internal Thread[] UnsuspendedThreads {
get { get {
List<Thread> threadsToRun = new List<Thread>(this.Threads.Count); List<Thread> unsuspendedThreads = new List<Thread>(this.Threads.Count);
foreach(Thread t in this.Threads) { foreach(Thread t in this.Threads) {
if (!t.Suspended) if (!t.Suspended)
threadsToRun.Add(t); unsuspendedThreads.Add(t);
} }
return threadsToRun.ToArray(); return unsuspendedThreads.ToArray();
} }
} }
@ -435,17 +435,18 @@ namespace Debugger
internal CorDebugThreadState NewThreadState = CorDebugThreadState.THREAD_RUN; internal CorDebugThreadState NewThreadState = CorDebugThreadState.THREAD_RUN;
/// <param name="threadsToRun"> Null to keep current setting </param>
/// <param name="newThreadState"> What happens to created threads. Null to keep current setting </param>
internal void AsyncContinue(DebuggeeStateAction action, Thread[] threadsToRun, CorDebugThreadState? newThreadState) internal void AsyncContinue(DebuggeeStateAction action, Thread[] threadsToRun, CorDebugThreadState? newThreadState)
{ {
AssertPaused(); AssertPaused();
if (threadsToRun != null) { if (threadsToRun != null) {
// corProcess.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, null); // corProcess.SetAllThreadsDebugState(CorDebugThreadState.THREAD_SUSPEND, null);
// TODO: There is second unreported thread, stopping it prevents the debugee from exiting // Note: There is unreported thread, stopping it prevents the debugee from exiting
// uint count = corProcess.EnumerateThreads().GetCount(); // It is not corProcess.GetHelperThreadID
// ICorDebugThread[] ts = new ICorDebugThread[count]; // ICorDebugThread[] ts = new ICorDebugThread[corProcess.EnumerateThreads().GetCount()];
// corProcess.EnumerateThreads().Next((uint)ts.Length, ts); // corProcess.EnumerateThreads().Next((uint)ts.Length, ts);
// uint helper = corProcess.GetHelperThreadID();
try { try {
foreach(Thread t in this.Threads) { foreach(Thread t in this.Threads) {
t.CorThread.SetDebugState(CorDebugThreadState.THREAD_SUSPEND); t.CorThread.SetDebugState(CorDebugThreadState.THREAD_SUSPEND);

Loading…
Cancel
Save