示例#1
0
        void NotifyTargetEvent(MD.Thread thread, MD.TargetEventArgs args)
        {
            if (args.Frame != null)
            {
                activeThread = args.Frame.Thread;
            }

            try {
                if (args.Type == MD.TargetEventType.TargetStopped && ((int)args.Data) != 0)
                {
                    DispatchEvent(delegate {
                        controller.OnDebuggerOutput(false, string.Format("Thread {0:x} received signal {1}.\n", args.Frame.Thread.ID, args.Data));
                    });
                }

                DL.TargetEventType type;

                switch (args.Type)
                {
                case MD.TargetEventType.Exception: type = DL.TargetEventType.ExceptionThrown; break;

                case MD.TargetEventType.TargetHitBreakpoint: type = DL.TargetEventType.TargetHitBreakpoint; break;

                case MD.TargetEventType.TargetInterrupted: type = DL.TargetEventType.TargetInterrupted; break;

                case MD.TargetEventType.TargetSignaled: type = DL.TargetEventType.TargetSignaled; break;

                case MD.TargetEventType.TargetStopped: type = DL.TargetEventType.TargetStopped; break;

                case MD.TargetEventType.UnhandledException: type = DL.TargetEventType.UnhandledException; break;

                default:
                    return;
                }

                OnCleanFrameData();

                DL.TargetEventArgs targetArgs = new DL.TargetEventArgs(type);

                if (args.Type != MD.TargetEventType.TargetExited)
                {
                    ML.TargetObject exception = null;
                    if (args.Type == MD.TargetEventType.UnhandledException || args.Type == MD.TargetEventType.Exception)
                    {
                        exception = args.Frame.ExceptionObject;
                    }
                    targetArgs.Backtrace = CreateBacktrace(thread, exception);
                    targetArgs.Thread    = CreateThreadInfo(activeThread);
                }


                running = false;

                DispatchEvent(delegate {
                    controller.OnTargetEvent(targetArgs);
                });
            } catch (Exception e) {
                Console.WriteLine("*** DS.OnTargetEvent2, exception : {0}", e.ToString());
            }
        }
示例#2
0
 private void OnTargetExitedEvent(MD.Debugger debugger)
 {
     exited = true;
     DispatchEvent(delegate {
         controller.OnDebuggerOutput(false, "Target exited.\n");
         DL.TargetEventArgs args = new DL.TargetEventArgs(DL.TargetEventType.TargetExited);
         controller.OnTargetEvent(args);
     });
 }
		void BreakpointHit(string path, int line)
		{
			foreach (var bp in Breakpoints.GetBreakpoints())
			{
				if(bp.FileName == path && bp.Line == line)
				{
					var args = new TargetEventArgs (TargetEventType.TargetHitBreakpoint);
					args.BreakEvent = bp;
					OnTargetEvent (args);
					break;
				}
			}
		}
