From ee6e5d7fb622c9948d1049503c4a171f24907192 Mon Sep 17 00:00:00 2001
From: Andy McFadden
Date: Wed, 4 Sep 2019 17:48:55 -0700
Subject: [PATCH] Fix a couple of obscure bugs
The code that checked to see if a data target was inside a data
operand wasn't going all the way back to the start of the file.
It was also failing to stop when it should, wasting time.
The anattrib validation method has code that avoids a false-positive
on certain complex embedded instruction arrangements. This was also
preventing it from seeing a transition from a data area to the
middle of an instruction (caused by issue #45).
---
SourceGen/DataAnalysis.cs | 12 ++++++++----
SourceGen/DisasmProject.cs | 7 +++++++
SourceGen/RuntimeData/Help/settings.html | 6 ++++--
SourceGen/SourceGen.csproj | 7 +++++++
4 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/SourceGen/DataAnalysis.cs b/SourceGen/DataAnalysis.cs
index 5290155..db22390 100644
--- a/SourceGen/DataAnalysis.cs
+++ b/SourceGen/DataAnalysis.cs
@@ -303,11 +303,15 @@ namespace SourceGen {
// (Note the uncategorized data pass hasn't run yet, so only instructions
// and offsets identified by users or scripts have been categorized.)
int scanOffset = targetOffset;
- while (--scanOffset > 0) {
+ while (--scanOffset >= 0) {
FormatDescriptor dfd = mAnattribs[scanOffset].DataDescriptor;
- if (dfd != null && scanOffset + dfd.Length > targetOffset) {
- // Descriptor encompasses target offset. Adjust target.
- targetOffset = scanOffset;
+ if (dfd != null) {
+ if (scanOffset + dfd.Length > targetOffset) {
+ // Found a descriptor that encompasses target offset. Adjust
+ // target to point at the start of the region.
+ targetOffset = scanOffset;
+ }
+ // Descriptors aren't allowed to overlap, so either way we're done.
break;
}
}
diff --git a/SourceGen/DisasmProject.cs b/SourceGen/DisasmProject.cs
index 3e97253..c61fd26 100644
--- a/SourceGen/DisasmProject.cs
+++ b/SourceGen/DisasmProject.cs
@@ -1308,6 +1308,7 @@ namespace SourceGen {
int offset = 0;
while (offset < mFileData.Length) {
Anattrib attr = mAnattribs[offset];
+ bool thisIsCode = attr.IsInstructionStart;
Debug.Assert(attr.IsStart);
Debug.Assert(attr.Length != 0);
offset += attr.Length;
@@ -1321,6 +1322,12 @@ namespace SourceGen {
extraInstrBytes++;
offset++;
}
+
+ // Make sure the extra code bytes were part of an instruction. Otherwise it
+ // means we moved from the end of a data area to the middle of an instruction,
+ // which is very bad.
+ Debug.Assert(extraInstrBytes == 0 || thisIsCode);
+
//if (extraInstrBytes > 0) { Debug.WriteLine("EIB=" + extraInstrBytes); }
// Max instruction len is 4, so the stray part must be shorter.
Debug.Assert(extraInstrBytes < 4);
diff --git a/SourceGen/RuntimeData/Help/settings.html b/SourceGen/RuntimeData/Help/settings.html
index 397d3e6..8477a2d 100644
--- a/SourceGen/RuntimeData/Help/settings.html
+++ b/SourceGen/RuntimeData/Help/settings.html
@@ -231,8 +231,10 @@ value. If it's not checked, anything that isn't detected as code or
explicitly formatted as data will be shown as individual byte values.
If "seek nearby targets" is checked, the analyzer will try to use
nearby labels for data loads and stores, adjusting them to fit
-(e.g. LDA LABEL+1
). If not enabled, labels are only used
-when they match exactly.
+(e.g. LDA LABEL+1
). If not enabled, labels are not applied
+unless they match exactly. Note that references into the middle of an
+instruction or formatted data area are always adjusted, regardless of
+how this is set. This setting has no effect on local variables.
If "smart PLP handling" is checked, the analyzer will try to use
the processor status flags from a nearby PHP
when a
PLP
is encountered. If not enabled, all flags are set to
diff --git a/SourceGen/SourceGen.csproj b/SourceGen/SourceGen.csproj
index a060190..38e2e67 100644
--- a/SourceGen/SourceGen.csproj
+++ b/SourceGen/SourceGen.csproj
@@ -109,6 +109,9 @@
EditInstructionOperand.xaml
+
+ EditInstructionOperand2.xaml
+
EditLabel.xaml
@@ -266,6 +269,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile