示例#1
0
        public void AttachToProcess(ProcessInfo proc, DebuggerSessionOptions options)
        {
            if (proc == null)
            {
                throw new ArgumentNullException("proc");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            lock (slock) {
                this.options = options;
                OnRunning();
                Dispatch(delegate {
                    try {
                        OnAttachToProcess(proc.Id);
                        attached = true;
                    } catch (Exception ex) {
                        ForceExit();
                        if (!HandleException(ex))
                        {
                            throw;
                        }
                    }
                });
            }
        }
示例#2
0
        public void Run(DebuggerStartInfo startInfo, DebuggerSessionOptions options)
        {
            if (startInfo == null)
            {
                throw new ArgumentNullException("startInfo");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            lock (slock) {
                this.options = options;
                OnRunning();
                Dispatch(delegate {
                    try {
                        OnRun(startInfo);
                    } catch (Exception ex) {
                        ForceExit();
                        if (!HandleException(ex))
                        {
                            throw;
                        }
                    }
                });
            }
        }
示例#3
0
		protected DebuggerSession Start (string test)
		{
			TargetRuntime runtime;
			switch (EngineId) {
			case "MonoDevelop.Debugger.Win32":
				runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("MS.NET");
				break;
			case "Mono.Debugger.Soft":
				runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("Mono");
				break;
			default:
				runtime = Runtime.SystemAssemblyService.DefaultRuntime;
				break;
			}

			if (runtime == null)
				return null;

			var cmd = new DotNetExecutionCommand ();
			cmd.Command = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "MonoDevelop.Debugger.Tests.TestApp.exe");
			cmd.Arguments = test;
			cmd.TargetRuntime = runtime;

			DebuggerStartInfo si = engine.CreateDebuggerStartInfo (cmd);
			DebuggerSession session = engine.CreateSession ();
			var ops = new DebuggerSessionOptions ();
			ops.EvaluationOptions = EvaluationOptions.DefaultOptions;
			ops.EvaluationOptions.EvaluationTimeout = 100000;

			FilePath path = Util.TestsRootDir;
			path = path.ParentDirectory.Combine ("src","addins","MonoDevelop.Debugger","MonoDevelop.Debugger.Tests.TestApp","Main.cs").FullPath;
			TextFile file = TextFile.ReadFile (path);
			int i = file.Text.IndexOf ("void " + test, StringComparison.Ordinal);
			if (i == -1)
				throw new Exception ("Test not found: " + test);
			i = file.Text.IndexOf ("/*break*/", i, StringComparison.Ordinal);
			if (i == -1)
				throw new Exception ("Break marker not found: " + test);
			int line, col;
			file.GetLineColumnFromPosition (i, out line, out col);
			Breakpoint bp = session.Breakpoints.Add (path, line);
			bp.Enabled = true;
			
			var done = new ManualResetEvent (false);
			
			session.OutputWriter = (isStderr, text) => Console.WriteLine ("PROC:" + text);
			
			session.TargetHitBreakpoint += delegate {
				done.Set ();
			};
				
			session.Run (si, ops);
			if (!done.WaitOne (3000))
				throw new Exception ("Timeout while waiting for initial breakpoint");
			
			return session;
		}
示例#4
0
文件: Executer.cs 项目: minuowa/Monos
        public void Attach()
        {
            ProcessInfo pi = GetCurPorcess();
            if (pi == null)
                return;

            DebuggerSessionOptions ops = new DebuggerSessionOptions();

            ops.EvaluationOptions = EvaluationOptions.DefaultOptions;
            ops.EvaluationOptions.EvaluationTimeout = 100000;

            mDebuggerSession.AttachToProcess(pi, ops);

            //Debugger.Launch();
        }
		public DebuggerOptionsPanelWidget ()
		{
			Build ();

			options = DebuggingService.GetUserOptions ();
			checkProjectCodeOnly.Active = options.ProjectAssembliesOnly;
			checkStepOverPropertiesAndOperators.Active = options.StepOverPropertiesAndOperators;
			checkAllowEval.Active = options.EvaluationOptions.AllowTargetInvoke;
			checkAllowToString.Active = options.EvaluationOptions.AllowToStringCalls;
			checkShowBaseGroup.Active = !options.EvaluationOptions.FlattenHierarchy;
			checkGroupPrivate.Active = options.EvaluationOptions.GroupPrivateMembers;
			checkGroupStatic.Active = options.EvaluationOptions.GroupStaticMembers;
			checkAllowToString.Sensitive = checkAllowEval.Active;
			spinTimeout.Value = options.EvaluationOptions.EvaluationTimeout;
		}
		protected DebuggerSession Start (string test)
		{
			DotNetExecutionCommand cmd = new DotNetExecutionCommand ();
			cmd.Command = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "MonoDevelop.Debugger.Tests.TestApp.exe");
			cmd.Arguments = test;
			
			DebuggerStartInfo si = engine.CreateDebuggerStartInfo (cmd);
			DebuggerSession session = engine.CreateSession ();
			DebuggerSessionOptions ops = new DebuggerSessionOptions ();
			ops.EvaluationOptions = EvaluationOptions.DefaultOptions;
			ops.EvaluationOptions.EvaluationTimeout = 100000;

			FilePath path = Util.TestsRootDir;
			path = path.ParentDirectory.Combine ("src","addins","MonoDevelop.Debugger","MonoDevelop.Debugger.Tests.TestApp","Main.cs").FullPath;
			TextFile file = TextFile.ReadFile (path);
			int i = file.Text.IndexOf ("void " + test);
			if (i == -1)
				throw new Exception ("Test not found: " + test);
			i = file.Text.IndexOf ("/*break*/", i);
			if (i == -1)
				throw new Exception ("Break marker not found: " + test);
			int line, col;
			file.GetLineColumnFromPosition (i, out line, out col);
			Breakpoint bp = session.Breakpoints.Add (path, line);
			bp.Enabled = true;
			
			ManualResetEvent done = new ManualResetEvent (false);
			
			session.OutputWriter = delegate (bool isStderr, string text) {
				Console.WriteLine ("PROC:" + text);
			};
			
			session.TargetHitBreakpoint += delegate {
				done.Set ();
			};
				
			session.Run (si, ops);
			if (!done.WaitOne (3000))
				throw new Exception ("Timeout while waiting for initial breakpoint");
			
			return session;
		}
		public DebuggerOptionsPanelWidget ()
		{
			this.Build ();
			options = DebuggingService.GetUserOptions ();
			projectCodeOnly.Active = options.ProjectAssembliesOnly;
			checkAllowEval.Active = options.EvaluationOptions.AllowTargetInvoke;
			checkToString.Active = options.EvaluationOptions.AllowToStringCalls;
			checkShowBaseGroup.Active = !options.EvaluationOptions.FlattenHierarchy;
			checkGroupPrivate.Active = options.EvaluationOptions.GroupPrivateMembers;
			checkGroupStatic.Active = options.EvaluationOptions.GroupStaticMembers;
			checkToString.Sensitive = checkAllowEval.Active;
			spinTimeout.Value = options.EvaluationOptions.EvaluationTimeout;

			// Debugger priorities
			prioritylist.Model = new Gtk.ListStore (typeof(string), typeof(string));
			prioritylist.AppendColumn ("", new Gtk.CellRendererText (), "text", 1);

			foreach (DebuggerEngine engine in DebuggingService.GetDebuggerEngines ()) {
				prioritylist.Model.AppendValues (engine.Id, engine.Name);
			}
		}