示例#4
0
		static void OnTargetEvent (object sender, TargetEventArgs args)
		{
			try {
				switch (args.Type) {
					case TargetEventType.TargetExited:
						Cleanup ();
						break;
					case TargetEventType.TargetSignaled:
					case TargetEventType.TargetStopped:
					case TargetEventType.TargetHitBreakpoint:
					case TargetEventType.TargetInterrupted:
					case TargetEventType.UnhandledException:
					case TargetEventType.ExceptionThrown:
						SetCurrentBacktrace (args.Backtrace);
						NotifyPaused ();
						NotifyException (args);
						break;
					default:
						break;
				}
			} catch (Exception ex) {
				LoggingService.LogError ("Error handling debugger target event", ex);
			}
		}
		void OnProcessExit (object sender, CorProcessEventArgs e)
		{
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetExited);

			// If the main thread stopped, terminate the debugger session
			if (e.Process.Id == process.Id) {
				lock (terminateLock) {
					process = null;
					ThreadPool.QueueUserWorkItem (delegate
					{
						// The Terminate call will fail if called in the event handler
						dbg.Terminate ();
						dbg = null;
						GC.Collect ();
					});
				}
			}

			OnTargetEvent (args);
		}
		void OnStepComplete (object sender, CorStepCompleteEventArgs e)
		{
			lock (debugLock) {
				if (evaluating) {
					e.Continue = true;
					return;
				}
			}
			OnStopped ();
			e.Continue = false;
			SetActiveThread (e.Thread);
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetStopped);
			args.Process = GetProcess (process);
			args.Thread = GetThread (e.Thread);
			args.Backtrace = new Backtrace (new CorBacktrace (e.Thread, this));
			OnTargetEvent (args);
		}
		void HandleBreakEventSet (Event[] es, bool dequeuing)
		{
			if (dequeuing && exited)
				return;
			
			OnHandleBreakEventSet (es);
			
			bool resume = true;
			ObjectMirror exception = null;
			TargetEventType etype = TargetEventType.TargetStopped;
			BreakEvent breakEvent = null;
			
			if (es[0] is ExceptionEvent) {
				var bad = es.FirstOrDefault (ee => !(ee is ExceptionEvent));
				if (bad != null)
					throw new Exception ("Catchpoint eventset had unexpected event type " + bad.GetType ());
				var ev = (ExceptionEvent)es[0];
				if (ev.Request == unhandledExceptionRequest)
					etype = TargetEventType.UnhandledException;
				else
					etype = TargetEventType.ExceptionThrown;
				exception = ev.Exception;
				if (ev.Request != unhandledExceptionRequest || exception.Type.FullName != "System.Threading.ThreadAbortException")
					resume = false;
			}
			else {
				//always need to evaluate all breakpoints, some might be tracepoints or conditional bps with counters
				foreach (Event e in es) {
					BreakpointEvent be = e as BreakpointEvent;
					if (be != null) {
						if (!HandleBreakpoint (e.Thread, be.Request)) {
							etype = TargetEventType.TargetHitBreakpoint;
							BreakInfo binfo;
							if (breakpoints.TryGetValue (be.Request, out binfo))
								breakEvent = binfo.BreakEvent;
							resume = false;
						}
					} else if (e is StepEvent) {
						etype = TargetEventType.TargetStopped;
						resume = false;
					} else {
						throw new Exception ("Break eventset had unexpected event type " + e.GetType ());
					}
				}
			}
			
			if (resume) {
				//all breakpoints were conditional and evaluated as false
				vm.Resume ();
				DequeueEventsForFirstThread ();
			} else {
				if (currentStepRequest != null) {
					currentStepRequest.Enabled = false;
					currentStepRequest = null;
				}
				current_thread = recent_thread = es[0].Thread;
				TargetEventArgs args = new TargetEventArgs (etype);
				args.Process = OnGetProcesses () [0];
				args.Thread = GetThread (args.Process, current_thread);
				args.Backtrace = GetThreadBacktrace (current_thread);
				args.BreakEvent = breakEvent;
				
				if (exception != null)
					activeExceptionsByThread [current_thread.ThreadId] = exception;
				
				OnTargetEvent (args);
			}
		}
		void HandleBreakEventSet (Event[] es, bool dequeuing)
		{
			if (dequeuing && exited)
				return;
			
			bool resume = true;
			bool steppedOut = false;
			bool steppedInto = false;
			bool redoCurrentStep = false;
			ObjectMirror exception = null;
			TargetEventType etype = TargetEventType.TargetStopped;
			BreakEvent breakEvent = null;
			
			if (es[0] is ExceptionEvent) {
				var bad = es.FirstOrDefault (ee => ee.EventType != EventType.Exception);
				if (bad != null)
					throw new Exception ("Catchpoint eventset had unexpected event type " + bad.GetType ());
				var ev = (ExceptionEvent)es[0];
				if (ev.Request == unhandledExceptionRequest)
					etype = TargetEventType.UnhandledException;
				else
					etype = TargetEventType.ExceptionThrown;
				exception = ev.Exception;
				if (ev.Request != unhandledExceptionRequest || exception.Type.FullName != "System.Threading.ThreadAbortException")
					resume = false;
			}
			else {
				//always need to evaluate all breakpoints, some might be tracepoints or conditional bps with counters
				foreach (Event e in es) {
					if (e.EventType == EventType.Breakpoint) {
						var be = e as BreakpointEvent;
						BreakInfo binfo;
						
						if (!HandleBreakpoint (e.Thread, be.Request)) {
							etype = TargetEventType.TargetHitBreakpoint;
							autoStepInto = false;
							resume = false;
						}
						
						if (breakpoints.TryGetValue (be.Request, out binfo)) {
							if (currentStepRequest != null &&
							    binfo.Location.ILOffset == currentAddress && 
							    e.Thread.Id == currentStepRequest.Thread.Id)
								redoCurrentStep = true;
							
							breakEvent = binfo.BreakEvent;
						}
					} else if (e.EventType == EventType.Step) {
						var stepRequest = e.Request as StepEventRequest;
						steppedInto = IsStepIntoRequest (stepRequest);
						steppedOut = IsStepOutRequest (stepRequest);
						etype = TargetEventType.TargetStopped;
						resume = false;
					} else if (e.EventType == EventType.UserBreak) {
						etype = TargetEventType.TargetStopped;
						autoStepInto = false;
						resume = false;
					} else {
						throw new Exception ("Break eventset had unexpected event type " + e.GetType ());
					}
				}
			}
			
			if (redoCurrentStep) {
				StepDepth depth = currentStepRequest.Depth;
				StepSize size = currentStepRequest.Size;
				
				current_thread = recent_thread = es[0].Thread;
				currentStepRequest.Enabled = false;
				currentStepRequest = null;
				
				Step (depth, size);
			} else if (resume) {
				//all breakpoints were conditional and evaluated as false
				vm.Resume ();
				DequeueEventsForFirstThread ();
			} else {
				if (currentStepRequest != null) {
					currentStepRequest.Enabled = false;
					currentStepRequest = null;
				}
				
				current_thread = recent_thread = es[0].Thread;
				
				if (exception != null)
					activeExceptionsByThread [current_thread.ThreadId] = exception;
				
				var backtrace = GetThreadBacktrace (current_thread);
				bool stepOut = false;
				
				if (backtrace.FrameCount > 0) {
					var frame = backtrace.GetFrame (0) as SoftDebuggerStackFrame;
					currentAddress = frame != null ? frame.Address : -1;
					
					if (steppedInto && Options.StepOverPropertiesAndOperators)
						stepOut = frame != null && IsPropertyOrOperatorMethod (frame.StackFrame.Method);
				}
				
				if (stepOut) {
					// We will want to call StepInto once StepOut returns...
					autoStepInto = true;
					Step (StepDepth.Out, StepSize.Min);
				} else if (steppedOut && autoStepInto) {
					autoStepInto = false;
					Step (StepDepth.Into, StepSize.Min);
				} else {
					var args = new TargetEventArgs (etype);
					args.Process = OnGetProcesses () [0];
					args.Thread = GetThread (args.Process, current_thread);
					args.Backtrace = backtrace;
					args.BreakEvent = breakEvent;
					
					OnTargetEvent (args);
				}
			}
		}
