private void mnuEditLabel_Click(object sender, EventArgs e) { UInt32 address = (UInt32)ctrlHexBox.SelectionStart; SnesMemoryType memType = _memoryType; if (!memType.SupportsLabels()) { AddressInfo relAddress = new AddressInfo() { Address = (int)address, Type = memType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address < 0 || !absAddress.Type.SupportsLabels()) { return; } address = (uint)absAddress.Address; memType = absAddress.Type; } CodeLabel label = LabelManager.GetLabel(address, memType); if (label == null) { label = new CodeLabel() { Address = address, MemoryType = memType }; } ctrlLabelList.EditLabel(label); }
private string GetFunctionName(int relSubEntryAddr, StackFrameFlags flags) { if (relSubEntryAddr < 0) { return("[bottom of stack]"); } CodeLabel label = relSubEntryAddr >= 0 ? LabelManager.GetLabel(new AddressInfo() { Address = relSubEntryAddr, Type = _cpuType.ToMemoryType() }) : null; if (label != null) { return(label.Label + " ($" + relSubEntryAddr.ToString(_format) + ")"); } else if (flags == StackFrameFlags.Nmi) { return("[nmi] $" + relSubEntryAddr.ToString(_format)); } else if (flags == StackFrameFlags.Irq) { return("[irq] $" + relSubEntryAddr.ToString(_format)); } return("$" + relSubEntryAddr.ToString(_format)); }
private string GetFunctionName(int relSubEntryAddr, int absSubEntryAddr, int nmiHandler, int irqHandler) { if (relSubEntryAddr < 0) { return("[bottom of stack]"); } string funcName; CodeLabel label = LabelManager.GetLabel((UInt32)absSubEntryAddr, AddressType.PrgRom); if (label != null) { funcName = label.Label + (relSubEntryAddr >= 0 ? (" ($" + relSubEntryAddr.ToString("X4") + ")") : ""); } else { funcName = (relSubEntryAddr >= 0 ? ("$" + relSubEntryAddr.ToString("X4")) : "n/a"); } if (relSubEntryAddr == nmiHandler) { funcName = "[nmi] " + funcName; } else if (relSubEntryAddr == irqHandler) { funcName = "[irq] " + funcName; } return(funcName); }
public static void EditLabel(UInt32 address, AddressType type) { CodeLabel existingLabel = LabelManager.GetLabel(address, type); CodeLabel newLabel = new CodeLabel() { Address = existingLabel?.Address ?? address, AddressType = existingLabel?.AddressType ?? type, Label = existingLabel?.Label, Comment = existingLabel?.Comment, Length = existingLabel?.Length ?? 1 }; frmEditLabel frm = new frmEditLabel(newLabel, existingLabel); if (frm.ShowDialog() == DialogResult.OK) { bool empty = string.IsNullOrWhiteSpace(newLabel.Label) && string.IsNullOrWhiteSpace(newLabel.Comment); if (existingLabel != null) { LabelManager.DeleteLabel(existingLabel, empty); } if (!empty) { LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length); } } }
private void RefreshList() { Int64 exclusiveTotal = _exclusiveTime.Sum(); int hexCount = GetMaxAddrHexSize(); lstFunctions.BeginUpdate(); lstFunctions.ListViewItemSorter = null; lstFunctions.Items.Clear(); for (UInt32 i = 0; i < _exclusiveTime.Length; i++) { if (_exclusiveTime[i] > 0) { string functionName; if (i == _exclusiveTime.Length - 2) { functionName = "[Reset]"; } else if (i == _exclusiveTime.Length - 1) { functionName = "[In-Memory Function]"; } else { CodeLabel label = LabelManager.GetLabel((UInt32)i, AddressType.PrgRom); functionName = "$" + i.ToString("X" + hexCount.ToString()); if (label != null) { functionName = label.Label + " (" + functionName + ")"; } } ListViewItem item = lstFunctions.Items.Add(functionName); item.Tag = i; item.SubItems.Add(_callCount[i].ToString()); item.SubItems[1].Tag = _callCount[i]; item.SubItems.Add(_inclusiveTime[i].ToString()); item.SubItems[2].Tag = _inclusiveTime[i]; double ratio = ((double)_inclusiveTime[i] / exclusiveTotal) * 100; item.SubItems.Add(ratio.ToString("0.00")); item.SubItems[3].Tag = (Int64)(ratio * 100); item.SubItems.Add(_exclusiveTime[i].ToString()); item.SubItems[4].Tag = _exclusiveTime[i]; ratio = ((double)_exclusiveTime[i] / exclusiveTotal) * 100; item.SubItems.Add(ratio.ToString("0.00")); item.SubItems[5].Tag = (Int64)(ratio * 100); } } lstFunctions.ListViewItemSorter = new ListComparer(_sortColumn, _sortOrder); lstFunctions.EndUpdate(); }
public static void EditComment(UInt32 address, AddressType type) { string autoName = "C" + address.ToString("X4"); CodeLabel existingLabel = LabelManager.GetLabel(address, type); CodeLabel newLabel = new CodeLabel() { Address = existingLabel?.Address ?? address, AddressType = existingLabel?.AddressType ?? type, Label = existingLabel?.Label, Comment = existingLabel?.Comment, Length = existingLabel?.Length ?? 1 }; if (existingLabel == null) { newLabel.Label = autoName; } bool isMultiLine = false; if (existingLabel != null && existingLabel.Comment.Contains("\r\n")) { isMultiLine = true; } if (isMultiLine) { frmEditLabel frm = new frmEditLabel(newLabel, existingLabel, true); if (frm.ShowDialog() == DialogResult.OK) { bool empty = string.IsNullOrWhiteSpace(newLabel.Comment) && newLabel.Label == autoName; if (existingLabel != null) { LabelManager.DeleteLabel(existingLabel, empty); } if (!empty) { LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length); } } } else { frmEditComment frm = new frmEditComment(newLabel, existingLabel); if (frm.ShowDialog() == DialogResult.OK) { bool empty = string.IsNullOrWhiteSpace(newLabel.Comment) && newLabel.Label == autoName; if (existingLabel != null) { LabelManager.DeleteLabel(existingLabel, empty); } if (!empty) { LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length); } } } }
private string GetFunctionName(ProfiledFunction func) { int hexCount = this.CpuType == CpuType.Spc ? 4 : 6; string functionName; if (func.Address.Address == -1) { functionName = "[Reset]"; } else { CodeLabel label = LabelManager.GetLabel((UInt32)func.Address.Address, func.Address.Type); switch (func.Address.Type) { case SnesMemoryType.PrgRom: functionName = "PRG: $"; break; case SnesMemoryType.Register: functionName = "REG: $"; break; case SnesMemoryType.SaveRam: functionName = "SRAM: $"; break; case SnesMemoryType.WorkRam: functionName = "WRAM: $"; break; case SnesMemoryType.SpcRam: functionName = "SPC: $"; break; case SnesMemoryType.SpcRom: functionName = "SPC ROM: $"; break; case SnesMemoryType.Sa1InternalRam: functionName = "IRAM: $"; break; case SnesMemoryType.GbPrgRom: functionName = "PRG: $"; break; case SnesMemoryType.GbWorkRam: functionName = "WRAM: $"; break; case SnesMemoryType.GbCartRam: functionName = "SRAM: $"; break; case SnesMemoryType.GbHighRam: functionName = "HRAM: $"; break; case SnesMemoryType.GbBootRom: functionName = "BOOT: $"; break; default: throw new Exception("Unsupported type"); } functionName += func.Address.Address.ToString("X" + hexCount.ToString()); if (label != null) { functionName = label.Label + " (" + functionName + ")"; } } return(functionName); }
private void EditLabel(LocationInfo location) { if (location.Symbol != null) { //Don't allow edit label on symbols return; } if (location.Label != null) { using (frmEditLabel frm = new frmEditLabel(location.Label)) { frm.ShowDialog(); } } else if (location.Address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = location.Address, Type = _manager.RelativeMemoryType }; AddressInfo absAddress = DebugApi.GetAbsoluteAddress(relAddress); if (absAddress.Address >= 0) { CodeLabel label = LabelManager.GetLabel((uint)absAddress.Address, absAddress.Type); if (label == null) { label = new CodeLabel() { Address = (uint)absAddress.Address, MemoryType = absAddress.Type }; } using (frmEditLabel frm = new frmEditLabel(label)) { frm.ShowDialog(); } } } }
private string GetFunctionName(ProfiledFunction func) { string functionName; if (func.Address.Address == -1) { functionName = "[Reset]"; } else { CodeLabel label = LabelManager.GetLabel((UInt32)func.Address.Address, func.Address.Type); switch (func.Address.Type) { case AddressType.PrgRom: functionName = "PRG: $"; break; case AddressType.Register: functionName = "REG: $"; break; case AddressType.SaveRam: functionName = "SRAM: $"; break; case AddressType.WorkRam: functionName = "WRAM: $"; break; case AddressType.InternalRam: functionName = "RAM: $"; break; default: throw new Exception("Unsupported type"); } functionName += func.Address.Address.ToString("X4"); if (label != null) { functionName = label.Label + " (" + functionName + ")"; } } return(functionName); }
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 void RefreshList() { Int64 exclusiveTotal = _exclusiveTime.Sum(); int hexCount = GetMaxAddrHexSize(); lstFunctions.BeginUpdate(); lstFunctions.ListViewItemSorter = null; int?topItemIndex = lstFunctions.TopItem?.Index; int selectedIndex = lstFunctions.SelectedIndices.Count > 0 ? lstFunctions.SelectedIndices[0] : -1; int itemNumber = 0; for (UInt32 i = 0; i < _exclusiveTime.Length; i++) { if (_exclusiveTime[i] > 0) { string functionName; if (i == _exclusiveTime.Length - 2) { functionName = "[Reset]"; } else if (i == _exclusiveTime.Length - 1) { functionName = "[In-Memory Function]"; } else { CodeLabel label = LabelManager.GetLabel((UInt32)i, AddressType.PrgRom); functionName = "$" + i.ToString("X" + hexCount.ToString()); if (label != null) { functionName = label.Label + " (" + functionName + ")"; } } ListViewItem item; if (itemNumber >= lstFunctions.Items.Count) { item = lstFunctions.Items.Add(""); item.SubItems.Add(""); item.SubItems.Add(""); item.SubItems.Add(""); item.SubItems.Add(""); item.SubItems.Add(""); } else { item = lstFunctions.Items[itemNumber]; } item.Text = functionName; item.Tag = i; item.Selected = false; item.Focused = false; item.SubItems[1].Text = _callCount[i].ToString(); item.SubItems[1].Tag = _callCount[i]; item.SubItems[2].Text = _inclusiveTime[i].ToString(); item.SubItems[2].Tag = _inclusiveTime[i]; double ratio = ((double)_inclusiveTime[i] / exclusiveTotal) * 100; item.SubItems[3].Text = ratio.ToString("0.00"); item.SubItems[3].Tag = (Int64)(ratio * 100); item.SubItems[4].Text = _exclusiveTime[i].ToString(); item.SubItems[4].Tag = _exclusiveTime[i]; ratio = ((double)_exclusiveTime[i] / exclusiveTotal) * 100; item.SubItems[5].Text = ratio.ToString("0.00"); item.SubItems[5].Tag = (Int64)(ratio * 100); itemNumber++; } } lstFunctions.ListViewItemSorter = new ListComparer(_sortColumn, _sortOrder); lstFunctions.EndUpdate(); if (topItemIndex.HasValue) { lstFunctions.TopItem = lstFunctions.Items[topItemIndex.Value]; } if (selectedIndex >= 0) { lstFunctions.Items[selectedIndex].Selected = true; lstFunctions.Items[selectedIndex].Focused = true; } }
public LocationInfo GetLocationInfo(string word, int lineIndex) { LocationInfo location = new LocationInfo(); int arraySeparatorIndex = word.IndexOf("+"); if (arraySeparatorIndex >= 0) { int index; if (int.TryParse(word.Substring(arraySeparatorIndex + 1), out index)) { location.ArrayIndex = index; } word = word.Substring(0, arraySeparatorIndex); } if (_provider is SymbolCodeDataProvider && _symbolProvider != null) { int rangeStart, rangeEnd; GetSymbolByteRange(lineIndex, out rangeStart, out rangeEnd); location.Symbol = _symbolProvider.GetSymbol(word, rangeStart, rangeEnd); } location.Label = LabelManager.GetLabel(word); int address; if (location.Label != null) { address = location.Label.GetRelativeAddress(this.CpuType).Address; if (address >= 0) { location.Address = location.Label.GetRelativeAddress(this.CpuType).Address + (location.ArrayIndex ?? 0); } else { location.Address = -1; } } else if (word.StartsWith("$")) { word = word.Replace("$", ""); if (Int32.TryParse(word, System.Globalization.NumberStyles.HexNumber, null, out address)) { location.Address = GetFullAddress(address, word.Length); } } else if (Int32.TryParse(word, out address)) { location.Address = (int)address; } else { location.Address = -1; } if (location.Label == null && location.Address >= 0) { AddressInfo relAddress = new AddressInfo() { Address = location.Address, Type = RelativeMemoryType }; CodeLabel label = LabelManager.GetLabel(relAddress); if (label != null && !string.IsNullOrWhiteSpace(label.Label)) { //ignore comment-only labels location.Label = label; } } if (location.Label != null && location.Address >= 0) { AddressInfo absAddress = location.Label.GetAbsoluteAddress(); AddressInfo absIndexedAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = location.Address, Type = RelativeMemoryType }); if (absIndexedAddress.Address > absAddress.Address) { location.ArrayIndex = absIndexedAddress.Address - absAddress.Address; } } return(location); }
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(); }
private bool UpdateContextMenu(Point mouseLocation) { _lastLocation = mouseLocation; UpdateContextMenuItemVisibility(contextMenu.Items); mnuSwitchView.Text = IsSourceView ? "Switch to Disassembly View" : "Switch to Source View"; string word = Viewer.CodeViewer.GetWordUnderLocation(mouseLocation); Ld65DbgImporter.SymbolInfo symbol = null; CodeLabel codeLabel = null; if (!word.StartsWith("$")) { Match arrayMatch = CodeTooltipManager.LabelArrayFormat.Match(word); if (arrayMatch.Success) { word = arrayMatch.Groups[1].Value; } codeLabel = LabelManager.GetLabel(word); if (Viewer.SymbolProvider != null && IsSourceView) { int rangeStart, rangeEnd; if (Viewer.CodeViewer.GetNoteRangeAtLocation(mouseLocation.Y, out rangeStart, out rangeEnd)) { symbol = Viewer.SymbolProvider.GetSymbol(word, rangeStart, rangeEnd); } } } 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); _lastClickedSymbol = null; _lastClickedLabel = null; _newWatchValue = "[$" + _lastClickedAddress.ToString("X") + "]"; } else if (symbol != null) { //Symbol _lastClickedAddress = -1; _lastClickedLabel = null; _lastClickedSymbol = symbol; _newWatchValue = "[" + word + "]"; } else if (codeLabel != null) { //Label _lastClickedLabel = codeLabel; _lastClickedAddress = -1; _lastClickedSymbol = null; _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"; _lastClickedLabel = null; _lastClickedSymbol = null; 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); } }