Beispiel #1
1
		internal StackFrame(Thread thread, ICorDebugILFrame corILFrame, uint chainIndex, uint frameIndex)
		{
			this.process = thread.Process;
			this.thread = thread;
			this.appDomain = process.AppDomains[corILFrame.GetFunction().GetClass().GetModule().GetAssembly().GetAppDomain()];
			this.corILFrame = corILFrame;
			this.corILFramePauseSession = process.PauseSession;
			this.corFunction = corILFrame.GetFunction();
			this.chainIndex = chainIndex;
			this.frameIndex = frameIndex;
			
			MetaDataImport metaData = thread.Process.Modules[corFunction.GetClass().GetModule()].MetaData;
			int methodGenArgs = metaData.EnumGenericParams(corFunction.GetToken()).Length;
			// Class parameters are first, then the method ones
			List<ICorDebugType> corGenArgs = ((ICorDebugILFrame2)corILFrame).EnumerateTypeParameters().ToList();
			// Remove method parametrs at the end
			corGenArgs.RemoveRange(corGenArgs.Count - methodGenArgs, methodGenArgs);
			List<DebugType> genArgs = new List<DebugType>(corGenArgs.Count);
			foreach(ICorDebugType corGenArg in corGenArgs) {
				genArgs.Add(DebugType.CreateFromCorType(this.AppDomain, corGenArg));
			}
			
			DebugType debugType = DebugType.CreateFromCorClass(
				this.AppDomain,
				null,
				corFunction.GetClass(),
				genArgs.ToArray()
			);
			this.methodInfo = (DebugMethodInfo)debugType.GetMember(corFunction.GetToken());
		}
Beispiel #2
0
		Eval(Process process, string description, ICorDebugEval corEval)
		{
			this.process = process;
			this.description = description;
			this.corEval = corEval;
			this.state = EvalState.Evaluating;
		}
		DebuggeeExceptionForm(Process process, string exceptionType)
		{
			InitializeComponent();
			
			this.Break = true;
			
			this.process = process;
			this.exceptionType = exceptionType;
			
			this.process.Exited += ProcessHandler;
			this.process.Resumed += ProcessHandler;
			
			this.FormClosed += FormClosedHandler;
			
			this.WindowState = DebuggingOptions.Instance.DebuggeeExceptionWindowState;
			FormLocationHelper.Apply(this, "DebuggeeExceptionForm", true);
			
			this.MinimizeBox = this.MaximizeBox = this.ShowIcon = false;
			
			this.exceptionView.Font = WinFormsResourceService.DefaultMonospacedFont;
			this.exceptionView.DoubleClick += ExceptionViewDoubleClick;
			this.exceptionView.WordWrap = false;
			
			this.btnBreak.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.ExceptionForm.Break}");
			this.btnStop.Text  = StringParser.Parse("${res:MainWindow.Windows.Debug.ExceptionForm.Terminate}");
			this.btnContinue.Text  = StringParser.Parse("${res:MainWindow.Windows.Debug.ExceptionForm.Continue}");
			
			this.btnBreak.Image = WinFormsResourceService.GetBitmap("Icons.16x16.Debug.Break");
			this.btnStop.Image = WinFormsResourceService.GetBitmap("Icons.16x16.StopProcess");
			this.btnContinue.Image = WinFormsResourceService.GetBitmap("Icons.16x16.Debug.Continue");
		}
		private Process debugActiveProcess(uint handle, string filename)
		{
			InitDebugger(GetProgramVersion(filename));
			Process p = new Process(this,this.CorDebug.DebugActiveProcess(handle,0));
			AddProcess(p);
			return p;
		}
Beispiel #5
0
        public void SelectProcess(Process process)
        {
            if (debuggedProcess != null)
            {
                debuggedProcess.Paused          -= debuggedProcess_DebuggingPaused;
                debuggedProcess.ExceptionThrown -= debuggedProcess_ExceptionThrown;
                debuggedProcess.Resumed         -= debuggedProcess_DebuggingResumed;
                debuggedProcess.ModulesAdded    -= debuggedProcess_ModulesAdded;
            }
            debuggedProcess = process;
            if (debuggedProcess != null)
            {
                debuggedProcess.Paused          += debuggedProcess_DebuggingPaused;
                debuggedProcess.ExceptionThrown += debuggedProcess_ExceptionThrown;
                debuggedProcess.Resumed         += debuggedProcess_DebuggingResumed;
                debuggedProcess.ModulesAdded    += debuggedProcess_ModulesAdded;

                debuggedProcess.BreakAtBeginning = BreakAtBeginning;
            }
            // reset
            BreakAtBeginning = false;

            //JumpToCurrentLine();
            OnProcessSelected(new ProcessEventArgs(process));
        }
Beispiel #6
0
 public MessageEventArgs(Process process, int level, string message, string category)
     : base(process)
 {
     this.level = level;
     this.message = message;
     this.category = category;
 }
Beispiel #7
0
        public void Attach(System.Diagnostics.Process existingProcess)
        {
            if (existingProcess == null)
            {
                return;
            }

            if (IsDebugging)
            {
                MessageBox.Show(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            string version = debugger.GetProgramVersion(existingProcess.MainModule.FileName);

            if (version.StartsWith("v1.0"))
            {
                MessageBox.Show("Net10NotSupported");
            }
            else
            {
                if (DebugStarting != null)
                {
                    DebugStarting(this, EventArgs.Empty);
                }

                try
                {
                    // set the JIT flag for evaluating optimized code
                    Process.DebugMode = DebugModeFlag.Debug;

                    Process process = debugger.Attach(existingProcess);
                    attached = true;
                    SelectProcess(process);
                }
                catch (System.Exception e)
                {
                    // CORDBG_E_DEBUGGER_ALREADY_ATTACHED
                    if (e is COMException || e is UnauthorizedAccessException)
                    {
                        string msg = "CannotAttachToProcess";
                        MessageBox.Show(msg + " " + e.Message);

                        if (DebugStopped != null)
                        {
                            DebugStopped(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
		public static Value Evaluate(INode code, Process context)
		{
			if (context.SelectedStackFrame == null && context.SelectedThread.MostRecentStackFrame == null)
				// This can happen when needed 'dll' is missing.  This causes an exception dialog to be shown even before the applicaiton starts
				throw new GetValueException("Can not evaluate because the process has no managed stack frames");
			
			return Evaluate(code, context.GetCurrentExecutingFrame());
		}
 public DebuggerProcessTreeNode(DebuggerProcessAssemblyList assemblyList)
 {
     if (assemblyList == null)
     {
         throw new ArgumentNullException("assemblyList");
     }
     this.assemblyList = assemblyList;
     this.process      = assemblyList.Process;
 }
		internal void RemoveProcess(Process process)
		{
			processCollection.Remove(process);
			OnProcessExited(process);
			if (processCollection.Count == 0) {
				// Exit callback and then terminate the debugger
				this.MTA2STA.AsyncCall( delegate { this.TerminateDebugger(); } );
			}
		}
		public static void Show(Process process, string title, string message, string stacktrace, Bitmap icon)
		{
			DebuggeeExceptionForm form = new DebuggeeExceptionForm(process);
			form.Text = title;
			form.pictureBox.Image = icon;
			form.lblExceptionText.Text = message;
			form.exceptionView.Text = stacktrace;
			
			form.Show(WorkbenchSingleton.MainWin32Window);
		}
Beispiel #12
0
        public void Attach(System.Diagnostics.Process existingProcess)
        {
            if (existingProcess == null)
            {
                return;
            }

            if (IsDebugging)
            {
                MessageService.ShowMessage(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            string version = debugger.GetProgramVersion(existingProcess.MainModule.FileName);

            if (version.StartsWith("v1.0"))
            {
                MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}");
            }
            else
            {
                if (DebugStarting != null)
                {
                    DebugStarting(this, EventArgs.Empty);
                }

                try {
                    Process process = debugger.Attach(existingProcess);
                    attached = true;
                    SelectProcess(process);

                    process.Modules.Added += process_Modules_Added;
                } catch (System.Exception e) {
                    // CORDBG_E_DEBUGGER_ALREADY_ATTACHED
                    if (e is COMException || e is UnauthorizedAccessException)
                    {
                        string msg = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.CannotAttachToProcess}");
                        MessageService.ShowMessage(msg + " " + e.Message);

                        if (DebugStopped != null)
                        {
                            DebugStopped(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Beispiel #13
0
		protected override void SelectProcess(Process process)
		{
			if (debuggedProcess != null) {
				debuggedProcess.Paused -= debuggedProcess_Paused;
			}
			debuggedProcess = process;
			if (debuggedProcess != null) {
				debuggedProcess.Paused += debuggedProcess_Paused;
			}
			RefreshPad();
		}
Beispiel #14
0
		/// <param name="process">Process on which to track debuggee state</param>
		public static void DoEvents(Process process)
		{
			if (process == null) return;
			DebuggeeState oldState = process.DebuggeeState;
			WpfDoEvents();
			DebuggeeState newState = process.DebuggeeState;
			if (oldState != newState) {
				//LoggingService.Info("Aborted because debuggee resumed");
				throw new AbortedBecauseDebuggeeResumedException();
			}
		}
Beispiel #15
0
		Eval(Process process,
		     string description,
		     EvaluationInvoker evaluationInvoker)
		{
			this.process = process;
			this.description = description;
			this.evaluationInvoker = evaluationInvoker;
			
			process.ScheduleEval(this);
			process.Debugger.MTA2STA.AsyncCall(delegate { process.StartEvaluation(); });
		}
Beispiel #16
0
 public EnCManager(Process process)
 {
     resource = new ResourceManager(this, process);
     resource.PreLoad();
     process.Modules.Added += this.ProcessModuleAdded;
     metadata = new MetaDataManager(this);
     eventCreator = new EditorEventCreator(this);
     process.EnCHook = this;
     this.process = process;
     LocalVarDiff.ClearLocalVarCache();
 }
        /// <summary>
        /// Create a new target VM for the giveb process id.
        /// </summary>
        /// <param name="pid">Process ID of the IKVM</param>
        internal TargetVM(int pid)
        {
            debugger = new NDebugger();
            System.Diagnostics.Process sysProcess = System.Diagnostics.Process.GetProcessById(pid);
            process = debugger.Attach(sysProcess);
            process.Exited += new EventHandler(ProcessExited);

            process.ModuleLoaded += new EventHandler<ModuleEventArgs>(ModuleLoaded);
            process.Paused += new EventHandler<ProcessEventArgs>(Paused);
            process.Resumed += new EventHandler<ProcessEventArgs>(Resumed);

        }
		public DebuggerProcessAssemblyList(Debugger.Process process)
		{
			if (process == null)
				throw new ArgumentNullException("process");
			this.process = process;
			this.moduleModels = new NullSafeSimpleModelCollection<DebuggerModuleModel>();
			this.moduleModels.AddRange(this.process.Modules.Select(m => new DebuggerModuleModel(m)));
			this.Assemblies = new NullSafeSimpleModelCollection<IAssemblyModel>();
			this.Assemblies.AddRange(moduleModels.Select(mm => mm.AssemblyModel));
			this.process.ModuleLoaded += ModuleLoaded;
			this.process.ModuleUnloaded += ModuleUnloaded;
		}
        public static void Detach(Debugger.Process process)
        {
            var classBrowser = SD.GetService <IClassBrowser>();
            var nodes        = classBrowser.AssemblyLists
                               .OfType <DebuggerProcessAssemblyList>()
                               .Where(n => n.Process == process)
                               .ToArray();

            foreach (var node in nodes)
            {
                classBrowser.AssemblyLists.Remove(node);
            }
        }
Beispiel #20
0
		internal LocalVariable(string name,
		                       Process process,
		                       IExpirable[] expireDependencies,
		                       IMutable[] mutateDependencies,
		                       CorValueGetter corValueGetter)
			:base (name,
			       process,
			       expireDependencies,
			       mutateDependencies,
			       corValueGetter)
		{
			
		}
Beispiel #21
0
		internal ArrayElement(uint[] indicies,
		                      Process process,
		                      IExpirable[] expireDependencies,
		                      IMutable[] mutateDependencies,
		                      CorValueGetter corValueGetter)
			:base (GetNameFromIndices(indicies),
			       process,
			       expireDependencies,
			       mutateDependencies,
			       corValueGetter)
		{
			this.indicies = indicies;
		}
Beispiel #22
0
		protected override void SelectProcess(Process process)
		{
			if (debuggedProcess != null) {
				debuggedProcess.Modules.Added -= debuggedProcess_ModuleLoaded;
				debuggedProcess.Modules.Removed -= debuggedProcess_ModuleUnloaded;
			}
			debuggedProcess = process;
			if (debuggedProcess != null) {
				debuggedProcess.Modules.Added += debuggedProcess_ModuleLoaded;
				debuggedProcess.Modules.Removed += debuggedProcess_ModuleUnloaded;
			}
			RefreshPad();
		}
 public DebuggerProcessEntityModelContext(Process process, Module currentModule)
 {
     if (process == null)
     {
         throw new ArgumentNullException("process");
     }
     if (currentModule == null)
     {
         throw new ArgumentNullException("currentModule");
     }
     this.process       = process;
     this.currentModule = currentModule;
 }
        /// <summary>
        /// Create a new target VM for the giveb process id.
        /// </summary>
        /// <param name="pid">Process ID of the IKVM</param>
        internal TargetVM(int pid, JdwpEventHandler jdwpEventHandler)
        {
            this.jdwpEventHandler = jdwpEventHandler;
            debugger = new NDebugger();
            System.Diagnostics.Process sysProcess = System.Diagnostics.Process.GetProcessById(pid);
            process = debugger.Attach(sysProcess);
            process.Exited += new EventHandler(ProcessExited);

            process.ModuleLoaded += new EventHandler<ModuleEventArgs>(ModuleLoaded);
            process.Paused += new EventHandler<ProcessEventArgs>(Paused);
            process.Resumed += new EventHandler<ProcessEventArgs>(Resumed);
            process.ThreadStarted += new EventHandler<ThreadEventArgs>(ThreadStarted);
        }
Beispiel #25
0
		internal MemberValue(MemberInfo memberInfo,
		                     Process process,
		                     IExpirable[] expireDependencies,
		                     IMutable[] mutateDependencies,
		                     CorValueGetter corValueGetter)
			:base (memberInfo.Name,
			       process,
			       expireDependencies,
			       mutateDependencies,
			       corValueGetter)
		{
			this.memberInfo = memberInfo;
		}
		public static void Show(Process process, string title, string message, string stacktrace, Bitmap icon, bool isUnhandled, Debugger.Exception exception)
		{
			DebuggeeExceptionForm form = new DebuggeeExceptionForm(process);
			form.Text = title;
			form.pictureBox.Image = icon;
			form.lblExceptionText.Text = message;
			form.exceptionView.Text = stacktrace;
			form.isUnhandled = isUnhandled;
			form.btnContinue.Enabled = !isUnhandled;
			form.Exception = exception;
			
			form.Show(WorkbenchSingleton.MainWin32Window);
		}
Beispiel #27
0
		internal MethodArgument(string name,
		                        int index,
		                        Process process,
		                        IExpirable[] expireDependencies,
		                        IMutable[] mutateDependencies,
		                        CorValueGetter corValueGetter)
			:base (name,
			       process,
			       expireDependencies,
			       mutateDependencies,
			       corValueGetter)
		{
			this.index = index;
		}
		protected override void SelectProcess(Process process)
		{
			if (debuggedProcess != null) {
				debuggedProcess.Paused               -= debuggedProcess_Paused;
				debuggedProcess.Threads.Added        -= debuggedProcess_ThreadStarted;
			}
			debuggedProcess = process;
			if (debuggedProcess != null) {
				debuggedProcess.Paused               += debuggedProcess_Paused;
				debuggedProcess.Threads.Added        += debuggedProcess_ThreadStarted;
			}
			runningThreads.Clear();
			InvalidatePad();
		}
Beispiel #29
0
		protected override void SelectProcess(Process process)
		{
			if (debuggedProcess != null) {
				debuggedProcess.Paused               -= debuggedProcess_Paused;
				debuggedProcess.Threads.Added        -= debuggedProcess_ThreadStarted;
			}
			debuggedProcess = process;
			if (debuggedProcess != null) {
				debuggedProcess.Paused               += debuggedProcess_Paused;
				debuggedProcess.Threads.Added        += debuggedProcess_ThreadStarted;
			}
			runningThreadsList.ItemCollection.Clear();
			RefreshPad();
		}
 public DebuggerProcessAssemblyList(Debugger.Process process)
 {
     if (process == null)
     {
         throw new ArgumentNullException("process");
     }
     this.process      = process;
     this.moduleModels = new NullSafeSimpleModelCollection <DebuggerModuleModel>();
     this.moduleModels.AddRange(this.process.Modules.Select(m => new DebuggerModuleModel(m)));
     this.Assemblies = new NullSafeSimpleModelCollection <IAssemblyModel>();
     this.Assemblies.AddRange(moduleModels.Select(mm => mm.AssemblyModel));
     this.process.ModuleLoaded   += ModuleLoaded;
     this.process.ModuleUnloaded += ModuleUnloaded;
 }
		public static bool Show(Process process, string title, string type, string stacktrace, Bitmap icon, bool isUnhandled)
		{
			DebuggeeExceptionForm form = new DebuggeeExceptionForm(process);
			form.Text = title;
			form.pictureBox.Image = icon;
			form.lblExceptionText.Text = type;
			form.exceptionView.Text = stacktrace;
			form.btnContinue.Enabled = !isUnhandled;
			
			// Showing the form as dialg seems like a resonable thing in the presence of potentially multiple
			// concurent debugger evetns
			form.ShowDialog(SD.WinForms.MainWin32Window);
			
			return form.Break;
		}
 public void SelectProcess(Process process)
 {
     if (debuggedProcess != null)
     {
         debuggedProcess.Paused          -= debuggedProcess_DebuggingPaused;
         debuggedProcess.ExceptionThrown -= debuggedProcess_ExceptionThrown;
         debuggedProcess.Resumed         -= debuggedProcess_DebuggingResumed;
     }
     debuggedProcess = process;
     if (debuggedProcess != null)
     {
         debuggedProcess.Paused          += debuggedProcess_DebuggingPaused;
         debuggedProcess.ExceptionThrown += debuggedProcess_ExceptionThrown;
         debuggedProcess.Resumed         += debuggedProcess_DebuggingResumed;
     }
     JumpToCurrentLine();
     OnProcessSelected(new ProcessEventArgs(process));
 }
Beispiel #33
0
		internal NamedValue(string name,
		                    Process process,
		                    IExpirable[] expireDependencies,
		                    IMutable[] mutateDependencies,
		                    CorValueGetter corValueGetter)
			:base (process,
			       expireDependencies,
			       mutateDependencies,
			       corValueGetter)
		{
			this.name = name;
			
			// TODO: clean up
			if (name.StartsWith("<") && name.Contains(">") && name != "<Base class>") {
				string middle = name.TrimStart('<').Split('>')[0]; // Get text between '<' and '>'
				if (middle != "") {
					this.name = middle;
				}
			}
		}
Beispiel #34
0
        internal Module(AppDomain appDomain, ICorDebugModule corModule)
        {
            this.appDomain = appDomain;
            this.process = appDomain.Process;
            this.corModule = corModule;

            metaData = new MetaDataImport(corModule);

            if (IsDynamic || IsInMemory) {
                name     = corModule.GetName();
            } else {
                fullPath = corModule.GetName();
                name     = System.IO.Path.GetFileName(FullPath);
            }
            asmFilename = corModule.GetAssembly().GetName();

            SetJITCompilerFlags();

            LoadSymbolsFromDisk(process.Options.SymbolsSearchPaths);
            ResetJustMyCodeStatus();
        }
		public static bool Show(Process process, string exceptionType, string stacktrace, bool isUnhandled)
		{
			DebuggeeExceptionForm form = new DebuggeeExceptionForm(process, exceptionType);
			string type = string.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.ExceptionForm.Message}"), exceptionType);
			Bitmap icon = WinFormsResourceService.GetBitmap(isUnhandled ? "Icons.32x32.Error" : "Icons.32x32.Warning");

			form.Text = isUnhandled ? StringParser.Parse("${res:MainWindow.Windows.Debug.ExceptionForm.Title.Unhandled}") : StringParser.Parse("${res:MainWindow.Windows.Debug.ExceptionForm.Title.Handled}");
			form.pictureBox.Image = icon;
			form.lblExceptionText.Text = type;
			form.exceptionView.Text = stacktrace;
			form.btnContinue.Enabled = !isUnhandled;
			form.chkBreakOnHandled.Visible = !isUnhandled;
			form.chkBreakOnHandled.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.ExceptionForm.BreakOnHandled}", new StringTagPair("ExceptionName", exceptionType));
			form.chkBreakOnHandled.Checked = true;
			
			// Showing the form as dialg seems like a resonable thing in the presence of potentially multiple
			// concurent debugger evetns
			form.ShowDialog(SD.WinForms.MainWin32Window);
			
			return form.Break;
		}
		public static Value Evaluate(INode code, Process context)
		{
			StackFrame stackFrame = null;
			if (context.SelectedStackFrame == null && context.SelectedThread.MostRecentStackFrame == null)
				// This can happen when needed 'dll' is missing.  This causes an exception dialog to be shown even before the applicaiton starts
				throw new GetValueException("Can not evaluate because the process has no managed stack frames");
			
			if (context.SelectedStackFrame != null) {
				if (context.SelectedThread.MostRecentStackFrame != null) {
					if (context.SelectedStackFrame.HasSymbols && context.SelectedThread.MostRecentStackFrame.HasSymbols) 
						stackFrame = context.SelectedStackFrame;
					else 
						stackFrame = context.SelectedThread.MostRecentStackFrame;
				} else {
					stackFrame = context.SelectedThread.MostRecentStackFrame;
				}
			} else {
				stackFrame = context.SelectedThread.MostRecentStackFrame;
			}
			
			return Evaluate(code, stackFrame);
		}
Beispiel #37
0
		internal Exception(Thread thread)
		{
			creationTime = DateTime.Now;
			this.process = thread.Process;
			this.thread = thread;
			corValue = thread.CorThread.CurrentException;
			exceptionType = thread.CurrentExceptionType;
			Value runtimeValue = new Value(process,
			                               new IExpirable[] {process.PauseSession},
			                               new IMutable[] {},
			                               delegate { return corValue; } );
			NamedValue nv = runtimeValue.GetMember("_message");
			if (!nv.IsNull)
			message = nv.AsString;
			else message = runtimeValue.Type.FullName;
			if (thread.LastFunctionWithLoadedSymbols != null) {
				location = thread.LastFunctionWithLoadedSymbols.NextStatement;
			}
			
			callstack = "";
			int callstackItems = 0;
			if (!nv.IsNull)
			foreach(Function function in thread.Callstack) {
				if (callstackItems >= 100) {
					callstack += "...\n";
					break;
				}
				
				SourcecodeSegment loc = function.NextStatement;
				callstack += function.Name + "()";
				if (loc != null) {
					callstack += " - " + loc.SourceFullFilename + ":" + loc.StartLine + "," + loc.StartColumn;
				}
				callstack += "\n";
				callstackItems++;
			}
			
			type = runtimeValue.Type.FullName;
		}
		bool InjectInterpreter()
		{
			if (!DebuggerService.IsDebuggerLoaded) {
				PrintLine(ResourceService.GetString("ICSharpCode.BooInterpreter.Debuggee.ErrorDebuggerNotLoaded"));
				return false;
			}
			WindowsDebugger winDebugger = DebuggerService.CurrentDebugger as WindowsDebugger;
			if (winDebugger == null) {
				PrintLine(ResourceService.GetString("ICSharpCode.BooInterpreter.Debuggee.ErrorIncompatibleDebugger"));
				return false;
			}
			if (winDebugger.DebuggedProcess == null) {
				PrintLine(ResourceService.GetString("ICSharpCode.BooInterpreter.Debuggee.ErrorNoProgramDebugged"));
				return false;
			}
			process = winDebugger.DebuggedProcess;
			process.Expired += delegate { interpreter = null; };
			process.LogMessage -= OnDebuggerLogMessage;
			process.LogMessage += OnDebuggerLogMessage;
			
			Value assembly;
			// Boo.Lang.Interpreter.dll
			string path = Path.Combine(Path.GetDirectoryName(typeof(InterpreterContext).Assembly.Location), "Boo.Lang.Interpreter.dll");
			assembly = LoadAssembly(path);
			// Debugger.BooInterpreter.dll
			assembly = LoadAssembly(typeof(DebugeeInteractiveInterpreter).Assembly.Location);
			Value interpreterType = Eval.NewString(process, typeof(DebugeeInteractiveInterpreter).FullName);
			interpreter = Eval.InvokeMethod(process, typeof(Assembly), "CreateInstance", assembly, new Value[] {interpreterType});
			interpreter_localVariable = interpreter.GetMember("localVariable");
			RunCommand(
				"import System\n" + 
				"import System.IO\n" +
				"import System.Text\n" +
				"interpreter.RememberLastValue = true\n" +
				"interpreter.Print = def(msg): System.Diagnostics.Debugger.Log(0xB00, \"DebugeeInterpreterContext.PrintLine\", msg)");
			
			return true;
		}
Beispiel #39
0
        public void SelectProcess(Process process, CollectionItemEventArgs <Process> e = null)
        {
            if (debuggedProcess != null)
            {
                debuggedProcess.Paused          -= debuggedProcess_DebuggingPaused;
                debuggedProcess.ExceptionThrown -= debuggedProcess_ExceptionThrown;
                debuggedProcess.Resumed         -= debuggedProcess_DebuggingResumed;
                debuggedProcess.ModulesAdded    -= debuggedProcess_ModulesAdded;
            }
            debuggedProcess = process;
            if (debuggedProcess != null)
            {
                debuggedProcess.Paused          += debuggedProcess_DebuggingPaused;
                debuggedProcess.ExceptionThrown += debuggedProcess_ExceptionThrown;
                debuggedProcess.Resumed         += debuggedProcess_DebuggingResumed;
                debuggedProcess.ModulesAdded    += debuggedProcess_ModulesAdded;

                debuggedProcess.BreakAtBeginning = BreakAtBeginning;
                if (DebugEvent != null)
                {
                    DebugEvent(this, new DebuggerEventArgs(DebuggerEvent.ProcessSelected));
                }
            }
            else
            {
                if (DebugEvent != null)
                {
                    DebugEvent(this, new DebuggerEventArgs(DebuggerEvent.ProcessSelected));
                }
                if (DebugEvent != null)
                {
                    DebugEvent(this, new DebuggerEventArgs(DebuggerEvent.Stopped));
                }
            }
            BreakAtBeginning = false;
        }
Beispiel #40
0
        public void Start(ProcessStartInfo processStartInfo)
        {
            lastStepType = StepType.Unknown;
            if (IsDebugging)
            {
                MainWindow.Instance.ShowMessageBox(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            string version = debugger.GetProgramVersion(processStartInfo.FileName);

            attached = false;
            if (DebugEvent != null)
            {
                DebugEvent(this, new DebuggerEventArgs(DebuggerEvent.Starting));
            }
            if (version.StartsWith("v1.0"))
            {
                StartError("Net10NotSupported");
            }
            else if (version.StartsWith("v1.1"))
            {
                StartError("Net1.1NotSupported");
            }
            else if (debugger.IsKernelDebuggerEnabled)
            {
                StartError("KernelDebuggerEnabled");
            }
            else
            {
                try {
                    // set the JIT flag for evaluating optimized code
                    Process.DebugMode = DebugModeFlag.Debug;

                    Process process = debugger.Start(processStartInfo.FileName,
                                                     processStartInfo.WorkingDirectory,
                                                     processStartInfo.Arguments);
                    SelectProcess(process);
                } catch (System.Exception e) {
                    // COMException: The request is not supported. (Exception from HRESULT: 0x80070032)
                    // COMException: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
                    // COMException: The requested operation requires elevation. (Exception from HRESULT: 0x800702E4)
                    // COMException: The directory name is invalid. (Exception from HRESULT: 0x8007010B)
                    // BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
                    // UnauthorizedAccessException: Отказано в доступе. (Исключение из HRESULT: 0x80070005 (E_ACCESSDENIED))
                    if (e is COMException || e is BadImageFormatException || e is UnauthorizedAccessException)
                    {
                        string msg = "CannotStartProcess";
                        msg += " " + e.Message;
                        if (e is COMException)
                        {
                            uint errCode = unchecked ((uint)((COMException)e).ErrorCode);
                            if (errCode == 0x80070032 || errCode == 0x80131C30)
                            {
                                var origMsg = msg;
                                if (errCode == 0x80131C30)
                                {
                                    msg = "Use dnSpy-x86.exe to debug 32-bit applications.";
                                }
                                else
                                {
                                    msg = "Use dnSpy.exe to debug 64-bit applications.";
                                }
                                msg += Environment.NewLine + Environment.NewLine;
                                msg += origMsg;
                            }
                        }
                        StartError(msg);
                    }
                    else
                    {
                        if (DebugEvent != null)
                        {
                            DebugEvent(this, new DebuggerEventArgs(DebuggerEvent.Stopped));
                        }
                        throw;
                    }
                }
            }
        }
Beispiel #41
0
        public void Start(ProcessStartInfo processStartInfo)
        {
            if (IsDebugging)
            {
                MessageService.ShowMessage(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            if (FileUtility.IsUrl(processStartInfo.FileName))
            {
                if (!CheckWebProjectStartInfo())
                {
                    return;
                }

                var project = ProjectService.OpenSolution.Preferences.StartupProject as CompilableProject;
                var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name);
                System.Diagnostics.Process defaultAppProcess = null;

                if (options.Data.WebServer != WebServer.None)
                {
                    string processName = WebProjectService.WorkerProcessName;

                    // try find the worker process directly or using the process monitor callback
                    var processes = System.Diagnostics.Process.GetProcesses();
                    int index     = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
                    if (index > -1)
                    {
                        Attach(processes[index]);
                    }
                    else
                    {
                        try {
                            this.monitor = new ProcessMonitor(processName);
                            this.monitor.ProcessCreated += delegate {
                                WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(defaultAppProcess, options)));
                            };
                            this.monitor.Start();
                        }
                        catch (System.Exception ex) {
                            LoggingService.ErrorFormatted("Process Monitor exception: {0}", ex.Message);
                        }
                    }

                    if (options.Data.WebServer == WebServer.IISExpress)
                    {
                        // start IIS express and attach to it
                        if (WebProjectService.IISVersion == IISVersion.IISExpress)
                        {
                            System.Diagnostics.Process.Start(WebProjectService.IISExpressProcessLocation);
                        }
                        else
                        {
                            MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                            return;
                        }
                    }
                }

                // start default application(e.g. browser)
                if (project.StartAction == StartAction.StartURL)
                {
                    defaultAppProcess = System.Diagnostics.Process.Start(project.StartUrl);
                }
                else
                {
                    if (!string.IsNullOrEmpty(options.Data.ProjectUrl) && options.Data.WebServer == WebServer.IIS)
                    {
                        defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
                    }
                    else
                    {
                        if (options.Data.WebServer == WebServer.IISExpress)
                        {
                            defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
                        }
                    }
                }
            }
            else
            {
                string version = debugger.GetProgramVersion(processStartInfo.FileName);

                if (version.StartsWith("v1.0"))
                {
                    MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}");
                }
                else if (version.StartsWith("v1.1"))
                {
                    MessageService.ShowMessage(StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}").Replace("1.0", "1.1"));
//					} else if (string.IsNullOrEmpty(version)) {
//					// Not a managed assembly
//					MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.BadAssembly}");
                }
                else if (debugger.IsKernelDebuggerEnabled)
                {
                    MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.KernelDebuggerEnabled}");
                }
                else
                {
                    attached = false;
                    if (DebugStarting != null)
                    {
                        DebugStarting(this, EventArgs.Empty);
                    }

                    try {
                        Process process = debugger.Start(processStartInfo.FileName,
                                                         processStartInfo.WorkingDirectory,
                                                         processStartInfo.Arguments);
                        SelectProcess(process);
                    } catch (System.Exception e) {
                        // COMException: The request is not supported. (Exception from HRESULT: 0x80070032)
                        // COMException: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
                        // COMException: The requested operation requires elevation. (Exception from HRESULT: 0x800702E4)
                        // COMException: The directory name is invalid. (Exception from HRESULT: 0x8007010B)
                        // BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
                        // UnauthorizedAccessException: Отказано в доступе. (Исключение из HRESULT: 0x80070005 (E_ACCESSDENIED))
                        if (e is COMException || e is BadImageFormatException || e is UnauthorizedAccessException)
                        {
                            string msg = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.CannotStartProcess}");
                            msg += " " + e.Message;
                            // TODO: Remove
                            if (e is COMException && ((uint)((COMException)e).ErrorCode == 0x80070032))
                            {
                                msg += Environment.NewLine + Environment.NewLine;
                                msg += "64-bit debugging is not supported.  Please set Project -> Project Options... -> Compiling -> Target CPU to 32bit.";
                            }
                            MessageService.ShowMessage(msg);

                            if (DebugStopped != null)
                            {
                                DebugStopped(this, EventArgs.Empty);
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }
Beispiel #42
0
        public void Start(ProcessStartInfo processStartInfo)
        {
            if (IsDebugging)
            {
                MessageBox.Show(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            string version = debugger.GetProgramVersion(processStartInfo.FileName);

            if (version.StartsWith("v1.0"))
            {
                MessageBox.Show("Net10NotSupported");
            }
            else if (version.StartsWith("v1.1"))
            {
                MessageBox.Show("Net1.1NotSupported");
//					} else if (string.IsNullOrEmpty(version)) {
//					// Not a managed assembly
//					MessageBox.Show(".Error.BadAssembly}");
            }
            else if (debugger.IsKernelDebuggerEnabled)
            {
                MessageBox.Show("KernelDebuggerEnabled");
            }
            else
            {
                attached = false;
                if (DebugStarting != null)
                {
                    DebugStarting(this, EventArgs.Empty);
                }

                try {
                    // set the JIT flag for evaluating optimized code
                    Process.DebugMode = DebugModeFlag.Debug;

                    Process process = debugger.Start(processStartInfo.FileName,
                                                     processStartInfo.WorkingDirectory,
                                                     processStartInfo.Arguments);
                    SelectProcess(process);
                } catch (System.Exception e) {
                    // COMException: The request is not supported. (Exception from HRESULT: 0x80070032)
                    // COMException: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
                    // COMException: The requested operation requires elevation. (Exception from HRESULT: 0x800702E4)
                    // COMException: The directory name is invalid. (Exception from HRESULT: 0x8007010B)
                    // BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
                    // UnauthorizedAccessException: Отказано в доступе. (Исключение из HRESULT: 0x80070005 (E_ACCESSDENIED))
                    if (e is COMException || e is BadImageFormatException || e is UnauthorizedAccessException)
                    {
                        string msg = "CannotStartProcess";
                        msg += " " + e.Message;
                        // TODO: Remove
                        if (e is COMException && ((uint)((COMException)e).ErrorCode == 0x80070032))
                        {
                            msg += Environment.NewLine + Environment.NewLine;
                            msg += "64-bit debugging is not supported.  Please set Project -> Project Options... -> Compiling -> Target CPU to 32bit.";
                        }
                        MessageBox.Show(msg);

                        if (DebugStopped != null)
                        {
                            DebugStopped(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
        public static void Attach(Debugger.Process process)
        {
            var classBrowser = SD.GetService <IClassBrowser>();

            classBrowser.AssemblyLists.Add(new DebuggerProcessAssemblyList(process));
        }
        public void Start(ProcessStartInfo processStartInfo)
        {
            if (IsDebugging)
            {
                MessageService.ShowMessage(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }
            string version = debugger.GetProgramVersion(processStartInfo.FileName);

            if (version.StartsWith("v1.0"))
            {
                MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}");
            }
            else if (version.StartsWith("v1.1"))
            {
                MessageService.ShowMessage(StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}").Replace("1.0", "1.1"));
//			} else if (string.IsNullOrEmpty(version)) {
//				// Not a managed assembly
//				MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.BadAssembly}");
            }
            else if (debugger.IsKernelDebuggerEnabled)
            {
                MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.KernelDebuggerEnabled}");
            }
            else
            {
                attached = false;
                if (DebugStarting != null)
                {
                    DebugStarting(this, EventArgs.Empty);
                }

                try {
                    Process process = debugger.Start(processStartInfo.FileName,
                                                     processStartInfo.WorkingDirectory,
                                                     processStartInfo.Arguments);
                    SelectProcess(process);
                } catch (System.Exception e) {
                    // COMException: The request is not supported. (Exception from HRESULT: 0x80070032)
                    // COMException: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
                    // COMException: The requested operation requires elevation. (Exception from HRESULT: 0x800702E4)
                    // COMException: The directory name is invalid. (Exception from HRESULT: 0x8007010B)
                    // BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
                    // UnauthorizedAccessException: Отказано в доступе. (Исключение из HRESULT: 0x80070005 (E_ACCESSDENIED))
                    if (e is COMException || e is BadImageFormatException || e is UnauthorizedAccessException)
                    {
                        string msg = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.CannotStartProcess}");
                        MessageService.ShowMessage(msg + " " + e.Message);

                        if (DebugStopped != null)
                        {
                            DebugStopped(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }