Exemple #1
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;
                }
            }
        }
Exemple #2
0
 public ResultEventArgs(Results results)
 {
     Results = results;
 }
Exemple #3
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-group-exited,", StringComparison.Ordinal))
            {
                results = _miResults.ParseResultList(cmd.Substring("thread-group-exited,".Length));
                HandleThreadGroupExited(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
            {
                // append a newline if the message didn't come with one
                if (!cmd.EndsWith("\n", StringComparison.Ordinal))
                {
                    cmd += "\n";
                }
                OnDebuggeeOutput("=" + cmd);
            }
        }
Exemple #4
0
 public ResultEventArgs(Results results, uint id)
 {
     Results = results;
     Id      = id;
 }
Exemple #5
0
        public override async Task <IEnumerable <ulong> > SetExceptionBreakpoints(Guid exceptionCategory, /*OPTIONAL*/ IEnumerable <string> exceptionNames, ExceptionBreakpointState exceptionBreakpointState)
        {
            List <string> commandTokens = new List <string>();

            commandTokens.Add("-break-exception-insert");

            if (exceptionCategory == s_exceptionCategory_MDA)
            {
                commandTokens.Add("--mda");
            }
            else if (exceptionCategory != s_exceptionCategory_CLR)
            {
                throw new ArgumentOutOfRangeException("exceptionCategory");
            }

            if (exceptionBreakpointState.HasFlag(ExceptionBreakpointState.BreakThrown))
            {
                if (exceptionBreakpointState.HasFlag(ExceptionBreakpointState.BreakUserHandled))
                {
                    commandTokens.Add("throw+user-unhandled");
                }
                else
                {
                    commandTokens.Add("throw");
                }
            }
            else
            {
                if (exceptionBreakpointState.HasFlag(ExceptionBreakpointState.BreakUserHandled))
                {
                    commandTokens.Add("user-unhandled");
                }
                else
                {
                    commandTokens.Add("unhandled");
                }
            }

            if (exceptionNames == null)
            {
                commandTokens.Add("*");
            }
            else
            {
                commandTokens.AddRange(exceptionNames);
            }

            string command = string.Join(" ", commandTokens);

            Results results = await _debugger.CmdAsync(command, ResultClass.done);

            ResultValue bkpt;

            if (results.TryFind("bkpt", out bkpt))
            {
                if (bkpt is ValueListValue)
                {
                    MICore.ValueListValue list = bkpt as MICore.ValueListValue;
                    return(list.Content.Select((x) => x.FindAddr("number")));
                }
                else
                {
                    return(new ulong[1] {
                        bkpt.FindAddr("number")
                    });
                }
            }
            else
            {
                return(new ulong[0]);
            }
        }
Exemple #6
0
 /// <summary>
 /// Decode properties from an exception-received event.
 /// </summary>
 /// <param name="miExceptionResult">Results object for the exception-received event</param>
 /// <param name="exceptionCategory">AD7 Exception Category to return</param>
 /// <param name="state">Exception state</param>
 public virtual void DecodeExceptionReceivedProperties(Results miExceptionResult, out Guid?exceptionCategory, out ExceptionBreakpointState state)
 {
     exceptionCategory = null;
     state             = ExceptionBreakpointState.None;
 }
Exemple #7
0
        private async void OnStopped(Results results)
        {
            string reason = results.TryFindString("reason");

            if (reason.StartsWith("exited"))
            {
                string threadGroupId = results.TryFindString("id");
                if (!String.IsNullOrEmpty(threadGroupId))
                {
                    lock (_debuggeePids)
                    {
                        _debuggeePids.Remove(threadGroupId);
                    }
                }

                if (IsLocalGdbAttach())
                {
                    CmdExitAsync();
                }

                this.ProcessState = ProcessState.Exited;
                if (ProcessExitEvent != null)
                {
                    ProcessExitEvent(this, new ResultEventArgs(results));
                }
                return;
            }

            //if this is an exception reported from LLDB, it will not currently contain a frame object in the MI
            //if we don't have a frame, check if this is an excpetion and retrieve the frame
            if (!results.Contains("frame") &&
                string.Compare(reason, "exception-received", StringComparison.OrdinalIgnoreCase) == 0
                )
            {
                //get the info for the current frame
                Results frameResult = await MICommandFactory.StackInfoFrame();

                //add the frame to the stopping results
                results.Add("frame", frameResult.Find("frame"));
            }

            bool fIsAsyncBreak = MICommandFactory.IsAsyncBreakSignal(results);

            if (await DoInternalBreakActions(fIsAsyncBreak))
            {
                return;
            }

            this.ProcessState = ProcessState.Stopped;
            FlushBreakStateData();

            if (!results.Contains("frame"))
            {
                if (ModuleLoadEvent != null)
                {
                    ModuleLoadEvent(this, new ResultEventArgs(results));
                }
            }
            else if (BreakModeEvent != null)
            {
                if (fIsAsyncBreak)
                {
                    _requestingRealAsyncBreak = false;
                }
                BreakModeEvent(this, new ResultEventArgs(results));
            }
        }
Exemple #8
0
 public virtual bool IsAsyncBreakSignal(Results results)
 {
     return(results.TryFindString("reason") == "signal-received" && results.TryFindString("signal-name") == "SIGINT");
 }
Exemple #9
0
        public virtual async Task <Results> ThreadInfo()
        {
            Results threadsinfo = await _debugger.CmdAsync("-thread-info", ResultClass.None);

            return(threadsinfo);
        }
Exemple #10
0
 public ResultsTypeProxy(Results results)
 {
     this.Content = results.Content;
 }
Exemple #11
0
        public virtual async Task <string[]> GetTargetFeatures()
        {
            Results results = await _debugger.CmdAsync("-list-target-features", ResultClass.done);

            return(results.Find <ValueListValue>("features").AsStrings);
        }