Esempio n. 1
0
        private void OnResult(string cmd, string token)
        {
            uint id = token != null?uint.Parse(token, CultureInfo.InvariantCulture) : 0;

            _lastResult = cmd;
            Results results = MIResults.ParseCommandOutput(cmd);

            if (results.ResultClass == ResultClass.done)
            {
                if (EvaluationEvent != null)
                {
                    EvaluationEvent(this, new ResultEventArgs(results, id));
                }
            }
            else if (results.ResultClass == ResultClass.error)
            {
                if (ErrorEvent != null)
                {
                    ErrorEvent(this, new ResultEventArgs(results, id));
                }
            }
            else
            {
                OnStateChanged(cmd, "");
            }
        }
Esempio n. 2
0
 public Debugger(LaunchOptions launchOptions, Logger logger)
 {
     _launchOptions = launchOptions;
     _debuggeePids  = new Dictionary <string, int>();
     Logger         = logger;
     _miResults     = new MIResults(logger);
 }
Esempio n. 3
0
        private void OnDebuggeeOutput(string cmd)
        {
            if (cmd.StartsWith("=thread-created,", StringComparison.Ordinal))
            {
                Results results = MIResults.ParseResultList(cmd.Substring(16));
                ThreadCreatedEvent(this, new ResultEventArgs(results, 0));
            }
            else if (cmd.StartsWith("=thread-exited,", StringComparison.Ordinal))
            {
                Results results = MIResults.ParseResultList(cmd.Substring(15));
                ThreadExitedEvent(this, new ResultEventArgs(results, 0));
            }
            string decodedOutput = MIResults.ParseCString(cmd);

            if (_consoleCommandOutput == null)
            {
                if (MessageEvent != null)
                {
                    MessageEvent(this, decodedOutput);
                }
            }
            else
            {
                _consoleCommandOutput.Append(decodedOutput);
            }
        }
Esempio n. 4
0
        private void OnNotificationOutput(string cmd)
        {
            Results results = null;

            if ((results = MICommandFactory.IsModuleLoad(cmd)) != null)
            {
                if (LibraryLoadEvent != null)
                {
                    LibraryLoadEvent(this, new ResultEventArgs(results));
                }
            }
            else if (cmd.StartsWith("breakpoint-modified,", StringComparison.Ordinal))
            {
                results = MIResults.ParseResultList(cmd.Substring(20));
                if (BreakChangeEvent != null)
                {
                    BreakChangeEvent(this, new ResultEventArgs(results));
                }
            }
            else if (cmd.StartsWith("thread-group-started,", StringComparison.Ordinal))
            {
                results = MIResults.ParseResultList(cmd.Substring("thread-group-started,".Length));
                HandleThreadGroupStarted(results);
            }
            else if (cmd.StartsWith("thread-created,", StringComparison.Ordinal))
            {
                results = MIResults.ParseResultList(cmd.Substring("thread-created,".Length));
                ThreadCreatedEvent(this, new ResultEventArgs(results, 0));
            }
            else if (cmd.StartsWith("thread-exited,", StringComparison.Ordinal))
            {
                results = MIResults.ParseResultList(cmd.Substring("thread-exited,".Length));
                ThreadExitedEvent(this, new ResultEventArgs(results, 0));
            }
            // NOTE: the message event is an MI Extension from clrdbg, though we could use in it the future for other debuggers
            else if (cmd.StartsWith("message,", StringComparison.Ordinal))
            {
                results = MIResults.ParseResultList(cmd.Substring("message,".Length));
                if (this.MessageEvent != null)
                {
                    this.MessageEvent(this, new ResultEventArgs(results));
                }
            }
            else if (cmd.StartsWith("telemetry,", StringComparison.Ordinal))
            {
                results = MIResults.ParseResultList(cmd.Substring("telemetry,".Length));
                if (this.TelemetryEvent != null)
                {
                    this.TelemetryEvent(this, new ResultEventArgs(results));
                }
            }
            else
            {
                OnDebuggeeOutput("=" + cmd);
            }
        }
Esempio n. 5
0
        public Results IsModuleLoad(string cmd)
        {
            Results results = null;

            if (cmd.StartsWith("library-loaded,", StringComparison.Ordinal))
            {
                results = MIResults.ParseResultList(cmd.Substring(15));
            }
            return(results);
        }
Esempio n. 6
0
 private void OnLogStreamOutput(string cmd)
 {
     if (_consoleCommandOutput == null)
     {
         // We see this in the transport diagnostics, we don't need to see it anywhere else
     }
     else
     {
         string decodedOutput = MIResults.ParseCString(cmd);
         _consoleCommandOutput.Append(decodedOutput);
     }
 }
Esempio n. 7
0
        protected async virtual void OnStateChanged(string mode, string strresult)
        {
            // NOTE: This is an async void method, so any exception leaked from here may crash Visual Studio. Be very careful.

            Results results = MIResults.ParseResultList(strresult);

            if (mode == "stopped")
            {
                OnStopped(results);
            }
            else if (mode == "running")
            {
                this.ProcessState = ProcessState.Running;
                if (RunModeEvent != null)
                {
                    RunModeEvent(this, new ResultEventArgs(results));
                }
            }
            else if (mode == "exit")
            {
                OnDebuggerProcessExit();
            }
            else if (mode.StartsWith("done,bkpt="))
            {
                // TODO handle breakpoint binding
            }
            else if (mode == "done")
            {
            }
            else if (mode == "connected")
            {
                if (this.ProcessState == ProcessState.NotConnected)
                {
                    this.ProcessState = ProcessState.Running;
                }

                if (RunModeEvent != null)
                {
                    RunModeEvent(this, new ResultEventArgs(results));
                }
            }
            else
            {
                Debug.Fail("Unknown mode: " + mode);
            }

            return;
        }
Esempio n. 8
0
        private void OnDebuggeeOutput(string cmd)
        {
            string decodedOutput = MIResults.ParseCString(cmd);

            if (_consoleCommandOutput == null)
            {
                if (OutputStringEvent != null)
                {
                    OutputStringEvent(this, decodedOutput);
                }
            }
            else
            {
                _consoleCommandOutput.Append(decodedOutput);
            }
        }
Esempio n. 9
0
        protected virtual void OnStateChanged(string mode, string strresult)
        {
            Results results = MIResults.ParseResultList(strresult);

            if (mode == "stopped")
            {
                OnStopped(results);
            }
            else if (mode == "running")
            {
                this.ProcessState = ProcessState.Running;
                if (RunModeEvent != null)
                {
                    RunModeEvent(this, new ResultEventArgs(results));
                }
            }
            else if (mode == "exit")
            {
                OnDebuggerProcessExit(null);
            }
            else if (mode.StartsWith("done,bkpt=", StringComparison.Ordinal))
            {
                // TODO handle breakpoint binding
            }
            else if (mode == "done")
            {
            }
            else if (mode == "connected")
            {
                if (this.ProcessState == ProcessState.NotConnected)
                {
                    this.ProcessState = ProcessState.Running;
                }

                if (RunModeEvent != null)
                {
                    RunModeEvent(this, new ResultEventArgs(results));
                }
            }
            else
            {
                Debug.Fail("Unknown mode: " + mode);
            }

            return;
        }
Esempio n. 10
0
 private void OnOutOfBand(string cmd)
 {
     if (cmd.StartsWith("stopped,", StringComparison.Ordinal))
     {
         string status = MIResults.ParseCString(cmd.Substring(8));
         OnStateChanged("stopped", status);
     }
     else if (cmd.StartsWith("running,", StringComparison.Ordinal))
     {
         string status = MIResults.ParseCString(cmd.Substring(8));
         OnStateChanged("running", status);
     }
     else
     {
         Debug.Fail("Unknown out-of-band msg: " + cmd);
     }
 }
Esempio n. 11
0
        private void OnNotificationOutput(string cmd)
        {
            Results results = null;

            if ((results = MICommandFactory.IsModuleLoad(cmd)) != null)
            {
                if (LibraryLoadEvent != null)
                {
                    LibraryLoadEvent(this, new ResultEventArgs(results));
                }
            }
            else if (cmd.StartsWith("breakpoint-modified,", StringComparison.Ordinal))
            {
                results = MIResults.ParseResultList(cmd.Substring(20));
                if (BreakChangeEvent != null)
                {
                    BreakChangeEvent(this, new ResultEventArgs(results));
                }
            }
            else
            {
                OnDebuggeeOutput("=" + cmd);
            }
        }
Esempio n. 12
0
        public void ProcessStdOutLine(string line)
        {
            if (line.Length == 0)
            {
                return;
            }
            else if (line == "(gdb)")
            {
                if (_consoleDebuggerInitializeCompletionSource != null)
                {
                    lock (_waitingOperations)
                    {
                        if (_consoleDebuggerInitializeCompletionSource != null)
                        {
                            _consoleDebuggerInitializeCompletionSource.TrySetResult(null);
                        }
                    }
                }
            }
            else
            {
                string token    = ParseToken(ref line);
                char   c        = line[0];
                string noprefix = line.Substring(1).Trim();

                if (token != null)
                {
                    // Look for event handlers registered on a specific Result id
                    if (c == '^')
                    {
                        uint id = uint.Parse(token, CultureInfo.InvariantCulture);
                        WaitingOperationDescriptor waitingOperation = null;
                        lock (_waitingOperations)
                        {
                            if (_waitingOperations.TryGetValue(id, out waitingOperation))
                            {
                                _waitingOperations.Remove(id);
                            }
                        }
                        if (waitingOperation != null)
                        {
                            Results results = MIResults.ParseCommandOutput(noprefix);
                            Logger.WriteLine(id + ": elapsed time " + (int)(DateTime.Now - waitingOperation.StartTime).TotalMilliseconds);
                            waitingOperation.OnComplete(results, this.MICommandFactory);
                            return;
                        }
                    }
                    // Check to see if we are just getting the echo of the command we sent
                    else if (c == '-')
                    {
                        uint id = uint.Parse(token, CultureInfo.InvariantCulture);
                        lock (_waitingOperations)
                        {
                            WaitingOperationDescriptor waitingOperation;
                            if (_waitingOperations.TryGetValue(id, out waitingOperation) &&
                                !waitingOperation.EchoReceived &&
                                line == waitingOperation.Command)
                            {
                                // This is just the echo. Ignore.
                                waitingOperation.EchoReceived = true;
                                return;
                            }
                        }
                    }
                }

                switch (c)
                {
                case '~':
                    OnDebuggeeOutput(noprefix);             // Console stream
                    break;

                case '^':
                    OnResult(noprefix, token);
                    break;

                case '*':
                    OnOutOfBand(noprefix);
                    break;

                case '&':
                    OnLogStreamOutput(noprefix);
                    break;

                case '=':
                    OnNotificationOutput(noprefix);
                    break;

                default:
                    OnDebuggeeOutput(line + '\n');
                    break;
                }
            }
        }