Example #1
0
		static void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			bool newIsDebugging = DebugManager.Instance.IsDebugging;
			if (newIsDebugging != prevIsDebugging) {
				prevIsDebugging = newIsDebugging;
				MainWindow.Instance.UpdateToolbar();
			}
		}
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			if (theDebugger.Debugger == null)
				return;
			if (theDebugger.Debugger.IsEvaluating)
				return;
			bool newIsRunning = theDebugger.ProcessState == DebuggerProcessState.Running;
			if (newIsRunning == isRunning)
				return;
			var dnProcess = theDebugger.Debugger.Processes.FirstOrDefault();
			if (dnProcess == null)
				return;

			isRunning = newIsRunning;
			int id = Interlocked.Increment(ref isRunningId);
			if (!isRunning)
				return;

			var process = GetProcessById(dnProcess.ProcessId);
			if (process == null)
				return;

			Timer timer = null;
			timer = new Timer(a => {
				timer.Dispose();
				if (id == isRunningId) {
					if (dispatcher.HasShutdownStarted || dispatcher.HasShutdownFinished)
						return;
					dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => {
						if (id == isRunningId) {
							ProcessRunning?.Invoke(this, new DebuggedProcessRunningEventArgs(process));
						}
					}));
				}
			}, null, WAIT_TIME_MS, Timeout.Infinite);
		}
Example #3
0
		void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var oldState = currentState;
			currentState = new CurrentState();
			var dbg = (DnDebugger)sender;
			switch (DebugManager.Instance.ProcessState) {
			case DebuggerProcessState.Starting:
				savedEvalState = null;
				break;

			case DebuggerProcessState.Continuing:
				if (dbg.IsEvaluating && savedEvalState == null)
					savedEvalState = oldState;
				break;

			case DebuggerProcessState.Running:
				if (!dbg.IsEvaluating)
					ClearStackFrameLines();
				break;

			case DebuggerProcessState.Stopped:
				if (dbg.IsEvaluating)
					break;

				// Don't update the selected thread if we just evaluated something
				if (UpdateState(savedEvalState)) {
					currentState.Thread = DebugManager.Instance.Debugger.Current.Thread;
					SelectedFrameNumber = 0;
				}
				else
					currentState = savedEvalState;
				savedEvalState = null;

				foreach (var textView in MainWindow.Instance.AllVisibleTextViews)
					UpdateStackFrameLines(textView, false);
				break;

			case DebuggerProcessState.Terminated:
				savedEvalState = null;
				ClearStackFrameLines();
				break;

			default:
				throw new InvalidOperationException();
			}

			if (StackFramesUpdated != null)
				StackFramesUpdated(this, new StackFramesUpdatedEventArgs(dbg));
		}
Example #4
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var dbg = (DnDebugger)sender;
			switch (theDebugger.ProcessState) {
			case DebuggerProcessState.Starting:
				dbg.DebugCallbackEvent += DnDebugger_DebugCallbackEvent;
				break;

			case DebuggerProcessState.Continuing:
			case DebuggerProcessState.Running:
			case DebuggerProcessState.Paused:
				break;

			case DebuggerProcessState.Terminated:
				dbg.DebugCallbackEvent -= DnDebugger_DebugCallbackEvent;
				break;
			}
		}
Example #5
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var dbg = (DnDebugger)sender;
			switch (dbg.ProcessState) {
			case DebuggerProcessState.Starting:
				if (outputLoggerSettings.ShowDebugOutputLog)
					outputService.Select(GUID_OUTPUT_LOGGER_DEBUG);

				debugState?.Dispose();
				debugState = null;

				textPane.Clear();
				dbg.DebugCallbackEvent += DnDebugger_DebugCallbackEvent;
				debugState = new DebugState(dbg);
				break;

			case DebuggerProcessState.Continuing:
			case DebuggerProcessState.Running:
			case DebuggerProcessState.Paused:
				Debug.Assert(debugState != null && debugState.dbg == dbg);
				break;

			case DebuggerProcessState.Terminated:
				Debug.Assert(debugState != null);
				Debug.Assert(debugState?.dbg == dbg);

				if (outputLoggerSettings.ShowProcessExitMessages) {
					int processExitCode;
					if (debugState == null || !NativeMethods.GetExitCodeProcess(debugState.hProcess_debuggee, out processExitCode))
						processExitCode = -1;
					textPane.WriteLine(BoxedTextColor.DebugLogExitProcess,
						string.Format(dnSpy_Debugger_Resources.DebugLogExitProcess,
								GetProcessNameWithPID(debugState?.debuggedProcess),
								processExitCode));
				}

				debugState?.Dispose();
				debugState = null;
				break;
			}
		}
		void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			if (DebugManager.Instance.Debugger == null)
				return;
			if (DebugManager.Instance.Debugger.IsEvaluating)
				return;
			bool newIsRunning = DebugManager.Instance.ProcessState == DebuggerProcessState.Running;
			if (newIsRunning == isRunning)
				return;
			var dnProcess = DebugManager.Instance.Debugger.Processes.FirstOrDefault();
			if (dnProcess == null)
				return;

			isRunning = newIsRunning;
			int id = Interlocked.Increment(ref isRunningId);
			if (!isRunning)
				return;

			var process = GetProcessById(dnProcess.ProcessId);
			if (process == null)
				return;

			Timer timer = null;
			timer = new Timer(a => {
				timer.Dispose();
				if (id == isRunningId) {
					var cur = App.Current;
					if (cur == null)
						return;
					cur.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => {
						if (id == isRunningId) {
							if (ProcessRunning != null)
								ProcessRunning(this, new DebuggedProcessRunningEventArgs(process));
						}
					}));
				}
			}, null, WAIT_TIME_MS, Timeout.Infinite);
		}
Example #7
0
        void TheDebugger_OnProcessStateChanged_Last(object sender, DBG.DebuggerEventArgs e)
        {
            switch (theDebugger.ProcessState)
            {
            case DBG.DebuggerProcessState.Starting:
                foreach (var bp in breakpointsToInitialize)
                {
                    Initialize(bp);
                }
                breakpointsToInitialize.Clear();
                InitializeProcessHandle();
                Debug.Assert(hProcess_debuggee != IntPtr.Zero);
                break;

            case DBG.DebuggerProcessState.Terminated:
                Debug.Assert(breakpointsToInitialize.Count == 0);
                breakpointsToInitialize.Clear();
                hProcess_debuggee = IntPtr.Zero;
                break;
            }

            Debug.Assert((theDebugger.ProcessState == DBG.DebuggerProcessState.Terminated && hProcess_debuggee == IntPtr.Zero) ||
                         (theDebugger.ProcessState != DBG.DebuggerProcessState.Terminated && hProcess_debuggee != IntPtr.Zero && hProcess_debuggee == GetProcessHandle()));

            var c = OnProcessStateChanged;

            if (c != null)
            {
                try {
                    c(this, DebuggerEventArgs.Empty);
                }
                catch {
                    // Ignore buggy script exceptions
                }
            }
            InitializePausedOrTerminatedEvent();
        }
Example #8
0
 void CallOnProcessStateChanged(object sender, DebuggerEventArgs e)
 {
     if (OnProcessStateChanged != null)
         OnProcessStateChanged(sender, e ?? DebuggerEventArgs.Empty);
 }
Example #9
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			// InMemoryModuleManager should be notified here. It needs to execute first so it can
			// call LoadEverything() and load all dynamic modules so ResolveToken() of new methods
			// and types work.
			if (OnProcessStateChanged2 != null)
				OnProcessStateChanged2(sender, e);
		}
