public ScrollbarColorProvider(ctrlSourceViewer viewer) { _viewer = viewer; DebugInfo info = ConfigManager.Config.DebugInfo; int len = viewer.ctrlCodeViewer.LineCount; int[] relativeAddresses = new int[len]; AddressTypeInfo[] addressInfo = new AddressTypeInfo[len]; for (int i = 0; i < len; i++) { addressInfo[i] = _viewer.GetAddressInfo(i); if (addressInfo[i].Address >= 0) { relativeAddresses[i] = InteropEmu.DebugGetRelativeAddress((uint)addressInfo[i].Address, AddressType.PrgRom); } else { relativeAddresses[i] = -1; } } foreach (Breakpoint breakpoint in BreakpointManager.Breakpoints) { for (int i = 0; i < len; i++) { if (breakpoint.Matches(relativeAddresses[i], addressInfo[i])) { Color bpColor = breakpoint.BreakOnExec ? info.CodeExecBreakpointColor : (breakpoint.BreakOnWrite ? info.CodeWriteBreakpointColor : info.CodeReadBreakpointColor); _breakpointColors[i] = bpColor; } } } }
public void ScrollToAddress(AddressTypeInfo addressInfo, bool scrollToTop = false) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type); if (relativeAddress >= 0) { this.ctrlCodeViewer.ScrollToLineNumber(relativeAddress, eHistoryType.Always, scrollToTop); } }
private void mnuViewInCpuMemory_Click(object sender, EventArgs e) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((UInt32)SelectionStartAddress, _memoryType.ToAddressType()); if (relativeAddress >= 0) { MemoryViewer.ShowAddress(relativeAddress, DebugMemoryType.CpuMemory); } }
private void ctrlProfiler_OnFunctionSelected(object sender, EventArgs e) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((UInt32)sender, AddressType.PrgRom); if (relativeAddress >= 0) { BringToFront(); _lastCodeWindow.ScrollToLineNumber(relativeAddress); } }
private Breakpoint GetCurrentLineBreakpoint() { AddressTypeInfo addressInfo = GetAddressInfo(ctrlCodeViewer.SelectedLine); if (addressInfo.Address >= 0) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type); return(BreakpointManager.GetMatchingBreakpoint(relativeAddress, addressInfo)); } return(null); }
private void lstFunctions_DoubleClick(object sender, EventArgs e) { if (lstFunctions.SelectedIndices.Count > 0) { AddressTypeInfo addr = _functions[lstFunctions.SelectedIndices[0]].Address; int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)addr.Address, addr.Type); if (relativeAddress >= 0) { OnFunctionSelected?.Invoke(relativeAddress, EventArgs.Empty); } } }
public void UpdateLabelList() { List <CodeLabel> labels = LabelManager.GetLabels(); List <ListViewItem> items = new List <ListViewItem>(labels.Count); foreach (CodeLabel label in labels) { if (label.Label.Length > 0) { ListViewItem item = new ListViewItem(label.Label); Int32 relativeAddress = InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType); if (relativeAddress >= 0) { item.SubItems.Add("$" + relativeAddress.ToString("X4")); } else { item.SubItems.Add("[n/a]"); item.ForeColor = Color.Gray; item.Font = new Font(item.Font, FontStyle.Italic); } string absAddress = string.Empty; switch (label.AddressType) { case AddressType.InternalRam: absAddress += "RAM: "; break; case AddressType.PrgRom: absAddress += "PRG: "; break; case AddressType.Register: absAddress += "REG: "; break; case AddressType.SaveRam: absAddress += "SRAM: "; break; case AddressType.WorkRam: absAddress += "WRAM: "; break; } absAddress += "$" + label.Address.ToString("X4"); item.SubItems.Add(absAddress); item.SubItems[1].Tag = label; item.Tag = relativeAddress; items.Add(item); } } lstLabels.BeginUpdate(); lstLabels.Items.Clear(); lstLabels.Items.AddRange(items.ToArray()); lstLabels.Sort(); lstLabels.EndUpdate(); _listItems = items; }
public static void ToggleBreakpoint(AddressTypeInfo info, bool toggleEnabled) { if (info.Address >= 0) { Breakpoint breakpoint = BreakpointManager.GetMatchingBreakpoint(InteropEmu.DebugGetRelativeAddress((uint)info.Address, info.Type), info); if (breakpoint != null) { if (toggleEnabled) { breakpoint.SetEnabled(!breakpoint.Enabled); } else { BreakpointManager.RemoveBreakpoint(breakpoint); } } else { if (info.Type == AddressType.InternalRam) { breakpoint = new Breakpoint() { MemoryType = DebugMemoryType.CpuMemory, BreakOnExec = true, BreakOnRead = true, BreakOnWrite = true, Address = (UInt32)info.Address, Enabled = true }; } else { breakpoint = new Breakpoint() { Enabled = true, BreakOnExec = true, Address = (UInt32)info.Address }; if (info.Type != AddressType.PrgRom) { breakpoint.BreakOnRead = true; breakpoint.BreakOnWrite = true; } breakpoint.MemoryType = info.Type.ToMemoryType(); } BreakpointManager.AddBreakpoint(breakpoint); } } }
public int GetRelativeAddress() { if (this.IsCpuBreakpoint) { if (this.IsAbsoluteAddress) { return(InteropEmu.DebugGetRelativeAddress((uint)this.Address, GUI.AddressType.PrgRom)); } else { return((int)this.Address); } } return(0); }
private int GetRelativeAddressEnd() { if (this.AddressType == BreakpointAddressType.AddressRange && this.IsAbsoluteAddress) { if (IsCpuBreakpoint) { return(InteropEmu.DebugGetRelativeAddress(this.EndAddress, this.MemoryType.ToAddressType())); } else if (_memoryType == DebugMemoryType.ChrRam || _memoryType == DebugMemoryType.ChrRom) { return(InteropEmu.DebugGetRelativeChrAddress(this.EndAddress)); } } return(-1); }
public int GetRelativeAddress() { UInt32 address = AddressType == BreakpointAddressType.SingleAddress ? this.Address : this.StartAddress; if (this.IsAbsoluteAddress) { if (IsCpuBreakpoint) { return(InteropEmu.DebugGetRelativeAddress(address, this.MemoryType.ToAddressType())); } else if (_memoryType == DebugMemoryType.ChrRam || _memoryType == DebugMemoryType.ChrRom) { return(InteropEmu.DebugGetRelativeChrAddress(address)); } } return(-1); }
private void mnuViewInDisassembly_Click(object sender, EventArgs e) { frmDebugger debugger = DebugWindowManager.GetDebugger(); if (debugger != null) { if (_memoryType == DebugMemoryType.CpuMemory) { debugger.ScrollToAddress(SelectionStartAddress); } else if (_memoryType == DebugMemoryType.PrgRom || _memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((UInt32)SelectionStartAddress, _memoryType.ToAddressType()); debugger.ScrollToAddress(relativeAddress); } } }
public void UpdateContextMenuItemVisibility(ToolStripItemCollection items) { items[nameof(mnuUndoPrgChrEdit)].Enabled = InteropEmu.DebugHasUndoHistory(); items[nameof(mnuShowNextStatement)].Enabled = Viewer.ActiveAddress.HasValue; items[nameof(mnuSetNextStatement)].Enabled = Viewer.ActiveAddress.HasValue; items[nameof(mnuEditSelectedCode)].Enabled = items[nameof(mnuEditSubroutine)].Enabled = InteropEmu.DebugIsExecutionStopped() && Viewer.CodeViewer.CurrentLine >= 0; bool hasSymbolProvider = Viewer.SymbolProvider != null; items[nameof(mnuShowSourceAsComments)].Visible = hasSymbolProvider; items[nameof(mnuSwitchView)].Visible = hasSymbolProvider; items[nameof(sepSwitchView)].Visible = hasSymbolProvider; if (IsSourceView) { items[nameof(mnuMarkSelectionAs)].Visible = false; items[nameof(mnuEditSubroutine)].Visible = false; items[nameof(mnuEditSelectedCode)].Visible = false; items[nameof(mnuNavigateForward)].Visible = false; items[nameof(mnuNavigateBackward)].Visible = false; items[nameof(mnuEditLabel)].Visible = false; items[nameof(sepNavigation)].Visible = false; items[nameof(mnuShowSourceAsComments)].Visible = false; items[nameof(sepMarkSelectionAs)].Visible = false; } else { items[nameof(mnuEditSourceFile)].Visible = false; } AddressTypeInfo addressInfo = Viewer.GetAddressInfo(Viewer.CodeViewer.SelectedLine); if (addressInfo.Address >= 0) { int relAddress = InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type); items[nameof(mnuPerfTracker)].Text = "Performance Tracker ($" + relAddress.ToString("X4") + ")"; items[nameof(mnuPerfTracker)].Enabled = true; } else { items[nameof(mnuPerfTracker)].Text = "Performance Tracker"; items[nameof(mnuPerfTracker)].Enabled = false; } }
private void mnuViewInCpuMemory_Click(object sender, EventArgs e) { if (_memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam || _memoryType == DebugMemoryType.PrgRom) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((UInt32)SelectionStartAddress, _memoryType.ToAddressType()); if (relativeAddress >= 0) { MemoryViewer.ShowAddress(relativeAddress, DebugMemoryType.CpuMemory); } } else { int relativeAddress = InteropEmu.DebugGetRelativePpuAddress((UInt32)SelectionStartAddress, _memoryType.ToPpuAddressType()); if (relativeAddress >= 0) { MemoryViewer.ShowAddress(relativeAddress, DebugMemoryType.PpuMemory); } } }
private void DisplaySymbolTooltip(Ld65DbgImporter.SymbolInfo symbol, int?arrayIndex = null) { AddressTypeInfo addressInfo = SymbolProvider.GetSymbolAddressInfo(symbol); if (addressInfo != null && addressInfo.Address >= 0) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)(addressInfo.Address + (arrayIndex ?? 0)), addressInfo.Type); byte byteValue = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0; UInt16 wordValue = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0; var values = new Dictionary <string, string>() { { "Symbol", symbol.Name + (arrayIndex != null ? $"+{arrayIndex.Value}" : "") } }; if (relativeAddress >= 0) { values["CPU Address"] = "$" + relativeAddress.ToString("X4"); } else { values["CPU Address"] = "<out of scope>"; } if (addressInfo.Type == AddressType.PrgRom) { values["PRG Offset"] = "$" + (addressInfo.Address + (arrayIndex ?? 0)).ToString("X4"); } values["Value"] = (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a"); ShowTooltip(symbol.Name, values, -1, addressInfo); } else { var values = new Dictionary <string, string>() { { "Symbol", symbol.Name }, { "Constant", symbol.Address.HasValue ? ("$" + symbol.Address.Value.ToString("X2")) : "<unknown>" } }; ShowTooltip(symbol.Name, values, -1, addressInfo); } }
private void DisplayLabelTooltip(string word, CodeLabel label) { Int32 relativeAddress = InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType); byte byteValue = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0; UInt16 wordValue = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0; var values = new Dictionary <string, string>() { { "Label", label.Label }, { "Address", "$" + InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType).ToString("X4") }, { "Value", (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a") }, }; if (!string.IsNullOrWhiteSpace(label.Comment)) { values["Comment"] = label.Comment; } ShowTooltip(word, values); }
public void UpdateLabelListAddresses() { bool needUpdate = false; Font italicFont = null; Font regularFont = null; foreach (ListViewItem item in _listItems) { CodeLabel label = (CodeLabel)item.SubItems[1].Tag; Int32 relativeAddress = InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType); if (relativeAddress != (Int32)item.Tag) { needUpdate = true; if (relativeAddress >= 0) { item.SubItems[1].Text = "$" + relativeAddress.ToString("X4"); item.ForeColor = ThemeHelper.Theme.LabelForeColor; if (regularFont == null) { regularFont = new Font(item.Font, FontStyle.Regular); } item.Font = regularFont; } else { item.SubItems[1].Text = "[n/a]"; item.ForeColor = ThemeHelper.Theme.LabelDisabledForeColor; if (italicFont == null) { italicFont = new Font(item.Font, FontStyle.Italic); } item.Font = italicFont; } item.Tag = relativeAddress; } } if (needUpdate) { SortItems(); } }
public int GetRelativeAddress() { UInt32 address = AddressType == BreakpointAddressType.SingleAddress ? this.Address : this.StartAddress; if (this.IsAbsoluteAddress) { if (IsCpuBreakpoint) { return(InteropEmu.DebugGetRelativeAddress(address, GUI.AddressType.PrgRom)); } else { return(InteropEmu.DebugGetRelativeChrAddress(address)); } } else { return((int)this.Address); } }
private void DisplayLabelTooltip(string word, CodeLabel label, int?arrayIndex = null) { int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)(label.Address + (arrayIndex ?? 0)), label.AddressType); byte byteValue = relativeAddress >= 0 ? InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress) : (byte)0; UInt16 wordValue = relativeAddress >= 0 ? (UInt16)(byteValue | (InteropEmu.DebugGetMemoryValue(DebugMemoryType.CpuMemory, (UInt32)relativeAddress + 1) << 8)) : (UInt16)0; var values = new Dictionary <string, string>() { { "Label", label.Label + (arrayIndex != null ? $"+{arrayIndex.Value}" : "") }, { "Address", "$" + relativeAddress.ToString("X4") }, { "Value", (relativeAddress >= 0 ? $"${byteValue.ToString("X2")} (byte){Environment.NewLine}${wordValue.ToString("X4")} (word)" : "n/a") }, }; if (!string.IsNullOrWhiteSpace(label.Comment)) { values["Comment"] = label.Comment; } ShowTooltip(word, values, -1, new AddressTypeInfo() { Address = (int)label.Address, Type = label.AddressType }); }
public void UpdateLabelListAddresses() { bool updating = false; foreach (ListViewItem item in _listItems) { CodeLabel label = (CodeLabel)item.SubItems[1].Tag; Int32 relativeAddress = InteropEmu.DebugGetRelativeAddress(label.Address, label.AddressType); if (relativeAddress != (Int32)item.Tag) { if (!updating) { lstLabels.BeginUpdate(); updating = true; } if (relativeAddress >= 0) { item.SubItems[0].Text = "$" + relativeAddress.ToString("X4"); item.ForeColor = Color.Black; item.Font = new Font(item.Font, FontStyle.Regular); } else { item.SubItems[0].Text = "[n/a]"; item.ForeColor = Color.Gray; item.Font = new Font(item.Font, FontStyle.Italic); } item.Tag = relativeAddress; } } if (updating) { lstLabels.Sort(); lstLabels.EndUpdate(); } }
private void SelectAndClose() { if (_resultCount > 0) { SearchResultInfo searchResult = _results[_selectedResult].Tag as SearchResultInfo; if (!searchResult.Disabled) { AddressTypeInfo addressInfo = new AddressTypeInfo() { Address = searchResult.AbsoluteAddress, Type = searchResult.MemoryType }; Destination = new GoToDestination() { AddressInfo = addressInfo, CpuAddress = addressInfo.Address >= 0 ? InteropEmu.DebugGetRelativeAddress((UInt32)addressInfo.Address, addressInfo.Type) : -1, Label = searchResult.CodeLabel, File = searchResult.Filename, Line = searchResult.FileLineNumber }; DialogResult = DialogResult.OK; Close(); } } }
private bool UpdateContextMenu(Point mouseLocation) { UpdateContextMenuItemVisibility(true); string word = GetWordUnderLocation(mouseLocation); if (word.StartsWith("$") || LabelManager.GetLabel(word) != null) { //Cursor is on a numeric value or label _lastWord = word; if (word.StartsWith("$")) { _lastClickedAddress = Int32.Parse(word.Substring(1), System.Globalization.NumberStyles.AllowHexSpecifier); _newWatchValue = "[$" + _lastClickedAddress.ToString("X") + "]"; } else { _lastClickedAddress = (Int32)InteropEmu.DebugGetRelativeAddress(LabelManager.GetLabel(word).Address, LabelManager.GetLabel(word).AddressType); _newWatchValue = "[" + word + "]"; } mnuGoToLocation.Enabled = true; mnuGoToLocation.Text = $"Go to Location ({word})"; mnuAddToWatch.Enabled = true; mnuAddToWatch.Text = $"Add to Watch ({word})"; mnuFindOccurrences.Enabled = true; mnuFindOccurrences.Text = $"Find Occurrences ({word})"; mnuEditLabel.Enabled = true; mnuEditLabel.Text = $"Edit Label ({word})"; return(true); } else { mnuGoToLocation.Enabled = false; mnuGoToLocation.Text = "Go to Location"; mnuAddToWatch.Enabled = false; mnuAddToWatch.Text = "Add to Watch"; mnuFindOccurrences.Enabled = false; mnuFindOccurrences.Text = "Find Occurrences"; mnuEditLabel.Enabled = false; mnuEditLabel.Text = "Edit Label"; _lastClickedAddress = ctrlCodeViewer.GetLineNumberAtPosition(mouseLocation.Y); if (mouseLocation.X < this.ctrlCodeViewer.CodeMargin && _lastClickedAddress >= 0) { //Cursor is in the margin, over an address label string address = $"${_lastClickedAddress.ToString("X4")}"; _newWatchValue = $"[{address}]"; _lastWord = address; mnuAddToWatch.Enabled = true; mnuAddToWatch.Text = $"Add to Watch ({address})"; mnuFindOccurrences.Enabled = true; mnuFindOccurrences.Text = $"Find Occurrences ({address})"; mnuEditLabel.Enabled = true; mnuEditLabel.Text = $"Edit Label ({address})"; return(true); } return(false); } }
private void UpdateCode() { if (_symbolProvider == null || CurrentFile == null) { return; } List <int> indents = new List <int>(); List <string> addressing = new List <string>(); List <string> comments = new List <string>(); List <int> lineNumbers = new List <int>(); List <string> lineNotes = new List <string>(); _lineNumberNotes = new List <string>(); List <string> codeLines = new List <string>(); bool isC = CurrentFile.Name.EndsWith(".h") || CurrentFile.Name.EndsWith(".c"); int index = 0; foreach (string line in CurrentFile.Data) { string l = line.Replace("\t", " "); addressing.Add(""); int prgAddress = _symbolProvider.GetPrgAddress(CurrentFile.ID, index); int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)prgAddress, AddressType.PrgRom); lineNumbers.Add(relativeAddress); lineNotes.Add(""); _lineNumberNotes.Add(prgAddress >= 0 ? prgAddress.ToString("X4") : ""); string trimmed = l.TrimStart(); int margin = (l.Length - trimmed.Length) * 10; indents.Add(margin); int commentIndex; if (isC) { commentIndex = trimmed.IndexOf("//"); } else { commentIndex = trimmed.IndexOfAny(new char[] { ';', '.' }); } if (commentIndex >= 0) { comments.Add(trimmed.Substring(commentIndex)); codeLines.Add(trimmed.Substring(0, commentIndex)); } else { comments.Add(""); codeLines.Add(trimmed); } index++; } ctrlCodeViewer.CodeHighlightingEnabled = !isC; ctrlCodeViewer.LineIndentations = indents.ToArray(); ctrlCodeViewer.Addressing = addressing.ToArray(); ctrlCodeViewer.Comments = comments.ToArray(); ctrlCodeViewer.LineNumbers = lineNumbers.ToArray(); ctrlCodeViewer.TextLineNotes = lineNotes.ToArray(); ctrlCodeViewer.LineNumberNotes = _lineNumberNotes.ToArray(); ctrlCodeViewer.TextLines = codeLines.ToArray(); this.RefreshViewer(); }
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 bool UpdateContextMenu(Point mouseLocation) { _lastLocation = mouseLocation; UpdateContextMenuItemVisibility(true); mnuSwitchView.Text = SourceView ? "Switch to Disassembly View" : "Switch to Source View"; string word = Viewer.CodeViewer.GetWordUnderLocation(mouseLocation); Ld65DbgImporter.SymbolInfo symbol = null; CodeLabel codeLabel = null; if (!word.StartsWith("$")) { codeLabel = LabelManager.GetLabel(word); if (Viewer.SymbolProvider != null) { int rangeStart, rangeEnd; if (Viewer.CodeViewer.GetNoteRangeAtLocation(mouseLocation.Y, out rangeStart, out rangeEnd)) { symbol = Viewer.SymbolProvider.GetSymbol(word, rangeStart, rangeEnd); if (symbol?.SegmentID == null) { symbol = null; } } } } if (word.StartsWith("$") || codeLabel != null || symbol != null) { //Cursor is on a numeric value or label _lastWord = word; if (word.StartsWith("$")) { //CPU Address _lastClickedAddress = Int32.Parse(word.Substring(1), NumberStyles.AllowHexSpecifier); _newWatchValue = "[$" + _lastClickedAddress.ToString("X") + "]"; } else if (symbol != null) { //Symbol AddressTypeInfo addressInfo = (AddressTypeInfo)Viewer.SymbolProvider.GetSymbolAddressInfo(symbol); _lastClickedAddress = (Int32)InteropEmu.DebugGetRelativeAddress((uint)addressInfo.Address, addressInfo.Type); bool matchingLabelExists = codeLabel != null && codeLabel.Label == symbol.Name; _newWatchValue = matchingLabelExists ? $"[{word}]" : $"[${_lastClickedAddress.ToString("X2")}]"; } else if (codeLabel != null) { //Label _lastClickedAddress = (Int32)InteropEmu.DebugGetRelativeAddress(codeLabel.Address, codeLabel.AddressType); _newWatchValue = "[" + word + "]"; } mnuGoToLocation.Enabled = true; mnuGoToLocation.Text = $"Go to Location ({word})"; mnuShowInSplitView.Enabled = true; mnuShowInSplitView.Text = $"Show in Split View ({word})"; mnuAddToWatch.Enabled = true; mnuAddToWatch.Text = $"Add to Watch ({word})"; mnuFindOccurrences.Enabled = true; mnuFindOccurrences.Text = $"Find Occurrences ({word})"; mnuEditLabel.Enabled = true; mnuEditLabel.Text = $"Edit Label ({word})"; mnuEditInMemoryViewer.Enabled = true; mnuEditInMemoryViewer.Text = $"Edit in Memory Viewer ({word})"; return(true); } else { mnuGoToLocation.Enabled = false; mnuGoToLocation.Text = "Go to Location"; mnuShowInSplitView.Enabled = false; mnuShowInSplitView.Text = "Show in Split View"; mnuAddToWatch.Enabled = false; mnuAddToWatch.Text = "Add to Watch"; mnuFindOccurrences.Enabled = false; mnuFindOccurrences.Text = "Find Occurrences"; mnuEditLabel.Enabled = false; mnuEditLabel.Text = "Edit Label"; mnuEditInMemoryViewer.Enabled = false; mnuEditInMemoryViewer.Text = $"Edit in Memory Viewer"; if (mouseLocation.X < Viewer.CodeViewer.CodeMargin) { _lastClickedAddress = Viewer.CodeViewer.GetLineNumberAtPosition(mouseLocation.Y); } else { _lastClickedAddress = Viewer.CodeViewer.LastSelectedLine; } if (_lastClickedAddress >= 0) { //Cursor is in the margin, over an address label string address = $"${_lastClickedAddress.ToString("X4")}"; _newWatchValue = $"[{address}]"; _lastWord = address; mnuShowInSplitView.Enabled = true; mnuShowInSplitView.Text = $"Show in Split View ({address})"; mnuAddToWatch.Enabled = true; mnuAddToWatch.Text = $"Add to Watch ({address})"; mnuFindOccurrences.Enabled = true; mnuFindOccurrences.Text = $"Find Occurrences ({address})"; mnuEditLabel.Enabled = true; mnuEditLabel.Text = $"Edit Label ({address})"; mnuEditInMemoryViewer.Enabled = true; mnuEditInMemoryViewer.Text = $"Edit in Memory Viewer ({address})"; return(true); } return(false); } }
private GoToDestination GetDestination() { Ld65DbgImporter.ReferenceInfo definitionInfo = _lastClickedSymbol != null?Viewer.SymbolProvider?.GetSymbolDefinition(_lastClickedSymbol) : null; AddressTypeInfo addressInfo = _lastClickedSymbol != null?Viewer.SymbolProvider?.GetSymbolAddressInfo(_lastClickedSymbol) : null; return(new GoToDestination() { CpuAddress = _lastClickedAddress >= 0 ? _lastClickedAddress : (addressInfo != null ? InteropEmu.DebugGetRelativeAddress((UInt32)addressInfo.Address, addressInfo.Type) : -1), Label = _lastClickedLabel, AddressInfo = addressInfo, File = definitionInfo?.FileName, Line = definitionInfo?.LineNumber ?? 0 }); }
private void UpdateActionAvailability() { UInt32 startAddress = (UInt32)SelectionStartAddress; UInt32 endAddress = (UInt32)SelectionEndAddress; string address = "$" + startAddress.ToString("X4"); string addressRange; if (startAddress != endAddress) { addressRange = "$" + startAddress.ToString("X4") + "-$" + endAddress.ToString("X4"); } else { addressRange = address; } mnuEditLabel.Text = $"Edit Label ({address})"; mnuEditBreakpoint.Text = $"Edit Breakpoint ({addressRange})"; mnuAddToWatch.Text = $"Add to Watch ({addressRange})"; mnuViewInDisassembly.Text = $"View in disassembly ({address})"; bool viewInCpuMemoryVisible = (_memoryType == DebugMemoryType.PrgRom || _memoryType == DebugMemoryType.WorkRam || _memoryType == DebugMemoryType.SaveRam); bool viewInMemoryTypeVisible = _memoryType == DebugMemoryType.CpuMemory; mnuViewInCpuMemory.Visible = viewInCpuMemoryVisible; mnuViewInMemoryType.Visible = viewInMemoryTypeVisible; mnuViewInDisassembly.Visible = (viewInCpuMemoryVisible || viewInMemoryTypeVisible); sepViewActions.Visible = (viewInCpuMemoryVisible || viewInMemoryTypeVisible); if (viewInMemoryTypeVisible) { frmDebugger debugger = DebugWindowManager.GetDebugger(); AddressTypeInfo addressInfo = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType(startAddress, addressInfo); mnuViewInMemoryType.Text = $"View in " + ResourceHelper.GetEnumText(addressInfo.Type) + $" ({address})"; mnuViewInDisassembly.Enabled = debugger != null; bool viewInMemoryTypeEnabled = addressInfo.Address >= 0 && (addressInfo.Type == AddressType.PrgRom || addressInfo.Type == AddressType.WorkRam || addressInfo.Type == AddressType.SaveRam); mnuViewInMemoryType.Enabled = viewInMemoryTypeEnabled; mnuViewInMemoryType.Visible = viewInMemoryTypeEnabled; mnuViewInCpuMemory.Enabled = false; } else if (viewInCpuMemoryVisible) { frmDebugger debugger = DebugWindowManager.GetDebugger(); int relativeAddress = InteropEmu.DebugGetRelativeAddress(startAddress, _memoryType.ToAddressType()); mnuViewInCpuMemory.Text = $"View in CPU memory ({address})"; mnuViewInCpuMemory.Enabled = relativeAddress >= 0; mnuViewInDisassembly.Enabled = debugger != null && relativeAddress >= 0; mnuViewInMemoryType.Enabled = false; } else { mnuViewInMemoryType.Enabled = false; mnuViewInCpuMemory.Enabled = false; mnuViewInDisassembly.Enabled = false; } if (this._memoryType == DebugMemoryType.CpuMemory) { bool[] freezeState = InteropEmu.DebugGetFreezeState((UInt16)startAddress, (UInt16)(endAddress - startAddress + 1)); mnuFreeze.Enabled = !freezeState.All((frozen) => frozen); mnuUnfreeze.Enabled = freezeState.Any((frozen) => frozen); mnuFreeze.Text = $"Freeze ({addressRange})"; mnuUnfreeze.Text = $"Unfreeze ({addressRange})"; } else { mnuFreeze.Text = $"Freeze"; mnuUnfreeze.Text = $"Unfreeze"; mnuFreeze.Enabled = false; mnuUnfreeze.Enabled = false; } if (this._memoryType == DebugMemoryType.CpuMemory) { int absStart = InteropEmu.DebugGetAbsoluteAddress(startAddress); int absEnd = InteropEmu.DebugGetAbsoluteAddress(endAddress); if (absStart >= 0 && absEnd >= 0 && absStart <= absEnd) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } } else if (this._memoryType == DebugMemoryType.PrgRom) { mnuMarkSelectionAs.Text = "Mark selection as... (" + addressRange + ")"; mnuMarkSelectionAs.Enabled = true; } else { mnuMarkSelectionAs.Text = "Mark selection as..."; mnuMarkSelectionAs.Enabled = false; } bool disableEditLabel = false; if (this._memoryType == DebugMemoryType.CpuMemory) { AddressTypeInfo info = new AddressTypeInfo(); InteropEmu.DebugGetAbsoluteAddressAndType(startAddress, info); disableEditLabel = info.Address == -1; } mnuEditLabel.Enabled = !disableEditLabel && (this._memoryType == DebugMemoryType.CpuMemory || this.GetAddressType().HasValue); mnuEditBreakpoint.Enabled = DebugWindowManager.GetDebugger() != null && ( this._memoryType == DebugMemoryType.CpuMemory || this._memoryType == DebugMemoryType.PpuMemory || this._memoryType == DebugMemoryType.PrgRom || this._memoryType == DebugMemoryType.WorkRam || this._memoryType == DebugMemoryType.SaveRam || this._memoryType == DebugMemoryType.ChrRam || this._memoryType == DebugMemoryType.ChrRom || this._memoryType == DebugMemoryType.PaletteMemory ); mnuAddToWatch.Enabled = this._memoryType == DebugMemoryType.CpuMemory; mnuCopy.Enabled = ctrlHexBox.CanCopy(); mnuPaste.Enabled = ctrlHexBox.CanPaste(); mnuSelectAll.Enabled = ctrlHexBox.CanSelectAll(); mnuUndo.Enabled = InteropEmu.DebugHasUndoHistory(); }
private void UpdateCode() { if (_symbolProvider == null || CurrentFile == null) { return; } List <int> indents = new List <int>(); List <string> addressing = new List <string>(); List <string> comments = new List <string>(); List <int> lineNumbers = new List <int>(); List <string> lineNotes = new List <string>(); _lineNumberNotes = new List <string>(); List <string> codeLines = new List <string>(); byte[] prgRomContent = InteropEmu.DebugGetMemoryState(DebugMemoryType.PrgRom); bool isC = CurrentFile.Name.EndsWith(".h") || CurrentFile.Name.EndsWith(".c"); int lineIndex = 0; foreach (string line in CurrentFile.Data) { string l = line.Replace("\t", " "); addressing.Add(""); int prgAddress = _symbolProvider.GetPrgAddress(CurrentFile.ID, lineIndex); if (prgAddress >= 0) { int opSize = frmOpCodeTooltip.GetOpSize(prgRomContent[prgAddress]); string byteCode = ""; for (int i = prgAddress, end = prgAddress + opSize; i < end && i < prgRomContent.Length; i++) { byteCode += "$" + prgRomContent[i].ToString("X2") + " "; } lineNotes.Add(byteCode); } else { lineNotes.Add(""); } int relativeAddress = InteropEmu.DebugGetRelativeAddress((uint)prgAddress, AddressType.PrgRom); lineNumbers.Add(relativeAddress); _lineNumberNotes.Add(prgAddress >= 0 ? prgAddress.ToString("X4") : ""); indents.Add(0); int commentIndex; if (isC) { commentIndex = l.IndexOf("//"); } else { commentIndex = l.IndexOfAny(new char[] { ';', '.' }); } if (commentIndex >= 0) { comments.Add(l.Substring(commentIndex)); codeLines.Add(l.Substring(0, commentIndex)); } else { comments.Add(""); codeLines.Add(l); } lineIndex++; } ctrlCodeViewer.CodeHighlightingEnabled = !isC; ctrlCodeViewer.LineIndentations = indents.ToArray(); ctrlCodeViewer.Addressing = addressing.ToArray(); ctrlCodeViewer.Comments = comments.ToArray(); ctrlCodeViewer.LineNumbers = lineNumbers.ToArray(); ctrlCodeViewer.TextLineNotes = lineNotes.ToArray(); ctrlCodeViewer.LineNumberNotes = _lineNumberNotes.ToArray(); ctrlCodeViewer.TextLines = codeLines.ToArray(); this.RefreshViewer(); }
public int GetRelativeAddress() { return(InteropEmu.DebugGetRelativeAddress(this.Address, this.AddressType)); }
public void UpdateFunctionList(bool reset) { if (reset) { _listItems.Clear(); _functions.Clear(); } Font italicFont = null; Font regularFont = null; Int32[] entryPoints = InteropEmu.DebugGetFunctionEntryPoints(); for (int i = 0; i < entryPoints.Length && entryPoints[i] >= 0; i++) { Int32 entryPoint = entryPoints[i]; ListViewItem item; if (!_functions.TryGetValue(entryPoint, out item)) { CodeLabel label = LabelManager.GetLabel((UInt32)entryPoint, AddressType.PrgRom); item = new ListViewItem(label?.Label); item.Tag = label; item.SubItems.Add("[n/a]"); item.SubItems[1].Tag = -1; item.ForeColor = Color.Gray; if (italicFont == null) { italicFont = new Font(item.Font, FontStyle.Italic); } item.Font = italicFont; item.SubItems.Add("$" + entryPoint.ToString("X4")); item.SubItems[2].Tag = entryPoint; _listItems.Add(item); _functions[entryPoint] = item; } Int32 relativeAddress = InteropEmu.DebugGetRelativeAddress((UInt32)entryPoint, AddressType.PrgRom); if (relativeAddress != (Int32)item.SubItems[1].Tag) { if (relativeAddress >= 0) { item.SubItems[1].Text = "$" + relativeAddress.ToString("X4"); item.ForeColor = Color.Black; if (regularFont == null) { regularFont = new Font(item.Font, FontStyle.Regular); } item.Font = regularFont; } else { item.SubItems[1].Text = "[n/a]"; item.ForeColor = Color.Gray; if (italicFont == null) { italicFont = new Font(item.Font, FontStyle.Italic); } item.Font = italicFont; } item.SubItems[1].Tag = relativeAddress; } } lstFunctions.BeginUpdate(); _listItems.Sort(CompareFunctions); lstFunctions.VirtualMode = true; lstFunctions.VirtualListSize = _listItems.Count; lstFunctions.EndUpdate(); }