void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) {
			if (e.Type == DebugCallbackType.CreateProcess) {
				dbg.DebugCallbackEvent -= DnDebugger_DebugCallbackEvent;
				var cpArgs = (CreateProcessDebugCallbackEventArgs)e;
				bool b = Initialize(cpArgs.CorProcess, dbg.DebuggeeVersion);
				Debug.Assert(b);
			}
		}
Esempio n. 2
0
		void InstallDebuggerHooks(DnDebugger dbg) {
			dbg.OnModuleAdded += DnDebugger_OnModuleAdded;
			dbg.OnNameChanged += DnDebugger_OnNameChanged;
			var modules = GetAllModules(dbg).ToArray();
			Array.Sort(modules, (a, b) => a.ModuleOrder.CompareTo(b.ModuleOrder));
			foreach (var module in modules)
				Add(module);
		}
Esempio n. 3
0
		public BreakProcessHelper(DnDebugger debugger, BreakProcessKind type, string filename) {
			if (debugger == null)
				throw new ArgumentNullException();
			this.debugger = debugger;
			this.type = type;
			this.filename = filename;
			AddStartupBreakpoint();
		}
Esempio n. 4
0
 internal DnProcess(DnDebugger ownerDebugger, ICorDebugProcess process, int incrementedId)
 {
     this.ownerDebugger = ownerDebugger;
     this.appDomains = new DebuggerCollection<ICorDebugAppDomain, DnAppDomain>(CreateAppDomain);
     this.threads = new DebuggerCollection<ICorDebugThread, DnThread>(CreateThread);
     this.process = new CorProcess(process);
     this.incrementedId = incrementedId;
 }
Esempio n. 5
0
		public void Initialize(DnDebugger dbg) {
			Debug.Assert(debugger.Dispatcher.CheckAccess());
			Debug.Assert(dbgBreakpoint == null);
			if (dbgBreakpoint != null)
				throw new InvalidOperationException();
			dbgBreakpoint = dbg.CreateBreakpoint(EventKind.ToDebugEventBreakpointKind(), HitHandler);
			dbgBreakpoint.IsEnabled = isEnabled;
			dbgBreakpoint.Tag = this;
		}
Esempio n. 6
0
		void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) {
			if (nameErrorCounter != 0 && e.Type == DebugCallbackType.LoadClass) {
				var lcArgs = (LoadClassDebugCallbackEventArgs)e;
				var module = dbg.TryGetModule(lcArgs.CorAppDomain, lcArgs.CorClass);
				Debug.Assert(module != null);
				if (module != null && module.IsDynamic)
					pendingModules.Add(module.SerializedDnModule);
			}
		}
Esempio n. 7
0
		static IEnumerable<DnModule> GetAllModules(DnDebugger dbg) {
			foreach (var process in dbg.Processes) {
				foreach (var appDomain in process.AppDomains) {
					foreach (var assembly in appDomain.Assemblies) {
						foreach (var module in assembly.Modules)
							yield return module;
					}
				}
			}
		}
Esempio n. 8
0
        void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
        {
            try {
                DebugCallbackEvent_counter++;

                if (DebugCallbackEvent_counter > 1)
                    return;
                if (e.Type == DebugCallbackType.Exception2) {
                    var ee = (Exception2DebugCallbackEventArgs)e;
                    if (ee.EventType == CorDebugExceptionCallbackType.DEBUG_EXCEPTION_UNHANDLED)
                        UnhandledException(ee);
                }
                else if (e.Type == DebugCallbackType.DebuggerError)
                    OnDebuggerError((DebuggerErrorDebugCallbackEventArgs)e);
            }
            finally {
                DebugCallbackEvent_counter--;
            }
        }
		public static void Initialize(DnDebugger debugger) {
			new DisableSystemDebuggerDetection(debugger);
		}
Esempio n. 10
0
        void AddDebugger(DnDebugger newDebugger)
        {
            RemoveDebugger();

            debugger = newDebugger;
            DebugCallbackEvent_counter = 0;
            newDebugger.OnProcessStateChanged += DnDebugger_OnProcessStateChanged;
            newDebugger.DebugCallbackEvent += DnDebugger_DebugCallbackEvent;
        }
Esempio n. 11
0
 void CallOnProcessStateChanged(DnDebugger dbg = null)
 {
     CallOnProcessStateChanged(dbg ?? debugger, DebuggerEventArgs.Empty);
 }
Esempio n. 12
0
        void Debugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
        {
            var ee = e as EvalDebugCallbackEventArgs;
            if (ee == null)
                return;

            if (ee.Eval == eval.RawObject) {
                debugger.DebugCallbackEvent -= Debugger_DebugCallbackEvent;
                e.AddStopReason(DebuggerStopReason.Eval);
                debugMessageDispatcher.CancelDispatchQueue(ee.WasException);
                return;
            }
        }
Esempio n. 13
0
        static MethodKey? CreateMethodKey(DnDebugger debugger, CorFrame frame)
        {
            var sma = frame.GetSerializedDnModuleWithAssembly();
            if (sma == null)
                return null;

            return MethodKey.Create(frame.Token, sma.Value.Module);
        }
Esempio n. 14
0
 static DnDebugger CreateDnDebuggerCoreCLR(DebugProcessOptions options)
 {
     var clrType = (CoreCLRTypeDebugInfo)options.CLRTypeDebugInfo;
     var dbg2 = CoreCLRHelper.CreateDnDebugger(options, clrType, () => false, (cd, pid) => {
         var dbg = new DnDebugger(cd, options.DebugOptions, options.DebugMessageDispatcher, null);
         if (options.BreakProcessType != BreakProcessType.None)
             new BreakProcessHelper(dbg, options.BreakProcessType, options.Filename);
         ICorDebugProcess comProcess;
         cd.DebugActiveProcess((int)pid, 0, out comProcess);
         var dnProcess = dbg.TryAdd(comProcess);
         if (dnProcess != null)
             dnProcess.Initialize(false, options.Filename, options.CurrentDirectory, options.CommandLine);
         return dbg;
     });
     if (dbg2 == null)
         throw new Exception("Could not create a debugger instance");
     return dbg2;
 }
Esempio n. 15
0
 void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e)
 {
     if (e.Type == DebugCallbackType.Exception2)
         OnException((Exception2DebugCallbackEventArgs)e);
 }
		public AnyDebugEventBreakpointConditionContext(DnDebugger debugger, DnAnyDebugEventBreakpoint bp, DebugCallbackEventArgs e)
			: base(debugger) {
			AnyDebugEventBreakpoint = bp;
			EventArgs = e;
		}
Esempio n. 17
0
		void UninstallDebuggerHooks(DnDebugger dbg) {
			dbg.OnModuleAdded -= DnDebugger_OnModuleAdded;
			dbg.OnNameChanged -= DnDebugger_OnNameChanged;
		}
Esempio n. 18
0
		void AddDebugger(DnDebugger newDebugger) {
			RemoveDebugger();

			debugger = newDebugger;
			newDebugger.OnProcessStateChanged += DnDebugger_OnProcessStateChanged;
		}
Esempio n. 19
0
		public void Initialize(DnDebugger newDebugger) {
			foreach (var l in loadBeforeDebugInsts) {
				var o = l.Value;
			}
			if (debuggerSettings.DisableManagedDebuggerDetection)
				DisableSystemDebuggerDetection.Initialize(newDebugger);
			AddDebugger(newDebugger);
			Debug.Assert(debugger == newDebugger);
			CallOnProcessStateChanged();
		}
Esempio n. 20
0
 internal DnEval(DnDebugger debugger, IDebugMessageDispatcher debugMessageDispatcher)
 {
     this.debugger = debugger;
     this.debugMessageDispatcher = debugMessageDispatcher;
     this.suspendOtherThreads = true;
 }
		DisableSystemDebuggerDetection(DnDebugger debugger) {
			debugger.DebugCallbackEvent += DnDebugger_DebugCallbackEvent;
		}
Esempio n. 22
0
		public void RemoveDebugger() {
			if (debugger == null)
				return;

			debugger.OnProcessStateChanged -= DnDebugger_OnProcessStateChanged;
			debugger = null;

			// HACK: Something still holds a reference to the debugged file perhaps
			// one of the debugger COM instances.
			// This thing will clean up if we just let the GC collect it.
			GC.Collect();
			GC.WaitForPendingFinalizers();
		}
Esempio n. 23
0
		public StackFramesUpdatedEventArgs(DnDebugger debugger) {
			this.Debugger = debugger;
		}
Esempio n. 24
0
            public string GetMessage(DnDebugger debugger)
            {
                if (debugger == null || debugger.ProcessState != DebuggerProcessState.Stopped)
                    return null;

                sb = new StringBuilder();

                bool seenIlbp = false;
                foreach (var state in debugger.DebuggerStates) {
                    foreach (var stopState in state.StopStates) {
                        switch (stopState.Reason) {
                        case DebuggerStopReason.Other:
                            Append("Unknown Reason");
                            break;

                        case DebuggerStopReason.UnhandledException:
                            Append("Unhandled Exception");
                            break;

                        case DebuggerStopReason.Exception:
                            Append("Exception");
                            break;

                        case DebuggerStopReason.DebugEventBreakpoint:
                            if (state.EventArgs != null)
                                Append(GetEventDescription(state.EventArgs));
                            else
                                Append("DebugEvent");
                            break;

                        case DebuggerStopReason.AnyDebugEventBreakpoint:
                            if (state.EventArgs != null)
                                Append(GetEventDescription(state.EventArgs));
                            else
                                Append("Any DebugEvent");
                            break;

                        case DebuggerStopReason.Break:
                            Append("Break Instruction");
                            break;

                        case DebuggerStopReason.ILCodeBreakpoint:
                            if (seenIlbp)
                                break;
                            seenIlbp = true;
                            Append("IL Breakpoint");
                            break;

                        case DebuggerStopReason.Step:
                            break;
                        }
                    }
                }

                return sb.ToString();
            }
