private static void UpdateAssertBreakpoints() { List <Breakpoint> asserts = new List <Breakpoint>(); foreach (CodeLabel label in LabelManager.GetLabels()) { foreach (string commentLine in label.Comment.Split('\n')) { Match m = LabelManager.AssertRegex.Match(commentLine); if (m.Success) { asserts.Add(new Breakpoint() { BreakOnExec = true, MemoryType = label.AddressType.ToMemoryType(), Address = label.Address, Condition = "!(" + m.Groups[1].Value + ")" }); } } } BreakpointManager.Asserts = asserts; BreakpointManager.SetBreakpoints(); }
public static void SaveWorkspace() { if (_workspace != null) { lock (_lock) { if (_workspace != null) { _workspace.WatchValues = new List <string>(WatchManager.WatchEntries); _workspace.Labels = new List <CodeLabel>(LabelManager.GetLabels()); _workspace.Breakpoints = new List <Breakpoint>(BreakpointManager.Breakpoints); _workspace.Save(); } } } }
public static void Export(string path) { List <CodeLabel> labels = new List <CodeLabel>(LabelManager.GetLabels()); labels.Sort((CodeLabel a, CodeLabel b) => { int result = a.AddressType.CompareTo(b.AddressType); if (result == 0) { return(a.Address.CompareTo(b.Address)); } else { return(result); } }); StringBuilder sb = new StringBuilder(); foreach (CodeLabel label in labels) { sb.Append(label.ToString() + "\n"); } File.WriteAllText(path, sb.ToString(), Encoding.UTF8); }
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; HashSet <int> entryPoints = new HashSet <int>(InteropEmu.DebugGetFunctionEntryPoints()); byte[] cdlData = InteropEmu.DebugGetPrgCdlData(); List <SearchResultInfo> searchResults = new List <SearchResultInfo>(); if (!string.IsNullOrWhiteSpace(searchString)) { if (_symbolProvider != null) { if (_showFilesAndConstants) { foreach (Ld65DbgImporter.FileInfo file in _symbolProvider.Files.Values) { if (Contains(file.Name, searchStrings)) { searchResults.Add(new SearchResultInfo() { Caption = Path.GetFileName(file.Name), AbsoluteAddress = -1, MemoryType = AddressType.InternalRam, SearchResultType = SearchResultType.File, Filename = file.Name, FileLineNumber = 0, RelativeAddress = -1, CodeLabel = null }); } } } foreach (Ld65DbgImporter.SymbolInfo symbol in _symbolProvider.GetSymbols()) { if (Contains(symbol.Name, searchStrings)) { Ld65DbgImporter.ReferenceInfo def = _symbolProvider.GetSymbolDefinition(symbol); AddressTypeInfo addressInfo = _symbolProvider.GetSymbolAddressInfo(symbol); int value = 0; int relAddress = -1; bool isConstant = addressInfo == null; if (!_showFilesAndConstants && isConstant) { continue; } if (addressInfo != null) { value = InteropEmu.DebugGetMemoryValue(addressInfo.Type.ToMemoryType(), (uint)addressInfo.Address); relAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type); } else { //For constants, the address field contains the constant's value value = symbol.Address ?? 0; } SearchResultType resultType = SearchResultType.Data; if (addressInfo?.Type == AddressType.PrgRom && entryPoints.Contains(addressInfo.Address)) { resultType = SearchResultType.Function; } else if (addressInfo?.Type == AddressType.PrgRom && addressInfo.Address < cdlData.Length && (cdlData[addressInfo.Address] & (byte)CdlPrgFlags.JumpTarget) != 0) { resultType = SearchResultType.JumpTarget; } else if (isConstant) { resultType = SearchResultType.Constant; } searchResults.Add(new SearchResultInfo() { Caption = symbol.Name, AbsoluteAddress = addressInfo?.Address ?? -1, MemoryType = addressInfo?.Type ?? AddressType.InternalRam, SearchResultType = resultType, Value = value, Filename = def?.FileName ?? "", FileLineNumber = def?.LineNumber ?? 0, RelativeAddress = relAddress, CodeLabel = LabelManager.GetLabel(symbol.Name) }); } } } else { foreach (CodeLabel label in LabelManager.GetLabels()) { if (Contains(label.Label, searchStrings)) { SearchResultType resultType = SearchResultType.Data; if (label.AddressType == AddressType.PrgRom && entryPoints.Contains((int)label.Address)) { resultType = SearchResultType.Function; } else if (label.AddressType == AddressType.PrgRom && label.Address < cdlData.Length && (cdlData[label.Address] & (byte)CdlPrgFlags.JumpTarget) != 0) { resultType = SearchResultType.JumpTarget; } int relativeAddress = label.GetRelativeAddress(); searchResults.Add(new SearchResultInfo() { Caption = label.Label, AbsoluteAddress = (int)label.Address, Value = label.GetValue(), MemoryType = label.AddressType, SearchResultType = resultType, Filename = "", Disabled = !_allowOutOfScope && relativeAddress < 0, RelativeAddress = relativeAddress, 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; if (searchResults.Count == 0) { searchResults.Add(new SearchResultInfo() { Caption = "No results found.", AbsoluteAddress = -1 }); 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 = searchResults.Count; 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; } }
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; } }