Ejemplo n.º 1
0
        private void EditInMemoryTools(LocationInfo location)
        {
            if (location.Symbol != null)
            {
                AddressInfo?address = _symbolProvider.GetSymbolAddressInfo(location.Symbol);
                if (address.HasValue)
                {
                    DebugWindowManager.OpenMemoryViewer(address.Value);
                }
            }
            else if (location.Address >= 0)
            {
                AddressInfo relAddress = new AddressInfo()
                {
                    Address = location.Address,
                    Type    = _manager.RelativeMemoryType
                };

                DebugWindowManager.OpenMemoryViewer(relAddress);
            }
            else if (location.Label != null)
            {
                DebugWindowManager.OpenMemoryViewer(location.Label.GetAbsoluteAddress());
            }
        }
Ejemplo n.º 2
0
        public Dictionary <string, string> GetTooltipData(string word, int lineIndex)
        {
            if (_provider.GetCodeLineData(lineIndex).Flags.HasFlag(LineFlags.ShowAsData))
            {
                //Disable tooltips for .db statements
                return(null);
            }

            LocationInfo location = GetLocationInfo(word, lineIndex);

            if (location.Symbol != null)
            {
                AddressInfo?symbolAddress = _symbolProvider.GetSymbolAddressInfo(location.Symbol);

                if (symbolAddress != null && symbolAddress.Value.Address >= 0)
                {
                    int    relativeAddress = DebugApi.GetRelativeAddress(symbolAddress.Value, this.CpuType).Address;
                    byte   byteValue       = relativeAddress >= 0 ? DebugApi.GetMemoryValue(this.RelativeMemoryType, (UInt32)relativeAddress) : (byte)0;
                    UInt16 wordValue       = relativeAddress >= 0 ? (UInt16)(byteValue | (DebugApi.GetMemoryValue(this.RelativeMemoryType, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0;

                    var values = new Dictionary <string, string>()
                    {
                        { "Symbol", location.Symbol.Name + (location.ArrayIndex != null ? $"+{location.ArrayIndex.Value}" : "") }
                    };

                    if (relativeAddress >= 0)
                    {
                        values["CPU Address"] = "$" + relativeAddress.ToString("X4");
                    }
                    else
                    {
                        values["CPU Address"] = "<out of scope>";
                    }

                    if (symbolAddress.Value.Type == SnesMemoryType.PrgRom)
                    {
                        values["PRG Offset"] = "$" + (symbolAddress.Value.Address + (location.ArrayIndex ?? 0)).ToString("X4");
                    }

                    values["Value"] = (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a");
                    return(values);
                }
                else
                {
                    return(new Dictionary <string, string>()
                    {
                        { "Symbol", location.Symbol.Name },
                        { "Constant", location.Symbol.Address.HasValue ? ("$" + location.Symbol.Address.Value.ToString("X2")) : "<unknown>" }
                    });
                }
            }
            else if (location.Label != null)
            {
                AddressInfo absAddress = location.Label.GetAbsoluteAddress();
                int         relativeAddress;
                if (location.Address >= 0)
                {
                    relativeAddress = location.Address;
                    AddressInfo absIndexedAddress = DebugApi.GetAbsoluteAddress(new AddressInfo()
                    {
                        Address = location.Address, Type = RelativeMemoryType
                    });
                    if (absIndexedAddress.Address > absAddress.Address)
                    {
                        location.ArrayIndex = absIndexedAddress.Address - absAddress.Address;
                    }
                }
                else if (absAddress.Type.IsRelativeMemory() || absAddress.Type == SnesMemoryType.Register)
                {
                    relativeAddress = absAddress.Address;
                }
                else
                {
                    relativeAddress = location.Label.GetRelativeAddress(this.CpuType).Address + (location.ArrayIndex ?? 0);
                }

                byte   byteValue = relativeAddress >= 0 ? DebugApi.GetMemoryValue(this.RelativeMemoryType, (UInt32)relativeAddress) : (byte)0;
                UInt16 wordValue = relativeAddress >= 0 ? (UInt16)(byteValue | (DebugApi.GetMemoryValue(this.RelativeMemoryType, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0;

                var values = new Dictionary <string, string>()
                {
                    { "Label", location.Label.Label + (location.ArrayIndex != null ? $"+{location.ArrayIndex.Value}" : "") },
                    { "Address", (relativeAddress >= 0 ? "$" + relativeAddress.ToString("X4") : "n/a") },
                    { "Value", (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a") },
                };

                if (!string.IsNullOrWhiteSpace(location.Label.Comment))
                {
                    values["Comment"] = location.Label.Comment;
                }
                return(values);
            }
            else if (location.Address >= 0)
            {
                byte   byteValue = DebugApi.GetMemoryValue(this.RelativeMemoryType, (uint)location.Address);
                UInt16 wordValue = (UInt16)(byteValue | (DebugApi.GetMemoryValue(this.RelativeMemoryType, (uint)location.Address + 1) << 8));
                return(new Dictionary <string, string>()
                {
                    { "Address", "$" + location.Address.ToString("X4") },
                    { "Value", $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" }
                });
            }

            return(null);
        }
Ejemplo n.º 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;
            }
        }