protected override void OnRun(DebuggerStartInfo startInfo)
        {
            started = true;
            MonoDebuggerStartInfo info = (MonoDebuggerStartInfo)startInfo;

            controller.StartDebugger(info);
            InitMdbVersion(info.MonoPrefix);
            controller.DebuggerServer.Run(info, Options);
        }
		public void StartDebugger (MonoDebuggerStartInfo startInfo)
		{
			lock (this)
			{
				exitRequestEvent.Reset ();

				string chId = RegisterRemotingChannel();

				BinaryFormatter bf = new BinaryFormatter();
				ObjRef oref = RemotingServices.Marshal(this);
				MemoryStream ms = new MemoryStream();
				bf.Serialize(ms, oref);
				string sref = Convert.ToBase64String(ms.ToArray());
				try
				{
					Process process = new Process();
					process.Exited += new EventHandler (ProcessExited);
					string location = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
					string argv = string.Empty;
					//if (isDebugMode) argv += " --debug";
					argv += " --debug '" + Path.Combine(location, "DebuggerServer.exe") + "' ";

					process.StartInfo = new ProcessStartInfo ("mono", argv);
					
					if (startInfo != null) {
						string monoPath = Path.Combine (startInfo.MonoPrefix, "bin");
						process.StartInfo.FileName = Path.Combine (monoPath, "mono");
						if (startInfo.ServerEnvironment != null) {
							foreach (KeyValuePair<string,string> evar in startInfo.ServerEnvironment)
								process.StartInfo.EnvironmentVariables [evar.Key] = evar.Value;
						}
					}
					
					process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
					process.StartInfo.UseShellExecute = false;
					process.StartInfo.RedirectStandardInput = true;
					process.EnableRaisingEvents = true;
					process.Start();
					
					// The server expects 3 lines with the following content:
					// 1) location of the Mono.Debugging assembly (needed since it may be located
					//    in a different directory)
					// 2) Remting channel to use
					// 3) Serialized reference to the IDebuggerController
					process.StandardInput.WriteLine (typeof(DebuggerSession).Assembly.Location);
					process.StandardInput.WriteLine (chId);
					process.StandardInput.WriteLine (sref);
					process.StandardInput.Flush();
					this.process = process;
				}
				catch (Exception ex)
				{
					Console.WriteLine("Error launching server: " + ex.ToString());
					throw;
				}
			}
			
			if (!runningEvent.WaitOne (15000, false)) {
				throw new ApplicationException ("Could not create the debugger process.");
			}
		}
		public static MonoDebuggerStartInfo CreateDebuggerStartInfo (TargetRuntime tr)
		{
			if (tr == null) tr = MonoDevelop.Core.Runtime.SystemAssemblyService.DefaultRuntime;
			MonoDebuggerStartInfo startInfo = new MonoDebuggerStartInfo ();
			MonoTargetRuntime mtr = (MonoTargetRuntime) tr;
			startInfo.ServerEnvironment = mtr.EnvironmentVariables;
			startInfo.MonoPrefix = mtr.Prefix;
			return startInfo;
		}
		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;
			}
		}
示例#5
0
        public void StartDebugger(MonoDebuggerStartInfo startInfo)
        {
            lock (this)
            {
                exitRequestEvent.Reset();

                string chId = RegisterRemotingChannel();

                BinaryFormatter bf   = new BinaryFormatter();
                ObjRef          oref = RemotingServices.Marshal(this);
                MemoryStream    ms   = new MemoryStream();
                bf.Serialize(ms, oref);
                string sref = Convert.ToBase64String(ms.ToArray());
                try
                {
                    Process process = new Process();
                    process.Exited += new EventHandler(ProcessExited);
                    string location = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    string argv     = string.Empty;
                    //if (isDebugMode) argv += " --debug";
                    argv += " --debug '" + Path.Combine(location, "DebuggerServer.exe") + "' ";

                    process.StartInfo = new ProcessStartInfo("mono", argv);

                    if (startInfo != null)
                    {
                        string monoPath = Path.Combine(startInfo.MonoPrefix, "bin");
                        process.StartInfo.FileName = Path.Combine(monoPath, "mono");
                        if (startInfo.ServerEnvironment != null)
                        {
                            foreach (KeyValuePair <string, string> evar in startInfo.ServerEnvironment)
                            {
                                process.StartInfo.EnvironmentVariables [evar.Key] = evar.Value;
                            }
                        }
                    }

                    process.StartInfo.WorkingDirectory      = AppDomain.CurrentDomain.BaseDirectory;
                    process.StartInfo.UseShellExecute       = false;
                    process.StartInfo.RedirectStandardInput = true;
                    process.EnableRaisingEvents             = true;
                    process.Start();

                    // The server expects 3 lines with the following content:
                    // 1) location of the Mono.Debugging assembly (needed since it may be located
                    //    in a different directory)
                    // 2) Remting channel to use
                    // 3) Serialized reference to the IDebuggerController
                    process.StandardInput.WriteLine(typeof(DebuggerSession).Assembly.Location);
                    process.StandardInput.WriteLine(chId);
                    process.StandardInput.WriteLine(sref);
                    process.StandardInput.Flush();
                    this.process = process;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error launching server: " + ex.ToString());
                    throw;
                }
            }

            if (!runningEvent.WaitOne(15000, false))
            {
                throw new ApplicationException("Could not create the debugger process.");
            }
        }