Esempio n. 25
0
        StepRange[] GetStepRanges(DnDebugger debugger, CorFrame frame, bool isStepInto)
        {
            if (frame == null)
                return null;
            if (!frame.IsILFrame)
                return null;
            if (frame.ILFrameIP.IsUnmappedAddress)
                return null;

            var key = CreateMethodKey(debugger, frame);
            if (key == null)
                return null;

            MemberMapping mapping;
            var textView = MainWindow.Instance.SafeActiveTextView;
            var cm = textView.CodeMappings;
            if (cm == null || !cm.TryGetValue(key.Value, out mapping)) {
                // User has decompiled some other code or switched to another tab
                UpdateCurrentMethod();
                JumpToCurrentStatement(textView);

                // It could be cached and immediately available. Check again
                cm = textView.CodeMappings;
                if (cm == null || !cm.TryGetValue(key.Value, out mapping))
                    return null;
            }

            bool isMatch;
            var scm = mapping.GetInstructionByOffset(frame.GetILOffset(), out isMatch);
            uint[] ilRanges;
            if (scm == null)
                ilRanges = mapping.ToArray(null, false);
            else
                ilRanges = scm.ToArray(isMatch);

            if (ilRanges.Length == 0)
                return null;
            return CreateStepRanges(ilRanges);
        }
Esempio n. 26
0
		void DnDebugger_DebugCallbackEvent(DnDebugger dbg, DebugCallbackEventArgs e) {
			if (e.Type == DebugCallbackType.LoadClass) {
				var lc = (LoadClassDebugCallbackEventArgs)e;
				var cls = lc.CorClass;
				var dnModule = dbg.TryGetModule(lc.CorAppDomain, cls);
				OnLoadClass(dnModule, cls);
			}
			else if (e.Type == DebugCallbackType.UnloadClass) {
				var uc = (UnloadClassDebugCallbackEventArgs)e;
				var cls = uc.CorClass;
				var dnModule = dbg.TryGetModule(uc.CorAppDomain, cls);
				OnUnloadClass(dnModule, cls);
			}
		}
Esempio n. 27
0
        public static DnDebugger Attach(AttachProcessOptions options)
        {
            var process = Process.GetProcessById(options.ProcessId);
            var filename = process.MainModule.FileName;

            string debuggeeVersion;
            var corDebug = CreateCorDebug(options, out debuggeeVersion);
            if (corDebug == null)
                throw new Exception("An ICorDebug instance couldn't be created");
            var dbg = new DnDebugger(corDebug, options.DebugOptions, options.DebugMessageDispatcher, debuggeeVersion);
            ICorDebugProcess comProcess;
            corDebug.DebugActiveProcess(options.ProcessId, 0, out comProcess);
            var dnProcess = dbg.TryAdd(comProcess);
            if (dnProcess != null)
                dnProcess.Initialize(true, filename, string.Empty, string.Empty);
            return dbg;
        }
Esempio n. 28
0
 void Initialize(DnDebugger newDebugger)
 {
     if (DebuggerSettings.Instance.DisableManagedDebuggerDetection)
         DisableSystemDebuggerDetection.Initialize(newDebugger);
     AddDebugger(newDebugger);
     Debug.Assert(debugger == newDebugger);
     CallOnProcessStateChanged();
 }
Esempio n. 29
0
 static DnDebugger CreateDnDebuggerDesktop(DebugProcessOptions options)
 {
     var clrType = (DesktopCLRTypeDebugInfo)options.CLRTypeDebugInfo;
     var debuggeeVersion = clrType.DebuggeeVersion ?? DebuggeeVersionDetector.GetVersion(options.Filename);
     var corDebug = CreateCorDebug(debuggeeVersion);
     if (corDebug == null)
         throw new Exception("Could not create an ICorDebug instance");
     var dbg = new DnDebugger(corDebug, options.DebugOptions, options.DebugMessageDispatcher, debuggeeVersion);
     if (options.BreakProcessType != BreakProcessType.None)
         new BreakProcessHelper(dbg, options.BreakProcessType, options.Filename);
     dbg.CreateProcess(options);
     return dbg;
 }
Esempio n. 30
0
        void RemoveDebugger()
        {
            if (debugger == null)
                return;

            debugger.OnProcessStateChanged -= DnDebugger_OnProcessStateChanged;
            debugger = null;
        }