Beispiel #1
0
        public static void Run(FileInfo file)
        {
            lock (_lock)
            {
                EnsureCreated();

                CurrentExecutable = file;
                CurrentAddress    = null;
                CurrentPort       = -1;

                _debuggeeKilled = false;
                _kind           = SessionKind.Launched;

                var info = new SoftDebuggerStartInfo(Configuration.Current.RuntimePrefix,
                                                     new Dictionary <string, string>(EnvironmentVariables))
                {
                    Command          = file.FullName,
                    Arguments        = Arguments,
                    WorkingDirectory = WorkingDirectory,
                    StartArgs        =
                    {
                        MaxConnectionAttempts         = Configuration.Current.MaxConnectionAttempts,
                        TimeBetweenConnectionAttempts = Configuration.Current.ConnectionAttemptInterval
                    }
                };

                // We need to ignore `SIGINT` while we start the inferior
                // process so that it inherits that signal disposition.
                CommandLine.UnsetControlCHandler();

                _session.Run(info, Options);

                CommandLine.InferiorExecuting = true;
            }
        }
Beispiel #2
0
        public static void Connect(IPAddress address, int port)
        {
            lock (_lock)
            {
                EnsureCreated();

                CurrentExecutable = null;
                CurrentAddress    = address;
                CurrentPort       = port;

                _showResumeMessage = false;
                _debuggeeKilled    = false;
                _kind = SessionKind.Connected;

                var args = new SoftDebuggerConnectArgs(string.Empty, address, port)
                {
                    MaxConnectionAttempts         = Configuration.Current.MaxConnectionAttempts,
                    TimeBetweenConnectionAttempts = Configuration.Current.ConnectionAttemptInterval
                };

                _session.Run(new SoftDebuggerStartInfo(args), Options);

                CommandLine.InferiorExecuting = true;
            }
        }
Beispiel #3
0
 public LivyClient(string livyUrl, string user, string password, SessionKind kind = SessionKind.pyspark3)
 {
     this.livyUrl  = livyUrl;
     this.user     = user;
     this.password = password;
     this.kind     = kind;
 }
Beispiel #4
0
        public static void Listen(IPAddress address, int port)
        {
            lock (_lock)
            {
                EnsureCreated();

                CurrentExecutable = null;
                CurrentAddress    = address;
                CurrentPort       = port;

                _debuggeeKilled = false;
                _kind           = SessionKind.Listening;

                var args = new SoftDebuggerListenArgs(string.Empty, address, port);

                _session.Run(new SoftDebuggerStartInfo(args), Options);

                CommandLine.InferiorExecuting = true;
            }
        }
Beispiel #5
0
        public static void Disconnect()
        {
            lock (_lock)
            {
                if (_session == null)
                {
                    return;
                }

                CommandLine.InferiorExecuting = true;

                _kind = SessionKind.Disconnected;

                Breakpoints.Clear();
                BreakEvents.Clear();

                _session.Continue();

                _session = null;
            }
        }
		public static void Disconnect()
		{
			lock (_lock)
			{
				if (_session == null)
					return;

				CommandLine.InferiorExecuting = true;

				_kind = SessionKind.Disconnected;

				Breakpoints.Clear();
				BreakEvents.Clear();

				_session.Continue();

				_session = null;
			}
		}
		public static void Listen(IPAddress address, int port)
		{
			lock (_lock)
			{
				EnsureCreated();

				CurrentExecutable = null;
				CurrentAddress = address;
				CurrentPort = port;

				_debuggeeKilled = false;
				_kind = SessionKind.Listening;

				var args = new SoftDebuggerListenArgs(string.Empty, address, port);

				_session.Run(new SoftDebuggerStartInfo(args), Options);

				CommandLine.InferiorExecuting = true;
			}
		}
		public static void Connect(IPAddress address, int port)
		{
			lock (_lock)
			{
				EnsureCreated();

				CurrentExecutable = null;
				CurrentAddress = address;
				CurrentPort = port;

				_debuggeeKilled = false;
				_kind = SessionKind.Connected;

				var args = new SoftDebuggerConnectArgs(string.Empty, address, port)
				{
					MaxConnectionAttempts = Configuration.Current.MaxConnectionAttempts,
					TimeBetweenConnectionAttempts = Configuration.Current.ConnectionAttemptInterval
				};

				_session.Run(new SoftDebuggerStartInfo(args), Options);

				CommandLine.InferiorExecuting = true;
			}
		}
		public static void Run(FileInfo file)
		{
			lock (_lock)
			{
				EnsureCreated();

				CurrentExecutable = file;
				CurrentAddress = null;
				CurrentPort = -1;

				_debuggeeKilled = false;
				_kind = SessionKind.Launched;

				var info = new SoftDebuggerStartInfo(Configuration.Current.RuntimePrefix,
					new Dictionary<string, string>(EnvironmentVariables))
				{
					Command = file.FullName,
					Arguments = Arguments,
					WorkingDirectory = WorkingDirectory,
					StartArgs =
					{
						MaxConnectionAttempts = Configuration.Current.MaxConnectionAttempts,
						TimeBetweenConnectionAttempts = Configuration.Current.ConnectionAttemptInterval
					}
				};

				// We need to ignore `SIGINT` while we start the inferior
				// process so that it inherits that signal disposition.
				CommandLine.UnsetControlCHandler();

				_session.Run(info, Options);

				CommandLine.InferiorExecuting = true;
			}
		}
		static void EnsureCreated()
		{
			lock (_lock)
			{
				if (_session != null)
					return;

				_session = new SoftDebuggerSession();
				_session.Breakpoints = BreakEvents;

				_session.ExceptionHandler = ex =>
				{
					if (Configuration.Current.LogInternalErrors)
					{
						Log.Error("Internal debugger error:", ex.GetType());
						Log.Error(ex.ToString());
					}

					return true;
				};

				_session.LogWriter = (isStdErr, text) =>
				{
					if (Configuration.Current.LogRuntimeSpew)
						Log.NoticeSameLine("[Mono] {0}", text); // The string already has a line feed.
				};

				_session.OutputWriter = (isStdErr, text) =>
				{
					//lock (Log.Lock)
					//{
						if (Callback != null)
						{
							Callback.Invoke(isStdErr ? "ErrorOutput" : "Output", null, null, text);
						}
						else
						{
							if (isStdErr)
								Console.Error.Write(text);
							else
								Console.Write(text);
						}
					//}
				};

				_session.TypeResolverHandler += (identifier, location) =>
				{
					// I honestly have no idea how correct this is. I suspect you
					// could probably break it in some corner cases. It does make
					// something like `p Android.Runtime.JNIEnv.Handle` work,
					// though, which would otherwise have required `global::` to
					// be explicitly prepended.

					if (identifier == "__EXCEPTION_OBJECT__")
						return null;

					foreach (var loc in ActiveFrame.GetAllLocals())
						if (loc.Name == identifier)
							return null;

					return identifier;
				};

				_session.TargetEvent += (sender, e) =>
				{
					Log.Debug("Event: '{0}'", e.Type);
				};

				_session.TargetStarted += (sender, e) =>
				{
					_activeFrame = null;

					/*
					if (_showResumeMessage)
						Log.Notice("Inferior process '{0}' ('{1}') resumed",
							ActiveProcess.Id, StringizeTarget());
					*/
				};

				_session.TargetReady += (sender, e) =>
				{
					_activeProcess = _session.GetProcesses().SingleOrDefault();

					// The inferior process has launched, so we can safely
					// set our `SIGINT` handler without it interfering with
					// the inferior.
					CommandLine.SetControlCHandler();

					/*
					Log.Notice("Inferior process '{0}' ('{1}') started",
						ActiveProcess.Id, StringizeTarget());
					*/
				};

				_session.TargetStopped += (sender, e) =>
				{
					//Log.Notice("Inferior process '{0}' ('{1}') suspended",
					//	ActiveProcess.Id, StringizeTarget());
					//Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

					if (Callback != null)
					{
						Callback.Invoke("TargetStopped", ActiveFrame.SourceLocation, e.Thread, null);
					}

					CommandLine.ResumeEvent.Set();
				};

				_session.TargetInterrupted += (sender, e) =>
				{
					Log.Notice("Inferior process '{0}' ('{1}') interrupted",
						ActiveProcess.Id, StringizeTarget());
					Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

					CommandLine.ResumeEvent.Set();
				};

				_session.TargetHitBreakpoint += (sender, e) =>
				{
					// var bp = e.BreakEvent as Breakpoint;
					// var fbp = e.BreakEvent as FunctionBreakpoint;

					/*
					if (fbp != null)
						Log.Notice("Hit method breakpoint on '{0}'", fbp.FunctionName);
					else
					{
						var cond = bp.ConditionExpression != null ?
							string.Format(" (condition '{0}' met)", bp.ConditionExpression) :
							string.Empty;

						Log.Notice("Hit breakpoint at '{0}:{1}'{2}", bp.FileName, bp.Line, cond);
					}

					Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));
					*/

					if (Callback != null)
					{
						Callback.Invoke("TargetHitBreakpoint", ActiveFrame.SourceLocation, e.Thread, null);
					}

					CommandLine.ResumeEvent.Set();
				};

				_session.TargetExited += (sender, e) =>
				{
					var p = ActiveProcess;

					/*
					// Can happen when a remote connection attempt fails.
					if (p == null)
					{
						if (_kind == SessionKind.Listening)
							Log.Notice("Listening socket closed");
						else if (_kind == SessionKind.Connected)
							Log.Notice("Connection attempt terminated");
						else
							Log.Notice("Failed to connect to '{0}'", StringizeTarget());
					}
					else
						Log.Notice("Inferior process '{0}' ('{1}') exited", ActiveProcess.Id, StringizeTarget());
					*/

					// Make sure we clean everything up on a normal exit.
					Kill();

					_debuggeeKilled = true;
					_kind = SessionKind.Disconnected;

					if (Callback != null)
					{
						Callback.Invoke("TargetExited", null, null, null);
					}

					CommandLine.ResumeEvent.Set();
				};

				_session.TargetExceptionThrown += (sender, e) =>
				{
					var ex = ActiveException;

					//Log.Notice("Trapped first-chance exception of type '{0}'", ex.Type);
					//Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

					PrintException(ex);

					if (Callback != null)
					{
						Callback.Invoke("TargetExceptionThrown", ActiveFrame.SourceLocation, e.Thread, null);
					}

					CommandLine.ResumeEvent.Set();
				};

				_session.TargetUnhandledException += (sender, e) =>
				{
					var ex = ActiveException;

					//Log.Notice("Trapped unhandled exception of type '{0}'", ex.Type);
					//Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

					PrintException(ex);

					if (Callback != null)
					{
						Callback.Invoke("TargetUnhandledException", ActiveFrame.SourceLocation, e.Thread, null);
					}

					CommandLine.ResumeEvent.Set();
				};

				_session.TargetThreadStarted += (sender, e) =>
				{
					//Log.Notice("Inferior thread '{0}' ('{1}') started",
					//	e.Thread.Id, e.Thread.Name);

					if (Callback != null)
					{
						Callback.Invoke("TargetThreadStarted", null, e.Thread, null);
					}
				};

				_session.TargetThreadStopped += (sender, e) =>
				{
					//Log.Notice("Inferior thread '{0}' ('{1}') exited",
					//	e.Thread.Id, e.Thread.Name);

					if (Callback != null)
					{
						Callback.Invoke("TargetThreadStopped", null, e.Thread, null);
					}
				};
			}
		}
