Inheritance: DebuggerMarshalByRefObject
Beispiel #1
0
        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();
            });
        }
Beispiel #2
0
        private void OnInitialized(MD.Debugger debugger, Process process)
        {
            Console.WriteLine(">> OnInitialized");

            this.process  = process;
            this.debugger = debugger;

            mdbAdaptor.Process = process;

            guiManager = process.StartGUIManager();

            //FIXME: conditionally add event handlers
            process.TargetOutputEvent += OnTargetOutput;

            debugger.ProcessCreatedEvent += OnProcessCreatedEvent;
            debugger.ProcessExecdEvent   += OnProcessExecdEvent;
            debugger.ProcessExitedEvent  += OnProcessExitedEvent;

            debugger.ThreadCreatedEvent += OnThreadCreatedEvent;
            debugger.ThreadExitedEvent  += OnThreadExitedEvent;

            debugger.TargetExitedEvent += OnTargetExitedEvent;
            guiManager.TargetEvent     += OnTargetEvent;

            // Not supported
            //guiManager.BreakpointHitHandler = BreakEventCheck;

            activeThread = process.MainThread;
            running      = true;

            Console.WriteLine("<< OnInitialized");
        }
Beispiel #3
0
        internal GUIManager(Debugger debugger)
        {
            this.Debugger = debugger;
            this.ThreadingModel = ThreadingModel.Global;

            debugger.ProcessExitedEvent += delegate (Debugger dummy, Process process) {
                try {
                    if (ProcessExitedEvent == null)
                        return;
                    ST.ThreadPool.QueueUserWorkItem (delegate {
                        ProcessExitedEvent (debugger, process);
                    });
                } catch (Exception ex) {
                    Report.Error ("Caught exception while sending process {0} exit:\n{1}",
                              process, ex);
                }
            };

            debugger.TargetEvent += delegate (Thread thread, TargetEventArgs args) {
                try {
                    if (TargetEvent == null)
                        return;
                    ST.ThreadPool.QueueUserWorkItem (delegate {
                        TargetEvent (thread, args);
                    });
                } catch (Exception ex) {
                    Report.Error ("{0} caught exception while sending {1}:\n{2}",
                              thread, args, ex);
                }
            };
        }
Beispiel #4
0
 private void OnTargetExitedEvent(MD.Debugger debugger)
 {
     exited = true;
     DispatchEvent(delegate {
         controller.OnDebuggerOutput(false, "Target exited.\n");
         DL.TargetEventArgs args = new DL.TargetEventArgs(DL.TargetEventType.TargetExited);
         controller.OnTargetEvent(args);
     });
 }
Beispiel #5
0
 public void Kill()
 {
     if (debugger != null) {
         debugger.Kill ();
         debugger = null;
     }
 }
Beispiel #6
0
        public Process Attach(int pid)
        {
            if ((debugger != null) || (main_process != null))
                throw new TargetException (TargetError.AlreadyHaveTarget);

            if (!IsScript)
                Print ("Attaching to {0}", pid);

            try {
                debugger = new Debugger (config);

                new InterpreterEventSink (this, debugger);

                CommandResult result;
                current_process = main_process = debugger.Attach (session, pid, out result);
                current_thread = current_process.MainThread;

                Wait (result);

                return current_process;
            } catch (TargetException) {
                debugger.Dispose ();
                debugger = null;
                throw;
            }
        }
Beispiel #7
0
 public void thread_exited(Debugger debugger, Thread thread)
 {
     if ((thread.ThreadFlags & Thread.Flags.Daemon) == 0)
         interpreter.OnThreadExited (thread);
 }
Beispiel #8
0
 public MyOperationHost(Debugger debugger)
 {
     this.Debugger = debugger;
 }
Beispiel #9
0
 public void process_exited(Debugger debugger, Process process)
 {
     interpreter.OnProcessExited (process);
 }
Beispiel #10
0
 public void managed_thread_created(Debugger debugger, Thread thread)
 {
     interpreter.OnThreadCreated (thread);
 }
Beispiel #11
0
        public Process OpenCoreFile(string core_file)
        {
            if ((debugger != null) || (main_process != null))
                throw new TargetException (TargetError.AlreadyHaveTarget);

            Console.WriteLine ("Loading core file {0}", core_file);

            try {
                debugger = new Debugger (config);

                new InterpreterEventSink (this, debugger);

                Thread[] threads;
                current_process = main_process = debugger.OpenCoreFile (
                    session, core_file, out threads);

                current_thread = current_process.MainThread;

                return current_process;
            } catch (TargetException) {
                debugger.Dispose ();
                debugger = null;
                throw;
            }
        }
Beispiel #12
0
        protected virtual void OnTargetExited()
        {
            debugger = null;
            main_process = current_process = null;
            current_thread = null;

            Print ("Target exited.");
        }