Example #10
0
		void DnDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			if (debugger == null || sender != debugger)
				return;

			switch (debugger.ProcessState) {
			case DebuggerProcessState.Starting:
				unhandledException = false;
				evalDisabled = false;
				break;

			case DebuggerProcessState.Stopped:
				if (debugger.IsEvaluating || debugger.EvalCompleted)
					break;
				evalDisabled = false;
				break;
			}

			CallOnProcessStateChanged(sender, e);

			if (debugger.ProcessState == DebuggerProcessState.Terminated) {
				RemoveDebugger();
				evalDisabled = false;
				unhandledException = false;
			}
		}
Example #11
0
		void CallOnProcessStateChanged(object sender, DebuggerEventArgs e) {
			// InMemoryModuleManager should be notified here. It needs to execute first so it can
			// call LoadEverything() and load all dynamic modules so ResolveToken() of new methods
			// and types work.
			if (OnProcessStateChanged_First != null)
				OnProcessStateChanged_First(sender, e);

			if (OnProcessStateChanged != null)
				OnProcessStateChanged(sender, e ?? DebuggerEventArgs.Empty);

			// The script code uses this event to make sure it always executes last
			if (OnProcessStateChanged_Last != null)
				OnProcessStateChanged_Last(sender, e);
		}
Example #12
0
		void DebugManager_OnProcessStateChanged2(object sender, DebuggerEventArgs e) {
			var dbg = (DnDebugger)sender;
			switch (DebugManager.Instance.ProcessState) {
			case DebuggerProcessState.Starting:
				classLoader = new ClassLoader();
				dbg.OnCorModuleDefCreated += DnDebugger_OnCorModuleDefCreated;
				dbg.DebugCallbackEvent += DnDebugger_DebugCallbackEvent;
				dbg.OnModuleAdded += DnDebugger_OnModuleAdded;
				break;

			case DebuggerProcessState.Continuing:
			case DebuggerProcessState.Running:
				break;

			case DebuggerProcessState.Stopped:
				if (dbg.IsEvaluating)
					break;

				LoadNewClasses();
				ReloadInMemoryModulesFromMemory();
				if (DynamicModulesLoaded != null)
					DynamicModulesLoaded(this, EventArgs.Empty);
				break;

			case DebuggerProcessState.Terminated:
				classLoader = null;
				break;
			}
		}
Example #13
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var dbg = (DnDebugger)sender;
			switch (theDebugger.ProcessState) {
			case DebuggerProcessState.Starting:
				InstallDebuggerHooks(dbg);
				break;

			case DebuggerProcessState.Continuing:
			case DebuggerProcessState.Running:
			case DebuggerProcessState.Paused:
				break;

			case DebuggerProcessState.Terminated:
				UninstallDebuggerHooks(dbg);
				break;
			}
		}
Example #14
0
		static void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			if (DebuggerSettings.Instance.AutoOpenLocalsWindow && DebugManager.Instance.ProcessState == DebuggerProcessState.Starting)
				LocalsControlInstance.Show();
		}
Example #15
0
        private void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e)
        {
            var dbg = (DnDebugger)sender;
            switch (dbg.ProcessState) {
            case DebuggerProcessState.Starting:
                dbg.DebugCallbackEvent += DnDebugger_DebugCallbackEvent;
                break;

            case DebuggerProcessState.Running:
            case DebuggerProcessState.Stopped:
                break;

            case DebuggerProcessState.Terminated:
                dbg.DebugCallbackEvent -= DnDebugger_DebugCallbackEvent;
                break;
            }
        }