Beispiel #11
0
        static void EnsureCreated()
        {
            lock (_lock)
            {
                if (_session != null)
                {
                    return;
                }

                _session             = new SoftDebuggerSession();
                _session.Breakpoints = BreakEvents;

                _session.ExceptionHandler = ex =>
                {
                    if (Configuration.Current.LogInternalErrors)
                    {
                        Log.Error("Internal debugger error:", ex.GetType());
                        Log.Error(ex.ToString());
                    }

                    return(true);
                };

                _session.LogWriter = (isStdErr, text) =>
                {
                    if (Configuration.Current.LogRuntimeSpew)
                    {
                        Log.NoticeSameLine("[Mono] {0}", text); // The string already has a line feed.
                    }
                };

                _session.OutputWriter = (isStdErr, text) =>
                {
                    lock (Log.Lock)
                    {
                        if (isStdErr)
                        {
                            Console.Error.Write(text);
                        }
                        else
                        {
                            Console.Write(text);
                        }
                    }
                };

                _session.TypeResolverHandler += (identifier, location) =>
                {
                    // I honestly have no idea how correct this is. I suspect you
                    // could probably break it in some corner cases. It does make
                    // something like `p Android.Runtime.JNIEnv.Handle` work,
                    // though, which would otherwise have required `global::` to
                    // be explicitly prepended.

                    if (identifier == "__EXCEPTION_OBJECT__")
                    {
                        return(null);
                    }

                    foreach (var loc in ActiveFrame.GetAllLocals())
                    {
                        if (loc.Name == identifier)
                        {
                            return(null);
                        }
                    }

                    return(identifier);
                };

                _session.TargetEvent += (sender, e) =>
                {
                    Log.Debug("Event: '{0}'", e.Type);
                };

                _session.TargetStarted += (sender, e) =>
                {
                    _activeFrame = null;

                    if (_showResumeMessage)
                    {
                        Log.Notice("Inferior process '{0}' ('{1}') resumed",
                                   ActiveProcess.Id, StringizeTarget());
                    }
                };

                _session.TargetReady += (sender, e) =>
                {
                    _showResumeMessage = true;
                    _activeProcess     = _session.GetProcesses().SingleOrDefault();

                    // The inferior process has launched, so we can safely
                    // set our `SIGINT` handler without it interfering with
                    // the inferior.
                    CommandLine.SetControlCHandler();

                    Log.Notice("Inferior process '{0}' ('{1}') started",
                               ActiveProcess.Id, StringizeTarget());
                };

                _session.TargetStopped += (sender, e) =>
                {
                    Log.Notice("Inferior process '{0}' ('{1}') suspended",
                               ActiveProcess.Id, StringizeTarget());
                    Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

                    CommandLine.ResumeEvent.Set();
                };

                _session.TargetInterrupted += (sender, e) =>
                {
                    Log.Notice("Inferior process '{0}' ('{1}') interrupted",
                               ActiveProcess.Id, StringizeTarget());
                    Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

                    CommandLine.ResumeEvent.Set();
                };

                _session.TargetHitBreakpoint += (sender, e) =>
                {
                    var bp  = e.BreakEvent as Breakpoint;
                    var fbp = e.BreakEvent as FunctionBreakpoint;

                    if (fbp != null)
                    {
                        Log.Notice("Hit method breakpoint on '{0}'", fbp.FunctionName);
                    }
                    else
                    {
                        var cond = bp.ConditionExpression != null?
                                   string.Format(" (condition '{0}' met)", bp.ConditionExpression) :
                                       string.Empty;

                        Log.Notice("Hit breakpoint at '{0}:{1}'{2}", bp.FileName, bp.Line, cond);
                    }

                    Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

                    CommandLine.ResumeEvent.Set();
                };

                _session.TargetExited += (sender, e) =>
                {
                    var p = ActiveProcess;

                    // Can happen when a remote connection attempt fails.
                    if (p == null)
                    {
                        if (_kind == SessionKind.Listening)
                        {
                            Log.Notice("Listening socket closed");
                        }
                        else if (_kind == SessionKind.Connected)
                        {
                            Log.Notice("Connection attempt terminated");
                        }
                        else
                        {
                            Log.Notice("Failed to connect to '{0}'", StringizeTarget());
                        }
                    }
                    else
                    {
                        var code = e.ExitCode != null?string.Format(" with code '{0}'", e.ExitCode) : string.Empty;

                        Log.Notice("Inferior process '{0}' ('{1}') exited{2}", ActiveProcess.Id, StringizeTarget(), code);
                    }

                    // Make sure we clean everything up on a normal exit.
                    Kill();

                    _debuggeeKilled = true;
                    _kind           = SessionKind.Disconnected;

                    CommandLine.ResumeEvent.Set();
                };

                _session.TargetExceptionThrown += (sender, e) =>
                {
                    var ex = ActiveException;

                    Log.Notice("Trapped first-chance exception of type '{0}'", ex.Type);
                    Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

                    PrintException(ex);

                    CommandLine.ResumeEvent.Set();
                };

                _session.TargetUnhandledException += (sender, e) =>
                {
                    var ex = ActiveException;

                    Log.Notice("Trapped unhandled exception of type '{0}'", ex.Type);
                    Log.Emphasis(Utilities.StringizeFrame(ActiveFrame, true));

                    PrintException(ex);

                    CommandLine.ResumeEvent.Set();
                };

                _session.TargetThreadStarted += (sender, e) =>
                {
                    Log.Notice("Inferior thread '{0}' ('{1}') started",
                               e.Thread.Id, e.Thread.Name);
                };

                _session.TargetThreadStopped += (sender, e) =>
                {
                    Log.Notice("Inferior thread '{0}' ('{1}') exited",
                               e.Thread.Id, e.Thread.Name);
                };
            }
        }
