Browse Source

Created ThreadCollection class

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4513 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 16 years ago
parent
commit
8ed71a4bf3
  1. 8
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs
  2. 60
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Threads.cs
  3. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process.cs
  4. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs
  5. 12
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs
  6. 4
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/ThreadName.cs

8
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs

@ -102,12 +102,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
{ {
if (debuggedProcess != null) { if (debuggedProcess != null) {
debuggedProcess.Paused -= debuggedProcess_Paused; debuggedProcess.Paused -= debuggedProcess_Paused;
debuggedProcess.ThreadStarted -= debuggedProcess_ThreadStarted; debuggedProcess.Threads.Added -= debuggedProcess_ThreadStarted;
} }
debuggedProcess = process; debuggedProcess = process;
if (debuggedProcess != null) { if (debuggedProcess != null) {
debuggedProcess.Paused += debuggedProcess_Paused; debuggedProcess.Paused += debuggedProcess_Paused;
debuggedProcess.ThreadStarted += debuggedProcess_ThreadStarted; debuggedProcess.Threads.Added += debuggedProcess_ThreadStarted;
} }
runningThreadsList.Items.Clear(); runningThreadsList.Items.Clear();
RefreshPad(); RefreshPad();
@ -118,9 +118,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
RefreshPad(); RefreshPad();
} }
void debuggedProcess_ThreadStarted(object sender, ThreadEventArgs e) void debuggedProcess_ThreadStarted(object sender, CollectionItemEventArgs<Thread> e)
{ {
AddThread(e.Thread); AddThread(e.Item);
} }
public override void RefreshPad() public override void RefreshPad()

60
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Threads.cs

@ -14,67 +14,45 @@ namespace Debugger
{ {
public partial class Process public partial class Process
{ {
Thread selectedThread; ThreadCollection threads;
List<Thread> threadCollection = new List<Thread>();
public event EventHandler<ThreadEventArgs> ThreadStarted; public ThreadCollection Threads {
get { return threads; }
protected virtual void OnThreadStarted(Thread thread)
{
if (ThreadStarted != null) {
ThreadStarted(this, new ThreadEventArgs(thread));
}
} }
public Thread SelectedThread { public Thread SelectedThread {
get { get { return this.Threads.Selected; }
return selectedThread; set { this.Threads.Selected = value; }
}
set {
selectedThread = value;
}
} }
}
public IList<Thread> Threads { public class ThreadCollection: CollectionWithEvents<Thread>
get { {
List<Thread> threads = new List<Thread>(); public ThreadCollection(NDebugger debugger): base(debugger) {}
foreach(Thread thread in threadCollection) {
if (!thread.HasExited) { Thread selected;
threads.Add(thread);
} public Thread Selected {
} get { return selected; }
return threads.AsReadOnly(); set { selected = value; }
}
} }
internal bool ContainsThread(ICorDebugThread corThread) internal bool Contains(ICorDebugThread corThread)
{ {
foreach(Thread thread in threadCollection) { foreach(Thread thread in this) {
if (thread.CorThread == corThread) return true; if (thread.CorThread == corThread) return true;
} }
return false; return false;
} }
internal Thread GetThread(ICorDebugThread corThread) internal Thread Get(ICorDebugThread corThread)
{ {
foreach(Thread thread in threadCollection) { foreach(Thread thread in this) {
if (thread.CorThread == corThread) { if (thread.CorThread == corThread) {
return thread; return thread;
} }
} }
throw new DebuggerException("Thread is not in collection"); throw new DebuggerException("Thread is not in collection");
} }
internal void AddThread(ICorDebugThread corThread)
{
Thread thread = new Thread(this, corThread);
threadCollection.Add(thread);
OnThreadStarted(thread);
thread.Exited += delegate {
threadCollection.Remove(thread);
};
}
} }
} }

1
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process.cs

@ -74,6 +74,7 @@ namespace Debugger
evals = new EvalCollection(debugger); evals = new EvalCollection(debugger);
modules = new ModuleCollection(debugger); modules = new ModuleCollection(debugger);
threads = new ThreadCollection(debugger);
} }
internal ICorDebugProcess CorProcess { internal ICorDebugProcess CorProcess {

1
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs

@ -100,6 +100,7 @@ namespace Debugger
this.HasExited = true; this.HasExited = true;
OnExited(new ThreadEventArgs(this)); OnExited(new ThreadEventArgs(this));
process.Threads.Remove(this);
} }
protected virtual void OnExited(ThreadEventArgs e) protected virtual void OnExited(ThreadEventArgs e)

12
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs

@ -78,7 +78,7 @@ namespace Debugger
void EnterCallback(PausedReason pausedReason, string name, ICorDebugThread pThread) void EnterCallback(PausedReason pausedReason, string name, ICorDebugThread pThread)
{ {
EnterCallback(pausedReason, name, pThread.Process); EnterCallback(pausedReason, name, pThread.Process);
process.SelectedThread = process.GetThread(pThread); process.SelectedThread = process.Threads.Get(pThread);
} }
void ExitCallback() void ExitCallback()
@ -123,7 +123,7 @@ namespace Debugger
{ {
EnterCallback(PausedReason.StepComplete, "StepComplete (" + reason.ToString() + ")", pThread); EnterCallback(PausedReason.StepComplete, "StepComplete (" + reason.ToString() + ")", pThread);
Thread thread = process.GetThread(pThread); Thread thread = process.Threads.Get(pThread);
Stepper stepper = thread.GetStepper(pStepper); Stepper stepper = thread.GetStepper(pStepper);
StackFrame currentStackFrame = process.SelectedThread.MostRecentStackFrame; StackFrame currentStackFrame = process.SelectedThread.MostRecentStackFrame;
@ -354,7 +354,7 @@ namespace Debugger
EnterCallback(PausedReason.Other, "NameChange: pThread", pThread); EnterCallback(PausedReason.Other, "NameChange: pThread", pThread);
Thread thread = process.GetThread(pThread); Thread thread = process.Threads.Get(pThread);
thread.NotifyNameChanged(); thread.NotifyNameChanged();
ExitCallback(); ExitCallback();
@ -368,7 +368,7 @@ namespace Debugger
// and we continue from this callback anyway // and we continue from this callback anyway
EnterCallback(PausedReason.Other, "CreateThread " + pThread.ID, pAppDomain); EnterCallback(PausedReason.Other, "CreateThread " + pThread.ID, pAppDomain);
process.AddThread(pThread); process.Threads.Add(new Thread(process, pThread));
ExitCallback(); ExitCallback();
} }
@ -410,10 +410,10 @@ namespace Debugger
public void ExitThread(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread) public void ExitThread(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread)
{ {
// ICorDebugThread is still not dead and can be used for some operations // ICorDebugThread is still not dead and can be used for some operations
if (process.ContainsThread(pThread)) { if (process.Threads.Contains(pThread)) {
EnterCallback(PausedReason.Other, "ExitThread " + pThread.ID, pThread); EnterCallback(PausedReason.Other, "ExitThread " + pThread.ID, pThread);
process.GetThread(pThread).NotifyExited(); process.Threads.Get(pThread).NotifyExited();
} else { } else {
EnterCallback(PausedReason.Other, "ExitThread " + pThread.ID, process.CorProcess); EnterCallback(PausedReason.Other, "ExitThread " + pThread.ID, process.CorProcess);

4
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/ThreadName.cs

@ -39,8 +39,8 @@ namespace Debugger.Tests {
void debugger_ProcessStarted(object sender, CollectionItemEventArgs<Process> e) void debugger_ProcessStarted(object sender, CollectionItemEventArgs<Process> e)
{ {
e.Item.ThreadStarted += delegate(object sender2, ThreadEventArgs f) { e.Item.Threads.Added += delegate(object sender2, CollectionItemEventArgs<Thread> f) {
ObjectDump("ThreadStartedEvent", f.Thread); ObjectDump("ThreadStartedEvent", f.Item);
}; };
} }
} }

Loading…
Cancel
Save