GT-2706 Fixed exceptions in Diff View

This commit is contained in:
ghidra5 2019-03-29 14:39:40 -04:00
parent 79d8f164f8
commit e75c28afd6
3 changed files with 39 additions and 23 deletions

View File

@ -193,11 +193,11 @@ public class DiffUtility extends SimpleDiffUtility {
return otherProgram.getSymbolTable().createExternalLibrary(namespace.getName(), source); return otherProgram.getSymbolTable().createExternalLibrary(namespace.getName(), source);
} }
else if (namespace instanceof GhidraClass) { else if (namespace instanceof GhidraClass) {
return otherProgram.getSymbolTable().createClass(otherParentNamespace, return otherProgram.getSymbolTable()
namespace.getName(), source); .createClass(otherParentNamespace, namespace.getName(), source);
} }
return otherProgram.getSymbolTable().createNameSpace(otherParentNamespace, return otherProgram.getSymbolTable()
namespace.getName(), source); .createNameSpace(otherParentNamespace, namespace.getName(), source);
} }
// /** // /**
@ -329,11 +329,11 @@ public class DiffUtility extends SimpleDiffUtility {
if (toAddr == null) { if (toAddr == null) {
return null; return null;
} }
return otherProgram.getReferenceManager().getReference(fromAddr, toAddr, return otherProgram.getReferenceManager()
ref.getOperandIndex()); .getReference(fromAddr, toAddr, ref.getOperandIndex());
} }
Reference otherRef = otherProgram.getReferenceManager().getPrimaryReferenceFrom(fromAddr, Reference otherRef = otherProgram.getReferenceManager()
ref.getOperandIndex()); .getPrimaryReferenceFrom(fromAddr, ref.getOperandIndex());
if (otherRef != null && ref.getToAddress().hasSameAddressSpace(otherRef.getToAddress())) { if (otherRef != null && ref.getToAddress().hasSameAddressSpace(otherRef.getToAddress())) {
return otherRef; return otherRef;
} }
@ -357,11 +357,11 @@ public class DiffUtility extends SimpleDiffUtility {
if (toAddr1 == null) { if (toAddr1 == null) {
return null; return null;
} }
return program.getReferenceManager().getReference(fromAddr1, toAddr1, return program.getReferenceManager()
p2Ref.getOperandIndex()); .getReference(fromAddr1, toAddr1, p2Ref.getOperandIndex());
} }
Reference p1Ref = program.getReferenceManager().getPrimaryReferenceFrom(fromAddr1, Reference p1Ref = program.getReferenceManager()
p2Ref.getOperandIndex()); .getPrimaryReferenceFrom(fromAddr1, p2Ref.getOperandIndex());
if (p1Ref != null && p1Ref.getToAddress().hasSameAddressSpace(p2Ref.getToAddress())) { if (p1Ref != null && p1Ref.getToAddress().hasSameAddressSpace(p2Ref.getToAddress())) {
return p1Ref; return p1Ref;
} }
@ -385,8 +385,9 @@ public class DiffUtility extends SimpleDiffUtility {
otherAddr = getCompatibleAddress(program, addr, otherProgram); otherAddr = getCompatibleAddress(program, addr, otherProgram);
} }
// FIXME Should this be passing the Namespace? // FIXME Should this be passing the Namespace?
return otherProgram.getExternalManager().addExtLocation(extLoc.getLibraryName(), return otherProgram.getExternalManager()
extLoc.getLabel(), otherAddr, extLoc.getSource()); .addExtLocation(extLoc.getLibraryName(), extLoc.getLabel(), otherAddr,
extLoc.getSource());
} }
/** /**
@ -707,6 +708,9 @@ public class DiffUtility extends SimpleDiffUtility {
Address refAddress = getCompatibleAddress(program, location.refAddr, otherProgram); Address refAddress = getCompatibleAddress(program, location.refAddr, otherProgram);
if (address != null) { if (address != null) {
if (byteAddress == null) {
byteAddress = address; // Make sure the byte address isn't null.
}
ProgramLocation otherLocation = new ProgramLocation(otherProgram, address, byteAddress, ProgramLocation otherLocation = new ProgramLocation(otherProgram, address, byteAddress,
location.getComponentPath(), refAddress, 0, 0, 0); location.getComponentPath(), refAddress, 0, 0, 0);
return otherLocation; return otherLocation;

View File

@ -2555,7 +2555,7 @@ public class ProgramDiffDetails {
} }
private void addColorAddress(StyledDocument doc, Address addr) { private void addColorAddress(StyledDocument doc, Address addr) {
String text = addr.toString(); String text = (addr != null) ? addr.toString() : "no matching address";
color(ADDRESS_COLOR); color(ADDRESS_COLOR);
try { try {
doc.insertString(doc.getLength(), text, textAttrSet); doc.insertString(doc.getLength(), text, textAttrSet);

View File

@ -441,6 +441,9 @@ public class ProgramDiffPlugin extends ProgramPlugin
Address primaryByteAddr = SimpleDiffUtility.getCompatibleAddress(secondaryDiffProgram, Address primaryByteAddr = SimpleDiffUtility.getCompatibleAddress(secondaryDiffProgram,
byteAddr, primaryProgram); byteAddr, primaryProgram);
if (primaryByteAddr == null) {
primaryByteAddr = primaryAddr; // Make sure the byte address isn't null.
}
Address primaryRefAddr = SimpleDiffUtility.getCompatibleAddress(secondaryDiffProgram, Address primaryRefAddr = SimpleDiffUtility.getCompatibleAddress(secondaryDiffProgram,
refAddr, primaryProgram); refAddr, primaryProgram);
ProgramLocation newP1Location = new ProgramLocation(primaryProgram, primaryAddr, ProgramLocation newP1Location = new ProgramLocation(primaryProgram, primaryAddr,
@ -463,7 +466,9 @@ public class ProgramDiffPlugin extends ProgramPlugin
} }
ProgramLocation previousP1LocationAsP2 = DiffUtility ProgramLocation previousP1LocationAsP2 = DiffUtility
.getCompatibleProgramLocation(primaryProgram, location, secondaryDiffProgram); .getCompatibleProgramLocation(primaryProgram, location, secondaryDiffProgram);
diffListingPanel.setCursorPosition(previousP1LocationAsP2); if (previousP1LocationAsP2 != null) {
diffListingPanel.setCursorPosition(previousP1LocationAsP2);
}
if (diffDetailsProvider != null && diffDetails != null) { if (diffDetailsProvider != null && diffDetails != null) {
diffDetailsProvider.locationChanged(previousP1Location); diffDetailsProvider.locationChanged(previousP1Location);
} }
@ -749,7 +754,7 @@ public class ProgramDiffPlugin extends ProgramPlugin
runSwing(() -> { runSwing(() -> {
MarkerSet selectionMarkers = getSelectionMarkers(); MarkerSet selectionMarkers = getSelectionMarkers();
selectionMarkers.clearAll(); selectionMarkers.clearAll();
selectionMarkers.add(p2SelectionAsP1); selectionMarkers.add(p2Selection);
}); });
diffListingPanel.setSelection(p2SelectionAsP1); diffListingPanel.setSelection(p2SelectionAsP1);
@ -798,9 +803,9 @@ public class ProgramDiffPlugin extends ProgramPlugin
// Limit the apply to the selection in the view. // Limit the apply to the selection in the view.
AddressSet p2SelectionAsP1 = AddressSet p2SelectionAsP1 =
DiffUtility.getCompatibleAddressSet(p2Selection, primaryProgram); DiffUtility.getCompatibleAddressSet(p2Selection, primaryProgram);
AddressSet p1ApplySet = AddressSet p1ApplySet = p2SelectionAsP1.intersect(p1ViewAddrSet)
p2SelectionAsP1.intersect(p1ViewAddrSet).subtract(addressesOnlyInP1).subtract( .subtract(addressesOnlyInP1)
compatibleOnlyInP2); .subtract(compatibleOnlyInP2);
if (p1ApplySet.isEmpty()) { if (p1ApplySet.isEmpty()) {
Msg.showInfo(getClass(), tool.getToolFrame(), "Apply Differences", Msg.showInfo(getClass(), tool.getToolFrame(), "Apply Differences",
(p2Selection.isEmpty()) ? "No diff selection in the current view." (p2Selection.isEmpty()) ? "No diff selection in the current view."
@ -860,7 +865,7 @@ public class ProgramDiffPlugin extends ProgramPlugin
// Right side markers need p1 addresses since they use p1 indexMap. // Right side markers need p1 addresses since they use p1 indexMap.
MarkerSet diffMarkers = getDiffMarkers(); // Get right side markers for program 2. MarkerSet diffMarkers = getDiffMarkers(); // Get right side markers for program 2.
diffMarkers.clearAll(); diffMarkers.clearAll();
diffMarkers.add(p2DiffSetAsP1); diffMarkers.add(p2DiffSet);
MarkerSet codeViewerDiffMarkers = getCodeViewerMarkers(); // Get left side markers for program 1. MarkerSet codeViewerDiffMarkers = getCodeViewerMarkers(); // Get left side markers for program 1.
codeViewerDiffMarkers.clearAll(); codeViewerDiffMarkers.clearAll();
@ -884,7 +889,7 @@ public class ProgramDiffPlugin extends ProgramPlugin
AddressSet p1DiffHighlightSet = AddressSet p1DiffHighlightSet =
DiffUtility.getCompatibleAddressSet(p2Highlight, primaryProgram); DiffUtility.getCompatibleAddressSet(p2Highlight, primaryProgram);
p2DiffHighlight = p2Highlight; p2DiffHighlight = p2Highlight;
diffMarkers.add(p1DiffHighlightSet); diffMarkers.add(p2Highlight);
codeViewerDiffMarkers.add(p1DiffHighlightSet); codeViewerDiffMarkers.add(p1DiffHighlightSet);
} }
@ -1603,7 +1608,14 @@ public class ProgramDiffPlugin extends ProgramPlugin
diffListingPanel.goTo(currentLocation); diffListingPanel.goTo(currentLocation);
MarkerSet cursorMarkers = getCursorMarkers(); MarkerSet cursorMarkers = getCursorMarkers();
cursorMarkers.setAddressSet(new AddressSet(currentLocation.getAddress())); Address currentP2Address = currentLocation.getAddress();
if (currentLocation.getProgram() != secondaryDiffProgram) { // Make sure address is from P2.
currentP2Address = SimpleDiffUtility.getCompatibleAddress(currentLocation.getProgram(),
currentLocation.getAddress(), secondaryDiffProgram);
}
if (currentP2Address != null) {
cursorMarkers.setAddressSet(new AddressSet(currentP2Address));
}
updatePgm2Enablement(); updatePgm2Enablement();