Beispiel #12
0
        public override string ToString()
        {
            // `new Uri ("/")` and `new Uri ("/a")` (but not `new Uri ("/aa")`)
            // throws UriFormatException on Mono, and Windows really does not
            // like it if you just prepend 'file://' to an absolute path...
            if (WorkbookPath != null)
            {
                var uri = new Uri(WorkbookPath, UriKind.RelativeOrAbsolute);
                if (uri.IsAbsoluteUri)
                {
                    return(uri.ToString());
                }

                // this should be okay for Mono for the '/' and '/a' cases...
                return("file://" + uri);
            }

            var builder = new StringBuilder(128 * (AssemblySearchPaths.Length + 2));

            builder.Append(xamarinInteractiveScheme).Append("://");

            // if Port is non-zero we will have explicitly
            // set both Port and Host in a constructor
            if (Port > 0)
            {
                builder.Append(Host).Append(':').Append(Port);
            }

            var qpCount = 0;

            void QP(string k, object v)
            => builder
            .Append(qpCount++ == 0 ? "/v1?" : "&")
            .Append(k)
            .Append('=')
            .Append(v);

            if (AgentType != AgentType.Unknown)
            {
                QP("agentType", AgentType.ToString());
            }

            if (SessionKind != ClientSessionKind.Unknown)
            {
                QP("sessionKind", SessionKind.ToString());
            }

            foreach (var path in AssemblySearchPaths)
            {
                if (!String.IsNullOrEmpty(path))
                {
                    QP("assemblySearchPath", Uri.EscapeDataString(path));
                }
            }

            if (!String.IsNullOrEmpty(WorkingDirectory))
            {
                QP("workingDirectory", Uri.EscapeDataString(WorkingDirectory));
            }

            foreach (var parameter in Parameters)
            {
                if (!String.IsNullOrEmpty(parameter.Key))
                {
                    QP(
                        Uri.EscapeDataString(parameter.Key),
                        Uri.EscapeDataString(parameter.Value));
                }
            }

            return(builder.ToString());
        }
Beispiel #13
0
 public SessionStatementRequest(Models.Requests.SessionStatementRequest request)
 {
     Code = request.Code;
     Kind = (SessionKind)request.Kind;
 }
Beispiel #14
0
 public SessionCfg(string name, SessionKind kind, string gameDefinitionFile)
 {
     Name = name;
     Kind = kind;
     GameDefinitionFile = new PropString(gameDefinitionFile);
 }