Beispiel #13
0
        public Process LoadSession(Stream stream)
        {
            if ((debugger != null) || (main_process != null))
                throw new TargetException (TargetError.AlreadyHaveTarget);

            try {
                debugger = new Debugger (config);
                parser = new ExpressionParser (this);
                session = new DebuggerSession (config, stream, parser);
                parser.Session = session;

                new InterpreterEventSink (this, debugger);

                CommandResult result;
                current_process = main_process = debugger.Run (session, out result);
                current_thread = current_process.MainThread;

                Wait (result);

                return current_process;
            } catch (TargetException ex) {
                Console.WriteLine ("Got a TargetException during LoadSession: {0}", ex);
                debugger.Dispose ();
                debugger = null;
                throw;
            } catch (Exception ex) {
                Console.WriteLine ("Got an Exception during LoadSession: {0}", ex);
                debugger.Dispose ();
                debugger = null;
                throw;
            }
        }
Beispiel #14
0
        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;
            }
        }
		private void OnInitialized (MD.Debugger debugger, Process process)
		{
			Console.WriteLine (">> OnInitialized");
			
			this.process = process;
			this.debugger = debugger;
			
			mdbAdaptor.Process = process;
			
			guiManager = process.StartGUIManager ();

			//FIXME: conditionally add event handlers
			process.TargetOutputEvent += OnTargetOutput;
			
			debugger.ProcessCreatedEvent += OnProcessCreatedEvent;
			debugger.ProcessExecdEvent += OnProcessExecdEvent;
			debugger.ProcessExitedEvent += OnProcessExitedEvent;
			
			debugger.ThreadCreatedEvent += OnThreadCreatedEvent;
			debugger.ThreadExitedEvent += OnThreadExitedEvent;
			
			debugger.TargetExitedEvent += OnTargetExitedEvent;
			guiManager.TargetEvent += OnTargetEvent;

			// Not supported
			//guiManager.BreakpointHitHandler = BreakEventCheck;
			
			activeThread = process.MainThread;
			running = true;
			
			Console.WriteLine ("<< OnInitialized");
		}
		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;
			}
		}
Beispiel #18
0
        public Process Start()
        {
            if ((debugger != null) || (main_process != null))
                throw new TargetException (TargetError.AlreadyHaveTarget);

            if (!IsScript)
                Print ("Starting program: {0} {1}", Options.File,
                       String.Join (" ", Options.InferiorArgs));

            try {
                debugger = new Debugger (config);

                new InterpreterEventSink (this, debugger);

                CommandResult result;
                current_process = main_process = debugger.Run (session, out result);
                current_thread = current_process.MainThread;

                Wait (result);

                return current_process;
            } catch (TargetException) {
                debugger.Dispose ();
                debugger = null;
                throw;
            }
        }
Beispiel #19
0
 private void OnProcessExecdEvent(MD.Debugger debugger, MD.Process process)
 {
     WriteDebuggerOutput(string.Format("Process {0} execd.\n", process.ID));
 }
Beispiel #20
0
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            lock (this) {
                if (disposed)
                    return;

                disposed = true;
            }

            // If this is a call to Dispose, dispose all managed resources.
            if (disposing) {
                if (debugger != null) {
                    debugger.Kill ();
                    debugger = null;
                }
            }
        }
Beispiel #21
0
 private void OnThreadCreatedEvent(MD.Debugger debugger, MD.Thread thread)
 {
     WriteDebuggerOutput(string.Format("Thread {0} created.\n", thread.ID));
 }
Beispiel #22
0
            public InterpreterEventSink(Interpreter interpreter, Debugger debugger)
            {
                this.interpreter = interpreter;

                debugger.TargetExitedEvent += target_exited;
                debugger.ThreadCreatedEvent += thread_created;
                debugger.ManagedThreadCreatedEvent += managed_thread_created;
                debugger.ThreadExitedEvent += thread_exited;
                debugger.MainProcessCreatedEvent += main_process_created;
                debugger.ProcessReachedMainEvent += process_reached_main;
                debugger.ProcessCreatedEvent += process_created;
                debugger.ProcessExitedEvent += process_exited;
                debugger.ProcessExecdEvent += process_execd;
                debugger.TargetEvent += target_event;
                debugger.EnterNestedBreakStateEvent +=
                    delegate (Debugger unused, Thread thread) {
                        interpreter.OnEnterNestedBreakState (thread);
                    };
                debugger.LeaveNestedBreakStateEvent +=
                    delegate (Debugger unused, Thread thread) {
                        interpreter.OnLeaveNestedBreakState (thread);
                    };
            }
Beispiel #23
0
 public void target_exited(Debugger debugger)
 {
     interpreter.OnTargetExited ();
 }
Beispiel #24
0
 public void process_created(Debugger debugger, Process process)
 {
     interpreter.OnProcessCreated (process);
 }
Beispiel #25
0
 public void thread_created(Debugger debugger, Thread thread)
 {
     if (!thread.Process.IsManaged ||
         ((thread.ThreadFlags & Thread.Flags.Daemon) == 0))
         interpreter.OnThreadCreated (thread);
 }
Beispiel #26
0
 public void process_reached_main(Debugger debugger, Process process)
 {
     interpreter.OnProcessReachedMain (process);
 }
Beispiel #27
0
 internal GlobalCommandResult(Debugger debugger, ThreadingModel model)
     : base(model)
 {
     this.Debugger = debugger;
 }