Browse Source

StateControl refactored. Added WaitForPause()

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@663 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 20 years ago
parent
commit
efb229d1ef
  1. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs
  2. 107
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs
  3. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs
  4. 6
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs

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

@ -61,19 +61,17 @@ namespace DebuggerLibrary
callingProcess = debugger.GetProcess(pProcess); callingProcess = debugger.GetProcess(pProcess);
callingProcess.IsRunning = false; callingProcess.IsRunning = false;
} }
// Sets CurrentProcess, CurrentThread and CurrentFunction
// (CurrentFunction will be set to null if there are no symbols)
void EnterCallback(string name, ICorDebugThread pThread) void EnterCallback(string name, ICorDebugThread pThread)
{ {
EnterCallback(name); EnterCallback(name);
callingThread = debugger.GetThread(pThread); callingThread = debugger.GetThread(pThread);
callingProcess = callingThread.Process; callingProcess = callingThread.Process;
callingProcess.IsRunning = false; callingProcess.IsRunning = false;
} }
void EnterCallback(string name) void EnterCallback(string name)
{ {
handlingCallback = true; handlingCallback = true;

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

@ -19,8 +19,11 @@ namespace DebuggerLibrary
{ {
public partial class NDebugger public partial class NDebugger
{ {
bool isPaused; PausedReason? pausedReason = null;
bool pauseOnHandledException = false; bool pauseOnHandledException = false;
EventWaitHandle waitForPauseHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
Process currentProcess;
public event EventHandler<DebuggingPausedEventArgs> DebuggingPaused; public event EventHandler<DebuggingPausedEventArgs> DebuggingPaused;
public event EventHandler<DebuggerEventArgs> DebuggingResumed; public event EventHandler<DebuggerEventArgs> DebuggingResumed;
@ -101,13 +104,24 @@ namespace DebuggerLibrary
public bool IsPaused { public bool IsPaused {
get { get {
return isPaused; return (pausedReason != null);
} }
} }
public bool IsRunning { public bool IsRunning {
get { get {
return !isPaused; return (pausedReason == null);
}
}
/// <summary>
/// The reason why the debugger is paused.
/// Thows an DebuggerException if debugger is not paused.
/// </summary>
public PausedReason PausedReason {
get {
AssertPaused();
return (PausedReason)pausedReason;
} }
} }
@ -116,9 +130,23 @@ namespace DebuggerLibrary
if (IsPaused) { if (IsPaused) {
throw new DebuggerException("Already paused"); throw new DebuggerException("Already paused");
} }
isPaused = true; if (process == null) {
SetUpEnvironment(process, thread, function); throw new DebuggerException("Process can not be null");
}
if (thread == null && function != null) {
throw new DebuggerException("Function can not be set without thread");
}
currentProcess = process;
currentProcess.CurrentThread = thread;
if (currentProcess.CurrentThread != null) {
currentProcess.CurrentThread.CurrentFunction = function;
}
pausedReason = reason;
OnDebuggingPaused(reason); OnDebuggingPaused(reason);
waitForPauseHandle.Set();
} }
internal void FakePause(PausedReason reason, bool keepCurrentFunction) internal void FakePause(PausedReason reason, bool keepCurrentFunction)
@ -132,63 +160,44 @@ namespace DebuggerLibrary
internal void Resume() internal void Resume()
{ {
if (!IsPaused) { if (IsRunning) {
throw new DebuggerException("Already resumed"); throw new DebuggerException("Already resumed");
} }
OnDebuggingResumed(); OnDebuggingResumed();
isPaused = false; waitForPauseHandle.Reset();
}
void SetUpEnvironment(Process process, Thread thread, Function function)
{
CleanEnvironment();
// Set the CurrentProcess
if (process == null) {
if (thread != null) {
process = thread.Process;
}
}
currentProcess = process;
// Set the CurrentThread pausedReason = null;
if (process != null) {
if (thread != null) {
process.CurrentThread = thread;
} else {
IList<Thread> threads = process.Threads;
if (threads.Count > 0) {
process.CurrentThread = threads[0];
} else {
process.CurrentThread = null;
}
}
}
// Set the CurrentFunction // Remove all stored functions, they are disponsed between callbacks and they need to be regenerated
// Other CurrentFunctions in threads are fetched on request
if (thread != null && function != null) {
thread.CurrentFunction = function;
}
}
void CleanEnvironment()
{
// Remove all stored functions,
// they are disponsed between callbacks and
// they need to be regenerated
foreach(Thread t in Threads) { foreach(Thread t in Threads) {
t.CurrentFunction = null; t.CurrentFunction = null;
} }
// Clear current thread
if (currentProcess != null) {
currentProcess.CurrentThread = null;
}
// Clear current process // Clear current process
currentProcess = null; currentProcess = null;
} }
/// <summary>
/// Waits until the debugger pauses unless it is already paused.
/// Use PausedReason to find out why it paused.
/// </summary>
public void WaitForPause()
{
if (IsRunning) {
WaitForPauseHandle.WaitOne();
}
}
/// <summary>
/// Wait handle, which will be set as long as the debugger is paused
/// </summary>
public WaitHandle WaitForPauseHandle {
get {
return waitForPauseHandle;
}
}
public void Break() public void Break()
{ {
foreach(Process p in Processes) { foreach(Process p in Processes) {

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs

@ -16,8 +16,6 @@ namespace DebuggerLibrary
{ {
List<Process> processCollection = new List<Process>(); List<Process> processCollection = new List<Process>();
Process currentProcess;
public event EventHandler<ProcessEventArgs> ProcessStarted; public event EventHandler<ProcessEventArgs> ProcessStarted;
public event EventHandler<ProcessEventArgs> ProcessExited; public event EventHandler<ProcessEventArgs> ProcessExited;

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

@ -38,6 +38,12 @@ namespace DebuggerLibrary
public Thread CurrentThread { public Thread CurrentThread {
get { get {
if (currentThread == null) {
IList<Thread> threads = Threads;
if (threads.Count > 0) {
currentThread = threads[0];
}
}
return currentThread; return currentThread;
} }
internal set { internal set {

Loading…
Cancel
Save