Example #16
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var oldState = currentState;
			currentState = new CurrentState();
			var dbg = (DnDebugger)sender;
			switch (theDebugger.ProcessState) {
			case DebuggerProcessState.Starting:
				savedEvalState = null;
				break;

			case DebuggerProcessState.Continuing:
				if (dbg.IsEvaluating && savedEvalState == null)
					savedEvalState = oldState;
				break;

			case DebuggerProcessState.Running:
				if (!dbg.IsEvaluating)
					ClearStackFrameLines();
				break;

			case DebuggerProcessState.Stopped:
				if (dbg.IsEvaluating)
					break;

				// Don't update the selected thread if we just evaluated something
				if (UpdateState(savedEvalState)) {
					currentState.Thread = dbg.Current.Thread;
					SelectedFrameNumber = 0;
				}
				else
					currentState = savedEvalState;
				savedEvalState = null;

				foreach (var tab in fileTabManager.VisibleFirstTabs)
					UpdateStackFrameLines(tab.UIContext as ITextEditorUIContext, false);
				break;

			case DebuggerProcessState.Terminated:
				savedEvalState = null;
				ClearStackFrameLines();
				break;

			default:
				throw new InvalidOperationException();
			}

			if (StackFramesUpdated != null)
				StackFramesUpdated(this, new StackFramesUpdatedEventArgs(dbg));
		}
Example #17
0
        void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e)
        {
            var state = DebugManager.Instance.ProcessState;
            switch (state) {
            case DebuggerProcessState.Starting:
                InitializeHexDocument();
                break;

            case DebuggerProcessState.Continuing:
            case DebuggerProcessState.Running:
            case DebuggerProcessState.Stopped:
                break;

            case DebuggerProcessState.Terminated:
                InitializeHexDocument();
                break;
            }

            IsStopped = state == DebuggerProcessState.Stopped;
            if (state != DebuggerProcessState.Continuing && state != DebuggerProcessState.Running)
                CanNotEditMemory = state != DebuggerProcessState.Stopped;

            InitializeMemory();
        }
Example #18
0
		void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			// InMemoryModuleManager should be notified here. It needs to execute first so it can
			// call LoadEverything() and load all dynamic modules so ResolveToken() of new methods
			// and types work.
			if (OnProcessStateChanged2 != null)
				OnProcessStateChanged2(sender, e);

			switch (DebugManager.Instance.ProcessState) {
			case DebuggerProcessState.Starting:
				evalDisabled = false;
				currentLocation = null;
				currentMethod = null;
				SetRunningStatusMessage();
				MainWindow.Instance.SetDebugging();
				break;

			case DebuggerProcessState.Continuing:
				break;

			case DebuggerProcessState.Running:
				if (Debugger.IsEvaluating)
					break;
				SetRunningStatusMessage();
				break;

			case DebuggerProcessState.Stopped:
				// If we're evaluating, or if eval has completed, don't do a thing. This code
				// should only be executed when a BP hits or if a stepping operation has completed.
				if (Debugger.IsEvaluating || Debugger.EvalCompleted)
					break;

				evalDisabled = false;
				BringMainWindowToFrontAndActivate();

				UpdateCurrentLocation();
				if (currentMethod != null && currentLocation != null)
					JumpToCurrentStatement(MainWindow.Instance.SafeActiveTextView);

				SetReadyStatusMessage(new StoppedMessageCreator().GetMessage(Debugger));
				break;

			case DebuggerProcessState.Terminated:
				evalDisabled = false;
				currentLocation = null;
				currentMethod = null;
				MainWindow.Instance.HideStatus();
				MainWindow.Instance.ClearDebugging();
				break;
			}
		}
Example #19
0
		void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			switch (DebugManager.Instance.ProcessState) {
			case DebuggerProcessState.Starting:
				AddDebuggerBreakpoints();
				break;

			case DebuggerProcessState.Running:
			case DebuggerProcessState.Stopped:
				break;

			case DebuggerProcessState.Terminated:
				RemoveDebuggerBreakpoints();
				break;
			}
		}
