Skip to content

Commit 4b465a9

Browse files
committed
Merge remote-tracking branch 'origin/GP-4165_ghidra1_ProgramUpgradeCacheImprovement--SQUASHED'
2 parents f765690 + 0aa96ce commit 4b465a9

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,9 @@ private Program openCachedProgram(ProgramLocator locator, Object consumer) {
304304
program = programMgr.getOpenProgram(locator);
305305
if (program != null) {
306306
program.addConsumer(consumer);
307-
if (!program.isChanged()) {
308-
// Don't put modified programs into the cache.
309-
// NOTE: This will prevent upgraded programs from being added to the cache
310-
// which are already open in the tool. This could be improved if we could
311-
// distinguish between upgrade and non-upgrade changes.
307+
if (!program.isChanged() || ProgramUtilities.isChangedWithUpgradeOnly(program)) {
308+
// Don't put modified programs into the cache unless the only change
309+
// corresponds to an upgrade during its instantiation.
312310
programCache.put(locator, program);
313311
}
314312
return program;

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/ProgramUtilities.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package ghidra.program.util;
1717

18+
import java.util.*;
19+
1820
import ghidra.program.model.address.Address;
1921
import ghidra.program.model.listing.*;
2022
import ghidra.program.model.mem.MemoryAccessException;
@@ -23,8 +25,6 @@
2325
import ghidra.util.exception.DuplicateNameException;
2426
import ghidra.util.exception.InvalidInputException;
2527

26-
import java.util.*;
27-
2828
/**
2929
* General utility class that provides convenience methods
3030
* to deal with Program objects.
@@ -173,4 +173,18 @@ public static void convertFunctionWrappedExternalPointer(Symbol functionSymbol)
173173
Msg.error(ProgramUtilities.class, "Unexpected Exception", e);
174174
}
175175
}
176+
177+
/**
178+
* Determine if a program has a single unsaved change which corresponds to an
179+
* upgrade which occured during instantiation.
180+
* @param program the program to be checked for an unsaved upgrade condition.
181+
* @return true if program upgraded and has not been saved, else false
182+
*/
183+
public static boolean isChangedWithUpgradeOnly(Program program) {
184+
// The only non-undoable change is an upgrade that occurs during instantiation
185+
if (!program.isChanged()) {
186+
return false;
187+
}
188+
return !program.canUndo();
189+
}
176190
}

0 commit comments

Comments
 (0)