From 0fb0b4cca8eff22bb0cbeffddb8f367d82e28a3e Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sun, 17 Oct 2021 18:02:29 -0700 Subject: [PATCH] Fix some address region issues Fixed a crash when the listing is refreshed while a .adrend line is the only thing selected. Fixed .adrend lines being spammed if the last thing before it is a multi-byte item, and you edit a comment / note / label on that line. Harmless, but weird. Also, added keyboard shortcuts in DefSymbol editor, so you can change from address to constant with Alt+C. --- SourceGen/DisasmProject.cs | 47 +++++++++++++++++++++-------- SourceGen/LineListGen.cs | 3 +- SourceGen/WpfGui/EditDefSymbol.xaml | 6 ++-- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs index c9f4674..3c2ab6f 100644 --- a/SourceGen/DisasmProject.cs +++ b/SourceGen/DisasmProject.cs @@ -2352,18 +2352,14 @@ namespace SourceGen { "project/platform symbol"); needReanalysis = UndoableChange.ReanalysisScope.DataOnly; } else { - affectedOffsets.Add(offset); + AddAffectedLine(affectedOffsets, offset); // Use the cross-reference table to identify the offsets that // we need to update. if (mXrefs.TryGetValue(offset, out XrefSet xrefs)) { foreach (XrefSet.Xref xr in xrefs) { - // This isn't quite right -- in theory we should be - // adding all offsets that are part of the instruction, - // so that affectedOffsets can hold a contiguous range - // instead of a collection of opcode offsets. In - // practice, for a label change, it shouldn't matter. - affectedOffsets.Add(xr.Offset); + // Add all bytes in the instruction / data item. + AddAffectedLine(affectedOffsets, xr.Offset); } } } @@ -2432,8 +2428,8 @@ namespace SourceGen { } Comments[offset] = (string)newValue; - // Only affects this offset. - affectedOffsets.Add(offset); + // Only affects the bytes at this offset. + AddAffectedLine(affectedOffsets, offset); } break; case UndoableChange.ChangeType.SetLongComment: { @@ -2449,8 +2445,8 @@ namespace SourceGen { LongComments[offset] = (MultiLineComment)newValue; } - // Only affects this offset. - affectedOffsets.Add(offset); + // Only affects the bytes at this offset. + AddAffectedLine(affectedOffsets, offset); } break; case UndoableChange.ChangeType.SetNote: { @@ -2466,8 +2462,8 @@ namespace SourceGen { Notes[offset] = (MultiLineComment)newValue; } - // Only affects this offset. - affectedOffsets.Add(offset); + // Only affects the bytes at this offset. + AddAffectedLine(affectedOffsets, offset); } break; case UndoableChange.ChangeType.SetProjectProperties: { @@ -2555,6 +2551,31 @@ namespace SourceGen { return needReanalysis; } + /// + /// Adds all offsets associated with the code or data item at the specified offset + /// to the range set. + /// + /// + /// In the past, it was only really necessary to add the first offset, because that + /// would trigger the entire line to be redrawn. That's not the case with arend + /// directives, which are associated with the last byte of a multi-byte item. + /// + /// Range set to update. + /// Offset of first byte. + private void AddAffectedLine(RangeSet affectedOffsets, int offset) { + int len = 1; + if (offset >= 0) { // header comment doesn't have an Anattrib entry + len = mAnattribs[offset].Length; + } + if (len == 0) { + Debug.Assert(false, "Zero-length affected line?"); + len = 1; + } + for (int i = offset; i < offset + len; i++) { + affectedOffsets.Add(i); + } + } + /// /// Clears all cached visualization images. /// diff --git a/SourceGen/LineListGen.cs b/SourceGen/LineListGen.cs index 8c765f5..7ba2e94 100644 --- a/SourceGen/LineListGen.cs +++ b/SourceGen/LineListGen.cs @@ -307,7 +307,8 @@ namespace SourceGen { if (lineType == Line.Type.Code || lineType == Line.Type.Data) { lineType = Line.Type.CodeOrData; } - if (line.FileOffset == curOffset || lineType == Line.Type.ArEndDirective) { + if (line.FileOffset == curOffset || + (tag != null && lineType == Line.Type.ArEndDirective)) { // Another item at same offset. We special-case the arend directive // because it's contained within the previous item, so we want it to be // set on the existing [offset,offset+span) range tag. diff --git a/SourceGen/WpfGui/EditDefSymbol.xaml b/SourceGen/WpfGui/EditDefSymbol.xaml index b3ccfdc..d45ddbb 100644 --- a/SourceGen/WpfGui/EditDefSymbol.xaml +++ b/SourceGen/WpfGui/EditDefSymbol.xaml @@ -32,8 +32,8 @@ limitations under the License. • Decimal or hex value, 1-{0} - Constant - Stack-Relative Offset + _Constant + Stack-Relative _Offset @@ -54,7 +54,7 @@ limitations under the License. Symbol type: - +