Example #20
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var oldState = currentState;
			currentState = new CurrentState();
			var dbg = (DnDebugger)sender;
			switch (theDebugger.ProcessState) {
			case DebuggerProcessState.Starting:
				savedEvalState = null;
				break;

			case DebuggerProcessState.Continuing:
				if (dbg.IsEvaluating && savedEvalState == null)
					savedEvalState = oldState;
				break;

			case DebuggerProcessState.Running:
				if (!dbg.IsEvaluating)
					RaiseClearFrames();
				break;

			case DebuggerProcessState.Paused:
				if (dbg.IsEvaluating)
					break;

				// Don't update the selected thread if we just evaluated something
				if (UpdateState(savedEvalState)) {
					currentState.Thread = dbg.Current.Thread;
					SelectedFrameNumber = 0;
				}
				else
					currentState = savedEvalState;
				savedEvalState = null;

				RaiseNewFrames();
				break;

			case DebuggerProcessState.Terminated:
				savedEvalState = null;
				RaiseClearFrames();
				break;

			default:
				throw new InvalidOperationException();
			}

			StackFramesUpdated?.Invoke(this, new StackFramesUpdatedEventArgs(dbg));
		}
Example #21
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			switch (theDebugger.ProcessState) {
			case DebuggerProcessState.Starting:
				AddDebuggerBreakpoints();
				break;

			case DebuggerProcessState.Continuing:
			case DebuggerProcessState.Running:
			case DebuggerProcessState.Paused:
				break;

			case DebuggerProcessState.Terminated:
				RemoveDebuggerBreakpoints();
				break;
			}
		}
Example #22
0
        void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e)
        {
            switch (DebugManager.Instance.ProcessState) {
            case DebuggerProcessState.Starting:
                evalDisabled = false;
                currentLocation = null;
                currentMethod = null;
                MainWindow.Instance.SessionSettings.FilterSettings.ShowInternalApi = true;
                SetRunningStatusMessage();
                MainWindow.Instance.SetDebugging();
                break;

            case DebuggerProcessState.Continuing:
                break;

            case DebuggerProcessState.Running:
                if (Debugger.IsEvaluating)
                    break;
                SetRunningStatusMessage();
                break;

            case DebuggerProcessState.Stopped:
                // If we're evaluating, or if eval has completed, don't do a thing. This code
                // should only be executed when a BP hits or if a stepping operation has completed.
                if (Debugger.IsEvaluating || Debugger.EvalCompleted)
                    break;

                evalDisabled = false;
                BringMainWindowToFrontAndActivate();

                UpdateCurrentLocation();
                if (currentMethod != null && currentLocation != null)
                    JumpToCurrentStatement(MainWindow.Instance.SafeActiveTextView);

                SetReadyStatusMessage(new StoppedMessageCreator().GetMessage(Debugger));
                break;

            case DebuggerProcessState.Terminated:
                evalDisabled = false;
                currentLocation = null;
                currentMethod = null;
                MainWindow.Instance.HideStatus();
                MainWindow.Instance.ClearDebugging();
                break;
            }
        }
Example #23
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var state = theDebugger.ProcessState;
			switch (state) {
			case DebuggerProcessState.Starting:
				InitializeHexStream();
				break;

			case DebuggerProcessState.Continuing:
			case DebuggerProcessState.Running:
			case DebuggerProcessState.Paused:
				break;

			case DebuggerProcessState.Terminated:
				InitializeHexStream();
				break;
			}

			InitializeMemory();
		}
Example #24
0
        void DnDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e)
        {
            if (debugger == null || sender != debugger)
                return;

            CallOnProcessStateChanged(sender, e);

            if (debugger.ProcessState == DebuggerProcessState.Terminated) {
                lastDebugProcessOptions = null;
                RemoveDebugger();
            }

            // This is sometimes needed. Press Ctrl+Shift+F5 a couple of times and the toolbar
            // debugger icons aren't updated until you release Ctrl+Shift.
            if (ProcessState == DebuggerProcessState.Stopped || !IsDebugging)
                CommandManager.InvalidateRequerySuggested();

            if (ProcessState == DebuggerProcessState.Stopped)
                ShowExceptionMessage();
        }