示例#9
0
        void ForceExit()
        {
            TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetExited);

            OnTargetEvent(args);
        }
示例#10
0
 public void NotifyTargetEvent(TargetEventArgs args)
 {
     session.OnTargetEvent(args);
 }
示例#11
0
		void ForceExit ()
		{
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetExited);
			OnTargetEvent (args);
		}
示例#12
0
		void FireTargetEvent (TargetEventType type, ResultData curFrame)
		{
			UpdateHitCountData ();

			TargetEventArgs args = new TargetEventArgs (type);
			
			if (type != TargetEventType.TargetExited) {
				GdbCommandResult res = RunCommand ("-stack-info-depth");
				int fcount = int.Parse (res.GetValue ("depth"));
				
				GdbBacktrace bt = new GdbBacktrace (this, activeThread, fcount, curFrame);
				args.Backtrace = new Backtrace (bt);
				args.Thread = GetThread (activeThread);
			}
			OnTargetEvent (args);
		}
示例#13
0
        private static void ExceptionHandler(object sender, TargetEventArgs e, bool firstChance)
        {
            SetBacktrace(e.Backtrace);

            _isPaused = true;
            _isExcepted = !firstChance;

            ExceptionPrinter.Print(Backtrace.CurrentStackFrame.GetException());

            if (CommandLine.Suspended)
                CommandLine.ResumeEvent.Set();
        }
示例#14
0
		protected override void OnExit ()
		{
			lock (gdbLock) {
				InternalStop ();
				RunCommand ("kill");
				TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetExited);
				OnTargetEvent (args);
/*				proc.Kill ();
				TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetExited);
				OnTargetEvent (args);
*/			}
		}
示例#15
0
        void FireBreakPoint(ulong offset)
        {
            TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetHitBreakpoint);

                ulong tempoff = (ulong)offset;
                if (breakpoints.ContainsKey(tempoff))
                {
                    breakpoints[(ulong)tempoff].EventInfo.UpdateHitCount((int)breakpoints[(ulong)tempoff].Breakpoint.HitCount);
                    args.BreakEvent = breakpoints[(ulong)tempoff].EventInfo.BreakEvent;
                }
                else
                {
                    args = new TargetEventArgs(TargetEventType.TargetStopped);
                    BreakEventInfo breakInfo = new BreakEventInfo();
                    breakInfo.Handle = tempoff;
                    breakInfo.SetStatus (BreakEventStatus.Bound, null);
                    string fn;
                    uint ln;
                    if (Engine.Symbols.GetLineByOffset(offset, out fn, out ln))
                    {
                        //breakInfo.BreakEvent = new Breakpoint(fn, (int)ln);
                        args.BreakEvent = breakInfo.BreakEvent;
                    }
                }

                ProcessInfo process = OnGetProcesses()[0];
                args.Process = new ProcessInfo(process.Id, process.Name);

                args.Backtrace = new Backtrace(new DDebugBacktrace(this, activeThread, Engine));

                ThreadPool.QueueUserWorkItem(delegate(object data)
                {
                    try
                    {
                        OnTargetEvent((TargetEventArgs)data);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }, args);
        }
