Пример #1
0
        private void RefreshLog(bool scrollToBottom, bool forceUpdate)
        {
            if (_refreshRunning)
            {
                return;
            }

            _refreshRunning = true;
            _interopOptions = GetInteropOptions();
            Task.Run(() => {
                SetCoreOptions();

                //Update trace log in another thread for performance
                DebugState state = DebugApi.GetState();
                if (_previousMasterClock != state.MasterClock || forceUpdate)
                {
                    string newTrace      = DebugApi.GetExecutionTrace((UInt32)_lineCount);
                    _previousMasterClock = state.MasterClock;
                    _previousTrace       = newTrace;

                    int index            = 0;
                    string line          = null;
                    Func <bool> readLine = () => {
                        if (index < newTrace.Length)
                        {
                            int endOfLineIndex = newTrace.IndexOf('\n', index);
                            line  = newTrace.Substring(index, endOfLineIndex - index);
                            index = endOfLineIndex + 1;
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    };

                    List <int> lineFlags      = new List <int>(30000);
                    List <int> programCounter = new List <int>(30000);
                    List <string> byteCode    = new List <string>(30000);
                    List <string> lineContent = new List <string>(30000);
                    List <int> indent         = new List <int>(30000);

                    bool showByteCode = false;
                    while (readLine())
                    {
                        string[] parts = line.Split('\x1');
                        lineFlags.Add((int)parts[0][0]);
                        programCounter.Add(Int32.Parse(parts[1], System.Globalization.NumberStyles.HexNumber));
                        byteCode.Add(parts[2]);

                        string content = parts[3];
                        while (true)
                        {
                            string str = content.TrimStart();
                            if (str.StartsWith(parts[1]))
                            {
                                content = str.Substring(parts[1].Length);
                            }
                            else if (str.StartsWith(parts[2]))
                            {
                                content      = str.Substring(parts[2].Length);
                                showByteCode = true;
                            }
                            else if (str.StartsWith(parts[3].Replace("$", "")))
                            {
                                content      = str.Substring(8);
                                showByteCode = true;
                            }
                            else
                            {
                                break;
                            }
                        }
                        lineContent.Add(content.TrimStart());
                    }
                    this.BeginInvoke((Action)(() => {
                        txtTraceLog.ShowContentNotes = showByteCode;
                        txtTraceLog.ShowSingleContentLineNotes = showByteCode;

                        txtTraceLog.DataProvider = new TraceLoggerCodeDataProvider(lineContent, programCounter, byteCode, lineFlags);
                        txtTraceLog.StyleProvider = new TraceLoggerStyleProvider(lineFlags);

                        if (scrollToBottom)
                        {
                            txtTraceLog.ScrollToLineIndex(txtTraceLog.LineCount - 1);
                        }
                    }));
                }
                _refreshRunning = false;
            });
        }