Example #25
0
		void TheDebugger_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var dbg = (DnDebugger)sender;
			switch (ProcessState) {
			case DebuggerProcessState.Starting:
				DebugCallbackEvent_counter = 0;
				dbg.DebugCallbackEvent += DnDebugger_DebugCallbackEvent;
				currentLocation = null;
				currentMethod = null;
				appWindow.StatusBar.Open();
				SetRunningStatusMessage();
				appWindow.AddTitleInfo(dnSpy_Debugger_Resources.AppTitle_Debugging);
				Application.Current.Resources["IsDebuggingKey"] = true;
				break;

			case DebuggerProcessState.Continuing:
				break;

			case DebuggerProcessState.Running:
				if (dbg.IsEvaluating)
					break;
				SetRunningStatusMessage();
				break;

			case DebuggerProcessState.Paused:
				// If we're evaluating, or if eval has completed, don't do a thing. This code
				// should only be executed when a BP hits or if a stepping operation has completed.
				if (dbg.IsEvaluating || dbg.EvalCompleted)
					break;

				BringMainWindowToFrontAndActivate();

				UpdateCurrentLocation();
				if (currentMethod != null && currentLocation != null)
					JumpToCurrentStatement(documentTabService.GetOrCreateActiveTab());

				SetReadyStatusMessage(new StoppedMessageCreator().GetMessage(dbg));
				break;

			case DebuggerProcessState.Terminated:
				dbg.DebugCallbackEvent -= DnDebugger_DebugCallbackEvent;
				currentLocation = null;
				currentMethod = null;
				appWindow.StatusBar.Close();
				lastDebugProcessOptions = null;
				appWindow.RemoveTitleInfo(dnSpy_Debugger_Resources.AppTitle_Debugging);
				Application.Current.Resources["IsDebuggingKey"] = false;
				break;
			}

			// This is sometimes needed. Press Ctrl+Shift+F5 a couple of times and the toolbar
			// debugger icons aren't updated until you release Ctrl+Shift.
			if (dbg.ProcessState == DebuggerProcessState.Paused || !IsDebugging)
				CommandManager.InvalidateRequerySuggested();

			if (dbg.ProcessState == DebuggerProcessState.Paused)
				ShowExceptionMessage();
		}
Example #26
0
		void DebugManager_OnProcessStateChanged(object sender, DebuggerEventArgs e) {
			var dbg = (DnDebugger)sender;
			switch (DebugManager.Instance.ProcessState) {
			case DebuggerProcessState.Starting:
				Collection.Clear();
				InstallDebuggerHooks(dbg);
				break;

			case DebuggerProcessState.Continuing:
			case DebuggerProcessState.Running:
			case DebuggerProcessState.Stopped:
				break;

			case DebuggerProcessState.Terminated:
				UninstallDebuggerHooks(dbg);
				Collection.Clear();
				break;
			}
		}
		void TheDebugger_OnProcessStateChanged_First(object sender, DebuggerEventArgs e) {
			var dbg = (DnDebugger)sender;
			switch (theDebugger.ProcessState) {
			case DebuggerProcessState.Starting:
				classLoader = new ClassLoader(documentTabService, appWindow.MainWindow);
				dbg.OnCorModuleDefCreated += DnDebugger_OnCorModuleDefCreated;
				dbg.DebugCallbackEvent += DnDebugger_DebugCallbackEvent;
				dbg.OnModuleAdded += DnDebugger_OnModuleAdded;
				break;

			case DebuggerProcessState.Continuing:
			case DebuggerProcessState.Running:
				break;

			case DebuggerProcessState.Paused:
				if (dbg.IsEvaluating)
					break;

				LoadNewClasses();
				ReloadInMemoryModulesFromMemory();
				DynamicModulesLoaded?.Invoke(this, EventArgs.Empty);
				break;

			case DebuggerProcessState.Terminated:
				classLoader = null;
				break;
			}
		}