1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-06-25 05:29:31 +00:00

Improve handling of hidden LV tables

If a local variable table gets buried, it won't appear in the code
list, so most things ignore it.  Unfortunately, the code that adds
new entries and edits tables was finding them, which was causing
variable definitions to appear to fall into a black hole.

This is addressed in two ways.  First, we now add a message to the
log when a hidden table is noticed.  Second, the code that finds
the nearest prior table now keeps track of hidden vs. not hidden.
If a non-hidden table is available, that is returned.  If the only
option is a hidden table, we will return that, because the callers
have already assumed that a table exists by virtue of its presence
in the LvTable list.
This commit is contained in:
Andy McFadden 2019-10-28 16:54:01 -07:00
parent 73f04ef2d2
commit 14ecad0849
6 changed files with 42 additions and 10 deletions

View File

@ -1191,6 +1191,14 @@ namespace SourceGen {
Debug.Assert(false);
}
}
} else if (LvTables.TryGetValue(offset, out LocalVariableTable unused)) {
// table was ignored
Messages.Add(new MessageList.MessageEntry(
MessageList.MessageEntry.SeverityLevel.Warning,
offset,
MessageList.MessageEntry.MessageType.HiddenLocalVariableTable,
string.Empty,
MessageList.MessageEntry.ProblemResolution.LocalVariableTableIgnored));
}
Anattrib attr = mAnattribs[offset];

View File

@ -256,13 +256,16 @@ namespace SourceGen {
}
/// <summary>
/// Finds the closest table that is defined at or before the specified offset.
/// Finds the closest table that is defined at or before the specified offset. Will
/// attempt to only return un-hidden tables, but will return a hidden table if no
/// others are available.
/// </summary>
/// <param name="offset">Target offset.</param>
/// <returns>The table's definition offset, or -1 if no tables were defined before this
/// point.</returns>
public int GetNearestTableOffset(int offset) {
int nearest = -1;
int nearestUnhidden = -1;
// Could do a smarter search, but I'm expecting the set to be small.
foreach (KeyValuePair<int, LocalVariableTable> kvp in mLvTables) {
@ -270,8 +273,15 @@ namespace SourceGen {
break;
}
nearest = kvp.Key;
if (mProject.GetAnattrib(nearest).IsStart) {
nearestUnhidden = nearest;
}
}
if (nearestUnhidden >= 0) {
return nearestUnhidden;
} else {
return nearest;
}
return nearest;
}
/// <summary>
@ -380,5 +390,9 @@ namespace SourceGen {
} while (mSymbolTable.TryGetNonVariableValue(testLabel, out Symbol unused));
return testLabel;
}
public static bool IsTableHidden(int offset, DisasmProject project) {
return !project.GetAnattrib(offset).IsStart;
}
}
}

View File

@ -1778,14 +1778,10 @@ namespace SourceGen {
public void EditLocalVariableTable() {
int selIndex = mMainWin.CodeListView_GetFirstSelectedIndex();
int offset = CodeLineList[selIndex].FileOffset;
// Find the offset of the nearest table that's earlier in the file.
int bestOffset = -1;
foreach (KeyValuePair<int,LocalVariableTable> kvp in mProject.LvTables) {
if (kvp.Key > offset) {
break; // too far
}
bestOffset = kvp.Key;
}
LocalVariableLookup lvLookup = new LocalVariableLookup(mProject.LvTables,
mProject, false);
int bestOffset = lvLookup.GetNearestTableOffset(offset);
Debug.Assert(bestOffset >= 0);
CreateOrEditLocalVariableTable(bestOffset);
}

View File

@ -48,6 +48,7 @@ namespace SourceGen {
public enum MessageType {
Unknown = 0,
HiddenLabel,
HiddenLocalVariableTable,
UnresolvedWeakRef,
InvalidOffsetOrLength,
InvalidDescriptor,
@ -61,6 +62,7 @@ namespace SourceGen {
Unknown = 0,
None,
LabelIgnored,
LocalVariableTableIgnored,
FormatDescriptorIgnored,
}
public ProblemResolution Resolution { get; private set; }
@ -149,6 +151,9 @@ namespace SourceGen {
case MessageEntry.MessageType.HiddenLabel:
problem = Res.Strings.MSG_HIDDEN_LABEL;
break;
case MessageEntry.MessageType.HiddenLocalVariableTable:
problem = Res.Strings.MSG_HIDDEN_LOCAL_VARIABLE_TABLE;
break;
case MessageEntry.MessageType.UnresolvedWeakRef:
problem = Res.Strings.MSG_UNRESOLVED_WEAK_REF;
break;
@ -173,6 +178,9 @@ namespace SourceGen {
case MessageEntry.ProblemResolution.LabelIgnored:
resolution = Res.Strings.MSG_LABEL_IGNORED;
break;
case MessageEntry.ProblemResolution.LocalVariableTableIgnored:
resolution = Res.Strings.MSG_LOCAL_VARIABLE_TABLE_IGNORED;
break;
case MessageEntry.ProblemResolution.FormatDescriptorIgnored:
resolution = Res.Strings.MSG_FORMAT_DESCRIPTOR_IGNORED;
break;

View File

@ -109,9 +109,11 @@ limitations under the License.
<system:String x:Key="str_LocalVariableTableEmpty">• Empty variable table</system:String>
<system:String x:Key="str_MsgFormatDescriptorIgnored">Format ignored</system:String>
<system:String x:Key="str_MsgHiddenLabel">Hidden label</system:String>
<system:String x:Key="str_MsgHiddenLocalVariableTable">Hidden variable table</system:String>
<system:String x:Key="str_MsgInvalidDescriptor">Invalid format desc</system:String>
<system:String x:Key="str_MsgInvalidOffsetOrLength">Invalid offset or len</system:String>
<system:String x:Key="str_MsgLabelIgnored">Label ignored</system:String>
<system:String x:Key="str_MsgLocalVariableTableIgnored">LV table skipped over</system:String>
<system:String x:Key="str_MsgUnresolvedWeakRef">Ref'd symbol not found</system:String>
<system:String x:Key="str_NoFilesAvailable">no files available</system:String>
<system:String x:Key="str_NoExportedSymbolsFound">No exported symbols found.</system:String>

View File

@ -199,12 +199,16 @@ namespace SourceGen.Res {
(string)Application.Current.FindResource("str_MsgFormatDescriptorIgnored");
public static string MSG_HIDDEN_LABEL =
(string)Application.Current.FindResource("str_MsgHiddenLabel");
public static string MSG_HIDDEN_LOCAL_VARIABLE_TABLE =
(string)Application.Current.FindResource("str_MsgHiddenLocalVariableTable");
public static string MSG_INVALID_DESCRIPTOR =
(string)Application.Current.FindResource("str_MsgInvalidDescriptor");
public static string MSG_INVALID_OFFSET_OR_LENGTH =
(string)Application.Current.FindResource("str_MsgInvalidOffsetOrLength");
public static string MSG_LABEL_IGNORED =
(string)Application.Current.FindResource("str_MsgLabelIgnored");
public static string MSG_LOCAL_VARIABLE_TABLE_IGNORED =
(string)Application.Current.FindResource("str_MsgLocalVariableTableIgnored");
public static string MSG_UNRESOLVED_WEAK_REF =
(string)Application.Current.FindResource("str_MsgUnresolvedWeakRef");
public static string NO_FILES_AVAILABLE =