public void Debug(int processID) { debugger = new CorDebugger(CorDebugger.GetDefaultDebuggerVersion()); process = debugger.DebugActiveProcess(processID, false); process.OnException += OnException; process.OnCreateAppDomain += OnNewAppDomain; process.OnProcessExit += OnExit; process.OnModuleLoad += OnModuleLoad; process.OnBreakpoint += OnBreakpoint; process.OnStepComplete += OnStepComplete; process.Continue(false); state = ProcessState.Started; subscriber.Published(string.Format("Successfully attached to Process with ID [{0}]", processID)); }
protected override void OnRun (DebuggerStartInfo startInfo) { // Create the debugger string dversion; try { dversion = CorDebugger.GetDebuggerVersionFromFile (startInfo.Command); } catch { dversion = CorDebugger.GetDefaultDebuggerVersion (); } dbg = new CorDebugger (dversion); Dictionary<string, string> env = new Dictionary<string, string> (); foreach (DictionaryEntry de in Environment.GetEnvironmentVariables ()) env[(string) de.Key] = (string) de.Value; foreach (KeyValuePair<string, string> var in startInfo.EnvironmentVariables) env[var.Key] = var.Value; // The second parameter of CreateProcess is the command line, and it includes the application being launched string cmdLine = "\"" + startInfo.Command + "\" " + startInfo.Arguments; int flags = 0; if (!startInfo.UseExternalConsole) { flags = 0x08000000; /* CREATE_NO_WINDOW*/ flags |= CorDebugger.CREATE_REDIRECT_STD; } process = dbg.CreateProcess (startInfo.Command, cmdLine, startInfo.WorkingDirectory, env, flags); processId = process.Id; process.OnCreateProcess += new CorProcessEventHandler (OnCreateProcess); process.OnCreateAppDomain += new CorAppDomainEventHandler (OnCreateAppDomain); process.OnAssemblyLoad += new CorAssemblyEventHandler (OnAssemblyLoad); process.OnAssemblyUnload += new CorAssemblyEventHandler (OnAssemblyUnload); process.OnCreateThread += new CorThreadEventHandler (OnCreateThread); process.OnThreadExit += new CorThreadEventHandler (OnThreadExit); process.OnModuleLoad += new CorModuleEventHandler (OnModuleLoad); process.OnModuleUnload += new CorModuleEventHandler (OnModuleUnload); process.OnProcessExit += new CorProcessEventHandler (OnProcessExit); process.OnUpdateModuleSymbols += new UpdateModuleSymbolsEventHandler (OnUpdateModuleSymbols); process.OnDebuggerError += new DebuggerErrorEventHandler (OnDebuggerError); process.OnBreakpoint += new BreakpointEventHandler (OnBreakpoint); process.OnStepComplete += new StepCompleteEventHandler (OnStepComplete); process.OnBreak += new CorThreadEventHandler (OnBreak); process.OnNameChange += new CorThreadEventHandler (OnNameChange); process.OnEvalComplete += new EvalEventHandler (OnEvalComplete); process.OnEvalException += new EvalEventHandler (OnEvalException); process.OnLogMessage += new LogMessageEventHandler (OnLogMessage); process.OnStdOutput += new CorTargetOutputEventHandler (OnStdOutput); process.Continue (false); OnStarted (); }