示例#8
0
        protected DebuggerSession Start(string args)
        {
            try
            {
                DebuggerStartInfo si = CreateDebuggerStartInfo();
                si.Command = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "UnitTests.TestApp.exe");
                si.Arguments = args;

                DebuggerSessionOptions ops = new DebuggerSessionOptions();
                ops.EvaluationOptions = EvaluationOptions.DefaultOptions;
                ops.EvaluationOptions.EvaluationTimeout = 100000;

                DebuggerSession session = CreateDebuggerSession();

                ManualResetEvent done = new ManualResetEvent(false);

                session.OutputWriter = delegate (bool isStderr, string text)
                {
                    Console.WriteLine("PROC:" + text);
                };

                session.TargetStopped += delegate
                {
                    done.Set();
                };

                session.Run(si, ops);
                if (!done.WaitOne(3000))
                    throw new Exception("Timeout while waiting for initial breakpoint");

                return session;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
示例#9
0
		public static void SetUserOptions (DebuggerSessionOptions options)
		{
			PropertyService.Set ("MonoDevelop.Debugger.DebuggingService.ProjectAssembliesOnly", options.ProjectAssembliesOnly);
			PropertyService.Set ("MonoDevelop.Debugger.DebuggingService.AllowTargetInvoke", options.EvaluationOptions.AllowTargetInvoke);
			PropertyService.Set ("MonoDevelop.Debugger.DebuggingService.AllowToStringCalls", options.EvaluationOptions.AllowToStringCalls);
			PropertyService.Set ("MonoDevelop.Debugger.DebuggingService.EvaluationTimeout", options.EvaluationOptions.EvaluationTimeout);
			PropertyService.Set ("MonoDevelop.Debugger.DebuggingService.FlattenHierarchy", options.EvaluationOptions.FlattenHierarchy);
			PropertyService.Set ("MonoDevelop.Debugger.DebuggingService.GroupPrivateMembers", options.EvaluationOptions.GroupPrivateMembers);
			PropertyService.Set ("MonoDevelop.Debugger.DebuggingService.GroupStaticMembers", options.EvaluationOptions.GroupStaticMembers);
			
			if (session != null) {
				session.Options.EvaluationOptions = GetUserOptions ().EvaluationOptions;
				if (EvaluationOptionsChanged != null)
					EvaluationOptionsChanged (null, EventArgs.Empty);
			}
		}
示例#10
0
		public static void ResetOptions()
		{
			// No need to lock on this data.

			Options = new DebuggerSessionOptions
			{
				EvaluationOptions = EvaluationOptions.DefaultOptions
			};

			Options.EvaluationOptions.UseExternalTypeResolver = true;
		}
示例#11
0
		protected void Start (string test)
		{
			TargetRuntime runtime;

			switch (EngineId) {
			case "MonoDevelop.Debugger.Win32":
				runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("MS.NET");
				break;
			case "Mono.Debugger.Soft":
				runtime = Runtime.SystemAssemblyService.GetTargetRuntimes ()
					.OfType<MonoTargetRuntime> ()
					.OrderByDescending(o => o.Version)
					.FirstOrDefault ();
				break;
			default:
				runtime = Runtime.SystemAssemblyService.DefaultRuntime;
				break;
			}

			if (runtime == null) {
				Assert.Ignore ("Runtime not found for: {0}", EngineId);
				return;
			}

			Console.WriteLine ("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version);

			// main/build/tests
			FilePath path = Path.GetDirectoryName (GetType ().Assembly.Location);
			var exe = Path.Combine (path, "MonoDevelop.Debugger.Tests.TestApp.exe");

			var cmd = new DotNetExecutionCommand ();
			cmd.TargetRuntime = runtime;
			cmd.Command = exe;
			cmd.Arguments = test;

			if (Platform.IsWindows) {
				var monoRuntime = runtime as MonoTargetRuntime;
				if (monoRuntime != null) {
					var psi = new System.Diagnostics.ProcessStartInfo (Path.Combine (monoRuntime.Prefix, "bin", "pdb2mdb.bat"), cmd.Command);
					psi.UseShellExecute = false;
					psi.CreateNoWindow = true;
					System.Diagnostics.Process.Start (psi).WaitForExit ();
				}
			}

			var dsi = engine.CreateDebuggerStartInfo (cmd);
			var soft = dsi as SoftDebuggerStartInfo;

			if (soft != null) {
				var assemblyName = AssemblyName.GetAssemblyName (exe);

				soft.UserAssemblyNames = new List<AssemblyName> ();
				soft.UserAssemblyNames.Add (assemblyName);
			}

			Session = engine.CreateSession ();
			var ops = new DebuggerSessionOptions ();
			ops.EvaluationOptions = EvaluationOptions.DefaultOptions;
			ops.EvaluationOptions.AllowTargetInvoke = AllowTargetInvokes;
			ops.EvaluationOptions.EvaluationTimeout = 100000;

			path = path.ParentDirectory.ParentDirectory.Combine ("src", "addins", "MonoDevelop.Debugger", "MonoDevelop.Debugger.Tests.TestApp", test + ".cs").FullPath;
			SourceFile = TextFile.ReadFile (path);
			TestName = test;
			AddBreakpoint ("break");
			
			var done = new ManualResetEvent (false);
			
			Session.OutputWriter = (isStderr, text) => Console.WriteLine ("PROC:" + text);

			Session.TargetHitBreakpoint += (sender, e) => {
				done.Set ();
				Frame = e.Backtrace.GetFrame (0);
				lastStoppedPosition = Frame.SourceLocation;
				targetStoppedEvent.Set ();
			};

			Session.TargetExceptionThrown += (sender, e) => {
				Frame = e.Backtrace.GetFrame (0);
				for (int i = 0; i < e.Backtrace.FrameCount; i++) {
					if (!e.Backtrace.GetFrame (i).IsExternalCode) {
						Frame = e.Backtrace.GetFrame (i);
						break;
					}
				}
				lastStoppedPosition = Frame.SourceLocation;
				targetStoppedEvent.Set ();
			};

			Session.TargetStopped += (sender, e) => {
				Frame = e.Backtrace.GetFrame (0);
				lastStoppedPosition = Frame.SourceLocation;
				targetStoppedEvent.Set ();
			};

			var targetExited = new ManualResetEvent (false);
			Session.TargetExited += delegate {
				targetExited.Set ();
			};

			Session.Run (dsi, ops);
			switch (WaitHandle.WaitAny (new WaitHandle[]{ done, targetExited }, 30000)) {
			case 0:
				//Breakpoint is hit good... run tests now
				break;
			case 1:
				throw new Exception ("Test application exited before hitting breakpoint");
			default:
				throw new Exception ("Timeout while waiting for initial breakpoint");
			}
		}
示例#12
0
		/// <summary>
		/// Starts a debugging session by attaching the debugger to a running process
		/// </summary>
		/// <param name='proc'>
		/// Process information
		/// </param>
		/// <param name='options'>
		/// Debugging options
		/// </param>
		/// <exception cref='ArgumentNullException'>
		/// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
		/// </exception>
		public void AttachToProcess (ProcessInfo proc, DebuggerSessionOptions options)
		{
			if (proc == null)
				throw new ArgumentNullException ("proc");
			if (options == null)
				throw new ArgumentNullException ("options");
			
			lock (slock) {
				this.options = options;
				OnRunning ();
				Dispatch (delegate {
					try {
						OnAttachToProcess (proc.Id);
						attached = true;
					} catch (Exception ex) {
						ForceExit ();
						if (!HandleException (ex))
							throw;
					}
				});
			}
		}
示例#13
0
		/// <summary>
		/// Starts a debugging session
		/// </summary>
		/// <param name='startInfo'>
		/// Startup information
		/// </param>
		/// <param name='options'>
		/// Session options
		/// </param>
		/// <exception cref='ArgumentNullException'>
		/// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
		/// </exception>
		public void Run (DebuggerStartInfo startInfo, DebuggerSessionOptions options)
		{
			if (startInfo == null)
				throw new ArgumentNullException ("startInfo");
			if (options == null)
				throw new ArgumentNullException ("options");
			
			lock (slock) {
				this.options = options;
				OnRunning ();
				Dispatch (delegate {
					try {
						OnRun (startInfo);
					} catch (Exception ex) {
						ForceExit ();
						if (!HandleException (ex))
							throw;
					}
				});
			}
		}
		protected void Start (string test)
		{
			TargetRuntime runtime;

			switch (EngineId) {
			case "MonoDevelop.Debugger.Win32":
				runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("MS.NET");
				break;
			case "Mono.Debugger.Soft":
				runtime = Runtime.SystemAssemblyService.GetTargetRuntimes ()
					.OfType<MonoTargetRuntime> ()
					.OrderByDescending ((o) => {
					//Attempt to find latest version of Mono registred in IDE and use that for unit tests
					if (string.IsNullOrWhiteSpace (o.Version) || o.Version == "Unknown")
						return new Version (0, 0, 0, 0);
					int indexOfBeforeDetails = o.Version.IndexOf (" (", StringComparison.Ordinal);
					if (indexOfBeforeDetails == -1)
						return new Version (0, 0, 0, 0);
					string hopefullyVersion = o.Version.Remove (indexOfBeforeDetails);
					Version version;
					if (Version.TryParse (hopefullyVersion, out version)) {
						return version;
					} else {
						return new Version (0, 0, 0, 0);
					}
				}).FirstOrDefault ();
				break;
			default:
				runtime = Runtime.SystemAssemblyService.DefaultRuntime;
				break;
			}

			if (runtime == null) {
				Assert.Ignore ("Runtime not found for: {0}", EngineId);
				return;
			}

			Console.WriteLine ("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version);

			// main/build/tests
			FilePath path = Path.GetDirectoryName (GetType ().Assembly.Location);
			var exe = Path.Combine (path, "MonoDevelop.Debugger.Tests.TestApp.exe");

			var cmd = new DotNetExecutionCommand ();
			cmd.TargetRuntime = runtime;
			cmd.Command = exe;
			cmd.Arguments = test;

			if (Platform.IsWindows) {
				var monoRuntime = runtime as MonoTargetRuntime;
				if (monoRuntime != null) {
					var psi = new System.Diagnostics.ProcessStartInfo (Path.Combine (monoRuntime.Prefix, "bin", "pdb2mdb.bat"), cmd.Command);
					psi.UseShellExecute = false;
					psi.CreateNoWindow = true;
					System.Diagnostics.Process.Start (psi).WaitForExit ();
				}
			}

			var dsi = engine.CreateDebuggerStartInfo (cmd);
			var soft = dsi as SoftDebuggerStartInfo;

			if (soft != null) {
				var assemblyName = AssemblyName.GetAssemblyName (exe);

				soft.UserAssemblyNames = new List<AssemblyName> ();
				soft.UserAssemblyNames.Add (assemblyName);
			}

			Session = engine.CreateSession ();
			var ops = new DebuggerSessionOptions ();
			ops.ProjectAssembliesOnly = true;
			ops.EvaluationOptions = EvaluationOptions.DefaultOptions;
			ops.EvaluationOptions.AllowTargetInvoke = AllowTargetInvokes;
			ops.EvaluationOptions.EvaluationTimeout = 100000;

			path = path.ParentDirectory.ParentDirectory.Combine ("src", "addins", "MonoDevelop.Debugger", "MonoDevelop.Debugger.Tests.TestApp", test + ".cs").FullPath;
			SourceFile = TextFile.ReadFile (path);
			TestName = test;
			AddBreakpoint ("break");
			
			var done = new ManualResetEvent (false);

			Session.TargetHitBreakpoint += (sender, e) => {
				Frame = e.Backtrace.GetFrame (0);
				lastStoppedPosition = Frame.SourceLocation;
				targetStoppedEvent.Set ();
				done.Set ();
			};

			Session.TargetExceptionThrown += (sender, e) => {
				Frame = e.Backtrace.GetFrame (0);
				for (int i = 0; i < e.Backtrace.FrameCount; i++) {
					if (!e.Backtrace.GetFrame (i).IsExternalCode) {
						Frame = e.Backtrace.GetFrame (i);
						break;
					}
				}
				lastStoppedPosition = Frame.SourceLocation;
				targetStoppedEvent.Set ();
			};

			Session.TargetStopped += (sender, e) => {
				//This can be null in case of ForcedStop
				//which is called when exception is thrown
				//when Continue & Stepping is executed
				if (e.Backtrace != null) {
					Frame = e.Backtrace.GetFrame (0);
					lastStoppedPosition = Frame.SourceLocation;
					targetStoppedEvent.Set ();
				} else {
					Console.WriteLine ("e.Backtrace is null");
				}
			};

			var targetExited = new ManualResetEvent (false);
			Session.TargetExited += delegate {
				targetExited.Set ();
			};

			Session.Run (dsi, ops);
			Session.ExceptionHandler = (ex) => {
				Console.WriteLine ("Session.ExceptionHandler:" + Environment.NewLine + ex.ToString ());
				return true;
			};
			switch (WaitHandle.WaitAny (new WaitHandle[]{ done, targetExited }, 30000)) {
			case 0:
				//Breakpoint is hit good... run tests now
				break;
			case 1:
				throw new Exception ("Test application exited before hitting breakpoint");
			default:
				throw new Exception ("Timeout while waiting for initial breakpoint");
			}
			if (Session is SoftDebuggerSession) {
				Console.WriteLine ("SDB protocol version:" + ((SoftDebuggerSession)Session).ProtocolVersion);
			}
		}
		public void AttachToProcess (long pid, DebuggerSessionOptions sessionOptions)
		{
			Report.Initialize ();

			this.SessionOptions = sessionOptions;
			DebuggerConfiguration config = new DebuggerConfiguration ();
			mdbAdaptor.Configuration = config;
			mdbAdaptor.InitializeConfiguration ();
			config.LoadConfiguration ();
			debugger = new MD.Debugger (config);

			DebuggerOptions options = DebuggerOptions.ParseCommandLine (new string[0]);
			options.StopInMain = false;
			session = new MD.DebuggerSession (config, options, "main", (IExpressionParser) null);
			mdbAdaptor.Session = session;
			
			Process proc = debugger.Attach (session, (int)pid);
			OnInitialized (debugger, proc);
			
			ST.ThreadPool.QueueUserWorkItem (delegate {
				NotifyStarted ();
			});
		}
		public void Run (MonoDebuggerStartInfo startInfo, DebuggerSessionOptions sessionOptions)
		{
			try {
				if (startInfo == null)
					throw new ArgumentNullException ("startInfo");
			
				Console.WriteLine ("MDB version: " + mdbAdaptor.MdbVersion);
				
				this.SessionOptions = sessionOptions;
				mdbAdaptor.StartInfo = startInfo;

				Report.Initialize ();

				DebuggerConfiguration config = new DebuggerConfiguration ();
				config.LoadConfiguration ();
				mdbAdaptor.Configuration = config;
				mdbAdaptor.InitializeConfiguration ();
				
				debugger = new MD.Debugger (config);
				
				debugger.ModuleLoadedEvent += OnModuleLoadedEvent;
				debugger.ModuleUnLoadedEvent += OnModuleUnLoadedEvent;
				
				debugger.ProcessReachedMainEvent += delegate (MD.Debugger deb, MD.Process proc) {
					OnInitialized (deb, proc);
				};

				if (startInfo.IsXsp) {
					mdbAdaptor.SetupXsp ();
					config.FollowFork = false;
				}
				config.OpaqueFileNames = false;
				
				DebuggerOptions options = DebuggerOptions.ParseCommandLine (new string[] { startInfo.Command } );
				options.WorkingDirectory = startInfo.WorkingDirectory;
				Environment.CurrentDirectory = startInfo.WorkingDirectory;
				options.StopInMain = false;
				
				if (!string.IsNullOrEmpty (startInfo.Arguments))
					options.InferiorArgs = ToArgsArray (startInfo.Arguments);
				
				if (startInfo.EnvironmentVariables != null) {
					foreach (KeyValuePair<string,string> env in startInfo.EnvironmentVariables)
						options.SetEnvironment (env.Key, env.Value);
				}
				session = new MD.DebuggerSession (config, options, "main", null);
				mdbAdaptor.Session = session;
				mdbAdaptor.InitializeSession ();
				
				ST.ThreadPool.QueueUserWorkItem (delegate {
					// Run in a thread to avoid a deadlock, since NotifyStarted calls back to the client.
					NotifyStarted ();
					debugger.Run(session);
				});

			} catch (Exception e) {
				Console.WriteLine ("error: " + e.ToString ());
				throw;
			}
		}