Skip to content

Commit

Permalink
Fix: navigation problem reported by @gbody.
Browse files Browse the repository at this point in the history
  • Loading branch information
uxmal committed Jan 3, 2025
1 parent 4e102e1 commit 40c4b3a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
14 changes: 6 additions & 8 deletions src/Gui/TextViewing/MixedCodeDataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,17 @@ public override string ToString()

public class DataItemNode
{
public Address? StartAddress { get; set; }
public Address? EndAddress { get; set; }
public Address StartAddress { get; set; }
public Address EndAddress { get; set; }
public Procedure? Proc { get; private set; }
public int NumLines { get; set; }
public TextModelNode? ModelNode { get; set; }
public DataItemNode(Procedure? proc, int numLines)
public DataItemNode(Procedure? proc, int numLines, Address addrStart, Address addrEnd)
{
this.Proc = proc;
this.NumLines = numLines;
this.StartAddress = addrStart;
this.EndAddress = addrEnd;
}
}

Expand Down Expand Up @@ -561,11 +563,7 @@ public Collection<DataItemNode> GetDataItemNodes()

if (curNode == null || curNode.Proc != curProc || curProc == null)
{
curNode = new DataItemNode(curProc, numLines)
{
StartAddress = startAddr,
EndAddress = endAddr
};
curNode = new DataItemNode(curProc, numLines, startAddr, endAddr);
nodes.Add(curNode);
}
else
Expand Down
17 changes: 7 additions & 10 deletions src/UserInterfaces/WindowsForms/CombinedCodeViewInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,9 @@ public void DisplayProcedure(Program program, Procedure proc)
this.proc = proc;
this.showProcedures = true;
ProgramChanged();
if (program != null)
if (program is not null)
{
var addr = proc.EntryAddress;
addr = program.SegmentMap.Segments.Values
.Select(s => Address.Max(s.Address, s.MemoryArea.BaseAddress))
.First();
SelectedAddress = addr;
}
}
Expand Down Expand Up @@ -174,7 +171,7 @@ private void CreateNestedTextModel()
nestedTextModel.Nodes.Add(model);
nodeCreated = true;
}
else if (program.ImageMap.TryFindItem(curAddr.Value, out ImageMapItem item) &&
else if (program.ImageMap.TryFindItem(curAddr, out ImageMapItem item) &&
item.DataType != null &&
item.DataType is not UnknownType)
{
Expand All @@ -185,7 +182,7 @@ private void CreateNestedTextModel()
var fmt = new AbsynCodeFormatter(tsf);
fmt.InnerFormatter.UseTabs = false;
var gdw = new GlobalDataWriter(program, tsf, false, false, services);
gdw.WriteGlobalVariable(curAddr.Value, dt, name);
gdw.WriteGlobalVariable(curAddr, dt, name);
//$TODO: make spacing between globals / procedures user adjustable
tsf.WriteLine("");
nestedTextModel.Nodes.Add(tsf.GetModel());
Expand All @@ -196,7 +193,7 @@ private void CreateNestedTextModel()
if (nodeCreated)
{
dataItemNode.ModelNode = nestedTextModel.Nodes.Last();
this.nodeByAddress[curAddr.Value] = dataItemNode;
this.nodeByAddress[curAddr] = dataItemNode;
}
}
combinedCodeView.CodeView.Model = nestedTextModel;
Expand All @@ -207,7 +204,7 @@ private bool ShowItem(MixedCodeDataModel.DataItemNode item)
if (!showProcedures && item.Proc is not null)
return false;

if (segment is not null && !segment.IsInRange(item.StartAddress.Value))
if (segment is not null && !segment.IsInRange(item.StartAddress))
return false;

return true;
Expand Down Expand Up @@ -615,7 +612,7 @@ nodeByAddress is null ||
{
var startAddr = dataItemNode.StartAddress;
var endAddr = topAddress;
var startPos = MixedCodeDataModel.Position(startAddr.Value, 0);
var startPos = MixedCodeDataModel.Position(startAddr, 0);
var endPos = MixedCodeDataModel.Position(endAddr.Value, 0);
numer = mixedCodeDataModel.CountLines(startPos, endPos);
denom = dataItemNode.NumLines;
Expand Down Expand Up @@ -646,7 +643,7 @@ private void CodeView_PositionChanged()
long numLines = dataItemNode.NumLines;
var offset = (int)((numLines * numer) / denom);
var startAddr = dataItemNode.StartAddress;
var startPos = MixedCodeDataModel.Position(startAddr.Value, 0);
var startPos = MixedCodeDataModel.Position(startAddr, 0);
combinedCodeView.MixedCodeDataView.Model.MoveToLine(startPos, offset);
combinedCodeView.MixedCodeDataView.InvalidateModel();
}
Expand Down
3 changes: 1 addition & 2 deletions src/UserInterfaces/WindowsForms/DisassemblyViewInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ private bool IsProgramLoaded(Program program)
return
program != null &&
program.Architecture != null &&
program.ImageMap != null &&
StartAddress != null;
program.ImageMap != null;
}

private async ValueTask GotoAddress()
Expand Down

0 comments on commit 40c4b3a

Please sign in to comment.