示例#16
0
        protected override void OnExit()
        {
            OnStop();

            TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetExited);
            OnTargetEvent(args);
        }
示例#17
0
 protected override void OnDetach()
 {
     TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetExited);
     OnTargetEvent(args);
 }
		public void OnTargetEvent (TargetEventArgs args)
		{
			frontend.NotifyTargetEvent (args);
			if (args.Type == TargetEventType.TargetExited)
				StopDebugger ();
		}
示例#19
0
		void ForceStop ()
		{
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetStopped);
			OnTargetEvent (args);
		}
示例#20
0
		void HandleEvent (Event e, bool dequeuing)
		{
			if (dequeuing && exited)
				return;

			bool resume = true;
			ObjectMirror exception = null;
			
			TargetEventType etype = TargetEventType.TargetStopped;

#if DEBUG_EVENT_QUEUEING
			if (!(e is TypeLoadEvent))
				Console.WriteLine ("pp event: " + e);
#endif

			OnHandleEvent (e);
			
			if (e is AssemblyLoadEvent) {
				AssemblyLoadEvent ae = (AssemblyLoadEvent)e;
				bool isExternal = !UpdateAssemblyFilters (ae.Assembly) && userAssemblyNames != null;
				string flagExt = isExternal? " [External]" : "";
				OnDebuggerOutput (false, string.Format ("Loaded assembly: {0}{1}\n", ae.Assembly.Location, flagExt));
			}
			
			if (e is AssemblyUnloadEvent) {
				AssemblyUnloadEvent aue = (AssemblyUnloadEvent)e;
				
				// Mark affected breakpoints as pending again
				List<KeyValuePair<EventRequest,BreakInfo>> affectedBreakpoints = new List<KeyValuePair<EventRequest, BreakInfo>> (
					breakpoints.Where (x=> (x.Value.Location.Method.DeclaringType.Assembly.Location.Equals (aue.Assembly.Location, StringComparison.OrdinalIgnoreCase)))
				);
				foreach (KeyValuePair<EventRequest,BreakInfo> breakpoint in affectedBreakpoints) {
					OnDebuggerOutput (false, string.Format ("Re-pending breakpoint at {0}:{1}\n",
					                                        Path.GetFileName (breakpoint.Value.Location.SourceFile),
					                                        breakpoint.Value.Location.LineNumber));
					breakpoints.Remove (breakpoint.Key);
					pending_bes.Add (breakpoint.Value.BreakEvent);
				}
				
				// Remove affected types from the loaded types list
				List<string> affectedTypes = new List<string> (
					from pair in types
					where pair.Value.Assembly.Location.Equals (aue.Assembly.Location, StringComparison.OrdinalIgnoreCase)
					select pair.Key
				);
				foreach (string typename in affectedTypes) {
					types.Remove (typename);
				}
				
				foreach (var pair in source_to_type) {
					pair.Value.RemoveAll (delegate (TypeMirror mirror){
						return mirror.Assembly.Location.Equals (aue.Assembly.Location, StringComparison.OrdinalIgnoreCase);
					});
				}
				OnDebuggerOutput (false, string.Format ("Unloaded assembly: {0}\n", aue.Assembly.Location));
			}
			
			if (e is VMStartEvent) {
				//HACK: 2.6.1 VM doesn't emit type load event, so work around it
				var t = vm.RootDomain.Corlib.GetType ("System.Exception", false, false);
				if (t != null)
					ResolveBreakpoints (t);
				OnVMStartEvent ((VMStartEvent) e);
			}
			
			if (e is TypeLoadEvent) {
				var t = ((TypeLoadEvent)e).Type;
				
				string typeName = t.FullName;
				
				if (types.ContainsKey (typeName)) {
					if (typeName != "System.Exception")
						LoggingService.LogError ("Type '" + typeName + "' loaded more than once", null);
				} else {
					ResolveBreakpoints (t);
				}
			}
			
			if (e is BreakpointEvent) {
				BreakpointEvent be = (BreakpointEvent)e;
				if (!HandleBreakpoint (e.Thread, be.Request)) {
					etype = TargetEventType.TargetHitBreakpoint;
					resume = false;
				}
			}
			
			if (e is ExceptionEvent) {
				etype = TargetEventType.ExceptionThrown;
				var ev = (ExceptionEvent)e;
				exception = ev.Exception;
				if (ev.Request != unhandledExceptionRequest || exception.Type.FullName != "System.Threading.ThreadAbortException")
					resume = false;
			}
			
			if (e is StepEvent) {
				etype = TargetEventType.TargetStopped;
				resume = false;
			}
			
			if (e is ThreadStartEvent) {
				ThreadStartEvent ts = (ThreadStartEvent)e;
				OnDebuggerOutput (false, string.Format ("Thread started: {0}\n", ts.Thread.Name));
			}
			
			if (resume)
				vm.Resume ();
			else {
				if (currentStepRequest != null) {
					currentStepRequest.Enabled = false;
					currentStepRequest = null;
				}
				current_thread = recent_thread = e.Thread;
				TargetEventArgs args = new TargetEventArgs (etype);
				args.Process = OnGetProcesses () [0];
				args.Thread = GetThread (args.Process, current_thread);
				args.Backtrace = GetThreadBacktrace (current_thread);
				
				if (exception != null)
					activeExceptionsByThread [current_thread.Id] = exception;
				
				OnTargetEvent (args);
			}
		}
示例#21
0
		internal protected void OnTargetEvent (TargetEventArgs args)
		{
			currentProcesses = null;
			
			if (args.Process != null)
				args.Process.Attach (this);
			if (args.Thread != null) {
				args.Thread.Attach (this);
				activeThread = args.Thread;
			}
			if (args.Backtrace != null)
				args.Backtrace.Attach (this);
			
			switch (args.Type) {
				case TargetEventType.ExceptionThrown:
					lock (slock) {
						isRunning = false;
						args.IsStopEvent = true;
					}
					if (TargetExceptionThrown != null)
						TargetExceptionThrown (this, args);
					break;
				case TargetEventType.TargetExited:
					lock (slock) {
						isRunning = false;
						started = false;
					}
					if (TargetExited != null)
						TargetExited (this, args);
					break;
				case TargetEventType.TargetHitBreakpoint:
					lock (slock) {
						isRunning = false;
						args.IsStopEvent = true;
					}
					if (TargetHitBreakpoint != null)
						TargetHitBreakpoint (this, args);
					break;
				case TargetEventType.TargetInterrupted:
					lock (slock) {
						isRunning = false;
						args.IsStopEvent = true;
					}
					if (TargetInterrupted != null)
						TargetInterrupted (this, args);
					break;
				case TargetEventType.TargetSignaled:
					lock (slock) {
						isRunning = false;
						args.IsStopEvent = true;
					}
					if (TargetSignaled != null)
						TargetSignaled (this, args);
					break;
				case TargetEventType.TargetStopped:
					lock (slock) {
						isRunning = false;
						args.IsStopEvent = true;
					}
					if (TargetStopped != null)
						TargetStopped (this, args);
					break;
				case TargetEventType.UnhandledException:
					lock (slock) {
						isRunning = false;
						args.IsStopEvent = true;
					}
					if (TargetUnhandledException != null)
						TargetUnhandledException (this, args);
					break;
				case TargetEventType.TargetReady:
					if (TargetReady != null)
						TargetReady (this, args);
					break;
				case TargetEventType.ThreadStarted:
					if (TargetThreadStarted != null)
						TargetThreadStarted (this, args);
					break;
				case TargetEventType.ThreadStopped:
					if (TargetThreadStopped != null)
						TargetThreadStopped (this, args);
					break;
			}
			if (TargetEvent != null)
				TargetEvent (this, args);
		}
示例#22
0
		internal protected void OnTargetEvent (TargetEventArgs args)
		{
			currentProcesses = null;
			
			if (args.Process != null)
				args.Process.Attach (this);
			if (args.Thread != null) {
				args.Thread.Attach (this);
				activeThread = args.Thread;
			}
			if (args.Backtrace != null)
				args.Backtrace.Attach (this);

			EventHandler<TargetEventArgs> evnt = null;
			switch (args.Type) {
			case TargetEventType.ExceptionThrown:
				lock (slock) {
					IsRunning = false;
					args.IsStopEvent = true;
				}
				evnt = TargetExceptionThrown;
				break;
			case TargetEventType.TargetExited:
				lock (slock) {
					IsRunning = false;
					IsConnected = false;
					HasExited = true;
				}
				EventHandler handler = TargetExited;
				if (handler != null)
					handler (this, args);
				break;
			case TargetEventType.TargetHitBreakpoint:
				lock (slock) {
					IsRunning = false;
					args.IsStopEvent = true;
				}
				evnt = TargetHitBreakpoint;
				break;
			case TargetEventType.TargetInterrupted:
				lock (slock) {
					IsRunning = false;
					args.IsStopEvent = true;
				}
				evnt = TargetInterrupted;
				break;
			case TargetEventType.TargetSignaled:
				lock (slock) {
					IsRunning = false;
					args.IsStopEvent = true;
				}
				evnt = TargetSignaled;
				break;
			case TargetEventType.TargetStopped:
				lock (slock) {
					IsRunning = false;
					args.IsStopEvent = true;
				}
				evnt = TargetStopped;
				break;
			case TargetEventType.UnhandledException:
				lock (slock) {
					IsRunning = false;
					args.IsStopEvent = true;
				}
				evnt = TargetUnhandledException;
				break;
			case TargetEventType.TargetReady:
				evnt = TargetReady;
				break;
			case TargetEventType.ThreadStarted:
				evnt = TargetThreadStarted;
				break;
			case TargetEventType.ThreadStopped:
				evnt = TargetThreadStopped;
				break;
			}

			if (evnt != null)
				evnt (this, args);

			EventHandler<TargetEventArgs> targetEvent = TargetEvent;
			if (targetEvent != null)
				targetEvent (this, args);
		}
示例#23
0
        void ForceStop()
        {
            TargetEventArgs args = new TargetEventArgs(TargetEventType.TargetStopped);

            OnTargetEvent(args);
        }
示例#24
0
文件: Executer.cs 项目: minuowa/Monos
 private void MDebuggerSession_TargetStopped(object sender, TargetEventArgs e)
 {
     mDoneEvent.Set();
 }
示例#25
0
        internal protected void OnTargetEvent(TargetEventArgs args)
        {
            currentProcesses = null;

            if (args.Process != null)
            {
                args.Process.Attach(this);
            }
            if (args.Thread != null)
            {
                args.Thread.Attach(this);
                activeThread = args.Thread;
            }
            if (args.Backtrace != null)
            {
                args.Backtrace.Attach(this);
            }

            switch (args.Type)
            {
            case TargetEventType.ExceptionThrown:
                lock (slock) {
                    isRunning = false;
                }
                if (TargetExceptionThrown != null)
                {
                    TargetExceptionThrown(this, args);
                }
                break;

            case TargetEventType.TargetExited:
                lock (slock) {
                    isRunning = false;
                    started   = false;
                    foreach (BreakEvent bp in Breakpoints)
                    {
                        Breakpoints.NotifyStatusChanged(bp);
                    }
                }
                if (TargetExited != null)
                {
                    TargetExited(this, args);
                }
                break;

            case TargetEventType.TargetHitBreakpoint:
                lock (slock) {
                    isRunning = false;
                }
                if (TargetHitBreakpoint != null)
                {
                    TargetHitBreakpoint(this, args);
                }
                break;

            case TargetEventType.TargetInterrupted:
                lock (slock) {
                    isRunning = false;
                }
                if (TargetInterrupted != null)
                {
                    TargetInterrupted(this, args);
                }
                break;

            case TargetEventType.TargetSignaled:
                lock (slock) {
                    isRunning = false;
                }
                if (TargetSignaled != null)
                {
                    TargetSignaled(this, args);
                }
                break;

            case TargetEventType.TargetStopped:
                lock (slock) {
                    isRunning = false;
                }
                if (TargetStopped != null)
                {
                    TargetStopped(this, args);
                }
                break;

            case TargetEventType.UnhandledException:
                lock (slock) {
                    isRunning = false;
                }
                if (TargetUnhandledException != null)
                {
                    TargetUnhandledException(this, args);
                }
                break;
            }
            if (TargetEvent != null)
            {
                TargetEvent(this, args);
            }
        }
示例#26
0
 void FireTargetEvent(TargetEventType type)
 {
     TargetEventArgs args = new TargetEventArgs (type);
     if (type != TargetEventType.TargetExited) {
         HxcppBacktrace bt = new HxcppBacktrace (this, lastResult.depth + 1, lastResult.threadId);
         args.Backtrace = new Backtrace (bt);
         args.Thread = GetThread (0);
     }
     OnTargetEvent (args);
 }
		static void OnTargetEvent (object sender, TargetEventArgs args)
		{
			try {
				Console.WriteLine ("OnTargetEvent, type - {0}", args.Type);

				switch (args.Type) {
					case TargetEventType.TargetExited:
						Cleanup ();
						break;
					case TargetEventType.TargetSignaled:
					case TargetEventType.TargetStopped:
					case TargetEventType.TargetHitBreakpoint:
					case TargetEventType.TargetInterrupted:
					case TargetEventType.UnhandledException:
					case TargetEventType.ExceptionThrown:
						SetCurrentBacktrace (args.Backtrace);
						NotifyPaused ();
						NotifyException (args);
						break;
					default:
						break;
				}
			} catch (Exception e) {
				Console.WriteLine ("OnTargetEvent, {0}", e.ToString ());
			}
		}
示例#28
0
		static void OnTargetEvent (object sender, TargetEventArgs args)
		{
			nextStatementLocations.Clear ();

			try {
				switch (args.Type) {
				case TargetEventType.TargetExited:
					Breakpoints.RemoveRunToCursorBreakpoints ();
					Cleanup ();
					break;
				case TargetEventType.TargetSignaled:
				case TargetEventType.TargetStopped:
				case TargetEventType.TargetHitBreakpoint:
				case TargetEventType.TargetInterrupted:
				case TargetEventType.UnhandledException:
				case TargetEventType.ExceptionThrown:
					Breakpoints.RemoveRunToCursorBreakpoints ();
					SetCurrentBacktrace (args.Backtrace);
					NotifyPaused ();
					NotifyException (args);
					break;
				}
			} catch (Exception ex) {
				LoggingService.LogError ("Error handling debugger target event", ex);
			}
		}
示例#29
0
		void HandleEvent (Event e)
		{
			OnHandleEvent (e);
			
			if (e is AssemblyLoadEvent) {
				AssemblyLoadEvent ae = (AssemblyLoadEvent)e;
				bool isExternal = !UpdateAssemblyFilters (ae.Assembly) && userAssemblyNames != null;
				string flagExt = isExternal? " [External]" : "";
				OnDebuggerOutput (false, string.Format ("Loaded assembly: {0}{1}\n", ae.Assembly.Location, flagExt));
			}
			else if (e is AssemblyUnloadEvent) {
				AssemblyUnloadEvent aue = (AssemblyUnloadEvent)e;
				
				// Mark affected breakpoints as pending again
				List<KeyValuePair<EventRequest,BreakInfo>> affectedBreakpoints = new List<KeyValuePair<EventRequest, BreakInfo>> (
					breakpoints.Where (x=> (x.Value.Location.Method.DeclaringType.Assembly.Location.Equals (aue.Assembly.Location, StringComparison.OrdinalIgnoreCase)))
				);
				foreach (KeyValuePair<EventRequest,BreakInfo> breakpoint in affectedBreakpoints) {
					string file = PathToFileName (breakpoint.Value.Location.SourceFile);
					int line = breakpoint.Value.Location.LineNumber;
					OnDebuggerOutput (false, string.Format ("Re-pending breakpoint at {0}:{1}\n", file, line));
					breakpoints.Remove (breakpoint.Key);
					pending_bes.Add (breakpoint.Value.BreakEvent);
				}
				
				// Remove affected types from the loaded types list
				List<string> affectedTypes = new List<string> (
					from pair in types
					where pair.Value.Assembly.Location.Equals (aue.Assembly.Location, StringComparison.OrdinalIgnoreCase)
					select pair.Key
				);
				foreach (string typename in affectedTypes) {
					types.Remove (typename);
				}
				
				foreach (var pair in source_to_type) {
					pair.Value.RemoveAll (delegate (TypeMirror mirror){
						return mirror.Assembly.Location.Equals (aue.Assembly.Location, StringComparison.OrdinalIgnoreCase);
					});
				}
				OnDebuggerOutput (false, string.Format ("Unloaded assembly: {0}\n", aue.Assembly.Location));
			}
			else if (e is VMStartEvent) {
				//HACK: 2.6.1 VM doesn't emit type load event, so work around it
				var t = vm.RootDomain.Corlib.GetType ("System.Exception", false, false);
				if (t != null)
					ResolveBreakpoints (t);
				OnVMStartEvent ((VMStartEvent) e);
			}
			else if (e is TypeLoadEvent) {
				var t = ((TypeLoadEvent)e).Type;
				
				string typeName = t.FullName;
				
				if (types.ContainsKey (typeName)) {
					if (typeName != "System.Exception")
						LoggingService.LogError ("Type '" + typeName + "' loaded more than once", null);
				} else {
					ResolveBreakpoints (t);
				}
			}
			else if (e is ThreadStartEvent) {
				ThreadStartEvent ts = (ThreadStartEvent)e;
				OnDebuggerOutput (false, string.Format ("Thread started: {0}\n", ts.Thread.Name));
				TargetEventArgs args = new TargetEventArgs (TargetEventType.ThreadStarted);
				args.Thread = new ThreadInfo (0, GetId (ts.Thread), ts.Thread.Name, null);
				OnTargetEvent (args);
			}
			else if (e is ThreadDeathEvent) {
				ThreadDeathEvent ts = (ThreadDeathEvent)e;
				OnDebuggerOutput (false, string.Format ("Thread finished: {0}\n", ts.Thread.Name));
				TargetEventArgs args = new TargetEventArgs (TargetEventType.ThreadStarted);
				args.Thread = new ThreadInfo (0, GetId (ts.Thread), ts.Thread.Name, null);
				OnTargetEvent (args);
			}
		}
		void OnBreakpoint (object sender, CorBreakpointEventArgs e)
		{
			lock (debugLock) {
				if (evaluating) {
					e.Continue = true;
					return;
				}
			}

			BreakEventInfo binfo;
			if (breakpoints.TryGetValue (e.Breakpoint, out binfo)) {
				e.Continue = true;
				Breakpoint bp = (Breakpoint)binfo.BreakEvent;
				
				if (bp.HitCount > 1) {
					// Just update the count and continue
					binfo.UpdateHitCount (bp.HitCount - 1);
					return;
				}
				
				if (!string.IsNullOrEmpty (bp.ConditionExpression)) {
					string res = EvaluateExpression (e.Thread, bp.ConditionExpression);
					if (bp.BreakIfConditionChanges) {
						if (res == bp.LastConditionValue)
							return;
						bp.LastConditionValue = res;
					} else {
						if (res != null && res.ToLower () == "false")
							return;
					}
				}
				switch (bp.HitAction) {
					case HitAction.CustomAction:
						// If custom action returns true, execution must continue
						if (binfo.RunCustomBreakpointAction (bp.CustomActionId))
							return;
						break;
					case HitAction.PrintExpression: {
						string exp = EvaluateTrace (e.Thread, bp.TraceExpression);
						binfo.UpdateLastTraceValue (exp);
						return;
					}
				}
			}
			
			OnStopped ();
			e.Continue = false;
			// If a breakpoint is hit while stepping, cancel the stepping operation
			if (stepper != null && stepper.IsActive ())
				stepper.Deactivate ();
			SetActiveThread (e.Thread);
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetHitBreakpoint);
			args.Process = GetProcess (process);
			args.Thread = GetThread (e.Thread);
			args.Backtrace = new Backtrace (new CorBacktrace (e.Thread, this));
			OnTargetEvent (args);
		}
		void OnBreakpoint (object sender, CorBreakpointEventArgs e)
		{
			lock (debugLock) {
				if (evaluating) {
					e.Continue = true;
					return;
				}
			}
			OnStopped ();
			e.Continue = false;
			// If a breakpoint is hit while stepping, cancel the stepping operation
			if (stepper != null && stepper.IsActive ())
				stepper.Deactivate ();
			SetActiveThread (e.Thread);
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetHitBreakpoint);
			args.Process = GetProcess (process);
			args.Thread = GetThread (e.Thread);
			args.Backtrace = new Backtrace (new CorBacktrace (e.Thread, this));
			OnTargetEvent (args);
		}
		void OnException2 (object sender, CorException2EventArgs e)
		{
			lock (debugLock) {
				if (evaluating) {
					e.Continue = true;
					return;
				}
			}
			
			TargetEventArgs args = null;
			
			switch (e.EventType) {
				case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_FIRST_CHANCE:
					if (!this.Options.ProjectAssembliesOnly && IsCatchpoint (e))
						args = new TargetEventArgs (TargetEventType.ExceptionThrown);
					break;
				case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_USER_FIRST_CHANCE:
					if (IsCatchpoint (e))
						args = new TargetEventArgs (TargetEventType.ExceptionThrown);
					break;
				case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_CATCH_HANDLER_FOUND:
					break;
				case CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED:
					args = new TargetEventArgs (TargetEventType.UnhandledException);
					break;
			}
			
			if (args != null) {
				OnStopped ();
				e.Continue = false;
				// If an exception is thrown while stepping, cancel the stepping operation
				if (stepper != null && stepper.IsActive ())
					stepper.Deactivate ();

				SetActiveThread (e.Thread);
				
				args.Process = GetProcess (process);
				args.Thread = GetThread (e.Thread);
				args.Backtrace = new Backtrace (new CorBacktrace (e.Thread, this));
				OnTargetEvent (args);	
			}
		}
		protected override void OnStop ( )
		{
			process.Stop (0);
			OnStopped ();
			CorThread currentThread = null;
			foreach (CorThread t in process.Threads) {
				currentThread = t;
				break;
			}
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetStopped);
			args.Process = GetProcess (process);
			args.Thread = GetThread (currentThread);
			args.Backtrace = new Backtrace (new CorBacktrace (currentThread, this));
			OnTargetEvent (args);
		}
示例#34
0
		public void NotifyTargetEvent (TargetEventArgs args)
		{
			session.OnTargetEvent (args);
		}
示例#35
0
		static void NotifyException (TargetEventArgs args)
		{
			if (args.Type == TargetEventType.UnhandledException || args.Type == TargetEventType.ExceptionThrown) {
				DispatchService.GuiDispatch (delegate {
					if (CurrentFrame != null) {
						ShowExceptionCaughtDialog ();
					}
				});
			}
		}
		int ICorDebugManagedCallback.StepComplete (CorDebugAppDomain pAppDomain, CorDebugThread pThread, CorDebugStepper pStepper, CorDebugStepReason reason)
		{
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetStopped);
			args.Process = GetProcess (pAppDomain.Process);
			args.Thread = pAppDomain.Process.GetThread (pThread);
			args.Backtrace = new Backtrace (new CorDebugBacktrace (pThread, this));
			OnTargetEvent (args);
			SetActiveThread (pThread);
			return 0;
		}