Merge remote-tracking branch 'origin/GP-4165_ghidra1_ProgramUpgradeCacheImprovement--SQUASHED'

This commit is contained in:
Ryan Kurtz 2024-01-10 08:29:42 -05:00
commit 4b465a980e
2 changed files with 19 additions and 7 deletions

View file

@ -304,11 +304,9 @@ public class ProgramManagerPlugin extends Plugin implements ProgramManager, Opti
program = programMgr.getOpenProgram(locator); program = programMgr.getOpenProgram(locator);
if (program != null) { if (program != null) {
program.addConsumer(consumer); program.addConsumer(consumer);
if (!program.isChanged()) { if (!program.isChanged() || ProgramUtilities.isChangedWithUpgradeOnly(program)) {
// Don't put modified programs into the cache. // Don't put modified programs into the cache unless the only change
// NOTE: This will prevent upgraded programs from being added to the cache // corresponds to an upgrade during its instantiation.
// which are already open in the tool. This could be improved if we could
// distinguish between upgrade and non-upgrade changes.
programCache.put(locator, program); programCache.put(locator, program);
} }
return program; return program;

View file

@ -15,6 +15,8 @@
*/ */
package ghidra.program.util; package ghidra.program.util;
import java.util.*;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
import ghidra.program.model.mem.MemoryAccessException; import ghidra.program.model.mem.MemoryAccessException;
@ -23,8 +25,6 @@ import ghidra.util.*;
import ghidra.util.exception.DuplicateNameException; import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.InvalidInputException; import ghidra.util.exception.InvalidInputException;
import java.util.*;
/** /**
* General utility class that provides convenience methods * General utility class that provides convenience methods
* to deal with Program objects. * to deal with Program objects.
@ -173,4 +173,18 @@ public class ProgramUtilities {
Msg.error(ProgramUtilities.class, "Unexpected Exception", e); Msg.error(ProgramUtilities.class, "Unexpected Exception", e);
} }
} }
/**
* Determine if a program has a single unsaved change which corresponds to an
* upgrade which occured during instantiation.
* @param program the program to be checked for an unsaved upgrade condition.
* @return true if program upgraded and has not been saved, else false
*/
public static boolean isChangedWithUpgradeOnly(Program program) {
// The only non-undoable change is an upgrade that occurs during instantiation
if (!program.isChanged()) {
return false;
}
return !program.canUndo();
}
} }