Пример #1
0
        public void Prepare(long firstByteIndex, long lastByteIndex)
        {
            int visibleByteCount = (int)(lastByteIndex - firstByteIndex + 1);

            if (_highlightBreakpoints)
            {
                Breakpoint[] breakpoints = BreakpointManager.Breakpoints.ToArray();
                _breakpointTypes = new BreakpointTypeFlags[visibleByteCount];

                for (int i = 0; i < visibleByteCount; i++)
                {
                    int byteIndex = i + (int)firstByteIndex;
                    foreach (Breakpoint bp in breakpoints)
                    {
                        if (bp.Enabled && bp.Matches((uint)byteIndex, _memoryType))
                        {
                            _breakpointTypes[i] = bp.BreakOnExec ? BreakpointTypeFlags.Execute : (bp.BreakOnWrite ? BreakpointTypeFlags.Write : BreakpointTypeFlags.Read);
                            break;
                        }
                    }
                }
            }
            else
            {
                _breakpointTypes = null;
            }

            _readStamps  = DebugApi.GetMemoryAccessStamps((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Read);
            _writeStamps = DebugApi.GetMemoryAccessStamps((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Write);
            _execStamps  = DebugApi.GetMemoryAccessStamps((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.ExecOpCode);

            _readCounts  = DebugApi.GetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Read);
            _writeCounts = DebugApi.GetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.Write);
            _execCounts  = DebugApi.GetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType, MemoryOperationType.ExecOpCode);

            _cdlData = null;
            if (_highlightDataBytes || _highlightCodeBytes)
            {
                switch (_memoryType)
                {
                case SnesMemoryType.CpuMemory:
                case SnesMemoryType.PrgRom:
                    _cdlData = DebugApi.GetCdlData((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
                    break;
                }
            }

            //TODO LABELS

            /*_hasLabel = new bool[visibleByteCount];
             * if(_highlightLabelledBytes) {
             *      if(_memoryType == DebugMemoryType.CpuMemory) {
             *              for(long i = 0; i < _hasLabel.Length; i++) {
             *                      _hasLabel[i] = (
             *                              !string.IsNullOrWhiteSpace(LabelManager.GetLabel((UInt16)(i + firstByteIndex))?.Label) ||
             *                              !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(i + firstByteIndex), AddressType.Register)?.Label)
             *                      );
             *              }
             *      } else if(_memoryType == DebugMemoryType.PrgRom || _memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam) {
             *              for(long i = 0; i < _hasLabel.Length; i++) {
             *                      _hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(firstByteIndex + i), _memoryType.ToAddressType())?.Label);
             *              }
             *      }
             * }*/

            _state = DebugApi.GetState();
        }
Пример #2
0
        public void Prepare(long firstByteIndex, long lastByteIndex)
        {
            int visibleByteCount = (int)(lastByteIndex - firstByteIndex + 1);

            if (_highlightBreakpoints)
            {
                Breakpoint[] breakpoints = BreakpointManager.Breakpoints.ToArray();
                _breakpointTypes = new BreakpointTypeFlags[visibleByteCount];

                for (int i = 0; i < visibleByteCount; i++)
                {
                    int byteIndex = i + (int)firstByteIndex;
                    foreach (Breakpoint bp in breakpoints)
                    {
                        if (bp.Enabled && bp.Matches((uint)byteIndex, _memoryType, null))
                        {
                            _breakpointTypes[i] = bp.BreakOnExec ? BreakpointTypeFlags.Execute : (bp.BreakOnWrite ? BreakpointTypeFlags.Write : BreakpointTypeFlags.Read);
                            break;
                        }
                    }
                }
            }
            else
            {
                _breakpointTypes = null;
            }

            _counters = DebugApi.GetMemoryAccessCounts((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);

            _cdlData = null;
            if (_highlightDataBytes || _highlightCodeBytes)
            {
                switch (_memoryType)
                {
                case SnesMemoryType.CpuMemory:
                case SnesMemoryType.Sa1Memory:
                case SnesMemoryType.Cx4Memory:
                case SnesMemoryType.GsuMemory:
                case SnesMemoryType.GameboyMemory:
                case SnesMemoryType.PrgRom:
                case SnesMemoryType.GbPrgRom:
                    _cdlData = DebugApi.GetCdlData((UInt32)firstByteIndex, (UInt32)visibleByteCount, _memoryType);
                    break;
                }
            }

            _hasLabel = new bool[visibleByteCount];
            if (_highlightLabelledBytes)
            {
                if (_memoryType <= SnesMemoryType.SpcMemory)
                {
                    AddressInfo addr = new AddressInfo();
                    addr.Type = _memoryType;
                    for (long i = 0; i < _hasLabel.Length; i++)
                    {
                        addr.Address = (int)(firstByteIndex + i);
                        _hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel(addr)?.Label);
                    }
                }
                else if (_memoryType == SnesMemoryType.PrgRom || _memoryType == SnesMemoryType.WorkRam || _memoryType == SnesMemoryType.SaveRam)
                {
                    for (long i = 0; i < _hasLabel.Length; i++)
                    {
                        _hasLabel[i] = !string.IsNullOrWhiteSpace(LabelManager.GetLabel((uint)(firstByteIndex + i), _memoryType)?.Label);
                    }
                }
            }

            _state = DebugApi.GetState();
        }
Пример #3
0
        private void UpdateResults()
        {
            string searchString = txtSearch.Text.Trim();

            List <string> searchStrings = new List <string>();

            searchStrings.Add(searchString.ToLower());
            searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            for (int i = 0; i < searchString.Length; i++)
            {
                char ch = searchString[i];
                if (ch >= 'A' && ch <= 'Z')
                {
                    searchString = searchString.Remove(i, 1).Insert(i, " " + (char)(ch + 'a' - 'A'));
                }
            }
            searchStrings.AddRange(searchString.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
            searchStrings = searchStrings.Distinct().ToList();

            _resultCount = 0;

            int size = DebugApi.GetMemorySize(SnesMemoryType.PrgRom);

            byte[] cdlData = DebugApi.GetCdlData(0, (uint)size, SnesMemoryType.PrgRom);

            List <SearchResultInfo> searchResults = new List <SearchResultInfo>();
            bool isEmptySearch = string.IsNullOrWhiteSpace(searchString);

            if (!isEmptySearch)
            {
                if (_symbolProvider != null)
                {
                    if (_showFilesAndConstants)
                    {
                        foreach (SourceFileInfo file in _symbolProvider.SourceFiles)
                        {
                            if (Contains(file.Name, searchStrings))
                            {
                                searchResults.Add(new SearchResultInfo()
                                {
                                    Caption          = Path.GetFileName(file.Name),
                                    AbsoluteAddress  = null,
                                    SearchResultType = SearchResultType.File,
                                    File             = file,
                                    SourceLocation   = null,
                                    RelativeAddress  = null,
                                    CodeLabel        = null
                                });
                            }
                        }
                    }

                    foreach (SourceSymbol symbol in _symbolProvider.GetSymbols())
                    {
                        if (Contains(symbol.Name, searchStrings))
                        {
                            SourceCodeLocation def         = _symbolProvider.GetSymbolDefinition(symbol);
                            AddressInfo?       addressInfo = _symbolProvider.GetSymbolAddressInfo(symbol);
                            int         value      = 0;
                            AddressInfo?relAddress = null;
                            bool        isConstant = addressInfo == null;
                            if (!_showFilesAndConstants && isConstant)
                            {
                                continue;
                            }

                            if (addressInfo != null)
                            {
                                value      = DebugApi.GetMemoryValue(addressInfo.Value.Type, (uint)addressInfo.Value.Address);
                                relAddress = DebugApi.GetRelativeAddress(addressInfo.Value, CpuType.Cpu);                                 //TODO
                            }
                            else
                            {
                                //For constants, the address field contains the constant's value
                                value = symbol.Address ?? 0;
                            }

                            SearchResultType resultType = SearchResultType.Data;
                            if (isConstant)
                            {
                                resultType = SearchResultType.Constant;
                            }
                            else if (addressInfo?.Type == SnesMemoryType.PrgRom && addressInfo.Value.Address < cdlData.Length)
                            {
                                if ((cdlData[addressInfo.Value.Address] & (byte)CdlFlags.JumpTarget) != 0)
                                {
                                    resultType = SearchResultType.JumpTarget;
                                }
                                else if ((cdlData[addressInfo.Value.Address] & (byte)CdlFlags.SubEntryPoint) != 0)
                                {
                                    resultType = SearchResultType.Function;
                                }
                            }

                            searchResults.Add(new SearchResultInfo()
                            {
                                Caption          = symbol.Name,
                                AbsoluteAddress  = addressInfo,
                                Length           = _symbolProvider.GetSymbolSize(symbol),
                                SearchResultType = resultType,
                                Value            = value,
                                File             = def?.File,
                                SourceLocation   = def,
                                RelativeAddress  = relAddress,
                                CodeLabel        = LabelManager.GetLabel(symbol.Name)
                            });
                        }
                    }
                }
                else
                {
                    foreach (CodeLabel label in LabelManager.GetLabels(CpuType.Cpu))                      //TODO
                    {
                        if (Contains(label.Label, searchStrings))
                        {
                            SearchResultType resultType  = SearchResultType.Data;
                            AddressInfo      addressInfo = label.GetAbsoluteAddress();
                            if (addressInfo.Type == SnesMemoryType.PrgRom && addressInfo.Address < cdlData.Length)
                            {
                                if ((cdlData[addressInfo.Address] & (byte)CdlFlags.JumpTarget) != 0)
                                {
                                    resultType = SearchResultType.JumpTarget;
                                }
                                else if ((cdlData[addressInfo.Address] & (byte)CdlFlags.SubEntryPoint) != 0)
                                {
                                    resultType = SearchResultType.Function;
                                }
                            }

                            AddressInfo relAddress = label.GetRelativeAddress(CpuType.Cpu);                             //TODO
                            searchResults.Add(new SearchResultInfo()
                            {
                                Caption          = label.Label,
                                AbsoluteAddress  = label.GetAbsoluteAddress(),
                                Length           = (int)label.Length,
                                Value            = label.GetValue(),
                                SearchResultType = resultType,
                                File             = null,
                                Disabled         = !_allowOutOfScope && relAddress.Address < 0,
                                RelativeAddress  = relAddress,
                                CodeLabel        = label
                            });
                        }
                    }
                }
            }

            searchResults.Sort((SearchResultInfo a, SearchResultInfo b) => {
                int comparison = a.Disabled.CompareTo(b.Disabled);

                if (comparison == 0)
                {
                    bool aStartsWithSearch = a.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase);
                    bool bStartsWithSearch = b.Caption.StartsWith(searchString, StringComparison.InvariantCultureIgnoreCase);

                    comparison = bStartsWithSearch.CompareTo(aStartsWithSearch);
                    if (comparison == 0)
                    {
                        comparison = a.Caption.CompareTo(b.Caption);
                    }
                }
                return(comparison);
            });

            _resultCount   = Math.Min(searchResults.Count, MaxResultCount);
            SelectedResult = 0;

            lblResultCount.Visible = !isEmptySearch;
            lblResultCount.Text    = searchResults.Count.ToString() + (searchResults.Count == 1 ? " result" : " results");
            if (searchResults.Count > MaxResultCount)
            {
                lblResultCount.Text += " (" + MaxResultCount.ToString() + " shown)";
            }

            if (searchResults.Count == 0 && !isEmptySearch)
            {
                _resultCount++;
                searchResults.Add(new SearchResultInfo()
                {
                    Caption = "No results found."
                });
                pnlResults.BackColor = SystemColors.ControlLight;
            }
            else
            {
                pnlResults.BackColor = SystemColors.ControlDarkDark;
            }

            if (Program.IsMono)
            {
                pnlResults.Visible = false;
            }
            else
            {
                //Suspend layout causes a crash on Mono
                tlpResults.SuspendLayout();
            }

            for (int i = 0; i < _resultCount; i++)
            {
                _results[i].Initialize(searchResults[i]);
                _results[i].Tag     = searchResults[i];
                _results[i].Visible = true;
            }

            for (int i = _resultCount; i < MaxResultCount; i++)
            {
                _results[i].Visible = false;
            }

            pnlResults.VerticalScroll.Value = 0;
            tlpResults.Height = (_results[0].Height + 1) * _resultCount;

            pnlResults.ResumeLayout();
            if (Program.IsMono)
            {
                pnlResults.Visible = true;
                tlpResults.Width   = pnlResults.ClientSize.Width - 17;
            }
            else
            {
                tlpResults.ResumeLayout();
                tlpResults.Width = pnlResults.ClientSize.Width - 1;
            }
        }